Ejemplo n.º 1
0
 @Override
 public boolean handleRequest(
     HttpServletRequest request, HttpServletResponse response, IFileStore dir)
     throws ServletException {
   try {
     switch (getMethod(request)) {
       case GET:
         return handleGet(request, response, dir);
       case PUT:
         return handlePut(request, response, dir);
       case POST:
         return handlePost(request, response, dir);
       case DELETE:
         return handleDelete(request, response, dir);
     }
   } catch (JSONException e) {
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Syntax error in request", e));
   } catch (CoreException e) {
     // core exception messages are designed for end user consumption, so use message directly
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
   } catch (Exception e) {
     // the exception message is probably not appropriate for end user consumption
     LogHelper.log(e);
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "An unknown failure occurred. Consult your server log or contact your system administrator.",
             e));
   }
   return false;
 }
Ejemplo n.º 2
0
 @Override
 public String getCharset(boolean checkImplicit) throws CoreException {
   // non-existing resources default to parent's charset
   ResourceInfo info = getResourceInfo(false, false);
   int flags = getFlags(info);
   if (!exists(flags, false))
     return checkImplicit
         ? workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true)
         : null;
   checkLocal(flags, DEPTH_ZERO);
   try {
     return internalGetCharset(checkImplicit, info);
   } catch (CoreException e) {
     if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND) {
       return checkImplicit
           ? workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true)
           : null;
     }
     throw e;
   }
 }
Ejemplo n.º 3
0
 /**
  * Perform a copy or move as specified by the request.
  *
  * @return <code>true</code> if the operation was successful, and <code>false</code> otherwise.
  */
 private boolean performCopyMove(
     HttpServletRequest request,
     HttpServletResponse response,
     JSONObject requestObject,
     IFileStore toCreate,
     boolean isCopy,
     int options)
     throws ServletException, CoreException {
   String locationString = requestObject.optString(ProtocolConstants.KEY_LOCATION, null);
   if (locationString == null) {
     statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_BAD_REQUEST,
             "Copy or move request must specify source location",
             null));
     return false;
   }
   try {
     IFileStore source = resolveSourceLocation(request, locationString);
     if (source == null) {
       statusHandler.handleRequest(
           request,
           response,
           new ServerStatus(
               IStatus.ERROR,
               HttpServletResponse.SC_NOT_FOUND,
               NLS.bind("Source does not exist: ", locationString),
               null));
       return false;
     }
     boolean allowOverwrite = (options & CREATE_NO_OVERWRITE) == 0;
     int efsOptions = allowOverwrite ? EFS.OVERWRITE : EFS.NONE;
     try {
       if (isCopy) source.copy(toCreate, efsOptions, null);
       else source.move(toCreate, efsOptions, null);
     } catch (CoreException e) {
       if (!source.fetchInfo().exists()) {
         statusHandler.handleRequest(
             request,
             response,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_NOT_FOUND,
                 NLS.bind("Source does not exist: ", locationString),
                 e));
         return false;
       }
       if (e.getStatus().getCode() == EFS.ERROR_EXISTS) {
         statusHandler.handleRequest(
             request,
             response,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_PRECONDITION_FAILED,
                 "A file or folder with the same name already exists at this location",
                 null));
         return false;
       }
       // just rethrow if we can't do something more specific
       throw e;
     }
   } catch (URISyntaxException e) {
     statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_BAD_REQUEST,
             NLS.bind("Bad source location in request: ", locationString),
             e));
     return false;
   }
   return true;
 }