forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r356383 - in /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher: ContractBean.java ContractBeanInterface.java transformation/DispatcherTransformer.java
Date Mon, 12 Dec 2005 21:29:11 GMT
Author: thorsten
Date: Mon Dec 12 13:28:59 2005
New Revision: 356383

URL: http://svn.apache.org/viewcvs?rev=356383&view=rev
Log:
Extracted contractBean interface and enhanced error handling

Added:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java
  (with props)
Modified:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBean.java
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBean.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBean.java?rev=356383&r1=356382&r2=356383&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBean.java
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBean.java
Mon Dec 12 13:28:59 2005
@@ -17,6 +17,7 @@
 package org.apache.forrest.dispatcher;
 
 import java.beans.Beans;
+import java.util.HashMap;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
@@ -30,6 +31,7 @@
 
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.forrest.dispatcher.lenya.xml.NamespaceHelper;
+import org.apache.forrest.dispatcher.transformation.DispatcherTransformer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -39,72 +41,7 @@
  * @author thorsten
  * 
  */
-public class ContractBean extends Beans {
-
-    /**
-     * The resolver prefix
-     */
-    public static final String CONTRACT_RESOLVE_PREFIX = "cocoon://resolve.contract";
-
-    /**
-     * <code>forrest:contract</code> element is used to include extra content
-     * and/or functionality.
-     * 
-     * <p>
-     * extra functionality requested from a uri via CONTRACT_NUGGET_ATTRIBUTE
-     * attribute - example:
-     * </p>
-     * 
-     * <pre>
-     *  &lt;forrest:contract name=&quot;nav-section&quot; dataURI=&quot;cocoon://index.navigation.xml&quot;/&gt;
-     * </pre>
-     */
-    public static final String CONTRACT_ELEMENT = "contract";
-
-    /**
-     * Each contract can contact external/internal business services to get the
-     * data model. The attribute "CONTRACT_NUGGET_ATTRIBUTE" is the identifier
-     * for the uri of the business data
-     */
-    public static final String CONTRACT_NUGGET_ATTRIBUTE = "dataURI";
-
-    /**
-     * Each contract must have an unique identifier. The attribute
-     * "CONTRACT_ID_ATTRIBUTE" stands for this id
-     */
-    public static final String CONTRACT_ID_ATTRIBUTE = "name";
-
-    /**
-     * Each contract implementation needs to define the input format for the
-     * transformation. ATM we only support xsl. The attribute
-     * "CONTRACT_IMPL_INPUT_FORMAT_ATTRIBUTE" defines the input format for
-     * transformation
-     */
-    public static final String CONTRACT_IMPL_INPUT_FORMAT_ATTRIBUTE = "inputFormat";
-
-    /**
-     * Each contract implementation needs to store the input format within a
-     * root element
-     */
-    public static final String CONTRACT_IMPL_ROOT_ELEMENT = "forrest:template";
-    
-    /**
-     * Each contract can have properties, which are definite e.g. in the
-     * structurer index.fv and used in the contract.
-     * 
-     * <pre>
-     *  &lt;forrest:contract name=&quot;nav-main-testing&quot; nugget=&quot;cocoon://index.navigation.xml&quot;&gt;
-     *   &lt;forrest:property name=&quot;nav-main-testing-test1&quot; &gt;Just
a test&lt;/forrest:property&gt;
-     *  &lt;/forrest:contract&gt;
-     * </pre>
-     */
-    public static final String PROPERTY_ELEMENT = "property";
-    
-    /**
-     * Each property must have an unique identifier. The attribute
-     * "PROPERTY_ID_ATTRIBUTE" stands for this id
-     */
-    static public final String PROPERTY_ID_ATTRIBUTE = "name";
+public class ContractBean extends Beans implements ContractBeanInterface {
 
     private Element[] propertyList;
 
@@ -170,6 +107,8 @@
 
     protected ServiceManager manager;
 
+    private HashMap parameterHelper;
+
     /**
      * The ContractBean contains all fields to work with contracts. It is a
      * helper bean.
@@ -180,16 +119,20 @@
      * information to the transfomer.
      * 
      * @param manager
+     * @param parameterHelper
      * @throws ParserConfigurationException
      */
-    public ContractBean(ServiceManager manager)
+    public ContractBean(ServiceManager manager, HashMap parameterHelper)
             throws ParserConfigurationException {
         this.manager = manager;
         dispatcherHelper = new DispatcherHelper(manager);
+        this.parameterHelper = parameterHelper;
     }
 
-    /**
-     * Recycle the component
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#recycle()
      */
     public void recycle() {
         this.contractDescription = null;
@@ -207,24 +150,19 @@
         this.propertyList = null;
     }
 
-    /**
-     * initialize the contract (normally done after recycle) Do not use to
-     * create a new instance!!!
+    /*
+     * (non-Javadoc)
      * 
-     * @throws ParserConfigurationException
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#initialize()
      */
     public void initialize() throws ParserConfigurationException {
         dispatcherHelper = new DispatcherHelper(this.manager);
     }
 
-    /**
-     * setContractImpl(String contractUri)
-     * 
-     * This method invokes the setting of the actual contract implementation via
-     * an URI.
+    /*
+     * (non-Javadoc)
      * 
-     * @param contractUri
-     * @throws Exception
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractImpl(java.lang.String)
      */
     public void setContractImpl(String contractUri) throws Exception {
         Document _contractImpl = dispatcherHelper.getDocument(contractUri);
@@ -232,14 +170,10 @@
         contractImplHelper(this.contractImpl);
     }
 
-    /**
-     * setContractImpl(Document _contractImpl)
-     * 
-     * This method invokes the setting of the actual contract implementation via
-     * a document.
+    /*
+     * (non-Javadoc)
      * 
-     * @param contractUri
-     * @throws Exception
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractImpl(org.w3c.dom.Document)
      */
     public void setContractImpl(Document _contractImpl) throws Exception {
         this.contractImpl = _contractImpl;
@@ -274,8 +208,8 @@
                     .getAttribute(CONTRACT_IMPL_INPUT_FORMAT_ATTRIBUTE);
             if ("".equals(format) | format == null) {
                 throw new DispatcherException(DispatcherException.ERROR_500
-                        + "\n" + "component: ContractBean" + "\n"
-                        + "message: inputFormat cannot be null");
+                        + "\n" + "component: ContractBean" + "\n" + "message:"
+                        + "\n" + "inputFormat cannot be null");
             } else if ("xsl".equals(format)) {
                 NodeList list_transformer = _contractImpl
                         .getElementsByTagName("xsl:stylesheet");
@@ -292,13 +226,24 @@
                                         + "\n"
                                         + "component: ContractBean"
                                         + "\n"
-                                        + "message: Could not setup transformer in the contractBean."
+                                        + "message:"
+                                        + "\n"
+                                        + "Could not setup transformer in the contractBean."
+                                        + "\n"
+                                        + "Please check that the contract implementation
is wellformed and valid!"
                                         + "\n"
-                                        + "Please check that the contract implementation
is wellformed and valid");
-                    /*
-                     * FIXME: Set default properties
+                                        + "\n"
+                                        + "One reason that an implementation may not be valid
is that you are using variables that cannot be resolved."
+                                        + "\n"
+                                        + "Please see the logs and the sysout for more information,
you may are see right away the error.");
+                    /**
+                     * Set default properties
                      */
-                    // transformer.setParameter()
+                    // default forrest properties
+                    Node defaultVariables = org.apache.forrest.dispatcher.util.SourceUtil.readDOM(
+                            "cocoon://test-props", this.manager);
+                    transformer.setParameter("defaultVariables",
+                            defaultVariables);
                     transformer.setOutputProperty(
                             OutputKeys.OMIT_XML_DECLARATION, "yes");
                     transformer.setOutputProperty(OutputKeys.INDENT, "yes");
@@ -307,12 +252,13 @@
                 }
             } else {
                 throw new DispatcherException(DispatcherException.ERROR_404
-                        + "\n" + "component: ContractBean" + "\n"
-                        + "message: inputFormat=\"" + format
+                        + "\n" + "component: ContractBean" + "\n" + "message:"
+                        + "\n" + "inputFormat=\"" + format
                         + "\" not implemented");
             }
         }
