1 16 17 package org.apache.jetspeed.util.rewriter; 18 19 import java.io.Reader ; 21 22 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 26 import javax.swing.text.html.HTML ; 28 import javax.swing.text.MutableAttributeSet ; 29 30 38 39 public class HTMLRewriter implements Rewriter 40 { 41 45 public HTMLRewriter() 46 { 47 } 48 49 protected String baseURL = null; 50 51 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; } 74 } 75 catch (Exception e) 76 { 77 System.err.println(e); 78 } 79 return fullPath; 80 81 } 82 83 84 89 public boolean proxyAllTags() 90 { 91 return true; } 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 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 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 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 148 public boolean enterText(char[] values, int param) 149 { 150 return true; 151 } 152 153 156 public void convertTagEvent(HTML.Tag tag, MutableAttributeSet attrs) 157 { 158 } 159 160 } 161 162 | Popular Tags |