You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2005/01/03 16:06:06 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util PropertyHelper.java
luetzkendorf 2005/01/03 07:06:06
Modified: src/webdav/server/org/apache/slide/webdav/util
PropertyHelper.java
Log:
support for validation and default values generalized
(the default value stuff is currently only used by some DeltaV methods,
this could be generalized)
Revision Changes Path
1.89 +185 -195 jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java
Index: PropertyHelper.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- PropertyHelper.java 29 Dec 2004 16:39:19 -0000 1.88
+++ PropertyHelper.java 3 Jan 2005 15:06:06 -0000 1.89
@@ -25,15 +25,10 @@
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
-
-import org.apache.slide.authenticate.CredentialsToken;
-import org.apache.slide.common.Domain;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.PropertyName;
import org.apache.slide.common.SlideException;
@@ -45,18 +40,14 @@
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.content.NodeProperty.NamespaceCache;
import org.apache.slide.lock.NodeLock;
-import org.apache.slide.structure.SubjectNode;
import org.apache.slide.util.XMLValue;
import org.apache.slide.webdav.WebdavServletConfig;
import org.apache.slide.webdav.util.properties.LockDiscoveryProperty;
import org.apache.slide.webdav.util.properties.PropertyComputer;
+import org.apache.slide.webdav.util.properties.PropertyDefaultProvider;
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
-import org.apache.slide.webdav.util.resourcekind.Activity;
-import org.apache.slide.webdav.util.resourcekind.DeltavCompliantCollection;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.ResourceKindManager;
-import org.apache.slide.webdav.util.resourcekind.VersionHistory;
-import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -146,200 +137,198 @@
* @post result != null
* @return a list of initial non-transient properties (empty list if none)
*/
- public List createInitialProperties( ResourceKind resourceKind, String resourcePath ) {
-
- Set sp = resourceKind.getSupportedLiveProperties();
- List result = null;
+ public List createInitialProperties(ResourceKind resourceKind, String resourcePath) {
- if( sp == null )
- result = Collections.EMPTY_LIST;
- else {
- result = new ArrayList();
- Iterator i = sp.iterator();
- while( i.hasNext() ) {
- String propName = (String)i.next();
- if( AbstractResourceKind.isComputedProperty(propName) )
- continue;
- Object pvalue = createDefaultValue( propName, resourceKind, resourcePath );
- if (pvalue != null) {
- result.add( new NodeProperty(propName, pvalue) );
- }
- }
- }
- return result;
- }
-
- /**
- * Create a default value for the specified property name and resource
- * kind
- */
- Object createDefaultValue( String propName, ResourceKind resourceKind, String resourcePath ) {
+ List result = new ArrayList();
- String autoVersion =
- Domain.getParameter(I_AUTO_VERSION,
- I_AUTO_VERSION_DEFAULT,
- nsaToken.getUri(sToken, resourcePath).getStore());
-
- String checkoutFork =
- Domain.getParameter(I_CHECKOUT_FORK,
- I_CHECKOUT_FORK_DEFAULT,
- nsaToken.getUri(sToken, resourcePath).getStore());
-
- String checkinFork =
- Domain.getParameter(I_CHECKIN_FORK,
- I_CHECKIN_FORK_DEFAULT,
- nsaToken.getUri(sToken, resourcePath).getStore());
-
- String result = null;
-
- if( P_RESOURCETYPE.equals(propName) ) {
- StringBuffer rtvv = new StringBuffer();
- try {
- if( resourceKind instanceof VersionHistory ) {
- rtvv.append(
- xmlOut.outputString(new Element(E_VERSION_HISTORY, DNSP)) );
- rtvv.append(
- xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
- }
- if( resourceKind instanceof DeltavCompliantCollection ) {
- rtvv.append(
- xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
- }
- if( resourceKind instanceof Activity ) {
- rtvv.append(
- xmlOut.outputString(new Element(E_ACTIVITY, DNSP)) );
- }
- }
- catch( Exception x ) {
- x.printStackTrace();
- }
- result = rtvv.toString();
- }
- else if( P_SUPPORTED_METHOD_SET.equals(propName) ) {
- Iterator i = resourceKind.getSupportedMethods().iterator();
- StringBuffer smsv = new StringBuffer();
- while( i.hasNext() ) {
- String m = (String) i.next();
- Element sm = new Element( E_SUPPORTED_METHOD, DNSP );
- Attribute na = new Attribute( A_NAME, m, DNSP );
- sm.setAttribute( na );
- try {
- smsv.append( xmlOut.outputString(sm) );
- }
- catch( Exception x ) { x.printStackTrace(); }
- }
- result = smsv.toString();
- }
- else if( P_SUPPORTED_LIVE_PROPERTY_SET.equals(propName) ) {
- Iterator i = resourceKind.getSupportedLiveProperties().iterator();
- StringBuffer spsv = new StringBuffer();
- while( i.hasNext() ) {
- String p = (String) i.next();
- Element sp = new Element( E_SUPPORTED_LIVE_PROPERTY, DNSP );
- Element na = new Element( E_NAME, DNSP );
- na.addContent( p );
- sp.addContent( na );
- try {
- spsv.append( xmlOut.outputString(sp) );
- }
- catch( Exception x ) { x.printStackTrace(); }
- }
- result = spsv.toString();
- }
- else if( P_SUPPORTED_REPORT_SET.equals(propName) ) {
- Iterator i = resourceKind.getSupportedReports().iterator();
- StringBuffer srsv = new StringBuffer();
- while( i.hasNext() ) {
- String r = (String) i.next();
- Element sr = new Element( E_SUPPORTED_REPORT, DNSP );
- Element na = new Element( E_NAME, DNSP );
- na.addContent( r );
- sr.addContent( na );
- try {
- srsv.append( xmlOut.outputString(sr) );
- }
- catch( Exception x ) { x.printStackTrace(); }
- }
- result = srsv.toString();
- }
- else if( P_AUTO_VERSION.equals(propName) ) {
-
- XMLValue xmlValue = new XMLValue();
-
- if (autoVersion.length() > 0) {
- xmlValue.add(new Element(autoVersion, DNSP));
- }
-
- if( ! resourceKind.isSupportedPropertyValue(P_AUTO_VERSION, xmlValue) ) {
- Domain.warn( "Auto-version not configured properly; using "
- +E_CHECKOUT_CHECKIN );
- xmlValue = new XMLValue(new Element(E_CHECKOUT_CHECKIN, DNSP));
- }
-
- result = xmlValue.toString();
- }
- else if( P_CHECKOUT_FORK.equals(propName) ) {
-
- XMLValue xmlValue = new XMLValue();
-
- if (checkoutFork.length() > 0) {
- xmlValue.add(new Element(checkoutFork, DNSP));
- }
-
- if( ! resourceKind.isSupportedPropertyValue(P_CHECKOUT_FORK, xmlValue) ) {
- Domain.warn( "Checkout-fork not configured properly; using "
- +E_FORBIDDEN );
- xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
- }
-
- result = xmlValue.toString();
- }
- else if( P_CHECKIN_FORK.equals(propName) ) {
-
- XMLValue xmlValue = new XMLValue();
-
- if (checkinFork.length() > 0) {
- xmlValue.add(new Element(checkinFork, DNSP));
- }
-
- if( ! resourceKind.isSupportedPropertyValue(P_CHECKIN_FORK, xmlValue) ) {
- Domain.warn( "Checkin-fork not configured properly; using "
- +E_FORBIDDEN );
- xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
- }
-
- result = xmlValue.toString();
- }
- else if( P_GETCONTENTLANGUAGE.equals(propName) ) {
- result = "en";
- }
- else if( P_CREATOR_DISPLAYNAME.equals(propName) ) {
- if( sToken != null ) {
- CredentialsToken credToken = sToken.getCredentialsToken();
- if( credToken != null ) {
- result = credToken.getPublicCredentials();
- if (result == null || result.equals("") || result.equals("/")) {
- result = SubjectNode.UNAUTHENTICATED_URI;
+ for(Iterator i = resourceKind.getSupportedLivePropertyNames().iterator(); i.hasNext();) {
+ PropertyName propName = (PropertyName)i.next();
+ if(!resourceKind.isComputedProperty(propName)) {
+ PropertyDefaultProvider defaultProvider =
+ resourceKind.getDefaultProvider(propName);
+ if (defaultProvider != null) {
+ Object pvalue = defaultProvider.createDefaultValue(
+ this.nsaToken, this.sToken, resourceKind, resourcePath);
+ if (pvalue != null) {
+ result.add(new NodeProperty(propName, pvalue));
}
}
}
}
- // REQUIRED properties
- else if( P_PREDECESSOR_SET.equals(propName) ) {
- result = "";
- }
- else if( P_CHECKOUT_SET.equals(propName) ) {
- result = "";
- }
- else if( P_COMMENT.equals(propName) ) {
- result = "";
- }
- else if( P_LABEL_NAME_SET.equals(propName) ) {
- result = "";
- }
return result;
}
+// /**
+// * Create a default value for the specified property name and resource
+// * kind
+// */
+// Object createDefaultValue( String propName, ResourceKind resourceKind, String resourcePath ) {
+//
+// String autoVersion =
+// Domain.getParameter(I_AUTO_VERSION,
+// I_AUTO_VERSION_DEFAULT,
+// nsaToken.getUri(sToken, resourcePath).getStore());
+//
+// String checkoutFork =
+// Domain.getParameter(I_CHECKOUT_FORK,
+// I_CHECKOUT_FORK_DEFAULT,
+// nsaToken.getUri(sToken, resourcePath).getStore());
+//
+// String checkinFork =
+// Domain.getParameter(I_CHECKIN_FORK,
+// I_CHECKIN_FORK_DEFAULT,
+// nsaToken.getUri(sToken, resourcePath).getStore());
+//
+// String result = null;
+//
+// if( P_RESOURCETYPE.equals(propName) ) {
+// StringBuffer rtvv = new StringBuffer();
+// try {
+// if( resourceKind instanceof VersionHistory ) {
+// rtvv.append(
+// xmlOut.outputString(new Element(E_VERSION_HISTORY, DNSP)) );
+// rtvv.append(
+// xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
+// }
+// if( resourceKind instanceof DeltavCompliantCollection ) {
+// rtvv.append(
+// xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
+// }
+// if( resourceKind instanceof Activity ) {
+// rtvv.append(
+// xmlOut.outputString(new Element(E_ACTIVITY, DNSP)) );
+// }
+// }
+// catch( Exception x ) {
+// x.printStackTrace();
+// }
+// result = rtvv.toString();
+// }
+//// else if( P_SUPPORTED_METHOD_SET.equals(propName) ) {
+//// Iterator i = resourceKind.getSupportedMethods().iterator();
+//// StringBuffer smsv = new StringBuffer();
+//// while( i.hasNext() ) {
+//// String m = (String) i.next();
+//// Element sm = new Element( E_SUPPORTED_METHOD, DNSP );
+//// Attribute na = new Attribute( A_NAME, m, DNSP );
+//// sm.setAttribute( na );
+//// try {
+//// smsv.append( xmlOut.outputString(sm) );
+//// }
+//// catch( Exception x ) { x.printStackTrace(); }
+//// }
+//// result = smsv.toString();
+//// }
+//// else if( P_SUPPORTED_LIVE_PROPERTY_SET.equals(propName) ) {
+//// Iterator i = resourceKind.getSupportedLiveProperties().iterator();
+//// StringBuffer spsv = new StringBuffer();
+//// while( i.hasNext() ) {
+//// String p = (String) i.next();
+//// Element sp = new Element( E_SUPPORTED_LIVE_PROPERTY, DNSP );
+//// Element na = new Element( E_NAME, DNSP );
+//// na.addContent( p );
+//// sp.addContent( na );
+//// try {
+//// spsv.append( xmlOut.outputString(sp) );
+//// }
+//// catch( Exception x ) { x.printStackTrace(); }
+//// }
+//// result = spsv.toString();
+//// }
+//// else if( P_SUPPORTED_REPORT_SET.equals(propName) ) {
+//// Iterator i = resourceKind.getSupportedReports().iterator();
+//// StringBuffer srsv = new StringBuffer();
+//// while( i.hasNext() ) {
+//// String r = (String) i.next();
+//// Element sr = new Element( E_SUPPORTED_REPORT, DNSP );
+//// Element na = new Element( E_NAME, DNSP );
+//// na.addContent( r );
+//// sr.addContent( na );
+//// try {
+//// srsv.append( xmlOut.outputString(sr) );
+//// }
+//// catch( Exception x ) { x.printStackTrace(); }
+//// }
+//// result = srsv.toString();
+//// }
+// else if( P_AUTO_VERSION.equals(propName) ) {
+//
+// XMLValue xmlValue = new XMLValue();
+//
+// if (autoVersion.length() > 0) {
+// xmlValue.add(new Element(autoVersion, DNSP));
+// }
+//
+// if( ! resourceKind.isSupportedPropertyValue(P_AUTO_VERSION, xmlValue) ) {
+// Domain.warn( "Auto-version not configured properly; using "
+// +E_CHECKOUT_CHECKIN );
+// xmlValue = new XMLValue(new Element(E_CHECKOUT_CHECKIN, DNSP));
+// }
+//
+// result = xmlValue.toString();
+// }
+// else if( P_CHECKOUT_FORK.equals(propName) ) {
+//
+// XMLValue xmlValue = new XMLValue();
+//
+// if (checkoutFork.length() > 0) {
+// xmlValue.add(new Element(checkoutFork, DNSP));
+// }
+//
+// if( ! resourceKind.isSupportedPropertyValue(P_CHECKOUT_FORK, xmlValue) ) {
+// Domain.warn( "Checkout-fork not configured properly; using "
+// +E_FORBIDDEN );
+// xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
+// }
+//
+// result = xmlValue.toString();
+// }
+// else if( P_CHECKIN_FORK.equals(propName) ) {
+//
+// XMLValue xmlValue = new XMLValue();
+//
+// if (checkinFork.length() > 0) {
+// xmlValue.add(new Element(checkinFork, DNSP));
+// }
+//
+// if( ! resourceKind.isSupportedPropertyValue(P_CHECKIN_FORK, xmlValue) ) {
+// Domain.warn( "Checkin-fork not configured properly; using "
+// +E_FORBIDDEN );
+// xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
+// }
+//
+// result = xmlValue.toString();
+// }
+// else if( P_GETCONTENTLANGUAGE.equals(propName) ) {
+// result = "en";
+// }
+// else if( P_CREATOR_DISPLAYNAME.equals(propName) ) {
+// if( sToken != null ) {
+// CredentialsToken credToken = sToken.getCredentialsToken();
+// if( credToken != null ) {
+// result = credToken.getPublicCredentials();
+// if (result == null || result.equals("") || result.equals("/")) {
+// result = SubjectNode.UNAUTHENTICATED_URI;
+// }
+// }
+// }
+// }
+// // REQUIRED properties
+// else if( P_PREDECESSOR_SET.equals(propName) ) {
+// result = "";
+// }
+// else if( P_CHECKOUT_SET.equals(propName) ) {
+// result = "";
+// }
+// else if( P_COMMENT.equals(propName) ) {
+// result = "";
+// }
+// else if( P_LABEL_NAME_SET.equals(propName) ) {
+// result = "";
+// }
+// return result;
+// }
+
/**
* Create CDATA value.
*/
@@ -551,6 +540,7 @@
Object value = definition.computeValue(this.nsaToken,
revisionDescriptors,
revisionDescriptor,
+ resourceKind,
this.webdavContext);
if (value != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org