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 2008/03/04 01:37:46 UTC

svn commit: r633333 - in /lenya/sandbox/modules: navigation/ navigation/config/ navigation/config/cocoon-xconf/ navigation/config/sitemap/ navigation/java/ navigation/java/src/org/apache/lenya/modules/sitemeta/ sitemeta/

Author: andreas
Date: Mon Mar  3 16:37:42 2008
New Revision: 633333

URL: http://svn.apache.org/viewvc?rev=633333&view=rev
Log:
Renaming sitemeta module to navigation module, adding SiteFragmentGenerator and supplementary classes.

Added:
    lenya/sandbox/modules/navigation/
      - copied from r633193, lenya/sandbox/modules/sitemeta/
    lenya/sandbox/modules/navigation/config/
      - copied from r633332, lenya/sandbox/modules/sitemeta/config/
    lenya/sandbox/modules/navigation/java/
      - copied from r633332, lenya/sandbox/modules/sitemeta/java/
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/BreadcrumbSelector.java
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/ChildrenSelector.java
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/FragmentSelector.java
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/NodeGenerator.java
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteFragmentGenerator.java
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SubtreeSelector.java
Removed:
    lenya/sandbox/modules/sitemeta/
Modified:
    lenya/sandbox/modules/navigation/config/cocoon-xconf/metadata-store.xconf
    lenya/sandbox/modules/navigation/config/module.xml
    lenya/sandbox/modules/navigation/config/sitemap/sitemeta-transformer.xmap
    lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java

Modified: lenya/sandbox/modules/navigation/config/cocoon-xconf/metadata-store.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/config/cocoon-xconf/metadata-store.xconf?rev=633333&r1=633332&r2=633333&view=diff
==============================================================================
--- lenya/sandbox/modules/navigation/config/cocoon-xconf/metadata-store.xconf (original)
+++ lenya/sandbox/modules/navigation/config/cocoon-xconf/metadata-store.xconf Mon Mar  3 16:37:42 2008
@@ -16,9 +16,9 @@
   limitations under the License.
 -->
 
-<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.modules.sitemeta.SiteMetaDataTransformerStore']">
-  <component role="org.apache.lenya.modules.sitemeta.SiteMetaDataTransformerStore"
-    class="org.apache.excalibur.store.impl.MRUMemoryStore" logger="lenya.source.sitemeta.store">
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.modules.navigation.SiteMetaDataTransformerStore']">
+  <component role="org.apache.lenya.modules.navigation.SiteMetaDataTransformerStore"
+    class="org.apache.excalibur.store.impl.MRUMemoryStore" logger="lenya.source.navigation.store">
     <parameter name="maxobjects" value="10000"/>
   </component>
 </xconf>

Modified: lenya/sandbox/modules/navigation/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/config/module.xml?rev=633333&r1=633332&r2=633333&view=diff
==============================================================================
--- lenya/sandbox/modules/navigation/config/module.xml (original)
+++ lenya/sandbox/modules/navigation/config/module.xml Mon Mar  3 16:37:42 2008
@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module xmlns="http://apache.org/lenya/module/1.0">
-  <id>org.apache.lenya.modules.sitemeta</id>
-  <export package="org.apache.lenya.modules.sitemeta"/>
+  <id>org.apache.lenya.modules.navigation</id>
+  <export package="org.apache.lenya.modules.navigation"/>
   <package>org.apache.lenya.modules</package>
   <version>0.1-dev</version>
-  <name>sitemeta</name>
+  <name>navigation</name>
   <lenya-version>@lenya.version@</lenya-version>
   <description>
-    This module allows to configure the sitetree presentation of documents
-    based on meta data.
+    This module contains Java classes and resources to generate navigation widgets.
   </description>
 </module>

