1 //
2 // ========================================================================
3 // Copyright (c) 1995-2012 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
23 /**
24 * Simple, yet surprisingly common utility methods for identifying various file types commonly seen and worked with in a
25 * deployment scenario.
26 */
27 public class FileID
28 {
29 /**
30 * Is the path a Web Archive?
31 *
32 * @param path
33 * the path to test.
34 * @return True if a .war or .jar or exploded web directory
35 * @see FileID#isWebArchiveFile(File)
36 */
37 public static boolean isWebArchive(File path)
38 {
39 if (path.isFile())
40 {
41 String name = path.getName().toLowerCase();
42 return (name.endsWith(".war") || name.endsWith(".jar"));
43 }
44
45 File webInf = new File(path,"WEB-INF");
46 File webXml = new File(webInf,"web.xml");
47 return webXml.exists() && webXml.isFile();
48 }
49
50 /**
51 * Is the path a Web Archive File (not directory)
52 *
53 * @param path
54 * the path to test.
55 * @return True if a .war or .jar file.
56 * @see FileID#isWebArchive(File)
57 */
58 public static boolean isWebArchiveFile(File path)
59 {
60 if (!path.isFile())
61 {
62 return false;
63 }
64
65 String name = path.getName().toLowerCase();
66 return (name.endsWith(".war") || name.endsWith(".jar"));
67 }
68
69 public static boolean isXmlFile(File path)
70 {
71 if (!path.isFile())
72 {
73 return false;
74 }
75
76 String name = path.getName().toLowerCase();
77 return name.endsWith(".xml");
78 }
79 }