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/08/19 15:11:26 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant InsertCopyNode.java TwoNodesTask.java MoveNode.java CopyDocumentTask.java
edith 2003/08/19 06:11:26
Modified: src/java/org/apache/lenya/cms/ant InsertCopyNode.java
TwoNodesTask.java MoveNode.java
CopyDocumentTask.java
Log:
Replace the deprecated DefaultSitetree
Revision Changes Path
1.7 +53 -95 cocoon-lenya/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java
Index: InsertCopyNode.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- InsertCopyNode.java 7 Aug 2003 15:52:26 -0000 1.6
+++ InsertCopyNode.java 19 Aug 2003 13:11:26 -0000 1.7
@@ -55,117 +55,75 @@
*/
package org.apache.lenya.cms.ant;
-import org.apache.lenya.cms.publication.DefaultSiteTree;
+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 java.io.IOException;
import java.util.StringTokenizer;
-import javax.xml.transform.TransformerException;
-
-
/**
* Ant task that copies a node of a tree and inserts it in tree
* @author edith
*
**/
public class InsertCopyNode extends TwoNodesTask {
- /**
- * Creates a new instance of InsertCopyNode
- */
- public InsertCopyNode() {
- super();
- }
+ /**
+ * Creates a new instance of InsertCopyNode
+ */
+ public InsertCopyNode() {
+ super();
+ }
/**
- * copies a node corresponding to a document with id firstdocumentid
- * and inserts it in the same tree like a node corresponding to a document with id secdocumentid.
- * @param firstdocumentid The document-id of the document corresponding to the source node.
+ * copies a node corresponding to a document with id firstdocumentid and area firstarea
+ * and inserts it like a node corresponding to a document with id secdocumentid and area secarea.
+ * @param firstdocumentid The document-id of the document corresponding to the source node.
* @param secdocumentid The document-id of the document corresponding to the destination node.
- * @param absolutetreepath The absolute path of the tree of the node.
+ * @param firstarea The area of the document corresponding to the source node.
+ * @param secarea The area of the document corresponding to the destination node.
* @throws SiteTreeException if there are problems with creating or saving the site tree.
*/
- private void manipulateTree(String firstdocumentid, String secdocumentid, String absolutetreepath) throws SiteTreeException {
- DefaultSiteTree tree = null;
-
- try {
- tree = new DefaultSiteTree(absolutetreepath);
-
- String parentid = "";
- StringTokenizer st = new StringTokenizer(secdocumentid, "/");
- int length = st.countTokens();
-
- for (int i = 0; i < (length - 1); i++) {
- parentid = parentid + "/" + st.nextToken();
- }
- String newid = st.nextToken();
-
- SiteTreeNode node = tree.getNode(firstdocumentid);
- if (node != null){
- SiteTreeNode parentNode = tree.getNode(parentid);
- if (parentNode != null) {
- tree.importSubtree(parentNode, node, newid);
- } else {
- throw new SiteTreeException("The parent node " + parentNode + " where the copied node shall be inserted not found");
- }
+ public void manipulateTree(
+ String firstdocumentid,
+ String secdocumentid,
+ String firstarea,
+ String secarea)
+ throws SiteTreeException {
+
+ Publication publication = getPublication();
+ SiteTree firsttree = publication.getSiteTree(firstarea);
+ SiteTree sectree = publication.getSiteTree(secarea);
+
+ String parentid = "";
+ StringTokenizer st = new StringTokenizer(secdocumentid, "/");
+ int length = st.countTokens();
+
+ for (int i = 0; i < (length - 1); i++) {
+ parentid = parentid + "/" + st.nextToken();
+ }
+ String newid = st.nextToken();
+
+ SiteTreeNode node = firsttree.getNode(firstdocumentid);
+
+ if (node != null) {
+ SiteTreeNode parentNode = sectree.getNode(parentid);
+ if (parentNode != null) {
+ sectree.importSubtree(parentNode, node, newid);
} else {
- throw new SiteTreeException("Node " + node + " couldn't be found");
- }
- tree.save();
- } catch (IOException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
- } catch (TransformerException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
+ throw new SiteTreeException(
+ "The parent node "
+ + parentNode
+ + " where the copied node shall be inserted not found");
}
+ } else {
+ throw new SiteTreeException("Node " + node + " couldn't be found");
+ }
+ if (firstarea.equals(secarea)) {
+ firsttree.save();
+ } else {
+ firsttree.save();
+ sectree.save();
+ }
}
- /**
- * copies a node corresponding to a document with id firstdocumentid
- * and inserts it like a node corresponding to a document with id secdocumentid.
- * @param firstdocumentid The document-id of the document corresponding to the source node.
- * @param secdocumentid The document-id of the document corresponding to the destination node.
- * @param absolutefirsttreepath The absolute path of the tree of the src node.
- * @param absolutesectreepath The absolute path of the tree of the destination node.
- * @throws SiteTreeException if there are problems with creating or saving the site tree.
- */
- public void manipulateTree(String firstdocumentid, String secdocumentid, String absolutefirsttreepath, String absolutesectreepath) throws SiteTreeException {
- if (absolutefirsttreepath.equals(absolutesectreepath)) {
- manipulateTree(firstdocumentid, secdocumentid, absolutefirsttreepath);
- return;
- }
- DefaultSiteTree firsttree = null;
- DefaultSiteTree sectree = null;
-
- try {
- firsttree = new DefaultSiteTree(absolutefirsttreepath);
- sectree = new DefaultSiteTree(absolutesectreepath);
-
- String parentid = "";
- StringTokenizer st = new StringTokenizer(secdocumentid, "/");
- int length = st.countTokens();
-
- for (int i = 0; i < (length - 1); i++) {
- parentid = parentid + "/" + st.nextToken();
- }
- String newid = st.nextToken();
-
- SiteTreeNode node = firsttree.getNode(firstdocumentid);
-
- if (node != null){
- SiteTreeNode parentNode = sectree.getNode(parentid);
- if (parentNode != null) {
- sectree.importSubtree(parentNode, node, newid);
- } else {
- throw new SiteTreeException("The parent node " + parentNode + " where the copied node shall be inserted not found");
- }
- } else {
- throw new SiteTreeException("Node " + node + " couldn't be found");
- }
- sectree.save();
- } catch (IOException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
- } catch (TransformerException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
- }
- }
}
1.5 +62 -74 cocoon-lenya/src/java/org/apache/lenya/cms/ant/TwoNodesTask.java
Index: TwoNodesTask.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/TwoNodesTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TwoNodesTask.java 25 Jul 2003 16:38:53 -0000 1.4
+++ TwoNodesTask.java 19 Aug 2003 13:11:26 -0000 1.5
@@ -58,22 +58,21 @@
import org.apache.lenya.cms.publication.SiteTreeException;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
/**
* Abstract base class for Ant tasks, which manipulates two nodes.
- * The first node corresponds to the document with id firstdocumentid and
- * is in the tree corresponding to the path absolutefirsttreepath.
- * The 2nd node corresponds to the document with id secdocumentid and
- * is in the tree corresponding to the path absolutesectreepath.
+ * The first node corresponds to the document with id firstdocumentid
+ * and the area firstarea.
+ * The 2nd node corresponds to the document with id secdocumentid
+ * and the area secarea.
* @author edith
*/
-public abstract class TwoNodesTask extends Task {
- private String absolutefirsttreepath;
- private String absolutesectreepath;
- private String firstdocumentid;
- private String secdocumentid;
+public abstract class TwoNodesTask extends PublicationTask {
+ private String firstarea;
+ private String firstdocumentid;
+ private String secarea;
+ private String secdocumentid;
/**
* Creates a new instance of TwoNodesTask
@@ -82,85 +81,74 @@
super();
}
- /**
- * @return absolutefirsttreepath, the absolute path of the tree of the first node
- */
- protected String getAbsolutefirsttreepath() {
- return absolutefirsttreepath;
- }
+ /**
+ * @return String The area of the document of the first node.
+ */
+ public String getFirstarea() {
+ return firstarea;
+ }
- /**
- * Set the value of the absolute path of the tree of the first node
- *
- * @param string The absolute path of the tree of the first node.
- */
- public void setAbsolutefirsttreepath(String string) {
- absolutefirsttreepath = string;
- }
+ /**
+ * @return String The document-id corresponding to the first node.
+ */
+ public String getFirstdocumentid() {
+ return firstdocumentid;
+ }
/**
- * @return absolutesectreepath, the absolute path of the tree of the 2nd node
+ * @return String The area of the document of the second node.
*/
- public String getAbsolutesectreepath() {
- return absolutesectreepath;
+ public String getSecarea() {
+ return secarea;
}
/**
- * Set the value of the absolute path of the tree of the 2nd node
- *
- * @param string The absolute path of the tree of the 2nd node.
+ * @return String The document-id corresponding to the second node.
*/
- public void setAbsolutesectreepath(String string) {
- absolutesectreepath = string;
+ public String getSecdocumentid() {
+ return secdocumentid;
}
- /**
- * return the document-id corresponding to the first node
- * @return documentid,
- */
- protected String getFirstdocumentid() {
- return firstdocumentid;
- }
+ /**
+ * @param string The area of the document of the first node.
+ */
+ public void setFirstarea(String string) {
+ firstarea = string;
+ }
- /**
- * Set the value of the document-id corresponding to the first node
- *
- * @param string the document-id
- */
- public void setFirstdocumentid(String string) {
- firstdocumentid = string;
- }
+ /**
+ * @param string The document-id corresponding to the first node.
+ */
+ public void setFirstdocumentid(String string) {
+ firstdocumentid = string;
+ }
- /**
- * Return the document-id corresponding to the 2nd node.
- *
- * @return newdocumentid the document-id
- */
- protected String getSecdocumentid() {
- return secdocumentid;
- }
+ /**
+ * @param string The area of the document of the second node.
+ */
+ public void setSecarea(String string) {
+ secarea = string;
+ }
- /**
- * Set the value of the document-id corresponding to the 2nd node.
- *
- * @param string the second document-id
- */
- public void setSecdocumentid(String string) {
- secdocumentid = string;
- }
+ /**
+ * @param string The document-id corresponding to the second node.
+ */
+ public void setSecdocumentid(String string) {
+ secdocumentid = string;
+ }
/**
* To be overriden.
* Manipulation of two nodes .
- * @param firstdocumentid : id of the copied document
- * @param secdocumentid : id of the new document
- * @param absolutefirsttreepath : absolute path of the tree of the first node
- * @param absolutesectreepath : absolute path of the tree of the 2nd node
+ * @param firstdocumentid : id of the first document
+ * @param secdocumentid : id of the second document
+ * @param firstarea : area of the tree of the first node
+ * @param secarea : area of the tree of the 2nd node
*
* @throws SiteTreeException if an error occurs
*/
public abstract void manipulateTree(String firstdocumentid, String secdocumentid,
- String absolutefirsttreepath, String absolutesectreepath)
+ String firstarea, String secarea)
throws SiteTreeException;
/** (non-Javadoc)
@@ -168,11 +156,11 @@
*/
public void execute() throws BuildException {
try {
- log("document-id corresponding to the first node: " + getFirstdocumentid());
- log("document-id corresponding to the second node: " + getSecdocumentid());
- log("Absolute Tree Path of the first node: " + getAbsolutefirsttreepath());
- log("Absolute Tree Path of the second node: " + getAbsolutesectreepath());
- manipulateTree(getFirstdocumentid(), getSecdocumentid(), getAbsolutefirsttreepath(), getAbsolutesectreepath());
+ log("document-id corresponding to the first node: " + this.getFirstdocumentid());
+ log("document-id corresponding to the second node: " + this.getSecdocumentid());
+ log("area corresponding to the first node: " + this.getFirstarea());
+ log("area corresponding to the second node: " + this.getSecarea());
+ manipulateTree(getFirstdocumentid(), getSecdocumentid(), getFirstarea(), getSecarea());
} catch (Exception e) {
throw new BuildException(e);
}
1.6 +52 -57 cocoon-lenya/src/java/org/apache/lenya/cms/ant/MoveNode.java
Index: MoveNode.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/MoveNode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MoveNode.java 7 Aug 2003 15:52:26 -0000 1.5
+++ MoveNode.java 19 Aug 2003 13:11:26 -0000 1.6
@@ -55,82 +55,77 @@
*/
package org.apache.lenya.cms.ant;
-import java.io.IOException;
import java.util.StringTokenizer;
-import javax.xml.transform.TransformerException;
-import org.apache.lenya.cms.publication.DefaultSiteTree;
+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;
-
/**
* @author edith
*
* Ant task that moves a node in a tree.
*/
public class MoveNode extends TwoNodesTask {
- /**
- *
- */
- public MoveNode() {
- super();
- }
+ /**
+ *
+ */
+ public MoveNode() {
+ super();
+ }
/**
- * Move a node in a tree.
+ * Move a node.
*
- * @param firstdocumentid The document-id of the document correponding to the source node.
- * @param secdocumentid The ment-id of the document corresponding to the destination node.
- * @param absolutefirsttreepath The absolute path of the tree of the src node.
- * @param absolutesectreepath The absolute path of the tree of the destination node.
- * @throws SiteTreeException if there are problems with creating or saving the site tree.
+ * @param firstdocumentid The document-id of the document corresponding to the source node.
+ * @param secdocumentid The document-id of the document corresponding to the destination node.
+ * @param firstarea The area of the document corresponding to the source node.
+ * @param secarea The area of the document corresponding to the destination node.
+ * @throws SiteTreeException if there are problems with creating or saving the site tree.
*/
- public void manipulateTree(String firstdocumentid, String secdocumentid, String absolutefirsttreepath, String absolutesectreepath)
+ public void manipulateTree(
+ String firstdocumentid,
+ String secdocumentid,
+ String firstarea,
+ String secarea)
throws SiteTreeException {
- DefaultSiteTree firsttree = null;
- DefaultSiteTree sectree = null;
-
- try {
- firsttree = new DefaultSiteTree(absolutefirsttreepath);
- if (absolutefirsttreepath.equals(absolutesectreepath)) {
- sectree = firsttree;
- } else {
- sectree = new DefaultSiteTree(absolutesectreepath);
- }
-
- String parentid = "";
- StringTokenizer st = new StringTokenizer(secdocumentid, "/");
- int length = st.countTokens();
-
- for (int i = 0; i < (length - 1); i++) {
- parentid = parentid + "/" + st.nextToken();
- }
- String newid = st.nextToken();
-
- SiteTreeNode node = firsttree.removeNode(firstdocumentid);
- if (node != null){
- SiteTreeNode parentNode = sectree.getNode(parentid);
- if (parentNode != null) {
- sectree.importSubtree(parentNode, node, newid);
- } else {
- throw new SiteTreeException("The parent node " + parentNode + " where the removed node shall be inserted not found");
- }
- } else {
- throw new SiteTreeException("Node " + node + " couldn't be removed");
- }
- if (absolutefirsttreepath.equals(absolutesectreepath)) {
- firsttree.save();
+ Publication publication = getPublication();
+ SiteTree firsttree = publication.getSiteTree(firstarea);
+ SiteTree sectree = publication.getSiteTree(secarea);
+
+ String parentid = "";
+ StringTokenizer st = new StringTokenizer(secdocumentid, "/");
+ int length = st.countTokens();
+
+ for (int i = 0; i < (length - 1); i++) {
+ parentid = parentid + "/" + st.nextToken();
+ }
+ String newid = st.nextToken();
+
+ SiteTreeNode node = firsttree.removeNode(firstdocumentid);
+ if (node != null) {
+ SiteTreeNode parentNode = sectree.getNode(parentid);
+ if (parentNode != null) {
+ sectree.importSubtree(parentNode, node, newid);
} else {
- firsttree.save();
- sectree.save();
+ throw new SiteTreeException(
+ "The parent node "
+ + parentNode
+ + " where the removed node shall be inserted not found");
}
- } catch (IOException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
- } catch (TransformerException e) {
- throw new SiteTreeException("Exception when saving the tree file", e);
+ } else {
+ throw new SiteTreeException(
+ "Node " + node + " couldn't be removed");
+ }
+
+ if (firstarea.equals(secarea)) {
+ firsttree.save();
+ } else {
+ firsttree.save();
+ sectree.save();
}
}
}
1.2 +6 -4 cocoon-lenya/src/java/org/apache/lenya/cms/ant/CopyDocumentTask.java
Index: CopyDocumentTask.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/CopyDocumentTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CopyDocumentTask.java 8 Aug 2003 08:15:14 -0000 1.1
+++ CopyDocumentTask.java 19 Aug 2003 13:11:26 -0000 1.2
@@ -170,16 +170,18 @@
String destDocumentid = srcDocumentid.replaceFirst(firstdocumentid,secdocumentid);
File file = pathMapper.getFile(publication, getFirstarea(), srcDocumentid, language);
+ if (!file.exists()) {
+ log("There are no file "+file.getAbsolutePath());
+ return;
+ }
File newfile = pathMapper.getFile(publication, getSecarea(), destDocumentid, language);
log("copy file "+file.getAbsolutePath()+"to file "+newfile.getAbsolutePath());
try {
FileUtil.copy(file.getAbsolutePath(), newfile.getAbsolutePath());
} catch (FileNotFoundException e) {
- e.printStackTrace();
throw new BuildException(e);
} catch (IOException e) {
- e.printStackTrace();
throw new BuildException(e);
}
@@ -221,7 +223,7 @@
Publication publication= getPublication();
SiteTree tree = publication.getSiteTree(getFirstarea());
- SiteTreeNode node = tree.getNode(firstdocumentid);
+ SiteTreeNode node = tree.getNode(getFirstdocumentid());
node.acceptSubtree(this);
} catch (Exception e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org