1 17 18 19 20 package org.apache.fop.render.ps.extensions; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.fop.util.ContentHandlerFactory; 25 import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; 26 import org.xml.sax.Attributes ; 27 import org.xml.sax.SAXException ; 28 import org.xml.sax.helpers.DefaultHandler ; 29 30 33 public class PSExtensionHandler extends DefaultHandler 34 implements ContentHandlerFactory.ObjectSource { 35 36 37 protected static Log log = LogFactory.getLog(PSExtensionHandler.class); 38 39 private StringBuffer content = new StringBuffer (); 40 private Attributes lastAttributes; 41 42 private PSSetupCode returnedObject; 43 private ObjectBuiltListener listener; 44 45 46 public void startElement(String uri, String localName, String qName, Attributes attributes) 47 throws SAXException { 48 boolean handled = false; 49 if (PSSetupCode.CATEGORY.equals(uri)) { 50 lastAttributes = attributes; 51 handled = true; 52 if ("ps-setup-code".equals(localName)) { 53 } else { 55 handled = false; 56 } 57 } 58 if (!handled) { 59 if (PSSetupCode.CATEGORY.equals(uri)) { 60 throw new SAXException ("Unhandled element " + localName 61 + " in namespace: " + uri); 62 } else { 63 log.warn("Unhandled element " + localName 64 + " in namespace: " + uri); 65 } 66 } 67 } 68 69 70 public void endElement(String uri, String localName, String qName) throws SAXException { 71 if (PSSetupCode.CATEGORY.equals(uri)) { 72 if ("ps-setup-code".equals(localName)) { 73 String name = lastAttributes.getValue("name"); 74 this.returnedObject = new PSSetupCode(name, content.toString()); 75 } 76 } 77 content.setLength(0); } 79 80 81 public void characters(char[] ch, int start, int length) throws SAXException { 82 content.append(ch, start, length); 83 } 84 85 88 public void endDocument() throws SAXException { 89 if (listener != null) { 90 listener.notifyObjectBuilt(getObject()); 91 } 92 } 93 94 97 public Object getObject() { 98 return returnedObject; 99 } 100 101 104 public void setObjectBuiltListener(ObjectBuiltListener listener) { 105 this.listener = listener; 106 } 107 108 } 109 | Popular Tags |