1 42 package org.jfree.xml; 43 44 import java.net.MalformedURLException ; 45 import java.net.URL ; 46 import java.util.Iterator ; 47 import java.util.Enumeration ; 48 49 import org.jfree.util.Configuration; 50 import org.jfree.util.DefaultConfiguration; 51 import org.xml.sax.Locator ; 52 import org.xml.sax.SAXException ; 53 import org.xml.sax.helpers.DefaultHandler ; 54 55 61 public abstract class FrontendDefaultHandler extends DefaultHandler implements Configuration { 62 65 public static final String CONTENTBASE_KEY = "content-base"; 66 67 70 private DefaultConfiguration parserConfiguration; 71 72 75 private Locator locator; 76 77 80 private final CommentHandler commentHandler; 81 82 85 protected FrontendDefaultHandler() { 86 this.parserConfiguration = new DefaultConfiguration(); 87 this.commentHandler = new CommentHandler(); 88 } 89 90 95 public CommentHandler getCommentHandler() { 96 return this.commentHandler; 97 } 98 99 111 public void setDocumentLocator(final Locator locator) { 112 this.locator = locator; 113 } 114 115 120 public Locator getLocator() { 121 return this.locator; 122 } 123 124 130 public String getConfigProperty(final String key) { 131 return getConfigProperty(key, null); 132 } 133 134 145 public String getConfigProperty(final String key, final String defaultValue) { 146 return this.parserConfiguration.getConfigProperty(key, defaultValue); 147 } 148 149 155 public void setConfigProperty(final String key, final String value) { 156 if (value == null) { 157 this.parserConfiguration.remove(key); 158 } 159 else { 160 this.parserConfiguration.setProperty(key, value); 161 } 162 } 163 164 public Enumeration getConfigProperties() 165 { 166 return parserConfiguration.getConfigProperties(); 167 } 168 169 174 public abstract FrontendDefaultHandler newInstance(); 175 176 182 public Iterator findPropertyKeys(final String prefix) { 183 return this.parserConfiguration.findPropertyKeys(prefix); 184 } 185 186 193 public abstract Object getResult() throws SAXException ; 194 195 200 public URL getContentBase() { 201 final String contentBase = getConfigProperty(Parser.CONTENTBASE_KEY); 202 if (contentBase == null) { 203 return null; 204 } 205 try { 206 return new URL (contentBase); 207 } 208 catch (MalformedURLException mfe) { 209 throw new IllegalStateException ("Content Base is illegal." + contentBase); 210 } 211 } 212 213 public Object clone () throws CloneNotSupportedException  214 { 215 final FrontendDefaultHandler o = (FrontendDefaultHandler) super.clone(); 216 o.parserConfiguration = (DefaultConfiguration) parserConfiguration.clone(); 217 return o; 218 } 219 } 220
| Popular Tags
|