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 2006/07/20 09:56:54 UTC
svn commit: r423814 - in /lenya/trunk/src: impl/java/org/apache/lenya/
impl/java/org/apache/lenya/cms/metadata/
impl/java/org/apache/lenya/cms/publication/
impl/test/org/apache/lenya/cms/metadata/
java/org/apache/lenya/cms/metadata/ java/org/apache/len...
Author: andreas
Date: Thu Jul 20 00:56:53 2006
New Revision: 423814
URL: http://svn.apache.org/viewvc?rev=423814&view=rev
Log:
Starting implementation of configurable meta data
Added:
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/MetaDataRegistryImpl.java
lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/
lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/ElementSet.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataRegistry.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadata.xconf
lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadataregistry.xconf
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles
lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
lenya/trunk/src/modules/sourcerepository/module.xml
Added: lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java (added)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ * Avalon-based element set.
+ */
+public class ConfigurableElementSet extends AbstractLogEnabled implements ElementSet, Configurable,
+ ThreadSafe {
+
+ private String namespaceUri;
+ private Map elements = new HashMap();
+
+ protected String getNamespaceURI() {
+ return this.namespaceUri;
+ }
+
+ public void configure(Configuration config) throws ConfigurationException {
+
+ this.namespaceUri = config.getAttribute("name");
+
+ Configuration[] attributeConfigs = config.getChildren("element");
+ for (int i = 0; i < attributeConfigs.length; i++) {
+ String name = attributeConfigs[i].getAttribute("name");
+ boolean isMultiple = attributeConfigs[i].getAttributeAsBoolean("multiple", false);
+ this.elements.put(name, new ElementImpl(name, isMultiple));
+ }
+
+ }
+
+ public Element[] getElements() {
+ Collection values = this.elements.values();
+ return (Element[]) values.toArray(new Element[values.size()]);
+ }
+
+ public Element getElement(String name) {
+ return (Element) this.elements.get(name);
+ }
+
+ public String getNamespaceUri() {
+ return this.namespaceUri;
+ }
+
+}
Added: lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java (added)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+/**
+ * Element implementation.
+ */
+public class ElementImpl implements Element {
+
+ private String name;
+ private boolean multiple;
+ private String description = "";
+
+ /**
+ * Ctor.
+ * @param name The name.
+ * @param isMultiple if the element can have multiple values.
+ */
+ public ElementImpl(String name, boolean isMultiple) {
+ this.name = name;
+ this.multiple = isMultiple;
+ }
+
+ /**
+ * Ctor.
+ * @param name The name.
+ * @param isMultiple if the element can have multiple values.
+ * @param description The description of the element.
+ */
+ public ElementImpl(String name, boolean isMultiple, String description) {
+ this.name = name;
+ this.multiple = isMultiple;
+ this.description = description;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public boolean isMultiple() {
+ return this.multiple;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+}
Added: lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/MetaDataRegistryImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/MetaDataRegistryImpl.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/MetaDataRegistryImpl.java (added)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/MetaDataRegistryImpl.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,66 @@
+/*
+ * 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.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.ExtendedComponentSelector;
+import org.apache.lenya.cms.publication.DocumentException;
+
+public class MetaDataRegistryImpl extends AbstractLogEnabled implements MetaDataRegistry, Serviceable {
+
+ public ElementSet getElementSet(String namespaceUri) throws DocumentException {
+ ServiceSelector selector = null;
+ try {
+ selector = (ServiceSelector) this.manager.lookup(ElementSet.class.getName() + "Selector");
+ return (ElementSet) selector.select(namespaceUri);
+ } catch (ServiceException e) {
+ throw new DocumentException(e);
+ }
+ finally {
+ if (selector != null) {
+ this.manager.release(selector);
+ }
+ }
+ }
+
+ public boolean isRegistered(String namespaceUri) throws DocumentException {
+ ServiceSelector selector = null;
+ try {
+ selector = (ServiceSelector) this.manager.lookup(ElementSet.class.getName() + "Selector");
+ return selector.isSelectable(namespaceUri);
+ } catch (ServiceException e) {
+ throw new DocumentException(e);
+ }
+ finally {
+ if (selector != null) {
+ this.manager.release(selector);
+ }
+ }
+ }
+
+ private ServiceManager manager;
+
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+}
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Thu Jul 20 00:56:53 2006
@@ -37,6 +37,7 @@
import org.apache.lenya.cms.metadata.MetaDataManager;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.site.SiteManager;
/**
@@ -532,6 +533,10 @@
}
}
return this.resourceType;
+ }
+
+ public MetaData getMetaData(String namespaceUri) throws RepositoryException {
+ return getRepositoryNode().getMetaData(namespaceUri);
}
}
Modified: lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles Thu Jul 20 00:56:53 2006
@@ -166,6 +166,10 @@
shorthand="resource-types"
default-class="org.apache.lenya.cms.publication.ResourceTypeSelector"/>
+ <role name="org.apache.lenya.cms.metadata.ElementSetSelector"
+ shorthand="meta-data"
+ default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+
<role name="org.apache.lenya.cms.repository.RepositoryManager"
shorthand="repository-manager"
default-class="org.apache.lenya.cms.repository.RepositoryManagerImpl"/>
Added: lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java (added)
+++ lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.ac.impl.AccessControlTest;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+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.PublicationUtil;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+
+public class MetaDataTest extends AccessControlTest {
+
+ public void testMetaData() throws Exception {
+ Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(getManager(), session);
+
+ Publication publication = PublicationUtil.getPublication(getManager(), "test");
+ Document doc = factory.get(publication, Publication.AUTHORING_AREA, "/index", "en");
+
+ String namespaceUri = "foobar";
+ Exception e = null;
+ try {
+ doc.getMetaData(namespaceUri);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ assertNotNull(e);
+
+ namespaceUri = DublinCoreImpl.DC_NAMESPACE;
+ MetaData dc = doc.getMetaData(namespaceUri);
+
+ doc.getRepositoryNode().lock();
+
+ checkSetTitle(dc);
+
+ }
+
+ protected void checkSetTitle(MetaData dc) throws DocumentException {
+ Exception e = null;
+ try {
+ dc.setValue("foo", "bar");
+ } catch (Exception e1) {
+ e = e1;
+ }
+ assertNotNull(e);
+ dc.setValue("title", "This is the title");
+ }
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * A meta data element.
+ */
+public interface Element {
+
+ /**
+ * @return the name of the element.
+ */
+ String getName();
+
+ /**
+ * @return if the element can have multiple values.
+ */
+ boolean isMultiple();
+
+ /**
+ * @return the description of the element.
+ */
+ String getDescription();
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/ElementSet.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/ElementSet.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/ElementSet.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/ElementSet.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,43 @@
+/*
+ * 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.repository.RepositoryException;
+
+/**
+ * Definition of a set of meta data elements.
+ */
+public interface ElementSet {
+
+ /**
+ * @return The supported elements.
+ */
+ Element[] getElements();
+
+ /**
+ * @param name The name.
+ * @return The element.
+ * @throws RepositoryException if the element with this name does not exist.
+ */
+ Element getElement(String name) throws RepositoryException;
+
+ /**
+ * @return The namespace URI of this element set.
+ */
+ String getNamespaceUri();
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaData.java Thu Jul 20 00:56:53 2006
@@ -95,4 +95,5 @@
* @throws DocumentException if an error occurs.
*/
long getLastModified() throws DocumentException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataOwner.java?rev=423814&r1=423813&r2=423814&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 Thu Jul 20 00:56:53 2006
@@ -17,6 +17,7 @@
package org.apache.lenya.cms.metadata;
import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.repository.RepositoryException;
/**
* Owner of meta-data.
@@ -27,7 +28,16 @@
/**
* @return A manager for the meta data.
+ * @deprecated Use {@link #getMetaData(String)}ĂŠinstead.
*/
MetaDataManager getMetaDataManager() throws DocumentException;
+
+ /**
+ * Returns a meta data object.
+ * @param namespaceUri The namespace URI.
+ * @return A meta data object.
+ * @throws RepositoryException if an error occurs.
+ */
+ MetaData getMetaData(String namespaceUri) throws RepositoryException;
}
Added: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataRegistry.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataRegistry.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataRegistry.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataRegistry.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * Meta data registry.
+ */
+public interface MetaDataRegistry {
+
+ /**
+ * The Avalon role.
+ */
+ String ROLE = MetaDataRegistry.class.getName();
+
+ /**
+ * @param namespaceUri The namespace URI of the element set.
+ * @return the element set.
+ * @throws DocumentException if an error occurs.
+ */
+ ElementSet getElementSet(String namespaceUri) throws DocumentException;
+
+ /**
+ * Checks if an element set is registered.
+ * @param namespaceUri The namespace URI.
+ * @return A boolean value.
+ * @throws DocumentException if an error occurs.
+ */
+ boolean isRegistered(String namespaceUri) throws DocumentException;
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Resource.java?rev=423814&r1=423813&r2=423814&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 Thu Jul 20 00:56:53 2006
@@ -26,9 +26,11 @@
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.repository.Node;
+import org.apache.lenya.cms.repository.RepositoryException;
/**
* A resource (asset).
@@ -254,6 +256,10 @@
this.manager.release(resolver);
}
}
+ }
+
+ public MetaData getMetaData(String namespaceUri) throws RepositoryException {
+ return null;
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java Thu Jul 20 00:56:53 2006
@@ -20,6 +20,7 @@
import java.io.OutputStream;
import java.util.Collection;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataOwner;
/**
Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java Thu Jul 20 00:56:53 2006
@@ -23,6 +23,7 @@
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataManager;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.repo.Translation;
@@ -190,6 +191,11 @@
public String getIdentifiableType() {
return Node.IDENTIFIABLE_TYPE;
+ }
+
+ public MetaData getMetaData(String namespaceUri) throws RepositoryException {
+ // TODO Auto-generated method stub
+ return null;
}
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Thu Jul 20 00:56:53 2006
@@ -22,12 +22,21 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+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.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.commons.collections.set.CompositeSet.SetMutator;
import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceNotFoundException;
@@ -36,8 +45,11 @@
import org.apache.lenya.ac.Identity;
import org.apache.lenya.ac.User;
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.MetaDataRegistry;
import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationUtil;
import org.apache.lenya.cms.rc.RCEnvironment;
@@ -46,6 +58,11 @@
import org.apache.lenya.transaction.Lock;
import org.apache.lenya.transaction.TransactionException;
import org.apache.lenya.transaction.Transactionable;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
/**
* A repository node.
@@ -674,6 +691,149 @@
} catch (Exception e) {
throw new RepositoryException(e);
}
+ }
+
+ private Map namespace2metadata = new HashMap();
+
+ public MetaData getMetaData(String namespaceUri) throws RepositoryException {
+
+ MetaDataRegistry registry = null;
+ try {
+ Object obj = this.manager.lookup(MetaDataRegistry.ROLE);
+ registry = (MetaDataRegistry) this.manager.lookup(MetaDataRegistry.ROLE);
+ if (!registry.isRegistered(namespaceUri)) {
+ throw new RepositoryException("The namespace [" + namespaceUri + "] is not registered!");
+ }
+ } catch (ServiceException e) {
+ throw new RepositoryException(e);
+ } catch (DocumentException e) {
+ throw new RepositoryException(e);
+ }
+ finally {
+ if (registry != null) {
+ this.manager.release(registry);
+ }
+ }
+
+ MetaData meta = (MetaData) this.namespace2metadata.get(namespaceUri);
+ if (meta == null) {
+ meta = new SourceNodeMetaData(namespaceUri, this, this.manager);
+ this.namespace2metadata.put(namespaceUri, meta);
+ }
+ return meta;
+ }
+
+ private Map namespace2metamap = null;
+
+ protected Map getMetaDataMap(String namespaceUri) throws RepositoryException {
+ if (this.namespace2metamap == null) {
+ loadMetaData();
+ }
+ Map map = (Map) this.namespace2metamap.get(namespaceUri);
+ if (map == null) {
+ map = new HashMap();
+ this.namespace2metamap.put(namespaceUri, map);
+ }
+ return map;
+ }
+
+ protected static final String META_DATA_NAMESPACE = "http://apache.org/lenya/metadata/1.0";
+ protected static final String ELEMENT_METADATA = "metadata";
+ protected static final String ELEMENT_SET = "element-set";
+ protected static final String ELEMENT_ELEMENT = "element";
+ protected static final String ELEMENT_VALUE = "value";
+ protected static final String ATTRIBUTE_NAMESPACE = "namespace";
+ protected static final String ATTRIBUTE_KEY = "key";
+
+ protected void loadMetaData() throws RepositoryException {
+
+ if (this.namespace2metamap != null) {
+ throw new IllegalStateException("The meta data have already been loaded!");
+ }
+
+ try {
+ this.namespace2metamap = new HashMap();
+ Document xml = SourceUtil.readDOM(getMetaSourceURI(), this.manager);
+ NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", xml);
+ Element[] setElements = helper.getChildren(xml.getDocumentElement(), ELEMENT_SET);
+ for (int setIndex = 0; setIndex < setElements.length; setIndex++) {
+ String namespace = setElements[setIndex].getAttribute(ATTRIBUTE_NAMESPACE);
+ Element[] elementElements = helper.getChildren(setElements[setIndex],
+ ELEMENT_ELEMENT);
+ for (int elemIndex = 0; elemIndex < elementElements.length; elemIndex++) {
+ String key = elementElements[elemIndex].getAttribute(ATTRIBUTE_KEY);
+ Element[] valueElements = helper.getChildren(elementElements[elemIndex],
+ ELEMENT_VALUE);
+ for (int valueIndex = 0; valueIndex < valueElements.length; valueIndex++) {
+ String value = DocumentHelper.getSimpleElementText(valueElements[valueIndex]);
+ addValue(namespace, key, value);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected void saveMetaData() throws RepositoryException {
+ try {
+ NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", ELEMENT_METADATA);
+ Collection namespaces = this.namespace2metamap.keySet();
+ for (Iterator i = namespaces.iterator(); i.hasNext();) {
+ String namespace = (String) i.next();
+
+ Element setElement = helper.createElement(ELEMENT_SET);
+ setElement.setAttribute(ATTRIBUTE_NAMESPACE, namespace);
+ helper.getDocument().getDocumentElement().appendChild(setElement);
+
+ Map map = getMetaDataMap(namespace);
+ Collection keys = map.keySet();
+ for (Iterator keyIterator = keys.iterator(); keyIterator.hasNext();) {
+ String key = (String) keyIterator.next();
+
+ Element elementElement = helper.createElement(ELEMENT_ELEMENT);
+ elementElement.setAttribute(ATTRIBUTE_KEY, key);
+ setElement.appendChild(elementElement);
+
+ List values = (List) map.get(key);
+ for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
+ String value = (String) valueIterator.next();
+ Element valueElement = helper.createElement(ELEMENT_VALUE, value);
+ elementElement.appendChild(valueElement);
+ }
+ }
+ }
+ SourceUtil.writeDOM(helper.getDocument(), getMetaSourceURI(), this.manager);
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected String[] getValues(String namespaceUri, String key) throws RepositoryException {
+ List values = getValueList(namespaceUri, key);
+ return (String[]) values.toArray(new String[values.size()]);
+ }
+
+ protected List getValueList(String namespaceUri, String key) throws RepositoryException {
+ Map map = getMetaDataMap(namespaceUri);
+ List values = (List) map.get(key);
+ if (values == null) {
+ values = new ArrayList();
+ map.put(key, values);
+ }
+ return values;
+ }
+
+ protected void addValue(String namespaceUri, String key, String value) throws RepositoryException {
+ List values = getValueList(namespaceUri, key);
+ values.add(value);
+ saveMetaData();
+ }
+
+ protected void removeAllValues(String namespaceUri, String key) throws RepositoryException {
+ List values = getValueList(namespaceUri, key);
+ values.clear();
+ saveMetaData();
}
}
Added: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java (added)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java Thu Jul 20 00:56:53 2006
@@ -0,0 +1,174 @@
+/*
+ * 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.repository;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.metadata.Element;
+import org.apache.lenya.cms.metadata.ElementSet;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataRegistry;
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * Source-node-based meta data.
+ */
+public class SourceNodeMetaData extends AbstractLogEnabled implements MetaData {
+
+ private String namespaceUri;
+ private ServiceManager manager;
+ private SourceNode node;
+
+ public SourceNodeMetaData(String namespaceUri, SourceNode node, ServiceManager manager) {
+ this.namespaceUri = namespaceUri;
+ this.node = node;
+ this.manager = manager;
+ }
+
+ private ElementSet elementSet;
+
+ protected ElementSet getElementSet() throws DocumentException {
+ if (this.elementSet == null) {
+ try {
+ MetaDataRegistry registry = (MetaDataRegistry) this.manager.lookup(MetaDataRegistry.ROLE);
+ this.elementSet = registry.getElementSet(this.namespaceUri);
+ } catch (ServiceException e) {
+ throw new DocumentException(e);
+ }
+
+ }
+ return this.elementSet;
+ }
+
+ public String[] getValues(String key) throws DocumentException {
+ checkKey(key);
+ try {
+ return this.node.getValues(this.namespaceUri, key);
+ } catch (RepositoryException e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ public String getFirstValue(String key) throws DocumentException {
+ checkKey(key);
+ String[] values = getValues(key);
+ if (values.length == 0) {
+ return null;
+ } else {
+ return values[0];
+ }
+ }
+
+ public String[] getAvailableKeys() {
+ Element[] elements;
+ try {
+ elements = getElementSet().getElements();
+ } catch (DocumentException e) {
+ throw new RuntimeException(e);
+ }
+ String[] keys = new String[elements.length];
+ for (int i = 0; i < elements.length; i++) {
+ keys[i] = elements[i].getName();
+ }
+ return keys;
+ }
+
+ protected void checkKey(String key) throws DocumentException {
+ if (!isValidAttribute(key)) {
+ throw new DocumentException("The meta data element set ["
+ + getElementSet().getNamespaceUri() + "] does not support the key [" + key
+ + "]!");
+ }
+ }
+
+ public void setValue(String key, String value) throws DocumentException {
+ checkKey(key);
+ try {
+ this.node.removeAllValues(this.namespaceUri, key);
+ addValue(key, value);
+ } catch (RepositoryException e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ public void addValue(String key, String value) throws DocumentException {
+ checkKey(key);
+ try {
+ this.node.addValue(this.namespaceUri, key, value);
+ } catch (RepositoryException e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ public void replaceBy(MetaData other) throws DocumentException {
+ Element[] elements = getElementSet().getElements();
+ for (int i = 0; i < elements.length; i++) {
+ String key = elements[i].getName();
+ String[] values = other.getValues(key);
+ removeAllValues(key);
+ for (int j = 0; j < values.length; j++) {
+ addValue(key, values[j]);
+ }
+ }
+ }
+
+ public String[] getPossibleKeys() {
+ return getAvailableKeys();
+ }
+
+ public HashMap getAvailableKey2Value() {
+ HashMap map = new HashMap();
+ try {
+ Element[] elements = getElementSet().getElements();
+ for (int i = 0; i < elements.length; i++) {
+ String key = elements[i].getName();
+ String[] values = getValues(key);
+ map.put(key, Arrays.asList(values));
+ }
+ } catch (DocumentException e) {
+ throw new RuntimeException(e);
+ }
+ return map;
+ }
+
+ public boolean isValidAttribute(String key) {
+ return Arrays.asList(getAvailableKeys()).contains(key);
+ }
+
+ public long getLastModified() throws DocumentException {
+ try {
+ return this.node.getLastModified();
+ } catch (RepositoryException e) {
+ throw new DocumentException(e);
+ }
+ }
+
+ public void removeAllValues(String key) throws DocumentException {
+ checkKey(key);
+ try {
+ this.node.removeAllValues(this.namespaceUri, key);
+ } catch (RepositoryException e) {
+ throw new DocumentException(e);
+ }
+ }
+
+}
Modified: lenya/trunk/src/modules/sourcerepository/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/module.xml?rev=423814&r1=423813&r2=423814&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/module.xml (original)
+++ lenya/trunk/src/modules/sourcerepository/module.xml Thu Jul 20 00:56:53 2006
@@ -19,6 +19,8 @@
<module xmlns="http://apache.org/lenya/module/1.0">
<id>org.apache.lenya.modules.sourcerepository</id>
+ <depends module="org.apache.lenya.modules.ac-impl"/>
+ <depends module="org.apache.lenya.modules.usecase-impl"/>
<package>org.apache.lenya.modules</package>
<version>0.1-dev</version>
<name>Repository Module</name>
Added: lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadata.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadata.xconf?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadata.xconf (added)
+++ lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadata.xconf Thu Jul 20 00:56:53 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon" unless="/cocoon/meta-data">
+
+ <meta-data>
+ <component-instance name="http://purl.org/dc/elements/1.1/"
+ class="org.apache.lenya.cms.metadata.ConfigurableElementSet">
+
+ <element name="title" multiple="false"/>
+
+ </component-instance>
+ </meta-data>
+
+ </xconf>
Added: lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadataregistry.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadataregistry.xconf?rev=423814&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadataregistry.xconf (added)
+++ lenya/trunk/src/webapp/lenya/config/cocoon-xconf/misc/metadataregistry.xconf Thu Jul 20 00:56:53 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.cms.metadata.MetaDataRegistry']">
+ <component role="org.apache.lenya.cms.metadata.MetaDataRegistry"
+ logger="lenya.cocoon.components"
+ class="org.apache.lenya.cms.metadata.MetaDataRegistryImpl"/>
+ </xconf>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org