check the validity of url pattern according to the spec. : URL « Network Protocol « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Network Protocol » URLScreenshots 
check the validity of url pattern according to the spec.
   

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License. You can obtain
 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
 * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
 * Sun designates this particular file as subject to the "Classpath" exception
 * as provided by Sun in the GPL Version 2 section of the License file that
 * accompanied this code.  If applicable, add the following below the License
 * Header, with the fields enclosed by brackets [] replaced by your own
 * identifying information: "Portions Copyrighted [year]
 * [name of copyright owner]"
 
 * Contributor(s):
 
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */


public class URLPattern {
    
    // In Ascii table, New Line (NL) decimal value is 10
    private final static int NL = 10;
    // In Ascii table, Carriage Return (CR) decimal value is 13
    private final static int CR = 13;

    /**
     *  This method is used to check the validity of url pattern 
     *  according to the spec. It is used in the following places:
     *
     *  1. in WebResourceCollection 
     *  2. in ServletMapping
     *  3. in ServletFilterMapping
     *  (above three see Servlet Spec, from version 2.3 on, 
     *  Secion 13.2: "Rules for Processing the Deployment Descriptor")
     *
     *  4. in jsp-property-group 
     *  (see JSP.3.3: "JSP Property Groups")
     *
     *  @param urlPattern the url pattern
     *  @return false for invalid url pattern
     */
    public static boolean isValid(String urlPattern) {
        // URL Pattern should not contain New Line (NL) or
        // Carriage Return (CR)
        if (urlPattern.indexOf(NL!= -1  || urlPattern.indexOf (CR!= -1) {
            return false;
        }

        // Check validity for extension mapping
        if (urlPattern.startsWith("*.")) {
            if (urlPattern.indexOf('/'0) {
                return true;
            else {
                return false;
            }
        }

        // check validity for path mapping
        if urlPattern.startsWith("/"&& urlPattern.indexOf("*."0) {
            return true;
        else {
            return false;
        }

    }
}

   
    
    
  
Related examples in the same category
1. Creating a URL with a single string.
2. Creating a URL With components
3. Converting Between a Filename Path and a URL
4. URL Constructor Test
5. URL Encode Test
6. Get URL Content
7. Get URL Parts
8. Read from a URL
9. Convert a URL to a URI
10. Converting Between a URL and a URI
11. Convert an absolute URI to a URL
12. URL Equality
13. Parsing a URL
14. URL Request
15. URL Get
16. A URL Retrieval Example
17. URL Reader
18. URL Connection ReaderURL Connection Reader
19. Using URLConnection
20. Parse URLParse URL
21. Resolve a relative URL
22. sends e-mail using a mailto: URLsends e-mail using a mailto: URL
23. Convert the absolute URI to a URL object
24. Convert URI to URL
25. Get parts of a url
26. Checks, whether the URL uses a file based protocol.
27. Add Parameter to URL
28. Returns the anchor value of the given URL
29. Extracts the file name from the URL.
30. Creates a relative url by stripping the common parts of the the url.
31. Checks, whether the URL points to the same service. A service is equal if the protocol, host and port are equal.
32. Extracts the base URL from the given URL by stripping the query and anchor part.
33. Returns true if the URL represents a path, and false otherwise.
34. Parse Port
35. Parse Host
36. Given a URL check if its a jar url(jar:!/archive) and if it is, extract the archive entry into the given dest directory and return a file URL to its location
37. A collection of File, URL and filename utility methods
38. Build Relative URL Path
39. Checks that the protocol://host:port part of two URLs are equal
40. Create valid URL from a system id
41. Extract URL File Name
42. Extract the URL page name from the given path
43. Get Domain Name
44. Get Locale From String
45. Get URL Last Modified
46. Get the name of the parent of the given URL path
47. Get the parent of the given URL path
48. Has URLContent Changed
49. Is URL a local file
50. Normalize an URL
51. Normalizes an URL
52. Resolve a relative URL string against an absolute URL string
53. ResourceBundle String manager
54. Save URL contents to a file
55. URL Path: standardize the creation of mutation of path-like structures
56. Utility class for building URLs
57. Add Default Port to a URL If Missing
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.