KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > web > URLPattern


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.util.web;
25
26 public class URLPattern {
27     
28     // In Ascii table, New Line (NL) decimal value is 10
29
private final static int NL = 10;
30     // In Ascii table, Carriage Return (CR) decimal value is 13
31
private final static int CR = 13;
32
33     /**
34      * This method is used to check the validity of url pattern
35      * according to the spec. It is used in the following places:
36      *
37      * 1. in WebResourceCollection
38      * 2. in ServletMapping
39      * 3. in ServletFilterMapping
40      * (above three see Servlet Spec, from version 2.3 on,
41      * Secion 13.2: "Rules for Processing the Deployment Descriptor")
42      *
43      * 4. in jsp-property-group
44      * (see JSP.3.3: "JSP Property Groups")
45      *
46      * @param urlPattern the url pattern
47      * @return false for invalid url pattern
48      */

49     public static boolean isValid(String JavaDoc urlPattern) {
50         // URL Pattern should not contain New Line (NL) or
51
// Carriage Return (CR)
52
if (urlPattern.indexOf(NL) != -1 || urlPattern.indexOf (CR) != -1) {
53             return false;
54         }
55
56         // Check validity for extension mapping
57
if (urlPattern.startsWith("*.")) {
58             if (urlPattern.indexOf('/') < 0) {
59                 return true;
60             } else {
61                 return false;
62             }
63         }
64
65         // check validity for path mapping
66
if ( urlPattern.startsWith("/") && urlPattern.indexOf("*.") < 0) {
67             return true;
68         } else {
69             return false;
70         }
71
72     }
73 }
74
Popular Tags