KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > http > HTMLRootHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.manager.http;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
28 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
29
30 /**
31  *
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
34  * @since 4.1
35  */

36 public class HTMLRootHandler
37     extends AbstractHTMLHandler
38 {
39     /*---------------------------------------------------------------
40      * Constructors
41      *-------------------------------------------------------------*/

42     /**
43      * Creates a new HTMLRootHandler.
44      *
45      * @param manager Reference to the DefaultInstrumentManager.
46      * @param connector The InstrumentManagerHTTPConnector.
47      */

48     public HTMLRootHandler( DefaultInstrumentManager manager,
49                             InstrumentManagerHTTPConnector connector )
50     {
51         super( "/", manager, connector );
52     }
53     
54     /*---------------------------------------------------------------
55      * AbstractHTTPURLHandler Methods
56      *-------------------------------------------------------------*/

57     /**
58      * Handles the specified request.
59      *
60      * @param The full path being handled.
61      * @param parameters A Map of the parameters in the request.
62      * @param os The PrintWriter to write the result to.
63      */

64     public void doGet( String JavaDoc path, Map JavaDoc parameters, PrintWriter JavaDoc out )
65         throws IOException JavaDoc
66     {
67         // Do not catch XML requests.
68
if ( path.endsWith( ".xml" ) )
69         {
70             throw new FileNotFoundException JavaDoc( "The Requested page does not exist" );
71         }
72         
73         if ( path.indexOf( '/', 1 ) >= 0 )
74         {
75             // Found a slash after the base, so we are in a subdirectory.
76
throw new HTTPRedirect( "../instrument-manager.html" );
77         }
78         else
79         {
80             throw new HTTPRedirect( "instrument-manager.html" );
81         }
82     }
83 }
84
85
Popular Tags