KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > wsdl > util > URLProcessor


1 package org.apache.axis2.wsdl.util;
2
3 import java.util.regex.Matcher JavaDoc;
4 import java.util.regex.Pattern JavaDoc;
5
6 /*
7  * Copyright 2004,2005 The Apache Software Foundation.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *
22  */

23 public class URLProcessor {
24     public static final String JavaDoc DEFAULT_PACKAGE = "axis2";
25
26     /**
27      * Breaks a given url to a package
28      * e.g. http://www.google.com/test will become
29      * com.google.www
30      * @param url
31      * @return
32      */

33     public static String JavaDoc getNameSpaceFromURL(String JavaDoc url){
34            String JavaDoc returnPackageName = "";
35            String JavaDoc regularExpression = "//[\\w\\.]*";
36            Pattern JavaDoc urlBreaker =Pattern.compile(regularExpression);
37            Matcher JavaDoc matcher = urlBreaker.matcher(url);
38            if (matcher.find()) {
39                String JavaDoc s = matcher.group();
40                s = s.replaceAll("//","");
41                String JavaDoc[] arrayOfItems = s.split("\\.");
42                int length = arrayOfItems.length;
43                for (int i = length; i > 0; i--) {
44                    returnPackageName = returnPackageName.concat((i==length?"":".") + arrayOfItems[i-1]);
45                }
46            }else{
47                returnPackageName = DEFAULT_PACKAGE;
48            }
49
50            return returnPackageName;
51        }
52
53 }
54
Popular Tags