1 //
2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.deploy.util;
20
21 import java.io.File;
22 import java.util.Locale;
23
24 /**
25 * Simple, yet surprisingly common utility methods for identifying various file types commonly seen and worked with in a
26 * deployment scenario.
27 */
28 public class FileID
29 {
30 /**
31 * Is the path a Web Archive?
32 *
33 * @param path
34 * the path to test.
35 * @return True if a .war or .jar or exploded web directory
36 * @see FileID#isWebArchiveFile(File)
37 */
38 public static boolean isWebArchive(File path)
39 {
40 if (path.isFile())
41 {
42 String name = path.getName().toLowerCase(Locale.ENGLISH);
43 return (name.endsWith(".war") || name.endsWith(".jar"));
44 }
45
46 File webInf = new File(path,"WEB-INF");
47 File webXml = new File(webInf,"web.xml");
48 return webXml.exists() && webXml.isFile();
49 }
50
51 /**
52 * Is the path a Web Archive File (not directory)
53 *
54 * @param path
55 * the path to test.
56 * @return True if a .war or .jar file.
57 * @see FileID#isWebArchive(File)
58 */
59 public static boolean isWebArchiveFile(File path)
60 {
61 if (!path.isFile())
62 {
63 return false;
64 }
65
66 String name = path.getName().toLowerCase(Locale.ENGLISH);
67 return (name.endsWith(".war") || name.endsWith(".jar"));
68 }
69
70 public static boolean isXmlFile(File path)
71 {
72 if (!path.isFile())
73 {
74 return false;
75 }
76
77 String name = path.getName().toLowerCase(Locale.ENGLISH);
78 return name.endsWith(".xml");
79 }
80 }