svn commit: r693670 [3/6] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/cms/ac/ src/java/org/apache/lenya/cms/ac/usecase/ src/java/org/apache/lenya/cms/ac/workflow/ src/java/org/apache/lenya/cms/ant/ src/java/org/apache/lenya/cms/...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java Tue Sep  9 17:30:20 2008
@@ -15,7 +15,6 @@
  *
  */
 package org.apache.lenya.cms.cocoon.components.modules.input;
-
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
@@ -26,81 +25,76 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.components.modules.input.AbstractInputModule;
-import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.PublicationFactory;
-
+import org.apache.lenya.util.Globals;
 /**
  * Gets the content directory of a specific publication and specific area
  */
 public class PublicationContentDirModule extends AbstractInputModule implements Serviceable, Disposable {
-
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
-     */
-    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
-
-    	if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Resolving directory path for [" + name + "]");
-        }
-    	String[] pubidAndArea = name.split(",");
-        if (pubidAndArea.length < 2) {
-            throw new ConfigurationException("Invalid number of parameters: " + pubidAndArea.length
-                    + ". Expected pub, area.");
-        }
-           
-        String id = pubidAndArea[0];
-        String area = pubidAndArea[1];
-    	String contextPath = ObjectModelHelper.getContext(objectModel).getRealPath("");
-    	
-    	try {
-			Publication pub = PublicationFactory.getPublication(id, contextPath);
-			return pub.getContentDirectory(area);
-		} catch (PublicationException e) {
-            throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
-		}
-    	
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
-     */
-    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
-        return Collections.EMPTY_SET.iterator();
-    }
-
-    private ServiceManager manager;
-    private SourceResolver resolver;
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
-     */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-        this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
-    public void dispose() {
-        super.dispose();
-        this.manager.release(this.resolver);
-        this.resolver = null;
-        this.manager = null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
-     */
-    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
-        Object result = this.getAttribute(name, modeConf, objectModel);
-        return (result == null ? null : new Object[] {result});
-    }
-
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+    */
+   public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+      if(getLogger().isDebugEnabled()){
+         getLogger().debug("Resolving directory path for [" + name + "]");
+      }
+      String[] pubidAndArea = name.split(",");
+      if(pubidAndArea.length < 2){
+         throw new ConfigurationException("Invalid number of parameters: " + pubidAndArea.length + ". Expected pub, area.");
+      }
+      String id = pubidAndArea[0];
+      String area = pubidAndArea[1];
+      try{
+         Publication publication = Globals.getPublication(id);
+         if(null == publication){
+            throw new PublicationException("UsecaseAuthorizer.authorize: No Publication.");
+         }
+         return publication.getContentDirectory(area);
+      }catch(PublicationException e){
+         throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
+      }
+   }
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+    */
+   public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+      return Collections.EMPTY_SET.iterator();
+   }
+   private ServiceManager manager;
+   private SourceResolver resolver;
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+    */
+   public void service(ServiceManager manager) throws ServiceException {
+      this.manager = manager;
+      this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+   }
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.avalon.framework.activity.Disposable#dispose()
+    */
+   public void dispose() {
+      super.dispose();
+      this.manager.release(this.resolver);
+      this.resolver = null;
+      this.manager = null;
+   }
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+    */
+   public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+      Object result = this.getAttribute(name, modeConf, objectModel);
+      return(result == null ? null : new Object[]{result});
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java Tue Sep  9 17:30:20 2008
@@ -5,6 +5,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.PageEnvelopeException;
 import org.apache.lenya.cms.publication.Publication;
@@ -13,8 +14,9 @@
  * 
  * @author solprovider
  * @since 1.3
+ * @deprecated Use org.apache.lenya.cms.modules.PublicationInputModule.  Will be deleted soon.
  */
