juergen 01/07/18 04:36:45
Modified: src/webdav/server/org/apache/slide/webdav/method
CopyMethod.java MoveMethod.java
Log:
use the new error generating messages in the new class.
Revision Changes Path
1.15 +6 -226
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- CopyMethod.java 2001/07/17 13:46:21 1.14
+++ CopyMethod.java 2001/07/18 11:36:45 1.15
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
1.14 2001/07/17 13:46:21 juergen Exp $
- * $Revision: 1.14 $
- * $Date: 2001/07/17 13:46:21 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
1.15 2001/07/18 11:36:45 juergen Exp $
+ * $Revision: 1.15 $
+ * $Date: 2001/07/18 11:36:45 $
*
* ====================================================================
*
@@ -83,30 +83,11 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
*/
-public class CopyMethod extends WebdavMethod {
+public class CopyMethod extends AbstractCopyMoveMethod {
- // ----------------------------------------------------- Instance Variables
- /**
- * Id of the resosurce or collection which is to be copied.
- */
- private String sourceUri;
-
-
- /**
- * Uri of the target.
- */
- private String destinationUri;
-
-
- /**
- * Overwrite.
- */
- private boolean overwrite;
-
-
// ----------------------------------------------------------- Constructors
@@ -128,78 +109,6 @@
// ------------------------------------------------------ Protected Methods
- /**
- * Parse request.
- *
- * @exception WebdavException Does not happen
- */
- protected void parseRequest()
- throws WebdavException {
-
- sourceUri = requestUri;
- if (sourceUri == null) {
- sourceUri = "/";
- }
-
- destinationUri = req.getHeader("Destination");
-
- String HTTPHeader = "http://";
- if (destinationUri.startsWith(HTTPHeader)) {
- destinationUri = destinationUri.substring(HTTPHeader.length());
- }
-
- String hostName = req.getServerName();
- if ((hostName != null) && (destinationUri.startsWith(hostName))) {
- destinationUri = destinationUri.substring(hostName.length());
- }
-
- if (destinationUri.indexOf(":") != (-1)) {
- destinationUri = destinationUri.substring(destinationUri.indexOf(":"));
- }
-
-
-
- if (destinationUri.startsWith(":")) {
- int firstSeparator = destinationUri.indexOf("/");
- if (firstSeparator < 0) {
- destinationUri = "/";
- } else {
- destinationUri = destinationUri.substring(firstSeparator);
- }
- }
-
- destinationUri = URLDecode(destinationUri);
-
- String contextPath = req.getContextPath();
- if ((contextPath != null) &&
- (destinationUri.startsWith(contextPath))) {
- destinationUri = destinationUri.substring(contextPath.length());
- }
-
- String pathInfo = req.getPathInfo();
- if (pathInfo != null) {
- String servletPath = req.getServletPath();
- if ((servletPath != null) &&
- (destinationUri.startsWith(servletPath))) {
- destinationUri = destinationUri
- .substring(servletPath.length());
- }
- }
-
- String overwriteHeader = req.getHeader("Overwrite");
-
- if (overwriteHeader != null) {
- if (overwriteHeader.equalsIgnoreCase("T")) {
- overwrite = true;
- } else {
- overwrite = false;
- }
- } else {
- overwrite = true;
- }
-
- }
-
/**
* Execute request.
@@ -242,8 +151,8 @@
// Returning 207 on non-collection requests is generally
// considered bad. So let's not do it, since this way
// makes clients generally behave better.
- Enumeration nestedExceptions = e.enumerateExceptions();
- setErrorCode(resp, (SlideException)nestedExceptions.nextElement());
+ resp.setStatus(
+
getErrorCode((SlideException)e.enumerateExceptions().nextElement()));
}
//
// make sure the transaction is aborted
@@ -269,135 +178,6 @@
}
- /**
- * Generate an XML error message.
- *
- * @param macroException Nested exception
- * @return String XML message
- */
- protected String generateErrorMessage(CopyMacroException macroException) {
-
- XMLPrinter errorMessage = new XMLPrinter();
-
- errorMessage.writeXMLHeader();
- errorMessage.writeElement("d", "DAV", "multistatus",
- XMLPrinter.OPENING);
-
- Enumeration nestedExceptionsList = macroException
- .enumerateExceptions();
-
- while (nestedExceptionsList.hasMoreElements()) {
-
- errorMessage.writeElement("d", "DAV", "response",
- XMLPrinter.OPENING);
-
- SlideException ex = (SlideException) nestedExceptionsList
- .nextElement();
-
- String status = new String();
-
- try {
- throw ex;
- } catch(ObjectNotFoundException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(AccessDeniedException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_FORBIDDEN);
- } catch(ForbiddenException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_FORBIDDEN);
- } catch(ConflictException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_CONFLICT);
- } catch(ObjectAlreadyExistsException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_PRECONDITION_FAILED);
- } catch(ServiceAccessException e) {
- generateStatusText(errorMessage, e.getMessage(),
- WebdavStatus.SC_BAD_GATEWAY);
- } catch(LinkedObjectNotFoundException e) {
- generateStatusText(errorMessage, e.getTargetUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(RevisionNotFoundException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ObjectLockedException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_LOCKED);
- } catch(SlideException e) {
- generateStatusText(errorMessage, e.getMessage(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
-
- errorMessage.writeElement("d", "DAV", "response",
- XMLPrinter.CLOSING);
-
- }
-
- errorMessage.writeElement("d", "DAV", "multistatus",
- XMLPrinter.CLOSING);
-
- return errorMessage.toString();
-
- }
-
-
- /**
- * Generate status text.
- *
- * @param printer XML Printer
- * @param href Uri of the object
- * @param statusCode HTTP status code of the error
- */
- protected void generateStatusText(XMLPrinter printer, String href,
- int statusCode) {
- printer.writeElement("d", "href", XMLPrinter.OPENING);
- printer.writeText(URLEncode(href));
- printer.writeElement("d", "href", XMLPrinter.CLOSING);
- printer.writeElement("d", "status", XMLPrinter.OPENING);
- printer.writeText("HTTP/1.1 " + statusCode + " "
- + WebdavStatus.getStatusText(statusCode));
- printer.writeElement("d", "status", XMLPrinter.CLOSING);
- }
-
-
-
- /**
- * Returns true
- */
- protected boolean methodNeedsTransactionSupport() {
- return true;
- }
-
- /**
- * Set return status based on exception type.
- */
- private void setErrorCode(HttpServletResponse resp, SlideException ex) {
- try {
- throw ex;
- } catch(ObjectNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch(ConflictException e) {
- resp.setStatus(WebdavStatus.SC_CONFLICT);
- } catch(ForbiddenException e) {
- resp.setStatus(WebdavStatus.SC_FORBIDDEN);
- } catch(AccessDeniedException e) {
- resp.setStatus(WebdavStatus.SC_FORBIDDEN);
- } catch(ObjectAlreadyExistsException e) {
- resp.setStatus(WebdavStatus.SC_PRECONDITION_FAILED);
- } catch(ServiceAccessException e) {
- resp.setStatus(WebdavStatus.SC_BAD_GATEWAY);
- } catch(LinkedObjectNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(RevisionNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ObjectLockedException e) {
- resp.setStatus(WebdavStatus.SC_LOCKED);
- } catch(SlideException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
- }
}
1.14 +6 -223
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java
Index: MoveMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MoveMethod.java 2001/07/17 13:47:20 1.13
+++ MoveMethod.java 2001/07/18 11:36:45 1.14
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
1.13 2001/07/17 13:47:20 juergen Exp $
- * $Revision: 1.13 $
- * $Date: 2001/07/17 13:47:20 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
1.14 2001/07/18 11:36:45 juergen Exp $
+ * $Revision: 1.14 $
+ * $Date: 2001/07/18 11:36:45 $
*
* ====================================================================
*
@@ -83,28 +83,10 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
*/
-public class MoveMethod extends WebdavMethod {
+public class MoveMethod extends AbstractCopyMoveMethod {
- // ----------------------------------------------------- Instance Variables
-
- /**
- * Id of the resosurce or collection which is to be move.
- */
- private String sourceUri;
-
- /**
- * Uri of the target.
- */
- private String destinationUri;
-
- /**
- * Overwrite.
- */
- private boolean overwrite;
-
-
// ----------------------------------------------------------- Constructors
@@ -124,78 +106,6 @@
// ------------------------------------------------------ Protected Methods
- /**
- * Parse request.
- *
- * @exception WebdavException Does not happen
- */
- protected void parseRequest()
- throws WebdavException {
-
- sourceUri = requestUri;
- if (sourceUri == null) {
- sourceUri = "/";
- }
-
- destinationUri = req.getHeader("Destination");
-
- String HTTPHeader = "http://";
- if (destinationUri.startsWith(HTTPHeader)) {
- destinationUri = destinationUri.substring(HTTPHeader.length());
- }
-
- String hostName = req.getServerName();
- if ((hostName != null) && (destinationUri.startsWith(hostName))) {
- destinationUri = destinationUri.substring(hostName.length());
- }
-
- if (destinationUri.indexOf(":") != (-1)) {
- destinationUri = destinationUri.substring(destinationUri.indexOf(":"));
- }
-
-
-
- if (destinationUri.startsWith(":")) {
- int firstSeparator = destinationUri.indexOf("/");
- if (firstSeparator < 0) {
- destinationUri = "/";
- } else {
- destinationUri = destinationUri.substring(firstSeparator);
- }
- }
-
- destinationUri = URLDecode(destinationUri);
-
- String contextPath = req.getContextPath();
- if ((contextPath != null) &&
- (destinationUri.startsWith(contextPath))) {
- destinationUri = destinationUri.substring(contextPath.length());
- }
-
- String pathInfo = req.getPathInfo();
- if (pathInfo != null) {
- String servletPath = req.getServletPath();
- if ((servletPath != null) &&
- (destinationUri.startsWith(servletPath))) {
- destinationUri = destinationUri
- .substring(servletPath.length());
- }
- }
-
- String overwriteHeader = req.getHeader("Overwrite");
-
- if (overwriteHeader != null) {
- if (overwriteHeader.equalsIgnoreCase("T")) {
- overwrite = true;
- } else {
- overwrite = false;
- }
- } else {
- overwrite = true;
- }
-
- }
-
/**
* Execute request.
@@ -237,8 +147,8 @@
// Returning 207 on non-collection requests is generally
// considered bad. So let's not do it, since this way
// makes clients generally behave better.
- Enumeration nestedExceptions = e.enumerateExceptions();
- setErrorCode(resp, (SlideException)nestedExceptions.nextElement());
+ resp.setStatus(
+
getErrorCode((SlideException)e.enumerateExceptions().nextElement()));
//
// make sure the transaction is aborted
// throw any WebDAV exception to indicate the transaction wants to be
aborted
@@ -249,133 +159,6 @@
}
- /**
- /**
- * Generate an XML error message.
- *
- * @param macroException Nested exception
- * @return String XML message
- */
- protected String generateErrorMessage(MacroException macroException) {
-
- XMLPrinter errorMessage = new XMLPrinter();
-
- errorMessage.writeXMLHeader();
- errorMessage.writeElement("d", "DAV", "multistatus",
- XMLPrinter.OPENING);
-
- Enumeration nestedExceptionsList =
- macroException.enumerateExceptions();
-
- while (nestedExceptionsList.hasMoreElements()) {
-
- errorMessage.writeElement("d", "DAV", "response",
- XMLPrinter.OPENING);
-
- SlideException ex =
- (SlideException) nestedExceptionsList.nextElement();
-
- String status = new String();
-
- try {
- throw ex;
- } catch(ObjectNotFoundException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(AccessDeniedException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_FORBIDDEN);
- } catch(ForbiddenException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_FORBIDDEN);
- } catch(ConflictException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_CONFLICT);
- } catch(ObjectAlreadyExistsException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ServiceAccessException e) {
- generateStatusText(errorMessage, e.getMessage(),
- WebdavStatus.SC_BAD_GATEWAY);
- } catch(LinkedObjectNotFoundException e) {
- generateStatusText(errorMessage, e.getTargetUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(RevisionNotFoundException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ObjectLockedException e) {
- generateStatusText(errorMessage, e.getObjectUri(),
- WebdavStatus.SC_LOCKED);
- } catch(SlideException e) {
- generateStatusText(errorMessage, e.getMessage(),
- WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
-
- errorMessage.writeElement("d", "DAV", "response",
- XMLPrinter.CLOSING);
-
- }
-
- errorMessage.writeElement("d", "DAV", "multistatus",
- XMLPrinter.CLOSING);
-
- return errorMessage.toString();
-
- }
-
-
- /**
- * Generate status text.
- *
- * @param printer XML Printer
- * @param href Uri of the object
- * @param statusCode HTTP status code of the error
- */
- protected void generateStatusText(XMLPrinter printer, String href,
- int statusCode) {
- printer.writeElement("d", "href", XMLPrinter.OPENING);
- printer.writeText(URLEncode(href));
- printer.writeElement("d", "href", XMLPrinter.CLOSING);
- printer.writeElement("d", "status", XMLPrinter.OPENING);
- printer.writeText("HTTP/1.1 " + statusCode + " "
- + WebdavStatus.getStatusText(statusCode));
- printer.writeElement("d", "status", XMLPrinter.CLOSING);
- }
-
-
- /**
- * Returns true
- */
- protected boolean methodNeedsTransactionSupport() {
- return true;
- }
-
- /**
- * Set return status based on exception type.
- */
- private void setErrorCode(HttpServletResponse resp, SlideException ex) {
- try {
- throw ex;
- } catch(ObjectNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch(AccessDeniedException e) {
- resp.setStatus(WebdavStatus.SC_FORBIDDEN);
- } catch(ObjectAlreadyExistsException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ServiceAccessException e) {
- resp.setStatus(WebdavStatus.SC_BAD_GATEWAY);
- } catch(LinkedObjectNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(RevisionNotFoundException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch(ObjectLockedException e) {
- resp.setStatus(WebdavStatus.SC_LOCKED);
- } catch(ForbiddenException e) {
- resp.setStatus(WebdavStatus.SC_FORBIDDEN);
- } catch(SlideException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
- }
}