svn commit: r633193 - in /lenya/sandbox/modules: foldernode/ linkdocument/ sitemeta/ sitemeta/config/ sitemeta/config/cocoon-xconf/ sitemeta/config/sitemap/ sitemeta/java/ sitemeta/java/src/ sitemeta/java/src/org/ sitemeta/java/src/org/apache/ sitemeta...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Mon Mar  3 09:39:45 2008
New Revision: 633193

URL: http://svn.apache.org/viewvc?rev=633193&view=rev
Log:
Replacing linkdocument and foldernode modules with sitemeta module.

Added:
    lenya/sandbox/modules/sitemeta/
    lenya/sandbox/modules/sitemeta/config/
    lenya/sandbox/modules/sitemeta/config/cocoon-xconf/
    lenya/sandbox/modules/sitemeta/config/cocoon-xconf/site-metadata.xconf
    lenya/sandbox/modules/sitemeta/config/module.xml
    lenya/sandbox/modules/sitemeta/config/sitemap/
    lenya/sandbox/modules/sitemeta/config/sitemap/sitemeta-transformer.xmap
    lenya/sandbox/modules/sitemeta/java/
    lenya/sandbox/modules/sitemeta/java/src/
    lenya/sandbox/modules/sitemeta/java/src/org/
    lenya/sandbox/modules/sitemeta/java/src/org/apache/
    lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/
    lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/
    lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/
    lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
Removed:
    lenya/sandbox/modules/foldernode/
    lenya/sandbox/modules/linkdocument/

Added: lenya/sandbox/modules/sitemeta/config/cocoon-xconf/site-metadata.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/config/cocoon-xconf/site-metadata.xconf?rev=633193&view=auto
==============================================================================
--- lenya/sandbox/modules/sitemeta/config/cocoon-xconf/site-metadata.xconf (added)
+++ lenya/sandbox/modules/sitemeta/config/cocoon-xconf/site-metadata.xconf Mon Mar  3 09:39:45 2008
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+  This file defines the publication specific use-cases
+-->
+
+  <xconf xpath="/cocoon/meta-data"
+    unless="/cocoon/meta-data/component-instance[@name = 'http://apache.org/lenya/metadata/site/1.0']">
+    <component-instance name="http://apache.org/lenya/metadata/site/1.0"
+      class="org.apache.lenya.cms.metadata.ConfigurableElementSet">
+      <element name="folderNode" multiple="false" editable="true"/>
+      <element name="externalLink" multiple="false" editable="true"/>
+    </component-instance>
+  </xconf>
+  

Added: lenya/sandbox/modules/sitemeta/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/config/module.xml?rev=633193&view=auto
==============================================================================
--- lenya/sandbox/modules/sitemeta/config/module.xml (added)
+++ lenya/sandbox/modules/sitemeta/config/module.xml Mon Mar  3 09:39:45 2008
@@ -0,0 +1,13 @@
+<?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"/>
+  <package>org.apache.lenya.modules</package>
+  <version>0.1-dev</version>
+  <name>sitemeta</name>
+  <lenya-version>@lenya.version@</lenya-version>
+  <description>
+    This module allows to configure the sitetree presentation of documents
+    based on meta data.
+  </description>
+</module>
\ No newline at end of file

Added: lenya/sandbox/modules/sitemeta/config/sitemap/sitemeta-transformer.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/config/sitemap/sitemeta-transformer.xmap?rev=633193&view=auto
==============================================================================
--- lenya/sandbox/modules/sitemeta/config/sitemap/sitemeta-transformer.xmap (added)
+++ lenya/sandbox/modules/sitemeta/config/sitemap/sitemeta-transformer.xmap Mon Mar  3 09:39:45 2008
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<xmap xpath="/sitemap/components/transformers" 
+  unless="/sitemap/components/transformers/transformer[@name = 'sitemeta']"
+  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"/>
+  
+</xmap>

