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/03 02:03:48 UTC
svn commit: r632900 - in /lenya/sandbox/modules: foldernode/
foldernode/config/ foldernode/config/cocoon-xconf/
foldernode/config/sitemap/ foldernode/java/ foldernode/java/src/
foldernode/java/src/org/ foldernode/java/src/org/apache/
foldernode/java/sr...
Author: andreas
Date: Sun Mar 2 17:03:46 2008
New Revision: 632900
URL: http://svn.apache.org/viewvc?rev=632900&view=rev
Log:
Adding foldernode and linkdocument modules (needed for documentation)
Added:
lenya/sandbox/modules/foldernode/
lenya/sandbox/modules/foldernode/config/
lenya/sandbox/modules/foldernode/config/cocoon-xconf/
lenya/sandbox/modules/foldernode/config/cocoon-xconf/foldernode-metadata.xconf
lenya/sandbox/modules/foldernode/config/module.xml
lenya/sandbox/modules/foldernode/config/sitemap/
lenya/sandbox/modules/foldernode/config/sitemap/foldernode-transformer.xmap
lenya/sandbox/modules/foldernode/java/
lenya/sandbox/modules/foldernode/java/src/
lenya/sandbox/modules/foldernode/java/src/org/
lenya/sandbox/modules/foldernode/java/src/org/apache/
lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/
lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/
lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/
lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/FolderNodeTransformer.java
lenya/sandbox/modules/linkdocument/
lenya/sandbox/modules/linkdocument/config/
lenya/sandbox/modules/linkdocument/config/cocoon-xconf/
lenya/sandbox/modules/linkdocument/config/cocoon-xconf/resourcetype-link.xconf
lenya/sandbox/modules/linkdocument/config/module.xml
lenya/sandbox/modules/linkdocument/java/
lenya/sandbox/modules/linkdocument/java/src/
lenya/sandbox/modules/linkdocument/java/src/org/
lenya/sandbox/modules/linkdocument/java/src/org/apache/
lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/
lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/
lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/
lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/LinkDocument.java
lenya/sandbox/modules/linkdocument/resources/
lenya/sandbox/modules/linkdocument/resources/samples/
lenya/sandbox/modules/linkdocument/resources/samples/link.xml
lenya/sandbox/modules/linkdocument/resources/schemas/
lenya/sandbox/modules/linkdocument/resources/schemas/link.rng
Added: lenya/sandbox/modules/foldernode/config/cocoon-xconf/foldernode-metadata.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/foldernode/config/cocoon-xconf/foldernode-metadata.xconf?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/foldernode/config/cocoon-xconf/foldernode-metadata.xconf (added)
+++ lenya/sandbox/modules/foldernode/config/cocoon-xconf/foldernode-metadata.xconf Sun Mar 2 17:03:46 2008
@@ -0,0 +1,31 @@
+<?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/foldernode/1.0']">
+ <component-instance name="http://apache.org/lenya/foldernode/1.0"
+ class="org.apache.lenya.cms.metadata.ConfigurableElementSet">
+ <element name="foldernode" multiple="false" editable="true"/>
+ </component-instance>
+ </xconf>
+
Added: lenya/sandbox/modules/foldernode/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/foldernode/config/module.xml?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/foldernode/config/module.xml (added)
+++ lenya/sandbox/modules/foldernode/config/module.xml Sun Mar 2 17:03:46 2008
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>org.apache.lenya.modules.foldernode</id>
+ <export package="org.apache.lenya.modules.foldernode"/>
+ <package>org.apache.lenya.modules</package>
+ <version>0.1-dev</version>
+ <name>foldernode</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description>
+ This module allows to configure documents as folder nodes via a meta data element.
+ A transformer removes the uuid attributes of the sitetree accordingly. This way,
+ a navigation can be built with nodes that don't show documents.
+ </description>
+</module>
\ No newline at end of file
Added: lenya/sandbox/modules/foldernode/config/sitemap/foldernode-transformer.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/foldernode/config/sitemap/foldernode-transformer.xmap?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/foldernode/config/sitemap/foldernode-transformer.xmap (added)
+++ lenya/sandbox/modules/foldernode/config/sitemap/foldernode-transformer.xmap Sun Mar 2 17:03:46 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 = 'foldernode']"
+ xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+
+ <map:transformer name="foldernode" logger="lenya.sitemap.transformer.foldernode"
+ src="org.apache.lenya.modules.foldernode.FolderNodeTransformer"/>
+
+</xmap>
Added: lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/FolderNodeTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/FolderNodeTransformer.java?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/FolderNodeTransformer.java (added)
+++ lenya/sandbox/modules/foldernode/java/src/org/apache/lenya/modules/foldernode/FolderNodeTransformer.java Sun Mar 2 17:03:46 2008
@@ -0,0 +1,139 @@
+/*
+ * 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.foldernode;
+
+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;
+
+/**
+ * Removes <em>href</em> attributes from navigation nodes for foldernode
+ * documents.
+ */
+public class FolderNodeTransformer 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";
+
+ /**
+ * The foldernode meta data namespace.
+ */
+ public static final String NAMESPACE = "http://apache.org/lenya/foldernode/1.0";
+
+ /**
+ * The foldernode meta data element name.
+ */
+ public static final String ELEM_FOLDERNODE = "foldernode";
+
+ 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("href");
+ try {
+ if (href != null && href.startsWith("lenya-document:")) {
+ LinkTarget target = linkResolver.resolve(this.area.getPublication()
+ .getFactory(), getLinkUri(href));
+ if (target.exists() && isFolderNode(target.getDocument())) {
+ attrs.removeAttribute(attrs.getIndex("href"));
+ }
+ }
+ } 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_FOLDERNODE);
+ boolean isFolderNode = value != null && Boolean.valueOf(value).booleanValue();
+ return isFolderNode;
+ }
+
+ 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();
+ }
+
+}
Added: lenya/sandbox/modules/linkdocument/config/cocoon-xconf/resourcetype-link.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/linkdocument/config/cocoon-xconf/resourcetype-link.xconf?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/linkdocument/config/cocoon-xconf/resourcetype-link.xconf (added)
+++ lenya/sandbox/modules/linkdocument/config/cocoon-xconf/resourcetype-link.xconf Sun Mar 2 17:03:46 2008
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed 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.
+-->
+<xconf xpath="/cocoon/resource-types"
+ unless="/cocoon/resource-types/component-instance[@name = 'link']">
+
+ <component-instance name="link" logger="lenya.resourcetypes"
+ class="org.apache.lenya.cms.publication.ResourceTypeImpl">
+
+ <schema namespace="http://relaxng.org/ns/structure/0.9"
+ uri="fallback://lenya/modules/linkdocument/resources/schemas/link.rng"/>
+
+ <sample mime-type="application/xml" uri="fallback://lenya/modules/linkdocument/resources/samples/link.xml"/>
+
+ <format name="xhtml" uri="cocoon://modules/link/xhtml.xml"/>
+ <format name="xhtml-include" uri="cocoon://modules/link/xhtml-include.xml"/>
+
+ </component-instance>
+
+</xconf>
\ No newline at end of file
Added: lenya/sandbox/modules/linkdocument/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/linkdocument/config/module.xml?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/linkdocument/config/module.xml (added)
+++ lenya/sandbox/modules/linkdocument/config/module.xml Sun Mar 2 17:03:46 2008
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed 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.
+-->
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>org.apache.lenya.modules.linkdocument</id>
+ <export package="org.apache.lenya.modules.linkdocument"/>
+ <package>org.apache.lenya.modules</package>
+ <version>0.1-dev</version>
+ <name>linkdocument</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description>
+ Resource type to store a link.
+ </description>
+</module>
\ No newline at end of file
Added: lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/LinkDocument.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/LinkDocument.java?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/LinkDocument.java (added)
+++ lenya/sandbox/modules/linkdocument/java/src/org/apache/lenya/modules/linkdocument/LinkDocument.java Sun Mar 2 17:03:46 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.linkdocument;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentDoesNotExistException;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.util.Assert;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Wrapper for link documents.
+ */
+public class LinkDocument {
+
+ public static final String RESOURCE_TYPE = "link";
+ public static final String NAMESPACE = "http://apache.org/lenya/linkdocument/1.0";
+ public static final String PREFIX = "";
+
+ protected static final String ELEM_LINK = "link";
+ protected static final String ATTR_HREF = "href";
+
+ private Document document;
+ private String href;
+
+ public LinkDocument(Document doc) {
+ Assert.notNull("document", doc);
+ this.document = doc;
+ }
+
+ /**
+ * @return The href attribute of this link document.
+ * @throws DocumentDoesNotExistException if the document doesn't exist.
+ */
+ public String getHref() throws DocumentDoesNotExistException {
+ try {
+ if (!this.document.exists()) {
+ throw new DocumentDoesNotExistException("Document [" + this.document
+ + "] doesn't exist.");
+ }
+ } catch (DocumentDoesNotExistException e) {
+ throw e;
+ } catch (DocumentException e) {
+ throw new RuntimeException(e);
+ }
+ load();
+ return this.href;
+ }
+
+ public void setHref(String href) {
+ this.href = href;
+ save();
+ }
+
+ protected void load() {
+ try {
+ if (this.document.exists()) {
+ org.w3c.dom.Document xml = DocumentHelper.readDocument(this.document
+ .getInputStream());
+ Element root = xml.getDocumentElement();
+ Assert.isTrue("Valid link document", root.getNamespaceURI().equals(NAMESPACE)
+ && root.getLocalName().equals(ELEM_LINK));
+ Assert.isTrue("Document element has href attribute", root.hasAttribute(ATTR_HREF));
+ this.href = root.getAttribute(ATTR_HREF);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void save() {
+ try {
+ NamespaceHelper helper = new NamespaceHelper(NAMESPACE, PREFIX, ELEM_LINK);
+ String href = this.href != null ? this.href : "";
+ helper.getDocument().getDocumentElement().setAttribute(ATTR_HREF, href);
+ helper.save(this.document.getOutputStream());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: lenya/sandbox/modules/linkdocument/resources/samples/link.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/linkdocument/resources/samples/link.xml?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/linkdocument/resources/samples/link.xml (added)
+++ lenya/sandbox/modules/linkdocument/resources/samples/link.xml Sun Mar 2 17:03:46 2008
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed 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.
+-->
+<link xmlns="http://apache.org/lenya/linkdocument/1.0" href="http://lenya.apache.org"/>
\ No newline at end of file
Added: lenya/sandbox/modules/linkdocument/resources/schemas/link.rng
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/linkdocument/resources/schemas/link.rng?rev=632900&view=auto
==============================================================================
--- lenya/sandbox/modules/linkdocument/resources/schemas/link.rng (added)
+++ lenya/sandbox/modules/linkdocument/resources/schemas/link.rng Sun Mar 2 17:03:46 2008
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed 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.
+-->
+<grammar ns="http://apache.org/lenya/linkdocument/1.0"
+ xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <start>
+ <element name="link">
+ <attribute name="href">
+ <data type="anyURI"/>
+ </attribute>
+ </element>
+ </start>
+</grammar>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org