You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ed...@apache.org on 2003/10/22 18:40:19 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant CopyResourcesTask.java
edith 2003/10/22 09:40:19
Modified: src/java/org/apache/lenya/cms/ant CopyResourcesTask.java
Log:
copy meta
Revision Changes Path
1.5 +89 -94 cocoon-lenya/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java
Index: CopyResourcesTask.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CopyResourcesTask.java 21 Oct 2003 09:51:55 -0000 1.4
+++ CopyResourcesTask.java 22 Oct 2003 16:40:19 -0000 1.5
@@ -56,9 +56,12 @@
package org.apache.lenya.cms.ant;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentBuilder;
@@ -66,7 +69,6 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.publication.SiteTreeNode;
-import org.apache.lenya.util.FileUtil;
import org.apache.tools.ant.BuildException;
/**
@@ -77,97 +79,90 @@
*/
public class CopyResourcesTask extends TwoDocumentsOperationTask {
- /**
- *
- */
- public CopyResourcesTask() {
- super();
- }
-
- /**
- * Copy the resources files belongs to the documents corresponding to this node
- *
- * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
- */
- public void visitSiteTreeNode(SiteTreeNode node) {
- log("visitSiteTreeNode in ");
- Publication publication = getPublication();
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- String parentid = node.getAbsoluteParentId();
- String srcDocumentid = parentid + "/" + node.getId();
- log("srcDocumentid " + srcDocumentid);
- String destDocumentid =
- srcDocumentid.replaceFirst(
- getFirstdocumentid(),
- getSecdocumentid());
- log("destDocumentid " + destDocumentid);
-
- Label[] labels = node.getLabels();
-
- // FIXME: if the resources differ for different languages, so iterate
- // on all languages
-
- String language = labels[0].getLanguage();
- log("language " + language);
- String srcUrl =
- builder.buildCanonicalUrl(
- publication,
- getFirstarea(),
- srcDocumentid,
- language);
- log("srcUrl " + srcUrl);
- Document srcDoc;
- try {
- srcDoc = builder.buildDocument(publication, srcUrl);
- } catch (DocumentBuildException e) {
- throw new BuildException(e);
- }
- ResourcesManager resourcesMgr = new ResourcesManager(srcDoc);
- File[] srcFiles = resourcesMgr.getResources();
-
- if (srcFiles == null) {
- log(
- "There are no resources for the document "
- + getFirstdocumentid());
- return;
- }
-
- String destUrl =
- builder.buildCanonicalUrl(
- publication,
- getSecarea(),
- destDocumentid,
- language);
- log("destUrl " + destUrl);
- Document destDoc;
- try {
- destDoc = builder.buildDocument(publication, destUrl);
- } catch (DocumentBuildException e) {
- throw new BuildException(e);
- }
- resourcesMgr = new ResourcesManager(destDoc);
- File destFilePath = resourcesMgr.getPath();
-
- for (int i = 0; i < srcFiles.length; i++) {
- String srcName = srcFiles[i].getName();
- String destPath =
- destFilePath.getAbsolutePath() + File.separator + srcName;
-
- log(
- "copy file "
- + srcFiles[i].getAbsolutePath()
- + "to file "
- + destPath);
- try {
- FileUtil.copy(srcFiles[i].getAbsolutePath(), destPath);
- } catch (FileNotFoundException e) {
- throw new BuildException(e);
- } catch (IOException e) {
- throw new BuildException(e);
- }
- }
+ /**
+ *
+ */
+ public CopyResourcesTask() {
+ super();
+ }
+
+ /**
+ * Copy the resources files belongs to the documents corresponding to this node
+ *
+ * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
+ */
+ public void visitSiteTreeNode(SiteTreeNode node) {
+ Publication publication = getPublication();
+ DocumentBuilder builder = publication.getDocumentBuilder();
+
+ String parentid = node.getAbsoluteParentId();
+ String srcDocumentid = parentid + "/" + node.getId();
+ String destDocumentid =
+ srcDocumentid.replaceFirst(
+ getFirstdocumentid(),
+ getSecdocumentid());
+
+ Label[] labels = node.getLabels();
+
+ // FIXME: if the resources differ for different languages, so iterate
+ // on all languages
+
+ String language = labels[0].getLanguage();
+ String srcUrl =
+ builder.buildCanonicalUrl(
+ publication,
+ getFirstarea(),
+ srcDocumentid,
+ language);
+ Document srcDoc;
+ try {
+ srcDoc = builder.buildDocument(publication, srcUrl);
+ } catch (DocumentBuildException e) {
+ throw new BuildException(e);
+ }
+ ResourcesManager resourcesMgr = new ResourcesManager(srcDoc);
+ List resources = new ArrayList(Arrays.asList(resourcesMgr.getResources()));
+ resources.addAll(Arrays.asList(resourcesMgr.getMetaFiles()));
+ File[] srcFiles =
+ (File[]) resources.toArray(new File[resources.size()]);
+
+ if (srcFiles == null) {
+ log(
+ "There are no resources for the document "
+ + getFirstdocumentid());
+ return;
+ }
+
+ String destUrl =
+ builder.buildCanonicalUrl(
+ publication,
+ getSecarea(),
+ destDocumentid,
+ language);
+ Document destDoc;
+ try {
+ destDoc = builder.buildDocument(publication, destUrl);
+ } catch (DocumentBuildException e) {
+ throw new BuildException(e);
+ }
+ resourcesMgr = new ResourcesManager(destDoc);
+
+ for (int i = 0; i < srcFiles.length; i++) {
+
+ try {
+ log(
+ "copy file "
+ + srcFiles[i].getAbsolutePath()
+ + "to file "
+ + resourcesMgr.getPath().getCanonicalPath());
+ FileUtil.copyFileToDirectory(
+ srcFiles[i],
+ resourcesMgr.getPath());
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
+ }
- }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org