KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > repository > ArtifactHandler


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.repository ;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.net.URLConnection JavaDoc;
23 import java.net.URLStreamHandler JavaDoc;
24
25 /**
26  * Repository URL protocol handler.
27  */

28 public class ArtifactHandler extends URLStreamHandler JavaDoc
29 {
30     /**
31      * Opens a connection to the specified URL.
32      *
33      * @param url A URL to open a connection to.
34      * @return The established connection.
35      * @throws IOException If a connection failure occurs.
36      */

37     protected URLConnection JavaDoc openConnection( final URL JavaDoc url )
38       throws IOException JavaDoc
39     {
40         return new ArtifactURLConnection( url );
41     }
42
43     protected int getDefaultPort()
44     {
45         return 0;
46     }
47
48     protected String JavaDoc toExternalForm( URL JavaDoc url )
49     {
50       StringBuffer JavaDoc result = new StringBuffer JavaDoc( "artifact:" );
51         if (url.getFile() != null )
52         {
53             result.append(url.getFile());
54         }
55       if (url.getRef() != null )
56         {
57           result.append("#");
58             result.append(url.getRef());
59       }
60       return result.toString();
61     }
62
63 }
64
Popular Tags