Added: lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java?rev=633193&view=auto
==============================================================================
--- lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java (added)
+++ lenya/sandbox/modules/sitemeta/java/src/org/apache/lenya/modules/sitemeta/SiteMetaDataTransformer.java Mon Mar  3 09:39:45 2008
@@ -0,0 +1,160 @@
+/*
+ * 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.sitemeta;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.lenya.cms.linking.Link;
+import org.apache.lenya.cms.linking.LinkResolver;
+import org.apache.lenya.cms.linking.LinkTarget;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.Document;
+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.publication.URLInformation;
+import org.apache.lenya.util.ServletHelper;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Updates navigation nodes according to the site meta data of the corresponding
+ * documents.
+ */
+public class SiteMetaDataTransformer extends AbstractSAXTransformer implements Initializable {
+
+    private Area area;
+    private LinkResolver linkResolver;
+
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+            throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, params);
+
+        Request req = ObjectModelHelper.getRequest(objectModel);
+        DocumentFactory factory = DocumentUtil.getDocumentFactory(this.manager, request);
+        String webappUrl = ServletHelper.getWebappURI(req);
+        URLInformation info = new URLInformation(webappUrl);
+        try {
+            Publication pub = factory.getPublication(info.getPublicationId());
+            this.area = pub.getArea(info.getArea());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void initialize() throws Exception {
+        this.linkResolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
+    }
+
+    public void dispose() {
+        super.dispose();
+        if (this.linkResolver == null) {
+            this.manager.release(linkResolver);
+        }
+    }
+
+    protected static final String NAV_NAMESPACE = "http://apache.org/cocoon/lenya/navigation/1.0";
+    protected static final String ELEM_NODE = "node";
+    protected static final String ATTR_HREF = "href";
+
+    /**
+     * The site meta data namespace.
+     */
+    public static final String NAMESPACE = "http://apache.org/lenya/metadata/site/1.0";
+
+    /**
+     * The folderNode meta data element name.
+     */
+    public static final String ELEM_FOLDER_NODE = "folderNode";
+
+    /**
+     * The externalLink meta data element name.
+     */
+    public static final String ELEM_EXTERNAL_LINK = "externalLink";
+
+    public void startElement(String uri, String localName, String qName, Attributes attr)
+            throws SAXException {
+        if (uri != null && uri.equals(NAV_NAMESPACE) && localName.equals(ELEM_NODE)) {
+            AttributesImpl attrs = new AttributesImpl(attr);
+            String href = attrs.getValue(ATTR_HREF);
+            try {
+                if (href != null && href.startsWith("lenya-document:")) {
+                    LinkTarget target = linkResolver.resolve(this.area.getPublication()
+                            .getFactory(), getLinkUri(href));
+                    if (target.exists()) {
+                        Document doc = target.getDocument();
+                        int hrefIndex = attrs.getIndex(ATTR_HREF);
+                        if (isFolderNode(doc)) {
+                            attrs.removeAttribute(hrefIndex);
+                        } else {
+                            String externalLink = getExternalLink(doc);
+                            if (externalLink != null) {
+                                attrs.setAttribute(hrefIndex, "", ATTR_HREF, ATTR_HREF, "CDATA",
+                                        externalLink);
+                            }
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                throw new SAXException(e);
+            } finally {
+                super.startElement(uri, localName, qName, attrs);
+            }
+        } else {
+            super.startElement(uri, localName, qName, attr);
+        }
+    }
+
+    protected boolean isFolderNode(Document doc) throws MetaDataException {
+        MetaData meta = doc.getMetaData(NAMESPACE);
+        String value = meta.getFirstValue(ELEM_FOLDER_NODE);
+        boolean isFolderNode = value != null && Boolean.valueOf(value).booleanValue();
+        return isFolderNode;
+    }
+
+    protected String getExternalLink(Document doc) throws MetaDataException {
+        MetaData meta = doc.getMetaData(NAMESPACE);
+        return meta.getFirstValue(ELEM_EXTERNAL_LINK);
+    }
+
+    protected String getLinkUri(String href) throws MalformedURLException {
+        int qm = href.indexOf("?");
+        String linkUri = qm < 0 ? href : href.substring(0, qm - 1);
+        Link link = new Link(linkUri);
+        if (link.getArea() == null) {
+            link.setArea(this.area.getName());
+        }
+        if (link.getPubId() == null) {
+            link.setPubId(this.area.getPublication().getId());
+        }
+        return link.getUri();
+    }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.