⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webdavrequestimpl.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (propfindProps == null) {            parsePropFindRequest();        }        return propfindProps;    }    /**     * Parse the propfind request body in order to determine the type of the propfind     * and the set of requested property.     * NOTE: An empty 'propfind' request body will be treated as request for all     * property according to the specification.     */    private void parsePropFindRequest() throws DavException {        propfindProps = new DavPropertyNameSet();        Document requestDocument = getRequestDocument();        // propfind httpRequest with empty body >> retrieve all property        if (requestDocument == null) {            return;        }        // propfind httpRequest with invalid body        Element root = requestDocument.getDocumentElement();        if (!XML_PROPFIND.equals(root.getLocalName())) {            log.info("PropFind-Request has no <profind> tag.");            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropFind-Request has no <profind> tag.");        }        ElementIterator it = DomUtil.getChildren(root);        while (it.hasNext()) {            Element child = it.nextElement();            String nodeName = child.getLocalName();            if (XML_PROP.equals(nodeName)) {                propfindType = PROPFIND_BY_PROPERTY;                propfindProps = new DavPropertyNameSet(child);                break;            } else if (XML_PROPNAME.equals(nodeName)) {                propfindType = PROPFIND_PROPERTY_NAMES;                break;            } else if (XML_ALLPROP.equals(nodeName)) {                propfindType = PROPFIND_ALL_PROP;                break;            }        }    }    /**     * Return the list of 'set' entries in the PROPPATCH request body. The list     * is empty if the request body could not be parsed or if the request body did     * not contain any 'set' elements.     *     * @return the list of 'set' entries in the PROPPATCH request body     * @see DavServletRequest#getPropPatchSetProperties()     * @deprecated use {@link #getPropPatchChangeList()} instead     */    public DavPropertySet getPropPatchSetProperties() throws DavException {        if (proppatchSet == null) {            parsePropPatchRequest();        }        return proppatchSet;    }    /**     * Return the list of 'remove' entries in the PROPPATCH request body. The list     * is empty if the request body could not be parsed or if the request body did     * not contain any 'remove' elements.     *     * @return the list of 'remove' entries in the PROPPATCH request body     * @see DavServletRequest#getPropPatchRemoveProperties()     * @deprecated use {@link #getPropPatchChangeList()} instead     */    public DavPropertyNameSet getPropPatchRemoveProperties() throws DavException {        if (proppatchRemove == null) {            parsePropPatchRequest();        }        return proppatchRemove;    }     /**      * Return a {@link List} of property change operations. Each entry      * is either of type {@link DavPropertyName}, indicating a &lt;remove&gt;      * operation, or of type {@link DavProperty}, indicating a &lt;set&gt;      * operation. Note that ordering is significant here.      *      * @return the list of change operations entries in the PROPPATCH request body      * @see DavServletRequest#getPropPatchChangeList()      */     public List getPropPatchChangeList() throws DavException {         if (proppatchList == null) {             parsePropPatchRequest();         }         return proppatchList;     }    /**     * Parse the PROPPATCH request body.     */    private void parsePropPatchRequest() throws DavException {        proppatchSet = new DavPropertySet();        proppatchRemove = new DavPropertyNameSet();        proppatchList = new ArrayList();        Document requestDocument = getRequestDocument();        if (requestDocument == null) {            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid request body.");        }        Element root = requestDocument.getDocumentElement();        if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) {            log.warn("PropPatch-Request has no <DAV:propertyupdate> tag.");            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropPatch-Request has no <propertyupdate> tag.");        }        ElementIterator it = DomUtil.getChildren(root);        while (it.hasNext()) {            Element el = it.nextElement();            if (DomUtil.matches(el, XML_SET, NAMESPACE)) {                Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);                if (propEl != null) {                    ElementIterator properties = DomUtil.getChildren(propEl);                    while (properties.hasNext()) {                        DavProperty davProp = DefaultDavProperty.createFromXml(properties.nextElement());                        proppatchSet.add(davProp);                        proppatchList.add(davProp);                    }                }            } else if (DomUtil.matches(el, XML_REMOVE, NAMESPACE)) {                Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);                if (propEl != null) {                    ElementIterator properties = DomUtil.getChildren(propEl);                    while (properties.hasNext()) {                        DavProperty davProp = DefaultDavProperty.createFromXml(properties.nextElement());                        proppatchSet.add(davProp);                        proppatchList.add(davProp.getName());                    }                }            } else {                log.debug("Unknown element in DAV:propertyupdate: " + el.getNodeName());                // unknown child elements are ignored            }        }    }    /**     * {@link LockInfo} object encapsulating the information passed with a LOCK     * request if the LOCK request body was valid. If the request body is     * missing a 'refresh lock' request is assumed. The {@link LockInfo}     * then only provides timeout and isDeep property and returns true on     * {@link org.apache.jackrabbit.webdav.lock.LockInfo#isRefreshLock()}     *     * @return lock info object or <code>null</code> if an error occured while     *         parsing the request body.     * @throws DavException throws a 400 (Bad Request) DavException if a request     * body is present but does not start with a DAV:lockinfo element. Note however,     * that a non-existing request body is a valid request used to refresh     * an existing lock.     * @see DavServletRequest#getLockInfo()     */    public LockInfo getLockInfo() throws DavException {        LockInfo lockInfo;        boolean isDeep = (getDepth(DEPTH_INFINITY) == DEPTH_INFINITY);        Document requestDocument = getRequestDocument();        // check if XML request body is present. It SHOULD have one for        // 'create Lock' request and missing for a 'refresh Lock' request        if (requestDocument != null) {            Element root = requestDocument.getDocumentElement();            if (root.getLocalName().equals(XML_LOCKINFO)) {                lockInfo = new LockInfo(root, getTimeout(), isDeep);            } else {                log.debug("Lock request body must start with a DAV:lockinfo element.");                throw new DavException(DavServletResponse.SC_BAD_REQUEST);            }        } else {            lockInfo = new LockInfo(null, getTimeout(), isDeep);        }        return lockInfo;    }    /**     * Test if the if header matches the given resource. The comparison is     * made with the {@link DavResource#getHref()     * resource href} and the token returned from an exclusive write lock present on     * the resource.<br>     * NOTE: If either the If header or the resource is <code>null</code> or if     * the resource has not applied an exclusive write lock the preconditions are met.     * If in contrast the lock applied to the given resource returns a     * <code>null</code> lock token (e.g. for security reasons) or a lock token     * that does not match, the method will return false.     *     * @param resource Webdav resources being operated on     * @return true if the test is successful and the preconditions for the     *         request processing are fulfilled.     * @see DavServletRequest#matchesIfHeader(DavResource)     * @see IfHeader#matches(String, String, String)     * @see DavResource#hasLock(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope)     * @see org.apache.jackrabbit.webdav.lock.ActiveLock#getToken()     */    public boolean matchesIfHeader(DavResource resource) {        // no ifheader, no resource or no write lock on resource        // >> preconditions ok so far        if (!ifHeader.hasValue() || resource == null || !resource.hasLock(Type.WRITE, Scope.EXCLUSIVE)) {            return true;        }        boolean isMatching = false;        String lockToken = resource.getLock(Type.WRITE, Scope.EXCLUSIVE).getToken();        if (lockToken != null) {            isMatching = matchesIfHeader(resource.getHref(), lockToken, getStrongETag(resource));        } // else: lockToken is null >> the if-header will not match.        return isMatching;    }    /**     * @see DavServletRequest#matchesIfHeader(String, String, String)     * @see IfHeader#matches(String, String, String)     */    public boolean matchesIfHeader(String href, String token, String eTag) {        return ifHeader.matches(href, token, isStrongETag(eTag) ?  eTag : "");    }    /**     * Returns the strong etag present on the given resource or empty string     * if either the resource does not provide any etag or if the etag is weak.     *     * @param resource     * @return strong etag or empty string.     */    private String getStrongETag(DavResource resource) {        DavProperty prop = resource.getProperty(DavPropertyName.GETETAG);        if (prop != null && prop.getValue() != null) {            String etag = prop.getValue().toString();            if (isStrongETag(etag)) {                return etag;            }        }        // no strong etag available        return "";    }    /**     * Returns true if the given string represents a strong etag.     *     * @param eTag     * @return true, if its a strong etag     */    private static boolean isStrongETag(String eTag) {        return eTag != null && eTag.length() > 0 && !eTag.startsWith("W\\");    }    //-----------------------------< TransactionDavServletRequest Interface >---    /**     * @see org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest#getTransactionId()     */    public String getTransactionId() {        return CodedUrlHeader.parse(httpRequest, TransactionConstants.HEADER_TRANSACTIONID).getCodedUrl();    }    /**     * @see org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest#getTransactionInfo()     */    public TransactionInfo getTransactionInfo() throws DavException {        Document requestDocument = getRequestDocument();        if (requestDocument != null) {            return new TransactionInfo(requestDocument.getDocumentElement());        }        return null;    }    //-----------------------------< ObservationDavServletRequest Interface >---    /**     * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getSubscriptionId()     */    public String getSubscriptionId() {        return CodedUrlHeader.parse(httpRequest, ObservationConstants.HEADER_SUBSCRIPTIONID).getCodedUrl();    }    /**     * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getPollTimeout()     */    public long getPollTimeout() {        return PollTimeoutHeader.parseHeader(httpRequest, 0).getTimeout();    }    /**     * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getSubscriptionInfo()     */    public SubscriptionInfo getSubscriptionInfo() throws DavException {        Document requestDocument = getRequestDocument();        if (requestDocument != null) {            Element root = requestDocument.getDocumentElement();            if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getLocalName())) {                int depth = getDepth(DEPTH_0);                return new SubscriptionInfo(root, getTimeout(), depth == DEPTH_INFINITY);            }        }        return null;    }    //--------------------------------< OrderingDavServletRequest Interface >---    /**     * @see org.apache.jackrabbit.webdav.ordering.OrderingDavServletRequest#getOrderingType()     */    public String getOrderingType() {        return getHeader(OrderingConstants.HEADER_ORDERING_TYPE);    }    /**     * @see org.apache.jackrabbit.webdav.ordering.OrderingDavServletRequest#getPosition()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -