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/07/09 14:59:59 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant TreePublisher.java

egli        2003/07/09 05:59:59

  Modified:    src/webapp/lenya/xslt/publishing screen.xsl
               src/webapp/lenya/pubs/default/config/tasks targets.xml
               src/java/org/apache/lenya/cms/ant TreePublisher.java
  Log:
  Publish should now correcly handle the multilingual case,
  i.e. only the requested label is published from the authoring
  to the live tree.
  
  Revision  Changes    Path
  1.6       +2 -0      cocoon-lenya/src/webapp/lenya/xslt/publishing/screen.xsl
  
  Index: screen.xsl
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/webapp/lenya/xslt/publishing/screen.xsl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- screen.xsl	13 Jun 2003 12:46:32 -0000	1.5
  +++ screen.xsl	9 Jul 2003 12:59:59 -0000	1.6
  @@ -19,6 +19,7 @@
   <xsl:variable name="uris"><xsl:value-of select="/usecase:publish/usecase:uris"/></xsl:variable>
   <xsl:variable name="sources"><xsl:value-of select="/usecase:publish/usecase:sources"/></xsl:variable>
   <xsl:variable name="document-id"><xsl:value-of select="/usecase:publish/usecase:document-id"/></xsl:variable>
  +<xsl:variable name="document-language"><xsl:value-of select="/usecase:publish/usecase:document-language"/></xsl:variable>
   <xsl:variable name="task-id"><xsl:value-of select="/usecase:publish/usecase:task-id"/></xsl:variable>
   
   <xsl:template match="/usecase:publish">
  @@ -34,6 +35,7 @@
           <input type="hidden" name="lenya.usecase" value="publish"/>
           <input type="hidden" name="lenya.step" value="publish"/>
           <input type="hidden" name="task-id" value="{$task-id}"/>
  +        <input type="hidden" name="document-language" value="{$document-language}"/>
           <xsl:call-template name="task-parameters">
             <xsl:with-param name="prefix" select="''"/>
           </xsl:call-template>
  
  
  
  1.7       +1 -0      cocoon-lenya/src/webapp/lenya/pubs/default/config/tasks/targets.xml
  
  Index: targets.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/webapp/lenya/pubs/default/config/tasks/targets.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- targets.xml	8 Jul 2003 16:16:09 -0000	1.6
  +++ targets.xml	9 Jul 2003 12:59:59 -0000	1.7
  @@ -74,6 +74,7 @@
   
     <publishtree 
         documentid= "${publish.documentid}"
  +      language= "${publish.language}"
         absolutetreeauthoringpath= "${pub.dir}/${authoring.dir}/${authoring.tree}"
         absolutetreelivepath = "${pub.dir}/${live.dir}/${authoring.tree}" 
         />
  
  
  
  1.6       +98 -23    cocoon-lenya/src/java/org/apache/lenya/cms/ant/TreePublisher.java
  
  Index: TreePublisher.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/TreePublisher.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TreePublisher.java	30 Jun 2003 11:42:51 -0000	1.5
  +++ TreePublisher.java	9 Jul 2003 12:59:59 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  -$Id
  +$Id$
   <License>
   
    ============================================================================
  @@ -56,26 +56,26 @@
   package org.apache.lenya.cms.ant;
   
   import org.apache.lenya.cms.publication.DefaultSiteTree;
  +import org.apache.lenya.cms.publication.Label;
   import org.apache.lenya.cms.publication.SiteTreeNode;
   import org.apache.lenya.cms.publishing.PublishingException;
   
   import org.apache.tools.ant.BuildException;
   
  -
   /**
  - * Ant task to publish the tree, adding a node for  the new published document
  - * in the live tree
  + * Ant task to publish the tree, adding a node for the new published
  + * document in the live tree
    */
   public class TreePublisher extends PublicationTask {
       private String documentid;
  +    private String language;
       private String absolutetreeauthoringpath;
       private String absolutetreelivepath;
   
       /**
        * Creates a new instance of TreePublisher
        */
  -    public TreePublisher() {
  -    }
  +    public TreePublisher() {}
   
       /**
        * Returns the document id
  @@ -96,6 +96,25 @@
       }
   
       /**
  +     * Get the language of the document to be published
  +     * 
  +     * @return a <code>String</code> containing the ISO string for
  +     * this language, e.g. "de", "en"
  +     */
  +    public String getLanguage() {
  +        return language;
  +    }
  +
  +    /**
  +     * Set the language of the document to be published
  +     * 
  +     * @param string the ISO string for this language, e.g. "de", "en"
  +     */
  +    public void setLanguage(String string) {
  +        language = string;
  +    }
  +
  +    /**
        * Returns the absolute authoring path for the tree
        *
        * @return DOCUMENT ME!
  @@ -134,32 +153,81 @@
       /**
        * adds a node for the published document in the live tree
        *
  -     * @param documentid The id of the published document
  -     * @param absolutetreeauthoringpath The path for the tree in authoring
  -     * @param absolutetreelivepath The path for the tree in live
  -     *
  -     * @throws PublishingException DOCUMENT ME!
  -     */
  -    public void publish(String documentid, String absolutetreeauthoringpath,
  -        String absolutetreelivepath) throws PublishingException {
  +     * @param documentId The id of the published document
  +     * @param language the language for which this document is to be published. 
  +     * 	Can be null if all languages are to be published.
  +     * @param absoluteTreeAuthoringPath The path for the tree in authoring
  +     * @param absoluteTreeLivePath The path for the tree in live
  +     *
  +     * @throws PublishingException if the publication failed.
  +     */
  +    public void publish(
  +        String documentId,
  +        String language,
  +        String absoluteTreeAuthoringPath,
  +        String absoluteTreeLivePath)
  +        throws PublishingException {
           DefaultSiteTree authoringTree = null;
           DefaultSiteTree liveTree = null;
   
           try {
  -            authoringTree = new DefaultSiteTree(absolutetreeauthoringpath);
  -            liveTree = new DefaultSiteTree(absolutetreelivepath);
  +            authoringTree = new DefaultSiteTree(absoluteTreeAuthoringPath);
  +            liveTree = new DefaultSiteTree(absoluteTreeLivePath);
   
  -            SiteTreeNode documentNode = authoringTree.getNode(documentid);
  +            SiteTreeNode authoringNode = authoringTree.getNode(documentId);
   
  -            if (documentNode != null) {
  -                liveTree.addNode(documentNode);
  +            if (authoringNode != null) {
  +                if (language == null) {
  +                    // no language was specified. Simply publish the
  +                    // node including all languages.
  +                    liveTree.addNode(authoringNode);
  +                } else {
  +                    // a language was specified. Let's see if this
  +                    // node even has an entry for the specified
  +                    // language.
  +                    Label label = authoringNode.getLabel(language);
  +                    if (label != null) {
  +                        // check if this node has already been
  +                        // published
  +                        SiteTreeNode liveNode = liveTree.getNode(documentId);
  +                        if (liveNode != null) {
  +                            // if the node already exists in the live
  +                            // tree simply insert the label in the
  +                            // live tree
  +                            liveTree.addLabel(documentId, label);
  +                        } else {
  +                            // if the node doesn't exist, add it and
  +                            // add the specified label to it.
  +                            Label[] labels = { label };
  +                            liveTree.addNode(
  +                                documentId,
  +                                labels,
  +                                authoringNode.getHref(),
  +                                authoringNode.getSuffix(),
  +                                authoringNode.hasLink());
  +                        }
  +                    } else {
  +                        // the node that we're trying to publish
  +                        // doesn't have this language
  +                        throw new PublishingException(
  +                            "The node "
  +                                + documentId
  +                                + " doesn't contain a label for language "
  +                                + language);
  +                    }
  +                }
               } else {
  -                throw new PublishingException("No node found for the document " + documentid);
  +                throw new PublishingException(
  +                    "No node found for the document " + documentId);
               }
   
               liveTree.save();
  +        } catch (PublishingException e) {
  +            throw e;
           } catch (Exception e) {
  -            throw new PublishingException("Couldn't publish the tree :" + absolutetreelivepath, e);
  +            throw new PublishingException(
  +                "Couldn't publish the tree :" + absoluteTreeLivePath,
  +                e);
           }
       }
   
  @@ -171,10 +239,17 @@
       public void execute() throws BuildException {
           try {
               log("document id: " + getDocumentid());
  -            log("Absolute Tree Authoring Path: " + getAbsolutetreeauthoringpath());
  +            log("language: " + getLanguage());
  +            log(
  +                "Absolute Tree Authoring Path: "
  +                    + getAbsolutetreeauthoringpath());
               log("Absolute Tree Live Path: " + getAbsolutetreelivepath());
   
  -            publish(getDocumentid(), getAbsolutetreeauthoringpath(), getAbsolutetreelivepath());
  +            publish(
  +                getDocumentid(),
  +                getLanguage(),
  +                getAbsolutetreeauthoringpath(),
  +                getAbsolutetreelivepath());
           } 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