KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > servlet > FramesetFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.help.internal.webapp.servlet;
13
14 import java.io.*;
15
16 import javax.servlet.http.*;
17
18 import org.eclipse.help.internal.webapp.data.*;
19
20 /**
21  * This class inserts a script for showing the page inside the appropriate
22  * frameset when bookmarked.
23  */

24 public class FramesetFilter implements IFilter {
25     private static final String JavaDoc scriptPart1 = "<script>if( self == top ){ window.location.replace( \""; //$NON-NLS-1$
26
private static final String JavaDoc scriptPart3 = "\");}</script>"; //$NON-NLS-1$
27

28     /*
29      * @see IFilter#filter(HttpServletRequest, OutputStream)
30      */

31     public OutputStream filter(HttpServletRequest req, OutputStream out) {
32         String JavaDoc uri = req.getRequestURI();
33         if (uri == null || !uri.endsWith("html") && !uri.endsWith("htm")) { //$NON-NLS-1$ //$NON-NLS-2$
34
return out;
35         }
36
37         if ("/nftopic".equals(req.getServletPath()) || //$NON-NLS-1$
38
"/ntopic".equals(req.getServletPath()) || //$NON-NLS-1$
39
"/rtopic".equals(req.getServletPath()) || //$NON-NLS-1$
40
UrlUtil.isBot(req)) {
41             return out;
42         }
43
44         String JavaDoc noframes = req.getParameter("noframes"); //$NON-NLS-1$
45
if ("true".equals(noframes)) { //$NON-NLS-1$
46
return out;
47         }
48
49         String JavaDoc path = req.getPathInfo();
50         if (path == null) {
51             return out;
52         }
53         StringBuffer JavaDoc script = new StringBuffer JavaDoc(scriptPart1);
54         for (int i; 0 <= (i = path.indexOf('/')); path = path.substring(i + 1)) {
55             script.append("../"); //$NON-NLS-1$
56
}
57         script.append("index.jsp?topic="); //$NON-NLS-1$
58
script.append(req.getPathInfo());
59         script.append(scriptPart3);
60         try {
61             return new FilterHTMLHeadOutputStream(out, script.toString()
62                     .getBytes("ASCII")); //$NON-NLS-1$
63
} catch (UnsupportedEncodingException uee) {
64             return out;
65         }
66     }
67 }
68
Popular Tags