-public class PublicationModule extends AbstractPageEnvelopeModule implements ThreadSafe {
+public class PublicationModule extends AbstractInputModule implements ThreadSafe {
    // public class PublicationModule extends AbstractPageEnvelopeModule implements Serviceable, Contextualizable, ThreadSafe {
    // private ServiceManager manager;
    // private org.apache.avalon.framework.context.Context context;

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/Usecase2ModuleModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/Usecase2ModuleModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/Usecase2ModuleModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/Usecase2ModuleModule.java Tue Sep  9 17:30:20 2008
@@ -12,6 +12,7 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.PageEnvelopeException;
 /**
@@ -19,7 +20,7 @@
  * 
  * @author solprovider
  */
-public class Usecase2ModuleModule extends AbstractPageEnvelopeModule implements Serviceable, Contextualizable, ThreadSafe {
+public class Usecase2ModuleModule extends AbstractInputModule implements Serviceable, Contextualizable, ThreadSafe {
    private org.apache.avalon.framework.context.Context context;
    /**
     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java Tue Sep  9 17:30:20 2008
@@ -14,11 +14,8 @@
  * the License.
  *  
  */
-
 /* $Id:$ */
-
 package org.apache.lenya.cms.cocoon.generation;
-
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.Map;
@@ -34,179 +31,144 @@
 import org.apache.lenya.cms.publication.Label;
 import org.apache.lenya.cms.publication.LastModified;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.PublicationFactory;
 import org.apache.lenya.cms.publication.SiteTree;
 import org.apache.lenya.cms.publication.SiteTreeException;
 import org.apache.lenya.cms.publication.SiteTreeNode;
+import org.apache.lenya.util.Globals;
 import org.apache.log4j.Logger;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 import org.xml.sax.helpers.NamespaceSupport;
-
 /**
  * Site tree generator.
  * 
  * @version $Id:$
  */
-public class SiteTreeGenerator extends ServiceableGenerator implements Parameterizable,
-        CacheableProcessingComponent {
-    private static Logger log = Logger.getLogger(SiteTreeGenerator.class);
-
-    protected final static String I18N_PX = "i18n";
-    protected final static String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
-
-    protected final static String CDATA = "CDATA";
-
-    protected final static String SITE_ELEMENT = "site";
-    protected final static String NODE_ELEMENT = "node";
-    protected final static String LABEL_ELEMENT = "label";
-
-    protected final static String LABEL_ATTRIBUTE = "label";
-    protected final static String ATTR_ATTRIBUTE = "attr";
-    protected final static String Q_ATTR_ATTRIBUTE = I18N_PX + ":" + ATTR_ATTRIBUTE;
-    protected final static String ID_ATTRIBUTE = "id";
-    protected final static String LANG_ATTRIBUTE = "lang";
-    protected final static String HREF_ATTRIBUTE = "href";
-    protected final static String LINK_ATTRIBUTE = "link";
-    protected final static String VISIBLEINNAV_ATTRIBUTE = "visibleinnav";
-    protected final static String SUFFIX_ATTRIBUTE = "suffix";
-
-    protected final static String Q_LANG_ATTRIBUTE = "xml:lang";
-
-    /**
-     * The area of the site tree.
-     */
-    public final static String AREA_PARAMETER = "area";
-
-    private final AttributesImpl atts = new AttributesImpl();
-
-    SiteTree sitetree = null;
-    String area = null;
-
-    /**
-     * No parameters implemented.
-     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
-     */
-    public void parameterize(Parameters parameters) throws ParameterException {
-    }
-
-    /**
-     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
-     *      java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
-     */
-    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
-            throws ProcessingException, SAXException, IOException {
-        log.debug("setup");
-        try {
-            Publication publication = PublicationFactory.getPublication(objectModel);
-            area = par.getParameter(AREA_PARAMETER);
-            sitetree = publication.getTree(area);
-        } catch (PublicationException e) {
-            throw new ProcessingException("Unable to get sitetree: publication exception.", e);
-        } catch (ParameterException e) {
-            throw new ProcessingException("Unable to get sitetree: parameter 'area' not found.", e);
-        } catch (SiteTreeException e) {
-            throw new ProcessingException("Unable to get sitetree.", e);
-        }
-    }
-
-    /**
-     * @see org.apache.cocoon.generation.Generator#generate()
-     */
-    public void generate() throws SAXException {
-        log.debug("generate");
-        // Start the document and set the namespace.
-        this.contentHandler.startDocument();
-        // Default namespace.
-        this.contentHandler.startPrefixMapping("", SiteTree.NAMESPACE_URI);
-        this.contentHandler.startPrefixMapping(I18N_PX, I18N_NS);
-
-        generateSiteTree(sitetree);
-
-        // End the document.
-        this.contentHandler.endPrefixMapping("");
-        this.contentHandler.endDocument();
-    }
-
-    private void generateSiteTree(SiteTree tree) throws SAXException {
-        atts.clear();
-        // TODO: Do not hardcode "Authoring" label!!!
-        atts.addAttribute("", LABEL_ATTRIBUTE, LABEL_ATTRIBUTE, CDATA, "Authoring");
-        atts.addAttribute(I18N_NS, ATTR_ATTRIBUTE, Q_ATTR_ATTRIBUTE, CDATA, "label");
-
-        this.contentHandler.startElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT, atts);
-
-        SiteTreeNode[] topNodes = tree.getTopNodes();
-        for (int i = 0; i < topNodes.length; i++) {
-            generateNodes(topNodes[i]);
-        }
-
-        this.contentHandler.endElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT);
-    }
-
-    private void generateNodes(SiteTreeNode node) throws SAXException {
-        atts.clear();
-        atts.addAttribute("", ID_ATTRIBUTE, ID_ATTRIBUTE, CDATA, node.getId());
-        if (node.getHref() != null)
-            atts.addAttribute("", HREF_ATTRIBUTE, HREF_ATTRIBUTE, CDATA, node.getHref());
-        if (node.getSuffix() != null)
-            atts.addAttribute("", SUFFIX_ATTRIBUTE, SUFFIX_ATTRIBUTE, CDATA, node.getSuffix());
-        atts.addAttribute("", LINK_ATTRIBUTE, LINK_ATTRIBUTE, CDATA, Boolean.toString(node
-                .hasLink()));
-        atts.addAttribute("", VISIBLEINNAV_ATTRIBUTE, VISIBLEINNAV_ATTRIBUTE, CDATA, Boolean
-                .toString(node.visibleInNav()));
-
-        this.contentHandler.startElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT, atts);
-
-        Label[] labels = node.getLabels();
-        for (int i = 0; i < labels.length; i++)
-            generateLabels(labels[i]);
-        SiteTreeNode[] children = node.getChildren();
-        for (int i = 0; i < children.length; i++)
-            generateNodes(children[i]);
-
-        this.contentHandler.endElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT);
-    }
-
-    private void generateLabels(Label label) throws SAXException {
-        atts.clear();
-        atts.addAttribute(NamespaceSupport.XMLNS, LANG_ATTRIBUTE, Q_LANG_ATTRIBUTE, CDATA, label
-                .getLanguage());
-
-        this.contentHandler
-                .startElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT, atts);
-        char[] labelA = label.getLabel().toCharArray();
-        this.contentHandler.characters(labelA, 0, labelA.length);
-        this.contentHandler.endElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT);
-    }
-
-    /**
-     * Recycle the generator
-     */
-    public void recycle() {
-        log.debug("recycle");
-        super.recycle();
-        sitetree = null;
-        area = null;
-    }
-
-    /**
-     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
-     */
-    public Serializable getKey() {
-        return area;
-    }
-
-    /**
-     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
-     */
-    public SourceValidity getValidity() {
-        // Check if sitetree implementation supports last modified
-        if (!(sitetree instanceof LastModified)) {
-            return null;
-        } else {
-            return new TimeStampValidity(((LastModified) sitetree).getLastModified());
-        }
-    }
+public class SiteTreeGenerator extends ServiceableGenerator implements Parameterizable, CacheableProcessingComponent {
+   private static Logger log = Logger.getLogger(SiteTreeGenerator.class);
+   protected final static String I18N_PX = "i18n";
+   protected final static String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
+   protected final static String CDATA = "CDATA";
+   protected final static String SITE_ELEMENT = "site";
+   protected final static String NODE_ELEMENT = "node";
+   protected final static String LABEL_ELEMENT = "label";
+   protected final static String LABEL_ATTRIBUTE = "label";
+   protected final static String ATTR_ATTRIBUTE = "attr";
+   protected final static String Q_ATTR_ATTRIBUTE = I18N_PX + ":" + ATTR_ATTRIBUTE;
+   protected final static String ID_ATTRIBUTE = "id";
+   protected final static String LANG_ATTRIBUTE = "lang";
+   protected final static String HREF_ATTRIBUTE = "href";
+   protected final static String LINK_ATTRIBUTE = "link";
+   protected final static String VISIBLEINNAV_ATTRIBUTE = "visibleinnav";
+   protected final static String SUFFIX_ATTRIBUTE = "suffix";
+   protected final static String Q_LANG_ATTRIBUTE = "xml:lang";
+   /**
+    * The area of the site tree.
+    */
+   public final static String AREA_PARAMETER = "area";
+   private final AttributesImpl atts = new AttributesImpl();
+   SiteTree sitetree = null;
+   String area = null;
+   /**
+    * No parameters implemented.
+    * 
+    * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+    */
+   public void parameterize(Parameters parameters) throws ParameterException {
+   }
+   /**
+    * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+    */
+   public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+      log.debug("setup");
+      try{
+         Publication publication = Globals.getPublication();
+         if(null == publication){
+            throw new ProcessingException("Unable to get sitetree: publication exception.");
+         }
+         area = par.getParameter(AREA_PARAMETER);
+         sitetree = publication.getTree(area);
+      }catch(ParameterException e){
+         throw new ProcessingException("Unable to get sitetree: parameter 'area' not found.", e);
+      }catch(SiteTreeException e){
+         throw new ProcessingException("Unable to get sitetree.", e);
+      }
+   }
+   /**
+    * @see org.apache.cocoon.generation.Generator#generate()
+    */
+   public void generate() throws SAXException {
+      log.debug("generate");
+      // Start the document and set the namespace.
+      this.contentHandler.startDocument();
+      // Default namespace.
+      this.contentHandler.startPrefixMapping("", SiteTree.NAMESPACE_URI);
+      this.contentHandler.startPrefixMapping(I18N_PX, I18N_NS);
+      generateSiteTree(sitetree);
+      // End the document.
+      this.contentHandler.endPrefixMapping("");
+      this.contentHandler.endDocument();
+   }
+   private void generateSiteTree(SiteTree tree) throws SAXException {
+      atts.clear();
+      // TODO: Do not hardcode "Authoring" label!!!
+      atts.addAttribute("", LABEL_ATTRIBUTE, LABEL_ATTRIBUTE, CDATA, "Authoring");
+      atts.addAttribute(I18N_NS, ATTR_ATTRIBUTE, Q_ATTR_ATTRIBUTE, CDATA, "label");
+      this.contentHandler.startElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT, atts);
+      SiteTreeNode[] topNodes = tree.getTopNodes();
+      for(int i = 0; i < topNodes.length; i++){
+         generateNodes(topNodes[i]);
+      }
+      this.contentHandler.endElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT);
+   }
+   private void generateNodes(SiteTreeNode node) throws SAXException {
+      atts.clear();
+      atts.addAttribute("", ID_ATTRIBUTE, ID_ATTRIBUTE, CDATA, node.getId());
+      if(node.getHref() != null) atts.addAttribute("", HREF_ATTRIBUTE, HREF_ATTRIBUTE, CDATA, node.getHref());
+      if(node.getSuffix() != null) atts.addAttribute("", SUFFIX_ATTRIBUTE, SUFFIX_ATTRIBUTE, CDATA, node.getSuffix());
+      atts.addAttribute("", LINK_ATTRIBUTE, LINK_ATTRIBUTE, CDATA, Boolean.toString(node.hasLink()));
+      atts.addAttribute("", VISIBLEINNAV_ATTRIBUTE, VISIBLEINNAV_ATTRIBUTE, CDATA, Boolean.toString(node.visibleInNav()));
+      this.contentHandler.startElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT, atts);
+      Label[] labels = node.getLabels();
+      for(int i = 0; i < labels.length; i++)
+         generateLabels(labels[i]);
+      SiteTreeNode[] children = node.getChildren();
+      for(int i = 0; i < children.length; i++)
+         generateNodes(children[i]);
+      this.contentHandler.endElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT);
+   }
+   private void generateLabels(Label label) throws SAXException {
+      atts.clear();
+      atts.addAttribute(NamespaceSupport.XMLNS, LANG_ATTRIBUTE, Q_LANG_ATTRIBUTE, CDATA, label.getLanguage());
+      this.contentHandler.startElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT, atts);
+      char[] labelA = label.getLabel().toCharArray();
+      this.contentHandler.characters(labelA, 0, labelA.length);
+      this.contentHandler.endElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT);
+   }
+   /**
+    * Recycle the generator
+    */
+   public void recycle() {
+      log.debug("recycle");
+      super.recycle();
+      sitetree = null;
+      area = null;
+   }
+   /**
+    * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
+    */
+   public Serializable getKey() {
+      return area;
+   }
+   /**
+    * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
+    */
+   public SourceValidity getValidity() {
+      // Check if sitetree implementation supports last modified
+      if(!(sitetree instanceof LastModified)){
+         return null;
+      }else{
+         return new TimeStampValidity(((LastModified) sitetree).getLastModified());
+      }
+   }
 }
