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 ju...@apache.org on 2002/08/22 14:49:10 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method CheckoutMethod.java CopyMethod.java GetMethod.java LabelMethod.java PropFindMethod.java
juergen 2002/08/22 05:49:10
Modified: src/webdav/server/org/apache/slide/webdav/method
CheckoutMethod.java CopyMethod.java GetMethod.java
LabelMethod.java PropFindMethod.java
Log:
1) I18N changes for the label header, correct the received encoding.
2) minor import refactoring
Revision Changes Path
1.20 +50 -48 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CheckoutMethod.java
Index: CheckoutMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CheckoutMethod.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- CheckoutMethod.java 12 Aug 2002 12:55:02 -0000 1.19
+++ CheckoutMethod.java 22 Aug 2002 12:49:09 -0000 1.20
@@ -62,30 +62,23 @@
*/
package org.apache.slide.webdav.method;
-import java.io.*;
-import java.util.*;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jdom.Element;
-import org.jdom.Document;
-import org.jdom.Namespace;
-import org.jdom.JDOMException;
-import org.jdom.output.XMLOutputter;
-
+import java.io.IOException;
+import java.util.Iterator;
import org.apache.slide.common.Domain;
-import org.apache.slide.common.SlideException;
import org.apache.slide.common.NamespaceAccessToken;
-import org.apache.slide.webdav.WebdavServletConfig;
+import org.apache.slide.common.SlideException;
+import org.apache.slide.util.Configuration;
import org.apache.slide.webdav.WebdavException;
-import org.apache.slide.webdav.util.VersioningHelper;
+import org.apache.slide.webdav.WebdavServletConfig;
import org.apache.slide.webdav.util.DeltavConstants;
-import org.apache.slide.webdav.util.ViolatedPrecondition;
-import org.apache.slide.webdav.util.PreconditionViolationException;
import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
-import org.apache.slide.util.Configuration;
+import org.apache.slide.webdav.util.PreconditionViolationException;
+import org.apache.slide.webdav.util.VersioningHelper;
+import org.apache.slide.webdav.util.ViolatedPrecondition;
+import org.apache.slide.webdav.util.WebdavUtils;
import org.apache.util.WebdavStatus;
+import org.jdom.Element;
+import org.jdom.JDOMException;
/**
* CHECKOUT method.
@@ -93,26 +86,26 @@
* @author <a href="mailto:ralf.stuckert@softwareag.com">Ralf Stuckert</a>
*/
public class CheckoutMethod extends AbstractWebdavMethod implements DeltavConstants {
-
+
/** Resource to be written. */
private String resourcePath;
-
+
/** Marshalling variables */
private boolean applyToVersion = false;
private boolean forkOk = false;
-
+
/**
* The VersioningHelper used by this instance.
*/
protected VersioningHelper versioningHelper = null;
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Constructor.
- *
+ *
* @param token the token for accessing the namespace
* @param config configuration of the WebDAV servlet
*/
@@ -120,37 +113,42 @@
WebdavServletConfig config) {
super(token, config);
}
-
+
/**
* Parse WebDAV XML query.
*
* @throws WebdavException
*/
protected void parseRequest() throws WebdavException {
-
+
resourcePath = requestUri;
if (resourcePath == null) {
resourcePath = "/";
}
-
+
versioningHelper =
VersioningHelper.getVersioningHelper(slideToken, token, req, resp,
config);
-
+
// evaluate "Label" header
if (Configuration.useVersionControl()) {
try {
- applyToVersion = (req.getHeader(DeltavConstants.H_LABEL) != null);
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ String labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
+
+ applyToVersion = (labelHeader != null);
+
resourcePath = versioningHelper.getLabeledResourceUri(resourcePath,
- req.getHeader(DeltavConstants.H_LABEL));
+ labelHeader);
}
catch (LabeledRevisionNotFoundException e) {
ViolatedPrecondition violatedPrecondition =
new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
WebdavStatus.SC_CONFLICT);
try {
- sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
- resourcePath));
+ sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
+ resourcePath));
} catch (IOException ioe) {}
throw new WebdavException(getErrorCode((Exception)e));
}
@@ -160,8 +158,8 @@
throw new WebdavException( statusCode );
}
}
-
-
+
+
if( req.getContentLength() > 0 ) {
readRequestContent();
try{
@@ -174,7 +172,11 @@
while( i.hasNext() ) {
Element e = (Element)i.next();
if ( e.getName().equals(E_APPLY_TO_VERSION) ) {
- if (req.getHeader(DeltavConstants.H_LABEL) != null) {
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ String labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
+
+ if (labelHeader != null) {
ViolatedPrecondition violatedPrecondition =
new ViolatedPrecondition(DeltavConstants.C_MUST_NOT_HAVE_LABEL_AND_APPLY_TO_VERSION,
WebdavStatus.SC_CONFLICT);
@@ -186,9 +188,9 @@
}
if ( e.getName().equals(E_FORK_OK) ) {
forkOk = true;
+ }
}
}
- }
catch (IOException e){
int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
sendError( statusCode, e );
@@ -201,7 +203,7 @@
}
}
}
-
+
/**
* Execute the request.
*
@@ -210,10 +212,10 @@
*/
protected void executeRequest() throws WebdavException, IOException {
String locationValue = null;
-
+
// Prevent dirty reads
slideToken.setForceStoreEnlistment(true);
-
+
try {
locationValue = versioningHelper.checkout( resourcePath, forkOk, applyToVersion );
}
@@ -222,7 +224,7 @@
throw e;
}
catch (Exception e) {
- int statusCode = getErrorCode(e);
+ int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
@@ -233,10 +235,10 @@
resp.setHeader( H_LOCATION, locationValue );
}
}
-
+
}
-
-
+
+
}
1.45 +140 -123 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java
Index: CopyMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- CopyMethod.java 12 Aug 2002 12:55:02 -0000 1.44
+++ CopyMethod.java 22 Aug 2002 12:49:09 -0000 1.45
@@ -63,36 +63,51 @@
package org.apache.slide.webdav.method;
-import java.security.Principal;
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import org.apache.util.WebdavStatus;
-import org.apache.slide.common.*;
-import org.apache.slide.webdav.*;
-import org.apache.slide.macro.*;
-import org.apache.slide.macro.CopyRouteRedirector.CopyRoute;
-import org.apache.slide.lock.*;
-import org.apache.slide.content.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.slide.common.NamespaceAccessToken;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.SlideException;
+import org.apache.slide.content.BranchNotFoundException;
+import org.apache.slide.content.NodeNotVersionedException;
+import org.apache.slide.content.NodeProperty;
+import org.apache.slide.content.NodeRevisionDescriptor;
+import org.apache.slide.content.NodeRevisionDescriptors;
+import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.content.RevisionAlreadyExistException;
+import org.apache.slide.content.RevisionDescriptorNotFoundException;
+import org.apache.slide.content.RevisionNotFoundException;
+import org.apache.slide.lock.ObjectLockedException;
+import org.apache.slide.macro.CopyListener;
+import org.apache.slide.macro.CopyRouteRedirector;
+import org.apache.slide.macro.DeleteListener;
+import org.apache.slide.macro.Macro;
+import org.apache.slide.macro.MacroException;
+import org.apache.slide.macro.MacroParameters;
import org.apache.slide.security.AccessDeniedException;
-import org.apache.slide.structure.*;
+import org.apache.slide.structure.LinkedObjectNotFoundException;
+import org.apache.slide.structure.ObjectNotFoundException;
+import org.apache.slide.util.Configuration;
+import org.apache.slide.webdav.WebdavException;
+import org.apache.slide.webdav.WebdavServletConfig;
+import org.apache.slide.webdav.util.DeltavConstants;
+import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
import org.apache.slide.webdav.util.PreconditionViolationException;
-import org.apache.slide.webdav.util.ViolatedPrecondition;
+import org.apache.slide.webdav.util.PropertyHelper;
import org.apache.slide.webdav.util.UriHandler;
-import org.apache.slide.webdav.util.DeltavConstants;
-import org.apache.slide.webdav.util.XMLValue;
import org.apache.slide.webdav.util.VersioningHelper;
-import org.apache.slide.webdav.util.PropertyHelper;
-import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
-import org.apache.slide.webdav.util.resourcekind.ResourceKind;
+import org.apache.slide.webdav.util.ViolatedPrecondition;
+import org.apache.slide.webdav.util.WebdavUtils;
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
-import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlledImpl;
-import org.apache.slide.webdav.util.resourcekind.DeltavCompliant;
+import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.VersionableImpl;
-import org.apache.slide.util.Configuration;
-
+import org.apache.util.WebdavStatus;
import org.jdom.JDOMException;
/**
@@ -102,48 +117,48 @@
* @author Juergen Pill
*/
public class CopyMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, CopyListener, DeleteListener, CopyRouteRedirector {
-
-
-
+
+
+
/**
* The VersioningHelper used by this instance.
*/
protected VersioningHelper versioningHelper = null;
-
+
/**
* Maps the URI of a destination to its descriptor.
* Used by {@link #beforeCopy beforeCopy()} and {@link #afterCopy afterCopy()}.
*/
protected Map destinationDescriptorMap = new HashMap();
-
+
/**
* Maps the URI of a destination to its backup descriptor.
* Used by {@link #beforeCopy beforeCopy()} and {@link #afterCopy afterCopy()}.
*/
protected Map destinationBackupDescriptorMap = new HashMap();
-
+
/**
* The value of the <code>Label</code> header.
*/
protected String labelHeader = null;
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Constructor.
- *
+ *
* @param token the token for accessing the namespace
* @param config configuration of the WebDAV servlet
*/
public CopyMethod(NamespaceAccessToken token, WebdavServletConfig config) {
super(token, config);
}
-
-
+
+
// ------------------------------------------------------ Protected Methods
-
+
/**
* Parse request.
*
@@ -151,13 +166,15 @@
*/
protected void parseRequest() throws WebdavException {
super.parseRequest();
-
+
versioningHelper =
VersioningHelper.getVersioningHelper(slideToken, token, req, resp,
config);
- labelHeader = req.getHeader(DeltavConstants.H_LABEL);
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
}
-
+
/**
* Execute request.
*
@@ -165,20 +182,20 @@
*/
protected void executeRequest()
throws WebdavException, IOException {
-
+
// Prevent dirty reads
slideToken.setForceStoreEnlistment(true);
-
+
MacroParameters macroParameters = null;
String status = null;
boolean isCollection = isCollection(sourceUri);
-
+
if (overwrite) {
macroParameters = Macro.RECURSIVE_OVERWRITE_PARAMETERS;
} else {
macroParameters = Macro.DEFAULT_PARAMETERS;
}
-
+
// check destination URI
UriHandler destinationUriHandler = UriHandler.getUriHandler(destinationUri);
if (destinationUriHandler.isRestrictedUri()) {
@@ -186,7 +203,7 @@
sendError( statusCode, getClass().getName()+".restrictedDestinationUri", new Object[]{destinationUri} );
throw new WebdavException( statusCode );
}
-
+
try {
macro.copy(slideToken, sourceUri, destinationUri, macroParameters, this, this, null, this);
if (overwrite) {
@@ -235,11 +252,11 @@
//
throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
}
-
+
}
-
-
-
+
+
+
/**
* Get return status based on exception type.
*/
@@ -252,9 +269,9 @@
return super.getErrorCode(e);
}
}
-
+
// ------------------------------------------------------ Interface CopyRouteRedirector
-
+
/**
* Returns the (redirected) CopyRoute to use. Must not be <code>null</code>.
*
@@ -267,12 +284,12 @@
* MacroCopyException).
*/
public CopyRoute getRedirectedCopyRoute(CopyRoute copyRoute) throws SlideException {
-
+
if (Configuration.useVersionControl()) {
-
+
String sourceUri = copyRoute.getSourceUri();
String destinationUri = copyRoute.getDestinationUri();
-
+
try {
sourceUri = versioningHelper.getLabeledResourceUri(sourceUri, labelHeader);
}
@@ -282,15 +299,15 @@
WebdavStatus.SC_CONFLICT);
throw new PreconditionViolationException(violatedPrecondition, sourceUri);
}
-
+
copyRoute = new CopyRoute(sourceUri, destinationUri);
}
-
+
return copyRoute;
}
-
+
// ------------------------------------------------------ Interface CopyListener
-
+
/**
* This method is called prior to copying the resource associated by
* the given <code>sourceUri</code>. The copy can be prohibited by
@@ -305,17 +322,17 @@
*/
public void beforeCopy(String sourceUri, String destinationUri) throws SlideException {
if(Configuration.useVersionControl()) {
-
+
UriHandler uriHandler = UriHandler.getUriHandler(sourceUri);
- if (uriHandler.isHistoryUri()) {
- throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_COPY_HISTORY,
- WebdavStatus.SC_FORBIDDEN),
- sourceUri);
- }
-
+ if (uriHandler.isHistoryUri()) {
+ throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_COPY_HISTORY,
+ WebdavStatus.SC_FORBIDDEN),
+ sourceUri);
+ }
+
}
}
-
+
/**
* This method is called after copying the resource to
* the given <code>destinationUri</code>.
@@ -328,56 +345,56 @@
* MacroDeleteException.
*/
public void afterCopy(String sourceUri, String destinationUri) throws SlideException {
-
+
if(Configuration.useVersionControl()) {
-
+
NodeRevisionDescriptors destinationRevisionDescriptors = content.retrieve( slideToken, destinationUri);
NodeRevisionDescriptor destinationRevisionDescriptor = content.retrieve( slideToken, destinationRevisionDescriptors);
-
+
// restore backup descriptor
restoreBackupRevisionDescriptor(destinationUri, destinationRevisionDescriptors);
-
+
NodeRevisionDescriptor existingDestinationRevisionDescriptor =
(NodeRevisionDescriptor)destinationDescriptorMap.get(destinationUri);
if (existingDestinationRevisionDescriptor != null) {
-
+
// there has been an existing destination, so restore live properties
restoreLiveProperties(destinationRevisionDescriptor, existingDestinationRevisionDescriptor);
- }
+ }
else {
-
+
// DAV:must-not-copy-versioning-property
resetDeltavProperties(destinationRevisionDescriptor);
}
-
- // set <workspace> property
- versioningHelper.setWorkspaceProperty(destinationUri, destinationRevisionDescriptor);
-
- content.store(slideToken, destinationRevisionDescriptors.getUri(), destinationRevisionDescriptor, null);
-
- // checkin if necessary
- boolean mustCheckin = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, destinationRevisionDescriptors, destinationRevisionDescriptor);
- if (mustCheckin) {
- try {
- versioningHelper.checkin(destinationUri, false, false ); //forkOk=false, keepCheckedOut=false
- }
- catch (IOException e) {
- throw new SlideException("Checkin failed: " + e.getMessage());
- }
- catch (JDOMException e) {
- throw new SlideException("Checkin failed: " + e.getMessage());
+
+ // set <workspace> property
+ versioningHelper.setWorkspaceProperty(destinationUri, destinationRevisionDescriptor);
+
+ content.store(slideToken, destinationRevisionDescriptors.getUri(), destinationRevisionDescriptor, null);
+
+ // checkin if necessary
+ boolean mustCheckin = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, destinationRevisionDescriptors, destinationRevisionDescriptor);
+ if (mustCheckin) {
+ try {
+ versioningHelper.checkin(destinationUri, false, false ); //forkOk=false, keepCheckedOut=false
+ }
+ catch (IOException e) {
+ throw new SlideException("Checkin failed: " + e.getMessage());
+ }
+ catch (JDOMException e) {
+ throw new SlideException("Checkin failed: " + e.getMessage());
}
}
-
+
// check if the resource should be put under version-control
if( PutMethod.AUTO_VERSION_CONTROL ) {
versioningHelper.versionControl(destinationUri);
}
-
+
}
-
+
}
-
+
/**
* Restores all live properties that should not be copied.
*
@@ -385,7 +402,7 @@
* @param existingDestinationRevisionDescriptor the descriptor that has been overwritten.
*/
private void restoreLiveProperties(NodeRevisionDescriptor destinationRevisionDescriptor, NodeRevisionDescriptor existingDestinationRevisionDescriptor) {
-
+
// remove all live properties
Enumeration propertyEnum = destinationRevisionDescriptor.enumerateProperties();
NodeProperty property = null;
@@ -395,7 +412,7 @@
destinationRevisionDescriptor.removeProperty(property);
}
}
-
+
// copy all live properties of the existing destination
propertyEnum = existingDestinationRevisionDescriptor.enumerateProperties();
property = null;
@@ -406,7 +423,7 @@
}
}
}
-
+
/**
* Indicates if the given property is a live property to restore.
*
@@ -418,7 +435,7 @@
return (property.isLiveProperty() &&
DeltavConstants.DELTAV_PROPERTY_LIST.contains(property.getName()));
}
-
+
/**
* Sets all DeltaV specific properties of the given NodeRevisionDescriptor
* to their initial value.
@@ -427,7 +444,7 @@
* properties should be reset.
*/
private void resetDeltavProperties(NodeRevisionDescriptor revisionDescriptor) {
-
+
// use initial values for DeltaV properties
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(slideToken, token);
ResourceKind resourceKind = VersionableImpl.getInstance();
@@ -441,7 +458,7 @@
initialDeltavProperties.add(property);
}
}
-
+
Enumeration propertyEnum = revisionDescriptor.enumerateProperties();
property = null;
int index = 0;
@@ -458,7 +475,7 @@
}
}
}
-
+
/**
* Restores the "backup" NodeRevisionDescriptor which has been saved in
* method {@link #beforeDelete beforeDelete()}.
@@ -468,7 +485,7 @@
* the resource.
*/
private void restoreBackupRevisionDescriptor(String destinationUri, NodeRevisionDescriptors destinationRevisionDescriptors) throws RevisionNotFoundException, ServiceAccessException, RevisionAlreadyExistException, ObjectNotFoundException, LinkedObjectNotFoundException, ObjectLockedException, AccessDeniedException, RevisionDescriptorNotFoundException, BranchNotFoundException, NodeNotVersionedException {
-
+
NodeRevisionDescriptor destinationBackupDescriptor =
(NodeRevisionDescriptor)destinationBackupDescriptorMap.get(destinationUri);
if (destinationBackupDescriptor != null) {
@@ -490,10 +507,10 @@
}
}
}
-
-
+
+
// ------------------------------------------------------ Interface DeleteListener
-
+
/**
* This method is called prior to deleting the resource associated by
* the given <code>targetUri</code>. The deletion can be prohibited by
@@ -506,9 +523,9 @@
* MacroDeleteException.
*/
public void beforeDelete(String targetUri) throws SlideException {
-
+
if( Configuration.useVersionControl() ) {
-
+
boolean destinationExists = false;
NodeRevisionDescriptors revisionDescriptors = null;
NodeRevisionDescriptor revisionDescriptor = null;
@@ -518,12 +535,12 @@
destinationExists = true;
}
catch (ObjectNotFoundException e) {}
-
+
if (destinationExists) {
-
+
ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, targetUri, revisionDescriptor);
if (resourceKind instanceof CheckedInVersionControlled) {
-
+
// check precondition DAV:cannot-modify-version-controlled-content
String autoVersion = versioningHelper.getAutoVersionElementName(revisionDescriptor);
if (autoVersion == null) {
@@ -542,19 +559,19 @@
WebdavStatus.SC_FORBIDDEN), targetUri);
}
}
-
+
// check precondition DAV:cannot-modify-version
UriHandler uriHandler = UriHandler.getUriHandler(targetUri);
if (uriHandler.isVersionUri()) {
throw new PreconditionViolationException(new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION,
WebdavStatus.SC_FORBIDDEN), targetUri);
}
-
+
// checkout if necessary
if( Configuration.useVersionControl() &&
(resourceKind instanceof CheckedInVersionControlled) &&
versioningHelper.mustCheckoutAutoVersionedVCR(revisionDescriptors, revisionDescriptor) ) {
-
+
try {
versioningHelper.checkout(revisionDescriptors, revisionDescriptor, false, false, true );
}
@@ -565,7 +582,7 @@
throw new SlideException("Checkout failed: " + e.getMessage());
}
}
-
+
// store the descriptor(s) in order to restore it in afterDelete()
// (the COPY specification for DeltaV says that an existing destination
// must not be deleted)
@@ -580,7 +597,7 @@
}
}
}
-
+
/**
* This method is called after deleting the resource associated by
* the given <code>targetUri</code>.
@@ -592,12 +609,12 @@
* targetUricroDeleteException.
*/
public void afterDelete(String targetUri) throws SlideException {
-
+
}
-
-
-
-
+
+
+
+
}
1.33 +234 -229 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java
Index: GetMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- GetMethod.java 12 Aug 2002 12:55:02 -0000 1.32
+++ GetMethod.java 22 Aug 2002 12:49:09 -0000 1.33
@@ -63,36 +63,38 @@
package org.apache.slide.webdav.method;
-import java.security.Principal;
-import java.io.*;
-import java.util.*;
-import java.text.SimpleDateFormat;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.text.ParseException;
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-import org.jdom.Document;
-import org.jdom.JDOMException;
-
-import org.apache.util.WebdavStatus;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.slide.common.NamespaceAccessToken;
-import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideException;
-import org.apache.slide.content.*;
-import org.apache.slide.lock.ObjectLockedException;
-import org.apache.slide.security.AccessDeniedException;
+import org.apache.slide.content.NodeRevisionDescriptor;
+import org.apache.slide.content.NodeRevisionDescriptors;
+import org.apache.slide.content.RevisionContentNotFoundException;
+import org.apache.slide.content.RevisionDescriptorNotFoundException;
+import org.apache.slide.content.RevisionNotFoundException;
import org.apache.slide.structure.LinkedObjectNotFoundException;
import org.apache.slide.structure.ObjectNode;
-import org.apache.slide.structure.ObjectNotFoundException;
-import org.apache.slide.structure.Structure;
+import org.apache.slide.util.Configuration;
import org.apache.slide.webdav.WebdavException;
import org.apache.slide.webdav.WebdavServletConfig;
-import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.DeltavConstants;
import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
import org.apache.slide.webdav.util.PreconditionViolationException;
+import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.ViolatedPrecondition;
-import org.apache.slide.util.Configuration;
+import org.apache.slide.webdav.util.WebdavUtils;
+import org.apache.util.WebdavStatus;
/**
* GET method.
@@ -100,14 +102,14 @@
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
*/
public class GetMethod extends AbstractWebdavMethod {
-
-
+
+
// -------------------------------------------------------------- Constants
-
-
+
+
protected final int BUFFER_SIZE = 2048;
-
-
+
+
/**
* The set of SimpleDateFormat formats to use in getDateHeader().
*/
@@ -116,63 +118,63 @@
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
};
-
-
+
+
/**
* MIME multipart separation string
*/
protected static final String mimeSeparation = "SLIDE_MIME_BOUNDARY";
-
-
+
+
/**
* The input buffer size to use when serving resources.
*/
protected int input = 2048;
-
-
+
+
/**
* The output buffer size to use when serving resources.
*/
protected int output = 2048;
-
-
+
+
/**
* Print content.
*/
protected boolean printContent = true;
-
+
/**
* The VersioningHelper used by this instance.
*/
protected VersioningHelper vHelp = null;
-
-
+
+
// ----------------------------------------------------- Instance Variables
-
-
+
+
/**
* Resource to be retrieved.
*/
private String resourcePath;
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Constructor.
- *
+ *
* @param token the token for accessing the namespace
* @param config configuration of the WebDAV servlet
*/
public GetMethod(NamespaceAccessToken token, WebdavServletConfig config) {
super(token, config);
}
-
-
+
+
// ------------------------------------------------------ Protected Methods
-
-
+
+
/**
* Parse XML request.
*/
@@ -184,33 +186,36 @@
if (resourcePath == null) {
resourcePath = "/";
}
-
+
// evaluate "Label" header
if (Configuration.useVersionControl()) {
try {
- resourcePath = vHelp.getLabeledResourceUri(resourcePath,
- req.getHeader(DeltavConstants.H_LABEL));
+
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ String labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
+ resourcePath = vHelp.getLabeledResourceUri(resourcePath, labelHeader);
}
catch (LabeledRevisionNotFoundException e) {
ViolatedPrecondition violatedPrecondition =
new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
WebdavStatus.SC_CONFLICT);
try {
- sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
- resourcePath));
+ sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
+ resourcePath));
} catch (IOException ioe) {}
throw new WebdavException( WebdavStatus.SC_CONFLICT );
}
catch (SlideException e) {
- int statusCode = getErrorCode((Exception)e);
+ int statusCode = getErrorCode( (Exception)e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
}
-
+
}
-
-
+
+
/**
* Execute request.
*
@@ -218,73 +223,73 @@
*/
protected void executeRequest()
throws WebdavException {
-
+
try {
-
+
// Then we must get object contents ...
-
+
ObjectNode object = structure.retrieve(slideToken, resourcePath);
NodeRevisionDescriptors revisionDescriptors =
content.retrieve(slideToken, resourcePath);
-
+
if (revisionDescriptors.hasRevisions()) {
-
+
// Retrieve latest revision descriptor
NodeRevisionDescriptor revisionDescriptor =
- content.retrieve(slideToken, revisionDescriptors);
-
+ content.retrieve(slideToken, revisionDescriptors);
+
if (revisionDescriptor != null) {
-
+
ResourceInfo resourceInfo =
new ResourceInfo(resourcePath, revisionDescriptor);
-
+
// Checking If headers
if (!checkIfHeaders(req, resp, resourceInfo))
return;
-
+
ServletOutputStream os = resp.getOutputStream();
InputStream is = null;
-
+
if (printContent) {
is = content.retrieve
(slideToken, revisionDescriptors,
revisionDescriptor).streamContent();
}
-
+
Vector ranges = parseRange(req, resp, resourceInfo);
-
+
// ETag header
resp.setHeader("ETag", getETag(resourceInfo, true));
resp.addHeader
("Last-Modified",
revisionDescriptor.getLastModified().toString());
-
+
if ( ((ranges == null) || (ranges.isEmpty()))
&& (req.getHeader("Range") == null) ) {
-
+
resp.setContentType
(revisionDescriptor.getContentType());
resp.setContentLength
((int) revisionDescriptor.getContentLength());
-
+
// Copy the input stream to our output stream
// (if requested)
if (printContent) {
resp.setBufferSize(output);
copy(resourceInfo, is, os);
}
-
+
} else {
-
+
if ((ranges == null) || (ranges.isEmpty()))
return;
-
+
// Partial content response.
-
+
resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
-
+
if (ranges.size() == 1) {
-
+
Range range = (Range) ranges.elementAt(0);
resp.addHeader("Content-Range", "bytes "
+ range.start
@@ -293,48 +298,48 @@
resp.setContentLength((int) range.length);
resp.setContentType
(revisionDescriptor.getContentType());
-
+
if (printContent) {
resp.setBufferSize(output);
copy(resourceInfo, is, os, range);
}
-
+
} else {
-
+
resp.setContentType
("multipart/byteranges; boundary="
+ mimeSeparation);
-
+
if (printContent) {
resp.setBufferSize(output);
copy(resourceInfo, is, os,
ranges.elements(),
revisionDescriptor.getContentType());
}
-
+
}
-
+
}
-
+
} else {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
-
+
} else {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
-
+
} catch (Exception e) {
- int statusCode = getErrorCode(e);
+ int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
-
+
}
-
-
-
-
+
+
+
+
/**
* Get return status based on exception type.
*/
@@ -353,12 +358,12 @@
return super.getErrorCode(e);
}
}
-
-
-
+
+
+
// -------------------------------------------------------- Private Methods
-
-
+
+
/**
* Check if the conditions specified in the optional If headers are
* satisfied.
@@ -374,29 +379,29 @@
HttpServletResponse response,
ResourceInfo resourceInfo)
throws IOException {
-
+
String eTag = getETag(resourceInfo, true);
long fileLength = resourceInfo.length;
long lastModified = resourceInfo.date;
-
+
StringTokenizer commaTokenizer;
-
+
String headerValue;
-
+
// Checking If-Match
headerValue = request.getHeader("If-Match");
if (headerValue != null) {
if (headerValue.indexOf("*") == -1) {
-
+
commaTokenizer = new StringTokenizer(headerValue, ",");
boolean conditionSatisfied = false;
-
+
while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
String currentToken = commaTokenizer.nextToken();
if (currentToken.trim().equals(eTag))
conditionSatisfied = true;
}
-
+
// If none of the given ETags match, 412 Precodition failed is
// sent back
if (!conditionSatisfied) {
@@ -404,20 +409,20 @@
(HttpServletResponse.SC_PRECONDITION_FAILED);
return false;
}
-
+
}
}
-
+
// Checking If-Modified-Since
headerValue = request.getHeader("If-Modified-Since");
if (headerValue != null) {
-
+
// If an If-None-Match header has been specified, if modified since
// is ignored.
if (request.getHeader("If-None-Match") == null) {
-
+
Date date = null;
-
+
// Parsing the HTTP Date
for (int i = 0; (date == null) && (i < formats.length); i++) {
try {
@@ -428,7 +433,7 @@
;
}
}
-
+
if ((date != null)
&& (lastModified <= (date.getTime() + 1000)) ) {
// The entity has not been modified since the date
@@ -437,27 +442,27 @@
(HttpServletResponse.SC_NOT_MODIFIED);
return false;
}
-
+
}
-
+
}
-
+
// Checking If-None-Match
headerValue = request.getHeader("If-None-Match");
if (headerValue != null) {
if (headerValue.indexOf("*") == -1) {
-
+
commaTokenizer = new StringTokenizer(headerValue, ",");
boolean conditionSatisfied = false;
-
+
while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
String currentToken = commaTokenizer.nextToken();
if (currentToken.trim().equals(eTag))
conditionSatisfied = true;
}
-
+
if (conditionSatisfied) {
-
+
// For GET and HEAD, we should respond with
// 304 Not Modified.
// For every other method, 412 Precondition Failed is sent
@@ -473,20 +478,20 @@
return false;
}
}
-
+
} else {
if (resourceInfo.exists()) {
-
+
}
}
}
-
+
// Checking If-Unmodified-Since
headerValue = request.getHeader("If-Unmodified-Since");
if (headerValue != null) {
-
+
Date date = null;
-
+
// Parsing the HTTP Date
for (int i = 0; (date == null) && (i < formats.length); i++) {
try {
@@ -497,7 +502,7 @@
;
}
}
-
+
if ( (date != null) && (lastModified > date.getTime()) ) {
// The entity has not been modified since the date
// specified by the client. This is not an error case.
@@ -505,13 +510,13 @@
(HttpServletResponse.SC_PRECONDITION_FAILED);
return false;
}
-
+
}
-
+
return true;
}
-
-
+
+
/**
* Get the ETag value associated with a file.
*
@@ -524,8 +529,8 @@
// of the file contents
return resourceInfo.length + "-" + resourceInfo.date;
}
-
-
+
+
/**
* Get the ETag associated with a file.
*
@@ -539,8 +544,8 @@
else
return "W/\"" + getETagValue(resourceInfo, strong) + "\"";
}
-
-
+
+
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
@@ -555,22 +560,22 @@
InputStream resourceInputStream,
ServletOutputStream ostream)
throws IOException {
-
+
IOException exception = null;
-
+
InputStream istream = new BufferedInputStream
(resourceInputStream, input);
-
+
// Copy the input stream to the output stream
exception = copyRange(istream, ostream);
-
+
// Clean up the input and output streams
try {
istream.close();
} catch (Throwable t) {
;
}
-
+
try {
ostream.flush();
} catch (Throwable t) {
@@ -581,14 +586,14 @@
} catch (Throwable t) {
;
}
-
+
// Rethrow any exception that has occurred
if (exception != null)
throw exception;
-
+
}
-
-
+
+
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
@@ -604,13 +609,13 @@
ServletOutputStream ostream,
Range range)
throws IOException {
-
+
IOException exception = null;
-
+
InputStream istream =
new BufferedInputStream(resourceInputStream, input);
exception = copyRange(istream, ostream, range.start, range.end);
-
+
// Clean up the input and output streams
try {
istream.close();
@@ -627,14 +632,14 @@
} catch (Throwable t) {
;
}
-
+
// Rethrow any exception that has occurred
if (exception != null)
throw exception;
-
+
}
-
-
+
+
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
@@ -651,16 +656,16 @@
ServletOutputStream ostream,
Enumeration ranges, String contentType)
throws IOException {
-
+
IOException exception = null;
-
+
while ( (exception == null) && (ranges.hasMoreElements()) ) {
-
+
InputStream istream =
new BufferedInputStream(resourceInputStream, input);
-
+
Range currentRange = (Range) ranges.nextElement();
-
+
// Writing MIME header.
ostream.println("--" + mimeSeparation);
if (contentType != null)
@@ -669,21 +674,21 @@
+ "-" + currentRange.end + "/"
+ currentRange.length);
ostream.println();
-
+
// Printing content
exception = copyRange(istream, ostream, currentRange.start,
currentRange.end);
-
+
try {
istream.close();
} catch (Throwable t) {
;
}
-
+
}
-
+
ostream.print("--" + mimeSeparation + "--");
-
+
// Clean up the output streams
try {
ostream.flush();
@@ -695,14 +700,14 @@
} catch (Throwable t) {
;
}
-
+
// Rethrow any exception that has occurred
if (exception != null)
throw exception;
-
+
}
-
-
+
+
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
@@ -714,7 +719,7 @@
*/
private IOException copyRange(InputStream istream,
ServletOutputStream ostream) {
-
+
// Copy the input stream to the output stream
IOException exception = null;
byte buffer[] = new byte[input];
@@ -732,10 +737,10 @@
}
}
return exception;
-
+
}
-
-
+
+
/**
* Copy the contents of the specified input stream to the specified
* output stream, and ensure that both streams are closed before returning
@@ -750,16 +755,16 @@
private IOException copyRange(InputStream istream,
ServletOutputStream ostream,
long start, long end) {
-
+
try {
istream.skip(start);
} catch (IOException e) {
return e;
}
-
+
IOException exception = null;
long bytesToRead = end - start + 1;
-
+
byte buffer[] = new byte[input];
int len = buffer.length;
while ( (bytesToRead > 0) && (len >= buffer.length)) {
@@ -779,12 +784,12 @@
if (len < buffer.length)
break;
}
-
+
return exception;
-
+
}
-
-
+
+
/**
* Parse the range header.
*
@@ -796,16 +801,16 @@
HttpServletResponse response,
ResourceInfo resourceInfo)
throws IOException {
-
+
// Checking If-Range
String headerValue = request.getHeader("If-Range");
if (headerValue != null) {
-
+
String eTag = getETag(resourceInfo, true);
long lastModified = resourceInfo.date;
-
+
Date date = null;
-
+
// Parsing the HTTP Date
for (int i = 0; (date == null) && (i < formats.length); i++) {
try {
@@ -816,34 +821,34 @@
;
}
}
-
+
if (date == null) {
-
+
// If the ETag the client gave does not match the entity
// etag, then the entire entity is returned.
if (!eTag.equals(headerValue.trim()))
return null;
-
+
} else {
-
+
// If the timestamp of the entity the client got is older than
// the last modification date of the entity, the entire entity
// is returned.
if (lastModified > (date.getTime() + 1000))
return null;
-
+
}
-
+
}
-
+
long fileLength = resourceInfo.length;
-
+
if (fileLength == 0)
return null;
-
+
// Retrieving the range header (if any is specified
String rangeHeader = request.getHeader("Range");
-
+
if (rangeHeader == null)
return null;
// bytes is the only range unit supported (and I don't see the point
@@ -853,32 +858,32 @@
(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return null;
}
-
+
rangeHeader = rangeHeader.substring(6);
-
+
// Vector which will contain all the ranges which are successfully
// parsed.
Vector result = new Vector();
StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");
-
+
// Parsing the range list
while (commaTokenizer.hasMoreTokens()) {
String rangeDefinition = commaTokenizer.nextToken();
-
+
Range currentRange = new Range();
currentRange.length = fileLength;
-
+
int dashPos = rangeDefinition.indexOf('-');
-
+
if (dashPos == -1) {
response.sendError
(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return null;
}
-
+
if (dashPos == 0) {
-
+
try {
long offset = Long.parseLong(rangeDefinition);
currentRange.start = fileLength + offset;
@@ -889,9 +894,9 @@
.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return null;
}
-
+
} else {
-
+
try {
currentRange.start = Long.parseLong
(rangeDefinition.substring(0, dashPos));
@@ -907,31 +912,31 @@
.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return null;
}
-
+
}
-
+
if (!currentRange.validate()) {
response.sendError
(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
return null;
}
-
+
result.addElement(currentRange);
}
-
+
return result;
}
-
-
+
+
// ------------------------------------------------------ Range Inner Class
-
-
+
+
private class Range {
-
+
public long start;
public long end;
public long length;
-
+
/**
* Validate range.
*/
@@ -939,33 +944,33 @@
return ( (start >= 0) && (end >= 0) && (length > 0)
&& (start <= end) && (end < length) );
}
-
+
}
-
-
+
+
// ---------------------------------------------- ResourceInfo Inner Class
-
-
+
+
private class ResourceInfo {
-
-
+
+
/**
* Constructor.
*
* @param pathname Path name of the file
*/
public ResourceInfo(String path, NodeRevisionDescriptor properties) {
-
+
this.path = path;
this.exists = true;
this.creationDate = properties.getCreationDateAsDate().getTime();
this.date = properties.getLastModifiedAsDate().getTime();
this.httpDate = properties.getLastModified();
this.length = properties.getContentLength();
-
+
}
-
-
+
+
public String path;
public long creationDate;
public String httpDate;
@@ -973,25 +978,25 @@
public long length;
//public boolean collection;
public boolean exists;
-
-
+
+
/**
* Test if the associated resource exists.
*/
public boolean exists() {
return exists;
}
-
-
+
+
/**
* String representation.
*/
public String toString() {
return path;
}
-
-
+
+
}
-
-
+
+
}
1.13 +74 -81 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LabelMethod.java
Index: LabelMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LabelMethod.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- LabelMethod.java 12 Aug 2002 12:55:02 -0000 1.12
+++ LabelMethod.java 22 Aug 2002 12:49:09 -0000 1.13
@@ -66,45 +66,32 @@
// import list
import java.io.IOException;
-
import java.util.Enumeration;
import java.util.Iterator;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.slide.common.NamespaceAccessToken;
-
import org.apache.slide.common.NestedSlideException;
import org.apache.slide.common.SlideException;
-
-import org.apache.slide.content.NodeRevisionDescriptor;
-import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeProperty;
import org.apache.slide.content.NodeProperty.NamespaceCache;
-
+import org.apache.slide.content.NodeRevisionDescriptor;
+import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.structure.ObjectNode;
-
-import org.apache.slide.webdav.WebdavServletConfig;
import org.apache.slide.webdav.WebdavException;
-
-import org.apache.slide.webdav.util.VersioningHelper;
+import org.apache.slide.webdav.WebdavServletConfig;
import org.apache.slide.webdav.util.DeltavConstants;
-import org.apache.slide.webdav.util.ViolatedPrecondition;
-import org.apache.slide.webdav.util.PreconditionViolationException;
import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
+import org.apache.slide.webdav.util.PreconditionViolationException;
import org.apache.slide.webdav.util.PropertyHelper;
-import org.apache.slide.webdav.util.UriHandler;
+import org.apache.slide.webdav.util.VersioningHelper;
+import org.apache.slide.webdav.util.ViolatedPrecondition;
+import org.apache.slide.webdav.util.WebdavUtils;
import org.apache.slide.webdav.util.XMLValue;
-
-import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
-import org.apache.slide.webdav.util.resourcekind.VersionControlled;
+import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.Version;
-
+import org.apache.slide.webdav.util.resourcekind.VersionControlled;
import org.apache.util.WebdavStatus;
-
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -117,23 +104,23 @@
* @author <a href="mailto:ralf.stuckert@softwareag.com">Ralf Stuckert</a>
*/
public class LabelMethod extends AbstractMultistatusResponseMethod implements DeltavConstants {
-
+
/**
** String constant for <code>Request content missing</code>.
**/
public static final String CONTENT_MISSING = "Request content missing";
-
+
/**
** String constant for <code>Label missing</code>.
**/
public static final String LABEL_MISSING = "Label missing";
-
+
/**
* String constant for <code>"Request content must start with a <label>
* element</code>.
*/
public static final String MUST_START_WITH_LABEL = "Request content must start with a <"+E_LABEL+"> element";
-
+
/**
* String constant for <code>Request content <label> element must
* contain either <add>, <set> or <remove></code>.
@@ -141,48 +128,48 @@
public static final String LABEL_MUST_CONTAIN_EITHER_ADD_SET_OR_REMOVE =
"Request content <label> element must contain either <" +
E_ADD + ">, <" + E_SET + "> or <" + E_REMOVE + ">";
-
-
-
-
+
+
+
+
/**
* Resource to be written.
*/
private String resourcePath;
-
+
/**
* Indicates if the resource to delete is a collection.
*/
protected boolean isCollection = false;
-
+
/**
* The VersioningHelper used by this instance.
*/
protected VersioningHelper versioningHelper = null;
-
+
/**
* Indicates which label operation to perform:
* <code>add</code>, <code>set</code> or <code>remove</code>.
*/
protected String operation = null;
-
+
/**
* The label to add/set/remove.
*/
protected String label = null;
-
+
/**
* The value of the <code>Label</code> header
*/
protected String labelHeader = null;
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Constructor.
- *
+ *
* @param token the token for accessing the namespace
* @param config configuration of the WebDAV servlet
*/
@@ -190,7 +177,7 @@
WebdavServletConfig config) {
super(token, config);
}
-
+
/**
* Parse WebDAV XML query.
*
@@ -207,8 +194,11 @@
if (resourcePath == null) {
resourcePath = "/";
}
- labelHeader = req.getHeader(DeltavConstants.H_LABEL);
-
+
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
+
try{
Document document = parseRequestContent();
if (document == null) {
@@ -221,7 +211,7 @@
if ( ! DeltavConstants.E_LABEL.equals(root.getName())) {
throw new JDOMException(MUST_START_WITH_LABEL);
}
-
+
Element current = root.getChild(DeltavConstants.E_ADD, NamespaceCache.DEFAULT_NAMESPACE);
Element operationElement = null;
if (current != null) {
@@ -245,7 +235,7 @@
throw new JDOMException(LABEL_MUST_CONTAIN_EITHER_ADD_SET_OR_REMOVE);
}
operation = operationElement.getName();
-
+
Element labelName = operationElement.getChild(DeltavConstants.E_LABEL_NAME, NamespaceCache.DEFAULT_NAMESPACE);
if ( (labelName == null) ||
(labelName.getText() == null) ||
@@ -265,7 +255,7 @@
throw new WebdavException( statusCode );
}
}
-
+
/**
* Execute the request.
*
@@ -311,7 +301,7 @@
sendError( statusCode, ex );
throw new WebdavException( statusCode );
}
- }
+ }
else {
int statusCode = getErrorCode( exception );
sendError( statusCode, exception );
@@ -328,7 +318,7 @@
resp.setHeader(H_CACHE_CONTROL, NO_CACHE);
}
}
-
+
/**
* Labels the reource identified by the given <code>resourcePath</code>.
* If the resource is a collection and a <code>Depth</code> header is specified
@@ -347,7 +337,7 @@
throw nestedSlideException;
}
}
-
+
/**
* Labels the reource identified by the given <code>resourcePath</code>.
* If the resource is a collection and the <code>depth</code> > 0
@@ -361,19 +351,19 @@
* Exceptions to.
*/
protected void labelResource(String resourcePath, int depth, NestedSlideException nestedSlideException) {
-
+
try {
-
+
if ( ! isCollection(resourcePath) ) {
ViolatedPrecondition violatedPrecondition = getPreconditionViolation(resourcePath);
if (violatedPrecondition != null) {
throw new PreconditionViolationException(violatedPrecondition, resourcePath);
}
-
+
performLabelOperation(resourcePath);
}
else if (depth > 0) {
-
+
// process children recursivly
ObjectNode currentNode = structure.retrieve(slideToken, resourcePath);
Enumeration childrenEnum = structure.getChildren(slideToken, currentNode);
@@ -391,7 +381,7 @@
nestedSlideException.addException(new SlideException(e.getMessage()));
}
}
-
+
/**
* Perform the LABEL operation means it either adds, sets or removes the label.
*
@@ -402,14 +392,17 @@
*/
private void performLabelOperation(String resourcePath) throws JDOMException, SlideException {
- String labeledResourceUri = getResourceUri(resourcePath, req.getHeader(H_LABEL));
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ String labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
+ String labeledResourceUri = getResourceUri(resourcePath, labelHeader);
NodeRevisionDescriptors revisionDescriptors =
content.retrieve( slideToken, labeledResourceUri);
NodeRevisionDescriptor revisionDescriptor =
content.retrieve( slideToken, revisionDescriptors);
ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, revisionDescriptors, revisionDescriptor);
if (resourceKind instanceof Version) {
-
+
if (DeltavConstants.E_REMOVE.equals(operation)) {
PropertyHelper.removeElementFromProperty(revisionDescriptor,
P_LABEL_NAME_SET,
@@ -417,7 +410,7 @@
label);
content.store(slideToken, revisionDescriptors.getUri(), revisionDescriptor, null);
}
-
+
if (DeltavConstants.E_SET.equals(operation)) {
try {
NodeRevisionDescriptor alreadyLabeledDescriptor =
@@ -434,7 +427,7 @@
// so we can perform the <set> operation without any preparation
}
}
-
+
if (DeltavConstants.E_ADD.equals(operation) ||
DeltavConstants.E_SET.equals(operation) ) {
PropertyHelper.addElementToProperty(revisionDescriptor,
@@ -445,7 +438,7 @@
}
}
}
-
+
/**
* Checks the (DeltaV) preconditions
* <ul>
@@ -462,21 +455,21 @@
* @throws SlideException
*/
protected ViolatedPrecondition getPreconditionViolation(String resourcePath) throws SlideException {
-
+
ViolatedPrecondition violatedPrecondition = null;
NodeRevisionDescriptors revisionDescriptors =
content.retrieve( slideToken, resourcePath);
NodeRevisionDescriptor revisionDescriptor =
content.retrieve( slideToken, revisionDescriptors);
ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, revisionDescriptors, revisionDescriptor);
-
+
// check <DAV:must-be-checked-in>
if ( (resourceKind instanceof VersionControlled) &&
!(resourceKind instanceof CheckedInVersionControlled) ) {
return new ViolatedPrecondition(DeltavConstants.C_MUST_BE_CHECKED_IN,
WebdavStatus.SC_CONFLICT);
}
-
+
// check <DAV:must-select-version-in-history>
if ( (resourceKind instanceof VersionControlled) &&
(labelHeader != null) ) {
@@ -488,7 +481,7 @@
WebdavStatus.SC_CONFLICT);
}
}
-
+
try {
String slideResourceUri = getResourceUri(resourcePath, labelHeader);
revisionDescriptors =
@@ -497,7 +490,7 @@
content.retrieve( slideToken, revisionDescriptors);
resourceKind = AbstractResourceKind.determineResourceKind(token, revisionDescriptors, revisionDescriptor);
if (resourceKind instanceof Version) {
-
+
// check <DAV:label-must-exist>
if (DeltavConstants.E_REMOVE.equals(operation)) {
if ( ! hasLabel(revisionDescriptor, label) ) {
@@ -505,7 +498,7 @@
WebdavStatus.SC_CONFLICT);
}
}
-
+
try {
versioningHelper.retrieveLabeledRevision(revisionDescriptors.getUri(), label);
// check <DAV:must-be-new-label>
@@ -524,11 +517,11 @@
WebdavStatus.SC_CONFLICT);
}
}
-
+
return violatedPrecondition;
}
-
-
+
+
/**
* Returns the value of the <code>Depth</code> header. If not specified,
* <code>0</code> is used as default.
@@ -536,7 +529,7 @@
* @return the value of the <code>Depth</code> header.
*/
protected int getDepth() {
-
+
int depth = 0;
try {
depth = Integer.parseInt(req.getHeader(H_DEPTH));
@@ -544,7 +537,7 @@
catch (NumberFormatException e) {}
return depth;
}
-
+
/**
* Returns <code>true</code> if the given <code>revisionDescriptor</code>
* has a <code><label-name-set></code> property that contains a
@@ -556,7 +549,7 @@
* @return <code>true</code>, if the label was found.
*/
protected boolean hasLabel(NodeRevisionDescriptor revisionDescriptor, String label) {
-
+
boolean containsLabel = false;
NodeProperty labelNameSetProperty = revisionDescriptor.getProperty(DeltavConstants.P_LABEL_NAME_SET);
if ( (labelNameSetProperty != null) && (labelNameSetProperty.getValue() != null) ) {
@@ -570,10 +563,10 @@
catch (JDOMException e) {}
catch (IllegalArgumentException e) {}
}
-
+
return containsLabel;
}
-
+
/**
* Returns the Uri of the resource identified by the given <code>resourcePath</code>
* and the given <code>label</code>. If the <code>label</code> is <code>null</code>
@@ -588,9 +581,9 @@
* @throws SlideException
*/
protected String getResourceUri(String resourcePath, String label) throws SlideException {
-
+
String labeledResourceUri = versioningHelper.getLabeledResourceUri(resourcePath,
- label);
+ label);
NodeRevisionDescriptors revisionDescriptors =
content.retrieve( slideToken,labeledResourceUri);
NodeRevisionDescriptor revisionDescriptor =
@@ -599,10 +592,10 @@
if (resourceKind instanceof VersionControlled) {
labeledResourceUri = versioningHelper.getUriOfAssociatedVR(resourcePath);
}
-
+
return labeledResourceUri;
}
-
+
}
1.82 +6 -4 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
Index: PropFindMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- PropFindMethod.java 12 Aug 2002 12:55:02 -0000 1.81
+++ PropFindMethod.java 22 Aug 2002 12:49:10 -0000 1.82
@@ -229,7 +229,9 @@
resourcePath = "/";
}
- labelHeader = req.getHeader(DeltavConstants.H_LABEL);
+ // the label header is "ISO-8859-1" encoded, but utf-8 is expected
+ labelHeader = WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(req.getHeader(DeltavConstants.H_LABEL), "ISO-8859-1"),
+ "utf-8");
retrieveDepth();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>