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/28 11:51:53 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication DublinCoreProxy.java DublinCoreImpl.java DublinCore.java DefaultDocument.java

egli        2003/08/28 02:51:53

  Modified:    src/java/org/apache/lenya/cms/publication DublinCore.java
                        DefaultDocument.java
  Added:       src/java/org/apache/lenya/cms/publication
                        DublinCoreProxy.java DublinCoreImpl.java
  Log:
  The Dublin Core class has been rewritten to make proper use of the GoF
  Proxy Pattern. The old 'clever' algorithm had severe timing flaws,
  whereas the new algorithm is based on tried and proven technology.
  So the DublinCore class has been transformed into an interface, a
  proxy and an actual implementation which is used by the proxy.
  
  Revision  Changes    Path
  1.18      +30 -334   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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DublinCore.java	21 Aug 2003 17:56:10 -0000	1.17
  +++ DublinCore.java	28 Aug 2003 09:51:53 -0000	1.18
  @@ -53,279 +53,22 @@
    DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
   </License>
   */
  -package org.apache.lenya.cms.publication;
  -
  -import org.apache.lenya.xml.DocumentHelper;
  -import org.apache.lenya.xml.NamespaceHelper;
   
  -import java.io.File;
  -import java.io.IOException;
  -import java.util.Date;
  -import java.util.HashMap;
  -import java.util.Map;
  -
  -import javax.xml.parsers.ParserConfigurationException;
  -import javax.xml.transform.TransformerConfigurationException;
  -import javax.xml.transform.TransformerException;
  -
  -import org.w3c.dom.Element;
  -import org.w3c.dom.NodeList;
  -import org.xml.sax.SAXException;
  +package org.apache.lenya.cms.publication;
   
   /**
  - * Access dublin core meta data in documents.
  - * This class uses the dublin core specification from 2003-03-04.
  - *
  - * @author <a href="mailto:gregor@apache.org">Gregor J. Rothfuss</a>
  + * 
  + * @author egli
  + * 
    */
  -public class DublinCore {
  -    private Document cmsdocument;
  -    private File infofile;
  -    private Date timestamp = new Date(0);
  -
  -    private Map elements = new HashMap();
  -    private Map terms = new HashMap();
  +public interface DublinCore {
       
  -    private static final String META = "meta";
  -
  -    // Dublin Core Elements
  -
  -    private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
  -    private static final String DC_PREFIX = "dc";
  -
  -    private static final String ELEMENT_TITLE = "title";
  -    private static final String ELEMENT_CREATOR = "creator";
  -    private static final String ELEMENT_SUBJECT = "subject";
  -    private static final String ELEMENT_DESCRIPTION = "description";
  -    private static final String ELEMENT_PUBLISHER = "publisher";
  -    private static final String ELEMENT_CONTRIBUTOR = "contributor";
  -    private static final String ELEMENT_DATE = "date";
  -    private static final String ELEMENT_TYPE = "type";
  -    private static final String ELEMENT_FORMAT = "format";
  -    private static final String ELEMENT_IDENTIFIER = "identifier";
  -    private static final String ELEMENT_SOURCE = "source";
  -    private static final String ELEMENT_LANGUAGE = "language";
  -    private static final String ELEMENT_RELATION = "relation";
  -    private static final String ELEMENT_COVERAGE = "coverage";
  -    private static final String ELEMENT_RIGHTS = "rights";
  -
  -    private static final String[] ELEMENTS =
  -        {
  -            ELEMENT_TITLE,
  -            ELEMENT_CREATOR,
  -            ELEMENT_SUBJECT,
  -            ELEMENT_DESCRIPTION,
  -            ELEMENT_PUBLISHER,
  -            ELEMENT_CONTRIBUTOR,
  -            ELEMENT_DATE,
  -            ELEMENT_TYPE,
  -            ELEMENT_FORMAT,
  -            ELEMENT_IDENTIFIER,
  -            ELEMENT_SOURCE,
  -            ELEMENT_LANGUAGE,
  -            ELEMENT_RELATION,
  -            ELEMENT_COVERAGE,
  -            ELEMENT_RIGHTS };
  -
  -    // Dublin Core Terms
  -
  -    private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
  -    private static final String DCTERMS_PREFIX = "dcterms";
  -
  -    private static final String TERM_AUDIENCE = "audience";
  -    private static final String TERM_ALTERNATIVE = "alternative";
  -    private static final String TERM_TABLEOFCONTENTS = "tableOfContents";
  -    private static final String TERM_ABSTRACT = "abstract";
  -    private static final String TERM_CREATED = "created";
  -    private static final String TERM_VALID = "valid";
  -    private static final String TERM_AVAILABLE = "available";
  -    private static final String TERM_ISSUED = "issued";
  -    private static final String TERM_MODIFIED = "modified";
  -    private static final String TERM_EXTENT = "extent";
  -    private static final String TERM_MEDIUM = "medium";
  -    private static final String TERM_ISVERSIONOF = "isVersionOf";
  -    private static final String TERM_HASVERSION = "hasVersion";
  -    private static final String TERM_ISREPLACEDBY = "isReplacedBy";
  -    private static final String TERM_REPLACES = "replaces";
  -    private static final String TERM_ISREQUIREDBY = "isRequiredBy";
  -    private static final String TERM_REQUIRES = "requires";
  -    private static final String TERM_ISPARTOF = "isPartOf";
  -    private static final String TERM_HASPART = "hasPart";
  -    private static final String TERM_ISREFERENCEDBY = "isReferencedBy";
  -    private static final String TERM_REFERENCES = "references";
  -    private static final String TERM_ISFORMATOF = "isFormatOf";
  -    private static final String TERM_HASFORMAT = "hasFormat";
  -    private static final String TERM_CONFORMSTO = "conformsTo";
  -    private static final String TERM_SPATIAL = "spatial";
  -    private static final String TERM_TEMPORAL = "temporal";
  -    private static final String TERM_MEDIATOR = "mediator";
  -    private static final String TERM_DATEACCEPTED = "dateAccepted";
  -    private static final String TERM_DATECOPYRIGHTED = "dateCopyrighted";
  -    private static final String TERM_DATESUBMITTED = "dateSubmitted";
  -    private static final String TERM_EDUCATIONLEVEL = "educationLevel";
  -    private static final String TERM_ACCESSRIGHTS = "accessRights";
  -    private static final String TERM_BIBLIOGRAPHICCITATION = "bibliographicCitation";
  -
  -    private static final String[] TERMS =
  -        {
  -            TERM_AUDIENCE,
  -            TERM_ALTERNATIVE,
  -            TERM_TABLEOFCONTENTS,
  -            TERM_ABSTRACT,
  -            TERM_CREATED,
  -            TERM_EXTENT,
  -            TERM_AVAILABLE,
  -            TERM_ISSUED,
  -            TERM_MODIFIED,
  -            TERM_EXTENT,
  -            TERM_MEDIUM,
  -            TERM_ISVERSIONOF,
  -            TERM_HASVERSION,
  -            TERM_ISREPLACEDBY,
  -            TERM_REPLACES,
  -            TERM_ISREQUIREDBY,
  -            TERM_REQUIRES,
  -            TERM_ISPARTOF,
  -            TERM_HASPART,
  -            TERM_ISREFERENCEDBY,
  -            TERM_REFERENCES,
  -            TERM_ISFORMATOF,
  -            TERM_HASFORMAT,
  -            TERM_CONFORMSTO,
  -            TERM_SPATIAL,
  -            TERM_TEMPORAL,
  -            TERM_MEDIATOR,
  -            TERM_DATEACCEPTED,
  -            TERM_DATECOPYRIGHTED,
  -            TERM_DATESUBMITTED,
  -            TERM_EDUCATIONLEVEL,
  -            TERM_ACCESSRIGHTS,
  -            TERM_BIBLIOGRAPHICCITATION };
  -
  -    /** 
  -     * 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(),
  -		        cmsdocument.getArea(),
  -		        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);
  -            }
  -            
  -            Element metaElement = getMetaElement(doc);
  -
  -            String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
  -            String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
  -            String[][] arrays = { ELEMENTS, TERMS };
  -            Map[] maps = { elements, terms };
  -
  -            for (int type = 0; type < 2; type++) {
  -                NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
  -                String[] elementNames = arrays[type];
  -                for (int i = 0; i < elementNames.length; i++) {
  -                    Element child = helper.getFirstChild(metaElement, elementNames[i]);
  -                    if (child != null) {
  -                        String value = DocumentHelper.getSimpleElementText(child);
  -                        maps[type].put(elementNames[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;
  -
  -        Element metaElement = getMetaElement(doc);
  -
  -        String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
  -        String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
  -        String[][] arrays = { ELEMENTS, TERMS };
  -        Map[] maps = { elements, terms };
  -
  -        for (int type = 0; type < 2; type++) {
  -            NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
  -            String[] elementNames = arrays[type];
  -            for (int i = 0; i < elementNames.length; i++) {
  -                Element element = helper.getFirstChild(metaElement, elementNames[i]);
  -                if (element != null) {
  -                    metaElement.removeChild(element);
  -                }
  -                String value = (String) maps[type].get(elementNames[i]);
  -                if (value != null) {
  -                    element = helper.createElement(elementNames[i], value);
  -                    metaElement.appendChild(element);
  -                }
  -            }
  -        }
  -
  -        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);
  -        }
  -
  -    }
  -
  -    /**
  -     * Returns the Lenya meta data element.
  -     * @param doc The XML document.
  -     * @return A DOM element.
  -     */
  -    protected Element getMetaElement(org.w3c.dom.Document doc) {
  -        NamespaceHelper namespaceHelper =
  -            new NamespaceHelper(PageEnvelope.NAMESPACE, PageEnvelope.DEFAULT_PREFIX, doc);
  -        Element documentElement = doc.getDocumentElement();
  -        Element metaElement = namespaceHelper.getFirstChild(documentElement, META);
  -        return metaElement;
  -    }
  +    void save() throws DocumentException;
   
       /**
        * Get the creator
  @@ -334,19 +77,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getCreator() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_CREATOR);
  -    }
  +    String getCreator() throws DocumentException;
   
       /**
        * Set the DC creator
        * 
        * @param creator the Creator
        */
  -    public void setCreator(String creator) {
  -        elements.put(ELEMENT_CREATOR, creator);
  -    }
  +    void setCreator(String creator);
   
       /**
        * Get the title
  @@ -355,19 +93,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getTitle() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_TITLE);
  -    }
  +    String getTitle() throws DocumentException;
   
       /**
        * Set the DC title
        * 
        * @param title the title
        */
  -    public void setTitle(String title) {
  -        elements.put(ELEMENT_TITLE, title);
  -    }
  +    void setTitle(String title);
   
       /**
        * Get the description
  @@ -376,19 +109,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getDescription() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_DESCRIPTION);
  -    }
  +    String getDescription() throws DocumentException;
   
       /**
        * Set the DC Description
        * 
        * @param description the description
        */
  -    public void setDescription(String description) {
  -        elements.put(ELEMENT_DESCRIPTION, description);
  -    }
  +    void setDescription(String description);
   
       /**
        * Get the identifier
  @@ -397,19 +125,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getIdentifier() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_IDENTIFIER);
  -    }
  +    String getIdentifier() throws DocumentException;
   
       /**
        * Set the DC Identifier
        * 
        * @param identifier the identifier
        */
  -    public void setIdentifier(String identifier) {
  -        elements.put(ELEMENT_IDENTIFIER, identifier);
  -    }
  +    void setIdentifier(String identifier);
   
       /**
        * Get the subject.
  @@ -418,19 +141,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getSubject() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_SUBJECT);
  -    }
  +    String getSubject() throws DocumentException;
   
       /**
        * Set the DC Subject
        * 
        * @param subject the subject
        */
  -    public void setSubject(String subject) {
  -        elements.put(ELEMENT_SUBJECT, subject);
  -    }
  +    void setSubject(String subject);
   
       /**
        * Get the publisher
  @@ -439,19 +157,14 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getPublisher() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_PUBLISHER);
  -    }
  +    String getPublisher() throws DocumentException;
   
       /**
        * Set the publisher
        * 
        * @param publisher the publisher
        */
  -    public void setPublisher(String publisher) {
  -        elements.put(ELEMENT_PUBLISHER, publisher);
  -    }
  +    void setPublisher(String publisher);
   
       /**
        * Get the date of issue
  @@ -460,20 +173,15 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getDateIssued() throws DocumentException {
  -        checkValidity();
  -        return (String) terms.get(TERM_ISSUED);
  -    }
  -
  +    String getDateIssued() throws DocumentException;
  +    
       /**
        * Set the date of issue
        * 
        * @param dateIssued the date of issue
        */
  -    public void setDateIssued(String dateIssued) {
  -        terms.put(TERM_ISSUED, dateIssued);
  -    }
  -
  +    void setDateIssued(String dateIssued);
  +    
       /**
        * Get the date of creation
        * 
  @@ -481,21 +189,15 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getDateCreated() throws DocumentException {
  -        checkValidity();
  -        return (String) terms.get(TERM_CREATED);
  -    }
  -
  +    String getDateCreated() throws DocumentException;
  +    
       /**
        * Set the date of creation
        * 
        * @param dateCreated the date of creation
        */
  -    public void setDateCreated(String dateCreated) {
  -        terms.put(TERM_CREATED, dateCreated);
  -    }
  -
  -
  +    void setDateCreated(String dateCreated);
  +    
       /**
        * Get the rights
        * 
  @@ -503,18 +205,12 @@
        * 
        * @throws DocumentException if an error occurs
        */
  -    public String getRights() throws DocumentException {
  -        checkValidity();
  -        return (String) elements.get(ELEMENT_RIGHTS);
  -    }
  -
  +    String getRights() throws DocumentException;
  +    
       /**
        * Set the DC Rights
        * 
        * @param rights the rights
        */
  -    public void setRights(String rights) {
  -        elements.put(ELEMENT_RIGHTS, rights);
  -    }
  -
  +    void setRights(String rights);
   }
  
  
  
  1.26      +5 -10     cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
  
  Index: DefaultDocument.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocument.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DefaultDocument.java	13 Aug 2003 15:05:59 -0000	1.25
  +++ DefaultDocument.java	28 Aug 2003 09:51:53 -0000	1.26
  @@ -56,8 +56,6 @@
   package org.apache.lenya.cms.publication;
   
   import java.io.File;
  -import org.w3c.dom.NodeList;
  -
   import java.util.ArrayList;
   import java.util.Date;
   
  @@ -70,11 +68,8 @@
   	private String id;
   	private Publication publication;
   	private DublinCore dublincore;
  -	private NodeList nodelist;
  -	
  -	private static final String PAGEENVELOPE_NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
   
  -    /**
  +	/**
        * Creates a new instance of DefaultDocument.
        * @param publication The publication the document belongs to.
        * @param id The document ID (starting with a slash).
  @@ -87,7 +82,7 @@
   
           assert (publication != null) && !"".equals(publication);
           this.publication = publication;
  -        this.dublincore =  new DublinCore(this);
  +        this.dublincore =  new DublinCoreProxy(this);
       }
   
       /**
  @@ -106,7 +101,7 @@
   
   		setArea(area);
   
  -		this.dublincore =  new DublinCore(this);
  +		this.dublincore =  new DublinCoreProxy(this);
   
       }
   
  @@ -128,7 +123,7 @@
   		this.language = language;
   		setArea(area);
   
  -		this.dublincore =  new DublinCore(this);
  +		this.dublincore =  new DublinCoreProxy(this);
   
   	}
   
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/publication/DublinCoreProxy.java
  
  Index: DublinCoreProxy.java
  ===================================================================
  /*
  $Id: DublinCoreProxy.java,v 1.1 2003/08/28 09:51:53 egli Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.cms.publication;
  
  /**
   * A proxy to the dublin core meta implementation so that meta data is 
   * only read from file when it is actually requested.
   *
   * @author <a href="mailto:egli@apache.org">Christian Egli</a>
   */
  public class DublinCoreProxy implements DublinCore {
  
      private DublinCore dcCore;
      private Document cmsDocument;
  
      /** 
       * Creates a new instance of Dublin Core
       * 
       * @param aDocument the document for which the Dublin Core instance is created.
       */
      public DublinCoreProxy(Document aDocument) {
          this.cmsDocument = aDocument;
      }
  
      /**
       * Instanciate a dublin core implementation object
       * 
       * @return a real dublin core object
       */
      protected DublinCore instance() {
          if (dcCore == null) {
              try {
                  dcCore = new DublinCoreImpl(this.cmsDocument);
              } catch (DocumentException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          return dcCore;
      }
      
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getCreator()
       */
      public String getCreator() throws DocumentException {
          return instance().getCreator();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getDateCreated()
       */
      public String getDateCreated() throws DocumentException {
          return instance().getDateCreated();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getDateIssued()
       */
      public String getDateIssued() throws DocumentException {
          return instance().getDateIssued();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getDescription()
       */
      public String getDescription() throws DocumentException {
          return instance().getDescription();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getIdentifier()
       */
      public String getIdentifier() throws DocumentException {
          return instance().getIdentifier();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getPublisher()
       */
      public String getPublisher() throws DocumentException {
          return instance().getPublisher();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getRights()
       */
      public String getRights() throws DocumentException {
          return instance().getRights();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getSubject()
       */
      public String getSubject() throws DocumentException {
          return instance().getSubject();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#getTitle()
       */
      public String getTitle() throws DocumentException {
          return instance().getTitle();
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setCreator(java.lang.String)
       */
      public void setCreator(String creator) {
          instance().setCreator(creator);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setDateCreated(java.lang.String)
       */
      public void setDateCreated(String dateCreated) {
          instance().setDateCreated(dateCreated);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setDateIssued(java.lang.String)
       */
      public void setDateIssued(String dateIssued) {
          instance().setDateIssued(dateIssued);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setDescription(java.lang.String)
       */
      public void setDescription(String description) {
          instance().setDescription(description);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setIdentifier(java.lang.String)
       */
      public void setIdentifier(String identifier) {
          instance().setIdentifier(identifier);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setPublisher(java.lang.String)
       */
      public void setPublisher(String publisher) {
          instance().setPublisher(publisher);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setRights(java.lang.String)
       */
      public void setRights(String rights) {
          instance().setRights(rights);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setSubject(java.lang.String)
       */
      public void setSubject(String subject) {
          instance().setSubject(subject);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#setTitle(java.lang.String)
       */
      public void setTitle(String title) {
          instance().setTitle(title);
      }
  
      /**
       *  (non-Javadoc)
       * @see org.apache.lenya.cms.publication.DublinCore#save()
       */
      public void save() throws DocumentException {
          instance().save();
      }
  
  }
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/publication/DublinCoreImpl.java
  
  Index: DublinCoreImpl.java
  ===================================================================
  /*
  $Id: DublinCoreImpl.java,v 1.1 2003/08/28 09:51:53 egli Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.cms.publication;
  
  import org.apache.lenya.xml.DocumentHelper;
  import org.apache.lenya.xml.NamespaceHelper;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.xml.parsers.ParserConfigurationException;
  import javax.xml.transform.TransformerConfigurationException;
  import javax.xml.transform.TransformerException;
  
  import org.w3c.dom.Element;
  import org.xml.sax.SAXException;
  
  /**
   * Access dublin core meta data in documents.
   * This class uses the dublin core specification from 2003-03-04.
   *
   * @author <a href="mailto:gregor@apache.org">Gregor J. Rothfuss</a>
   */
  public class DublinCoreImpl implements DublinCore {
      private Document cmsdocument;
      private File infofile;
  
      private Map elements = new HashMap();
      private Map terms = new HashMap();
      
      private static final String META = "meta";
  
      // Dublin Core Elements
  
      private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
      private static final String DC_PREFIX = "dc";
  
      private static final String ELEMENT_TITLE = "title";
      private static final String ELEMENT_CREATOR = "creator";
      private static final String ELEMENT_SUBJECT = "subject";
      private static final String ELEMENT_DESCRIPTION = "description";
      private static final String ELEMENT_PUBLISHER = "publisher";
      private static final String ELEMENT_CONTRIBUTOR = "contributor";
      private static final String ELEMENT_DATE = "date";
      private static final String ELEMENT_TYPE = "type";
      private static final String ELEMENT_FORMAT = "format";
      private static final String ELEMENT_IDENTIFIER = "identifier";
      private static final String ELEMENT_SOURCE = "source";
      private static final String ELEMENT_LANGUAGE = "language";
      private static final String ELEMENT_RELATION = "relation";
      private static final String ELEMENT_COVERAGE = "coverage";
      private static final String ELEMENT_RIGHTS = "rights";
  
      private static final String[] ELEMENTS =
          {
              ELEMENT_TITLE,
              ELEMENT_CREATOR,
              ELEMENT_SUBJECT,
              ELEMENT_DESCRIPTION,
              ELEMENT_PUBLISHER,
              ELEMENT_CONTRIBUTOR,
              ELEMENT_DATE,
              ELEMENT_TYPE,
              ELEMENT_FORMAT,
              ELEMENT_IDENTIFIER,
              ELEMENT_SOURCE,
              ELEMENT_LANGUAGE,
              ELEMENT_RELATION,
              ELEMENT_COVERAGE,
              ELEMENT_RIGHTS };
  
      // Dublin Core Terms
  
      private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
      private static final String DCTERMS_PREFIX = "dcterms";
  
      private static final String TERM_AUDIENCE = "audience";
      private static final String TERM_ALTERNATIVE = "alternative";
      private static final String TERM_TABLEOFCONTENTS = "tableOfContents";
      private static final String TERM_ABSTRACT = "abstract";
      private static final String TERM_CREATED = "created";
      private static final String TERM_VALID = "valid";
      private static final String TERM_AVAILABLE = "available";
      private static final String TERM_ISSUED = "issued";
      private static final String TERM_MODIFIED = "modified";
      private static final String TERM_EXTENT = "extent";
      private static final String TERM_MEDIUM = "medium";
      private static final String TERM_ISVERSIONOF = "isVersionOf";
      private static final String TERM_HASVERSION = "hasVersion";
      private static final String TERM_ISREPLACEDBY = "isReplacedBy";
      private static final String TERM_REPLACES = "replaces";
      private static final String TERM_ISREQUIREDBY = "isRequiredBy";
      private static final String TERM_REQUIRES = "requires";
      private static final String TERM_ISPARTOF = "isPartOf";
      private static final String TERM_HASPART = "hasPart";
      private static final String TERM_ISREFERENCEDBY = "isReferencedBy";
      private static final String TERM_REFERENCES = "references";
      private static final String TERM_ISFORMATOF = "isFormatOf";
      private static final String TERM_HASFORMAT = "hasFormat";
      private static final String TERM_CONFORMSTO = "conformsTo";
      private static final String TERM_SPATIAL = "spatial";
      private static final String TERM_TEMPORAL = "temporal";
      private static final String TERM_MEDIATOR = "mediator";
      private static final String TERM_DATEACCEPTED = "dateAccepted";
      private static final String TERM_DATECOPYRIGHTED = "dateCopyrighted";
      private static final String TERM_DATESUBMITTED = "dateSubmitted";
      private static final String TERM_EDUCATIONLEVEL = "educationLevel";
      private static final String TERM_ACCESSRIGHTS = "accessRights";
      private static final String TERM_BIBLIOGRAPHICCITATION = "bibliographicCitation";
  
      private static final String[] TERMS =
          {
              TERM_AUDIENCE,
              TERM_ALTERNATIVE,
              TERM_TABLEOFCONTENTS,
              TERM_ABSTRACT,
              TERM_CREATED,
              TERM_VALID,
              TERM_EXTENT,
              TERM_AVAILABLE,
              TERM_ISSUED,
              TERM_MODIFIED,
              TERM_EXTENT,
              TERM_MEDIUM,
              TERM_ISVERSIONOF,
              TERM_HASVERSION,
              TERM_ISREPLACEDBY,
              TERM_REPLACES,
              TERM_ISREQUIREDBY,
              TERM_REQUIRES,
              TERM_ISPARTOF,
              TERM_HASPART,
              TERM_ISREFERENCEDBY,
              TERM_REFERENCES,
              TERM_ISFORMATOF,
              TERM_HASFORMAT,
              TERM_CONFORMSTO,
              TERM_SPATIAL,
              TERM_TEMPORAL,
              TERM_MEDIATOR,
              TERM_DATEACCEPTED,
              TERM_DATECOPYRIGHTED,
              TERM_DATESUBMITTED,
              TERM_EDUCATIONLEVEL,
              TERM_ACCESSRIGHTS,
              TERM_BIBLIOGRAPHICCITATION };
  
      /** 
       * Creates a new instance of Dublin Core
       * 
       * @param aDocument the document for which the Dublin Core instance is created.
       * 
       * @throws DocumentException if an error occurs
       */
      protected DublinCoreImpl(Document aDocument) throws DocumentException {
          this.cmsdocument = aDocument;
          infofile =
              cmsdocument.getPublication().getPathMapper().getFile(
                  cmsdocument.getPublication(),
  		        cmsdocument.getArea(),
  		        cmsdocument.getId(),
                  cmsdocument.getLanguage());
  
          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);
          }
              
          Element metaElement = getMetaElement(doc);
  
          String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
          String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
          String[][] arrays = { ELEMENTS, TERMS };
          Map[] maps = { elements, terms };
  
          for (int type = 0; type < 2; type++) {
              NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
              String[] elementNames = arrays[type];
              for (int i = 0; i < elementNames.length; i++) {
                  Element child = helper.getFirstChild(metaElement, elementNames[i]);
                  if (child != null) {
                      String value = DocumentHelper.getSimpleElementText(child);
                      maps[type].put(elementNames[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);
          }
          
          Element metaElement = getMetaElement(doc);
  
          String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
          String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
          String[][] arrays = { ELEMENTS, TERMS };
          Map[] maps = { elements, terms };
  
          for (int type = 0; type < 2; type++) {
              NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
              String[] elementNames = arrays[type];
              for (int i = 0; i < elementNames.length; i++) {
                  Element element = helper.getFirstChild(metaElement, elementNames[i]);
                  if (element != null) {
                      metaElement.removeChild(element);
                  }
                  String value = (String) maps[type].get(elementNames[i]);
                  if (value != null) {
                      element = helper.createElement(elementNames[i], value);
                      metaElement.appendChild(element);
                  }
              }
          }
  
          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);
          }
  
      }
  
      /**
       * Returns the Lenya meta data element.
       * @param doc The XML document.
       * @return A DOM element.
       */
      protected Element getMetaElement(org.w3c.dom.Document doc) {
          NamespaceHelper namespaceHelper =
              new NamespaceHelper(PageEnvelope.NAMESPACE, PageEnvelope.DEFAULT_PREFIX, doc);
          Element documentElement = doc.getDocumentElement();
          Element metaElement = namespaceHelper.getFirstChild(documentElement, META);
          return metaElement;
      }
  
      /**
       * Get the creator
       * 
       * @return the creator
       * 
       * @throws DocumentException if an error occurs
       */
      public String getCreator() throws DocumentException {
          return (String) elements.get(ELEMENT_CREATOR);
      }
  
      /**
       * Set the DC creator
       * 
       * @param creator the Creator
       */
      public void setCreator(String creator) {
          elements.put(ELEMENT_CREATOR, creator);
      }
  
      /**
       * Get the title
       * 
       * @return the title
       * 
       * @throws DocumentException if an error occurs
       */
      public String getTitle() throws DocumentException {
          return (String) elements.get(ELEMENT_TITLE);
      }
  
      /**
       * Set the DC title
       * 
       * @param title the title
       */
      public void setTitle(String title) {
          elements.put(ELEMENT_TITLE, title);
      }
  
      /**
       * Get the description
       * 
       * @return the description
       * 
       * @throws DocumentException if an error occurs
       */
      public String getDescription() throws DocumentException {
          return (String) elements.get(ELEMENT_DESCRIPTION);
      }
  
      /**
       * Set the DC Description
       * 
       * @param description the description
       */
      public void setDescription(String description) {
          elements.put(ELEMENT_DESCRIPTION, description);
      }
  
      /**
       * Get the identifier
       * 
       * @return the identifier
       * 
       * @throws DocumentException if an error occurs
       */
      public String getIdentifier() throws DocumentException {
          return (String) elements.get(ELEMENT_IDENTIFIER);
      }
  
      /**
       * Set the DC Identifier
       * 
       * @param identifier the identifier
       */
      public void setIdentifier(String identifier) {
          elements.put(ELEMENT_IDENTIFIER, identifier);
      }
  
      /**
       * Get the subject.
       * 
       * @return the subject
       * 
       * @throws DocumentException if an error occurs
       */
      public String getSubject() throws DocumentException {
          return (String) elements.get(ELEMENT_SUBJECT);
      }
  
      /**
       * Set the DC Subject
       * 
       * @param subject the subject
       */
      public void setSubject(String subject) {
          elements.put(ELEMENT_SUBJECT, subject);
      }
  
      /**
       * Get the publisher
       * 
       * @return the publisher
       * 
       * @throws DocumentException if an error occurs
       */
      public String getPublisher() throws DocumentException {
          return (String) elements.get(ELEMENT_PUBLISHER);
      }
  
      /**
       * Set the publisher
       * 
       * @param publisher the publisher
       */
      public void setPublisher(String publisher) {
          elements.put(ELEMENT_PUBLISHER, publisher);
      }
  
      /**
       * Get the date of issue
       * 
       * @return the date of issue
       * 
       * @throws DocumentException if an error occurs
       */
      public String getDateIssued() throws DocumentException {
          return (String) terms.get(TERM_ISSUED);
      }
  
      /**
       * Set the date of issue
       * 
       * @param dateIssued the date of issue
       */
      public void setDateIssued(String dateIssued) {
          terms.put(TERM_ISSUED, dateIssued);
      }
  
      /**
       * Get the date of creation
       * 
       * @return the date of creation
       * 
       * @throws DocumentException if an error occurs
       */
      public String getDateCreated() throws DocumentException {
          return (String) terms.get(TERM_CREATED);
      }
  
      /**
       * Set the date of creation
       * 
       * @param dateCreated the date of creation
       */
      public void setDateCreated(String dateCreated) {
          terms.put(TERM_CREATED, dateCreated);
      }
  
  
      /**
       * Get the rights
       * 
       * @return the rights
       * 
       * @throws DocumentException if an error occurs
       */
      public String getRights() throws DocumentException {
          return (String) elements.get(ELEMENT_RIGHTS);
      }
  
      /**
       * Set the DC Rights
       * 
       * @param rights the rights
       */
      public void setRights(String rights) {
          elements.put(ELEMENT_RIGHTS, rights);
      }
  
  }
  
  

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