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/06/25 19:00:31 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication UniqueDocumentId.java
edith 2003/06/25 10:00:31
Modified: src/java/org/apache/lenya/cms/publication
UniqueDocumentId.java
Log:
fix
Revision Changes Path
1.2 +25 -18 cocoon-lenya/src/java/org/apache/lenya/cms/publication/UniqueDocumentId.java
Index: UniqueDocumentId.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/UniqueDocumentId.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UniqueDocumentId.java 18 Jun 2003 17:44:28 -0000 1.1
+++ UniqueDocumentId.java 25 Jun 2003 17:00:31 -0000 1.2
@@ -45,17 +45,18 @@
import org.apache.log4j.Category;
/**
- * class to compute a new id for a document, if there is already a node in
- * the tree for a document with this id
+ * class to compute an unique document id for a document, if there is
+ * already a node in the sitetree for a document with this id. It will
+ * documentid_"number of version"
* @author edith
*
*/
public class UniqueDocumentId {
- static Category log = Category.getInstance(UniqueDocumentId.class);
+ private static Category log = Category.getInstance(UniqueDocumentId.class);
- /**
- * @param absolutetreepath: path of the tree
- * @param documentid: documentid to test
+/** compute an unique document id
+ * @param absolutetreepath The absolute path of the tree.
+ * @param documentid The documentid .
* @return the unique documentid
*/
public String computeUniqueDocumentId(String absolutetreepath,String documentid){
@@ -64,19 +65,25 @@
tree = new DefaultSiteTree(absolutetreepath);
SiteTreeNode node = tree.getNode(documentid);
String suffix = null;
+ int version = 0;
+ String idwithoutsuffix = null;
if (node != null) {
- int l = documentid.length();
- int index=documentid.lastIndexOf("_");
- if ((index < l) & (index > 0)) {
- suffix = documentid.substring(index);
- documentid= documentid.substring(0,index);
- int version = Integer.parseInt(suffix);
- version = version + 1;
- suffix= (new Integer(version+1)).toString();
- } else {
- suffix="1";
- }
- documentid= documentid+"_"+suffix;
+ int l = documentid.length();
+ int index=documentid.lastIndexOf("_");
+ if ((index < l) & (index > 0)) {
+ suffix = documentid.substring(index);
+ idwithoutsuffix= documentid.substring(0,index);
+ version = Integer.parseInt(suffix);
+ } else {
+ idwithoutsuffix= documentid;
+ }
+ while (node!=null) {
+ version= version + 1;
+ suffix= (new Integer(version)).toString();
+ documentid= idwithoutsuffix+"_"+suffix;
+ log.debug("version: "+version);
+ node = tree.getNode(documentid);
+ }
}
} catch (Exception e) {
e.printStackTrace();
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org