lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ed...@apache.org
Subject cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant SetIdentifier.java
Date Wed, 20 Aug 2003 16:47:45 GMT
edith       2003/08/20 09:47:45

  Modified:    src/java/org/apache/lenya/cms/ant SetIdentifier.java
  Log:
  set the identifier only for the documents corresponding to the document id
  
  Revision  Changes    Path
  1.3       +57 -50    cocoon-lenya/src/java/org/apache/lenya/cms/ant/SetIdentifier.java
  
  Index: SetIdentifier.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/SetIdentifier.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SetIdentifier.java	14 Aug 2003 10:45:34 -0000	1.2
  +++ SetIdentifier.java	20 Aug 2003 16:47:45 -0000	1.3
  @@ -59,23 +59,21 @@
   import org.apache.lenya.cms.publication.Document;
   import org.apache.lenya.cms.publication.DocumentBuildException;
   import org.apache.lenya.cms.publication.DocumentException;
  -import org.apache.lenya.cms.publication.DocumentIdToPathMapper;
   import org.apache.lenya.cms.publication.DublinCore;
   import org.apache.lenya.cms.publication.Label;
   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 org.apache.lenya.cms.publication.SiteTreeNodeVisitor;
   import org.apache.tools.ant.BuildException;
   
   /**
  - * anttask visitor to set the document-id in the dc:identifier
  + * anttask to set the document-id in the dc:identifier of all existing files
  + * corresponding to this document-id 
    * @author edith
    *
    */
  -public class SetIdentifier
  -	extends PublicationTask
  -	implements SiteTreeNodeVisitor {
  +public class SetIdentifier extends PublicationTask {
   
   	private String area;
   	private String documentid;
  @@ -115,57 +113,66 @@
   		documentid = string;
   	}
   
  -    /** (non-Javadoc)
  -     * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
  -     */
  -    public void visitSiteTreeNode(SiteTreeNode node) throws DocumentException {
  -        Publication publication = getPublication();
  -        DocumentIdToPathMapper pathMapper = publication.getPathMapper();
  -        Label[] labels = node.getLabels();
  -        for (int i = 0; i < labels.length; i++) {
  -            String language = labels[i].getLanguage();
  -            String parentid = node.getAbsoluteParentId();
  -            String documentid = parentid + "/" + node.getId();
  -            String url =
  -                "/"
  -                    + publication.getId()
  -                    + "/"
  -                    + area
  -                    + documentid
  -                    + "_"
  -                    + language
  -                    + ".html";
  -            log("url : " + url);
  -            Document document = null;
  -            try {
  -                document =
  -                    DefaultDocumentBuilder.getInstance().buildDocument(
  -                        publication,
  -                        url);
  -            } catch (DocumentBuildException e) {
  -                e.printStackTrace();
  -            }
  -            DublinCore dublincore = document.getDublinCore();
  -            dublincore.setIdentifier(documentid);
  -            dublincore.save();
  -        }
  -    }
  +	/**
  +	 * write the document id in the DC Identifier of a document corresponding to this url
  +	 * @param publication The publication the document belongs to.
  +	 * @param url The URL of the form /{publication-id}/...
  +	 * @throws DocumentBuildException when something went wrong when building the cms document.
  +	 * @throws DocumentException when something went wrong when getting the DublinCore.
  +	 */
  +	public void writeDCIdentifier(Publication publication, String url)
  +		throws DocumentBuildException, DocumentException {
  +		assert url != null;
  +
  +		Document document = null;
  +		document =
  +			DefaultDocumentBuilder.getInstance().buildDocument(
  +				publication,
  +				url);
  +		DublinCore dublincore = document.getDublinCore();
  +		dublincore.setIdentifier(documentid);
  +		dublincore.save();
  +	}
   
   	/** 
   	 * @see org.apache.tools.ant.Task#execute()
   	 **/
   	public void execute() throws BuildException {
  -		try {
  -			log("document-id " + this.getDocumentid());
  -			log("area " + this.getArea());
  +		log("document-id " + this.getDocumentid());
  +		log("area " + this.getArea());
   
  -			Publication publication = getPublication();
  -			SiteTree tree = publication.getSiteTree(area);
  -			SiteTreeNode node = tree.getNode(documentid);
  +		Publication publication = getPublication();
   
  -			node.acceptSubtree(this);
  -		} catch (Exception e) {
  +		String language = null;
  +		String url = null;
  +		SiteTree tree;
  +
  +		try {
  +			tree = publication.getSiteTree(area);
  +		} catch (SiteTreeException e) {
   			throw new BuildException(e);
  +		}
  +		SiteTreeNode node = tree.getNode(documentid);
  +		Label[] labels = node.getLabels();
  +
  +		try {
  +			if (labels.length < 1) {
  +				log(
  +					"no languages found for the node with id : "
  +						+ node.getId());
  +				url = DefaultDocumentBuilder.getInstance().buildCanonicalUrl(publication, area, documentid);
  +				writeDCIdentifier(publication, url);
  +			} else {
  +				for (int i = 0; i < labels.length; i++) {
  +					language = labels[i].getLanguage();
  +					url = DefaultDocumentBuilder.getInstance().buildCanonicalUrl(publication, area, documentid,
language);
  +					writeDCIdentifier(publication, url);
  +				}
  +			}
  +		} catch (DocumentException e1) {
  +			throw new BuildException(e1);
  +		} catch (DocumentBuildException e2) {
  +			throw new BuildException(e2);
   		}
   	}
   
  
  
  

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


Mime
View raw message