1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.util.rewriter;
17
18 import java.io.Reader;
19 import java.io.InputStreamReader;
20
21 import java.net.URL;
22 import java.net.URLConnection;
23
24 public class TestRewriter
25 {
26
27
28
29
30
31
32
33 public TestRewriter(String name)
34 {
35
36 }
37
38
39
40
41 protected void setUp()
42 {
43 }
44
45 protected void tearDown()
46 {
47 }
48
49
50
51
52 public void testPage()
53 {
54 Reader reader = null;
55
56 try
57 {
58 String baseURL = "http://java.sun.com/";
59 String fullURL = "http://java.sun.com/";
60
61
62 URL pageUrl = new URL(fullURL);
63
64 URLConnection pageConn = pageUrl.openConnection();
65 String encoding = pageConn.getContentEncoding();
66
67 if(encoding == null)
68 {
69
70 encoding = "iso-8859-1";
71 }
72
73 reader = new InputStreamReader(pageConn.getInputStream(),
74 encoding );
75
76
77
78
79 HTMLRewriter rewriter = new HTMLRewriter();
80
81
82 String result = rewriter.rewrite(reader, baseURL);
83 System.out.println(result);
84
85 reader.close();
86 reader = null;
87
88 } catch (Exception e)
89 {
90 System.err.println("Exception occurred:" + e.toString());
91 e.printStackTrace();
92 }
93 finally
94 {
95 try
96 {
97 if (null != reader)
98 reader.close();
99 }
100 catch (Exception e)
101 {}
102 }
103 }
104
105
106
107 static public void main(String[] argv)
108 {
109
110
111 TestRewriter trw = new TestRewriter("test");
112 trw.testPage();
113
114 }
115
116 }
117