Modified:
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/test/org/apache/lenya/cms/metadata/MetaDataTest.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java
lenya/trunk/src/modules-core/workflow-impl/config/cocoon-xconf/workflow-metadata.xconf
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
Modified:
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?view=diff&rev=447411&r1=447410&r2=447411
==============================================================================
---
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
(original)
+++
lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
Mon Sep 18 07:30:28 2006
@@ -48,7 +48,27 @@
String name = attributeConfigs[i].getAttribute("name");
boolean isMultiple =
attributeConfigs[i].getAttributeAsBoolean("multiple", false);
boolean isEditable =
attributeConfigs[i].getAttributeAsBoolean("editable", false);
- this.elements.put(name, new ElementImpl(name, isMultiple,
isEditable));
+ String actionOnCopy = attributeConfigs[i].getAttribute("onCopy",
"copy");
+ ElementImpl element = new ElementImpl(name, isMultiple,
isEditable);
+ int action;
+ if (actionOnCopy.equalsIgnoreCase("copy")) {
+ action = Element.ONCOPY_COPY;
+ }
+ else if (actionOnCopy.equalsIgnoreCase("ignore")) {
+ action = Element.ONCOPY_IGNORE;
+ }
+ else if (actionOnCopy.equalsIgnoreCase("delete")) {
+ action = Element.ONCOPY_DELETE;
+ }
+ else {
+ throw new ConfigurationException("The action [" + actionOnCopy + "]
is not supported.");
+ }
+ try {
+ element.setActionOnCopy(action);
+ } catch (MetaDataException e) {
+ throw new RuntimeException(e);
+ }
+ this.elements.put(name, element);
}
}
Modified:
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?view=diff&rev=447411&r1=447410&r2=447411
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
(original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
Mon Sep 18 07:30:28 2006
@@ -42,11 +42,11 @@
* Ctor.
* @param name The name.
* @param isMultiple if the element can have multiple values.
+ * @param isEditable if the element can be edited.
* @param description The description of the element.
*/
- public ElementImpl(String name, boolean isMultiple, String description) {
- this.name = name;
- this.multiple = isMultiple;
+ public ElementImpl(String name, boolean isMultiple, boolean isEditable,
String description) {
+ this(name, isMultiple, isEditable);
this.description = description;
}
@@ -64,6 +64,20 @@
public boolean isEditable() {
return this.editable;
+ }
+
+ private int actionOnCopy;
+
+ public int getActionOnCopy() {
+ return this.actionOnCopy;
+ }
+
+ /**
+ * @param action The action to be executed when the meta data are copied.
+ * @throws MetaDataException if the action is not supported.
+ */
+ public void setActionOnCopy(int action) throws MetaDataException {
+ this.actionOnCopy = action;
}
}
Modified:
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?view=diff&rev=447411&r1=447410&r2=447411
==============================================================================
--- lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
(original)
+++ lenya/trunk/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
Mon Sep 18 07:30:28 2006
@@ -16,9 +16,13 @@
*/
package org.apache.lenya.cms.metadata;
+import java.util.Map;
+
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.lenya.ac.impl.AbstractAccessControlTest;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.publication.Publication;
@@ -52,12 +56,12 @@
namespaceUri = DublinCore.DC_NAMESPACE;
MetaData dc = doc.getMetaData(namespaceUri);
-
+
doc.getRepositoryNode().lock();
-
+
checkSetTitle(dc);
checkRemoveAllValues(dc);
-
+
}
protected void checkSetTitle(MetaData dc) throws MetaDataException {
@@ -69,7 +73,7 @@
}
assertNotNull(e);
dc.setValue("title", "This is the title");
-
+
e = null;
// addValue() should throw an exception because a value is already set
try {
@@ -78,12 +82,113 @@
e = e1;
}
assertNotNull(e);
+
+ }
+
+ String NAMESPACE = "http://apache.org/lenya/test/metadata";
+
+ protected void checkOnCopy(Publication pub) throws Exception {
+ MetaDataRegistry registry = null;
+ try {
+ registry = (MetaDataRegistry)
getManager().lookup(MetaDataRegistry.ROLE);
+ ElementSet set = new TestElementSet();
+ registry.register(NAMESPACE, set);
+ }
+ finally {
+ getManager().release(registry);
+ }
+
+ DocumentFactory factory = getFactory();
+ Document source = factory.get(pub, Publication.AUTHORING_AREA, "/index",
"en");
+ Document target = factory.get(pub, Publication.AUTHORING_AREA, "/index",
"en");
+
+ MetaData sourceMeta = source.getMetaData(NAMESPACE);
+ sourceMeta.setValue("copy", "sourceCopy");
+ sourceMeta.setValue("ignore", "sourceIgnore");
+ sourceMeta.setValue("delete", "sourceDelete");
+
+ MetaData targetMeta = target.getMetaData(NAMESPACE);
+ targetMeta.setValue("ignore", "targetIgnore");
+ targetMeta.setValue("delete", "targetDelete");
+
+ targetMeta.replaceBy(sourceMeta);
+
+ assertTrue(targetMeta.getValues("copy").length == 1);
+ assertEquals(sourceMeta.getValues("copy"),
targetMeta.getValues("copy"));
+ assertTrue(targetMeta.getValues("ignore").length == 1);
+ assertEquals(targetMeta.getFirstValue("ignore"), "targetIgnore");
+
+ assertTrue(targetMeta.getValues("delete").length == 0);
}
protected void checkRemoveAllValues(MetaData dc) throws MetaDataException {
dc.removeAllValues("title");
assertTrue(dc.getValues("title").length == 0);
}
-
+
+ protected class TestElement implements Element {
+
+ private String name;
+ private int actionOnCopy;
+
+ protected TestElement(String name, int actionOnCopy) {
+ this.name = name;
+ this.actionOnCopy = actionOnCopy;
+ }
+
+ public int getActionOnCopy() {
+ return actionOnCopy;
+ }
+
+ public String getDescription() {
+ return "";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isEditable() {
+ return false;
+ }
+
+ public boolean isMultiple() {
+ return false;
+ }
+
+ }
+
+ protected class TestElementSet implements ElementSet {
+
+ private Element[] elements = { new TestElement("copy",
Element.ONCOPY_COPY),
+ new TestElement("ignore", Element.ONCOPY_IGNORE),
+ new TestElement("delete", Element.ONCOPY_DELETE) };
+
+ private Map name2element;
+
+ protected TestElementSet() {
+ for (int i = 0; i < elements.length; i++) {
+ this.name2element.put(elements[i].getName(), elements[i]);
+ }
+ }
+
+ public boolean containsElement(String name) {
+ return true;
+ }
+
+ public Element getElement(String name) throws MetaDataException {
+ return (Element) this.name2element.get(name);
+ }
+
+ public Element[] getElements() {
+ return elements;
+ }
+
+ public String getNamespaceUri() {
+ return NAMESPACE;
+ }
+
+ }
+
}
Modified: 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?view=diff&rev=447411&r1=447410&r2=447411
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/Element.java Mon Sep 18
07:30:28 2006
@@ -20,25 +20,45 @@
* 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();
-
+
/**
* @return if the element value can be edited.
*/
boolean isEditable();
+
+ /**
+ * Copy all values if the meta data are copied.
+ */
+ int ONCOPY_COPY = 0;
+
+ /**
+ * Don't copy the values of this element if the meta data are copied.
+ */
+ int ONCOPY_IGNORE = 1;
+
+ /**
+ * Delete all values of this element if the meta data are copied.
+ */
+ int ONCOPY_DELETE = 2;
+
+ /**
+ * @return The action to be taken when meta data are copied from one owner
to another.
+ */
+ int getActionOnCopy();
}
Modified:
lenya/trunk/src/modules-core/workflow-impl/config/cocoon-xconf/workflow-metadata.xconf
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow-impl/config/cocoon-xconf/workflow-metadata.xconf?view=diff&rev=447411&r1=447410&r2=447411
==============================================================================
---
lenya/trunk/src/modules-core/workflow-impl/config/cocoon-xconf/workflow-metadata.xconf
(original)