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