1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util.rewriter;
18
19
20 import java.io.Reader;
21
22
23 import java.net.MalformedURLException;
24 import java.net.URL;
25
26
27 import javax.swing.text.html.HTML;
28 import javax.swing.text.MutableAttributeSet;
29
30 /***
31 *
32 * Basic Rewriter for rewriting HTML content.
33 *
34 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
35 * @version $Id: HTMLRewriter.java,v 1.6 2004/02/23 03:18:59 jford Exp $
36 *
37 */
38
39 public class HTMLRewriter implements Rewriter
40 {
41
42
43
44
45 public HTMLRewriter()
46 {
47 }
48
49 protected String baseURL = null;
50
51
52
53
54
55
56
57
58
59 public String generateNewUrl( String targetURL, HTML.Tag tag, HTML.Attribute attribute)
60 {
61 String fullPath = "";
62 try
63 {
64
65 if (baseURL != null)
66 {
67 URL full = new URL(new URL(baseURL), targetURL);
68 fullPath = full.toString();
69 }
70 else
71 {
72 return targetURL;
73 }
74 }
75 catch (Exception e)
76 {
77 System.err.println(e);
78 }
79 return fullPath;
80
81 }
82
83
84
85
86
87
88
89 public boolean proxyAllTags()
90 {
91 return true;
92 }
93
94 public String rewrite(Reader input, String baseURL)
95 throws MalformedURLException
96 {
97 String rewrittenHTML = "";
98 this.baseURL = baseURL;
99
100 HTMLParserAdaptor parser = new SwingParserAdaptor(this);
101 rewrittenHTML = parser.run(input);
102
103 return rewrittenHTML;
104 }
105
106
107
108
109 public boolean enterSimpleTagEvent(HTML.Tag tag, MutableAttributeSet attrs)
110 {
111 return true;
112 }
113
114 public String exitSimpleTagEvent(HTML.Tag tag, MutableAttributeSet attrs)
115 {
116 return null;
117 }
118
119
120
121
122 public boolean enterStartTagEvent(HTML.Tag tag, MutableAttributeSet attrs)
123 {
124 return true;
125 }
126
127 public String exitStartTagEvent(HTML.Tag tag, MutableAttributeSet attrs)
128 {
129 return null;
130 }
131
132
133
134
135 public boolean enterEndTagEvent(HTML.Tag tag)
136 {
137 return true;
138 }
139
140 public String exitEndTagEvent(HTML.Tag tag)
141 {
142 return null;
143 }
144
145
146
147
148 public boolean enterText(char[] values, int param)
149 {
150 return true;
151 }
152
153
154
155
156 public void convertTagEvent(HTML.Tag tag, MutableAttributeSet attrs)
157 {
158 }
159
160 }
161