Modified: lenya/sandbox/modules/navigation/config/sitemap/sitemeta-transformer.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/config/sitemap/sitemeta-transformer.xmap?rev=633333&r1=633332&r2=633333&view=diff
==============================================================================
--- lenya/sandbox/modules/navigation/config/sitemap/sitemeta-transformer.xmap (original)
+++ lenya/sandbox/modules/navigation/config/sitemap/sitemeta-transformer.xmap Mon Mar  3 16:37:42 2008
@@ -21,6 +21,6 @@
   xmlns:map="http://apache.org/cocoon/sitemap/1.0">
     
   <map:transformer name="sitemeta" logger="lenya.sitemap.transformer.sitemeta"
-    src="org.apache.lenya.modules.sitemeta.SiteMetaDataTransformer"/>
+    src="org.apache.lenya.modules.navigation.SiteMetaDataTransformer"/>
   
 </xmap>

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/BreadcrumbSelector.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/BreadcrumbSelector.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/BreadcrumbSelector.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/BreadcrumbSelector.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import java.util.StringTokenizer;
+
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.xml.sax.SAXException;
+
+public class BreadcrumbSelector implements FragmentSelector {
+
+    public void selectFragment(NodeGenerator generator, SiteStructure site, String path) throws SAXException, SiteException {
+        StringTokenizer tokens = new StringTokenizer(path, "/");
+        StringBuffer currentPath = new StringBuffer();
+        while (tokens.hasMoreTokens()) {
+            String name = tokens.nextToken();
+            currentPath.append("/").append(name);
+            if (site.contains(path)) {
+                SiteNode node = site.getNode(path);
+                generator.startNode(node);
+                generator.endNode(node);
+            }
+            else {
+                break;
+            }
+        }
+    }
+
+}

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/ChildrenSelector.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/ChildrenSelector.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/ChildrenSelector.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/ChildrenSelector.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.xml.sax.SAXException;
+
+/**
+ * Select the child nodes of a node non-recursively. If the path is "" or "/", the top-level nodes are generated.
+ */
+public class ChildrenSelector implements FragmentSelector {
+
+    public void selectFragment(NodeGenerator generator, SiteStructure site, String path) throws SAXException, SiteException {
+        SiteNode[] nodes;
+        if (path.equals("/") || path.equals("")) {
+            nodes = site.getTopLevelNodes();
+        }
+        else {
+            if (site.contains(path)) {
+                nodes = site.getNode(path).getChildren();
+            }
+            else {
+                nodes = new SiteNode[0];
+            }
+        }
+        for (int i = 0; i < nodes.length; i++) {
+            generator.startNode(nodes[i]);
+            generator.endNode(nodes[i]);
+        }
+    }
+
+}

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/FragmentSelector.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/FragmentSelector.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/FragmentSelector.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/FragmentSelector.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.xml.sax.SAXException;
+
+public interface FragmentSelector {
+    
+    void selectFragment(NodeGenerator generator, SiteStructure site, String path) throws SAXException, SiteException;
+
+}

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/NodeGenerator.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/NodeGenerator.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/NodeGenerator.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/NodeGenerator.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.xml.sax.SAXException;
+
+public interface NodeGenerator {
+    
+    void startNode(SiteNode node) throws SAXException;
+
+    void endNode(SiteNode node) throws SAXException;
+
+}

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteFragmentGenerator.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteFragmentGenerator.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteFragmentGenerator.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteFragmentGenerator.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.site.Link;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Generate a fragment of the site.
+ */
+public class SiteFragmentGenerator extends ServiceableGenerator implements
+        CacheableProcessingComponent, Parameterizable, NodeGenerator {
+
+    protected static final String PARAM_PUB = "pub";
+    protected static final String PARAM_AREA = "area";
+    protected static final String PARAM_LANG = "lang";
+    protected static final String PARAM_PATH = "path";
+    protected static final String PARAM_SELECTOR_PATH = "selectorPath";
+    protected static final String PARAM_SELECTOR = "selector";
+
+    protected static final String PREFIX = "site";
+    protected static final String NAMESPACE = "http://apache.org/lenya/site/1.0";
+    protected static final String ATTR_PUB = "pub";
+    protected static final String ATTR_AREA = "area";
+    protected static final String ELEM_FRAGMENT = "fragment";
+    protected static final String ELEM_NODE = "node";
+    protected static final String ELEM_LINK = "link";
+    protected static final String ATTR_UUID = "uuid";
+    protected static final String ATTR_NAME = "name";
+    protected static final String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+    protected static final String XML_PREFIX = "xml";
+    protected static final String ATTR_LANG = "lang";
+    protected static final String ATTR_LABEL = "label";
+    protected static final String ATTR_CURRENT = "current";
+    protected static final String ATTR_ANCESTOR_OF_CURRENT = "ancestorOfCurrent";
+    protected static final String ATTR_HREF = "href";
+
+    private SiteStructure site;
+    private String cacheKey;
+    private SourceValidity validity;
+    private String language;
+    private String selectorClass;
+    private String path;
+    private String selectorPath;
+
+    public void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel,
+            String src, Parameters params) throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, params);
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+
+        Source source = null;
+        try {
+            String pubId = params.getParameter(PARAM_PUB);
+            String area = params.getParameter(PARAM_AREA);
+            this.language = params.getParameter(PARAM_LANG);
+            this.path = params.getParameter(PARAM_PATH);
+            this.selectorPath = params.getParameter(PARAM_SELECTOR_PATH, "");
+
+            DocumentFactory factory = DocumentUtil.getDocumentFactory(this.manager, request);
+            Publication pub = factory.getPublication(pubId);
+            this.site = pub.getArea(area).getSite();
+
+            this.cacheKey = pubId + "/" + area;
+            source = resolver.resolveURI(this.site.getRepositoryNode().getSourceURI());
+            this.validity = source.getValidity();
+
+        } catch (Exception e) {
+            throw new ProcessingException("Could not setup transformer: ", e);
+        } finally {
+            if (source != null) {
+                resolver.release(source);
+            }
+        }
+    }
+
+    /**
+     * @return The site structure to generate from.
+     */
+    protected SiteStructure getSite() {
+        return this.site;
+    }
+
+    /**
+     * @return The language to generate the fragment for.
+     */
+    protected String getLanguage() {
+        return this.language;
+    }
+
+    public Serializable getKey() {
+        if (this.cacheKey == null) {
+            throw new IllegalStateException("setup() has not been called.");
+        }
+        return this.cacheKey;
+    }
+
+    public SourceValidity getValidity() {
+        if (this.validity == null) {
+            throw new IllegalStateException("setup() has not been called.");
+        }
+        return this.validity;
+    }
+
+    protected String getPath() {
+        return this.path;
+    }
+
+    public void generate() throws IOException, SAXException, ProcessingException {
+
+        this.contentHandler.startDocument();
+        this.contentHandler.startPrefixMapping(PREFIX, NAMESPACE);
+
+        AttributesImpl attrs = new AttributesImpl();
+        addAttribute(attrs, ATTR_PUB, this.site.getPublication().getId());
+        addAttribute(attrs, ATTR_AREA, this.site.getArea());
+        this.contentHandler.startElement(NAMESPACE, ELEM_FRAGMENT, PREFIX + ':' + ELEM_FRAGMENT,
+                attrs);
+
+        generateFragment();
+
+        this.contentHandler.endElement(NAMESPACE, ELEM_FRAGMENT, PREFIX + ':' + ELEM_FRAGMENT);
+
+        this.contentHandler.endPrefixMapping(PREFIX);
+        this.contentHandler.endDocument();
+
+    }
+
+    protected void generateFragment() throws ProcessingException {
+        try {
+            FragmentSelector selector = (FragmentSelector) Class.forName(this.selectorClass)
+                    .newInstance();
+            selector.selectFragment(this, getSite(), this.selectorPath);
+        } catch (Exception e) {
+            throw new ProcessingException(e);
+        }
+    }
+
+    public void startNode(SiteNode node) throws SAXException {
+        AttributesImpl attrs = new AttributesImpl();
+        addAttribute(attrs, ATTR_UUID, node.getUuid());
+        addAttribute(attrs, ATTR_NAME, node.getName());
+        
+        if (node.getPath().equals(getPath())) {
+            addAttribute(attrs, ATTR_CURRENT, Boolean.toString(true));
+        }
+        
+        if (getPath().startsWith(node.getPath() + "/")) {
+            addAttribute(attrs, ATTR_ANCESTOR_OF_CURRENT, Boolean.toString(true));
+        }
+        
+        this.contentHandler.startElement(NAMESPACE, ELEM_NODE, PREFIX + ':' + ELEM_NODE, attrs);
+
+        String lang = getLanguage();
+        if (node.isVisible() && node.hasLink(lang)) {
+            try {
+                generateLink(node.getLink(lang));
+            } catch (SiteException e) {
+                throw new SAXException(e);
+            }
+        }
+    }
+
+    public void endNode(SiteNode node) throws SAXException {
+        this.contentHandler.endElement(NAMESPACE, ELEM_NODE, PREFIX + ':' + ELEM_NODE);
+    }
+
+    protected void generateLink(Link link) throws SAXException {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute(XML_NAMESPACE, ATTR_LANG, XML_PREFIX + ":" + ATTR_LANG, "CDATA", link
+                .getLanguage());
+        addAttribute(attrs, ATTR_LABEL, link.getLabel());
+        addAttribute(attrs, ATTR_HREF, getHref(link).getUri());
+        this.contentHandler.startElement(NAMESPACE, ELEM_LINK, PREFIX + ':' + ELEM_LINK, attrs);
+        this.contentHandler.endElement(NAMESPACE, ELEM_LINK, PREFIX + ':' + ELEM_LINK);
+    }
+
+    protected org.apache.lenya.cms.linking.Link getHref(Link link) {
+        org.apache.lenya.cms.linking.Link href = new org.apache.lenya.cms.linking.Link();
+        href.setPubId(getSite().getPublication().getId());
+        href.setArea(getSite().getArea());
+        href.setUuid(link.getNode().getUuid());
+        href.setLanguage(getLanguage());
+        return href;
+    }
+
+    protected void addAttribute(AttributesImpl attrs, String name, String value) {
+        attrs.addAttribute("", name, name, "CDATA", value);
+    }
+
+    public void parameterize(Parameters params) throws ParameterException {
+        this.selectorClass = params.getParameter(PARAM_SELECTOR);
+    }
+
+}

