KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > commons > net > URIWrapper


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.commons.net;
20
21 import java.net.*;
22 import java.util.*;
23 import java.util.logging.*;
24
25 /**
26  * Wraps the <code>java.net.URI</code> implementation and adds some useful
27  * utility methods.
28  *
29  * @author Matthew Large
30  * @version $Revision: 1.1 $
31  *
32  */

33 public class URIWrapper {
34     
35     /**
36      * Wrapped URI.
37      */

38     private URI m_uri = null;
39     
40     /**
41      * List of segments in URI.
42      */

43     private ArrayList m_aSegments = new ArrayList();
44     
45     /**
46      * Logger for this class.
47      */

48     private static final Logger m_logger = Logger.getLogger(URIWrapper.class.getName());
49
50     /**
51      * Constructs an object representing the given URI.
52      *
53      * @param uri URI to be represented
54      */

55     public URIWrapper(String JavaDoc uri) {
56         try {
57             this.m_uri = new URI(uri);
58         } catch (URISyntaxException e) {
59             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
60         }
61         this.setup();
62     }
63
64     /**
65      * Constructs a URI from the given components.
66      *
67      * @param scheme Scheme name
68      * @param ssp Scheme-specific part
69      * @param fragment Fragment
70      */

71     public URIWrapper(String JavaDoc scheme, String JavaDoc ssp, String JavaDoc fragment) {
72         try {
73             this.m_uri = new URI(scheme, ssp, fragment);
74         } catch (URISyntaxException e) {
75             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
76         }
77         this.setup();
78     }
79
80     /**
81      * Constructs a URI from the given components.
82      *
83      * @param scheme Scheme name
84      * @param userInfo User name and authorization information
85      * @param host Host name
86      * @param port Port number
87      * @param path Path
88      * @param query Query
89      * @param fragment Fragment
90      */

91     public URIWrapper(
92         String JavaDoc scheme,
93         String JavaDoc userInfo,
94         String JavaDoc host,
95         int port,
96         String JavaDoc path,
97         String JavaDoc query,
98         String JavaDoc fragment) {
99         try {
100             this.m_uri =
101                 new URI(scheme, userInfo, host, port, path, query, fragment);
102         } catch (URISyntaxException e) {
103             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
104         }
105         this.setup();
106     }
107
108     /**
109      * Constructs a hierarchical URI from the given components.
110      *
111      * @param scheme Scheme name
112      * @param host Host name
113      * @param path Path
114      * @param fragment Fragment
115      */

116     public URIWrapper(String JavaDoc scheme, String JavaDoc host, String JavaDoc path, String JavaDoc fragment) {
117         try {
118             this.m_uri = new URI(scheme, host, path, fragment);
119         } catch (URISyntaxException e) {
120             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
121         }
122         this.setup();
123     }
124
125     /**
126      *
127      * Constructs a hierarchical URI from the given components.
128      *
129      * @param scheme Scheme name
130      * @param authority Authority
131      * @param path Path
132      * @param query Query
133      * @param fragment Fragment
134      */

135     public URIWrapper(
136         String JavaDoc scheme,
137         String JavaDoc authority,
138         String JavaDoc path,
139         String JavaDoc query,
140         String JavaDoc fragment) {
141         try {
142             this.m_uri = new URI(scheme, authority, path, query, fragment);
143         } catch (URISyntaxException e) {
144             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
145         }
146         this.setup();
147     }
148     
149     /**
150      * Sets up the member variables using the path of the URI.
151      *
152      */

153     private void setup() {
154         StringTokenizer sTok = new StringTokenizer(this.getPath(), "/", false);
155         while(sTok.hasMoreElements()) {
156             this.m_aSegments.add( (String JavaDoc)sTok.nextElement() );
157         }
158     }
159     
160     /**
161      * Delegate method.
162      *
163      * @see java.net.URI#create(String)
164      */

165     public static URI create(String JavaDoc arg0) {
166         return URI.create(arg0);
167     }
168
169     /**
170      * Delegate method.
171      *
172      * @see java.net.URI#compareTo(Object)
173      */

174     public int compareTo(Object JavaDoc arg0) {
175         return m_uri.compareTo(arg0);
176     }
177
178     /* (non-Javadoc)
179      * @see java.lang.Object#equals(java.lang.Object)
180      */

181     public boolean equals(Object JavaDoc arg0) {
182         return m_uri.equals(arg0);
183     }
184
185     /**
186      * Delegate method.
187      *
188      * @see java.net.URI#getAuthority()
189      */

190     public String JavaDoc getAuthority() {
191         return m_uri.getAuthority();
192     }
193
194     /**
195      * Delegate method.
196      *
197      * @see java.net.URI#getFragment()
198      */

199     public String JavaDoc getFragment() {
200         return m_uri.getFragment();
201     }
202
203     /**
204      * Delegate method.
205      *
206      * @see java.net.URI#getHost()
207      */

208     public String JavaDoc getHost() {
209         return m_uri.getHost();
210     }
211
212     /**
213      * Delegate method.
214      *
215      * @see java.net.URI#getPath()
216      */

217     public String JavaDoc getPath() {
218         return m_uri.getPath();
219     }
220     
221     /**
222      * Returns a list of the path segments for this URI
223      *
224      * @return list of <code>String</code>s
225      */

226     public List getPathSegments() {
227         return (List) m_aSegments.clone();
228     }
229
230     /**
231      * Delegate method.
232      *
233      * @see java.net.URI#getPort()
234      */

235     public int getPort() {
236         return m_uri.getPort();
237     }
238
239     /**
240      * Delegate method.
241      *
242      * @see java.net.URI#getQuery()
243      */

244     public String JavaDoc getQuery() {
245         return m_uri.getQuery();
246     }
247
248     /**
249      * Delegate method.
250      *
251      * @see java.net.URI#getRawAuthority()
252      */

253     public String JavaDoc getRawAuthority() {
254         return m_uri.getRawAuthority();
255     }
256
257     /**
258      * Delegate method.
259      *
260      * @see java.net.URI#getRawFragment()
261      */

262     public String JavaDoc getRawFragment() {
263         return m_uri.getRawFragment();
264     }
265
266     /**
267      * Delegate method.
268      *
269      * @see java.net.URI#getRawPath()
270      */

271     public String JavaDoc getRawPath() {
272         return m_uri.getRawPath();
273     }
274
275     /**
276      * Delegate method.
277      *
278      * @see java.net.URI#getRawQuery()
279      */

280     public String JavaDoc getRawQuery() {
281         return m_uri.getRawQuery();
282     }
283
284     /**
285      * Delegate method.
286      *
287      * @see java.net.URI#getRawSchemeSpecificPart()
288      */

289     public String JavaDoc getRawSchemeSpecificPart() {
290         return m_uri.getRawSchemeSpecificPart();
291     }
292
293     /**
294      * Delegate method.
295      *
296      * @see java.net.URI#getRawUserInfo()
297      */

298     public String JavaDoc getRawUserInfo() {
299         return m_uri.getRawUserInfo();
300     }
301
302     /**
303      * Delegate method.
304      *
305      * @see java.net.URI#getScheme()
306      */

307     public String JavaDoc getScheme() {
308         return m_uri.getScheme();
309     }
310
311     /**
312      * Delegate method.
313      *
314      * @see java.net.URI#getSchemeSpecificPart()
315      */

316     public String JavaDoc getSchemeSpecificPart() {
317         return m_uri.getSchemeSpecificPart();
318     }
319
320     /**
321      * Delegate method.
322      *
323      * @see java.net.URI#getUserInfo()
324      */

325     public String JavaDoc getUserInfo() {
326         return m_uri.getUserInfo();
327     }
328
329     /* (non-Javadoc)
330      * @see java.lang.Object#hashCode()
331      */

332     public int hashCode() {
333         return m_uri.hashCode();
334     }
335
336     /**
337      * Delegate method.
338      *
339      * @see java.net.URI#isAbsolute()
340      */

341     public boolean isAbsolute() {
342         return m_uri.isAbsolute();
343     }
344
345     /**
346      * Delegate method.
347      *
348      * @see java.net.URI#isOpaque()
349      */

350     public boolean isOpaque() {
351         return m_uri.isOpaque();
352     }
353
354     /**
355      * Delegate method.
356      *
357      * @see java.net.URI#normalize()
358      */

359     public URI normalize() {
360         return m_uri.normalize();
361     }
362
363     /**
364      * Delegate method.
365      *
366      * @see java.net.URI#parseServerAuthority()
367      */

368     public URI parseServerAuthority() throws URISyntaxException {
369         return m_uri.parseServerAuthority();
370     }
371
372     /**
373      * Delegate method.
374      *
375      * @see java.net.URI#relativize(URI)
376      */

377     public URI relativize(URI arg0) {
378         return m_uri.relativize(arg0);
379     }
380
381     /**
382      * Delegate method.
383      *
384      * @see java.net.URI#resolve(String)
385      */

386     public URI resolve(String JavaDoc arg0) {
387         return m_uri.resolve(arg0);
388     }
389
390     /**
391      * Delegate method.
392      *
393      * @see java.net.URI#resolve(URI)
394      */

395     public URI resolve(URI arg0) {
396         return m_uri.resolve(arg0);
397     }
398
399     /**
400      * Delegate method.
401      *
402      * @see java.net.URI#toASCIIString()
403      */

404     public String JavaDoc toASCIIString() {
405         return m_uri.toASCIIString();
406     }
407
408     /* (non-Javadoc)
409      * @see java.lang.Object#toString()
410      */

411     public String JavaDoc toString() {
412         return m_uri.toString();
413     }
414
415     /**
416      * Delegate method.
417      *
418      * @see java.net.URI#toURL()
419      */

420     public URL toURL() throws MalformedURLException {
421         return m_uri.toURL();
422     }
423
424 }
425
Popular Tags