forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r808392 - in /forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src: cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/ java/org/apache/forrest/dispatcher/config/ java/org/apache/forrest/disp...
Date Thu, 27 Aug 2009 12:13:45 GMT
Author: thorsten
Date: Thu Aug 27 12:13:44 2009
New Revision: 808392

URL: http://svn.apache.org/viewvc?rev=808392&view=rev
Log:
Dispatcher has thrown an error when the dataUri from a contract had a DTD declaration. Using
the cocoon entity resolver and injecting in the xmlReader. Using then this reader instead
the 'normal' parser

Modified:
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/dispatcher-context.xml
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/DispatcherBean.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/WritableDispatcherBean.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/dispatcher-context.xml
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/dispatcher-context.xml?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/dispatcher-context.xml
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/cocoon-2.2-block/src/main/resources/META-INF/cocoon/spring/dispatcher-context.xml
Thu Aug 27 12:13:44 2009
@@ -51,6 +51,8 @@
     <property name="contractUriSufix" value="" />
     <property name="contractUriPrefix" value="cocoon://resolve.contract." />
     <property name="staxHelper" ref="staxHelper" />
+    <property name="entityResolver" 
+      ref="org.xml.sax.EntityResolver" />
   </bean>
   <bean id="staxHelper"
   class="org.apache.forrest.dispatcher.impl.helper.StAX" />

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/DispatcherBean.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/DispatcherBean.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/DispatcherBean.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/DispatcherBean.java
Thu Aug 27 12:13:44 2009
@@ -20,6 +20,7 @@
 
 import org.apache.forrest.dispatcher.api.Resolver;
 import org.apache.forrest.dispatcher.impl.helper.StAX;
+import org.xml.sax.EntityResolver;
 
 /**
  * The dispatcherBean is holding all configuration information that are needed
@@ -84,6 +85,12 @@
   public Resolver getResolver() {
     return resolver;
   }
+  
+  protected EntityResolver entityResolver;
+
+  public EntityResolver getEntityResolver() {
+    return entityResolver;
+  }
 
   protected String contractUriPrefix = "";
 

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/WritableDispatcherBean.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/WritableDispatcherBean.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/WritableDispatcherBean.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/config/WritableDispatcherBean.java
Thu Aug 27 12:13:44 2009
@@ -20,8 +20,10 @@
 
 import org.apache.forrest.dispatcher.api.Resolver;
 import org.apache.forrest.dispatcher.impl.helper.StAX;
+import org.xml.sax.EntityResolver;
 
 public class WritableDispatcherBean extends DispatcherBean {
+
   /**
    * If you use properties like
    * <code>&lt;forrest:property name="theme" value="pelt"/></code>
@@ -113,4 +115,8 @@
     this.transFact = transFact;
   }
 
+  public void setEntityResolver(EntityResolver entityResolver) {
+    this.entityResolver = entityResolver;
+  }
+
 }

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
Thu Aug 27 12:13:44 2009
@@ -79,7 +79,7 @@
        * we already have set this up?
        */
       if (dummyContract == null){
-        dummyContract = new XSLContract(config.isAllowXmlProperties(),config.getTransFact());
+        dummyContract = new XSLContract(config.isAllowXmlProperties(),config.getTransFact(),config.getEntityResolver());
       }
       contract = dummyContract;
       /*

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
Thu Aug 27 12:13:44 2009
@@ -34,6 +34,7 @@
 import org.apache.forrest.dispatcher.exception.ContractException;
 import org.apache.forrest.dispatcher.impl.helper.Loggable;
 import org.apache.forrest.dispatcher.impl.helper.XSLContractHelper;
+import org.xml.sax.EntityResolver;
 
 public class XSLContract extends Loggable implements Contract {
 
@@ -52,16 +53,17 @@
    * @param allowXmlProperties are we allowing xml based properties. This are the ones where
you 
    * have you own set of xml within the <code>&lt;forrest:property></code>
element.
    * @param transformerFactory the transformer factory that we should use
+   * @param entityResolver 
    * @throws ContractException
    */
