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/12/04 19:07:14 UTC

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

andreas     2003/12/04 10:07:14

  Modified:    src/java/org/apache/lenya/cms/publication Publication.java
                        AbstractPublication.java DefaultDocument.java
  Log:
  sitetree is now optional
  
  Revision  Changes    Path
  1.39      +2 -0      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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- Publication.java	1 Dec 2003 16:05:29 -0000	1.38
  +++ Publication.java	4 Dec 2003 18:07:14 -0000	1.39
  @@ -26,6 +26,8 @@
       String TRASH_AREA = "trash";
       String ELEMENT_PATH_MAPPER = "path-mapper";
       String ELEMENT_DOCUMENT_BUILDER = "document-builder";
  +    String ELEMENT_SITE_STRUCTURE = "site-structure";
  +    String ATTRIBUTE_TYPE = "type";
       String LANGUAGES = "languages";
       String LANGUAGE = "language";
       String DEFAULT_LANGUAGE_ATTR = "default";
  
  
  
  1.8       +150 -114  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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractPublication.java	2 Dec 2003 13:18:13 -0000	1.7
  +++ AbstractPublication.java	4 Dec 2003 18:07:14 -0000	1.8
  @@ -82,6 +82,7 @@
       private String defaultLanguage = null;
       private String breadcrumbprefix = null;
       private HashMap siteTrees = new HashMap();
  +    private boolean hasSitetree = true;
   
       /** 
        * Creates a new instance of Publication
  @@ -127,7 +128,8 @@
               }
   
               try {
  -                Configuration documentBuilderConfiguration = config.getChild(ELEMENT_DOCUMENT_BUILDER, false);
  +                Configuration documentBuilderConfiguration =
  +                    config.getChild(ELEMENT_DOCUMENT_BUILDER, false);
                   if (documentBuilderConfiguration != null) {
                       documentBuilderClassName = documentBuilderConfiguration.getValue();
                       Class documentBuilderClass = Class.forName(documentBuilderClassName);
  @@ -149,6 +151,15 @@
                   }
               }
   
  +            Configuration siteStructureConfiguration =
  +                config.getChild(ELEMENT_SITE_STRUCTURE, false);
  +            if (siteStructureConfiguration != null) {
  +                String siteStructureType = siteStructureConfiguration.getAttribute(ATTRIBUTE_TYPE);
  +                if (!siteStructureType.equals("sitetree")) {
  +                    hasSitetree = false;
  +                }
  +            }
  +
           } catch (PublicationException e) {
               throw e;
           } catch (Exception e) {
  @@ -283,11 +294,13 @@
   
           DefaultSiteTree sitetree = null;
   
  -        if (siteTrees.containsKey(area)) {
  -            sitetree = (DefaultSiteTree) siteTrees.get(area);
  -        } else {
  -            sitetree = new DefaultSiteTree(getDirectory(), area);
  -            siteTrees.put(area, sitetree);
  +        if (hasSitetree) {
  +            if (siteTrees.containsKey(area)) {
  +                sitetree = (DefaultSiteTree) siteTrees.get(area);
  +            } else {
  +                sitetree = new DefaultSiteTree(getDirectory(), area);
  +                siteTrees.put(area, sitetree);
  +            }
           }
           return sitetree;
       }
  @@ -299,11 +312,11 @@
        * @return A document builder.
        */
       public DocumentBuilder getDocumentBuilder() {
  -        
  +
           if (documentBuilder == null) {
               throw new IllegalStateException("The document builder was not defined in publication.xconf!");
           }
  -        
  +
           return documentBuilder;
       }
   
  @@ -399,79 +412,93 @@
   
           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 {
  +        copySiteStructure(sourceDocument, destinationDocument);
  +    }
   
  -                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;
  -                        }
  -                    }
  -                }
  +    /**
  +     * Copies a document in the site structure.
  +     * @param sourceDocument The source document.
  +     * @param destinationDocument The destination document.
  +     * @throws PublicationException when something went wrong.
  +     */
  +    protected void copySiteStructure(Document sourceDocument, Document destinationDocument)
  +        throws PublicationException {
  +        if (hasSitetree) {
  +            try {
  +                SiteTree sourceTree = getSiteTree(sourceDocument.getArea());
  +                SiteTree destinationTree = getSiteTree(destinationDocument.getArea());
   
  -                Label label = sourceNode.getLabel(sourceDocument.getLanguage());
  -                if (label == null) {
  -                    // the node that we're trying to publish
  -                    // doesn't have this language
  +                SiteTreeNode sourceNode = sourceTree.getNode(sourceDocument.getId());
  +                if (sourceNode == null) {
                       throw new PublicationException(
  -                        "The node "
  +                        "The node for source document ["
                               + sourceDocument.getId()
  -                            + " doesn't contain a label for language "
  -                            + sourceDocument.getLanguage());
  +                            + "] doesn't exist!");
                   } 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);
  +
  +                    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 {
  -                        // if the node already exists in the live
  -                        // tree simply insert the label in the
  -                        // live tree
  -                        destinationTree.setLabel(destinationDocument.getId(), label);
  +                        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);
  +                destinationTree.save();
  +            } catch (SiteTreeException e) {
  +                throw new PublicationException(e);
  +            }
           }
  -
       }
   
       /**
  @@ -489,52 +516,61 @@
        * @see org.apache.lenya.cms.publication.Publication#deleteDocument(org.apache.lenya.cms.publication.Document)
        */
       public void deleteDocument(Document document) throws PublicationException {
  +        deleteFromSiteStructure(document);
  +        deleteDocumentSource(document);
  +    }
   
  -        SiteTree tree;
  -        try {
  -            tree = getSiteTree(document.getArea());
  -        } catch (SiteTreeException e) {
  -            throw new PublicationException(e);
  -        }
  -
  -        SiteTreeNode node = tree.getNode(document.getId());
  -
  -        if (node == null) {
  -            throw new PublicationException(
  -                "Sitetree node for document [" + document + "] does not exist!");
  -        }
  -
  -        Label label = node.getLabel(document.getLanguage());
  -
  -        if (label == null) {
  -            throw new PublicationException(
  -                "Sitetree label for document ["
  -                    + document
  -                    + "] in language ["
  -                    + document.getLanguage()
  -                    + "]does not exist!");
  -        }
  -
  -        if (node.getLabels().length == 1 && node.getChildren().length > 0) {
  -            throw new PublicationException(
  -                "Cannot delete last language version of document ["
  -                    + document
  -                    + "] because this node has children.");
  -        }
  -
  -        node.removeLabel(label);
  -
  -        if (node.getLabels().length == 0) {
  -            tree.removeNode(document.getId());
  -        }
  -
  -        try {
  -            tree.save();
  -        } catch (SiteTreeException e) {
  -            throw new PublicationException(e);
  +    /**
  +     * Deletes a document from the site structure.
  +     * @param document The document to remove.
  +     * @throws PublicationException when something went wrong.
  +     */
  +    protected void deleteFromSiteStructure(Document document) throws PublicationException {
  +        if (hasSitetree) {
  +            SiteTree tree;
  +            try {
  +                tree = getSiteTree(document.getArea());
  +            } catch (SiteTreeException e) {
  +                throw new PublicationException(e);
  +            }
  +        
  +            SiteTreeNode node = tree.getNode(document.getId());
  +        
  +            if (node == null) {
  +                throw new PublicationException(
  +                    "Sitetree node for document [" + document + "] does not exist!");
  +            }
  +        
  +            Label label = node.getLabel(document.getLanguage());
  +        
  +            if (label == null) {
  +                throw new PublicationException(
  +                    "Sitetree label for document ["
  +                        + document
  +                        + "] in language ["
  +                        + document.getLanguage()
  +                        + "]does not exist!");
  +            }
  +        
  +            if (node.getLabels().length == 1 && node.getChildren().length > 0) {
  +                throw new PublicationException(
  +                    "Cannot delete last language version of document ["
  +                        + document
  +                        + "] because this node has children.");
  +            }
  +        
  +            node.removeLabel(label);
  +        
  +            if (node.getLabels().length == 0) {
  +                tree.removeNode(document.getId());
  +            }
  +        
  +            try {
  +                tree.save();
  +            } catch (SiteTreeException e) {
  +                throw new PublicationException(e);
  +            }
           }
  -
  -        deleteDocumentSource(document);
       }
   
       /**
  
  
  
  1.36      +31 -19    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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- DefaultDocument.java	4 Dec 2003 16:06:10 -0000	1.35
  +++ DefaultDocument.java	4 Dec 2003 18:07:14 -0000	1.36
  @@ -194,12 +194,16 @@
           SiteTree sitetree;
           try {
               sitetree = getPublication().getSiteTree(getArea());
  -            SiteTreeNode node = sitetree.getNode(getId());
  -            if (node != null) {
  -                Label[] labels = node.getLabels();
  -                for (int i = 0; i < labels.length; i++) {
  -                    languages.add(labels[i].getLanguage());
  +            if (sitetree != null) {
  +                SiteTreeNode node = sitetree.getNode(getId());
  +                if (node != null) {
  +                    Label[] labels = node.getLabels();
  +                    for (int i = 0; i < labels.length; i++) {
  +                        languages.add(labels[i].getLanguage());
  +                    }
                   }
  +            } else {
  +                languages.add(getLanguage());
               }
           } catch (SiteTreeException e) {
               throw new DocumentException(e);
  @@ -221,15 +225,16 @@
        * @see org.apache.lenya.cms.publication.Document#getLabel()
        */
       public String getLabel() throws DocumentException {
  +        String label = "";
           try {
  -            return getPublication()
  -                .getSiteTree(getArea())
  -                .getNode(getId())
  -                .getLabel(getLanguage())
  -                .getLabel();
  +            SiteTree siteTree = getPublication().getSiteTree(getArea());
  +            if (siteTree != null) {
  +                label = siteTree.getNode(getId()).getLabel(getLanguage()).getLabel();
  +            }
           } catch (SiteTreeException e) {
               throw new DocumentException(e);
           }
  +        return label;
       }
   
       private String area;
  @@ -316,18 +321,20 @@
   
       /** (non-Javadoc)
        * @see org.apache.lenya.cms.publication.Document#exists()
  -     * FIXME: Don't use getFile().exists() as basis for Document.exists()
        */
       public boolean exists() throws DocumentException {
           boolean exists;
           try {
               SiteTree sitetree = getPublication().getSiteTree(getArea());
  -            SiteTreeNode node = sitetree.getNode(getId());
  -            exists = (node != null) && (node.getLabel(getLanguage()) != null);
  +            if (sitetree != null) {
  +                SiteTreeNode node = sitetree.getNode(getId());
  +                exists = (node != null) && (node.getLabel(getLanguage()) != null);
  +            } else {
  +                exists = getFile().exists();
  +            }
           } catch (SiteTreeException e) {
               throw new DocumentException(e);
           }
  -        exists = exists || getFile().exists();
           return exists;
       }
   
  @@ -335,14 +342,19 @@
        * @see org.apache.lenya.cms.publication.Document#existsInAnyLanguage()
        */
       public boolean existsInAnyLanguage() throws DocumentException {
  -        SiteTree sitetree;
  +        boolean exists = false;
           try {
  -            sitetree = getPublication().getSiteTree(getArea());
  -            SiteTreeNode node = sitetree.getNode(getId());
  -            return (node != null);
  +            SiteTree sitetree = getPublication().getSiteTree(getArea());
  +            if (sitetree != null) {
  +                SiteTreeNode node = sitetree.getNode(getId());
  +                exists = node != null;
  +            } else {
  +                exists = getFile().exists();
  +            }
           } catch (SiteTreeException e) {
               throw new DocumentException(e);
           }
  +        return exists;
       }
   
       /**
  
  
  

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