KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > URLPatternWarningCheck


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 package com.sun.enterprise.tools.verifier.tests.web;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * The content of the url-pattern element follows the rules specified in
33  * section 10 of the servlet spec.
34  * In this test we check for warnings. See bug#4880426 for more details about the motivation.
35  */

36 public class URLPatternWarningCheck extends URLPattern {
37
38     protected void checkUrlPatternAndSetResult(String JavaDoc urlPattern, Descriptor descriptor, Result result, ComponentNameConstructor compName){
39
40      if(urlPattern==null) return;//URLPattern1 will take care of this condition. So don't do any thing. More over, the super class would have set NA status, so we don't do that either.
41

42      int count = new StringTokenizer(urlPattern,"*", true).countTokens();
43      // See bug#4880426
44
if((count ==2 && !urlPattern.endsWith("/*") && !urlPattern.startsWith("*.")) // patterns like /abc*, but not /abc/*, /*, *.jsp or *.
45
|| (count > 2)) //patterns like *.*, *.j*p, /*.jsp, /**, but not *.jsp
46
{
47     oneWarning=true;
48         result.warning(smh.getLocalString
49                                  ("tests.componentNameConstructor",
50                                   "For [ {0} ]",
51                                   new Object JavaDoc[] {compName.toString()}));
52         result.addWarningDetails (smh.getLocalString
53                                    (getClass().getName() + ".warning",
54                                     "url-pattern [ {0} ] within [ {1} ] will be used for exact match only, although it contains a *",
55                                     new Object JavaDoc[] {urlPattern, descriptor.getName()}));
56      } else {
57         result.passed(smh.getLocalString
58                               ("tests.componentNameConstructor",
59                                "For [ {0} ]",
60                                new Object JavaDoc[] {compName.toString()}));
61         result.addGoodDetails (smh.getLocalString
62                             (getClass().getName() + ".passed",
63                              "url-pattern [ {0} ] within [ {1} ] follows the rules specified in servlet spec",
64                              new Object JavaDoc[] {urlPattern, descriptor.getName()}));
65      }
66     }
67 }
68
Popular Tags