You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/11/28 17:57:17 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication Publication.java AbstractPublication.java

andreas     2003/11/28 08:57:17

  Modified:    src/java/org/apache/lenya/cms/publication Publication.java
                        AbstractPublication.java
  Log:
  implemented document transfer in site tree
  
  Revision  Changes    Path
  1.37      +8 -5      cocoon-lenya/src/java/org/apache/lenya/cms/publication/Publication.java
  
  Index: Publication.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/Publication.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- Publication.java	27 Nov 2003 14:01:49 -0000	1.36
  +++ Publication.java	28 Nov 2003 16:57:16 -0000	1.37
  @@ -132,19 +132,21 @@
       DocumentBuilder getDocumentBuilder();
   
       /**
  -     * Copies a document source from one location to another location.
  +     * Copies a document from one location to another location.
        * @param sourceDocument The document to copy.
        * @param destinationDocument The destination document.
  -     * @throws PublicationException when an error occurs.
  +     * @throws PublicationException if a document which destinationDocument depends on
  +     * does not exist.
        */
       void copyDocument(Document sourceDocument, Document destinationDocument)
           throws PublicationException;
   
       /**
  -     * Copies a document source to another area.
  +     * Copies a document to another area.
        * @param sourceDocument The document to copy.
        * @param destinationArea The destination area.
  -     * @throws PublicationException when an error occurs.
  +     * @throws PublicationException if a document which the
  +     * destination document depends on does not exist.
        */
       void copyDocumentToArea(Document sourceDocument, String destinationArea)
           throws PublicationException;
  @@ -153,7 +155,8 @@
        * Copies a document set to another area.
        * @param documentSet The document set to copy.
        * @param destinationArea The destination area.
  -     * @throws PublicationException when an error occurs.
  +     * @throws PublicationException if a document which one of the
  +     * destination documents depends on does not exist.
        */
       void copyDocumentSetToArea(DocumentSet documentSet, String destinationArea)
           throws PublicationException;
  
  
  
  1.4       +88 -12    cocoon-lenya/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
  
  Index: AbstractPublication.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/AbstractPublication.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractPublication.java	28 Nov 2003 15:52:32 -0000	1.3
  +++ AbstractPublication.java	28 Nov 2003 16:57:16 -0000	1.4
  @@ -350,10 +350,10 @@
        */
       public boolean dependsOn(Document dependingDocument, Document requiredDocument)
           throws PublicationException {
  -        
  +
           Document[] requiredDocuments = getRequiredDocuments(dependingDocument);
           List requiredList = Arrays.asList(requiredDocuments);
  -        
  +
           return requiredList.contains(requiredDocument);
       }
   
  @@ -388,16 +388,92 @@
        */
       public void copyDocument(Document sourceDocument, Document destinationDocument)
           throws PublicationException {
  -            
  +
           copyDocumentSource(sourceDocument, destinationDocument);
  +
  +        try {
  +            SiteTree sourceTree = getSiteTree(sourceDocument.getArea());
  +            SiteTree destinationTree = getSiteTree(destinationDocument.getArea());
  +
  +            SiteTreeNode sourceNode = sourceTree.getNode(sourceDocument.getId());
  +            if (sourceNode == null) {
  +                throw new PublicationException(
  +                    "The node for source document [" + sourceDocument.getId() + "] doesn't exist!");
  +            } else {
  +
  +                SiteTreeNode[] siblings = sourceNode.getNextSiblings();
  +                String parentId = sourceNode.getAbsoluteParentId();
  +                SiteTreeNode sibling = null;
  +                String siblingDocId = null;
  +
  +                // same document ID -> insert at the same position
  +                if (sourceDocument.getId().equals(destinationDocument.getId())) {
  +                    for (int i = 0; i < siblings.length; i++) {
  +                        String docId = parentId + "/" + siblings[i].getId();
  +                        sibling = destinationTree.getNode(docId);
  +                        if (sibling != null) {
  +                            siblingDocId = docId;
  +                            break;
  +                        }
  +                    }
  +                }
  +
  +                Label label = sourceNode.getLabel(sourceDocument.getLanguage());
  +                if (label == null) {
  +                    // the node that we're trying to publish
  +                    // doesn't have this language
  +                    throw new PublicationException(
  +                        "The node "
  +                            + sourceDocument.getId()
  +                            + " doesn't contain a label for language "
  +                            + sourceDocument.getLanguage());
  +                } else {
  +                    SiteTreeNode destinationNode =
  +                        destinationTree.getNode(destinationDocument.getId());
  +                    if (destinationNode == null) {
  +                        Label[] labels = { label };
  +
  +                        if (siblingDocId == null) {
  +                            destinationTree.addNode(
  +                                destinationDocument.getId(),
  +                                labels,
  +                                sourceNode.getHref(),
  +                                sourceNode.getSuffix(),
  +                                sourceNode.hasLink());
  +                        } else {
  +                            destinationTree.addNode(
  +                                destinationDocument.getId(),
  +                                labels,
  +                                sourceNode.getHref(),
  +                                sourceNode.getSuffix(),
  +                                sourceNode.hasLink(),
  +                                siblingDocId);
  +                        }
  +
  +                    } else {
  +                        // if the node already exists in the live
  +                        // tree simply insert the label in the
  +                        // live tree
  +                        destinationTree.setLabel(destinationDocument.getId(), label);
  +                    }
  +                }
  +            }
  +
  +            destinationTree.save();
  +        } catch (SiteTreeException e) {
  +            throw new PublicationException(e);
  +        }
  +
       }
  -    
  +
       /**
  -     * Copies a document source.
  -     * @param sourceDocument The source document.
  -     * @param destinationDocument The destination document.
  -     * @throws PublicationException when something went wrong.
  -     */
  -    protected abstract void copyDocumentSource(Document sourceDocument, Document destinationDocument) throws PublicationException;
  -    
  +                 * Copies a document source.
  +                 * @param sourceDocument The source document.
  +                 * @param destinationDocument The destination document.
  +                 * @throws PublicationException when something went wrong.
  +                 */
  +    protected abstract void copyDocumentSource(
  +        Document sourceDocument,
  +        Document destinationDocument)
  +        throws PublicationException;
   }
  
  
  

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