1 16 package org.apache.cocoon.components.language.markup; 17 18 import org.apache.excalibur.xml.xslt.XSLTProcessor; 19 import org.apache.excalibur.xml.xslt.XSLTProcessorException; 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.avalon.framework.service.ServiceException; 22 import org.apache.avalon.framework.service.ServiceManager; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.components.source.SourceUtil; 25 import org.apache.excalibur.source.Source; 26 import org.apache.excalibur.source.SourceException; 27 import org.apache.excalibur.source.SourceResolver; 28 import org.xml.sax.SAXException ; 29 30 import javax.xml.transform.sax.TransformerHandler ; 31 32 import java.io.IOException ; 33 import java.net.MalformedURLException ; 34 import java.util.HashMap ; 35 import java.util.Map ; 36 37 50 public class Logicsheet extends AbstractLogEnabled 51 { 52 55 private SourceResolver resolver; 56 57 60 private String systemId; 61 62 65 protected Map namespaceURIs = new HashMap (); 66 67 70 private ServiceManager manager; 71 72 75 private LogicsheetFilter filter; 76 77 public Logicsheet(Source source, ServiceManager manager, 78 SourceResolver resolver, LogicsheetFilter filter) 79 throws SAXException , IOException , ProcessingException 80 { 81 this.resolver = resolver; 82 this.systemId = source.getURI(); 83 this.manager = manager; 84 this.filter = filter; 85 } 86 87 public Logicsheet(String systemId, ServiceManager manager, 88 SourceResolver resolver, LogicsheetFilter filter) 89 throws SAXException , IOException , SourceException, ProcessingException 90 { 91 this.resolver = resolver; 92 this.manager = manager; 93 this.filter = filter; 94 Source source = null; 95 try { 96 source = this.resolver.resolveURI( systemId ); 97 this.systemId = source.getURI(); 98 } finally { 99 this.resolver.release( source ); 100 } 101 } 102 103 106 public boolean equals(Object other) 107 { 108 if (other == this) 109 return true; 110 if (other == null) 111 return false; 112 if (!(other instanceof Logicsheet)) 113 return false; 114 Logicsheet that = (Logicsheet)other; 115 return this.systemId.equals(that.systemId); 116 } 117 118 121 public int hashCode() 122 { 123 return this.systemId.hashCode(); 124 } 125 126 129 public String getSystemId() 130 { 131 return this.systemId; 132 } 133 134 137 public Map getNamespaceURIs() throws ProcessingException 138 { 139 getTransformerHandler(); 142 return namespaceURIs; 143 } 144 145 151 public TransformerHandler getTransformerHandler() throws ProcessingException 152 { 153 XSLTProcessor xsltProcessor = null; 154 Source source = null; 155 try { 156 xsltProcessor = (XSLTProcessor)this.manager.lookup(XSLTProcessor.ROLE); 157 source = this.resolver.resolveURI( this.systemId ); 158 159 filter.setNamespaceMap(namespaceURIs); 164 return xsltProcessor.getTransformerHandler(source, filter); 165 166 } catch (ServiceException e) { 167 throw new ProcessingException("Could not obtain XSLT processor", e); 168 } catch (MalformedURLException e) { 169 throw new ProcessingException("Could not resolve " + this.systemId, e); 170 } catch (SourceException e) { 171 throw SourceUtil.handle("Could not resolve " + this.systemId, e); 172 } catch (IOException e) { 173 throw new ProcessingException("Could not resolve " + this.systemId, e); 174 } catch (XSLTProcessorException e) { 175 throw new ProcessingException("Could not transform " + this.systemId, e); 176 } finally { 177 this.manager.release(xsltProcessor); 178 this.resolver.release( source ); 180 } 181 } 182 } 183 | Popular Tags |