-  public XSLContract(boolean allowXmlProperties, TransformerFactory transformerFactory) throws
ContractException {
+  public XSLContract(boolean allowXmlProperties, TransformerFactory transformerFactory, EntityResolver
entityResolver) throws ContractException {
     this.allowXmlProperties = allowXmlProperties;
     /*
      * get a new instance of the corresponding helper class since the helper is
      * doing the actual work
      */
     try {
-      helper = new XSLContractHelper(transformerFactory);
+      helper = new XSLContractHelper(transformerFactory,entityResolver);
     } catch (Exception e) {
       throw new ContractException(e);
     }

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
Thu Aug 27 12:13:44 2009
@@ -36,14 +36,19 @@
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.forrest.dispatcher.exception.ContractException;
 import org.apache.forrest.dispatcher.impl.XSLContract;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 public class XSLContractHelper extends Loggable {
 
@@ -54,6 +59,7 @@
   private String name;
   private ContractHandler handler;
   private LoggingErrorListener listener;
+  private XMLReader xmlReader;
 
   /**
    * @return the name of the contract
@@ -80,7 +86,7 @@
    * @throws SAXNotSupportedException 
    * @throws SAXNotRecognizedException 
    */
-  public XSLContractHelper(TransformerFactory transformerFactory)
+  public XSLContractHelper(TransformerFactory transformerFactory, EntityResolver entityResolver)
       throws ContractException, SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException
{
     this.transFact = transformerFactory;
     SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -91,8 +97,9 @@
     listener = new LoggingErrorListener(log);
     try {
       parser = factory.newSAXParser();
-      builder = DocumentBuilderFactory.newInstance()
-      .newDocumentBuilder();
+      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+      xmlReader=XMLReaderFactory.createXMLReader();
+      xmlReader.setEntityResolver(entityResolver);
     } catch (Exception e) {
       throw new ContractException(e);
     }
@@ -245,9 +252,10 @@
    */
   public void transform(InputStream dataStream, Result streamResult)
       throws ContractException {
-    Source dataSource = new StreamSource(dataStream);
+    //Source dataSource = new StreamSource(dataStream);
     try {
-      transformer.transform(dataSource, streamResult);
+      SAXSource saxSource = new SAXSource(xmlReader,new InputSource(dataStream));
+      transformer.transform(saxSource, streamResult);
     } catch (Exception e) {
       String message = "The xsl transformation has thrown an exception. for "
             + "the contract \""+name+"\".\nPlease see some FAQ:"

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=808392&r1=808391&r2=808392&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Thu Aug 27 12:13:44 2009
@@ -77,6 +77,7 @@
 import org.apache.forrest.dispatcher.impl.helper.XMLProperties;
 import org.jaxen.JaxenException;
 import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -169,7 +170,7 @@
   public void setManager(ServiceManager manager) {
     this.manager = manager;
   }
-
+  
   /**
    * The level of xpath support we need.
    * <p>
@@ -242,7 +243,9 @@
 
   private String prefixString;
   
-  private TransformerFactory tfactory = TransformerFactory.newInstance(); 
+  private TransformerFactory tfactory = TransformerFactory.newInstance();
+
+  private EntityResolver entityResolver; 
 
   /*
    * @see
@@ -269,6 +272,7 @@
     // Do we want to shrink xml properties that have only a @value?
     boolean shrink = configuration.getChild("shrink").getValueAsBoolean(true);
     config.setShrink(shrink);
+    config.setEntityResolver(this.entityResolver);
     // request all factories to be created at this point since it is better to
     // create them only once
     try {
@@ -946,6 +950,7 @@
    */
   public void service(ServiceManager manager) throws ServiceException {
     super.service(manager);
+    this.entityResolver = (EntityResolver) this.manager.lookup(org.apache.excalibur.xml.EntityResolver.ROLE);
   }
 
   /**



Mime
View raw message