org.apache.jackrabbit.webdav.WebdavRequest Java Examples
The following examples show how to use
org.apache.jackrabbit.webdav.WebdavRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The REPORT method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doReport(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { log.debug("doReport"); ReportInfo info = request.getReportInfo(); Report report; if (resource instanceof DeltaVResource) { report = ((DeltaVResource) resource).getReport(info); } else if (resource instanceof AclResource) { report = ((AclResource) resource).getReport(info); } else { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } int statusCode = (report.isMultiStatusReport()) ? DavServletResponse.SC_MULTI_STATUS : DavServletResponse.SC_OK; response.sendXmlResponse(report, statusCode); }
Example #2
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The OPTION method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource */ protected void doOptions(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doOptions"); response.addHeader(DavConstants.HEADER_DAV, resource.getComplianceClass()); response.addHeader("Allow", resource.getSupportedMethods()); response.addHeader("MS-Author-Via", DavConstants.HEADER_DAV); if (resource instanceof SearchResource) { String[] langs = ((SearchResource) resource).getQueryGrammerSet().getQueryLanguages(); for (int i = 0; i < langs.length; i++) { response.addHeader(SearchConstants.HEADER_DASL, "<" + langs[i] + ">"); } } // with DeltaV the OPTIONS request may contain a Xml body. OptionsResponse oR = null; OptionsInfo oInfo = request.getOptionsInfo(); if (oInfo != null && resource instanceof DeltaVResource) { oR = ((DeltaVResource) resource).getOptionResponse(oInfo); } if (oR == null) { response.setStatus(DavServletResponse.SC_OK); } else { response.sendXmlResponse(oR, DavServletResponse.SC_OK); } }
Example #3
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The PROPPATCH method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error */ @SuppressWarnings("rawtypes") protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doPropPatch"); List changeList = request.getPropPatchChangeList(); if (changeList.isEmpty()) { response.sendError(DavServletResponse.SC_BAD_REQUEST); return; } MultiStatus ms = new MultiStatus(); MultiStatusResponse msr = resource.alterProperties(changeList); ms.addResponse(msr); response.sendMultiStatus(ms); }
Example #4
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The COPY method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doCopy"); // only depth 0 and infinity is allowed int depth = request.getDepth(DEPTH_INFINITY); if (!(depth == DEPTH_0 || depth == DEPTH_INFINITY)) { response.sendError(DavServletResponse.SC_BAD_REQUEST); return; } DavResource destResource = null; try { destResource = getResourceFactory().createResource(request.getDestinationLocator(), request); } catch (Throwable e) { destResource = resource.getCollection(); } int status = validateDestination(destResource, request); if (status > DavServletResponse.SC_NO_CONTENT) { response.sendError(status); return; } resource.copy(destResource, depth == DEPTH_0); response.setStatus(status); }
Example #5
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * The DELETE method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doDelete(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doDelete"); try { if (log.isDebugEnabled()) log.debug("[DELETE] {} {}", (resource.isCollection() ? " FOLDER" : " DOCUMENT"), resource.getDisplayName()); DavResource parent = resource.getCollection(); if (parent != null) { parent.removeMember(resource); response.setStatus(DavServletResponse.SC_NO_CONTENT); } else { response.sendError(DavServletResponse.SC_FORBIDDEN, "Cannot remove the root resource."); } } catch (Exception e) { log.error(e.getMessage(), e); } }
Example #6
Source File: UnauthenticatedDavSessionProvider.java From archiva with Apache License 2.0 | 5 votes |
@Override public boolean attachSession( WebdavRequest request ) throws DavException { request.setDavSession(new ArchivaDavSession()); return true; }
Example #7
Source File: WebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) { if (resource.getDisplayName().toLowerCase().equals("thumbs.db")) return false; return !resource.exists() || request.matchesIfHeader(resource); }
Example #8
Source File: RepositoryServlet.java From archiva with Apache License 2.0 | 5 votes |
@Override protected boolean isPreconditionValid( final WebdavRequest request, final DavResource davResource ) { // check for read or write access to the resource when resource-based permission is implemented return true; }
Example #9
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * The EVENT_UNCHECKOUT method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doUncheckout(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { log.debug("doUncheckout(" + resource.getDisplayName() + ")"); if (!(resource instanceof VersionControlledResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } ((VersionControlledResource) resource).uncheckout(); response.setStatus(DavServletResponse.SC_OK); }
Example #10
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
protected void doVersionControl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { log.debug("doVersionControl"); if (!(resource instanceof VersionableResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } ((VersionableResource) resource).addVersionControl(); }
Example #11
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * Validate the given destination resource and return the proper status * code: Any return value greater/equal than * {@link DavServletResponse#SC_NO_CONTENT} indicates an error. * * @param destResource destination resource to be validated. * @param request the HTTP request * * @return status code indicating whether the destination is valid. */ private int validateDestination(DavResource destResource, WebdavRequest request) throws DavException { String destHeader = request.getHeader(HEADER_DESTINATION); if (destHeader == null || "".equals(destHeader)) { return DavServletResponse.SC_BAD_REQUEST; } if (destResource.getLocator().equals(request.getRequestLocator())) { return DavServletResponse.SC_FORBIDDEN; } int status; if (destResource.exists()) { if (request.isOverwrite()) { // matching if-header required for existing resources if (!request.matchesIfHeader(destResource)) { return DavServletResponse.SC_PRECONDITION_FAILED; } else { // overwrite existing resource destResource.getCollection().removeMember(destResource); status = DavServletResponse.SC_NO_CONTENT; } } else { // cannot copy/move to an existing item, if overwrite is not // forced return DavServletResponse.SC_PRECONDITION_FAILED; } } else { // destination does not exist >> copy/move can be performed status = DavServletResponse.SC_CREATED; } return status; }
Example #12
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * The MKCOL method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doMkCol(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doMkCol"); if (log.isDebugEnabled()) log.debug("[ADD] Directory {}", resource.getDisplayName()); try { DavResource parentResource = resource.getCollection(); if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) { // parent does not exist or is not a collection response.sendError(DavServletResponse.SC_CONFLICT); return; } // shortcut: mkcol is only allowed on deleted/non-existing resources if (resource.exists()) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); } if (request.getContentLength() > 0 || request.getHeader("Transfer-Encoding") != null) { parentResource.addMember(resource, getInputContext(request, request.getInputStream())); } else { parentResource.addMember(resource, getInputContext(request, null)); } response.setStatus(DavServletResponse.SC_CREATED); } catch (Exception e) { e.printStackTrace(); } }
Example #13
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * The PUT method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doPut(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("************doPut*****************"); if (log.isDebugEnabled()) log.debug("[ADD] Document {}", resource.getDisplayName()); try { DavResource parentResource = resource.getCollection(); if (parentResource == null || !parentResource.exists()) { // parent does not exist response.sendError(DavServletResponse.SC_CONFLICT); return; } int status; // test if resource already exists if (resource.exists()) { status = DavServletResponse.SC_NO_CONTENT; } else { status = DavServletResponse.SC_CREATED; } parentResource.addMember(resource, getInputContext(request, request.getInputStream())); getResourceFactory().putInCache((com.logicaldoc.webdav.session.DavSession) parentResource.getSession(), parentResource); response.setStatus(status); } catch (Exception e) { } }
Example #14
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * @param sendContent * * @throws IOException generic I/O error */ private void spoolResource(WebdavRequest request, WebdavResponse response, DavResource resource, boolean sendContent) throws IOException { if (!resource.exists()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } long modSince = request.getDateHeader("If-Modified-Since"); if (modSince > UNDEFINED_TIME) { long modTime = resource.getModificationTime(); // test if resource has been modified. note that formatted // modification // time lost the milli-second precision if (modTime != UNDEFINED_TIME && (modTime / 1000 * 1000) <= modSince) { // resource has not been modified since the time indicated in // the // 'If-Modified-Since' header. response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } // spool resource properties and ev. resource content. OutputStream out = (sendContent) ? response.getOutputStream() : null; resource.spool(getOutputContext(response, out)); }
Example #15
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * The GET method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error */ protected void doGet(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException { log.debug("get"); try { spoolResource(request, response, resource, true); } catch (Exception e) { log.error(e.getMessage(), e); } }
Example #16
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
/** * The PROPFIND method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error */ protected void doPropFind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doPropFind"); if (log.isDebugEnabled()) log.debug("[READ] FINDING {} {}", (resource.isCollection() ? "DOCUMENTS WITHIN THE FOLDER" : "JUST THE DOCUMENT"), resource.getDisplayName()); if (!resource.exists()) { log.warn("Resource not found: {}", resource.getResourcePath()); response.sendError(DavServletResponse.SC_NOT_FOUND); return; } DavPropertyNameSet requestProperties = request.getPropFindProperties(); if (log.isDebugEnabled()) { DavPropertyNameIterator iter = requestProperties.iterator(); StringBuffer sb = new StringBuffer("Requested properties: "); while (iter.hasNext()) { sb.append(((DavPropertyName) iter.next()).getName()); sb.append(","); } log.debug(sb.toString()); } int propfindType = request.getPropFindType(); int depth = Context.get().getProperties().getInt("webdav.depth", 1); String headerDepth = request.getHeader("Depth"); if (StringUtils.isNotEmpty(headerDepth)) { if ("infinity".equals(headerDepth)) depth = request.getDepth(DEPTH_INFINITY); else { depth = Integer.parseInt(headerDepth); } } MultiStatus mstatus = new MultiStatus(); mstatus.addResourceProperties(resource, requestProperties, propfindType, depth); response.sendMultiStatus(mstatus); }
Example #17
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
protected void doLock(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("doLock - interpreting as checkout"); doCheckout(request, response, resource); }
Example #18
Source File: ArchivaDavSessionProvider.java From archiva with Apache License 2.0 | 4 votes |
@Override public void releaseSession( WebdavRequest request ) { request.setDavSession( null ); }
Example #19
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
/** * Executes the respective method in the given webdav context * * @param request the HTTP request * @param response the server's response * @param method the HTTP method * * @param resource the DAV resource * * @throws ServletException error inside the servlet container * @throws IOException generic I/O error * @throws DavException generic error in the WebDAV communication */ protected boolean execute(WebdavRequest request, WebdavResponse response, int method, DavResource resource) throws ServletException, IOException, DavException { switch (method) { case DavMethods.DAV_GET: doGet(request, response, resource); break; case DavMethods.DAV_HEAD: doHead(request, response, resource); break; case DavMethods.DAV_PROPFIND: doPropFind(request, response, resource); break; case DavMethods.DAV_PROPPATCH: doPropPatch(request, response, resource); break; case DavMethods.DAV_POST: doPost(request, response, resource); break; case DavMethods.DAV_PUT: doPut(request, response, resource); break; case DavMethods.DAV_DELETE: doDelete(request, response, resource); break; case DavMethods.DAV_COPY: doCopy(request, response, resource); break; case DavMethods.DAV_MOVE: doMove(request, response, resource); break; case DavMethods.DAV_MKCOL: doMkCol(request, response, resource); break; case DavMethods.DAV_OPTIONS: doOptions(request, response, resource); break; case DavMethods.DAV_LOCK: doLock(request, response, resource); break; case DavMethods.DAV_UNLOCK: doUnlock(request, response, resource); break; case DavMethods.DAV_CHECKOUT: doCheckout(request, response, resource); break; case DavMethods.DAV_CHECKIN: doCheckin(request, response, resource); break; case DavMethods.DAV_REPORT: doReport(request, response, resource); break; case DavMethods.DAV_VERSION_CONTROL: doVersionControl(request, response, resource); break; case DavMethods.DAV_UNCHECKOUT: doUncheckout(request, response, resource); break; default: // any other method return false; } return true; }
Example #20
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 3 votes |
/** * The EVENT_CHECKEDOUT method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws DavException * @throws IOException */ protected void doCheckout(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { log.debug("doCheckout"); if (!(resource instanceof VersionControlledResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } ((VersionControlledResource) resource).checkout(); }
Example #21
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 3 votes |
/** * The EVENT_CHECKEDIN method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doCheckin(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { log.debug("doCheckin"); response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); }
Example #22
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 2 votes |
/** * The POST method. Delegate to PUT * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doPost(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { log.debug("************doPost*****************"); doPut(request, response, resource); }
Example #23
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 2 votes |
/** * The UNLOCK method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error * @throws DavException error in the DAV communication */ protected void doUnlock(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { doUncheckout(request, response, resource); }
Example #24
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 2 votes |
/** * The HEAD method * * @param request the HTTP request * @param response the server's response * @param resource the DAV resource * * @throws IOException generic I/O error */ protected void doHead(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException { log.debug("head"); spoolResource(request, response, resource, false); }
Example #25
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 2 votes |
/** * Checks if the precondition for this request and resource is valid. * * @param request the HTTP request * @param response the server's response * * @return if the precondition is valid */ abstract protected boolean isPreconditionValid(WebdavRequest request, DavResource resource);