-        NodeList description = _contractImpl.getElementsByTagName("description");
+        NodeList description = _contractImpl
+                .getElementsByTagName("description");
         if (description.getLength() == 1) {
             Element node = (Element) description.item(0);
             this.contractDescription = node;
@@ -324,22 +270,10 @@
         }
     }
 
-    /**
-     * The presentation model (contractRawData) has to be requested by the
-     * contract if it needs it. This is be done by setting the
-     * CONTRACT_NUGGET_ATTRIBUTE attribute in the structurer which then use this
-     * method to set the contractRawData.
-     * <p>
-     * Extra functionality requested from a uri via CONTRACT_NUGGET_ATTRIBUTE
-     * attribute - example:
-     * </p>
-     * 
-     * <pre>
-     * &lt;forrest:contract name=&quot;nav-section&quot; dataURI=&quot;cocoon://index.navigation.xml&quot;/&gt;
-     * </pre>
+    /*
+     * (non-Javadoc)
      * 
-     * @param nuggetUri
-     * @throws Exception
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setNuggetUri(java.lang.String)
      */
     public void setNuggetUri(String nuggetUri) throws Exception {
         this.nuggetUri = nuggetUri;
@@ -347,12 +281,10 @@
         this.contractRawData = rawData;
     }
 
-    /**
-     * This method invokes the transformation of the this.contractRawData with
-     * the this.contractTransformer (make sure you set them before). The result
-     * is set to this.contractResultData.
+    /*
+     * (non-Javadoc)
      * 
-     * @throws TransformerException
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractResultData()
      */
     public void setContractResultData() throws DispatcherException {
         if (this.getContractRawData() == null
@@ -362,7 +294,9 @@
                             + "\n"
                             + "component: ContractBean"
                             + "\n"
-                            + "message: Could not transform the result data in contractBean."
+                            + "message:"
+                            + "\n"
+                            + "Could not transform the result data in contractBean."
                             + "\n"
                             + "You need to invoke first the transfomer and the rawData.");
         } else {
@@ -376,7 +310,9 @@
                                 + "\n"
                                 + "component: ContractBean"
                                 + "\n"
-                                + "message: Could not transform the result data in contractBean."
+                                + "message:"
+                                + "\n"
+                                + "Could not transform the result data in contractBean."
                                 + "\n"
                                 + "While trying to transform the raw data with the transformer,
following error was thrown:\n"
                                 + e);
