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/18 19:44:29 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant ComputeUniqueDocumentId.java
edith 2003/06/18 10:44:29
Added: src/java/org/apache/lenya/cms/publication
UniqueDocumentId.java
src/java/org/apache/lenya/cms/ant
ComputeUniqueDocumentId.java
Log:
compute a new id for a document if there is already a node for a document with this id
Revision Changes Path
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/publication/UniqueDocumentId.java
Index: UniqueDocumentId.java
===================================================================
/*
* <License>
* The Apache Software License
*
* Copyright (c) 2002 lenya. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software must
* display the following acknowledgment: "This product includes software developed
* by lenya (http://www.lenya.org)"
*
* 4. The name "lenya" must not be used to endorse or promote products derived from
* this software without prior written permission. For written permission, please
* contact contact@lenya.org
*
* 5. Products derived from this software may not be called "lenya" nor may "lenya"
* appear in their names without prior written permission of lenya.
*
* 6. Redistributions of any form whatsoever must retain the following acknowledgment:
* "This product includes software developed by lenya (http://www.lenya.org)"
*
* THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
* INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
* BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
* BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
* THIRD PARTY CLAIMS AGAINST YOU.
*
* Lenya includes software developed by the Apache Software Foundation, W3C,
* DOM4J Project, BitfluxEditor and Xopus.
* </License>
*/
package org.apache.lenya.cms.publication;
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
* @author edith
*
*/
public class UniqueDocumentId {
static Category log = Category.getInstance(UniqueDocumentId.class);
/**
* @param absolutetreepath: path of the tree
* @param documentid: documentid to test
* @return the unique documentid
*/
public String computeUniqueDocumentId(String absolutetreepath,String documentid){
DefaultSiteTree tree = null;
try {
tree = new DefaultSiteTree(absolutetreepath);
SiteTreeNode node = tree.getNode(documentid);
String suffix = 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;
}
} catch (Exception e) {
e.printStackTrace();
}
return documentid;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ant/ComputeUniqueDocumentId.java
Index: ComputeUniqueDocumentId.java
===================================================================
/*
* <License>
* The Apache Software License
*
* Copyright (c) 2002 lenya. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software must
* display the following acknowledgment: "This product includes software developed
* by lenya (http://www.lenya.org)"
*
* 4. The name "lenya" must not be used to endorse or promote products derived from
* this software without prior written permission. For written permission, please
* contact contact@lenya.org
*
* 5. Products derived from this software may not be called "lenya" nor may "lenya"
* appear in their names without prior written permission of lenya.
*
* 6. Redistributions of any form whatsoever must retain the following acknowledgment:
* "This product includes software developed by lenya (http://www.lenya.org)"
*
* THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
* INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
* BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
* BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
* THIRD PARTY CLAIMS AGAINST YOU.
*
* Lenya includes software developed by the Apache Software Foundation, W3C,
* DOM4J Project, BitfluxEditor and Xopus.
* </License>
*/
package org.apache.lenya.cms.ant;
import org.apache.lenya.cms.publication.UniqueDocumentId;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
/**
* ant task to compute a new id for a document
* if there is already a node for a document with this id
* @author edith
*
*/
public class ComputeUniqueDocumentId extends Task {
private String absolutetreepath;
private String documentid;
/**
* Creates a new instance of ComputeUniqueDocumentId
*/
public ComputeUniqueDocumentId() {
super();
}
/**
* @return absolutetreepath, the absolute path of the tree
*/
protected String getAbsolutetreepath() {
return absolutetreepath;
}
/**
* set the value of the absolute path of the tree
* @param string
*/
public void setAbsolutetreepath(String string) {
absolutetreepath = string;
}
/**
* return the document-id corresponding
* @return documentid,
*/
protected String getDocumentid() {
return documentid;
}
/**
* set the value of the document-id
* @param string
*/
public void setDocumentid(String string) {
documentid = string;
}
/**
* copy a node of a tree and insert this in the same tree
* @param documentid : id of the copied document
* @param absolutetreepath : absolute path of the tree
*/
public void compute(String documentid, String absolutetreepath) {
UniqueDocumentId uniqueDocumentId = new UniqueDocumentId();
documentid=uniqueDocumentId.computeUniqueDocumentId(absolutetreepath, documentid);
Target target=getOwningTarget();
Project project=target.getProject();
project.setProperty("node.newdocumentid", documentid);
}
/**
* execute the task
*/
public void execute() throws BuildException {
try {
log("document-id " + getDocumentid());
log("Absolute Tree Path: " +getAbsolutetreepath());
compute(getDocumentid(), getAbsolutetreepath());
} catch (Exception 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