1 16 package org.apache.cocoon.transformation; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.component.ComponentManager; 20 import org.apache.avalon.framework.component.Composable; 21 import org.apache.avalon.framework.parameters.Parameters; 22 23 import org.apache.avalon.excalibur.pool.Recyclable; 24 25 import org.apache.cocoon.ProcessingException; 26 import org.apache.cocoon.environment.SourceResolver; 27 import org.apache.cocoon.xml.dom.DOMBuilder; 28 import org.apache.cocoon.xml.dom.DOMStreamer; 29 30 import org.w3c.dom.Document ; 31 import org.xml.sax.SAXException ; 32 import org.xml.sax.Locator ; 33 import org.xml.sax.Attributes ; 34 35 import java.io.IOException ; 36 import java.util.Map ; 37 38 50 public abstract class AbstractDOMTransformer extends AbstractTransformer 51 implements Transformer, DOMBuilder.Listener, Composable, Disposable, Recyclable { 52 53 56 protected SourceResolver resolver; 57 58 61 protected Map objectModel; 62 63 66 protected String source; 67 68 71 protected Parameters parameters; 72 73 76 protected ComponentManager manager; 77 78 82 protected DOMBuilder builder; 83 84 85 public AbstractDOMTransformer() { 86 super(); 87 this.builder = new DOMBuilder(this); 88 } 89 90 93 public void compose(ComponentManager manager) { 94 this.manager = manager; 95 } 96 97 104 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) 105 throws ProcessingException, SAXException , IOException { 106 107 this.resolver = resolver; 108 this.objectModel = objectModel; 109 this.source = src; 110 this.parameters = par; 111 } 112 113 116 public void recycle() { 117 this.resolver = null; 118 this.source = null; 119 this.objectModel = null; 120 this.parameters = null; 121 this.builder.recycle(); 122 } 123 124 127 public void dispose() { 128 this.builder = null; 129 this.manager = null; 130 } 131 132 137 public void notify(Document doc) throws SAXException { 138 Document newdoc = transform(doc); 140 141 DOMStreamer s = new DOMStreamer(contentHandler, lexicalHandler); 143 s.stream(newdoc); 144 } 145 146 151 protected abstract Document transform(Document doc); 152 153 154 158 public void setDocumentLocator(Locator locator) { 159 builder.setDocumentLocator(locator); 160 } 161 162 public void startDocument() throws SAXException { 163 builder.startDocument(); 164 } 165 166 public void endDocument() throws SAXException { 167 builder.endDocument(); 168 } 169 170 public void startPrefixMapping(String prefix, String uri) throws SAXException { 171 builder.startPrefixMapping(prefix, uri); 172 } 173 174 public void endPrefixMapping(String prefix) throws SAXException { 175 builder.endPrefixMapping(prefix); 176 } 177 178 public void startElement(String uri, String loc, String raw, Attributes a) 179 throws SAXException { 180 builder.startElement(uri, loc, raw, a); 181 } 182 183 public void endElement(String uri, String loc, String raw) 184 throws SAXException { 185 builder.endElement(uri, loc, raw); 186 } 187 188 public void characters(char c[], int start, int len) 189 throws SAXException { 190 builder.characters(c, start, len); 191 } 192 193 public void ignorableWhitespace(char c[], int start, int len) 194 throws SAXException { 195 builder.ignorableWhitespace(c, start, len); 196 } 197 198 public void processingInstruction(String target, String data) 199 throws SAXException { 200 builder.processingInstruction(target, data); 201 } 202 203 public void skippedEntity(String name) 204 throws SAXException { 205 builder.skippedEntity(name); 206 } 207 208 public void startDTD(String name, String publicId, String systemId) 209 throws SAXException { 210 builder.startDTD(name, publicId, systemId); 211 } 212 213 public void endDTD() 214 throws SAXException { 215 builder.endDTD(); 216 } 217 218 public void startEntity(String name) 219 throws SAXException { 220 builder.startEntity(name); 221 } 222 223 public void endEntity(String name) 224 throws SAXException { 225 builder.endEntity(name); 226 } 227 228 public void startCDATA() 229 throws SAXException { 230 builder.startCDATA(); 231 } 232 233 public void endCDATA() 234 throws SAXException { 235 builder.endCDATA(); 236 } 237 238 public void comment(char ch[], int start, int len) 239 throws SAXException { 240 builder.comment(ch, start, len); 241 } 242 } 243 | Popular Tags |