@@ -388,82 +324,182 @@
     /*
      * Simple getter and setter methods
      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractName()
+     */
     public String getContractName() {
         return contractName;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractName(java.lang.String)
+     */
     public void setContractName(String contractName) {
         this.contractName = contractName;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#isHasProperties()
+     */
     public boolean isHasProperties() {
         return hasProperties;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setHasProperties(boolean)
+     */
     public void setHasProperties(boolean hasProperties) {
         this.hasProperties = hasProperties;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#isNugget()
+     */
     public boolean isNugget() {
         return isNugget;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setNugget(boolean)
+     */
     public void setNugget(boolean isNugget) {
         this.isNugget = isNugget;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getNuggetUri()
+     */
     public String getNuggetUri() {
         return nuggetUri;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractRawData()
+     */
     public Node getContractRawData() {
         return contractRawData;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractRawData(org.w3c.dom.Document)
+     */
     public void setContractRawData(Document contractRawData) {
         this.contractRawData = contractRawData;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractTransformer()
+     */
     public Transformer getContractTransformer() {
         return contractTransformer;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractTransformer(javax.xml.transform.Transformer)
+     */
     public void setContractTransformer(Transformer contractTransformer) {
         this.contractTransformer = contractTransformer;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractImpl()
+     */
     public Document getContractImpl() {
         return contractImpl;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractDescription()
+     */
     public Element getContractDescription() {
         return contractDescription;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractDescription(org.w3c.dom.Element)
+     */
     public void setContractDescription(Element contractDescription) {
         this.contractDescription = contractDescription;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractUsage()
+     */
     public Element getContractUsage() {
         return contractUsage;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractUsage(org.w3c.dom.Element)
+     */
     public void setContractUsage(Element contractUsage) {
         this.contractUsage = contractUsage;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getPropertyList()
+     */
     public Element[] getPropertyList() {
         return propertyList;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setPropertyList(org.w3c.dom.Element[])
+     */
     public void setPropertyList(Element[] propertyList) {
         this.propertyList = propertyList;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#getContractResultData()
+     */
     public DOMResult getContractResultData() {
         return contractResultData;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.forrest.dispatcher.ContractBeanInterface#setContractResultData(javax.xml.transform.dom.DOMResult)
+     */
     public void setContractResultData(DOMResult contractResultData) {
         this.contractResultData = contractResultData;
     }

Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java?rev=356383&view=auto
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java
(added)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java
Mon Dec 12 13:28:59 2005
@@ -0,0 +1,186 @@
+package org.apache.forrest.dispatcher;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public interface ContractBeanInterface {
+
+    /**
+     * The resolver prefix
+     */
+    public static final String CONTRACT_RESOLVE_PREFIX = "cocoon://resolve.contract";
+
+    /**
+     * <code>forrest:contract</code> element is used to include extra content
+     * and/or functionality.
+     * 
+     * <p>
+     * extra functionality requested from a uri via CONTRACT_NUGGET_ATTRIBUTE
+     * attribute - example:
+     * </p>
+     * 
+     * <pre>
+     *  &lt;forrest:contract name=&quot;nav-section&quot; dataURI=&quot;cocoon://index.navigation.xml&quot;/&gt;
+     * </pre>
+     */
+    public static final String CONTRACT_ELEMENT = "contract";
+
+    /**
+     * Each contract can contact external/internal business services to get the
+     * data model. The attribute "CONTRACT_NUGGET_ATTRIBUTE" is the identifier
+     * for the uri of the business data
+     */
+    public static final String CONTRACT_NUGGET_ATTRIBUTE = "dataURI";
+
+    /**
+     * Each contract must have an unique identifier. The attribute
+     * "CONTRACT_ID_ATTRIBUTE" stands for this id
+     */
+    public static final String CONTRACT_ID_ATTRIBUTE = "name";
+
+    /**
+     * Each contract implementation needs to define the input format for the
+     * transformation. ATM we only support xsl. The attribute
+     * "CONTRACT_IMPL_INPUT_FORMAT_ATTRIBUTE" defines the input format for
+     * transformation
+     */
+    public static final String CONTRACT_IMPL_INPUT_FORMAT_ATTRIBUTE = "inputFormat";
+
+    /**
+     * Each contract implementation needs to store the input format within a
+     * root element
+     */
+    public static final String CONTRACT_IMPL_ROOT_ELEMENT = "forrest:template";
+
+    /**
+     * Each contract can have properties, which are definite e.g. in the
+     * structurer index.fv and used in the contract.
+     * 
+     * <pre>
+     *  &lt;forrest:contract name=&quot;nav-main-testing&quot; nugget=&quot;cocoon://index.navigation.xml&quot;&gt;
+     *   &lt;forrest:property name=&quot;nav-main-testing-test1&quot; &gt;Just
a test&lt;/forrest:property&gt;
+     *  &lt;/forrest:contract&gt;
+     * </pre>
+     */
+    public static final String PROPERTY_ELEMENT = "property";
+
+    /**
+     * Each property must have an unique identifier. The attribute
+     * "PROPERTY_ID_ATTRIBUTE" stands for this id
+     */
+    static public final String PROPERTY_ID_ATTRIBUTE = "name";
+
+    /**
+     * Recycle the component
+     */
+    public abstract void recycle();
+
+    /**
+     * initialize the contract (normally done after recycle) Do not use to
+     * create a new instance!!!
+     * 
+     * @throws ParserConfigurationException
+     */
+    public abstract void initialize() throws ParserConfigurationException;
+
+    /**
+     * setContractImpl(String contractUri)
+     * 
+     * This method invokes the setting of the actual contract implementation via
+     * an URI.
+     * 
+     * @param contractUri
+     * @throws Exception
+     */
+    public abstract void setContractImpl(String contractUri) throws Exception;
+
+    /**
+     * setContractImpl(Document _contractImpl)
+     * 
+     * This method invokes the setting of the actual contract implementation via
+     * a document.
+     * 
+     * @param contractUri
+     * @throws Exception
+     */
+    public abstract void setContractImpl(Document _contractImpl)
+            throws Exception;
+
+    /**
+     * The presentation model (contractRawData) has to be requested by the
+     * contract if it needs it. This is be done by setting the
+     * CONTRACT_NUGGET_ATTRIBUTE attribute in the structurer which then use this
+     * method to set the contractRawData.
+     * <p>
+     * Extra functionality requested from a uri via CONTRACT_NUGGET_ATTRIBUTE
+     * attribute - example:
+     * </p>
+     * 
+     * <pre>
+     * &lt;forrest:contract name=&quot;nav-section&quot; dataURI=&quot;cocoon://index.navigation.xml&quot;/&gt;
+     * </pre>
+     * 
+     * @param nuggetUri
+     * @throws Exception
+     */
+    public abstract void setNuggetUri(String nuggetUri) throws Exception;
+
+    /**
+     * This method invokes the transformation of the this.contractRawData with
+     * the this.contractTransformer (make sure you set them before). The result
+     * is set to this.contractResultData.
+     * 
+     * @throws TransformerException
+     */
+    public abstract void setContractResultData() throws DispatcherException;
+
+    /*
+     * Getter and setter methods
+     */
+    public abstract String getContractName();
+
+    public abstract void setContractName(String contractName);
+
+    public abstract boolean isHasProperties();
+
+    public abstract void setHasProperties(boolean hasProperties);
+
+    public abstract boolean isNugget();
+
+    public abstract void setNugget(boolean isNugget);
+
+    public abstract String getNuggetUri();
+
+    public abstract Node getContractRawData();
+
+    public abstract void setContractRawData(Document contractRawData);
+
+    public abstract Transformer getContractTransformer();
+
+    public abstract void setContractTransformer(Transformer contractTransformer);
+
+    public abstract Document getContractImpl();
+
+    public abstract Element getContractDescription();
+
+    public abstract void setContractDescription(Element contractDescription);
+
+    public abstract Element getContractUsage();
+
+    public abstract void setContractUsage(Element contractUsage);
+
+    public abstract Element[] getPropertyList();
+
+    public abstract void setPropertyList(Element[] propertyList);
+
+    public abstract DOMResult getContractResultData();
+
+    public abstract void setContractResultData(DOMResult contractResultData);
+
+}
\ No newline at end of file

Propchange: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/ContractBeanInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=356383&r1=356382&r2=356383&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Mon Dec 12 13:28:59 2005
@@ -24,7 +24,6 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 
@@ -43,6 +42,7 @@
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.xml.xpath.XPathProcessor;
 import org.apache.forrest.dispatcher.ContractBean;
+import org.apache.forrest.dispatcher.ContractBeanInterface;
 import org.apache.forrest.dispatcher.DispatcherException;
 import org.apache.forrest.dispatcher.DispatcherHelper;
 import org.apache.forrest.dispatcher.lenya.xml.NamespaceHelper;
@@ -137,7 +137,7 @@
 
     protected String currentFormat;
 
-    protected ContractBean contract;
+    protected ContractBeanInterface contract;
 
     /**
      * The namespace used by the transformer for the SAX events filtering. This
@@ -179,8 +179,10 @@
 
     private String hooksXSL;
 
-    public static final String HOOKS_TRANSFORMER_PARAMETER = "hooksTransformer";
+    private HashMap parameterHelper;
 
+    public static final String HOOKS_TRANSFORMER_PARAMETER = "hooksTransformer";
+    public static final String PATH_PARAMETER = "path";
     /**
      * Constructor Set the namespace
      */
@@ -257,6 +259,7 @@
             throw new ProcessingException(error);
         }
         storedPrefixMap = new HashMap();
+        this.parameterHelper= new HashMap();
 
         this.allowMarkup = Boolean.getBoolean(parameters.getParameter(
                 DISPATCHER_ALLOW_MARKUP, null));
@@ -268,6 +271,15 @@
             getLogger().error(error);
             throw new ProcessingException(error);
         }
+        parameterHelper.put(STRUCTURER_FORMAT_ATTRIBUTE,requestedFormat);
+        /*this.pathXSL = parameters.getParameter(PATH_PARAMETER,null);
+        if (this.pathXSL==null){
+            String warning = "dispatcherError:\n"
+                + "You did not set up the \"path\" parameter in the sitemap, we are not going
to support default variables in contracts."
+                + " Meaning that you are not able to use e.g. $skin-img-dir, if you do the
contract bean implementation will throw an exception.";
+        getLogger().warn(warning);
+        }
+        parameterHelper.put(PATH_PARAMETER,pathXSL);*/
         this.hooksXSL = parameters.getParameter(HOOKS_TRANSFORMER_PARAMETER,
                 null);
         try {
@@ -282,6 +294,7 @@
                 this.structurerTransformer = dispatcherHelper
                         .createTransformer(stylesheet);
             }
+            parameterHelper.put(HOOKS_TRANSFORMER_PARAMETER,hooksXSL);
         } catch (Exception e) {
             String error = "dispatcherError:\n"
                     + "Could not set up the \"hooks transformer\".\n\n DispatcherStack:\n
"
@@ -332,10 +345,10 @@
                 structurerProcessingStart(attr);
             else if (DISPATCHER_HOOK_ELEMENT.equals(name) & this.includeNodes)
                 hookProcessingStart(name, raw, attr);
-            else if (ContractBean.CONTRACT_ELEMENT.equals(name)
+            else if (ContractBeanInterface.CONTRACT_ELEMENT.equals(name)
                     & this.includeNodes)
                 contractProcessingStart(attr);
-            else if (ContractBean.PROPERTY_ELEMENT.equals(name)
+            else if (ContractBeanInterface.PROPERTY_ELEMENT.equals(name)
                     & this.includeNodes) {
                 this.insideProperties = true;
                 propertyProcessingStart(uri, name, raw, attr);
@@ -428,7 +441,7 @@
         } else if (DispatcherHelper.DISPATCHER_NAMESPACE_URI.equals(uri)) {
             if (STRUCTURER_ELEMENT.equals(name))
                 structurerProcessingEnd(raw);
-            else if (ContractBean.CONTRACT_ELEMENT.equals(name)
+            else if (ContractBeanInterface.CONTRACT_ELEMENT.equals(name)
                     & this.includeNodes)
                 contractProcessingEnd();
             else if (DISPATCHER_HOOK_ELEMENT.equals(name) & this.includeNodes)
@@ -562,7 +575,7 @@
     private void contractProcessingStart(Attributes attr) throws SAXException {
         try {
             if (contract == null)
-                contract = new ContractBean(this.manager);
+                contract = new ContractBean(this.manager,parameterHelper);
             else
                 contract.initialize();
         } catch (ParserConfigurationException e) {
@@ -576,10 +589,10 @@
         for (int i = 0; i < attr.getLength(); i++) {
             String localName = attr.getLocalName(i);
             String value = attr.getValue(i);
-            if (ContractBean.CONTRACT_ID_ATTRIBUTE.equals(localName)) {
+            if (ContractBeanInterface.CONTRACT_ID_ATTRIBUTE.equals(localName)) {
                 // getting the contract name
                 contract.setContractName(value);
-                String contractUri = ContractBean.CONTRACT_RESOLVE_PREFIX + "."
+                String contractUri = ContractBeanInterface.CONTRACT_RESOLVE_PREFIX + "."
                         + currentFormat + "." + value;
                 try {
                     Document doc = org.apache.forrest.dispatcher.util.SourceUtil
@@ -604,7 +617,7 @@
                                     + localName + "\n" + "value" + "-->"
                                     + value);
                 }
-            } else if (ContractBean.CONTRACT_NUGGET_ATTRIBUTE.equals(localName)) {
+            } else if (ContractBeanInterface.CONTRACT_NUGGET_ATTRIBUTE.equals(localName))
{
                 // contract is a nugget-contract
                 contract.setNugget(true);
                 try {
@@ -771,14 +784,14 @@
         for (int i = 0; i < attr.getLength(); i++) {
             String localName = attr.getLocalName(i);
             String value = attr.getValue(i);
-            if (ContractBean.PROPERTY_ID_ATTRIBUTE.equals(localName))
+            if (ContractBeanInterface.PROPERTY_ID_ATTRIBUTE.equals(localName))
                 this.propertyID = value;
         }
         if (this.propertyID.equals("") | this.propertyID == null) {
             String error = "dispatcherError: " + DispatcherException.ERROR_500
                     + "\n" + "The contract \"" + contract.getContractName()
                     + "\" has no identifier attribute \""
-                    + ContractBean.PROPERTY_ID_ATTRIBUTE + "\" in the " + raw;
+                    + ContractBeanInterface.PROPERTY_ID_ATTRIBUTE + "\" in the " + raw;
             getLogger().error(error);
             throw new SAXException(error);
         }
@@ -796,7 +809,7 @@
      */
     private void propertyProcessingEnd(String uri, String name, String raw)
             throws SAXException {
-        if (ContractBean.PROPERTY_ELEMENT.equals(name)) {
+        if (ContractBeanInterface.PROPERTY_ELEMENT.equals(name)) {
             this.insideProperties = false;
             if (this.includeNodes) {
                 this.builder.endElement(uri, name, raw);



Mime
View raw message