1 16 package org.outerj.daisy.books.publisher.impl.cocooncomponents; 17 18 import org.apache.cocoon.transformation.AbstractTransformer; 19 import org.apache.cocoon.environment.SourceResolver; 20 import org.apache.cocoon.ProcessingException; 21 import org.apache.cocoon.components.flow.FlowHelper; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.commons.jxpath.JXPathContext; 24 import org.xml.sax.SAXException ; 25 import org.xml.sax.Attributes ; 26 import org.outerj.daisy.books.publisher.impl.util.XMLPropertiesHelper; 27 28 import java.util.Map ; 29 import java.io.IOException ; 30 31 34 public class MergePropsAndMetadataTransformer extends AbstractTransformer { 35 private Map publicationProperties; 36 private Map bookMetadata; 37 private boolean rootElement; 38 39 public void setup(SourceResolver sourceResolver, Map objectModel, String string, Parameters parameters) throws ProcessingException, SAXException , IOException { 40 Object flowContext = FlowHelper.getContextObject(objectModel); 41 JXPathContext jxpc = JXPathContext.newContext(flowContext); 42 43 publicationProperties = (Map )jxpc.getValue("/pubProps"); 44 if (publicationProperties == null) 45 throw new ProcessingException("Missing 'pubProps' in flow context."); 46 47 bookMetadata = (Map )jxpc.getValue("/bookMetadata"); 48 if (bookMetadata == null) 49 throw new ProcessingException("Missing 'bookMetadata' in flow context."); 50 51 rootElement = true; 52 } 53 54 public void recycle() { 55 super.recycle(); 56 this.publicationProperties = null; 57 this.bookMetadata = null; 58 } 59 60 public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { 61 super.startElement(namespaceURI, localName, qName, attributes); 62 63 if (rootElement) { 64 XMLPropertiesHelper.generateSaxFragment(publicationProperties, contentHandler); 65 XMLPropertiesHelper.generateSaxFragment(bookMetadata, "metadata", contentHandler); 66 rootElement = false; 67 } 68 } 69 } 70 | Popular Tags |