Modified: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java?rev=633333&r1=633332&r2=633333&view=diff
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java (original)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java Mon Mar  3 16:37:42 2008
@@ -15,7 +15,7 @@
  *  limitations under the License.
  *
  */
-package org.apache.lenya.modules.sitemeta;
+package org.apache.lenya.modules.navigation;
 
 import java.io.IOException;
 import java.net.MalformedURLException;

Added: lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SubtreeSelector.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SubtreeSelector.java?rev=633333&view=auto
==============================================================================
--- lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SubtreeSelector.java (added)
+++ lenya/sandbox/modules/navigation/java/src/org/apache/lenya/modules/sitemeta/SubtreeSelector.java Mon Mar  3 16:37:42 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.navigation;
+
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.xml.sax.SAXException;
+
+/**
+ * Select a node and its children recursively. If the path is "" or "/", the
+ * whole site is generated.
+ */
+public class SubtreeSelector implements FragmentSelector {
+
+    public void selectFragment(NodeGenerator generator, SiteStructure site, String path)
+            throws SAXException, SiteException {
+        if (path.equals("/") || path.equals("")) {
+            SiteNode[] nodes = site.getTopLevelNodes();
+            selectNodes(generator, nodes);
+        } else if (site.contains(path)) {
+            SiteNode node = site.getNode(path);
+            selectSubtree(generator, node);
+        }
+    }
+    
+    protected void selectSubtree(NodeGenerator generator, SiteNode node) throws SAXException {
+        generator.startNode(node);
+        selectNodes(generator, node.getChildren());
+        generator.endNode(node);
+    }
+
+    protected void selectNodes(NodeGenerator generator, SiteNode[] nodes) throws SAXException {
+        for (int i = 0; i < nodes.length; i++) {
+            selectSubtree(generator, nodes[i]);
+        }
+    }
+
+}



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