\ No newline at end of file

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/task/CocoonTaskWrapper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/task/CocoonTaskWrapper.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/task/CocoonTaskWrapper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/task/CocoonTaskWrapper.java Tue Sep  9 17:30:20 2008
@@ -19,7 +19,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
 import org.apache.lenya.ac.AccessControlException;
@@ -28,13 +27,12 @@
 import org.apache.lenya.ac.User;
 import org.apache.lenya.ac.impl.PolicyAuthorizer;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.PublicationFactory;
 import org.apache.lenya.cms.task.DefaultTaskWrapper;
 import org.apache.lenya.cms.task.ExecutionException;
 import org.apache.lenya.cms.task.Notifier;
 import org.apache.lenya.cms.task.TaskWrapperParameters;
 import org.apache.lenya.cms.task.WorkflowInvoker;
+import org.apache.lenya.util.Globals;
 import org.apache.lenya.util.NamespaceMap;
 import org.apache.lenya.util.ServletHelper;
 import org.apache.log4j.Logger;
@@ -55,13 +53,11 @@
     */
    public CocoonTaskWrapper(Map objectModel, Parameters parameters) throws ExecutionException {
       log.debug("Creating CocoonTaskWrapper");
-      Publication publication;
-      try{
-         publication = PublicationFactory.getPublication(objectModel);
-      }catch(PublicationException e){
-         throw new ExecutionException(e);
+      Publication publication = Globals.getPublication();
+      if(null == publication){
+         throw new ExecutionException("CocoonTaskWrapper: No Publication.");
       }
-      Request request = ObjectModelHelper.getRequest(objectModel);
+      Request request = Globals.getRequest();
       initialize(parameters, publication, request);
    }
    /**

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java Tue Sep  9 17:30:20 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.cocoon.transformation;
-
 import java.io.IOException;
 import java.util.Map;
 import org.apache.avalon.framework.activity.Disposable;
@@ -38,122 +35,98 @@
 import org.apache.lenya.ac.impl.PolicyAuthorizer;
 import org.apache.lenya.cms.ac.usecase.UsecaseAuthorizer;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.util.Globals;
 import org.apache.lenya.util.ServletHelper;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
-
 /**
- * This transformer disables menu items (by removing the href attribute)
- * which are not allowed with respect to the usecase policies.
+ * This transformer disables menu items (by removing the href attribute) which are not allowed with respect to the usecase policies.
  */
 public class UsecaseMenuTransformer extends AbstractSAXTransformer implements Disposable {
-
-    public static final String MENU_ELEMENT = "menu";
-    public static final String ITEM_ELEMENT = "item";
-    public static final String USECASE_ATTRIBUTE = "usecase";
-    public static final String NAMESPACE = "http://apache.org/cocoon/lenya/usecase/1.0";
-
-    /** (non-Javadoc)
-     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-     */
-    public void startElement(String uri, String localName, String raw, Attributes attr)
-        throws SAXException {
-
-        Attributes attributes = attr;
-
-        if (authorizer != null && localName.equals(ITEM_ELEMENT)) {
-            String usecase = attr.getValue(NAMESPACE, USECASE_ATTRIBUTE);
-
-            // filter item if usecase not allowed 
-            if (usecase != null) {
-                getLogger().debug("Found usecase [" + usecase + "]");
-
-                try {
-                    if (!authorizer.authorizeUsecase(usecase, roles, publication)) {
-                        getLogger().debug("Usecase not authorized");
-                        int hrefIndex = attributes.getIndex("href");
-                        if (hrefIndex > -1) {
-                            attributes = new AttributesImpl(attr);
-                            ((AttributesImpl) attributes).removeAttribute(hrefIndex);
-                        }
-                    }
-                } catch (AccessControlException e) {
-                    throw new SAXException(e);
-                }
+   public static final String MENU_ELEMENT = "menu";
+   public static final String ITEM_ELEMENT = "item";
+   public static final String USECASE_ATTRIBUTE = "usecase";
+   public static final String NAMESPACE = "http://apache.org/cocoon/lenya/usecase/1.0";
+   /**
+    * (non-Javadoc)
+    * 
+    * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+    */
+   public void startElement(String uri, String localName, String raw, Attributes attr) throws SAXException {
+      Attributes attributes = attr;
+      if(authorizer != null && localName.equals(ITEM_ELEMENT)){
+         String usecase = attr.getValue(NAMESPACE, USECASE_ATTRIBUTE);
+         // filter item if usecase not allowed
+         if(usecase != null){
+            getLogger().debug("Found usecase [" + usecase + "]");
+            try{
+               if(!authorizer.authorizeUsecase(usecase, roles, publication)){
+                  getLogger().debug("Usecase not authorized");
+                  int hrefIndex = attributes.getIndex("href");
+                  if(hrefIndex > -1){
+                     attributes = new AttributesImpl(attr);
+                     ((AttributesImpl) attributes).removeAttribute(hrefIndex);
+                  }
+               }
+            }catch(AccessControlException e){
+               throw new SAXException(e);
             }
-        }
-
-        super.startElement(uri, localName, raw, attributes);
-
-    }
-
-    private UsecaseAuthorizer authorizer;
-    private ServiceSelector serviceSelector = null;
-    private Role[] roles;
-    private Publication publication;
-    private AccessControllerResolver acResolver;
-
-    /**
-     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
-     */
-    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
-        throws ProcessingException, SAXException, IOException {
-        
-        super.setup(resolver, objectModel, src, parameters);
-
-        getLogger().debug("Setting up transformer");
-
-        serviceSelector = null;
-        acResolver = null;
-        authorizer = null;
-
-        Request request = ObjectModelHelper.getRequest(objectModel);
-
-        try {
-            roles = PolicyAuthorizer.getRoles(request);
-
-            publication = PublicationFactory.getPublication(objectModel);
-
-            serviceSelector =
-                (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
-            acResolver =
-                (AccessControllerResolver) serviceSelector.select(
-                    AccessControllerResolver.DEFAULT_RESOLVER);
-            getLogger().debug("Resolved AC resolver [" + acResolver + "]");
-
-            String webappUrl = ServletHelper.getWebappURI(request);
-            AccessController accessController = acResolver.resolveAccessController(webappUrl);
-
-            if (accessController instanceof DefaultAccessController) {
-                DefaultAccessController defaultAccessController =
-                    (DefaultAccessController) accessController;
-                Authorizer[] authorizers = defaultAccessController.getAuthorizers();
-                for (int i = 0; i < authorizers.length; i++) {
-                    if (authorizers[i] instanceof UsecaseAuthorizer) {
-                        authorizer = (UsecaseAuthorizer) authorizers[i];
-                    }
-                }
+         }
+      }
+      super.startElement(uri, localName, raw, attributes);
+   }
+   private UsecaseAuthorizer authorizer;
+   private ServiceSelector serviceSelector = null;
+   private Role[] roles;
+   private Publication publication;
+   private AccessControllerResolver acResolver;
+   /**
+    * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+    */
+   public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
+      super.setup(resolver, objectModel, src, parameters);
+      getLogger().debug("Setting up transformer");
+      serviceSelector = null;
+      acResolver = null;
+      authorizer = null;
+      Request request = ObjectModelHelper.getRequest(objectModel);
+      try{
+         roles = PolicyAuthorizer.getRoles(request);
+         publication = Globals.getPublication();
+         if(null == publication){
+            throw new PublicationException("UsecaseMenuTransformer.setup: No Publication.");
+         }
+         serviceSelector = (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
+         acResolver = (AccessControllerResolver) serviceSelector.select(AccessControllerResolver.DEFAULT_RESOLVER);
+         getLogger().debug("Resolved AC resolver [" + acResolver + "]");
+         String webappUrl = ServletHelper.getWebappURI(request);
+         AccessController accessController = acResolver.resolveAccessController(webappUrl);
+         if(accessController instanceof DefaultAccessController){
+            DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
+            Authorizer[] authorizers = defaultAccessController.getAuthorizers();
+            for(int i = 0; i < authorizers.length; i++){
+               if(authorizers[i] instanceof UsecaseAuthorizer){
+                  authorizer = (UsecaseAuthorizer) authorizers[i];
+               }
             }
-
-            getLogger().debug("Using authorizer [" + authorizer + "]");
-        } catch (Exception e) {
-            throw new ProcessingException(e);
-        }
-    }
-
-    /**
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
-    public void dispose() {
-        getLogger().debug("Disposing transformer");
-        if (serviceSelector != null) {
-            if (acResolver != null) {
-                serviceSelector.release(acResolver);
-            }
-            manager.release(serviceSelector);
-        }
-    }
-
+         }
+         getLogger().debug("Using authorizer [" + authorizer + "]");
+      }catch(Exception e){
+         throw new ProcessingException(e);
+      }
+   }
+   /**
+    * @see org.apache.avalon.framework.activity.Disposable#dispose()
+    */
+   public void dispose() {
+      getLogger().debug("Disposing transformer");
+      if(serviceSelector != null){
+         if(acResolver != null){
+            serviceSelector.release(acResolver);
+         }
+         manager.release(serviceSelector);
+      }
+   }
 }

Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/AbstractContentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/AbstractContentSourceFactory.java?rev=693670&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/AbstractContentSourceFactory.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/AbstractContentSourceFactory.java Tue Sep  9 17:30:20 2008
@@ -0,0 +1,112 @@
+package org.apache.lenya.cms.content;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+import java.util.StringTokenizer;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.CocoonComponentManager;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceUtil;
+import org.apache.excalibur.source.URIAbsolutizer;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.util.Globals;
+/**
+ * @author solprovider
+ * @since 1.3
+ */
+public abstract class AbstractContentSourceFactory implements SourceFactory, ThreadSafe, URIAbsolutizer, Contextualizable {
+   protected static final int REQUEST_DATA = 0;
+   protected static final int REQUEST_META = 1;
+   protected static final int REQUEST_INFO = 2;
+   protected org.apache.avalon.framework.context.Context context;
+   // private String pubsPrefix;
+   // private DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+   protected SourceResolver resolver = null;
+   protected Publication publication;
+   // protected Content content;
+   private Location location;
+   protected ComponentManager manager;
+   public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException {
+      this.context = context;
+   }
+   public Source getSource(String src, Map parameters) throws IOException, MalformedURLException {
+      // System.out.println("\nAbstractContentSourceFactory.getSource " + src.toString());
+      try{
+         manager = CocoonComponentManager.getSitemapComponentManager();
+         try{
+            resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+         }catch(org.apache.avalon.framework.component.ComponentException ce){
+         }
+         if(null == resolver){ throw new SourceNotFoundException("No Resolver: " + src); }
+         publication = Globals.getPublication();
+         // content = publication.getContent();
+         location = new Location(src); // Parse Location: Removes everything after first period, underscore, or exclamation mark.
+         String workLocation = location.getUnid();
+         // Decide Usage
+         StringTokenizer tokens = new StringTokenizer(workLocation, "/:", true);
+         if(!tokens.hasMoreTokens()){ throw new MalformedURLException("No UNID specified."); }
+         String token = tokens.nextToken();
+         if(workLocation.indexOf(":") > 0) token = tokens.nextToken(); // Remove protocol
+         int colonCount = 0;
+         while(token.equals(":")){
+            colonCount++;
+            token = (tokens.hasMoreTokens() ? tokens.nextToken() : "");
+         }
+         int slashCount = 0;
+         while(token.equals("/")){
+            slashCount++;
+            token = (tokens.hasMoreTokens() ? tokens.nextToken() : "");
+         }
+         // Sets request type without using constants
+         int requestType = colonCount - 1;
+         // Set request type from word overriding colon syntax.
+         boolean isFormat2 = false;
+         if(token.equals("DATA")){
+            requestType = REQUEST_DATA;
+            isFormat2 = true;
+         }else if(token.equals("META")){
+            requestType = REQUEST_META;
+            isFormat2 = true;
+         }else if(token.equals("INFO")){
+            requestType = REQUEST_INFO;
+            isFormat2 = true;
+         }
+         if(isFormat2){
+            token = tokens.nextToken();
+            int slashCount2 = 0;
+            while(token.equals("/")){
+               slashCount2++;
+               token = tokens.nextToken();
+            }
+            slashCount = (slashCount > slashCount2 ? slashCount : slashCount2);
+         }
+         // Rebuild unid
+         StringBuffer buffer = new StringBuffer();
+         for(int s = 0; s < slashCount; s++){
+            buffer.append("/");
+         }
+         buffer.append(token);
+         while(tokens.hasMoreTokens()){
+            buffer.append(tokens.nextToken());
+         }
+         location.setUnid(buffer.toString());
+         // ASSUME: UNID
+         return getResource(requestType, location);
+      }finally{
+         if(resolver != null) manager.release((Component) resolver);
+      }
+   }
+   abstract Source getResource(int requestType, Location location) throws MalformedURLException, IOException;
+   public void release(Source source1) {
+   }
+   public String absolutize(String baseURI, String location) {
+      return SourceUtil.absolutize(baseURI, location, false, false);
+   }
+}

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java Tue Sep  9 17:30:20 2008
@@ -5,9 +5,9 @@
  * @since 1.3
  */
 public interface Content {
-   public static final String TYPE_FLAT = "flat";
    public static final String TYPE_HIERARCHICAL = "hierarchical";
    public static final String TYPE_DEFAULT = "all";
+   public static final String REVISION_DEFAULT = "live";
    public String getURI(String unid, String language, String revision);
    public String getMetaURI(String unid, String language, String revision);
    public String getNewURI(String unid, String language);

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java Tue Sep  9 17:30:20 2008
@@ -5,17 +5,16 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.lenya.cms.cocoon.components.modules.input.AbstractPageEnvelopeModule;
-import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeException;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.util.Globals;
 /**
  * Retrieves Content Variables from the appropriate Resource
  * 
  * @author solprovider
  * @since 1.3
  */
-public class ContentInputModule extends AbstractPageEnvelopeModule implements ThreadSafe {
+public class ContentInputModule extends AbstractInputModule implements ThreadSafe {
    // public class ContentInputModule extends AbstractPageEnvelopeModule implements Serviceable, Contextualizable, ThreadSafe {
    // private ServiceManager manager;
    // private org.apache.avalon.framework.context.Context context;
@@ -23,20 +22,17 @@
     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
     */
    public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+      // System.out.println("ContentInputModule.getAttribute " + name);
       if(getLogger().isDebugEnabled()){
          getLogger().debug("Resolving [" + name + "]");
       }
-      PageEnvelope pe;
-      try{
-         pe = PageEnvelope.getCurrent();
-      }catch(PageEnvelopeException e){
-         throw new ConfigurationException("Resolving page envelope failed: ", e);
+      Publication publication = Globals.getPublication();
+      if(null == publication){
+         System.out.println("ContentInputModule.getAttribute: Publication is null");
+         return "error";
       }
-      Publication pub = pe.getPublication();
-      // String publication = pub.getId();
-      Content content = pub.getContent();
+      Content content = publication.getContent();
       String unid = "";
-      // System.out.println("ContentInputModule name=" + name);
       int pos = name.indexOf(":");
       if(pos > 0){
          unid = name.substring(pos + 1);
@@ -47,18 +43,14 @@
       }
       Resource resource = content.getResource(unid);
       if(null == resource){
-         System.out.println("ContentInputModule: No Resource NAME=" + name + " UNID=" + unid);
+         System.out.println("ContentInputModule.getAttribute: No Resource NAME=" + name + " UNID=" + unid);
       }
       if(name.equalsIgnoreCase("type")){
          // System.out.println("ContentInputModule NAME=" + name + " UNID=" + unid + " TYPE=" + resource.getType());
          return resource.getType();
       }
-      if(name.equalsIgnoreCase("doctype") || name.equalsIgnoreCase("documenttype")){
-         return resource.getDocumentType();
-      }
-      if(name.equalsIgnoreCase("defaultlanguage")){
-         return resource.getDefaultLanguage();
-      }
+      if(name.equalsIgnoreCase("doctype") || name.equalsIgnoreCase("documenttype")){ return resource.getDocumentType(); }
+      if(name.equalsIgnoreCase("defaultlanguage")){ return resource.getDefaultLanguage(); }
       return "";
    }
    /**

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java Tue Sep  9 17:30:20 2008
@@ -1,24 +1,11 @@
 package org.apache.lenya.cms.content;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.util.Map;
 import java.util.StringTokenizer;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.CocoonComponentManager;
 import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceFactory;
 import org.apache.excalibur.source.SourceNotFoundException;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.SourceUtil;
-import org.apache.excalibur.source.URIAbsolutizer;
 import org.apache.lenya.cms.cocoon.components.source.impl.StringSource;
-import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.content.flat.FlatDesign;
 import org.w3c.dom.Document;
 /**
  * Implements content: protocol. <BR>
@@ -33,146 +20,68 @@
  * @author solprovider
  * @since 1.3
  */
-public class ContentSourceFactory implements SourceFactory, ThreadSafe, URIAbsolutizer, Contextualizable {
-   private static final int REQUEST_DATA = 0;
-   private static final int REQUEST_META = 1;
-   private static final int REQUEST_INFO = 2;
-   protected org.apache.avalon.framework.context.Context context;
-   // private String servletContextPath;
-   String pubsPrefix;
-   DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-   SourceResolver resolver = null;
-   public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException {
-      this.context = context;
-   }
-   public Source getSource(String location, Map parameters) throws IOException, MalformedURLException {
-      String workLocation = location;
-      int pos;
-      // Map contextmap = ContextHelper.getObjectModel(context);
-      // org.apache.cocoon.environment.http.HttpContext httpcontext = (org.apache.cocoon.environment.http.HttpContext) contextmap.get("context");
-      // servletContextPath = httpcontext.getRealPath("");
-      // TODO: Move resolver, pubsPrefix and other init out of getSource(). Make static?
-      ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
-      try{
-         resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
-      }catch(org.apache.avalon.framework.component.ComponentException ce){
-      }
-      if(null == resolver){
-         throw new SourceNotFoundException("No Resolver: " + location);
-      }
-      String uri = resolver.resolveURI("").getURI();
-      pos = uri.indexOf("/pubs/");
-      if(pos > 0){
-         pubsPrefix = uri.substring(0, pos + 6);
-      }else{
-         pos = uri.indexOf("/modules/");
-         if(pos > 0){
-            pubsPrefix = uri.substring(0, pos) + "/pubs/";
-         }
-      }
-      // String publication;
-      // String contentpath;
-      Publication pub;
-      Content content;
-      try{
-         PageEnvelope envelope = PageEnvelope.getCurrent();
-         pub = envelope.getPublication();
-         // publication = pub.getId();
-         content = pub.getContent();
-         // contentpath = pub.getContentDirectory().getAbsolutePath() + File.separator;
-      }catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
-         throw new MalformedURLException("Could not get Publication ID.");
-      }
-      // Parse Location
-      Location locationParser = new Location(workLocation);
-      // Removes everything after first period, underscore, or exclamation mark.
-      workLocation = locationParser.getUnid();
-      // Decide Usage
-      StringTokenizer tokens = new StringTokenizer(workLocation, "/:", true);
-      if(!tokens.hasMoreTokens())
-         throw new MalformedURLException("Nothing specified.");
-      String token = tokens.nextToken();
-      if(workLocation.indexOf(":") > 0)
-         token = tokens.nextToken(); // Remove protocol
-      int colonCount = 0;
-      while(token.equals(":")){
-         colonCount++;
-         token = (tokens.hasMoreTokens() ? tokens.nextToken() : "");
-      }
+public class ContentSourceFactory extends AbstractContentSourceFactory {
+   Source getResource(int requestType, Location location) throws MalformedURLException, IOException {
+      // System.out.println("ContentSourceFactory.getResource " + location.toString());
+      /** ******** Get Source (uses Content) ************ */
+      Content content = super.publication.getContent();
+      StringTokenizer tokens = new StringTokenizer(location.getUnid(), "/:", true);
       int slashCount = 0;
+      String token = tokens.nextToken();
       while(token.equals("/")){
          slashCount++;
-         token = (tokens.hasMoreTokens() ? tokens.nextToken() : "");
-      }
-      int requestType = colonCount - 1;
-      boolean isFormat2 = false;
-      if(token.equals("DATA")){
-         requestType = REQUEST_DATA;
-         isFormat2 = true;
-      }else if(token.equals("META")){
-         requestType = REQUEST_META;
-         isFormat2 = true;
-      }else if(token.equals("INFO")){
-         requestType = REQUEST_INFO;
-         isFormat2 = true;
-      }
-      if(isFormat2){
          token = tokens.nextToken();
-         int slashCount2 = 0;
-         while(token.equals("/")){
-            slashCount2++;
-            token = tokens.nextToken();
-         }
-         slashCount = (slashCount > slashCount2 ? slashCount : slashCount2);
       }
       String structure = (2 < slashCount ? "" : token);
       String unid = token;
       StringBuffer buffer = new StringBuffer();
-      while(tokens.hasMoreTokens())
+      while(tokens.hasMoreTokens()){
          buffer.append(tokens.nextToken());
+      }
       String fullid = buffer.toString();
-      if((1 < slashCount) || (0 < fullid.length()))
+      if((1 < slashCount) || (0 < fullid.length())){
          unid = content.getUNID(structure, fullid);
-      // ASSUME: UNID
-      /** ******** Get Source (uses Content) ************ */
+      }
+      // System.out.println("ContentSourceFactory.getResource unid=" + unid);
       Source source;
       if(REQUEST_INFO == requestType){
          // TODO: Catch errors
          Resource resource = content.getResource(unid);
          if(resource == null){
-            throw new SourceNotFoundException("Source not found (no Resource): " + location);
+            System.out.println("ContentSourceFactory.getSource Null Resource UNID=" + unid);
+            throw new SourceNotFoundException("Source not found (no Resource): " + location.toString());
          }
          Document doc = resource.getInfoDocument();
          if(doc == null){
-            throw new SourceNotFoundException("Source not found (no Document): " + location);
+            System.out.println("ContentSourceFactory.getSource Null Document UNID=" + unid);
+            throw new SourceNotFoundException("Source not found (no Document): " + location.toString());
          }
          source = new StringSource(manager, doc);
          if(source == null){
-            throw new SourceNotFoundException("Source not found (no Source): " + location);
+            System.out.println("ContentSourceFactory.getSource Null Source UNID=" + unid);
+            throw new SourceNotFoundException("Source not found (no Source): " + location.toString());
          }
          return source;
       }
       // Revision
-      String revision = locationParser.getRevision();
+      String revision = location.getRevision();
       if(0 == revision.length()){
-         revision = "live";
+         revision = Content.REVISION_DEFAULT;
       }
       // Language
-      String language = locationParser.getLanguage();
-      if(language.length() < 1){
+      String language = location.getLanguage();
+      if((1 > language.length()) || (FlatDesign.DESIGN_LANGUAGE.equalsIgnoreCase(language))){
          Resource resource = content.getResource(unid);
          if(resource != null){
             language = resource.getDefaultLanguage();
          }
       }
-      if(language.length() < 1){
-         language = pub.getDefaultLanguage();
+      if((1 > language.length()) || (FlatDesign.DESIGN_LANGUAGE.equalsIgnoreCase(language))){
+         language = publication.getDefaultLanguage();
       }
       if(REQUEST_META == requestType){
          source = resolver.resolveURI(content.getMetaURI(unid, language, revision));
          if(source.exists()){
-            if(resolver != null)
-               manager.release((Component) resolver);
             return source;
          }else{
             throw new SourceNotFoundException("Source not found (no Meta Source): " + location);
@@ -180,20 +89,9 @@
       }
       String curi = content.getURI(unid, language, revision);
       // System.out.println("ContentSourceFactory.getSource UNID=" + unid + " LANG=" + language + " REV=" + revision + " CURI=" + curi);
-      if(curi.length() < 1){
-         throw new SourceNotFoundException("Source not found (no URI): " + location + " UNID=" + unid + " LANG=" + language + " REV=" + revision);
-      }
+      if(curi.length() < 1){ throw new SourceNotFoundException("Source not found (no URI): " + location + " UNID=" + unid + " LANG=" + language + " REV=" + revision); }
       source = resolver.resolveURI(curi);
-      if(resolver != null)
-         manager.release((Component) resolver);
-      if(source.exists()){
-         return source;
-      }
+      if(source.exists()){ return source; }
       throw new SourceNotFoundException("Source not found: " + location + " (" + curi + ")");
    }
-   public void release(Source source1) {
-   }
-   public String absolutize(String baseURI, String location) {
-      return SourceUtil.absolutize(baseURI, location, false, false);
-   }
 }

Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/DesignSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/DesignSourceFactory.java?rev=693670&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/DesignSourceFactory.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/DesignSourceFactory.java Tue Sep  9 17:30:20 2008
@@ -0,0 +1,73 @@
+package org.apache.lenya.cms.content;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.StringTokenizer;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.lenya.cms.cocoon.components.source.impl.StringSource;
+import org.apache.lenya.cms.content.flat.FlatDesign;
+import org.w3c.dom.Document;
+/**
+ * Implements content: protocol. <BR>
+ * This should call the Content API that calls a Content Impl. <BR>
+ * <BR>== Content API == <BR>
+ * Source getResourceByUNID(String unid, String translation, String revision) <BR>
+ * Source getResourceByID(String structure, String id, String translation, String revision) <BR>
+ * <BR>== Content Impls == <BR>
+ * ContentHierarchical (Lenya 1.2) <BR>
+ * ContentFlat (Lenya 1.3)
+ * 
+ * @author solprovider
+ * @since 1.3
+ */
+public class DesignSourceFactory extends AbstractContentSourceFactory {
+   Source getResource(int requestType, Location location) throws MalformedURLException, IOException {
+      // System.out.println("DesignSourceFactory.getResource " + location.toString());
+      /** ******** Get Source (uses Content) ************ */
+      StringTokenizer tokens = new StringTokenizer(location.getUnid(), "/", true);
+      // int slashCount = 0;
+      String token = tokens.nextToken();
+      // Remove leading slashes
+      while(token.equals("/") && tokens.hasMoreTokens()){
+         // slashCount++;
+         token = tokens.nextToken();
+      }
+      StringBuffer buffer = new StringBuffer();
+      buffer.append(token);
+      while(tokens.hasMoreTokens()){
+         buffer.append(tokens.nextToken());
+      }
+      String filename = buffer.toString();
+      Source source;
+      FlatDesign design = super.publication.getDesign();
+      if(REQUEST_INFO == requestType){
+         Resource resource = design.getDesign(filename);
+         if(resource == null){ throw new SourceNotFoundException("Source not found (no Resource): " + location.toString()); }
+         Document doc = resource.getInfoDocument();
+         if(doc == null){ throw new SourceNotFoundException("Source not found (no Document): " + location.toString()); }
+         source = new StringSource(manager, doc);
+         if(source == null){ throw new SourceNotFoundException("Source not found (no Source): " + location.toString()); }
+         return source;
+      }
+      // Revision
+      String revision = location.getRevision();
+      if(0 == revision.length()){
+         revision = Content.REVISION_DEFAULT;
+      }
+      if(REQUEST_META == requestType){
+         source = resolver.resolveURI(design.getDesign(filename, revision).getMetaURI());
+         // source = resolver.resolveURI(design.getResource(unid, revision).getMetaURI());
+         if(source.exists()){
+            return source;
+         }else{
+            throw new SourceNotFoundException("Source not found (no Meta Source): " + location.toString());
+         }
+      }
+      String curi = design.getDesign(filename, revision).getURI();
+      // System.out.println("ContentSourceFactory.getSource UNID=" + unid + " LANG=" + language + " REV=" + revision + " CURI=" + curi);
+      if(curi.length() < 1){ throw new SourceNotFoundException("Source not found (no URI): " + location.toString() + " UNID=" + filename + " REV=" + revision); }
+      source = resolver.resolveURI(curi);
+      if(source.exists()){ return source; }
+      throw new SourceNotFoundException("Source not found: " + location.toString() + " (" + curi + ")");
+   }
+}

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java Tue Sep  9 17:30:20 2008
@@ -76,4 +76,10 @@
    public String getExtension() {
       return extension;
    }
+   void setUnid(String unid) {
+      this.unid = unid;
+   }
+   public String toString() {
+      return unid + (0 < extension.length() ? "." + extension : "") + (0 < language.length() ? "_" + language : "") + (0 < revision.length() ? "!" + revision : "");
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java Tue Sep  9 17:30:20 2008
@@ -13,9 +13,7 @@
    public String getID();
    public String getType();
    /**
-    * Used by Lenya-1.2 Publications.
-    * 
-    * @deprecated Use getType()
+    * getDocumentType() is used by Lenya-1.2 Publications. Deprecate in post-1.3 version.
     */
    public String getDocumentType();
    public String getLanguage();

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java Tue Sep  9 17:30:20 2008
@@ -1,10 +1,16 @@
 package org.apache.lenya.cms.content;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.transformation.AbstractDOMTransformer;
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.PageEnvelopeException;
 import org.apache.lenya.cms.publication.Publication;
+import org.xml.sax.SAXException;
 /**
  * This transformer modifies the structural information of a Resource. It accepts a UNID as the src parameter. It can: - change the id and defaultlanguage of the Resource, - delete Translations and Revisions, - change the live and edit Revisions of Translations. <resource [id="newid"] [defaultlanguage="aa"]> <translation language="xx" [action="delete"] [live="1137958604000"] [edit="1137958604000"]> <revision revision="1137958604000" [action="delete"]/> </translation> </resource> action="delete" has top priority. Any settings not included will not be affected.
  * 
@@ -12,22 +18,36 @@
  * @since 1.3
  */
 public class ResourceTransformer extends AbstractDOMTransformer {
+   public static final String TYPE_CONTENT = "content";
+   public static final String TYPE_DESIGN = "design";
+   public static final String TYPE_STRUCTURE = "structure";
+   private String type = TYPE_CONTENT;
+   public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+      super.setup(resolver, objectModel, src, par);
+      type = parameters.getParameter("type", type);
+   }
    protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
       System.out.println("ResourceTransformer - BEGIN");
       String unid = this.source;
       Request request = ObjectModelHelper.getRequest(super.objectModel);
-      return transformDocument(request, unid, doc);
+      return transformDocument(request, unid, doc, type);
    }
-   static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc) {
+   static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc, String type) {
       PageEnvelope envelope;
       try{
          envelope = PageEnvelope.getCurrent();
       }catch(PageEnvelopeException e){
          return null;
       }
-      Publication pub = envelope.getPublication();
-      Content content = pub.getContent();
-      Resource resource = content.getResource(unid);
+      Publication publication = envelope.getPublication();
+      Resource resource;
+      if(TYPE_DESIGN.equalsIgnoreCase(type)){
+         resource = publication.getDesign().getDesign(unid);
+      }else if(TYPE_STRUCTURE.equalsIgnoreCase(type)){
+         resource = publication.getDesign().getStructure(unid);
+      }else{ // TYPE_CONTENT
+         resource = publication.getContent().getResource(unid);
+      }
       resource.update(doc);
       return doc;
    }

Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/StructureSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/StructureSourceFactory.java?rev=693670&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/StructureSourceFactory.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/StructureSourceFactory.java Tue Sep  9 17:30:20 2008
@@ -0,0 +1,90 @@
+package org.apache.lenya.cms.content;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.StringTokenizer;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.lenya.cms.cocoon.components.source.impl.StringSource;
+import org.apache.lenya.cms.content.flat.FlatDesign;
+import org.w3c.dom.Document;
+/**
+ * Implements content: protocol. <BR>
+ * This should call the Content API that calls a Content Impl. <BR>
+ * <BR>== Content API == <BR>
+ * Source getResourceByUNID(String unid, String translation, String revision) <BR>
+ * Source getResourceByID(String structure, String id, String translation, String revision) <BR>
+ * <BR>== Content Impls == <BR>
+ * ContentHierarchical (Lenya 1.2) <BR>
+ * ContentFlat (Lenya 1.3)
+ * 
+ * @author solprovider
+ * @since 1.3
+ */
+public class StructureSourceFactory extends AbstractContentSourceFactory {
+   Source getResource(int requestType, Location location) throws MalformedURLException, IOException {
+      System.out.println("StructureSourceFactory.getResource l=" + location.toString());
+      /** ******** Get Source (uses Content) ************ */
+      StringTokenizer tokens = new StringTokenizer(location.getUnid(), "/", true);
+      String token = tokens.nextToken();
+      // Remove leading slashes
+      while(token.equals("/") && tokens.hasMoreTokens()){
+         token = tokens.nextToken();
+      }
+      StringBuffer buffer = new StringBuffer();
+      buffer.append(token);
+      while(tokens.hasMoreTokens()){
+         buffer.append(tokens.nextToken());
+      }
+      String structure = buffer.toString();
+      System.out.println("StructureSourceFactory.getResource s=" + structure);
+      Source source;
+      FlatDesign design = super.publication.getDesign();
+      if(REQUEST_INFO == requestType){
+         Resource resource = design.getStructure(structure);
+         if(resource == null){
+            System.out.println("StructureSourceFactory.getResource MISSING INFO Resource=null");
+            throw new SourceNotFoundException("Source not found (no Resource): " + location.toString());
+         }
+         Document doc = resource.getInfoDocument();
+         if(doc == null){
+            System.out.println("StructureSourceFactory.getResource MISSING INFO doc=null");
+            throw new SourceNotFoundException("Source not found (no Document): " + location.toString());
+         }
+         source = new StringSource(manager, doc);
+         if(source == null){
+            System.out.println("StructureSourceFactory.getResource MISSING INFO source=null");
+            throw new SourceNotFoundException("Source not found (no Source): " + location.toString());
+         }
+         System.out.println("StructureSourceFactory.getResource FOUND INFO " + location.toString());
+         return source;
+      }
+      // Revision
+      String revision = location.getRevision();
+      if(0 == revision.length()){
+         revision = Content.REVISION_DEFAULT;
+      }
+      if(REQUEST_META == requestType){
+         source = resolver.resolveURI(design.getStructure(structure, revision).getMetaURI());
+         if(source.exists()){
+            System.out.println("StructureSourceFactory.getResource FOUND META " + location.toString());
+            return source;
+         }else{
+            System.out.println("StructureSourceFactory.getResource MISSING INFO " + location.toString());
+            throw new SourceNotFoundException("Source not found (no Meta Source): " + location.toString());
+         }
+      }
+      String curi = design.getStructure(structure, revision).getURI();
+      System.out.println("StructureSourceFactory.getResource REV=" + revision + " CURI='" + curi + "'");
+      if(curi.length() < 1){
+         System.out.println("StructureSourceFactory.getResource: No URI " + location.toString());
+         throw new SourceNotFoundException("Source not found (no URI): " + location.toString() + " UNID=" + structure + " REV=" + revision);
+      }
+      source = resolver.resolveURI(curi);
+      if(source.exists()){
+         System.out.println("StructureSourceFactory.getResource FOUND " + location.toString());
+         return source;
+      }
+      System.out.println("StructureSourceFactory.getResource MISSING " + location.toString());
+      throw new SourceNotFoundException("Source not found: " + location.toString() + " (" + curi + ")");
+   }
+}

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java Tue Sep  9 17:30:20 2008
@@ -1,11 +1,15 @@
 package org.apache.lenya.cms.content.flat;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.transformation.AbstractDOMTransformer;
 import org.apache.lenya.cms.content.ResourceException;
+import org.apache.lenya.cms.content.ResourceTransformer;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
 /**
  * @cocoon.sitemap.component.documentation This transformer creates a new Resource.
  * 
@@ -14,27 +18,29 @@
  */
 // <?xml version="1.0" encoding="UTF-8"?>
 // <resource defaultlanguage="en" doctype="xhtml" id="doctypes" type="xml" unid="0002" xmlns=""/>
-public class CreateResourceTransformer extends AbstractDOMTransformer {
-   public static final String CONTENT_PREFIX = "content";
-   public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_. ]+";
-   protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
-      Request request = ObjectModelHelper.getRequest(super.objectModel);
-      createResource(request, doc);
-      return doc;
+public class CreateResourceTransformer extends AbstractDOMTransformer implements Configurable {
+   private String type = ResourceTransformer.TYPE_CONTENT;
+   public void configure(Configuration conf) throws ConfigurationException {
+      Configuration child = conf.getChild("type");
+      type = child.getValue(type);
    }
-   static public org.w3c.dom.Document transformDocument(Request request, org.w3c.dom.Document doc) throws ProcessingException {
-      createResource(request, doc);
+   protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
+      createResource(doc, type);
       return doc;
    }
    /**
-    * @param request
-    *           The request
-    * @param doc
-    *           The data to be inserted.
-    * @throws ProcessingException
-    * @throws ResourceException
+    * @deprecated Request is not needed. Must update JS files in Modules before deleting.
     */
-   static private void createResource(Request request, org.w3c.dom.Document doc) {
+   static public org.w3c.dom.Document transformDocument(Request request, org.w3c.dom.Document doc, String type) throws ProcessingException {
+      createResource(doc, type);
+      return doc;
+   }
+   static public org.w3c.dom.Document transformDocument(org.w3c.dom.Document doc, String type) throws ProcessingException {
+      createResource(doc, type);
+      return doc;
+   }
+   static private void createResource(org.w3c.dom.Document doc, String resourceType) {
+      // System.out.println("CreateResourceTransformer.createResource Type=" + resourceType);
       if(doc == null){
          System.out.println("CreateResource: Document is required.");
          // throw new ProcessingException("CreateResource: document is required.");
@@ -50,18 +56,21 @@
          String id = element.getAttribute("id");
          FlatResource resource;
          try{
-            resource = FlatResource.create(unid, type, id);
+            if(ResourceTransformer.TYPE_STRUCTURE.equalsIgnoreCase(resourceType)){
+               System.out.println("CreateResourceTransformer.createResource calling createStructure");
+               resource = FlatResource.createStructure(unid, type, id);
+            }else if(ResourceTransformer.TYPE_DESIGN.equalsIgnoreCase(resourceType)){
+               resource = FlatResource.createDesign(unid, type, id);
+            }else{
+               resource = FlatResource.createContent(unid, type, id);
+            }
             unid = resource.getUNID();
-            // Attempts to make UNID accessible to XMAP.
-            // request.setAttribute("unid", unid);
-            // Globals.getRequest().setAttribute("unid", unid);
-            // ContextMap contextMap = ContextMap.getCurrentContext();
-            // contextMap.set("unid", unid);
             element.setAttribute("unid", unid);
             element.setAttribute("status", "SUCCESS");
          }catch(ResourceException e){
             element.setAttribute("status", "FAILURE");
-            element.setNodeValue(e.getLocalizedMessage());
+            Text text = doc.createTextNode(e.getMessage());
+            element.appendChild(text);
          }
       }
    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.