Element responseElem = addElement(elem, TAG_RESPONSE); Element hrefElem = addElement(responseElem, TAG_HREF); hrefElem.addText(rewriteUrl(href)); } catch (UnsupportedEncodingException ex) { return; Element propstatElem = addElement(responseElem, TAG_PROPSTAT); Element propElem = addElement(propstatElem, TAG_PROP); addElement(propElem, TAG_CREATIONDATE).addText(ISO8601_FORMAT.format(new Date(item.getCreationDate()))); addElement(propElem, TAG_DISPLAYNAME).addCDATA(resourceName); addElement(propElem, TAG_LASTMODIFIED).addText( HTTP_DATE_FORMAT.format(new Date(item.getLastModifiedDate()))); addElement(propElem, TAG_CONTENTLENGTH).addText(String.valueOf(item.getContentLength())); String contentType = getServletContext().getMimeType(item.getName()); if (contentType != null) { addElement(propElem, TAG_CONTENTTYPE).addText(contentType); addElement(propElem, TAG_ETAG).addText(getETag(item)); addElement(propElem, TAG_RESOURCETYPE); } else { addElement(addElement(propElem, TAG_RESOURCETYPE), TAG_COLLECTION); addElement(propElem, TAG_SOURCE).addText("");
/** * 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; }
/** * 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"); }
String path = getRelativePath(req); LOG.debug("[" + method + "] " + path); requestAuthorization(resp); doPropfind(req, resp); } else if (method.equals(METHOD_PROPPATCH)) { doProppatch(req, resp); } else if (method.equals(METHOD_MKCOL)) { doMkcol(req, resp); } else if (method.equals(METHOD_COPY)) { doCopy(req, resp); } else if (method.equals(METHOD_MOVE)) { doMove(req, resp); } else if (method.equals(METHOD_LOCK)) { doLock(req, resp); } else if (method.equals(METHOD_UNLOCK)) { doUnlock(req, resp); } else {
String path = getRelativePath(request); if (LOG.isDebugEnabled()) { if (content) { contentType = getServletContext().getMimeType(item.getName()); ranges = parseRange(request, response, item); response.setHeader(HEADER_ETAG, getETag(item)); renderResult = renderHtml(request.getContextPath() + request.getServletPath(), item.getName()); copy(item, renderResult, ostream); } else { copy(item, renderResult, writer); copy(item, ostream, range); } else { copy(item, writer, range); copy(item, ostream, ranges.iterator(), contentType); } else { copy(item, writer, ranges.iterator(), contentType);
String path = getRelativePath(req); if (isLocked(req)) { resp.addHeader(HEADER_LOCKTOKEN, "<opaquelocktoken:" + generateLockToken(req, lock) + ">"); Element propElem = doc.addElement(new QName(TAG_PROP, Namespace.get(DEFAULT_NAMESPACE))); Element lockElem = addElement(propElem, TAG_LOCKDISCOVERY); addLockElement(lock, lockElem, generateLockToken(req, lock));
String path = getRelativePath(req); if (isLocked(req)) { checkChildLocks(req, path, errorList); if (!errorList.isEmpty()) { sendReport(req, resp, errorList);
String path = getRelativePath(req); if (isLocked(req)) { StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); resp.addHeader(HEADER_ALLOW, methodsAllowed.toString()); resp.setStatus(CmsWebdavStatus.SC_METHOD_NOT_ALLOWED);
String path = getRelativePath(req); StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); parseProperties(req, multiStatusElem, item, type, properties); } else { parseProperties(req, multiStatusElem, currentItem, type, properties);
/** * 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; } }
/** * Checks if the items in the path or in a subpath are locked.<p> * * @param req the servlet request we are processing * @param path the path to check the items for locks * @param errorList the error list where to put the found errors */ private void checkChildLocks(HttpServletRequest req, String path, Hashtable<String, Integer> errorList) { List<I_CmsRepositoryItem> list = null; try { list = m_session.list(path); } catch (CmsException e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_ERROR_1, path), e); } errorList.put(path, new Integer(CmsWebdavStatus.SC_INTERNAL_SERVER_ERROR)); return; } Iterator<I_CmsRepositoryItem> iter = list.iterator(); while (iter.hasNext()) { I_CmsRepositoryItem element = iter.next(); if (isLocked(element.getName())) { errorList.put(element.getName(), new Integer(CmsWebdavStatus.SC_LOCKED)); } else { if (element.isCollection()) { checkChildLocks(req, element.getName(), errorList); } } } }
String relativePath = getRelativePath(req); int errorCode = e.getValue().intValue(); Element responseElem = addElement(multiStatusElem, TAG_RESPONSE); toAppend = "/" + toAppend; addElement(responseElem, TAG_HREF).addText(absoluteUri + toAppend); addElement(responseElem, TAG_STATUS).addText( "HTTP/1.1 " + errorCode + " " + CmsWebdavStatus.getStatusText(errorCode));
/** * 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); }
String path = getRelativePath(req); LOG.debug("[" + method + "] " + path); requestAuthorization(resp); doPropfind(req, resp); } else if (method.equals(METHOD_PROPPATCH)) { doProppatch(req, resp); } else if (method.equals(METHOD_MKCOL)) { doMkcol(req, resp); } else if (method.equals(METHOD_COPY)) { doCopy(req, resp); } else if (method.equals(METHOD_MOVE)) { doMove(req, resp); } else if (method.equals(METHOD_LOCK)) { doLock(req, resp); } else if (method.equals(METHOD_UNLOCK)) { doUnlock(req, resp); } else {
String path = getRelativePath(request); if (LOG.isDebugEnabled()) { if (content) { contentType = getServletContext().getMimeType(item.getName()); ranges = parseRange(request, response, item); response.setHeader(HEADER_ETAG, getETag(item)); renderResult = renderHtml(request.getContextPath() + request.getServletPath(), item.getName()); copy(item, renderResult, ostream); } else { copy(item, renderResult, writer); copy(item, ostream, range); } else { copy(item, writer, range); copy(item, ostream, ranges.iterator(), contentType); } else { copy(item, writer, ranges.iterator(), contentType);
protected void doLock(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = getRelativePath(req); if (isLocked(req)) { resp.addHeader(HEADER_LOCKTOKEN, "<opaquelocktoken:" + generateLockToken(req, lock) + ">"); Element propElem = doc.addElement(new QName(TAG_PROP, Namespace.get(DEFAULT_NAMESPACE))); Element lockElem = addElement(propElem, TAG_LOCKDISCOVERY); addLockElement(lock, lockElem, generateLockToken(req, lock));
String path = getRelativePath(req); if (isLocked(req)) { checkChildLocks(req, path, errorList); if (!errorList.isEmpty()) { sendReport(req, resp, errorList);
String path = getRelativePath(req); if (isLocked(req)) { StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); resp.addHeader(HEADER_ALLOW, methodsAllowed.toString()); resp.setStatus(CmsWebdavStatus.SC_METHOD_NOT_ALLOWED);
String path = getRelativePath(req); StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); parseProperties(req, multiStatusElem, item, type, properties); } else { parseProperties(req, multiStatusElem, currentItem, type, properties);
exception = copyRange(reader, writer);