KickJava   Java API By Example, From Geeks To Geeks.

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


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 BlockHandler extends URLStreamHandler JavaDoc
29 {
30
31     /**
32      * Opens a connection to the specified URL.
33      *
34      * @param url A URL to open a connection to.
35      * @return The established connection.
36      * @throws IOException If a connection failure occurs.
37      */

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