Author: xlawrence
Date: Thu Sep 27 14:55:45 2007
New Revision: 18693
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18693&repname=
=3Djahia
Log:
adapt listener for SP BRANCH
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/li=
steners/CopyPropertyToSubObjectsListener.java
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/web=
dav/listeners/CopyPropertyToSubObjectsListener.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/webdav/listeners/CopyPropertyToSub=
ObjectsListener.java&rev=3D18693&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/li=
steners/CopyPropertyToSubObjectsListener.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/li=
steners/CopyPropertyToSubObjectsListener.java Thu Sep 27 14:55:45 2007
@@ -26,10 +26,9 @@
import org.apache.slide.event.ContentEvent;
import org.apache.slide.event.ContentListener;
import org.apache.slide.event.VetoException;
-import org.apache.slide.store.Store;
import org.apache.slide.webdav.util.WebdavUtils;
+import org.apache.slide.store.Store;
import org.jahia.data.events.JahiaEventListener;
-import org.jahia.engines.filemanager.DAVFilemanager_Engine;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.sites.JahiaSite;
import org.jahia.services.webdav.DAVFileAccess;
@@ -37,7 +36,8 @@
import java.util.*;
=
/**
- * A WebDAV listener that copies property values to sub-objects if option =
is activated
+ * A WebDAV listener that copies property values to sub-objects if option =
is activated. Only properties having the GED:
+ * namespace will be copied. Others will be ignored.
*
* @author Xavier Lawrence
* @version 1.0
@@ -74,45 +74,43 @@
parentProperties =3D parentDav.getProperties();
}
final NodeRevisionDescriptor childRevDesc =3D contentEvent.get=
RevisionDescriptor();
- final Enumeration childProperties =3D childRevDesc.enumeratePr=
opertiesName();
- final Enumeration changed =3D childRevDesc.enumerateUpdatedPro=
perties();
- while (changed.hasMoreElements()) {
- logger.debug("Name: " + ((NodeProperty)changed.nextElement=
()).getName());
- }
=
final Set allProperties =3D new HashSet();
final Iterator parentKeys =3D parentProperties.keySet().iterat=
or();
while (parentKeys.hasNext()) {
allProperties.add(parentKeys.next());
}
+
+ final Enumeration childProperties =3D childRevDesc.enumerateUp=
datedProperties();
while (childProperties.hasMoreElements()) {
- allProperties.add(childProperties.nextElement());
+ final NodeProperty p =3D (NodeProperty) childProperties.ne=
xtElement();
+ allProperties.add(p.getNamespace() + p.getName());
}
=
- final Iterator iterator =3D allProperties.iterator();
// Contains the property names of all modified properties. See=
DAVFileAccess#setPropertyNoEvents
final NodeProperty updatedProperties =3D childRevDesc.getPrope=
rty("updatedProperties", "DAV:");
+
+ final Iterator iterator =3D allProperties.iterator();
while (iterator.hasNext()) {
final String key =3D (String) iterator.next();
- // We are only dealing with checkboxes that are used to co=
py the value of the corresponding property
- // in the DAV sub-tree
- if (key.endsWith(DAVFilemanager_Engine.COPY_VALUE_TO_CHILD=
REN)) {
+ // Only copy the properties that have the GED_NAMESPACE
+ if (key.startsWith(DAVFileAccess.GED_NAMESPACE)) {
NodeProperty prop =3D (NodeProperty) parentProperties.=
get(key);
- if (prop =3D=3D null) prop =3D childRevDesc.getPropert=
y(key, "GED:");
+ if (prop =3D=3D null) prop =3D childRevDesc.getPropert=
y(key.substring(DAVFileAccess.GED_NAMESPACE.length()),
+ DAVFileAccess.GED_NAMESPACE);
if (prop !=3D null) {
if (updatedProperties !=3D null) {
final Set updatedPropertiesNames =3D (Set) upd=
atedProperties.getValue();
logger.debug("updatedPropertiesNames: " + upda=
tedPropertiesNames);
// In case "off" is the value, the user has ex=
plicitly unchecked the checkbox thus
// cutting the inheritance of the propagation =
of the value. We just do nothing
- if (updatedPropertiesNames.contains(prop.getNa=
mespace()+prop.getName()) &&
- ! "off".equals(prop.getValue())) {
+ if (updatedPropertiesNames.contains(prop.getNa=
mespace() + prop.getName())) {
logger.debug("--> Handling property: " + k=
ey);
setPropertyForObject(childRevDesc,
childUri,
token,
nameSpace,
- prop.getNamespace(),
+ DAVFileAccess.GED_NAMESPACE,
prop.getName(),
parentProperties,
true);
@@ -127,7 +125,7 @@
if (updatedProperties !=3D null) {
// Once the update is done, erase the updatedProperties Se=
t so we don't do the same thing again
// in case the user goes back into the engine and clicks OK
- Enumeration updateProperties =3D childRevDesc.enumerateUpd=
atedProperties();
+ // Enumeration updateProperties =3D childRevDesc.enumerate=
UpdatedProperties();
childRevDesc.setProperty("updatedProperties", "DAV:", null=
);
// This is automatically done later too
//childUri.getStore().storeRevisionDescriptor(childUri, ch=
ildRevDesc);
@@ -158,22 +156,19 @@
final Iterator ite =3D parentProperties.keySet().iterator();
while (ite.hasNext()) {
final String key =3D (String) ite.next();
- if (key.endsWith(DAVFilemanager_Engine.COPY_VALUE_TO_CHILD=
REN)) {
- final NodeProperty prop =3D (NodeProperty) parentPrope=
rties.get(key);
+ // Only copy the properties that have the GED_NAMESPACE
+ if (key.startsWith(DAVFileAccess.GED_NAMESPACE)) {
+ final NodeProperty prop =3D (NodeProperty) parentPrope=
rties.get(key);
if (prop !=3D null) {
- if ("on".equals(prop.getValue())) {
- logger.debug("--> Handling property: " + key);
- setPropertyForObject(childRevDesc,
- childUri,
- token,
- nameSpace,
- prop.getNamespace(),
- prop.getName(),
- parentProperties,
- true);
- } else {
- logger.debug("=3D=3D=3D=3D Ignoring property: =
" + key);
- }
+ logger.debug("--> Handling property: " + key);
+ setPropertyForObject(childRevDesc,
+ childUri,
+ token,
+ nameSpace,
+ prop.getNamespace(),
+ prop.getName(),
+ parentProperties,
+ true);
}
}
}
@@ -197,15 +192,108 @@
/**
* Recursive method that copies a given value to the sub-tree of the s=
tarting point
*
- * @param childDescriptor The current DAV object we are handling
- * @param childUri The uri of the current DAV object we are handling
- * @param token The SlideToken
- * @param nameSpace The current nameSpace
- * @param propNameSpace The DAV property NameSpace we want to propagat=
e in the sub-tree
- * @param checkboxPropertyName The DAV checkbox property we want to pr=
opagate in the sub-tree
+ * @param childDescriptor The current DAV object we are handling
+ * @param childUri The uri of the current DAV object we are ha=
ndling
+ * @param token The SlideToken
+ * @param nameSpace The current nameSpace
+ * @param propNameSpace The DAV property NameSpace we want to propa=
gate in the sub-tree
+ * @param propertyName The DAV property we want to propagate in th=
e sub-tree
* @param parentProperties The DAV properties of the parent collection=
of the current DAV object we are handling
- * @param startingPoint TRUE is the current DAV object is the starting=
point of the recursion
+ * @param startingPoint TRUE is the current DAV object is the start=
ing point of the recursion
+ * @throws Exception If something goes wrong
+ */
+ protected void setPropertyForSubTree(NodeRevisionDescriptor childDescr=
iptor,
+ Uri childUri,
+ SlideToken token,
+ Namespace nameSpace,
+ final String propNameSpace,
+ final String propertyName,
+ Map parentProperties,
+ final boolean startingPoint)
+ throws Exception {
+ logger.debug("!!!!! setPropertyForSubTree: " + propertyName + ": "=
+ childUri);
+ // The corresponding parent property we want to deal with
+ final NodeProperty parentProp =3D (NodeProperty) parentProperties.=
get(propNameSpace + propertyName);
+ final String parentPropValue;
+ if (parentProp =3D=3D null) {
+ parentPropValue =3D null;
+ } else {
+ parentPropValue =3D (String) parentProp.getValue();
+ }
+
+ // The corresponding child property we want to deal with
+ final NodeProperty childProp =3D childDescriptor.getProperty(prope=
rtyName, propNameSpace);
+ final String childPropValue;
+ if (childProp =3D=3D null) {
+ childPropValue =3D null;
+ } else {
+ childPropValue =3D childProp.getValue().toString();
+ }
+
+ // If we are handling a directory
+ if (WebdavUtils.isCollection(childDescriptor)) {
+ logger.debug("current childPropValue: " + childPropValue);
+ // Case where we are processing a sub-directory which is not t=
he entry point
+ // Its value can be null if the user has never edited its prop=
erties through the engine.
+ // In any case, we use the value of the parent collection and =
set it to the current object
+ if (! startingPoint) {
+ logger.debug("childPropValue: " + childPropValue);
+ logger.debug("parentPropValue: " + parentPropValue);
+ if (! ((childPropValue =3D=3D null && parentPropValue =3D=
=3D null) ||
+ (childPropValue !=3D null && childPropValue.equals=
(parentPropValue)))) {
+ // Let's set the property for the current object. Now =
we need to deal with the children
+ logger.debug("Collection: Setting Prop: " + propertyNa=
me + "=3D" + parentPropValue);
+ childDescriptor.setProperty(propertyName, propNameSpac=
e, parentPropValue);
+ childUri.getStore().storeRevisionDescriptor(childUri, =
childDescriptor);
+ }
+ }
+ final Store store =3D childUri.getStore();
+ final Enumeration children =3D store.retrieveObject(childUri).=
enumerateChildren();
+ // In case the collection has children, we have to go down and=
continue the recursion
+ if (children =3D=3D null || ! children.hasMoreElements()) retu=
rn;
+
+ while (children.hasMoreElements()) {
+ final String path =3D (String) children.nextElement();
+ final Uri uri =3D new Uri(token, nameSpace, path);
+ final NodeRevisionDescriptors descs =3D store.retrieveRevi=
sionDescriptors(uri);
+ final NodeRevisionDescriptor grandChildren =3D store.retri=
eveRevisionDescriptor(uri, descs.getLatestRevision());
+ setPropertyForSubTree(grandChildren,
+ uri,
+ token,
+ nameSpace,
+ propNameSpace,
+ propertyName,
+ getPropertyMap(childDescriptor.enumerateProperties=
()),
+ false);
+ }
+
+ } else {
+ // In case have modified a file, we need to check the parent c=
ollection and copy its value
+ logger.debug("childPropValue: " + childPropValue);
+ logger.debug("parentPropValue: " + parentPropValue);
+ if ((childPropValue =3D=3D null && parentPropValue =3D=3D null=
) ||
+ (childPropValue !=3D null && childPropValue.equals(par=
entPropValue))) {
+ return;
+ }
+ logger.debug("File: Setting Prop: " + propertyName + "=3D" + p=
arentPropValue);
+ childDescriptor.setProperty(propertyName, propNameSpace, paren=
tPropValue);
+ if (!startingPoint) {
+ childUri.getStore().storeRevisionDescriptor(childUri, chil=
dDescriptor);
+ }
+ }
+ }
+
+ /**
+ * Recursive method that copies a given value to the sub-tree of the s=
tarting point
*
+ * @param childDescriptor The current DAV object we are handling
+ * @param childUri The uri of the current DAV object we are ha=
ndling
+ * @param token The SlideToken
+ * @param nameSpace The current nameSpace
+ * @param propNameSpace The DAV property NameSpace we want to propa=
gate in the sub-tree
+ * @param propertyName The DAV checkbox property we want to propag=
ate in the sub-tree
+ * @param parentProperties The DAV properties of the parent collection=
of the current DAV object we are handling
+ * @param startingPoint TRUE is the current DAV object is the start=
ing point of the recursion
* @throws Exception If something goes wrong
*/
protected void setPropertyForObject(NodeRevisionDescriptor childDescri=
ptor,
@@ -213,28 +301,15 @@
SlideToken token,
Namespace nameSpace,
final String propNameSpace,
- final String checkboxPropertyName,
+ final String propertyName,
Map parentProperties,
final boolean startingPoint)
- throws Exception {
- logger.debug("!!!!! setPropertyForObject: " + checkboxPropertyName=
+ ": " + childUri);
- // ie: GED:statuscopytochildren
- final NodeProperty parentCheckBoxProp =3D (NodeProperty) parentPro=
perties.get(propNameSpace + checkboxPropertyName);
- // ie: GED:status
- final String propertyName =3D checkboxPropertyName.substring(0,
- checkboxPropertyName.indexOf(DAVFilemanager_Engine.COPY_VA=
LUE_TO_CHILDREN));
- logger.debug("propertyName is: " + propertyName);
+ throws Exception {
+ logger.debug("!!!!! setPropertyForObject: " + propertyName + ": " =
+ childUri);
=
// The corresponding parent property we want to deal with
final NodeProperty parentProp =3D (NodeProperty) parentProperties.=
get(propNameSpace + propertyName);
=
- final String parentCheckBoxPropValue;
- if (parentCheckBoxProp =3D=3D null) {
- parentCheckBoxPropValue =3D null;
- } else {
- parentCheckBoxPropValue =3D (String) parentCheckBoxProp.getVal=
ue();
- }
-
final String parentPropValue;
if (parentProp =3D=3D null) {
logger.debug(parentProperties);
@@ -254,93 +329,66 @@
=
// If we are handling a directory
if (WebdavUtils.isCollection(childDescriptor)) {
- final NodeProperty childCheckBoxProp =3D childDescriptor.getPr=
operty(checkboxPropertyName, propNameSpace);
- final String childCheckBoxPropValue;
- if (childCheckBoxProp =3D=3D null) {
- childCheckBoxPropValue =3D null;
- } else {
- childCheckBoxPropValue =3D childCheckBoxProp.getValue().to=
String();
+ // Case where we are processing a sub-directory which is not t=
he entry point
+ // Its value can be null if the user has never edited its prop=
erties through the engine.
+ // In any case, we use the value of the parent collection and =
set it to the current object
+ logger.debug("childPropValue: " + childPropValue);
+ logger.debug("parentPropValue: " + parentPropValue);
+// if (! ((childPropValue =3D=3D null && parentPropValue =3D=3D=
null) ||
+// (childPropValue !=3D null && childPropValue.equals(p=
arentPropValue)))) {
+//
+// // Let's set the property for the current object. Now we=
need to deal with the children
+// logger.debug("Collection: Setting Prop: " + propertyName=
+ "=3D" + parentPropValue);
+// childDescriptor.setProperty(propertyName, propNameSpace,=
parentPropValue);
+// if (!startingPoint) {
+// childUri.getStore().storeRevisionDescriptor(childUri=
, childDescriptor);
+// }
+// }
+
+ final Store store =3D childUri.getStore();
+ final Enumeration children =3D store.retrieveObject(childUri).=
enumerateChildren();
+ // In case the collection has children, we have to go down and=
continue the recursion
+ if (children =3D=3D null || ! children.hasMoreElements()) retu=
rn;
+
+ while (children.hasMoreElements()) {
+ final String path =3D (String) children.nextElement();
+ final Uri uri =3D new Uri(token, nameSpace, path);
+ final NodeRevisionDescriptors descs =3D store.retrieveRevi=
sionDescriptors(uri);
+ final NodeRevisionDescriptor grandChildren =3D store.retri=
eveRevisionDescriptor(uri, descs.getLatestRevision());
+ setPropertyForObject(grandChildren,
+ uri,
+ token,
+ nameSpace,
+ propNameSpace,
+ propertyName,
+ getPropertyMap(childDescriptor.enumerateProperties=
()),
+ false);
}
=
- logger.debug("childCheckBoxPropValue: " + childCheckBoxPropVal=
ue);
- logger.debug("parentCheckBoxPropValue: " + parentCheckBoxPropV=
alue);
- // In case "off" is encountered, we stop the recursion as we h=
ave detected a breakPoint in the propagation
- if (! "off".equals(childCheckBoxPropValue)) {
- // When we propagate a value, we set the corresponding che=
ckbox of all the sub-directories
- if (childCheckBoxPropValue =3D=3D null) {
- // Let's set the property for the current object. Now =
we need to deal with the children
- logger.debug("Collection: Setting Prop: " + checkboxPr=
opertyName + "=3D on");
- childDescriptor.setProperty(checkboxPropertyName, prop=
NameSpace, "on");
- if ( !startingPoint ){
- childUri.getStore().storeRevisionDescriptor(childU=
ri, childDescriptor);
- }
- }
- logger.debug("current childPropValue: " + childPropValue);
- // Case where we are processing a sub-directory which is n=
ot the entry point
- // Its value can be null if the user has never edited its =
properties through the engine.
- // In any case, we use the value of the parent collection =
and set it to the current object
- if ("on".equals(parentCheckBoxPropValue) && childCheckBoxP=
ropValue =3D=3D null || ! startingPoint) {
- logger.debug("childPropValue: " + childPropValue);
- logger.debug("parentPropValue: " + parentPropValue);
- if (! ((childPropValue =3D=3D null && parentPropValue =
=3D=3D null) ||
- (childPropValue !=3D null && childPropValue.eq=
uals(parentPropValue)))) {
-
- // Let's set the property for the current object. =
Now we need to deal with the children
- logger.debug("Collection: Setting Prop: " + proper=
tyName + "=3D" + parentPropValue);
- childDescriptor.setProperty(propertyName, propName=
Space, parentPropValue);
- if ( !startingPoint ){
- childUri.getStore().storeRevisionDescriptor(ch=
ildUri, childDescriptor);
- }
- }
- }
- final Store store =3D childUri.getStore();
- final Enumeration children =3D store.retrieveObject(childU=
ri).enumerateChildren();
- // In case the collection has children, we have to go down=
and continue the recursion
- if (children =3D=3D null || ! children.hasMoreElements()) =
return;
-
- while (children.hasMoreElements()) {
- final String path =3D (String) children.nextElement();
- final Uri uri =3D new Uri(token, nameSpace, path);
- final NodeRevisionDescriptors descs =3D store.retrieve=
RevisionDescriptors(uri);
- final NodeRevisionDescriptor grandChildren =3D store.r=
etrieveRevisionDescriptor(uri, descs.getLatestRevision());
- setPropertyForObject(grandChildren,
- uri,
- token,
- nameSpace,
- propNameSpace,
- checkboxPropertyName,
- getPropertyMap(childDescriptor.enumerateProper=
ties()),
- false);
- }
- }
} else {
// In case have modified a file, we need to check the parent c=
ollection and copy its value
- logger.debug("parentCheckBoxPropValue: " + parentCheckBoxPropV=
alue);
- if ("on".equals(parentCheckBoxPropValue)) {
- logger.debug("childPropValue: " + childPropValue);
- logger.debug("parentPropValue: " + parentPropValue);
- if ((childPropValue =3D=3D null && parentPropValue =3D=3D =
null) ||
- (childPropValue !=3D null && childPropValue.equals=
(parentPropValue))) {
- return;
- }
- logger.debug("File: Setting Prop: " + propertyName + "=3D"=
+ parentPropValue);
- childDescriptor.setProperty(propertyName, propNameSpace, p=
arentPropValue);
- if ( !startingPoint ){
- childUri.getStore().storeRevisionDescriptor(childUri, =
childDescriptor);
- }
- }
+ logger.debug("childPropValue: " + childPropValue);
+ logger.debug("parentPropValue: " + parentPropValue);
+ if ((childPropValue =3D=3D null && parentPropValue =3D=3D null=
) ||
+ (childPropValue !=3D null && childPropValue.equals(par=
entPropValue))) {
+ return;
+ }
+ logger.debug("File: Setting Prop: " + propNameSpace + property=
Name + "=3D" + parentPropValue);
+ childDescriptor.setProperty(propertyName, propNameSpace, paren=
tPropValue);
+ childUri.getStore().storeRevisionDescriptor(childUri, childDes=
criptor);
}
}
=
/**
* Simply utility method that takes an Enumeration of DAV Properties a=
nd puts them into a Map.
+ *
* @param en The Enumeration of DAV properties
*/
private Map getPropertyMap(final Enumeration en) {
final Map result =3D new HashMap();
while (en.hasMoreElements()) {
- final NodeProperty prop =3D (NodeProperty)en.nextElement();
- result.put(prop.getNamespace()+prop.getName(), prop);
+ final NodeProperty prop =3D (NodeProperty) en.nextElement();
+ result.put(prop.getNamespace() + prop.getName(), prop);
}
return result;
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list