You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/05/27 09:44:39 UTC

svn commit: r178766 - /lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java

Author: andreas
Date: Fri May 27 00:44:38 2005
New Revision: 178766

URL: http://svn.apache.org/viewcvs?rev=178766&view=rev
Log:
Instanciator: allow to copy directories (credits to Doug Chestnut)

Modified:
    lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java

Modified: lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java?rev=178766&r1=178765&r2=178766&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/publication/templating/Instantiator.java Fri May 27 00:44:38 2005
@@ -20,6 +20,8 @@
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.Iterator;
 
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
@@ -34,6 +36,7 @@
 import org.apache.excalibur.source.ModifiableSource;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.impl.FileSource;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.PublicationImpl;
 import org.apache.lenya.xml.DocumentHelper;
@@ -57,8 +60,7 @@
             "config/ac/passwd/edit.rml", "config/ac/passwd/alice.iml",
             "config/ac/passwd/admin.rml", "config/ac/passwd/admin.gml", "config/ac/ac.xconf",
             "config/ac/usecase-policies.xml", "config/doctypes/doctypes.xconf",
-            "config/workflow/workflow.xml", "content/authoring/sitetree.xml",
-            "content/authoring/index/index_en.xml", "content/authoring/index/index_en.xml.meta" };
+            "config/workflow/workflow.xml", "content/authoring/sitetree.xml", "content/" };
 
     /**
      * @see org.apache.lenya.cms.publication.templating.Instantiator#instantiate(org.apache.lenya.cms.publication.Publication,
@@ -80,7 +82,11 @@
             for (int i = 0; i < sourcesToCopy.length; i++) {
 
                 String source = sourcesToCopy[i];
-                copySource(template, newPublicationId, resolver, publicationsUri, source);
+                if (source.endsWith("/")) {
+                    copyDirSource(template, newPublicationId, resolver, publicationsUri, source);
+                } else {
+                    copySource(template, newPublicationId, resolver, publicationsUri, source);
+                }
             }
 
             metaSource = (ModifiableSource) resolver.resolveURI(publicationsUri + "/"
@@ -152,6 +158,26 @@
             }
             if (targetSource != null) {
                 resolver.release(targetSource);
+            }
+        }
+    }
+
+    protected void copyDirSource(Publication template,
+            String publicationId,
+            SourceResolver resolver,
+            String publicationsUri,
+            String source) throws MalformedURLException, IOException {
+        FileSource directory = new FileSource(publicationsUri + "/" + template.getId() + "/"
+                + source);
+        Collection files = directory.getChildren();
+        for (Iterator iter = files.iterator(); iter.hasNext();) {
+            FileSource filesource = (FileSource) iter.next();
+            if (filesource.isCollection()) {
+                copyDirSource(template, publicationId, resolver, publicationsUri, source + "/"
+                        + filesource.getName());
+            } else {
+                copySource(template, publicationId, resolver, publicationsUri, source + "/"
+                        + filesource.getName());
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org