You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by jw...@apache.org on 2005/05/09 14:00:47 UTC
svn commit: r169299 [1/2] - in /lenya/trunk/src:
java/org/apache/lenya/cms/ant/
java/org/apache/lenya/cms/cocoon/components/modules/input/
java/org/apache/lenya/cms/metadata/
java/org/apache/lenya/cms/metadata/dublincore/
java/org/apache/lenya/cms/metadata/usecases/
java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/site/usecases/
test/org/apache/lenya/cms/publication/
webapp/lenya/pubs/default/content/authoring/concepts/
webapp/lenya/pubs/default/content/authoring/doctypes/
webapp/lenya/pubs/default/content/authoring/doctypes/xhtml-document/
webapp/lenya/pubs/default/content/authoring/features/
webapp/lenya/pubs/default/content/authoring/index/
webapp/lenya/pubs/default/content/authoring/links/
webapp/lenya/pubs/default/content/authoring/tutorial/
webapp/lenya/pubs/default/content/authoring/tutorial/new_doctype/
Author: jwkaltz
Date: Mon May 9 05:00:43 2005
New Revision: 169299
URL: http://svn.apache.org/viewcvs?rev=169299&view=rev
Log:
modified metadata handling: all meta is now separate from content, and can be of 3 different types (dc, lenya, custom)
Added:
lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java (with props)
lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java (with props)
lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java (with props)
lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/concepts/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/concepts/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/xhtml-document/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/xhtml-document/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/features/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/features/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/index/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/index/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/links/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/index_de.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/index_en.xml.meta (with props)
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/new_doctype/index_en.xml.meta (with props)
Removed:
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
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/metadata/dublincore/DublinCore.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java
lenya/trunk/src/test/org/apache/lenya/cms/publication/DublinCoreTest.java
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/concepts/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/concepts/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/xhtml-document/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/doctypes/xhtml-document/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/features/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/features/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/index/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/index/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/index_de.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/index_en.xml
lenya/trunk/src/webapp/lenya/pubs/default/content/authoring/tutorial/new_doctype/index_en.xml
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -19,6 +19,7 @@
package org.apache.lenya.cms.ant;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuildException;
@@ -234,13 +235,14 @@
Document doc = getIdentityMap()
.get(getPublication(), _area, _documentId, lang);
- DublinCore dc = (DublinCore) doc.getMetaData();
+ MetaData dc = (MetaData) doc.getMetaDataManager().getDublinCoreMetaData();
dc.setValue(DublinCore.ELEMENT_CREATOR, _creator);
dc.setValue(DublinCore.ELEMENT_TITLE, _title);
dc.setValue(DublinCore.ELEMENT_DESCRIPTION, _description);
dc.setValue(DublinCore.ELEMENT_SUBJECT, _subject);
dc.setValue(DublinCore.ELEMENT_PUBLISHER, _publisher);
dc.setValue(DublinCore.ELEMENT_RIGHTS, _rights);
+ dc.save();
}
/**
@@ -266,4 +268,4 @@
}
}
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -19,15 +19,13 @@
package org.apache.lenya.cms.cocoon.components.modules.input;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
import org.apache.lenya.cms.publication.Document;
@@ -44,18 +42,18 @@
public Object getAttribute(String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
- if (!DublinCoreImpl.isValidElement(name) && !DublinCoreImpl.isValidTerm(name)) {
- throw new ConfigurationException("The attribute [" + name + "] is not supported!");
- }
-
- Document document = getEnvelope(objectModel, name).getDocument();
-
- if (document == null) {
- throw new ConfigurationException("There is no document for this page envelope!");
- }
Object value;
try {
- DublinCore dc = (DublinCore) document.getMetaData();
+ Document document = getEnvelope(objectModel, name).getDocument();
+ if (document == null) {
+ throw new ConfigurationException("There is no document for this page envelope!");
+ }
+ MetaData dc = document.getMetaDataManager().getDublinCoreMetaData();
+
+ if (! dc.isValidAttribute(name)) {
+ throw new ConfigurationException("The attribute [" + name + "] is not supported!");
+ }
+
value = dc.getFirstValue(name);
} catch (Exception e) {
throw new ConfigurationException("Obtaining dublin core value for [" + name
@@ -72,9 +70,11 @@
public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
throws ConfigurationException {
- List names = new ArrayList();
- names.addAll(Arrays.asList(DublinCoreImpl.getElements()));
- names.addAll(Arrays.asList(DublinCoreImpl.getTerms()));
+ // calling static method on DublinCoreImpl is a work-around
+ // because we do not have access to an instance here, because
+ // the page envelope cannot be read here.
+ List names = DublinCoreImpl.getAttributeNames();
+
return names.iterator();
}
@@ -89,4 +89,4 @@
return objects;
}
-}
\ No newline at end of file
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java?rev=169299&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java Mon May 9 05:00:43 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999-2005 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.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * Custom meta-data is arbitrary meta-data that can be associated
+ * to a document or a resource.
+ *
+ * The following code illustrates how you would add custom
+ * metadata to a document:
+ * <pre>
+ * MetaData customMetaData = document.getMetaDataManager().getCustomMetaData();
+ * customMetaData.setValue("some-great-attribute", "some great value");
+ * customMetaData.setValue("another-great-attribute", "some fantastic value");
+ * customMetaData.save();
+ * </pre>
+ * @version $Id$
+ */
+public class CustomMetaData extends MetaDataImpl {
+
+ private static final String LOCAL_META = "custom";
+
+ private static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
+ private static final String PREFIX = "lenya";
+
+ /**
+ * @see MetaDataImpl#MetaDataImpl(java.lang.String, org.apache.avalon.framework.service.ServiceManager, org.apache.avalon.framework.logger.Logger)
+ */
+ public CustomMetaData(String sourceUri, ServiceManager manager, Logger _logger) throws DocumentException {
+ super(sourceUri, manager, _logger);
+ }
+
+ /**
+ * @see MetaDataImpl#useFixedElements()
+ */
+ protected boolean useFixedElements() {
+ return false;
+ }
+
+ /**
+ * @see MetaDataImpl#getNamespaces()
+ */
+ protected String[] getNamespaces() {
+ return new String[] { NAMESPACE };
+ }
+
+ /**
+ * @see MetaDataImpl#getPrefixes()
+ */
+ protected String[] getPrefixes() {
+ return new String[] { PREFIX };
+ }
+
+ /**
+ * @see MetaDataImpl#getElements()
+ */
+ protected String[] getElements() {
+ return new String[0];
+ }
+
+ /**
+ * @see MetaDataImpl#getTerms()
+ */
+ protected String[] getTerms() {
+ return new String[0];
+ }
+
+ /**
+ * @see MetaDataImpl#getLocalElementName()
+ */
+ protected String getLocalElementName() {
+ return LOCAL_META;
+ }
+
+}
Propchange: lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java?rev=169299&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java Mon May 9 05:00:43 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 1999-2005 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.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * Meta-data for Lenya's internal usage.
+ *
+ * @version $Id$
+ */
+public class LenyaMetaData extends MetaDataImpl {
+
+ private static final String LOCAL_META = "internal";
+
+ private static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
+ private static final String PREFIX = "lenya";
+
+ /**
+ * The name of the resource type attribute.
+ * An XML resource has a resource type; this information can be
+ * used e.g. for different rendering of different types.
+ */
+ public static final String ELEMENT_RESOURCE_TYPE = "resourceType";
+
+ /**
+ * The name of the content type attribute.
+ * Any content managed by Lenya has a type; this information can
+ * be used e.g. to provide an appropriate management interface.
+ */
+ public static final String ELEMENT_CONTENT_TYPE = "contentType";
+
+ static final String[] ELEMENTS = {
+ ELEMENT_RESOURCE_TYPE,
+ ELEMENT_CONTENT_TYPE
+ };
+
+ /**
+ * @see MetaDataImpl#MetaDataImpl(java.lang.String, org.apache.avalon.framework.service.ServiceManager, org.apache.avalon.framework.logger.Logger)
+ */
+ public LenyaMetaData(String sourceUri, ServiceManager manager, Logger _logger) throws DocumentException {
+ super(sourceUri, manager, _logger);
+ }
+
+ /**
+ * @see MetaDataImpl#getNamespaces()
+ */
+ protected String[] getNamespaces() {
+ return new String[] { NAMESPACE };
+ }
+
+ /**
+ * @see MetaDataImpl#getPrefixes()
+ */
+ protected String[] getPrefixes() {
+ return new String[] { PREFIX };
+ }
+
+ /**
+ * @see MetaDataImpl#getElements()
+ */
+ protected String[] getElements() {
+ return ELEMENTS;
+ }
+
+ /**
+ * @see MetaDataImpl#getTerms()
+ */
+ protected String[] getTerms() {
+ return new String[0];
+ }
+
+ /**
+ * @see MetaDataImpl#getLocalElementName()
+ */
+ protected String getLocalElementName() {
+ return LOCAL_META;
+ }
+
+}
Propchange: lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java?rev=169299&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java Mon May 9 05:00:43 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1999-2005 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 MetaData {
+
+ /**
+ * 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;
+
+ /**
+ * 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(MetaData other) throws DocumentException;
+
+ /**
+ * @return All keys that can be used.
+ */
+ String[] getPossibleKeys();
+
+ /**
+ * Checks if a key represents a valid metadata attribute.
+ * @param key The key.
+ * @return A boolean value.
+ */
+ boolean isValidAttribute(String key);
+
+}
Propchange: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java?rev=169299&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java Mon May 9 05:00:43 2005
@@ -0,0 +1,507 @@
+/*
+ * Copyright 1999-2005 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+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.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Generic meta-data implementation.
+ *
+ * Meta-data is represented as XML. For compatibility with the Dublin Core
+ * meta-data requirements, a set of meta-data may contain up to two
+ * namespaces, one for "elements" and one for "terms".
+ * A metadata implementation requiring only one namespace can ignore the
+ * "terms".
+ *
+ * @version $Id$
+ */
+public abstract class MetaDataImpl extends AbstractLogEnabled implements MetaData {
+
+ private String sourceUri;
+ private ServiceManager manager;
+
+ private Map elements = new HashMap();
+ private Map terms = new HashMap();
+ private List elementList = Arrays.asList(getElements());
+ private List termList = Arrays.asList(getTerms());
+
+ private static final String META_ROOT = "meta";
+
+ /**
+ * Creates a new instance of metadata
+ * @param sourceUri The source URI.
+ * @param manager The service manager.
+ * @param _logger A logger
+ * @throws DocumentException if an error occurs
+ */
+ public MetaDataImpl(String sourceUri, ServiceManager manager, Logger _logger) throws DocumentException {
+ ContainerUtil.enableLogging(this, _logger);
+ this.sourceUri = sourceUri;
+ this.manager = manager;
+ this.elementList = Arrays.asList(getElements());
+ this.termList = Arrays.asList(getTerms());
+ loadValues();
+ }
+
+ /**
+ * Determine under which element name this meta-data is specified.
+ *
+ * @return the name of the element containing this meta-data
+ */
+ protected abstract String getLocalElementName();
+
+ /**
+ * The namespaces under which this meta-data is specified.
+ *
+ * @return an array of strings, containing the names of the namespaces
+ */
+ protected abstract String[] getNamespaces();
+
+ /**
+ * The prefixes under which this meta-data is specified.
+ *
+ * @return an array of strings, containing the names of the prefixes
+ */
+ protected abstract String[] getPrefixes();
+
+ /**
+ * Elements to be used in this meta-data. A meta-data
+ * implementation which does not have a fixed list
+ * of elements may return an empty array, and override
+ * useFixedElements()
+ * @see #useFixedElements()
+ * @return an array of string representing the elements
+ */
+ protected abstract String[] getElements();
+
+ /**
+ * Terms to be used in this meta-data. A meta-data
+ * implementation requiring only one namespace may
+ * ignore terms and return an empty array.
+ *
+ * @return an array of string representing the terms
+ */
+ protected abstract String[] getTerms();
+
+ /**
+ * Determine if the meta-data should consist of a fixed list
+ * of known attributes, or whether arbitrary names can be used.
+ *
+ * @return true if meta-data consists of fixed elements
+ */
+ protected boolean useFixedElements() {
+ return true;
+ }
+
+ /**
+ * Loads the meta values from the XML source.
+ * @throws DocumentException when something went wrong.
+ */
+ protected void loadValues() throws DocumentException {
+
+ try {
+ Document doc = getDocument();
+ if (doc != null) {
+
+ Element metaElement = getLocalMetaElement(doc);
+
+ String[] namespaces = getNamespaces();
+ String[] prefixes = getPrefixes();
+ String[][] arrays = { getElements(), getTerms() };
+ Map[] maps = { this.elements, this.terms };
+
+ for (int type = 0; type < namespaces.length; type++) {
+ NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
+
+ if (useFixedElements()) {
+ String[] elementNames = arrays[type];
+ for (int i = 0; i < elementNames.length; i++) {
+ Element[] children = helper.getChildren(metaElement, elementNames[i]);
+ loadElementValues(maps[type], elementNames[i], children);
+ }
+ }
+ else {
+ Element[] elements = helper.getChildren(metaElement);
+ for (int i = 0; i < elements.length; i++) {
+ loadElementValues(maps[type], elements[i].getTagName(), helper.getChildren(metaElement, elements[i].getTagName()));
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ /**
+ * Retrieve an element (and its values) from the DOM and add the element to the map
+ */
+ private void loadElementValues(Map map, String elementName, Element[] children) {
+ String[] values = new String[children.length];
+ for (int valueIndex = 0; valueIndex < children.length; valueIndex++) {
+ values[valueIndex] =
+ DocumentHelper.getSimpleElementText(children[valueIndex]);
+ }
+ map.put(elementName, values);
+ }
+
+ /**
+ * Save the meta data.
+ * @throws DocumentException if the meta data could not be made persistent.
+ */
+ public void save() throws DocumentException {
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("MetaDataImpl::save() called, sourceUri [" + sourceUri + "]");
+
+ try {
+ Document doc = getDocument();
+ Element metaElement = getLocalMetaElement(doc);
+ String[] namespaces = getNamespaces();
+ String[] prefixes = getPrefixes();
+ String[][] arrays = { getElements(), getTerms() };
+ Map[] maps = { this.elements, this.terms };
+
+ List childNodes = new ArrayList();
+ NodeList nodes = metaElement.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ if (nodes.item(i).getParentNode() == metaElement) {
+ childNodes.add(nodes.item(i));
+ }
+ }
+ Node[] children = (Node[])childNodes.toArray(new Node[childNodes.size()]);
+ for (int i = 0; i < children.length; i++){
+ metaElement.removeChild(children[i]);
+ }
+
+ for (int type = 0; type < namespaces.length; type++) {
+ NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
+ if (useFixedElements()) {
+ String[] elementNames = arrays[type];
+ for (int i = 0; i < elementNames.length; i++) {
+ writeElementValues(helper, metaElement, maps[type], elementNames[i]);
+ }
+ }
+ else {
+ Iterator elementNames = maps[type].keySet().iterator();
+ while (elementNames.hasNext()) {
+ writeElementValues(helper, metaElement, maps[type], (String)elementNames.next());
+ }
+ }
+ }
+
+ SourceUtil.writeDOM(doc, this.sourceUri, this.manager);
+ } catch (final Exception e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ /**
+ * Add a new element (and its values) to an existing element in the DOM
+ */
+ private void writeElementValues(NamespaceHelper helper, Element father, Map elementMap, String elementName) {
+ String[] values = (String[]) elementMap.get(elementName);
+ for (int valueIndex = 0; valueIndex < values.length; valueIndex++) {
+ Element valueElement = helper.createElement(elementName,
+ values[valueIndex]);
+ father.appendChild(valueElement);
+ }
+ }
+
+
+ /**
+ * Create a DOM representation of this meta-data.
+ * @return A DOM document.
+ * @throws ServiceException if a general error occurs.
+ * @throws SourceNotFoundException if the meta-data's source can not be found
+ */
+ protected Document getDocument() throws ServiceException, SourceNotFoundException,
+ ParserConfigurationException, SAXException, IOException {
+ org.w3c.dom.Document doc = SourceUtil.readDOM(this.sourceUri, this.manager);
+ NamespaceHelper namespaceHelper;
+ if (doc == null) {
+ namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, "document");
+ } else {
+ namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, doc);
+ }
+ return namespaceHelper.getDocument();
+ }
+
+
+ /**
+ * Returns the Lenya meta data element.
+ * @param document The XML document.
+ * @return A DOM element.
+ * @throws DocumentException if an error occurs.
+ */
+ protected Element getMetaElement(Document document) throws DocumentException {
+ Element metaElement;
+ try {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, document);
+ Element documentElement = namespaceHelper.getDocument().getDocumentElement();
+ metaElement = namespaceHelper.getFirstChild(documentElement, META_ROOT);
+
+ if (metaElement == null) {
+ metaElement = namespaceHelper.createElement(META_ROOT);
+ Element[] children = DocumentHelper.getChildren(documentElement);
+ if (children.length == 0) {
+ documentElement.appendChild(metaElement);
+ } else {
+ documentElement.insertBefore(metaElement, children[0]);
+ }
+ }
+ } catch (final Exception e) {
+ throw new DocumentException(e);
+ }
+ return metaElement;
+ }
+
+ /**
+ * Returns the meta data element for this type of meta-data
+ * @param document The XML document.
+ * @return A DOM element.
+ * @throws DocumentException if an error occurs.
+ */
+ protected Element getLocalMetaElement(Document document) throws DocumentException {
+ Element topMetaElement = getMetaElement(document);
+
+ Element metaElement;
+ try {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, document);
+ metaElement = namespaceHelper.getFirstChild(topMetaElement, getLocalElementName());
+
+ if (metaElement == null) {
+ metaElement = namespaceHelper.createElement(getLocalElementName());
+ Element[] children = DocumentHelper.getChildren(topMetaElement);
+ if (children.length == 0) {
+ topMetaElement.appendChild(metaElement);
+ } else {
+ topMetaElement.insertBefore(metaElement, children[0]);
+ }
+ }
+ } catch (final Exception e) {
+ throw new DocumentException(e);
+ }
+ return metaElement;
+ }
+
+ /**
+ * Returns the first value for a certain key.
+ * @param key The key.
+ * @return A string.
+ * @throws DocumentException if an error occurs.
+ */
+ public String getFirstValue(String key) throws DocumentException {
+ String value = null;
+ String[] values = getElementOrTerm(key);
+ if (values.length > 0) {
+ value = values[0];
+ }
+ return value;
+ }
+
+ /**
+ * Returns the element or term values, resp., for a certain key.
+ * @param key The key.
+ * @return An array of strings.
+ * @throws DocumentException if an error occurs.
+ */
+ protected String[] getElementOrTerm(String key) throws DocumentException {
+ String[] values;
+
+ if (elementList.contains(key)) {
+ values = (String[]) this.elements.get(key);
+ } else if (termList.contains(key)) {
+ values = (String[]) this.terms.get(key);
+ } else {
+ throw new DocumentException("The key [" + key
+ + "] does not refer to a metadata element or term!");
+ }
+ if (values == null) {
+ values = new String[0];
+ }
+ return values;
+ }
+
+ /**
+ * Returns all values for a certain key.
+ * @param key The key.
+ * @return An array of strings.
+ * @throws DocumentException if an error occurs.
+ * @see MetaData#getValues(String)
+ */
+ public String[] getValues(String key) throws DocumentException {
+ return getElementOrTerm(key);
+ }
+
+ /**
+ * @param key The key.
+ * @param value The value.
+ * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaData#setValue(java.lang.String,
+ * java.lang.String)
+ */
+ public void setValue(String key, String value) throws DocumentException {
+ String[] newValues = { value };
+
+ if (useFixedElements()) {
+ if (elementList.contains(key)) {
+ this.elements.put(key, newValues);
+ } else if (termList.contains(key)) {
+ this.terms.put(key, newValues);
+ } else {
+ throw new DocumentException("The key [" + key
+ + "] does not refer to a dublin core element or term!");
+ }
+ }
+ else
+ this.elements.put(key, newValues);
+ }
+
+ /**
+ * @param other The other meta-data
+ * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaData#replaceBy(org.apache.lenya.cms.metadata.MetaData)
+ */
+ public void replaceBy(MetaData other) throws DocumentException {
+ if (useFixedElements()) {
+ String[] elements = getElements();
+ String[] terms = getTerms();
+ for (int i = 0; i < elements.length; i++) {
+ String key = elements[i];
+ removeAllValues(key);
+ addValues(key, other.getValues(key));
+ }
+ for (int i = 0; i < terms.length; i++) {
+ String key = terms[i];
+ removeAllValues(key);
+ addValues(key, other.getValues(key));
+ }
+ }
+ else {
+ // elements not fixed: clear old elements and write all from other
+ elementList = new ArrayList();
+ termList = new ArrayList();
+ String[] newKeys = other.getPossibleKeys();
+ for (int i = 0; i < newKeys.length; i++) {
+ String key = newKeys[i];
+ addValues(key, other.getValues(key));
+ }
+ }
+ save();
+ }
+
+ /**
+ * @return All possible keys.
+ */
+ public String[] getPossibleKeys() {
+ List keys = new ArrayList();
+ keys.addAll(this.elementList);
+ keys.addAll(this.termList);
+ return (String[]) keys.toArray(new String[keys.size()]);
+ }
+
+ /**
+ * Checks if a key represents a valid metadata attribute.
+ * @param key The key.
+ * @return A boolean value.
+ */
+ public boolean isValidAttribute(String key) {
+ return termList.contains(key) || elementList.contains(key);
+ }
+
+ /**
+ * Adds a value for a certain key.
+ * @param key The key.
+ * @param value The value.
+ * @throws DocumentException if an error occurs.
+ */
+ private void addValue(String key, String value) throws DocumentException {
+ String[] existingValues = getElementOrTerm(key);
+ List list = new ArrayList(Arrays.asList(existingValues));
+ list.add(value);
+ String[] newValues = (String[]) list.toArray(new String[list.size()]);
+
+ if (elementList.contains(key)) {
+ this.elements.put(key, newValues);
+ } else if (termList.contains(key)) {
+ this.terms.put(key, newValues);
+ } else {
+ throw new DocumentException("The key [" + key
+ + "] does not refer to a metadata element or term!");
+ }
+ }
+
+ /**
+ * @param key The key.
+ * @param values The values.
+ * @throws DocumentException if an error occurs.
+ */
+ private void addValues(String key, String[] values) throws DocumentException {
+ for (int i = 0; i < values.length; i++) {
+ addValue(key, values[i]);
+ }
+ }
+
+ /**
+ * @param key The key.
+ * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaData#removeAllValues(java.lang.String)
+ */
+ private void removeAllValues(String key) throws DocumentException {
+ if (elementList.contains(key)) {
+ this.elements.put(key, new String[0]);
+ } else if (termList.contains(key)) {
+ this.terms.put(key, new String[0]);
+ } else {
+ throw new DocumentException("The key [" + key
+ + "] does not refer to a dublin core element or term!");
+ }
+ }
+
+
+}
Propchange: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: 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?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java Mon May 9 05:00:43 2005
@@ -16,88 +16,88 @@
*/
package org.apache.lenya.cms.metadata;
+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.metadata.dublincore.DublinCoreImpl;
import org.apache.lenya.cms.publication.DocumentException;
/**
- * Generic meta data interface.
+ * Manager for meta data of a Lenya resource/document
*
- * @version $Id:$
+ * @version $Id$
*/
-public interface MetaDataManager {
+public class MetaDataManager extends AbstractLogEnabled {
- /**
- * 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();
+ private String sourceUri;
+ private ServiceManager serviceManager;
+ private DublinCoreImpl dublinCore;
+ private LenyaMetaData lenyaMetaData;
+ private CustomMetaData customMetaData;
+
+ /**
+ * Ctor.
+ */
+ public MetaDataManager(String _sourceUri, ServiceManager _serviceManager, Logger _logger) {
+ ContainerUtil.enableLogging(this, _logger);
+ this.sourceUri = _sourceUri;
+ this.serviceManager = _serviceManager;
+ }
+
+ /**
+ * Retrieve the dublin core meta-data managed by this instance.
+ * @return the dublin core meta-data
+ * @throws DocumentException if the meta-data could not be retrieved
+ */
+ public DublinCoreImpl getDublinCoreMetaData() throws DocumentException {
+ if (dublinCore == null) {
+ dublinCore = new DublinCoreImpl(this.sourceUri, this.serviceManager, getLogger());
+ }
+ return dublinCore;
+ }
+
+ /**
+ * Retrieve the Lenya internal meta-data managed by this instance.
+ * @return the Lenya meta-data
+ * @throws DocumentException if the meta-data could not be retrieved
+ */
+ public LenyaMetaData getLenyaMetaData() throws DocumentException {
+ if (lenyaMetaData == null) {
+ lenyaMetaData = new LenyaMetaData(this.sourceUri, this.serviceManager, getLogger());
+ }
+ return lenyaMetaData;
+ }
+
+ /**
+ * Retrieve the custom meta-data managed by this instance.
+ * @return the custom meta-data
+ * @throws DocumentException if the meta-data could not be retrieved
+ */
+ public CustomMetaData getCustomMetaData() throws DocumentException {
+ if (customMetaData == null) {
+ customMetaData = new CustomMetaData(this.sourceUri, this.serviceManager, getLogger());
+ }
+ return customMetaData;
+ }
+
+ /**
+ * Replace the contents of the meta-data managed by this instance with
+ * the contents of the meta-data managed by another instance of
+ * MetaDataManager.
+ * @param sourceManager the MetaDataManager from which to read the new meta-data
+ * @throws DocumentException if something goes wrong
+ */
+ public void replaceMetaData(MetaDataManager sourceManager) throws DocumentException {
+ MetaData source = sourceManager.getDublinCoreMetaData();
+ MetaData dest = this.getDublinCoreMetaData();
+ dest.replaceBy(source);
+ source = sourceManager.getLenyaMetaData();
+ dest = this.getLenyaMetaData();
+ dest.replaceBy(source);
+ source = sourceManager.getCustomMetaData();
+ dest = this.getCustomMetaData();
+ dest.replaceBy(source);
+ }
}
Modified: 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?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java Mon May 9 05:00:43 2005
@@ -16,16 +16,18 @@
*/
package org.apache.lenya.cms.metadata;
+import org.apache.lenya.cms.publication.DocumentException;
+
/**
- * Owner of meta data.
+ * Owner of meta-data.
*
- * @version $Id:$
+ * @version $Id$
*/
public interface MetaDataOwner {
/**
- * @return The meta data.
+ * @return A manager for the meta data.
*/
- MetaDataManager getMetaData();
+ MetaDataManager getMetaDataManager() throws DocumentException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -17,7 +17,7 @@
package org.apache.lenya.cms.metadata.dublincore;
-import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.MetaData;
/**
* <p>
@@ -29,7 +29,7 @@
*
* @version $Id$
*/
-public interface DublinCore extends MetaDataManager {
+public interface DublinCore extends MetaData {
/**
* A name given to the resource. Typically, Title will be a name by which the resource is
@@ -346,4 +346,4 @@
*/
static final String TERM_VALID = "valid";
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -21,6 +21,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
@@ -40,6 +41,9 @@
}
private static Logger log = Logger.getLogger(DublinCoreHelper.class);
+ private static Logger getLogger() {
+ return log;
+ }
/**
* Get the value of the DCIdentifier corresponding to a document id.
@@ -67,16 +71,18 @@
if (languages.length > 0) {
while (identifier == null && i < languages.length) {
Document document = map.get(publication, area, documentId, languages[i]);
- log.debug("document file : " + document.getFile().getAbsolutePath());
- DublinCore dublincore = (DublinCore) document.getMetaData();
- log.debug("dublincore title : "
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("document file : " + document.getFile().getAbsolutePath());
+ MetaData dublincore = document.getMetaDataManager().getDublinCoreMetaData();
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("dublincore title : "
+ dublincore.getFirstValue(DublinCore.ELEMENT_TITLE));
identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
i = i + 1;
}
}
if (languages.length < 1 || identifier == null) {
- DublinCore dublincore = (DublinCore) baseDocument.getMetaData();
+ MetaData dublincore = baseDocument.getMetaDataManager().getDublinCoreMetaData();
identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
}
} catch (final DocumentException e) {
@@ -92,4 +98,4 @@
return identifier;
}
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java Mon May 9 05:00:43 2005
@@ -15,48 +15,25 @@
*
*/
-/* $Id$ */
-
package org.apache.lenya.cms.metadata.dublincore;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-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.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.excalibur.source.SourceNotFoundException;
-import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.metadata.MetaDataImpl;
import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.xml.DocumentHelper;
-import org.apache.lenya.xml.NamespaceHelper;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
/**
* Access dublin core meta data in documents. This class uses the dublin core specification from
* 2003-03-04.
+ * @version $Id$
*/
-public class DublinCoreImpl extends AbstractLogEnabled {
+public class DublinCoreImpl extends MetaDataImpl {
- private String sourceUri;
-
- private Map elements = new HashMap();
- private Map terms = new HashMap();
-
- private static final String META = "meta";
+ private static final String LOCAL_META = "dc";
private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
private static final String DC_PREFIX = "dc";
@@ -64,12 +41,22 @@
/**
* The dublin core elements.
*/
- static final String[] ELEMENTS = { DublinCore.ELEMENT_TITLE, DublinCore.ELEMENT_CREATOR,
- DublinCore.ELEMENT_SUBJECT, DublinCore.ELEMENT_DESCRIPTION,
- DublinCore.ELEMENT_PUBLISHER, DublinCore.ELEMENT_CONTRIBUTOR, DublinCore.ELEMENT_DATE,
- DublinCore.ELEMENT_TYPE, DublinCore.ELEMENT_FORMAT, DublinCore.ELEMENT_IDENTIFIER,
- DublinCore.ELEMENT_SOURCE, DublinCore.ELEMENT_LANGUAGE, DublinCore.ELEMENT_RELATION,
- DublinCore.ELEMENT_COVERAGE, DublinCore.ELEMENT_RIGHTS };
+ static final String[] ELEMENTS = {
+ DublinCore.ELEMENT_TITLE,
+ DublinCore.ELEMENT_CREATOR,
+ DublinCore.ELEMENT_SUBJECT,
+ DublinCore.ELEMENT_DESCRIPTION,
+ DublinCore.ELEMENT_PUBLISHER,
+ DublinCore.ELEMENT_CONTRIBUTOR,
+ DublinCore.ELEMENT_DATE,
+ DublinCore.ELEMENT_TYPE,
+ DublinCore.ELEMENT_FORMAT,
+ DublinCore.ELEMENT_IDENTIFIER,
+ DublinCore.ELEMENT_SOURCE,
+ DublinCore.ELEMENT_LANGUAGE,
+ DublinCore.ELEMENT_RELATION,
+ DublinCore.ELEMENT_COVERAGE,
+ DublinCore.ELEMENT_RIGHTS };
private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
private static final String DCTERMS_PREFIX = "dcterms";
@@ -77,392 +64,95 @@
/**
* The dublin core terms.
*/
- static final String[] TERMS = { DublinCore.TERM_AUDIENCE, DublinCore.TERM_ALTERNATIVE,
- DublinCore.TERM_TABLEOFCONTENTS, DublinCore.TERM_ABSTRACT, DublinCore.TERM_CREATED,
- DublinCore.TERM_VALID, DublinCore.TERM_EXTENT, DublinCore.TERM_AVAILABLE,
- DublinCore.TERM_ISSUED, DublinCore.TERM_MODIFIED, DublinCore.TERM_EXTENT,
- DublinCore.TERM_LICENSE, DublinCore.TERM_MEDIUM, DublinCore.TERM_ISVERSIONOF,
- DublinCore.TERM_HASVERSION, DublinCore.TERM_ISREPLACEDBY, DublinCore.TERM_REPLACES,
- DublinCore.TERM_ISREQUIREDBY, DublinCore.TERM_REQUIRES, DublinCore.TERM_ISPARTOF,
- DublinCore.TERM_HASPART, DublinCore.TERM_ISREFERENCEDBY, DublinCore.TERM_REFERENCES,
- DublinCore.TERM_RIGHTSHOLDER, DublinCore.TERM_ISFORMATOF, DublinCore.TERM_HASFORMAT,
- DublinCore.TERM_CONFORMSTO, DublinCore.TERM_SPATIAL, DublinCore.TERM_TEMPORAL,
- DublinCore.TERM_MEDIATOR, DublinCore.TERM_DATEACCEPTED,
- DublinCore.TERM_DATECOPYRIGHTED, DublinCore.TERM_DATESUBMITTED,
- DublinCore.TERM_EDUCATIONLEVEL, DublinCore.TERM_ACCESSRIGHTS,
+ private static final String[] TERMS = {
+ DublinCore.TERM_AUDIENCE,
+ DublinCore.TERM_ALTERNATIVE,
+ DublinCore.TERM_TABLEOFCONTENTS,
+ DublinCore.TERM_ABSTRACT,
+ DublinCore.TERM_CREATED,
+ DublinCore.TERM_VALID,
+ DublinCore.TERM_EXTENT,
+ DublinCore.TERM_AVAILABLE,
+ DublinCore.TERM_ISSUED,
+ DublinCore.TERM_MODIFIED,
+ DublinCore.TERM_EXTENT,
+ DublinCore.TERM_LICENSE,
+ DublinCore.TERM_MEDIUM,
+ DublinCore.TERM_ISVERSIONOF,
+ DublinCore.TERM_HASVERSION,
+ DublinCore.TERM_ISREPLACEDBY,
+ DublinCore.TERM_REPLACES,
+ DublinCore.TERM_ISREQUIREDBY,
+ DublinCore.TERM_REQUIRES,
+ DublinCore.TERM_ISPARTOF,
+ DublinCore.TERM_HASPART,
+ DublinCore.TERM_ISREFERENCEDBY,
+ DublinCore.TERM_REFERENCES,
+ DublinCore.TERM_RIGHTSHOLDER,
+ DublinCore.TERM_ISFORMATOF,
+ DublinCore.TERM_HASFORMAT,
+ DublinCore.TERM_CONFORMSTO,
+ DublinCore.TERM_SPATIAL,
+ DublinCore.TERM_TEMPORAL,
+ DublinCore.TERM_MEDIATOR,
+ DublinCore.TERM_DATEACCEPTED,
+ DublinCore.TERM_DATECOPYRIGHTED,
+ DublinCore.TERM_DATESUBMITTED,
+ DublinCore.TERM_EDUCATIONLEVEL,
+ DublinCore.TERM_ACCESSRIGHTS,
DublinCore.TERM_BIBLIOGRAPHICCITATION };
- private ServiceManager manager;
-
/**
- * Creates a new instance of Dublin Core
- * @param sourceUri The source URI.
- * @param manager The service manager.
- * @throws DocumentException if an error occurs
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#MetaDataImpl(java.lang.String, org.apache.avalon.framework.service.ServiceManager, org.apache.avalon.framework.logger.Logger)
*/
public DublinCoreImpl(String sourceUri, ServiceManager manager, Logger _logger) throws DocumentException {
- ContainerUtil.enableLogging(this, _logger);
- this.sourceUri = sourceUri;
- this.manager = manager;
- loadValues();
- }
-
- /**
- * Loads the dublin core values from the XML file.
- * @throws DocumentException when something went wrong.
- */
- protected void loadValues() throws DocumentException {
-
- try {
- Document doc = getDocument();
- if (doc != null) {
-
- // FIXME: what if "lenya:meta" element doesn't exist yet?
- // Currently the element is inserted.
- Element metaElement = getMetaElement(doc);
-
- String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
- String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
- String[][] arrays = { ELEMENTS, TERMS };
- Map[] maps = { this.elements, this.terms };
-
- for (int type = 0; type < 2; type++) {
- NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type],
- doc);
- String[] elementNames = arrays[type];
- for (int i = 0; i < elementNames.length; i++) {
- Element[] children = helper.getChildren(metaElement, elementNames[i]);
- String[] values = new String[children.length];
- for (int valueIndex = 0; valueIndex < children.length; valueIndex++) {
- values[valueIndex] = DocumentHelper
- .getSimpleElementText(children[valueIndex]);
- }
- maps[type].put(elementNames[i], values);
- }
- }
- }
- } catch (Exception e) {
- throw new DocumentException(e);
- }
- }
-
- /**
- * Save the meta data.
- * @throws DocumentException if the meta data could not be made persistent.
- */
- protected void save() throws DocumentException {
-
- if (getLogger().isDebugEnabled())
- getLogger().debug("DublinCoreImpl::save() called, sourceUri [" + sourceUri + "]");
-
- try {
- Document doc = getDocument();
- Element metaElement = getMetaElement(doc);
- String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
- String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
- String[][] arrays = { ELEMENTS, TERMS };
- Map[] maps = { this.elements, this.terms };
-
- List childNodes = new ArrayList();
- NodeList nodes = metaElement.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- if (nodes.item(i).getParentNode() == metaElement) {
- childNodes.add(nodes.item(i));
- }
- }
- Node[] children = (Node[])childNodes.toArray(new Node[childNodes.size()]);
- for (int i = 0; i < children.length; i++){
- metaElement.removeChild(children[i]);
- }
-
- for (int type = 0; type < 2; type++) {
- NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
- String[] elementNames = arrays[type];
- for (int i = 0; i < elementNames.length; i++) {
- String[] values = (String[]) maps[type].get(elementNames[i]);
- for (int valueIndex = 0; valueIndex < values.length; valueIndex++) {
- Element valueElement = helper.createElement(elementNames[i],
- values[valueIndex]);
- metaElement.appendChild(valueElement);
- }
- }
- }
-
- SourceUtil.writeDOM(doc, this.sourceUri, this.manager);
- } catch (final Exception e) {
- throw new DocumentException(e);
- }
+ super(sourceUri, manager, _logger);
}
/**
- * Returns the Lenya meta data element.
- * @param document The XML document.
- * @return A DOM element.
- * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#getNamespaces()
*/
- protected Element getMetaElement(Document document) throws DocumentException {
- Element metaElement;
- try {
- NamespaceHelper namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
- PageEnvelope.DEFAULT_PREFIX, document);
- Element documentElement = namespaceHelper.getDocument().getDocumentElement();
- metaElement = namespaceHelper.getFirstChild(documentElement, META);
-
- if (metaElement == null) {
- metaElement = namespaceHelper.createElement(META);
- Element[] children = DocumentHelper.getChildren(documentElement);
- if (children.length == 0) {
- documentElement.appendChild(metaElement);
- } else {
- documentElement.insertBefore(metaElement, children[0]);
- }
- }
- } catch (final Exception e) {
- throw new DocumentException(e);
- }
- return metaElement;
- }
-
- protected Document getDocument() throws ServiceException, SourceNotFoundException,
- ParserConfigurationException, SAXException, IOException {
- org.w3c.dom.Document doc = SourceUtil.readDOM(this.sourceUri, this.manager);
- NamespaceHelper namespaceHelper;
- if (doc == null) {
- namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
- PageEnvelope.DEFAULT_PREFIX, "document");
- } else {
- namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
- PageEnvelope.DEFAULT_PREFIX, doc);
- }
- return namespaceHelper.getDocument();
+ protected String[] getNamespaces() {
+ return new String[] { DC_NAMESPACE, DCTERMS_NAMESPACE };
}
/**
- * Returns the first value for a certain key.
- * @param key The key.
- * @return A string.
- * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#getPrefixes()
*/
- public String getFirstValue(String key) throws DocumentException {
- String value = null;
- String[] values = getElementOrTerm(key);
- if (values.length > 0) {
- value = values[0];
- }
- return value;
+ protected String[] getPrefixes() {
+ return new String[] { DC_PREFIX, DCTERMS_PREFIX };
}
/**
- * Returns the element or term values, resp., for a certain key.
- * @param key The key.
- * @return An array of strings.
- * @throws DocumentException if an error occurs.
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#getElements()
*/
- protected String[] getElementOrTerm(String key) throws DocumentException {
- String[] values;
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- values = (String[]) this.elements.get(key);
- } else if (termList.contains(key)) {
- values = (String[]) this.terms.get(key);
- } else {
- throw new DocumentException("The key [" + key
- + "] does not refer to a dublin core element or term!");
- }
- if (values == null) {
- values = new String[0];
- }
- return values;
+ protected String[] getElements() {
+ return ELEMENTS;
}
/**
- * Returns all values for a certain key.
- * @param key The key.
- * @return An array of strings.
- * @throws DocumentException if an error occurs.
- * @see DublinCore#getValues(String)
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#getTerms()
*/
- public String[] getValues(String key) throws DocumentException {
- return getElementOrTerm(key);
- }
-
- /**
- * Adds a value for a certain key.
- * @param key The key.
- * @param value The value.
- * @throws DocumentException if an error occurs.
- * @see DublinCore#addValue(String, String)
- */
- public void addValue(String key, String value) throws DocumentException {
- String[] existingValues = getElementOrTerm(key);
- List list = new ArrayList(Arrays.asList(existingValues));
- list.add(value);
- String[] newValues = (String[]) list.toArray(new String[list.size()]);
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- this.elements.put(key, newValues);
- } else if (termList.contains(key)) {
- this.terms.put(key, newValues);
- } else {
- throw new DocumentException("The key [" + key
- + "] does not refer to a dublin core element or term!");
- }
- save();
- }
-
- /**
- * @param key The key.
- * @param value The value.
- * @throws DocumentException if an error occurs.
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#setValue(java.lang.String,
- * java.lang.String)
- */
- public void setValue(String key, String value) throws DocumentException {
- String[] newValues = { value };
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- this.elements.put(key, newValues);
- } else if (termList.contains(key)) {
- this.terms.put(key, newValues);
- } else {
- throw new DocumentException("The key [" + key
- + "] does not refer to a dublin core element or term!");
- }
- save();
+ protected String[] getTerms() {
+ return TERMS;
}
/**
- * @param key The key.
- * @param values The values.
- * @throws DocumentException if an error occurs.
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#addValues(java.lang.String,
- * java.lang.String[])
+ * @see org.apache.lenya.cms.metadata.MetaDataImpl#getLocalElementName()
*/
- public void addValues(String key, String[] values) throws DocumentException {
- for (int i = 0; i < values.length; i++) {
- addValue(key, values[i]);
- }
- save();
+ protected String getLocalElementName() {
+ return LOCAL_META;
}
/**
- * @param key The key.
- * @param value The value.
- * @throws DocumentException if an error occurs.
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#removeValue(java.lang.String,
- * java.lang.String)
+ * Returns a list of all allowed attribute names in this
+ * metadata.
+ * @return the list of attribute names
*/
- public void removeValue(String key, String value) throws DocumentException {
- String[] existingValues = getElementOrTerm(key);
- List list = new ArrayList(Arrays.asList(existingValues));
-
- if (!list.contains(value)) {
- throw new DocumentException("The key [" + key + "] does not contain the value ["
- + value + "]!");
- }
-
- list.remove(value);
- String[] newValues = (String[]) list.toArray(new String[list.size()]);
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- this.elements.put(key, newValues);
- } else if (termList.contains(key)) {
- this.terms.put(key, newValues);
- } else {
- throw new DocumentException("The key [" + key
- + "] does not refer to a dublin core element or term!");
- }
- save();
+ public static List getAttributeNames() {
+ List names = new ArrayList();
+ names.addAll(Arrays.asList(ELEMENTS));
+ names.addAll(Arrays.asList(TERMS));
+ return names;
}
-
- /**
- * @param key The key.
- * @throws DocumentException if an error occurs.
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#removeAllValues(java.lang.String)
- */
- public void removeAllValues(String key) throws DocumentException {
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- this.elements.put(key, new String[0]);
- } else if (termList.contains(key)) {
- this.terms.put(key, new String[0]);
- } else {
- throw new DocumentException("The key [" + key
- + "] does not refer to a dublin core element or term!");
- }
- save();
- }
-
- /**
- * @param other The other dublin core.
- * @throws DocumentException if an error occurs.
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#replaceBy(org.apache.lenya.cms.metadata.dublincore.DublinCore)
- */
- public void replaceBy(DublinCore other) throws DocumentException {
- for (int i = 0; i < ELEMENTS.length; i++) {
- String key = ELEMENTS[i];
- removeAllValues(key);
- addValues(key, other.getValues(key));
- }
- for (int i = 0; i < TERMS.length; i++) {
- String key = TERMS[i];
- removeAllValues(key);
- addValues(key, other.getValues(key));
- }
- save();
- }
-
- /**
- * Returns the term keys.
- * @return An array of strings.
- */
- public static String[] getTerms() {
- return (String[]) Arrays.asList(TERMS).toArray(new String[TERMS.length]);
- }
-
- /**
- * Returns the element keys.
- * @return An array of strings.
- */
- public static String[] getElements() {
- return (String[]) Arrays.asList(ELEMENTS).toArray(new String[ELEMENTS.length]);
- }
-
- /**
- * Checks if a key represents a valid dublin core term.
- * @param key The key.
- * @return A boolean value.
- */
- public static boolean isValidTerm(String key) {
- return Arrays.asList(DublinCoreImpl.TERMS).contains(key);
- }
-
- /**
- * Checks if a key represents a valid dublin core element.
- * @param key The key.
- * @return A boolean value.
- */
- public static boolean isValidElement(String key) {
- return Arrays.asList(DublinCoreImpl.ELEMENTS).contains(key);
- }
-
- /**
- * @return All possible keys.
- */
- public String[] getPossibleKeys() {
- List keys = new ArrayList();
- keys.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS));
- keys.addAll(Arrays.asList(DublinCoreImpl.TERMS));
- return (String[]) keys.toArray(new String[keys.size()]);
- }
-
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java Mon May 9 05:00:43 2005
@@ -16,7 +16,7 @@
*/
package org.apache.lenya.cms.metadata.usecases;
-import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.transaction.Transactionable;
@@ -49,7 +49,7 @@
super.initParameters();
try {
- MetaDataManager meta = getSourceDocument().getMetaData();
+ MetaData meta = getSourceDocument().getMetaDataManager().getDublinCoreMetaData();
String[] keys = meta.getPossibleKeys();
for (int i = 0; i < keys.length; i++) {
@@ -86,7 +86,7 @@
protected void doExecute() throws Exception {
super.doExecute();
- MetaDataManager meta = getSourceDocument().getMetaData();
+ MetaData meta = getSourceDocument().getMetaDataManager().getDublinCoreMetaData();
String[] keys = meta.getPossibleKeys();
for (int i = 0; i < keys.length; i++) {
@@ -95,8 +95,9 @@
meta.setValue(keys[i], value);
}
}
+ meta.save();
//TODO set workflow situation to edit here.
}
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Mon May 9 05:00:43 2005
@@ -32,8 +32,8 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.RepositorySource;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataManager;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreProxy;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.repository.Node;
import org.apache.lenya.cms.site.SiteManager;
@@ -52,6 +52,7 @@
private String id;
private DocumentIdentityMap identityMap;
protected ServiceManager manager;
+ private MetaDataManager metaDataManager;
/**
* Creates a new instance of DefaultDocument. The language of the document is the default
@@ -386,11 +387,15 @@
}
/**
- * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaData()
+ * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaDataManager()
*/
- public MetaDataManager getMetaData() {
- return new DublinCoreProxy(getMetaSourceURI(), this.manager, getLogger());
+ public MetaDataManager getMetaDataManager() {
+ if (this.metaDataManager == null) {
+ metaDataManager = new MetaDataManager(getMetaSourceURI(), this.manager, getLogger());
+ }
+ return metaDataManager;
}
+
private History history;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -15,8 +15,6 @@
*
*/
-/* $Id$ */
-
package org.apache.lenya.cms.publication;
import java.io.File;
@@ -39,11 +37,13 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
-import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.transaction.Transactionable;
/**
* Manager for resources of a CMS document.
+ * @version $Id$
*/
public class DefaultResourcesManager extends AbstractLogEnabled implements ResourcesManager,
Serviceable {
@@ -95,10 +95,9 @@
}
}
- protected static final String NAMESPACE_META = "http://lenya.apache.org/meta/1.0";
/**
- * Create a new instance of Resources.
+ * Constructor
*/
public DefaultResourcesManager() {
}
@@ -136,8 +135,7 @@
/* if (type.equals("resource")) { */
- // create an extra file containing the meta description for
- // the resource.
+ // create the meta description for the resource.
createMetaData(resource, metadata);
/*
@@ -222,13 +220,19 @@
if (getLogger().isDebugEnabled())
getLogger().debug("DefaultResourcesManager::createMetaData() called");
- MetaDataManager meta = resource.getMetaData();
+ // Write Dublin Core meta-data
+ MetaData meta = resource.getMetaDataManager().getDublinCoreMetaData();
Iterator iter = metadata.entrySet().iterator();
-
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
meta.setValue((String) entry.getKey(), (String) entry.getValue());
}
+ meta.save();
+
+ // Now write Lenya internal metadata
+ MetaData lenyaMetaData = resource.getMetaDataManager().getLenyaMetaData();
+ lenyaMetaData.setValue(LenyaMetaData.ELEMENT_CONTENT_TYPE, "asset");
+ lenyaMetaData.save();
if (getLogger().isDebugEnabled())
getLogger().debug("DefaultResourcesManager::createMetaData() done.");
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -98,33 +98,33 @@
*/
String getLanguage();
- /**
- * Returns all the languages this document is available in.
+ /**
+ * Returns all the languages this document is available in.
* A document has one associated language (@see Document#getLanguage)
* but there are possibly a number of other languages for which a
* document with the same document-id is also available in.
*
- * @return An array of strings denoting the languages.
+ * @return An array of strings denoting the languages.
+ *
+ * @throws DocumentException if an error occurs
+ */
+ String[] getLanguages() throws DocumentException;
+
+ /**
+ * Get the navigation label associated with this document
+ * for the language.
+ *
+ * @return the label String
*
* @throws DocumentException if an error occurs
- */
- String[] getLanguages() throws DocumentException;
+ */
+ String getLabel() throws DocumentException;
- /**
- * Get the navigation label associated with this document
- * for the language.
- *
- * @return the label String
- *
- * @throws DocumentException if an error occurs
- */
- String getLabel() throws DocumentException;
-
- /**
- * Returns the date of the last modification of this document.
- * @return A date denoting the date of the last modification.
- */
- Date getLastModified();
+ /**
+ * Returns the date of the last modification of this document.
+ * @return A date denoting the date of the last modification.
+ */
+ Date getLastModified();
/**
* Returns the area this document belongs to.
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Mon May 9 05:00:43 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2005 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.
@@ -33,7 +33,7 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
-import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.site.SiteManager;
@@ -41,7 +41,7 @@
import org.apache.lenya.cms.workflow.WorkflowManager;
/**
- * Abstract DocumentManager implementation.
+ * DocumentManager implementation.
*
* @version $Id:$
*/
@@ -364,9 +364,8 @@
destination = sourceResolver.resolveURI(destinationDocument.getSourceURI());
SourceUtil.copy(source, (ModifiableSource) destination, true);
- MetaDataManager sourceCore = sourceDocument.getMetaData();
- MetaDataManager destCore = destinationDocument.getMetaData();
- destCore.replaceBy(sourceCore);
+ destinationDocument.getMetaDataManager().replaceMetaData(sourceDocument.getMetaDataManager());
+
} catch (Exception e) {
throw new PublicationException(e);
} finally {
@@ -403,14 +402,23 @@
this.rootTarget = target;
}
+ /**
+ * @return the root source
+ */
protected Document getRootSource() {
return rootSource;
}
+ /**
+ * @return the root target
+ */
protected Document getRootTarget() {
return rootTarget;
}
+ /**
+ * @return the document manager
+ */
protected DocumentManager getDocumentManager() {
return this.manager;
}
Modified: 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?rev=169299&r1=169298&r2=169299&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java Mon May 9 05:00:43 2005
@@ -24,22 +24,23 @@
import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.RepositorySource;
+import org.apache.lenya.cms.metadata.MetaData;
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:$
+ * @version $Id$
*/
public class Resource extends AbstractLogEnabled implements MetaDataOwner {
private Document document;
private String name;
private ServiceManager manager;
+ private MetaDataManager metaDataManager;
/**
* Ctor.
@@ -69,10 +70,13 @@
}
/**
- * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaData()
+ * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaDataManager()
*/
- public MetaDataManager getMetaData() {
- return new DublinCoreProxy(getMetaSourceURI(), this.manager, getLogger());
+ public MetaDataManager getMetaDataManager() {
+ if (this.metaDataManager == null) {
+ metaDataManager = new MetaDataManager(getMetaSourceURI(), this.manager, getLogger());
+ }
+ return metaDataManager;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org