1 /* 2 * Copyright 2000-2001,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 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 // extends TestCase 25 { 26 /* 27 static public Test suite() 28 { 29 TestSuite suite = new TestSuite(TestRewriter.class); 30 return(suite); 31 } 32 */ 33 public TestRewriter(String name) 34 { 35 //super(name); 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 //URL pageUrl = new URL("http://www.devx.com/Java/Article/9747/"); 62 URL pageUrl = new URL(fullURL); 63 64 URLConnection pageConn = pageUrl.openConnection(); 65 String encoding = pageConn.getContentEncoding(); 66 67 if(encoding == null) 68 { 69 // Standard HTTP encoding 70 encoding = "iso-8859-1"; 71 } 72 73 reader = new InputStreamReader(pageConn.getInputStream(), 74 encoding ); 75 76 //String crap = Streams.getAsString(reader); 77 //System.out.println("crap = " + crap); 78 79 HTMLRewriter rewriter = new HTMLRewriter(); 80 81 // String result = rewriter.rewrite(reader, "XXXX", "YYYY"); 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 // String[] testCaseName = {TestRewriter.class.getName()}; 110 // junit.swingui.TestRunner.main(testCaseName); 111 TestRewriter trw = new TestRewriter("test"); 112 trw.testPage(); 113 114 } 115 116 } 117