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 2007/11/16 15:07:46 UTC

svn commit: r595667 - in /lenya/sandbox/modules: externallinks/ externallinks/config/ externallinks/config/sitemap/ externallinks/java/ externallinks/java/src/ externallinks/java/src/org/ externallinks/java/src/org/apache/ externallinks/java/src/org/ap...

Author: andreas
Date: Fri Nov 16 06:07:44 2007
New Revision: 595667

URL: http://svn.apache.org/viewvc?rev=595667&view=rev
Log:
Added externallinks and propertiesdocument modules

Added:
    lenya/sandbox/modules/externallinks/
    lenya/sandbox/modules/externallinks/config/
    lenya/sandbox/modules/externallinks/config/module.xml
    lenya/sandbox/modules/externallinks/config/sitemap/
    lenya/sandbox/modules/externallinks/config/sitemap/transformers.xmap
    lenya/sandbox/modules/externallinks/java/
    lenya/sandbox/modules/externallinks/java/src/
    lenya/sandbox/modules/externallinks/java/src/org/
    lenya/sandbox/modules/externallinks/java/src/org/apache/
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinks.java
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksRewriter.java
    lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksTransformer.java
    lenya/sandbox/modules/propertiesdocument/
    lenya/sandbox/modules/propertiesdocument/config/
    lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/
    lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/resourcetype-properties.xconf
    lenya/sandbox/modules/propertiesdocument/config/module.xml
    lenya/sandbox/modules/propertiesdocument/java/
    lenya/sandbox/modules/propertiesdocument/java/src/
    lenya/sandbox/modules/propertiesdocument/java/src/org/
    lenya/sandbox/modules/propertiesdocument/java/src/org/apache/
    lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/
    lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/
    lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/
    lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/PropertiesDocument.java
    lenya/sandbox/modules/propertiesdocument/java/test/
    lenya/sandbox/modules/propertiesdocument/java/test/org/
    lenya/sandbox/modules/propertiesdocument/java/test/org/apache/
    lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/
    lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/
    lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/
    lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/PropertiesDocumentTest.java
    lenya/sandbox/modules/propertiesdocument/resources/
    lenya/sandbox/modules/propertiesdocument/resources/samples/
    lenya/sandbox/modules/propertiesdocument/resources/samples/properties.xml
    lenya/sandbox/modules/propertiesdocument/resources/schemas/
    lenya/sandbox/modules/propertiesdocument/resources/schemas/properties.rng

Added: lenya/sandbox/modules/externallinks/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/externallinks/config/module.xml?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/externallinks/config/module.xml (added)
+++ lenya/sandbox/modules/externallinks/config/module.xml Fri Nov 16 06:07:44 2007
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+  <id>org.apache.lenya.modules.externallinks</id>
+  <export package="org.apache.lenya.modules.externallinks"/>
+  <depends module="org.apache.lenya.modules.propertiesdocument"/>
+  <package>org.apache.lenya.modules</package>
+  <version>0.1-dev</version>
+  <name>External Links</name>
+  <lenya-version>@lenya.version@</lenya-version>
+  <description>Manage external links</description>
+</module>

Added: lenya/sandbox/modules/externallinks/config/sitemap/transformers.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/externallinks/config/sitemap/transformers.xmap?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/externallinks/config/sitemap/transformers.xmap (added)
+++ lenya/sandbox/modules/externallinks/config/sitemap/transformers.xmap Fri Nov 16 06:07:44 2007
@@ -0,0 +1,33 @@
+<?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 = 'uuid2url']"
+  xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+  
+  <map:transformer name="externallinks-xhtml" logger="lenya.sitemap.transformer.externallinks-xhtml"
+    src="org.apache.lenya.modules.externallinks.ExternalLinksTransformer">
+    <transform namespace="http://www.w3.org/1999/xhtml" element="a" attribute="href"/>
+    <transform namespace="http://www.w3.org/1999/xhtml" element="object" attribute="data"/>
+    <transform namespace="http://www.w3.org/1999/xhtml" element="img" attribute="src"/>
+    <transform namespace="http://www.w3.org/1999/xhtml" element="link" attribute="href"/>
+    <transform namespace="http://www.w3.org/1999/xhtml" element="form" attribute="action"/>
+    <transform namespace="http://www.w3.org/1999/xhtml" element="script" attribute="src"/>
+  </map:transformer>
+
+</xmap>

