You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/08/14 12:45:35 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication SiteTreeNode.java SiteTreeNodeImpl.java SiteTreeNodeVisitor.java DublinCore.java

egli        2003/08/14 03:45:35

  Modified:    src/java/org/apache/lenya/cms/ant SetIdentifier.java
               src/java/org/apache/lenya/cms/publication SiteTreeNode.java
                        SiteTreeNodeImpl.java SiteTreeNodeVisitor.java
                        DublinCore.java
  Log:
  The dublic core class has been changed to be more efficient.
  It no longer parses the document xml for each query.
  Due to the change some different Exceptions are thrown and this
  made a change to some other classes and interfaces necessary.
  
  Revision  Changes    Path
  1.2       +34 -33    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetIdentifier.java	8 Aug 2003 09:48:55 -0000	1.1
  +++ SetIdentifier.java	14 Aug 2003 10:45:34 -0000	1.2
  @@ -58,6 +58,7 @@
   import org.apache.lenya.cms.publication.DefaultDocumentBuilder;
   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;
  @@ -114,41 +115,41 @@
   		documentid = string;
   	}
   
  -	/** (non-Javadoc)
  -	 * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
  -	 */
  -	public void visitSiteTreeNode(SiteTreeNode node) {
  -		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); 
  +    /** (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();
  -			}
  +            try {
  +                document =
  +                    DefaultDocumentBuilder.getInstance().buildDocument(
  +                        publication,
  +                        url);
  +            } catch (DocumentBuildException e) {
  +                e.printStackTrace();
  +            }
               DublinCore dublincore = document.getDublinCore();
               dublincore.setIdentifier(documentid);
  -		}
  -
  -	}
  +            dublincore.save();
  +        }
  +    }
   
   	/** 
   	 * @see org.apache.tools.ant.Task#execute()
  
  
  
  1.8       +8 -4      cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java
  
  Index: SiteTreeNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SiteTreeNode.java	8 Aug 2003 08:19:58 -0000	1.7
  +++ SiteTreeNode.java	14 Aug 2003 10:45:34 -0000	1.8
  @@ -148,13 +148,17 @@
   	 * the operation that shall be perfoemed on this node
   	 * (Visitor pattern)
   	 * @param visitor The visitor.
  +     * 
  +     * @throws DocumentException if an error occurs
   	 */
  -	void accept (SiteTreeNodeVisitor visitor);
  +	void accept (SiteTreeNodeVisitor visitor) throws DocumentException;
   	
   	/**
   	 * Traverse the node ant its children and call the
   	 * accept method.
   	 * @param visitor The visitor.
  +     * 
  +     * @throws DocumentException if an error occurs
   	 */
  -	void acceptSubtree (SiteTreeNodeVisitor visitor);
  +	void acceptSubtree (SiteTreeNodeVisitor visitor) throws DocumentException;
   }
  
  
  
  1.13      +4 -4      cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java
  
  Index: SiteTreeNodeImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SiteTreeNodeImpl.java	8 Aug 2003 08:19:58 -0000	1.12
  +++ SiteTreeNodeImpl.java	14 Aug 2003 10:45:34 -0000	1.13
  @@ -347,7 +347,7 @@
   	 * (non-Javadoc)
   	 * @see org.apache.lenya.cms.publication.SiteTreeNode#accept(org.apache.lenya.cms.publication.SiteTreeNodeVisitor)
   	 */
  -	public void accept (SiteTreeNodeVisitor visitor) {
  +	public void accept (SiteTreeNodeVisitor visitor) throws DocumentException {
   		visitor.visitSiteTreeNode(this);
   	}
   	
  @@ -355,7 +355,7 @@
   	 * (non-Javadoc)
   	 * @see org.apache.lenya.cms.publication.SiteTreeNode#acceptSubtree(org.apache.lenya.cms.publication.SiteTreeNodeVisitor)
   	 */
  -	public void acceptSubtree (SiteTreeNodeVisitor visitor) {
  +	public void acceptSubtree (SiteTreeNodeVisitor visitor) throws DocumentException {
   		this.accept(visitor);
           SiteTreeNode[] children = this.getChildren();
   		if (children == null) {
  
  
  
  1.2       +4 -2      cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeVisitor.java
  
  Index: SiteTreeNodeVisitor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeVisitor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SiteTreeNodeVisitor.java	8 Aug 2003 08:21:22 -0000	1.1
  +++ SiteTreeNodeVisitor.java	14 Aug 2003 10:45:34 -0000	1.2
  @@ -67,7 +67,9 @@
   	/**
   	 * Operation performed on a SiteTreeNode
   	 * @param node The SiteTreeNode.
  +     * 
  +     * @throws DocumentException if an error occurs
   	 */
  -	void visitSiteTreeNode(SiteTreeNode node);
  +	void visitSiteTreeNode(SiteTreeNode node) throws DocumentException;
   
   }
  
  
  
  1.13      +313 -150  cocoon-lenya/src/java/org/apache/lenya/cms/publication/DublinCore.java
  
  Index: DublinCore.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DublinCore.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DublinCore.java	12 Aug 2003 10:04:28 -0000	1.12
  +++ DublinCore.java	14 Aug 2003 10:45:34 -0000	1.13
  @@ -55,14 +55,19 @@
   */
   package org.apache.lenya.cms.publication;
   
  -import org.apache.lenya.cms.publication.Document;
  -import org.apache.lenya.cms.publication.PublicationException;
  -
   import org.apache.lenya.xml.DocumentHelper;
   
   import java.io.File;
  +import java.io.IOException;
  +import java.util.Date;
  +import java.util.HashMap;
  +
  +import javax.xml.parsers.ParserConfigurationException;
  +import javax.xml.transform.TransformerConfigurationException;
  +import javax.xml.transform.TransformerException;
   
   import org.w3c.dom.NodeList;
  +import org.xml.sax.SAXException;
   
   /**
    * A publication.
  @@ -70,149 +75,307 @@
    * @author <a href="mailto:gregor@apache.org">Gregor J. Rothfuss</a>
    */
   public class DublinCore {
  -	private Document cmsdocument;
  -	private File infofile;
  -	private NodeList nodelist;
  -	private String string;
  -
  -    private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
  -
  -	/** 
  -	 * Creates a new instance of Dublin Core
  -     * 
  -     * @param mydocument the document for which the Dublin Core instance is created.
  -	 * 
  -	 */
  -	protected DublinCore(Document mydocument) {
  -		this.cmsdocument = mydocument;
  -		this.infofile =
  -			cmsdocument.getPublication().getPathMapper().getFile(
  -				cmsdocument.getPublication(),
  -				Publication.AUTHORING_AREA,
  -				cmsdocument.getId(),
  -				cmsdocument.getLanguage());
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getTitle() throws PublicationException {
  -		return getDCNode("title");
  -	}
  -
  -	/**
  -	 * Set the DC title
  -	 * 
  -	 * @param title the title
  -	 */
  -	public void setTitle(String title) {
  -		setDCNode("title", title);
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getCreator() throws PublicationException {
  -		return getDCNode("creator");
  -	}
  -
  -	/**
  -	 * Set the DC creator
  -	 * 
  -	 * @param creator the Creator
  -	 */
  -	public void setCreator(String creator) {
  -		setDCNode("creator", creator);
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getSubject() throws PublicationException {
  -		return getDCNode("subject");
  -	}
  -
  -	private String getDCNode(String node) {
  -		try {
  -			nodelist =
  -                DocumentHelper.readDocument(infofile).getElementsByTagNameNS(DC_NAMESPACE, node);
  -			try {
  -				string = nodelist.item(0).getFirstChild().getNodeValue();
  -			} catch (Exception e) {
  -				string = "";
  -			}
  -		} catch (Exception e) {
  -			string = e.toString();
  -		}
  -
  -		return string;
  -	}
  -
  -	private void setDCNode(String node, String text) {
  -		org.w3c.dom.Document document;
  -		try {
  -			document = DocumentHelper.readDocument(infofile);
  -			nodelist = document.getElementsByTagNameNS(DC_NAMESPACE, node);
  -			nodelist.item(0).getFirstChild().setNodeValue(text);
  -			DocumentHelper.writeDocument(document, infofile);
  -		} catch (Exception e) {
  -			string = e.toString();
  -		}
  -	}
  -
  -	/**
  -	 * Set the DC Subject
  -	 * 
  -	 * @param subject the subject
  -	 */
  -	public void setSubject(String subject) {
  -		setDCNode("subject", subject);
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getDescription() throws PublicationException {
  -		return getDCNode("description");
  -	}
  -
  -	/**
  -	 * Set the DC Description
  -	 * 
  -	 * @param description the description
  -	 */
  -	public void setDescription(String description) {
  -		setDCNode("description", description);
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getRights() throws PublicationException {
  -		return getDCNode("rights");
  -	}
  -
  -	/**
  -	 * Set the DC Rights
  -	 * 
  -	 * @param rights the rights
  -	 */
  -	public void setRights(String rights) {
  -		setDCNode("rights", rights);
  -	}
  -
  -	/**
  -	 * @see org.apache.lenya.cms.publication.Document#getDCTitle()
  -	 */
  -	public String getIdentifier() throws PublicationException {
  -		return getDCNode("identifier");
  -	}
  -	/**
  -	 * Set the DC Identifier
  -	 * 
  -	 * @param identifier The identifier
  -	 */
  -	public void setIdentifier(String identifier) {
  -		setDCNode("identifier", identifier);
  -	}
  -}
  +    private Document cmsdocument;
  +    private File infofile;
  +    private Date timestamp = new Date(0);
  +
  +    private HashMap map = new HashMap();
  +
  +    private static final String DC_NAMESPACE =
  +        "http://purl.org/dc/elements/1.1/";
  +    
  +    private static final String CREATOR = "creator";
  +    private static final String TITLE = "title";
  +    private static final String DESCRIPTION = "description";
  +    private static final String IDENTIFIER = "identifier";
  +    private static final String SUBJECT = "subject";
  +    private static final String PUBLISHER = "publisher";
  +    private static final String DATEISSUED = "dateissued";
  +    private static final String DATEPUBLISHED = "datepublished";
  +    private static final String RIGHTS = "rights";
  +
  +    private static final String[] fields =
  +        {
  +            CREATOR,
  +            TITLE,
  +            DESCRIPTION,
  +            IDENTIFIER,
  +            SUBJECT,
  +            PUBLISHER,
  +            DATEISSUED,
  +            DATEPUBLISHED,
  +            RIGHTS };
  +
  +    /** 
  +     * Creates a new instance of Dublin Core
  +     * 
  +     * @param aDocument the document for which the Dublin Core instance is created.
  +     */
  +    protected DublinCore(Document aDocument) {
  +        this.cmsdocument = aDocument;
  +        this.infofile =
  +            cmsdocument.getPublication().getPathMapper().getFile(
  +                cmsdocument.getPublication(),
  +                Publication.AUTHORING_AREA,
  +                cmsdocument.getId(),
  +                cmsdocument.getLanguage());
  +    }
  +
  +    /**
  +     * Check if the persistent dublin core data has been changed since the last access
  +     * If yes reload the data. 
  +     * 
  +     * @throws DocumentException if the persistent data could not be loaded.
  +     */
  +    private void checkValidity() throws DocumentException {
  +        Date modificationDate = new Date(infofile.lastModified());
  +        if (modificationDate.after(timestamp)) {
  +            timestamp = modificationDate;
  +
  +            org.w3c.dom.Document doc = null;
  +            try {
  +                doc = DocumentHelper.readDocument(infofile);
  +            } catch (ParserConfigurationException e) {
  +                throw new DocumentException(e);
  +            } catch (SAXException e) {
  +                throw new DocumentException(e);
  +            } catch (IOException e) {
  +                throw new DocumentException(e);
  +            }
  +            NodeList nodelist = null;
  +            String value = null;
  +            
  +            for (int i = 0; i < fields.length; i++) {
  +                    nodelist = doc.getElementsByTagNameNS(DC_NAMESPACE, fields[i]);
  +                    value = nodelist.item(0).getFirstChild().getNodeValue();
  +                    map.put(fields[i], value);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Save the meta data.
  +     *
  +     * @throws DocumentException if the meta data could not be made persistent.
  +     */
  +    public void save() throws DocumentException {
  +        org.w3c.dom.Document doc = null;
  +        try {
  +            doc = DocumentHelper.readDocument(infofile);
  +        } catch (ParserConfigurationException e) {
  +            throw new DocumentException(e);
  +        } catch (SAXException e) {
  +            throw new DocumentException(e);
  +        } catch (IOException e) {
  +            throw new DocumentException(e);
  +        }
  +        NodeList nodelist = null;
  +        String value = null;
  +
  +        for (int i = 0; i < fields.length; i++) {
  +            nodelist = doc.getElementsByTagNameNS(DC_NAMESPACE, fields[i]);
  +            nodelist.item(0).getFirstChild().setNodeValue(
  +                (String)map.get(fields[i]));
  +        }
  +        try {
  +            DocumentHelper.writeDocument(doc, infofile);
  +        } catch (TransformerConfigurationException e) {
  +            throw new DocumentException(e);
  +        } catch (TransformerException e) {
  +            throw new DocumentException(e);
  +        } catch (IOException e) {
  +            throw new DocumentException(e);
  +        }
  +
  +    }
  +    
  +    /**
  +     * Get the creator
  +     * 
  +     * @return the creator
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getCreator() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(CREATOR);
  +    }
  +
  +    /**
  +     * Set the DC creator
  +     * 
  +     * @param creator the Creator
  +     */
  +    public void setCreator(String creator) {
  +        map.put(CREATOR, creator);
  +    }
  +
  +    /**
  +     * Get the title
  +     * 
  +     * @return the title
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getTitle() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(TITLE);
  +    }
  +
  +    /**
  +     * Set the DC title
  +     * 
  +     * @param title the title
  +     */
  +    public void setTitle(String title) {
  +        map.put(TITLE, title);
  +    }
  +
  +    /**
  +     * Get the description
  +     * 
  +     * @return the description
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getDescription() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(DESCRIPTION);
  +    }
  +
  +    /**
  +     * Set the DC Description
  +     * 
  +     * @param description the description
  +     */
  +    public void setDescription(String description) {
  +        map.put(DESCRIPTION, description);
  +    }
  +
  +    /**
  +     * Get the identifier
  +     * 
  +     * @return the identifier
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getIdentifier() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(IDENTIFIER);
  +    }
  +
  +    /**
  +     * Set the DC Identifier
  +     * 
  +     * @param identifier the identifier
  +     */
  +    public void setIdentifier(String identifier) {
  +        map.put(IDENTIFIER, identifier);
  +    }
  +
  +    /**
  +     * Get the subject.
  +     * 
  +     * @return the subject
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getSubject() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(SUBJECT);
  +    }
  +
  +    /**
  +     * Set the DC Subject
  +     * 
  +     * @param subject the subject
  +     */
  +    public void setSubject(String subject) {
  +        map.put(SUBJECT, subject);
  +    }
  +
  +    /**
  +     * Get the publisher
  +     * 
  +     * @return the publisher
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getPublisher() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(PUBLISHER);
  +    }
  +
  +    /**
  +     * Set the publisher
  +     * 
  +     * @param publisher the publisher
  +     */
  +    public void setPublisher(String publisher) {
  +        map.put(PUBLISHER, publisher);
  +    }
  +
  +    /**
  +     * Get the date of issue
  +     * 
  +     * @return the date of issue
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getDateIssued() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(DATEISSUED);
  +    }
  +
  +    /**
  +     * Set the date of issue
  +     * 
  +     * @param dateIssued the date of issue
  +     */
  +    public void setDateIssued(String dateIssued) {
  +        map.put(DATEISSUED, dateIssued);
  +    }
  +
  +    /**
  +     * Get the date of publication.
  +     * 
  +     * @return the date of publication
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getDatePublished() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(DATEPUBLISHED);
  +    }
  +
  +    /**
  +     * Set the publication date
  +     * 
  +     * @param datePublished the date of publication
  +     */
  +    public void setDatePublished(String datePublished) {
  +        map.put(DATEPUBLISHED, datePublished);
  +    }
  +
  +    /**
  +     * Get the rights
  +     * 
  +     * @return the rights
  +     * 
  +     * @throws DocumentException if an error occurs
  +     */
  +    public String getRights() throws DocumentException {
  +        checkValidity();
  +        return (String)map.get(RIGHTS);
  +    }
  +
  +    /**
  +     * Set the DC Rights
  +     * 
  +     * @param rights the rights
  +     */
  +    public void setRights(String rights) {
  +        map.put(RIGHTS, rights);
  +    }
  +
  +}
  \ No newline at end of file
  
  
  

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