/** * Process a HEAD request for the specified resource.<p> * * @param request the servlet request we are processing * @param response the servlet response we are creating * * @throws IOException if an input/output error occurs */ @Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException { // Serve the requested resource, without the data content serveResource(request, response, false); }
/** * Check to see if a resource is currently write locked.<p> * * @param req the servlet request we are processing * * @return true if the resource is locked otherwise false */ private boolean isLocked(HttpServletRequest req) { return isLocked(getRelativePath(req)); }
/** * Print the lock discovery information associated with a path.<p> * * @param path the path to the resource * @param elem the dom element where to add the lock discovery elements * @param req the servlet request we are processing * * @return true if at least one lock was displayed */ private boolean generateLockDiscovery(String path, Element elem, HttpServletRequest req) { CmsRepositoryLockInfo lock = m_session.getLock(path); if (lock != null) { Element lockElem = addElement(elem, TAG_LOCKDISCOVERY); addLockElement(lock, lockElem, generateLockToken(req, lock)); return true; } return false; }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception).<p> * * @param item the RepositoryItem * @param ostream the output stream to write to * @param range the range the client wants to retrieve * * @throws IOException if an input/output error occurs */ protected void copy(I_CmsRepositoryItem item, ServletOutputStream ostream, CmsWebdavRange range) throws IOException { IOException exception = null; InputStream resourceInputStream = new ByteArrayInputStream(item.getContent()); InputStream istream = new BufferedInputStream(resourceInputStream, m_input); exception = copyRange(istream, ostream, range.getStart(), range.getEnd()); // Clean up the input stream try { istream.close(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_INPUT_STREAM_0), e); } } // Rethrow any exception that has occurred if (exception != null) { throw exception; } }
/** * Process a PROPPATCH WebDAV request for the specified resource.<p> * * Not implemented yet.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ protected void doProppatch(HttpServletRequest req, HttpServletResponse resp) { // Check if Webdav is read only if (m_readOnly) { resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WEBDAV_READ_ONLY_0)); } return; } // Check if resource is locked if (isLocked(req)) { resp.setStatus(CmsWebdavStatus.SC_LOCKED); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_LOCKED_1, getRelativePath(req))); } return; } resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); }
/** * Process a OPTIONS WebDAV request for the specified resource.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ @Override protected void doOptions(HttpServletRequest req, HttpServletResponse resp) { resp.addHeader("DAV", "1,2"); StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); resp.addHeader(HEADER_ALLOW, methodsAllowed.toString()); resp.addHeader("MS-Author-Via", "DAV"); }
/** * Generate a dom element from the given information with all needed subelements to * add to the parent.<p> * * @param lock the lock with the information to create the subelements * @param parent the parent element where to add the created element * @param lockToken the lock token to use */ private void addLockElement(CmsRepositoryLockInfo lock, Element parent, String lockToken) { Element activeLockElem = addElement(parent, TAG_ACTIVELOCK); addElement(addElement(activeLockElem, TAG_LOCKTYPE), lock.getType()); addElement(addElement(activeLockElem, TAG_LOCKSCOPE), lock.getScope()); if (lock.getDepth() == CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE) { addElement(activeLockElem, TAG_DEPTH).addText(DEPTH_INFINITY); } else { addElement(activeLockElem, TAG_DEPTH).addText("0"); } Element ownerElem = addElement(activeLockElem, TAG_OWNER); addElement(ownerElem, TAG_HREF).addText(lock.getOwner()); if (lock.getExpiresAt() == CmsRepositoryLockInfo.TIMEOUT_INFINITE_VALUE) { addElement(activeLockElem, TAG_TIMEOUT).addText(TIMEOUT_INFINITE); } else { long timeout = (lock.getExpiresAt() - System.currentTimeMillis()) / 1000; addElement(activeLockElem, TAG_TIMEOUT).addText("Second-" + timeout); } Element lockTokenElem = addElement(activeLockElem, TAG_LOCKTOKEN); addElement(lockTokenElem, TAG_HREF).addText("opaquelocktoken:" + lockToken); }
/** * Generates a lock token out of the lock and some information out of the * request to make it unique.<p> * * @param req the servlet request we are processing * @param lock the lock with the information for the lock token * * @return the generated lock token */ private String generateLockToken(HttpServletRequest req, CmsRepositoryLockInfo lock) { String lockTokenStr = req.getServletPath() + "-" + req.getUserPrincipal() + "-" + lock.getOwner() + "-" + lock.getPath() + "-" + m_secret; return MD5_ENCODER.encode(m_md5Helper.digest(lockTokenStr.getBytes())); }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception).<p> * * @param item the RepositoryItem * @param writer the writer to write to * @param range the range the client wants to retrieve * * @throws IOException if an input/output error occurs */ protected void copy(I_CmsRepositoryItem item, PrintWriter writer, CmsWebdavRange range) throws IOException { IOException exception = null; InputStream resourceInputStream = new ByteArrayInputStream(item.getContent()); Reader reader = new InputStreamReader(resourceInputStream); exception = copyRange(reader, writer, range.getStart(), range.getEnd()); // Clean up the input stream try { reader.close(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_READER_0), e); } } // Rethrow any exception that has occurred if (exception != null) { throw exception; } }
/** * Process a PROPPATCH WebDAV request for the specified resource.<p> * * Not implemented yet.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ protected void doProppatch(HttpServletRequest req, HttpServletResponse resp) { // Check if Webdav is read only if (m_readOnly) { resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WEBDAV_READ_ONLY_0)); } return; } // Check if resource is locked if (isLocked(req)) { resp.setStatus(CmsWebdavStatus.SC_LOCKED); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_LOCKED_1, getRelativePath(req))); } return; } resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); }
/** * Print the lock discovery information associated with a path.<p> * * @param path the path to the resource * @param elem the dom element where to add the lock discovery elements * @param req the servlet request we are processing * * @return true if at least one lock was displayed */ private boolean generateLockDiscovery(String path, Element elem, HttpServletRequest req) { CmsRepositoryLockInfo lock = m_session.getLock(path); if (lock != null) { Element lockElem = addElement(elem, TAG_LOCKDISCOVERY); addLockElement(lock, lockElem, generateLockToken(req, lock)); return true; } return false; }
/** * Check to see if a resource is currently write locked.<p> * * @param req the servlet request we are processing * * @return true if the resource is locked otherwise false */ private boolean isLocked(HttpServletRequest req) { return isLocked(getRelativePath(req)); }
/** * Process a OPTIONS WebDAV request for the specified resource.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ @Override protected void doOptions(HttpServletRequest req, HttpServletResponse resp) { resp.addHeader("DAV", "1,2"); StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); resp.addHeader(HEADER_ALLOW, methodsAllowed.toString()); resp.addHeader("MS-Author-Via", "DAV"); }
/** * Process a HEAD request for the specified resource.<p> * * @param request the servlet request we are processing * @param response the servlet response we are creating * * @throws IOException if an input/output error occurs */ @Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException { // Serve the requested resource, without the data content serveResource(request, response, false); }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception).<p> * * @param item the RepositoryItem * @param writer the writer to write to * @param range the range the client wants to retrieve * * @throws IOException if an input/output error occurs */ protected void copy(I_CmsRepositoryItem item, PrintWriter writer, CmsWebdavRange range) throws IOException { IOException exception = null; InputStream resourceInputStream = new ByteArrayInputStream(item.getContent()); Reader reader = new InputStreamReader(resourceInputStream); exception = copyRange(reader, writer, range.getStart(), range.getEnd()); // Clean up the input stream try { reader.close(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_READER_0), e); } } // Rethrow any exception that has occurred if (exception != null) { throw exception; } }
/** * Process a UNLOCK WebDAV request for the specified resource.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ protected void doUnlock(HttpServletRequest req, HttpServletResponse resp) { String path = getRelativePath(req); // Check if Webdav is read only if (m_readOnly) { resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WEBDAV_READ_ONLY_0)); } return; } // Check if resource is locked if (isLocked(req)) { resp.setStatus(CmsWebdavStatus.SC_LOCKED); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_LOCKED_1, path)); } return; } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_UNLOCK_ITEM_0)); } m_session.unlock(path); resp.setStatus(CmsWebdavStatus.SC_NO_CONTENT); }
/** * Process a GET request for the specified resource.<p> * * @param request the servlet request we are processing * @param response the servlet response we are creating * * @throws IOException if an input/output error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // Serve the requested resource, including the data content serveResource(request, response, true); }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception).<p> * * @param item the RepositoryItem * @param ostream the output stream to write to * @param range the range the client wants to retrieve * * @throws IOException if an input/output error occurs */ protected void copy(I_CmsRepositoryItem item, ServletOutputStream ostream, CmsWebdavRange range) throws IOException { IOException exception = null; InputStream resourceInputStream = new ByteArrayInputStream(item.getContent()); InputStream istream = new BufferedInputStream(resourceInputStream, m_input); exception = copyRange(istream, ostream, range.getStart(), range.getEnd()); // Clean up the input stream try { istream.close(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_INPUT_STREAM_0), e); } } // Rethrow any exception that has occurred if (exception != null) { throw exception; } }
/** * Process a UNLOCK WebDAV request for the specified resource.<p> * * @param req the servlet request we are processing * @param resp the servlet response we are creating */ protected void doUnlock(HttpServletRequest req, HttpServletResponse resp) { String path = getRelativePath(req); // Check if Webdav is read only if (m_readOnly) { resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WEBDAV_READ_ONLY_0)); } return; } // Check if resource is locked if (isLocked(req)) { resp.setStatus(CmsWebdavStatus.SC_LOCKED); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_LOCKED_1, path)); } return; } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_UNLOCK_ITEM_0)); } m_session.unlock(path); resp.setStatus(CmsWebdavStatus.SC_NO_CONTENT); }
/** * Process a GET request for the specified resource.<p> * * @param request the servlet request we are processing * @param response the servlet response we are creating * * @throws IOException if an input/output error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // Serve the requested resource, including the data content serveResource(request, response, true); }