Added: lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinks.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinks.java?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinks.java (added)
+++ lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinks.java Fri Nov 16 06:07:44 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.externallinks;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.modules.propertiesdocument.PropertiesDocument;
+
+/**
+ * Manage external links. The links are stored in a document at the path
+ * {@link #PATH} with the publication's default language.
+ */
+public class ExternalLinks extends AbstractLogEnabled {
+
+    public static final String PATH = "/externallinks";
+
+    public ExternalLinks(ServiceManager manager, Area area, Logger logger) {
+        ContainerUtil.enableLogging(this, logger);
+        this.properties = new PropertiesDocument(manager, area, PATH, logger);
+    }
+
+    private PropertiesDocument properties;
+
+    public void setUri(String name, String uri) {
+        this.properties.put(name, uri);
+        this.properties.save();
+    }
+
+    public boolean contains(String name) {
+        return this.properties.containsKey(name);
+    }
+
+    /**
+     * @param name The name of the link.
+     * @return A URI.
+     * @throws IllegalArgumentException if no link exists with this name.
+     */
+    public String getUri(String name) {
+        return this.properties.get(name);
+    }
+
+}

Added: lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksRewriter.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksRewriter.java?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksRewriter.java (added)
+++ lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksRewriter.java Fri Nov 16 06:07:44 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.externallinks;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.linking.LinkRewriter;
+import org.apache.lenya.cms.publication.Area;
+
+public class ExternalLinksRewriter extends AbstractLogEnabled implements LinkRewriter {
+    
+    private ExternalLinks links;
+
+    public ExternalLinksRewriter(ServiceManager manager, Area area, Logger logger) {
+        ContainerUtil.enableLogging(this, logger);
+        this.links = new ExternalLinks(manager, area, logger);
+    }
+
+    protected static final String PROTOCOL = "ext:";
+
+    public boolean matches(String url) {
+        return url.startsWith(PROTOCOL) && this.links.contains(getLinkName(url));
+    }
+
+    protected String getLinkName(String url) {
+        return url.substring(PROTOCOL.length());
+    }
+
+    public String rewrite(String url) {
+        return this.links.getUri(getLinkName(url));
+    }
+
+}

Added: lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksTransformer.java?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksTransformer.java (added)
+++ lenya/sandbox/modules/externallinks/java/src/org/apache/lenya/modules/externallinks/ExternalLinksTransformer.java Fri Nov 16 06:07:44 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.externallinks;
+
+import java.io.IOException;
+import java.util.Map;
+
+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.lenya.cms.cocoon.transformation.AbstractLinkTransformer;
+import org.apache.lenya.cms.linking.LinkRewriter;
+import org.apache.lenya.cms.publication.Area;
+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.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.util.ServletHelper;
+import org.xml.sax.SAXException;
+
+public class ExternalLinksTransformer extends AbstractLinkTransformer {
+
+    private Area area;
+
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+            throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, params);
+        try {
+            Request request = ObjectModelHelper.getRequest(objectModel);
+            Session session = RepositoryUtil.getSession(this.manager, request);
+            DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
+            String webappUrl = ServletHelper.getWebappURI(request);
+            URLInformation info = new URLInformation(webappUrl);
+            Publication pub = factory.getPublication(info.getPublicationId());
+            this.area = pub.getArea(info.getArea());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected LinkRewriter getLinkRewriter() {
+        return new ExternalLinksRewriter(this.manager, this.area, getLogger());
+    }
+
+}

Added: lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/resourcetype-properties.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/resourcetype-properties.xconf?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/resourcetype-properties.xconf (added)
+++ lenya/sandbox/modules/propertiesdocument/config/cocoon-xconf/resourcetype-properties.xconf Fri Nov 16 06:07:44 2007
@@ -0,0 +1,43 @@
+<?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: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon/resource-types" unless="/cocoon/resource-types/component-instance[@name = 'properties']">
+  
+  <component-instance name="properties"
+    logger="lenya.resourcetypes.properties"
+    class="org.apache.lenya.cms.publication.ResourceTypeImpl">
+    <schema 
+      namespace="http://relaxng.org/ns/structure/0.9"
+      uri="fallback://lenya/modules/propertiesdocument/resources/schemas/properties.rng"/>
+    
+    <!-- Default time in seconds until the resource-type has expired -->  
+    <expires seconds="3600" />
+    
+    <sample 
+      mime-type="application/xml" 
+      uri="fallback://lenya/modules/propertiesdocument/resources/samples/properties.xml"
+    />
+    
+    <format name="xhtml" uri="cocoon://modules/propertiesdocument/xhtml.xml"/>
+    <format name="icon" uri="cocoon://modules/propertiesdocument/icon"/>
+    
+  </component-instance>
+  
+</xconf>

