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 2005/04/14 15:54:02 UTC

svn commit: r161285 - in lenya/trunk/src/java/org/apache/lenya/cms: metadata/MetaDataManager.java metadata/MetaDataOwner.java publication/Resource.java

Author: andreas
Date: Thu Apr 14 06:54:01 2005
New Revision: 161285

URL: http://svn.apache.org/viewcvs?view=rev&rev=161285
Log:
generalized DublinCore to MetaDataManager, using lenya:// sources for asset management

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java?view=auto&rev=161285
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java Thu Apr 14 06:54:01 2005
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.metadata;
+
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * Generic meta data interface.
+ * 
+ * @version $Id:$
+ */
+public interface MetaDataManager {
+    
+    /**
+     * Save the meta data.
+     * 
+     * @throws DocumentException if the meta data could not be made persistent.
+     */
+    void save() throws DocumentException;
+
+    /**
+     * Returns the values for a certain key.
+     * @param key The key.
+     * @return An array of strings.
+     * @throws DocumentException when something went wrong.
+     */
+    String[] getValues(String key) throws DocumentException;
+
+    /**
+     * Returns the first value for a certain key.
+     * @param key The key.
+     * @return A string or <code>null</code> if no value is set for this key.
+     * @throws DocumentException if an error occurs.
+     */
+    String getFirstValue(String key) throws DocumentException;
+
+    /**
+     * Sets the value for a certain key. All existing values will be removed.
+     * @param key The key.
+     * @param value The value to set.
+     * @throws DocumentException when something went wrong.
+     */
+    void setValue(String key, String value) throws DocumentException;
+
+    /**
+     * Adds a value for a certain key.
+     * @param key The key.
+     * @param value The value to add.
+     * @throws DocumentException when something went wrong.
+     */
+    void addValue(String key, String value) throws DocumentException;
+
+    /**
+     * Add all values for a certain key.
+     * 
+     * @param key The key
+     * @param values The value to add
+     * @throws DocumentException if something went wrong
+     */
+    void addValues(String key, String[] values) throws DocumentException;
+
+    /**
+     * Removes a specific value for a certain key.
+     * @param key The key.
+     * @param value The value to remove.
+     * @throws DocumentException when something went wrong.
+     */
+    void removeValue(String key, String value) throws DocumentException;
+
+    /**
+     * Removes all values for a certain key.
+     * @param key The key.
+     * @throws DocumentException when something went wrong.
+     */
+    void removeAllValues(String key) throws DocumentException;
+
+    /**
+     * Replace the contents of the current meta data by the contents of other.
+     * @param other The other meta data manager.
+     * @throws DocumentException if an error occurs.
+     */
+    void replaceBy(MetaDataManager other) throws DocumentException;
+    
+    /**
+     * @return All keys that can be used.
+     */
+    String[] getPossibleKeys();
+
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java?view=auto&rev=161285
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java Thu Apr 14 06:54:01 2005
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.metadata;
+
+/**
+ * Owner of meta data.
+ *
+ * @version $Id:$
+ */
+public interface MetaDataOwner {
+
+    /**
+     * @return The meta data.
+     */
+    MetaDataManager getMetaData();
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java?view=auto&rev=161285
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java Thu Apr 14 06:54:01 2005
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.publication;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.cocoon.source.RepositorySource;
+import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.MetaDataOwner;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreProxy;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.transaction.Transactionable;
+
+/**
+ * A resource (asset).
+ * 
+ * @version $Id:$
+ */
+public class Resource implements MetaDataOwner {
+
+    private Document document;
+    private String name;
+    private ServiceManager manager;
+
+    /**
+     * Ctor.
+     * @param document The document the resource belongs to.
+     * @param name The name.
+     * @param manager The service manager.
+     */
+    public Resource(Document document, String name, ServiceManager manager) {
+        this.document = document;
+        this.name = name;
+        this.manager = manager;
+    }
+
+    /**
+     * @return The document.
+     */
+    public Document getDocument() {
+        return document;
+    }
+
+    /**
+     * @return The name.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaData()
+     */
+    public MetaDataManager getMetaData() {
+        return new DublinCoreProxy(getMetaSourceURI(), this.manager);
+    }
+
+    /**
+     * @return The source URI.
+     */
+    public String getSourceURI() {
+        String srcUri = getResourcesURI() + "/" + getName();
+        return srcUri;
+    }
+
+    /**
+     * @return The meta source URI.
+     */
+    public String getMetaSourceURI() {
+        return getSourceURI() + ResourcesManager.RESOURCES_META_SUFFIX;
+    }
+
+    /**
+     * @return The directory URI where the resources are located.
+     */
+    public String getBaseURI() {
+        String resourcesUri = getResourcesURI().substring("lenya://".length());
+        return "context://" + resourcesUri;
+    }
+
+    protected String getResourcesURI() {
+        String pubId = document.getPublication().getId();
+        String resourcesUri = "lenya://lenya/pubs/" + pubId + "/"
+                + ResourcesManager.RESOURCES_PREFIX + "/" + document.getArea() + document.getId();
+        return resourcesUri;
+    }
+
+    /**
+     * @return The repository nodes that represent this resource.
+     */
+    public Transactionable[] getRepositoryNodes() {
+        Node[] nodes = new Node[2];
+        SourceResolver resolver = null;
+        RepositorySource documentSource = null;
+        RepositorySource metaSource = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            documentSource = (RepositorySource) resolver.resolveURI(getSourceURI());
+            metaSource = (RepositorySource) resolver.resolveURI(getMetaSourceURI());
+            nodes[0] = documentSource.getNode();
+            nodes[1] = metaSource.getNode();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (resolver != null) {
+                if (documentSource != null) {
+                    resolver.release(documentSource);
+                }
+                if (metaSource != null) {
+                    resolver.release(metaSource);
+                }
+                this.manager.release(resolver);
+            }
+        }
+        return nodes;
+    }
+
+}
\ 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