1 16 package org.outerj.daisy.frontend; 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.avalon.framework.parameters.Parameters; 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.Attributes ; 24 import org.xml.sax.helpers.AttributesImpl ; 25 import org.outerj.daisy.util.Constants; 26 27 import java.util.Map ; 28 import java.io.IOException ; 29 30 39 public class IDAbsolutizerTransformer extends AbstractTransformer { 40 private boolean inPart; 41 private long documentId; 42 43 public void setup(SourceResolver sourceResolver, Map map, String s, Parameters parameters) throws ProcessingException, SAXException , IOException { 44 this.inPart = false; 45 } 46 47 public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { 48 if (namespaceURI.equals(Constants.DAISY_NAMESPACE)) { 49 if (localName.equals("part")) { 50 inPart = true; 51 } else if (localName.equals("document")) { 52 documentId = Long.parseLong(attributes.getValue("id")); 53 } 54 } 55 56 int index; 57 if (inPart && namespaceURI.equals("") && (index = attributes.getIndex("id")) != -1) { 58 AttributesImpl newAttrs = new AttributesImpl (attributes); 59 String id = newAttrs.getValue(index); 60 newAttrs.setValue(index, "dsy" + documentId + "_" + id); 61 attributes = newAttrs; 62 } 63 64 super.startElement(namespaceURI, localName, qName, attributes); 65 } 66 67 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 68 if (namespaceURI.equals(Constants.DAISY_NAMESPACE) && localName.equals("part")) { 69 inPart = false; 70 } 71 super.endElement(namespaceURI, localName, qName); 72 } 73 } 74 | Popular Tags |