Added: lenya/sandbox/modules/propertiesdocument/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/config/module.xml?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/config/module.xml (added)
+++ lenya/sandbox/modules/propertiesdocument/config/module.xml Fri Nov 16 06:07:44 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+  <id>org.apache.lenya.modules.propertiesdocument</id>
+  <export package="org.apache.lenya.modules.propertiesdocument"/>
+  <package>org.apache.lenya.modules</package>
+  <version>0.1-dev</version>
+  <name>Properties Resource Type</name>
+  <lenya-version>@lenya.version@</lenya-version>
+  <description>Resource type to store key-value pairs in documents.</description>
+</module>

Added: lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/PropertiesDocument.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/PropertiesDocument.java?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/PropertiesDocument.java (added)
+++ lenya/sandbox/modules/propertiesdocument/java/src/org/apache/lenya/modules/propertiesdocument/PropertiesDocument.java Fri Nov 16 06:07:44 2007
@@ -0,0 +1,199 @@
+/*
+ * 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.propertiesdocument;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.util.Assert;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+public class PropertiesDocument extends AbstractLogEnabled {
+
+    protected static final String RESOURCE_TYPE = "properties";
+    protected static final String EXTENSION = "xml";
+    protected static final String TITLE = "Properties";
+    protected static final String NAMESPACE = "http://apache.org/lenya/propertiesdocument/1.0";
+    protected static final String PREFIX = "";
+    protected static final String ELEM_PROPERTIES = "properties";
+    protected static final String ELEM_PROPERTY = "property";
+    protected static final String ATTR_NAME = "name";
+    protected static final String ATTR_VALUE = "value";
+
+    private Document delegate;
+    private Area area;
+    private String path;
+    private ServiceManager manager;
+    private Map properties;
+
+    public PropertiesDocument(ServiceManager manager, Area area, String path, Logger logger) {
+        ContainerUtil.enableLogging(this, logger);
+        this.area = area;
+        this.path = path;
+        this.manager = manager;
+    }
+    
+    public boolean containsKey(String key) {
+        return properties().containsKey(key);
+    }
+
+    /**
+     * @param name The key.
+     * @return A string.
+     * @throws IllegalArgumentException if no value exists for this name.
+     */
+    public String get(String key) {
+        String value = (String) properties().get(key);
+        if (value == null) {
+            throw new IllegalArgumentException("No value for key [" + key + "].");
+        }
+        return value;
+    }
+
+    public String get(String key, String defaultValue) {
+        String value = (String) properties().get(key);
+        return value == null ? defaultValue : value;
+    }
+    
+    public void put(String key, String value) {
+        Assert.notNull("key", key);
+        Assert.notNull("value", value);
+        properties().put(key, value);
+    }
+
+    protected Map properties() {
+        if (this.properties == null) {
+            this.properties = load();
+        }
+        return this.properties;
+    }
+
+    public void save() {
+        NamespaceHelper helper = createEmptyNamespaceHelper();
+        Map properties = properties();
+        for (Iterator i = properties.keySet().iterator(); i.hasNext(); ) {
+            String name = (String) i.next();
+            String value = (String) properties.get(name);
+            Element element = helper.createElement(ELEM_PROPERTY);
+            element.setAttribute(ATTR_NAME, name);
+            element.setAttribute(ATTR_VALUE, value);
+            helper.getDocument().getDocumentElement().appendChild(element);
+        }
+        helper.save(delegate().getOutputStream());
+    }
+
+    protected Map load() {
+        Map properties = new HashMap();
+        NamespaceHelper helper = getNamespaceHelper();
+        Element[] elements = helper.getChildren(helper.getDocument().getDocumentElement());
+        for (int i = 0; i < elements.length; i++) {
+            String name = elements[i].getAttribute("name");
+            String value = elements[i].getAttribute("value");
+            Assert.notNull("name", name);
+            Assert.notNull("value", value);
+            properties.put(name, value);
+        }
+        return properties;
+    }
+
+    protected NamespaceHelper getNamespaceHelper() {
+        NamespaceHelper helper;
+        Document delegate = delegate();
+        try {
+            if (delegate.getContentLength() == 0) {
+                helper = createEmptyNamespaceHelper();
+            }
+            else {
+                org.w3c.dom.Document xml = DocumentHelper.readDocument(delegate.getInputStream());
+                helper = new NamespaceHelper(NAMESPACE, PREFIX, xml);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return helper;
+    }
+
+    protected NamespaceHelper createEmptyNamespaceHelper() {
+        try {
+            return new NamespaceHelper(NAMESPACE, PREFIX, ELEM_PROPERTIES);
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected Document delegate() {
+        if (this.delegate == null) {
+            Publication pub = area.getPublication();
+            String language = pub.getDefaultLanguage();
+            SiteStructure site = area.getSite();
+            try {
+                if (site.contains(path)) {
+                    SiteNode node = site.getNode(path);
+                    if (node.getUuid() != null && node.hasLink(language)) {
+                        this.delegate = node.getLink(language).getDocument();
+                    }
+                }
+                if (this.delegate == null) {
+                    ServiceSelector selector = null;
+                    ResourceType type = null;
+                    DocumentManager docMgr = null;
+                    try {
+                        selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE
+                                + "Selector");
+                        type = (ResourceType) selector.select(RESOURCE_TYPE);
+                        docMgr = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+                        String sourceUri = type.getSample(type.getSampleNames()[0]).getUri();
+                        this.delegate = docMgr.add(pub.getFactory(), type, sourceUri, pub, area
+                                .getName(), path, language, EXTENSION, TITLE, false);
+                    } finally {
+                        if (docMgr != null) {
+                            this.manager.release(docMgr);
+                        }
+                        if (selector != null) {
+                            if (type != null) {
+                                selector.release(type);
+                            }
+                            this.manager.release(selector);
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return this.delegate;
+    }
+}

Added: lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/PropertiesDocumentTest.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/PropertiesDocumentTest.java?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/PropertiesDocumentTest.java (added)
+++ lenya/sandbox/modules/propertiesdocument/java/test/org/apache/lenya/module/propertiesdocument/PropertiesDocumentTest.java Fri Nov 16 06:07:44 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.module.propertiesdocument;
+
+import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.modules.propertiesdocument.PropertiesDocument;
+
+public class PropertiesDocumentTest extends AbstractAccessControlTest {
+
+    protected static final String VALUE = "testValue";
+    protected static final String NAME = "testName";
+
+    public void testPropertiesDocument() throws Exception {
+        
+        login("lenya");
+        
+        PropertiesDocument properties = getPropertiesDocument();
+        
+        properties.put(NAME, VALUE);
+        assertEquals(properties.get(NAME), VALUE);
+        properties.save();
+        
+        PropertiesDocument properties2 = getPropertiesDocument();
+        assertEquals(properties2.get(NAME), VALUE);
+        
+    }
+
+    protected PropertiesDocument getPropertiesDocument() throws PublicationException {
+        Publication pub = getPublication("test");
+        return new PropertiesDocument(getManager(), pub.getArea(Publication.AUTHORING_AREA),
+                "/properties", getLogger());
+    }
+    
+}

Added: lenya/sandbox/modules/propertiesdocument/resources/samples/properties.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/resources/samples/properties.xml?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/resources/samples/properties.xml (added)
+++ lenya/sandbox/modules/propertiesdocument/resources/samples/properties.xml Fri Nov 16 06:07:44 2007
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<properties xmlns="http://apache.org/lenya/propertiesdocument/1.0">
+  <property name="foo" value="bar"/>
+</properties>
\ No newline at end of file

Added: lenya/sandbox/modules/propertiesdocument/resources/schemas/properties.rng
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/propertiesdocument/resources/schemas/properties.rng?rev=595667&view=auto
==============================================================================
--- lenya/sandbox/modules/propertiesdocument/resources/schemas/properties.rng (added)
+++ lenya/sandbox/modules/propertiesdocument/resources/schemas/properties.rng Fri Nov 16 06:07:44 2007
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar 
+  xmlns="http://relaxng.org/ns/structure/1.0"
+  xmlns:xsp="http://apache.org/xsp/core/v1"
+  xmlns:s="http://www.ascc.net/xml/schematron"
+  xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
+  xmlns:f="http://axkit.org/NS/xsp/perform/v1"
+  xmlns:p="http://apache.org/lenya/propertiesdocument/1.0"
+  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <start>
+    <element name="p:properties">
+      <zeroOrMore>
+        <element name="p:property">
+          <attribute name="name"><text/></attribute>
+          <attribute name="value"><text/></attribute>
+        </element>
+      </zeroOrMore>
+    </element>
+  </start>
+</grammar>
\ No newline at end of file



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