svn commit: r635107 [3/7] - in /lenya/branches/revolution/1.3.x: ./ src/cocoon/ src/java/org/apache/cocoon/components/source/ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya...

[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/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=635107&r1=635106&r2=635107&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 Sat Mar  8 14:58:32 2008
@@ -6,6 +6,7 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
 import org.apache.lenya.cms.publication.Publication;
 /**
  * Retrieves Publication variables.
@@ -24,7 +25,12 @@
       if(getLogger().isDebugEnabled()){
          getLogger().debug("Resolving [" + name + "]");
       }
-      PageEnvelope pe = getEnvelope(objectModel);
+      PageEnvelope pe;
+      try{
+         pe = PageEnvelope.getCurrent();
+      }catch(PageEnvelopeException e){
+         throw new ConfigurationException("Resolving page envelope failed: ", e);
+      }
       Publication pub = pe.getPublication();
       if(name.equalsIgnoreCase("contenttype"))
          return pub.getContentType();

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceExistsModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceExistsModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceExistsModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceExistsModule.java Sat Mar  8 14:58:32 2008
@@ -19,7 +19,6 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
-
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/SitetreeModule.java Sat Mar  8 14:58:32 2008
@@ -14,99 +14,75 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.cocoon.components.modules.input;
-
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Map;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.SiteTree;
 import org.apache.lenya.cms.publication.SiteTreeNode;
-
 public class SitetreeModule extends AbstractInputModule {
-
-    public static final String AUTHORING_NODE = "authoring-node";
-    public static final String LIVE_NODE = "live-node";
-    public static final String TRASH_NODE = "trash-node";
-    public static final String ARCHIVE_NODE = "archive-node";
-    public static final String FIRST_CHILD_ID = "first-child-id";
-
-    protected static final String[] PARAMETER_NAMES = { AUTHORING_NODE, LIVE_NODE, TRASH_NODE, ARCHIVE_NODE, FIRST_CHILD_ID };
-
-    /**
-     * @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 {
-
-        Object value = null;
-
-        try {
-            PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-            Publication publication = envelope.getPublication();
-
-            if (name.equals(AUTHORING_NODE)) {
-                SiteTree authoringTree = publication.getTree(Publication.AUTHORING_AREA);
-                value = authoringTree.getNode(envelope.getDocument().getId());
+   public static final String AUTHORING_NODE = "authoring-node";
+   public static final String LIVE_NODE = "live-node";
+   public static final String TRASH_NODE = "trash-node";
+   public static final String ARCHIVE_NODE = "archive-node";
+   public static final String FIRST_CHILD_ID = "first-child-id";
+   protected static final String[] PARAMETER_NAMES = {AUTHORING_NODE, LIVE_NODE, TRASH_NODE, ARCHIVE_NODE, FIRST_CHILD_ID};
+   /**
+    * @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 {
+      Object value = null;
+      try{
+         PageEnvelope envelope = PageEnvelope.getCurrent();
+         Publication publication = envelope.getPublication();
+         if(name.equals(AUTHORING_NODE)){
+            SiteTree authoringTree = publication.getTree(Publication.AUTHORING_AREA);
+            value = authoringTree.getNode(envelope.getDocument().getId());
+         }
+         if(name.equals(LIVE_NODE)){
+            SiteTree liveTree = publication.getTree(Publication.LIVE_AREA);
+            value = liveTree.getNode(envelope.getDocument().getId());
+         }
+         if(name.equals(TRASH_NODE)){
+            SiteTree trashTree = publication.getTree(Publication.TRASH_AREA);
+            value = trashTree.getNode(envelope.getDocument().getId());
+         }
+         if(name.equals(ARCHIVE_NODE)){
+            SiteTree archiveTree = publication.getTree(Publication.ARCHIVE_AREA);
+            value = archiveTree.getNode(envelope.getDocument().getId());
+         }
+         if(name.equals(FIRST_CHILD_ID)){
+            SiteTree siteTree = publication.getTree(envelope.getDocument().getArea());
+            SiteTreeNode node = siteTree.getNode(envelope.getDocument().getId());
+            SiteTreeNode[] children = node.getChildren(envelope.getDocument().getLanguage());
+            if(children.length > 0){
+               value = children[0].getId();
+            }else{
+               value = null;
             }
-
-            if (name.equals(LIVE_NODE)) {
-                SiteTree liveTree = publication.getTree(Publication.LIVE_AREA);
-                value = liveTree.getNode(envelope.getDocument().getId());
-            }
-
-            if (name.equals(TRASH_NODE)) {
-                SiteTree trashTree = publication.getTree(Publication.TRASH_AREA);
-                value = trashTree.getNode(envelope.getDocument().getId());
-            }
-            
-            if (name.equals(ARCHIVE_NODE)) {
-                SiteTree archiveTree = publication.getTree(Publication.ARCHIVE_AREA);
-                value = archiveTree.getNode(envelope.getDocument().getId());
-            }
-            
-            if (name.equals(FIRST_CHILD_ID)) {
-                SiteTree siteTree = publication.getTree(envelope.getDocument().getArea());
-                SiteTreeNode node = siteTree.getNode(envelope.getDocument().getId()); 
-                SiteTreeNode[] children = node.getChildren(envelope.getDocument().getLanguage());
-                if (children.length > 0){
-                    value = children[0].getId();
-                } else {
-                    value = null;   
-                }
-            }
-
-        } catch (Exception e) {
-            throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
-        }
-
-        return value;
-    }
-
-    /**
-     * @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 Arrays.asList(PARAMETER_NAMES).iterator();
-    }
-
-    /**
-     * @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[] objects = { getAttribute(name, modeConf, objectModel) };
-        return objects;
-    }
-
+         }
+      }catch(Exception e){
+         throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
+      }
+      return value;
+   }
+   /**
+    * @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 Arrays.asList(PARAMETER_NAMES).iterator();
+   }
+   /**
+    * @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[] objects = {getAttribute(name, modeConf, objectModel)};
+      return objects;
+   }
 }

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=635107&r1=635106&r2=635107&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 Sat Mar  8 14:58:32 2008
@@ -13,6 +13,7 @@
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
 /**
  * Converts querystring Usecases into Module format.
  * 
@@ -21,16 +22,19 @@
 public class Usecase2ModuleModule extends AbstractPageEnvelopeModule 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)
+    * @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 [" + name + "]");
       }
       String resolvedUri = name;
-      PageEnvelope pe = getEnvelope(objectModel);
+      PageEnvelope pe;
+      try{
+         pe = PageEnvelope.getCurrent();
+      }catch(PageEnvelopeException e){
+         throw new ConfigurationException("Resolving page envelope failed: ", e);
+      }
       String publication = pe.getPublication().getId();
       Map contextmap = ContextHelper.getObjectModel(context);
       org.apache.cocoon.environment.http.HttpRequest req = (org.apache.cocoon.environment.http.HttpRequest) contextmap.get("request");
@@ -70,16 +74,13 @@
       return resolvedUri;
    }
    /**
-    * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
-    *      java.util.Map)
+    * @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();
    }
    /**
-    * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
-    *      org.apache.avalon.framework.configuration.Configuration,
-    *      java.util.Map)
+    * @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[] objects = {getAttribute(name, modeConf, objectModel)};

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java Sat Mar  8 14:58:32 2008
@@ -14,90 +14,67 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.cocoon.components.modules.input;
-
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Map;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.workflow.CMSHistory;
 import org.apache.lenya.cms.workflow.WorkflowFactory;
 import org.apache.lenya.workflow.WorkflowInstance;
-
 public class WorkflowModule extends AbstractInputModule {
-
-    public static final String STATE = "state";
-    public static final String VARIABLE_PREFIX = "variable.";
-    public static final String HISTORY_PATH = "history-path";
-
-    static final String[] PARAMETER_NAMES = { STATE, HISTORY_PATH };
-
-    /**
-     * @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 {
-
-        Object value = null;
-
-		
-        try {
-            PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-            Document document = envelope.getDocument();
-
-            WorkflowFactory factory = WorkflowFactory.newInstance();
-            if (factory.hasWorkflow(document)) {
-                WorkflowInstance instance = factory.buildInstance(document);
-                if (name.equals(STATE)) {
-                    value = instance.getCurrentState().toString();
-                }
-                else if (name.startsWith(VARIABLE_PREFIX)) {
-                    String variableName = name.substring(VARIABLE_PREFIX.length());
-                    String[] variableNames = instance.getWorkflow().getVariableNames();
-                    if (Arrays.asList(variableNames).contains(variableName)) {
-                        value = Boolean.valueOf(instance.getValue(variableName));
-                    }
-                }
-                else if (name.equals(HISTORY_PATH)) {
-                    value = ((CMSHistory) WorkflowFactory.getHistory(document)).getHistoryPath();
-                }
-				else {
-					throw new ConfigurationException("The attribute [" + name + "] is not supported!");
-				}
+   public static final String STATE = "state";
+   public static final String VARIABLE_PREFIX = "variable.";
+   public static final String HISTORY_PATH = "history-path";
+   static final String[] PARAMETER_NAMES = {STATE, HISTORY_PATH};
+   /**
+    * @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 {
+      Object value = null;
+      try{
+         PageEnvelope envelope = PageEnvelope.getCurrent();
+         Document document = envelope.getDocument();
+         WorkflowFactory factory = WorkflowFactory.newInstance();
+         if(factory.hasWorkflow(document)){
+            WorkflowInstance instance = factory.buildInstance(document);
+            if(name.equals(STATE)){
+               value = instance.getCurrentState().toString();
+            }else if(name.startsWith(VARIABLE_PREFIX)){
+               String variableName = name.substring(VARIABLE_PREFIX.length());
+               String[] variableNames = instance.getWorkflow().getVariableNames();
+               if(Arrays.asList(variableNames).contains(variableName)){
+                  value = Boolean.valueOf(instance.getValue(variableName));
+               }
+            }else if(name.equals(HISTORY_PATH)){
+               value = ((CMSHistory) WorkflowFactory.getHistory(document)).getHistoryPath();
+            }else{
+               throw new ConfigurationException("The attribute [" + name + "] is not supported!");
             }
-		} catch (ConfigurationException e) {
-			throw e;
-        } catch (Exception e) {
-            throw new ConfigurationException("Resolving attribute failed: ", e);
-        }
-        return value;
-    }
-
-    /**
-     * @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 Arrays.asList(PARAMETER_NAMES).iterator();
-    }
-
-    /**
-     * @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[] objects = { getAttribute(name, modeConf, objectModel)};
-
-        return objects;
-    }
-    
+         }
+      }catch(ConfigurationException e){
+         throw e;
+      }catch(Exception e){
+         throw new ConfigurationException("Resolving attribute failed: ", e);
+      }
+      return value;
+   }
+   /**
+    * @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 Arrays.asList(PARAMETER_NAMES).iterator();
+   }
+   /**
+    * @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[] objects = {getAttribute(name, modeConf, objectModel)};
+      return objects;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java Sat Mar  8 14:58:32 2008
@@ -1,5 +1,4 @@
 package org.apache.lenya.cms.cocoon.components.source.impl;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
@@ -7,48 +6,45 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceFactory;
 import org.apache.excalibur.source.SourceNotFoundException;
-
+import org.apache.lenya.util.Globals;
 public class VirtualSourceFactory implements SourceFactory, ThreadSafe {
-    static private Map sources = new HashMap();
-    static private Random random = new Random();
-    public Source getSource(String plocation, Map parameters) throws SourceNotFoundException {
-        String location = plocation;
-        // System.out.println("VS LOC=" + location);
-        int pos = location.lastIndexOf("/");
-        if ((pos > -1) && (pos + 1 < location.length()))
-            location = location.substring(pos + 1);
-        pos = location.lastIndexOf(":");
-        if ((pos > -1) && (pos + 1 < location.length()))
-            location = location.substring(pos + 1);
-        if (sources.containsKey(location))
-            return (Source) sources.get(location);
-        throw new SourceNotFoundException("VirtualSource not found: " + location);
-    }
-    public void release(Source source1) {
-        sources = null;
-    }
-    static public String addSource(Source source) {
-        return addSource(reserve(), source);
-    }
-    static public String addSource(String key, Source source) {
-        sources.put(key, source);
-        return key;
-    }
-    static public synchronized String reserve() {
-        String key = Integer.toString(random.nextInt(1000)) + getDateString();
-        while (hasKey(key))
-            key = key + Integer.toString(random.nextInt(1000));
-        sources.put(key, null);
-        return key;
-    }
-    static public void releaseSource(String key) {
-        if (hasKey(key))
-            sources.remove(key);
-    }
-    static public boolean hasKey(String key) {
-        return sources.containsKey(key);
-    }
-    static private String getDateString() {
-        return Long.toString(new java.util.Date().getTime());
-    }
+   static private Map sources = new HashMap();
+   static private Random random = new Random();
+   public Source getSource(String plocation, Map parameters) throws SourceNotFoundException {
+      String location = plocation;
+      // System.out.println("VS LOC=" + location);
+      int pos = location.lastIndexOf("/");
+      if((pos > -1) && (pos + 1 < location.length()))
+         location = location.substring(pos + 1);
+      pos = location.lastIndexOf(":");
+      if((pos > -1) && (pos + 1 < location.length()))
+         location = location.substring(pos + 1);
+      if(sources.containsKey(location))
+         return (Source) sources.get(location);
+      throw new SourceNotFoundException("VirtualSource not found: " + location);
+   }
+   public void release(Source source1) {
+      sources = null;
+   }
+   static public String addSource(Source source) {
+      return addSource(reserve(), source);
+   }
+   static public String addSource(String key, Source source) {
+      sources.put(key, source);
+      return key;
+   }
+   static public synchronized String reserve() {
+      String key = Integer.toString(random.nextInt(1000)) + Globals.getDateString();
+      while(hasKey(key))
+         key = key + Integer.toString(random.nextInt(1000));
+      sources.put(key, null);
+      return key;
+   }
+   static public void releaseSource(String key) {
+      if(hasKey(key))
+         sources.remove(key);
+   }
+   static public boolean hasKey(String key) {
+      return sources.containsKey(key);
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelper.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelper.java Sat Mar  8 14:58:32 2008
@@ -33,7 +33,6 @@
 import org.apache.lenya.cms.publication.DocumentHelper;
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.PageEnvelopeException;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.rc.FileReservedCheckInException;
 import org.apache.lenya.cms.rc.RCEnvironment;
@@ -95,8 +94,7 @@
     *            when something went wrong.
     */
    public PageEnvelope getPageEnvelope(FOM_Cocoon cocoon) throws PageEnvelopeException {
-      PageEnvelopeFactory factory = PageEnvelopeFactory.getInstance();
-      return factory.getPageEnvelope(cocoon.getObjectModel());
+      return PageEnvelope.getCurrent();
    }
    /**
     * Returns the request URI of the current request.

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=635107&r1=635106&r2=635107&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 Sat Mar  8 14:58:32 2008
@@ -22,7 +22,6 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.Map;
-
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameterizable;
 import org.apache.avalon.framework.parameters.Parameters;

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java Sat Mar  8 14:58:32 2008
@@ -14,14 +14,10 @@
  *  limitations under the License.
  *
  */
-
 /* @version $Id$*/
-
 package org.apache.lenya.cms.cocoon.generation;
-
 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;
@@ -30,467 +26,334 @@
 import org.apache.cocoon.generation.AbstractGenerator;
 import org.apache.lenya.cms.publication.Label;
 import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.SiteTree;
 import org.apache.lenya.cms.publication.SiteTreeException;
 import org.apache.lenya.cms.publication.SiteTreeNode;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
-
 /**
- * Generates a fragment of the XML from the sitetree, corresponding to a given
- * node. The node is specified by the sitemap parameters area/documentid. If the
- * sitemap parameter initialTree is true, the top nodes of the tree will be
- * generated and the node given by the sitemap parameters area/documentid will
- * be unfolded. If initialTree is false, only the children of the selected node
- * will be generated.
- *  
+ * Generates a fragment of the XML from the sitetree, corresponding to a given node. The node is specified by the sitemap parameters area/documentid. If the sitemap parameter initialTree is true, the top nodes of the tree will be generated and the node given by the sitemap parameters area/documentid will be unfolded. If initialTree is false, only the children of the selected node will be generated.
+ * 
  */
 public class SitetreeFragmentGenerator extends AbstractGenerator {
-
-    protected Publication publication;
-
-    /** Parameter which denotes the documentid of the clicked node */
-    protected String documentid;
-
-    /** Parameter which denotes the area of the clicked node */
-    protected String area;
-
-    /**
-     * Parameter which decides if the initial tree with the root nodes is
-     * generated
-     */
-    protected boolean initialTree;
-
-    /**
-     * Parameter which denotes a comma-separated list of areas, for which the
-     * xml will be generated.
-     */
-    protected String[] areas = null;
-
-    /**
-     * Convenience object, so we don't need to create an AttributesImpl for
-     * every element.
-     */
-    protected AttributesImpl attributes;
-
-    protected static final String PARAM_AREA = "area";
-
-    protected static final String PARAM_DOCUMENTID = "documentid";
-
-    protected static final String PARAM_INITIAL = "initial";
-
-    protected static final String PARAM_AREAS = "areas";
-
-    /** The URI of the namespace of this generator. */
-    protected static final String URI = "http://apache.org/cocoon/lenya/sitetree/1.0";
-
-    protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
-
-    /** The namespace prefix for this namespace. */
-    protected static final String PREFIX = "site";
-
-    protected static final String XML_PREFIX = "xml";
-
-    protected static final String NODE_NODE = "node";
-
-    protected static final String NODE_LABEL = "label";
-
-    protected static final String NODE_SITE = "site";
-
-    protected static final String NODE_FRAGMENT = "fragment";
-
-    protected static final String ATTR_ID = "id";
-
-    protected static final String ATTR_FOLDER = "folder";
-
-    protected static final String ATTR_AREA = "area";
-
-    protected static final String ATTR_LABEL = "label";
-
-    protected static final String ATTR_VISIBLEINNAV = "visibleinnav";
-
-    protected static final String ATTR_LINK = "link";
-
-    protected static final String ATTR_BASE = "base";
-
-    protected static final String ATTR_SUFFIX = "suffix";
-
-    protected static final String ATTR_HREF = "href";
-
-    protected static final String ATTR_LANG = "lang";
-
-    /**
-     * @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 {
-        super.setup(resolver, objectModel, src, par);
-
-        PageEnvelope envelope = null;
-
-        if (getLogger().isDebugEnabled()) {
-            Request request = ObjectModelHelper.getRequest(objectModel);
-            getLogger().debug(
-                    "Resolving page envelope for URL ["
-                            + request.getRequestURI() + "]");
-        }
-
-        this.area = par.getParameter(PARAM_AREA, null);
-        this.documentid = par.getParameter(PARAM_DOCUMENTID, null);
-
-        if (par.isParameter(PARAM_INITIAL)) {
-            this.initialTree = Boolean.valueOf(
-                    par.getParameter(PARAM_INITIAL, null)).booleanValue();
-        } else {
-            this.initialTree = false;
-        }
-
-        if (par.isParameter(PARAM_AREAS)) {
-            String parAreas = par.getParameter(PARAM_AREAS, null);
-            this.areas = parAreas.split(",");
-        } else {
-            String temp[] = { "authoring", "archive", "trash" };
-            this.areas = temp;
-        }
-
-        if (this.getLogger().isDebugEnabled()) {
-            this.getLogger().debug("Parameter area: " + this.area);
-            this.getLogger().debug("Parameter documentid: " + this.documentid);
-            this.getLogger()
-                    .debug("Parameter initialTree: " + this.initialTree);
-            String areasStr = "";
-            for (int i = 0; i < this.areas.length; i++)
-                areasStr += this.areas[i] + " ";
-            this.getLogger().debug("Parameter areas: " + areasStr);
-        }
-
-        try {
-            envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(
-                    objectModel);
-        } catch (Exception e) {
-            throw new ProcessingException("Resolving page envelope failed: ", e);
-        }
-
-        this.publication = envelope.getPublication();
-        this.attributes = new AttributesImpl();
-
-    }
-
-    /**
-     * @see org.apache.cocoon.generation.Generator#generate()
-     */
-    public void generate() throws IOException, SAXException,
-            ProcessingException {
-
-        try {
-
-            this.contentHandler.startDocument();
-            this.contentHandler.startPrefixMapping(PREFIX, URI);
-
-            attributes.clear();
-            if (!initialTree) {
-                attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
-                        this.area);
-                attributes.addAttribute("", ATTR_BASE, ATTR_BASE, "CDATA",
-                        this.documentid);
+   protected Publication publication;
+   /** Parameter which denotes the documentid of the clicked node */
+   protected String documentid;
+   /** Parameter which denotes the area of the clicked node */
+   protected String area;
+   /**
+    * Parameter which decides if the initial tree with the root nodes is generated
+    */
+   protected boolean initialTree;
+   /**
+    * Parameter which denotes a comma-separated list of areas, for which the xml will be generated.
+    */
+   protected String[] areas = null;
+   /**
+    * Convenience object, so we don't need to create an AttributesImpl for every element.
+    */
+   protected AttributesImpl attributes;
+   protected static final String PARAM_AREA = "area";
+   protected static final String PARAM_DOCUMENTID = "documentid";
+   protected static final String PARAM_INITIAL = "initial";
+   protected static final String PARAM_AREAS = "areas";
+   /** The URI of the namespace of this generator. */
+   protected static final String URI = "http://apache.org/cocoon/lenya/sitetree/1.0";
+   protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
+   /** The namespace prefix for this namespace. */
+   protected static final String PREFIX = "site";
+   protected static final String XML_PREFIX = "xml";
+   protected static final String NODE_NODE = "node";
+   protected static final String NODE_LABEL = "label";
+   protected static final String NODE_SITE = "site";
+   protected static final String NODE_FRAGMENT = "fragment";
+   protected static final String ATTR_ID = "id";
+   protected static final String ATTR_FOLDER = "folder";
+   protected static final String ATTR_AREA = "area";
+   protected static final String ATTR_LABEL = "label";
+   protected static final String ATTR_VISIBLEINNAV = "visibleinnav";
+   protected static final String ATTR_LINK = "link";
+   protected static final String ATTR_BASE = "base";
+   protected static final String ATTR_SUFFIX = "suffix";
+   protected static final String ATTR_HREF = "href";
+   protected static final String ATTR_LANG = "lang";
+   /**
+    * @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 {
+      super.setup(resolver, objectModel, src, par);
+      PageEnvelope envelope = null;
+      if(getLogger().isDebugEnabled()){
+         Request request = ObjectModelHelper.getRequest(objectModel);
+         getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
+      }
+      this.area = par.getParameter(PARAM_AREA, null);
+      this.documentid = par.getParameter(PARAM_DOCUMENTID, null);
+      if(par.isParameter(PARAM_INITIAL)){
+         this.initialTree = Boolean.valueOf(par.getParameter(PARAM_INITIAL, null)).booleanValue();
+      }else{
+         this.initialTree = false;
+      }
+      if(par.isParameter(PARAM_AREAS)){
+         String parAreas = par.getParameter(PARAM_AREAS, null);
+         this.areas = parAreas.split(",");
+      }else{
+         String temp[] = {"authoring", "archive", "trash"};
+         this.areas = temp;
+      }
+      if(this.getLogger().isDebugEnabled()){
+         this.getLogger().debug("Parameter area: " + this.area);
+         this.getLogger().debug("Parameter documentid: " + this.documentid);
+         this.getLogger().debug("Parameter initialTree: " + this.initialTree);
+         String areasStr = "";
+         for(int i = 0; i < this.areas.length; i++)
+            areasStr += this.areas[i] + " ";
+         this.getLogger().debug("Parameter areas: " + areasStr);
+      }
+      try{
+         envelope = PageEnvelope.getCurrent();
+      }catch(Exception e){
+         throw new ProcessingException("Resolving page envelope failed: ", e);
+      }
+      this.publication = envelope.getPublication();
+      this.attributes = new AttributesImpl();
+   }
+   /**
+    * @see org.apache.cocoon.generation.Generator#generate()
+    */
+   public void generate() throws IOException, SAXException, ProcessingException {
+      try{
+         this.contentHandler.startDocument();
+         this.contentHandler.startPrefixMapping(PREFIX, URI);
+         attributes.clear();
+         if(!initialTree){
+            attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA", this.area);
+            attributes.addAttribute("", ATTR_BASE, ATTR_BASE, "CDATA", this.documentid);
+         }
+         this.contentHandler.startElement(URI, NODE_FRAGMENT, PREFIX + ':' + NODE_FRAGMENT, this.attributes);
+         if(this.initialTree){
+            for(int i = 0; i < this.areas.length; i++){
+               generateFragmentInitial(this.areas[i]);
             }
-
-            this.contentHandler.startElement(URI, NODE_FRAGMENT, PREFIX + ':'
-                    + NODE_FRAGMENT, this.attributes);
-
-            if (this.initialTree) {
-                for (int i = 0; i < this.areas.length; i++) {
-                    generateFragmentInitial(this.areas[i]);
-                }
-            } else {
-                generateFragment();
-            }
-
-            this.contentHandler.endElement(URI, NODE_FRAGMENT, PREFIX + ':'
-                    + NODE_FRAGMENT);
-
-            this.contentHandler.endPrefixMapping(PREFIX);
-            this.contentHandler.endDocument();
-
-        } catch (SAXException e) {
-            throw new ProcessingException(e);
-        } catch (SiteTreeException e) {
-            throw new ProcessingException(e);
-        }
-
-    }
-
-    /**
-     * Generates a fragment of the tree which contains the children of a given
-     * node.
-     * 
-     * @throws SiteTreeException
-     * @throws SAXException
-     * @throws ProcessingException
-     */
-    protected void generateFragment() throws SiteTreeException, SAXException,
-            ProcessingException {
-
-        SiteTree siteTree = null;
-        if (!this.area.equals(Publication.AUTHORING_AREA)
-                && !this.area.equals(Publication.ARCHIVE_AREA)
-                && !this.area.equals(Publication.TRASH_AREA)
-                && !this.area.equals(Publication.STAGING_AREA)
-                && !this.area.equals(Publication.LIVE_AREA)) {
-            throw new ProcessingException("Invalid area: " + this.area);
-        }
-        siteTree = publication.getTree(this.area);
-
-        SiteTreeNode node = siteTree.getNode(this.documentid);
-        if (this.getLogger().isDebugEnabled()) {
-            this.getLogger().debug(
-                    "Node with documentid " + documentid + " found.");
-        }
-        if (node == null)
-            throw new SiteTreeException("Node with documentid " + documentid
-                    + " not found.");
-
-        SiteTreeNode[] children = node.getChildren();
-
-        for (int i = 0; i < children.length; i++) {
-            startNode(NODE_NODE, children[i]);
-            addLabels(children[i]);
-            endNode(NODE_NODE);
-        }
-    }
-
-    /**
-     * Generates the top node of the given area and then calls a recursive
-     * method to traverse the tree, if the node given by area/documentid is in
-     * this area.
-     * 
-     * @param siteArea
-     * @throws SiteTreeException
-     * @throws SAXException
-     * @throws ProcessingException
-     */
-    protected void generateFragmentInitial(String siteArea)
-            throws SiteTreeException, SAXException, ProcessingException {
-
-        SiteTree siteTree = publication.getTree(siteArea);
-
-        String label = "";
-        String isFolder = "";
-
-        // FIXME: don't hardcode area label
-        if (siteArea.equals(Publication.AUTHORING_AREA))
-            label = "Authoring";
-        if (siteArea.equals(Publication.ARCHIVE_AREA))
-            label = "Archive";
-        if (siteArea.equals(Publication.TRASH_AREA))
-            label = "Trash";
-        if (siteArea.equals(Publication.LIVE_AREA))
-            label = "Live";
-        if (siteArea.equals(Publication.STAGING_AREA))
-            label = "Staging";
-
-        if (siteTree.getTopNodes().length > 0)
-            isFolder = "true";
-        else
-            isFolder = "false";
-
-        this.attributes.clear();
-        this.attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
-                siteArea);
-        this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
-                isFolder);
-        this.attributes
-                .addAttribute("", ATTR_LABEL, ATTR_LABEL, "CDATA", label);
-
-        startNode(NODE_SITE);
-
-        if (area.equals(siteArea)) {
-            generateFragmentRecursive(siteTree.getTopNodes(), this.documentid);
-        }
-
-        endNode(NODE_SITE);
-    }
-
-    /**
-     * Follows the documentid to find the way in the sitetree to the specified
-     * node and opens all folders on its way.
-     * 
-     * @param nodes
-     * @param docid
-     * @throws SiteTreeException
-     * @throws SAXException
-     */
-    protected void generateFragmentRecursive(SiteTreeNode[] nodes, String docid)
-            throws SiteTreeException, SAXException {
-        String nodeid;
-        String childid;
-
-        if (nodes == null)
-            return;
-        if (docid.startsWith("/"))
-            docid = docid.substring(1);
-        if (docid.indexOf("/") != -1) {
-            nodeid = docid.substring(0, docid.indexOf("/"));
-            childid = docid.substring(docid.indexOf("/") + 1);
-        } else {
-            nodeid = docid;
-            childid = "";
-        }
-
-        for (int i = 0; i < nodes.length; i++) {
-            startNode(NODE_NODE, nodes[i]);
-            addLabels(nodes[i]);
-            if (nodes[i].getId().equals(nodeid)) {
-                generateFragmentRecursive(nodes[i].getChildren(), childid);
-            }
-            endNode(NODE_NODE);
-        }
-    }
-
-    /**
-     * Begins a named node and calls setNodeAttributes to set its attributes.
-     * 
-     * @param nodeName
-     *            the name of the new node
-     * @throws SAXException
-     *             if an error occurs while creating the node
-     */
-    protected void startNode(String nodeName) throws SAXException {
-        this.contentHandler.startElement(URI, nodeName,
-                PREFIX + ':' + nodeName, this.attributes);
-    }
-
-    /**
-     * Begins a named node and calls setNodeAttributes to set its attributes.
-     * 
-     * @param nodeName
-     *            the name of the new node
-     * @param node
-     *            The attributes are taken from this node
-     * @throws SAXException
-     *             if an error occurs while creating the node
-     */
-    protected void startNode(String nodeName, SiteTreeNode node)
-            throws SAXException {
-        setNodeAttributes(node);
-        this.contentHandler.startElement(URI, nodeName,
-                PREFIX + ':' + nodeName, this.attributes);
-    }
-
-    /**
-     * Sets the attributes for a given node. Sets attributes id, href, folder,
-     * suffix, basic-url, language-suffix.
-     * 
-     * @param node
-     * @throws SAXException
-     *             if an error occurs while setting the attributes
-     */
-    protected void setNodeAttributes(SiteTreeNode node) throws SAXException {
-        this.attributes.clear();
-
-        String id = node.getId();
-        String isVisible = Boolean.toString(node.visibleInNav());
-        String hasLink = Boolean.toString(node.hasLink());
-        String href = node.getHref();
-        String suffix = node.getSuffix();
-        String isFolder = isFolder(node);
-
-        if (this.getLogger().isDebugEnabled()) {
-            this.getLogger().debug("adding attribute id: " + id);
-            this.getLogger().debug(
-                    "adding attribute visibleinnav: " + isVisible);
-            this.getLogger().debug("adding attribute link: " + hasLink);
-            if (href != null)
-                this.getLogger().debug("adding attribute href: " + href);
-            if (suffix != null)
-                this.getLogger().debug("adding attribute suffix: " + suffix);
-            this.getLogger().debug("adding attribute folder: " + isFolder);
-        }
-        this.attributes.addAttribute("", ATTR_ID, ATTR_ID, "CDATA", id);
-        this.attributes.addAttribute("", ATTR_VISIBLEINNAV, ATTR_VISIBLEINNAV,
-                "CDATA", isVisible);
-        this.attributes
-                .addAttribute("", ATTR_LINK, ATTR_LINK, "CDATA", hasLink);
-        if (href != null)
-            this.attributes.addAttribute("", ATTR_HREF, ATTR_HREF, "CDATA",
-                    href);
-        if (suffix != null)
-            this.attributes.addAttribute("", ATTR_SUFFIX, ATTR_SUFFIX, "CDATA",
-                    suffix);
-        this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
-                isFolder);
-    }
-
-    /**
-     * Returns a value to indicate whether a node is a folder (contains
-     * subnodes). With the incremental sitetree loading, we sometimes load nodes
-     * which are folders, but we don't load their children. But we still have to
-     * know if it's a folder or not, i.e. if it can be opened.
-     * 
-     * @param node
-     * @return "true" or "false"
-     */
-    protected String isFolder(SiteTreeNode node) {
-        if (node.getChildren().length > 0)
-            return "true";
-        else
-            return "false";
-    }
-
-    /**
-     * Ends the named node.
-     * 
-     * @param nodeName
-     *            the name of the new node
-     * @throws SAXException
-     *             if an error occurs while closing the node
-     */
-    protected void endNode(String nodeName) throws SAXException {
-        this.contentHandler.endElement(URI, nodeName, PREFIX + ':' + nodeName);
-    }
-
-    /**
-     * Finds all the label children of a node and adds them to the nav xml.
-     * 
-     * @param node
-     * @throws SAXException
-     */
-    protected void addLabels(SiteTreeNode node) throws SAXException {
-        Label[] labels = node.getLabels();
-
-        for (int i = 0; i < labels.length; i++) {
-            String lang = labels[i].getLanguage();
-            if (lang == null)
-                lang = "";
-            addLabel(labels[i].getLabel(), lang);
-        }
-    }
-
-    /**
-     * Adds a label element of a given language.
-     * 
-     * @param label
-     *            the value of the label
-     * @param language
-     *            the language of the label
-     * @throws SAXException
-     */
-    protected void addLabel(String label, String language) throws SAXException {
-        this.attributes.clear();
-        this.attributes.addAttribute(XML_URI, ATTR_LANG, XML_PREFIX + ":"
-                + ATTR_LANG, "CDATA", language);
-
-        this.contentHandler.startElement(URI, NODE_LABEL, PREFIX + ':'
-                + NODE_LABEL, this.attributes);
-        char[] labelArray = label.toCharArray();
-        this.contentHandler.characters(labelArray, 0, labelArray.length);
-        this.contentHandler.endElement(URI, NODE_LABEL, PREFIX + ':'
-                + NODE_LABEL);
-    }
-
+         }else{
+            generateFragment();
+         }
+         this.contentHandler.endElement(URI, NODE_FRAGMENT, PREFIX + ':' + NODE_FRAGMENT);
+         this.contentHandler.endPrefixMapping(PREFIX);
+         this.contentHandler.endDocument();
+      }catch(SAXException e){
+         throw new ProcessingException(e);
+      }catch(SiteTreeException e){
+         throw new ProcessingException(e);
+      }
+   }
+   /**
+    * Generates a fragment of the tree which contains the children of a given node.
+    * 
+    * @throws SiteTreeException
+    * @throws SAXException
+    * @throws ProcessingException
+    */
+   protected void generateFragment() throws SiteTreeException, SAXException, ProcessingException {
+      SiteTree siteTree = null;
+      if(!this.area.equals(Publication.AUTHORING_AREA) && !this.area.equals(Publication.ARCHIVE_AREA) && !this.area.equals(Publication.TRASH_AREA) && !this.area.equals(Publication.STAGING_AREA) && !this.area.equals(Publication.LIVE_AREA)){
+         throw new ProcessingException("Invalid area: " + this.area);
+      }
+      siteTree = publication.getTree(this.area);
+      SiteTreeNode node = siteTree.getNode(this.documentid);
+      if(this.getLogger().isDebugEnabled()){
+         this.getLogger().debug("Node with documentid " + documentid + " found.");
+      }
+      if(node == null)
+         throw new SiteTreeException("Node with documentid " + documentid + " not found.");
+      SiteTreeNode[] children = node.getChildren();
+      for(int i = 0; i < children.length; i++){
+         startNode(NODE_NODE, children[i]);
+         addLabels(children[i]);
+         endNode(NODE_NODE);
+      }
+   }
+   /**
+    * Generates the top node of the given area and then calls a recursive method to traverse the tree, if the node given by area/documentid is in this area.
+    * 
+    * @param siteArea
+    * @throws SiteTreeException
+    * @throws SAXException
+    * @throws ProcessingException
+    */
+   protected void generateFragmentInitial(String siteArea) throws SiteTreeException, SAXException, ProcessingException {
+      SiteTree siteTree = publication.getTree(siteArea);
+      String label = "";
+      String isFolder = "";
+      // FIXME: don't hardcode area label
+      if(siteArea.equals(Publication.AUTHORING_AREA))
+         label = "Authoring";
+      if(siteArea.equals(Publication.ARCHIVE_AREA))
+         label = "Archive";
+      if(siteArea.equals(Publication.TRASH_AREA))
+         label = "Trash";
+      if(siteArea.equals(Publication.LIVE_AREA))
+         label = "Live";
+      if(siteArea.equals(Publication.STAGING_AREA))
+         label = "Staging";
+      if(siteTree.getTopNodes().length > 0)
+         isFolder = "true";
+      else
+         isFolder = "false";
+      this.attributes.clear();
+      this.attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA", siteArea);
+      this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA", isFolder);
+      this.attributes.addAttribute("", ATTR_LABEL, ATTR_LABEL, "CDATA", label);
+      startNode(NODE_SITE);
+      if(area.equals(siteArea)){
+         generateFragmentRecursive(siteTree.getTopNodes(), this.documentid);
+      }
+      endNode(NODE_SITE);
+   }
+   /**
+    * Follows the documentid to find the way in the sitetree to the specified node and opens all folders on its way.
+    * 
+    * @param nodes
+    * @param docid
+    * @throws SiteTreeException
+    * @throws SAXException
+    */
+   protected void generateFragmentRecursive(SiteTreeNode[] nodes, String docid) throws SiteTreeException, SAXException {
+      String nodeid;
+      String childid;
+      if(nodes == null)
+         return;
+      if(docid.startsWith("/"))
+         docid = docid.substring(1);
+      if(docid.indexOf("/") != -1){
+         nodeid = docid.substring(0, docid.indexOf("/"));
+         childid = docid.substring(docid.indexOf("/") + 1);
+      }else{
+         nodeid = docid;
+         childid = "";
+      }
+      for(int i = 0; i < nodes.length; i++){
+         startNode(NODE_NODE, nodes[i]);
+         addLabels(nodes[i]);
+         if(nodes[i].getId().equals(nodeid)){
+            generateFragmentRecursive(nodes[i].getChildren(), childid);
+         }
+         endNode(NODE_NODE);
+      }
+   }
+   /**
+    * Begins a named node and calls setNodeAttributes to set its attributes.
+    * 
+    * @param nodeName
+    *           the name of the new node
+    * @throws SAXException
+    *            if an error occurs while creating the node
+    */
+   protected void startNode(String nodeName) throws SAXException {
+      this.contentHandler.startElement(URI, nodeName, PREFIX + ':' + nodeName, this.attributes);
+   }
+   /**
+    * Begins a named node and calls setNodeAttributes to set its attributes.
+    * 
+    * @param nodeName
+    *           the name of the new node
+    * @param node
+    *           The attributes are taken from this node
+    * @throws SAXException
+    *            if an error occurs while creating the node
+    */
+   protected void startNode(String nodeName, SiteTreeNode node) throws SAXException {
+      setNodeAttributes(node);
+      this.contentHandler.startElement(URI, nodeName, PREFIX + ':' + nodeName, this.attributes);
+   }
+   /**
+    * Sets the attributes for a given node. Sets attributes id, href, folder, suffix, basic-url, language-suffix.
+    * 
+    * @param node
+    * @throws SAXException
+    *            if an error occurs while setting the attributes
+    */
+   protected void setNodeAttributes(SiteTreeNode node) throws SAXException {
+      this.attributes.clear();
+      String id = node.getId();
+      String isVisible = Boolean.toString(node.visibleInNav());
+      String hasLink = Boolean.toString(node.hasLink());
+      String href = node.getHref();
+      String suffix = node.getSuffix();
+      String isFolder = isFolder(node);
+      if(this.getLogger().isDebugEnabled()){
+         this.getLogger().debug("adding attribute id: " + id);
+         this.getLogger().debug("adding attribute visibleinnav: " + isVisible);
+         this.getLogger().debug("adding attribute link: " + hasLink);
+         if(href != null)
+            this.getLogger().debug("adding attribute href: " + href);
+         if(suffix != null)
+            this.getLogger().debug("adding attribute suffix: " + suffix);
+         this.getLogger().debug("adding attribute folder: " + isFolder);
+      }
+      this.attributes.addAttribute("", ATTR_ID, ATTR_ID, "CDATA", id);
+      this.attributes.addAttribute("", ATTR_VISIBLEINNAV, ATTR_VISIBLEINNAV, "CDATA", isVisible);
+      this.attributes.addAttribute("", ATTR_LINK, ATTR_LINK, "CDATA", hasLink);
+      if(href != null)
+         this.attributes.addAttribute("", ATTR_HREF, ATTR_HREF, "CDATA", href);
+      if(suffix != null)
+         this.attributes.addAttribute("", ATTR_SUFFIX, ATTR_SUFFIX, "CDATA", suffix);
+      this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA", isFolder);
+   }
+   /**
+    * Returns a value to indicate whether a node is a folder (contains subnodes). With the incremental sitetree loading, we sometimes load nodes which are folders, but we don't load their children. But we still have to know if it's a folder or not, i.e. if it can be opened.
+    * 
+    * @param node
+    * @return "true" or "false"
+    */
+   protected String isFolder(SiteTreeNode node) {
+      if(node.getChildren().length > 0)
+         return "true";
+      else
+         return "false";
+   }
+   /**
+    * Ends the named node.
+    * 
+    * @param nodeName
+    *           the name of the new node
+    * @throws SAXException
+    *            if an error occurs while closing the node
+    */
+   protected void endNode(String nodeName) throws SAXException {
+      this.contentHandler.endElement(URI, nodeName, PREFIX + ':' + nodeName);
+   }
+   /**
+    * Finds all the label children of a node and adds them to the nav xml.
+    * 
+    * @param node
+    * @throws SAXException
+    */
+   protected void addLabels(SiteTreeNode node) throws SAXException {
+      Label[] labels = node.getLabels();
+      for(int i = 0; i < labels.length; i++){
+         String lang = labels[i].getLanguage();
+         if(lang == null)
+            lang = "";
+         addLabel(labels[i].getLabel(), lang);
+      }
+   }
+   /**
+    * Adds a label element of a given language.
+    * 
+    * @param label
+    *           the value of the label
+    * @param language
+    *           the language of the label
+    * @throws SAXException
+    */
+   protected void addLabel(String label, String language) throws SAXException {
+      this.attributes.clear();
+      this.attributes.addAttribute(XML_URI, ATTR_LANG, XML_PREFIX + ":" + ATTR_LANG, "CDATA", language);
+      this.contentHandler.startElement(URI, NODE_LABEL, PREFIX + ':' + NODE_LABEL, this.attributes);
+      char[] labelArray = label.toCharArray();
+      this.contentHandler.characters(labelArray, 0, labelArray.length);
+      this.contentHandler.endElement(URI, NODE_LABEL, PREFIX + ':' + NODE_LABEL);
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/scheduler/SchedulerHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/scheduler/SchedulerHelper.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/scheduler/SchedulerHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/scheduler/SchedulerHelper.java Sat Mar  8 14:58:32 2008
@@ -14,76 +14,60 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.cocoon.scheduler;
-
 import java.util.HashMap;
 import java.util.Map;
-
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
 import org.apache.lenya.cms.cocoon.task.CocoonTaskWrapper;
 import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.scheduler.LoadQuartzServlet;
 import org.apache.lenya.cms.scheduler.ServletJob;
 import org.apache.lenya.cms.task.TaskWrapper;
 import org.apache.lenya.util.NamespaceMap;
-
 public class SchedulerHelper {
-
-    /**
-     * Ctor.
-     * @param objectModel The Cocoon component object model.
-     * @param parameters The Cocoon component parameters.
-     * @param logger The logger to use.
-     */
-    public SchedulerHelper(Map objectModel, Parameters parameters, Logger logger) {
-        this.objectModel = objectModel;
-        this.parameters = parameters;
-        this.logger = logger;
-    }
-
-    private Logger logger;
-    private Parameters parameters;
-    private Map objectModel;
-
-    /**
-     * Creates the scheduler parameters.
-     * @return A map.
-     * @throws ProcessingException when something went wrong.
-     */
-    public Map createParameters() throws ProcessingException {
-
-        Map map = new HashMap();
-
-        try {
-            TaskWrapper wrapper = new CocoonTaskWrapper(objectModel, parameters);
-
-            logger.debug("Adding task wrapper parameters");
-            Map wrapperParameters = wrapper.getParameters();
-            map.putAll(wrapperParameters);
-
-            NamespaceMap schedulerParameters = new NamespaceMap(LoadQuartzServlet.PREFIX);
-
-            PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-
-            schedulerParameters.put(
-                ServletJob.PARAMETER_DOCUMENT_URL,
-                envelope.getDocument().getCompleteURL());
-            schedulerParameters.put(
-                LoadQuartzServlet.PARAMETER_PUBLICATION_ID,
-                envelope.getPublication().getId());
-            map.putAll(schedulerParameters.getPrefixedMap());
-
-        } catch (Exception e) {
-            throw new ProcessingException(e);
-        }
-
-        return map;
-    }
-
+   /**
+    * Ctor.
+    * 
+    * @param objectModel
+    *           The Cocoon component object model.
+    * @param parameters
+    *           The Cocoon component parameters.
+    * @param logger
+    *           The logger to use.
+    */
+   public SchedulerHelper(Map objectModel, Parameters parameters, Logger logger) {
+      this.objectModel = objectModel;
+      this.parameters = parameters;
+      this.logger = logger;
+   }
+   private Logger logger;
+   private Parameters parameters;
+   private Map objectModel;
+   /**
+    * Creates the scheduler parameters.
+    * 
+    * @return A map.
+    * @throws ProcessingException
+    *            when something went wrong.
+    */
+   public Map createParameters() throws ProcessingException {
+      Map map = new HashMap();
+      try{
+         TaskWrapper wrapper = new CocoonTaskWrapper(objectModel, parameters);
+         logger.debug("Adding task wrapper parameters");
+         Map wrapperParameters = wrapper.getParameters();
+         map.putAll(wrapperParameters);
+         NamespaceMap schedulerParameters = new NamespaceMap(LoadQuartzServlet.PREFIX);
+         PageEnvelope envelope = PageEnvelope.getCurrent();
+         schedulerParameters.put(ServletJob.PARAMETER_DOCUMENT_URL, envelope.getDocument().getCompleteURL());
+         schedulerParameters.put(LoadQuartzServlet.PARAMETER_PUBLICATION_ID, envelope.getPublication().getId());
+         map.putAll(schedulerParameters.getPrefixedMap());
+      }catch(Exception e){
+         throw new ProcessingException(e);
+      }
+      return map;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/source/SourceUtil.java Sat Mar  8 14:58:32 2008
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-
 import org.apache.commons.io.CopyUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.excalibur.source.ModifiableSource;

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java Sat Mar  8 14:58:32 2008
@@ -21,7 +21,6 @@
 
 import java.io.IOException;
 import java.util.Map;
-
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceSelector;

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java Sat Mar  8 14:58:32 2008
@@ -14,17 +14,13 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.cocoon.transformation;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameterizable;
 import org.apache.avalon.framework.parameters.Parameters;
@@ -36,244 +32,184 @@
 import org.apache.lenya.cms.publication.DocumentBuilder;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.SiteTree;
 import org.apache.lenya.cms.publication.SiteTreeNode;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
-
 /**
- * This transformer lists the children of a document if the tag <namespaceURI:children> 
- * is present in this document. The list of the children is in the form :
- * <namespaceURI:children>
- *   <child href="....html>
- *     <ci:include src="..." element="included"/> 
- *   </child>
- *   ...
- * </namespaceURI:children>
- * Multiple language : if a child doesn't exist in the parent language, then the version 
- * in the default language will be considered. If it doesn't exist too, any other existent 
- * language will be considered.
+ * This transformer lists the children of a document if the tag <namespaceURI:children> is present in this document. The list of the children is in the form : <namespaceURI:children> <child href="....html> <ci:include src="..." element="included"/> </child> ... </namespaceURI:children> Multiple language : if a child doesn't exist in the parent language, then the version in the default language will be considered. If it doesn't exist too, any other existent language will be considered.
  */
 public class DocumentIndexTransformer extends AbstractSAXTransformer implements Parameterizable {
-
-    private String namespace;
-    private String cIncludeNamespace;
-
-    public static final String CHILDREN_ELEMENT = "children";
-    public static final String ABSTRACT_ATTRIBUTE = "abstract";
-    
-    public static final String NAMESPACE = "http://apache.org/cocoon/lenya/documentindex/1.0";
-    public static final String PREFIX = "index:";
-
-    /** (non-Javadoc)
-    	 * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
-    	 */
-    public void parameterize(Parameters parameters) throws ParameterException {
-        this.namespace = parameters.getParameter("namespace", null);
-        this.cIncludeNamespace = parameters.getParameter("cIncludeNamespace", null);
-    }
-
-    private Document document;
-
-    private Publication publication;
-
-    private String area;
-
-    private DocumentBuilder builder;
-
-    private SiteTree siteTree;
-
-    /** (non-Javadoc)
-     * @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 {
-        try {
-
-        	super.setup(resolver, objectModel, src, parameters);
-
-        	parameterize(parameters);
-
-            PageEnvelope envelope = null;
-            envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-
-            setDocument(envelope.getDocument());
-            setPublication(document.getPublication());
-            setArea(document.getArea());
-            setBuilder(document.getPublication().getDocumentBuilder());
-            setSiteTree(publication.getTree(area));
-
-        } catch (Exception e) {
-            throw new ProcessingException(e);
-        }
-
-    }
-
-    /** (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 {
-
-        if (uri != null
-            && uri.equals(namespace)
-            && cIncludeNamespace != null
-            && localName.equals(CHILDREN_ELEMENT)) {
-                
-            if (getLogger().isInfoEnabled()) {
-                getLogger().info("Inserting index");
+   private String namespace;
+   private String cIncludeNamespace;
+   public static final String CHILDREN_ELEMENT = "children";
+   public static final String ABSTRACT_ATTRIBUTE = "abstract";
+   public static final String NAMESPACE = "http://apache.org/cocoon/lenya/documentindex/1.0";
+   public static final String PREFIX = "index:";
+   /**
+    * (non-Javadoc)
+    * 
+    * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+    */
+   public void parameterize(Parameters parameters) throws ParameterException {
+      this.namespace = parameters.getParameter("namespace", null);
+      this.cIncludeNamespace = parameters.getParameter("cIncludeNamespace", null);
+   }
+   private Document document;
+   private Publication publication;
+   private String area;
+   private DocumentBuilder builder;
+   private SiteTree siteTree;
+   /**
+    * (non-Javadoc)
+    * 
+    * @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 {
+      try{
+         super.setup(resolver, objectModel, src, parameters);
+         parameterize(parameters);
+         PageEnvelope envelope = null;
+         envelope = PageEnvelope.getCurrent();
+         setDocument(envelope.getDocument());
+         setPublication(document.getPublication());
+         setArea(document.getArea());
+         setBuilder(document.getPublication().getDocumentBuilder());
+         setSiteTree(publication.getTree(area));
+      }catch(Exception e){
+         throw new ProcessingException(e);
+      }
+   }
+   /**
+    * (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 {
+      if(uri != null && uri.equals(namespace) && cIncludeNamespace != null && localName.equals(CHILDREN_ELEMENT)){
+         if(getLogger().isInfoEnabled()){
+            getLogger().info("Inserting index");
+         }
+         String cIncludePrefix = "";
+         if(!this.cIncludeNamespace.equals("")){
+            cIncludePrefix = "ci:";
+         }
+         String documentId = document.getId();
+         String language = document.getLanguage();
+         String defaultLanguage = publication.getDefaultLanguage();
+         SiteTreeNode[] children = siteTree.getNode(documentId).getChildren();
+         super.startElement(uri, localName, raw, attr);
+         for(int i = 0; i < children.length; i++){
+            String childId = documentId + "/" + children[i].getId();
+            // get child document with the same language than the parent document
+            String url = builder.buildCanonicalUrl(publication, area, childId, language);
+            Document doc;
+            try{
+               doc = builder.buildDocument(publication, url);
+            }catch(DocumentBuildException e){
+               throw new SAXException(e);
             }
-
-            String cIncludePrefix = "";
-            if (!this.cIncludeNamespace.equals("")) {
-                cIncludePrefix = "ci:";
+            File file = doc.getFile();
+            if(!file.exists()){
+               // get first the child document in the default language and then in any other existent language
+               getLogger().debug("There is no child file " + file.getAbsolutePath() + " in the same language as the parent document [" + language + "]");
+               // available language
+               String[] availableLanguages = null;
+               try{
+                  availableLanguages = doc.getLanguages();
+               }catch(DocumentException e){
+                  throw new SAXException(e);
+               }
+               List languages = new ArrayList();
+               for(int l = 0; l < availableLanguages.length; l++){
+                  if(availableLanguages[l].equals(language)){
+                     getLogger().debug("Do nothing because language was already tested: [" + availableLanguages[l] + "]");
+                  }else if(availableLanguages[l].equals(defaultLanguage)){
+                     languages.add(0, availableLanguages[l]);
+                  }else{
+                     languages.add(availableLanguages[l]);
+                  }
+               }
+               int j = 0;
+               while(!file.exists() && j < languages.size()){
+                  String newlanguage = (String) languages.get(j);
+                  url = builder.buildCanonicalUrl(publication, area, childId, newlanguage);
+                  try{
+                     doc = builder.buildDocument(publication, url);
+                  }catch(DocumentBuildException e){
+                     throw new SAXException(e);
+                  }
+                  file = doc.getFile();
+                  j++;
+               }
             }
-
-            String documentId = document.getId();
-            String language = document.getLanguage();
-            String defaultLanguage = publication.getDefaultLanguage();
-            SiteTreeNode[] children = siteTree.getNode(documentId).getChildren();
-
-            super.startElement(uri, localName, raw, attr);
-
-            for (int i = 0; i < children.length; i++) {
-                String childId = documentId + "/" + children[i].getId();
-
-                //get child document with the same language than the parent document
-                String url = builder.buildCanonicalUrl(publication, area, childId, language);
-                Document doc;
-                try {
-                    doc = builder.buildDocument(publication, url);
-                } catch (DocumentBuildException e) {
-                    throw new SAXException(e);
-                }
-                File file = doc.getFile();
-
-                if (!file.exists()) {
-                    //get first the child document in the default language and then in any other existent language
-                    getLogger().debug(
-                        "There is no child file "
-                            + file.getAbsolutePath()
-                            + " in the same language as the parent document ["
-                            + language
-                            + "]");
-
-                    //available language    
-                    String[] availableLanguages = null;
-                    try {
-                        availableLanguages = doc.getLanguages();
-                    } catch (DocumentException e) {
-                        throw new SAXException(e);
-                    }
-
-                    List languages = new ArrayList();
-                    for (int l = 0; l < availableLanguages.length; l++) {
-                        if (availableLanguages[l].equals(language)) {
-                            getLogger().debug(
-                                "Do nothing because language was already tested: ["
-                                    + availableLanguages[l]
-                                    + "]");
-                        } else if (availableLanguages[l].equals(defaultLanguage)) {
-                            languages.add(0, availableLanguages[l]);
-                        } else {
-                            languages.add(availableLanguages[l]);
-                        }
-                    }
-
-                    int j = 0;
-                    while (!file.exists() && j < languages.size()) {
-                        String newlanguage = (String) languages.get(j);
-                        url = builder.buildCanonicalUrl(publication, area, childId, newlanguage);
-                        try {
-                            doc = builder.buildDocument(publication, url);
-                        } catch (DocumentBuildException e) {
-                            throw new SAXException(e);
-                        }
-                        file = doc.getFile();
-
-                        j++;
-                    }
-                }
-
-                if (file.exists()) {
-                    //create the tags for the child
-                    String path;
-                    try {
-                        path = file.getCanonicalPath();
-                    } catch (IOException e) {
-                        throw new SAXException(e);
-                    }
-
-                    AttributesImpl attribute = new AttributesImpl();
-                    attribute.addAttribute("", "href", "href", "", url);
-                    super.startElement(NAMESPACE, "child", PREFIX + "child", attribute);
-
-                    AttributesImpl attributes = new AttributesImpl();
-                    attributes.addAttribute("", "src", "src", "", path);
-                    attributes.addAttribute("", "element", "element", "", "included");
-
-                    super.startElement(
-                        this.cIncludeNamespace,
-                        "include",
-                        cIncludePrefix + "include",
-                        attributes);
-                    super.endElement(this.cIncludeNamespace, "include", cIncludePrefix + "include");
-                    super.endElement(NAMESPACE, "child", PREFIX + "child");
-                } else {
-                    //do nothing for this child
-                    getLogger().warn("There are no existing file for the child with id " + childId);
-                }
-
+            if(file.exists()){
+               // create the tags for the child
+               String path;
+               try{
+                  path = file.getCanonicalPath();
+               }catch(IOException e){
+                  throw new SAXException(e);
+               }
+               AttributesImpl attribute = new AttributesImpl();
+               attribute.addAttribute("", "href", "href", "", url);
+               super.startElement(NAMESPACE, "child", PREFIX + "child", attribute);
+               AttributesImpl attributes = new AttributesImpl();
+               attributes.addAttribute("", "src", "src", "", path);
+               attributes.addAttribute("", "element", "element", "", "included");
+               super.startElement(this.cIncludeNamespace, "include", cIncludePrefix + "include", attributes);
+               super.endElement(this.cIncludeNamespace, "include", cIncludePrefix + "include");
+               super.endElement(NAMESPACE, "child", PREFIX + "child");
+            }else{
+               // do nothing for this child
+               getLogger().warn("There are no existing file for the child with id " + childId);
             }
-        } else {
-            super.startElement(uri, localName, raw, attr);
-        }
-
-    }
-
-    /**
-     * @return SiteTree The siteTree belonging to the area of the document
-     */
-    public SiteTree getSiteTree() {
-        return siteTree;
-    }
-
-    /**
-     * @param tree The siteTree of the area, which the document belongs.
-     */
-    public void setSiteTree(SiteTree tree) {
-        siteTree = tree;
-    }
-
-    /**
-     * @param string The area, which the document belongs.
-     */
-    public void setArea(String string) {
-        area = string;
-    }
-
-    /**
-     * @param builder The document builder.
-     */
-    public void setBuilder(DocumentBuilder builder) {
-        this.builder = builder;
-    }
-
-    /**
-     * @param document The document.
-     */
-    public void setDocument(Document document) {
-        this.document = document;
-    }
-
-    /**
-     * @param publication The publication, which the document belongs.
-     */
-    public void setPublication(Publication publication) {
-        this.publication = publication;
-    }
-
+         }
+      }else{
+         super.startElement(uri, localName, raw, attr);
+      }
+   }
+   /**
+    * @return SiteTree The siteTree belonging to the area of the document
+    */
+   public SiteTree getSiteTree() {
+      return siteTree;
+   }
+   /**
+    * @param tree
+    *           The siteTree of the area, which the document belongs.
+    */
+   public void setSiteTree(SiteTree tree) {
+      siteTree = tree;
+   }
+   /**
+    * @param string
+    *           The area, which the document belongs.
+    */
+   public void setArea(String string) {
+      area = string;
+   }
+   /**
+    * @param builder
+    *           The document builder.
+    */
+   public void setBuilder(DocumentBuilder builder) {
+      this.builder = builder;
+   }
+   /**
+    * @param document
+    *           The document.
+    */
+   public void setDocument(Document document) {
+      this.document = document;
+   }
+   /**
+    * @param publication
+    *           The publication, which the document belongs.
+    */
+   public void setPublication(Publication publication) {
+      this.publication = publication;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java Sat Mar  8 14:58:32 2008
@@ -22,9 +22,9 @@
 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.transformation.AbstractDOMTransformer;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.transformation.AbstractDOMTransformer;
 import org.apache.excalibur.source.Source;
 import org.w3c.dom.Document;
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.