📄 multistatusresponse.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.webdav;import org.apache.jackrabbit.webdav.property.DavProperty;import org.apache.jackrabbit.webdav.property.DavPropertyIterator;import org.apache.jackrabbit.webdav.property.DavPropertyName;import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;import org.apache.jackrabbit.webdav.property.DavPropertySet;import org.apache.jackrabbit.webdav.property.DefaultDavProperty;import org.apache.jackrabbit.webdav.property.PropContainer;import org.apache.jackrabbit.webdav.xml.DomUtil;import org.apache.jackrabbit.webdav.xml.ElementIterator;import org.apache.jackrabbit.webdav.xml.XmlSerializable;import org.w3c.dom.Document;import org.w3c.dom.Element;import java.util.HashMap;import java.util.Iterator;/** * <code>MultiStatusResponse</code> represents the DAV:multistatus element defined * by RFC 2518: * <pre> * <!ELEMENT response (href, ((href*, status)|(propstat+)), responsedescription?) > * <!ELEMENT status (#PCDATA) > * <!ELEMENT propstat (prop, status, responsedescription?) > * <!ELEMENT responsedescription (#PCDATA) > * <!ELEMENT prop ANY > * </pre> */public class MultiStatusResponse implements XmlSerializable, DavConstants { private static final int TYPE_PROPSTAT = 0; private static final int TYPE_HREFSTATUS = 1; /** * The type of MultiStatusResponse */ private final int type; /** * The content the 'href' element for this response */ private final String href; /** * An optional response description. */ private final String responseDescription; /** * Type of MultiStatus response: Href + Status */ private Status status; /** * Type of MultiStatus response: PropStat Hashmap containing all status */ private HashMap statusMap = new HashMap(); private MultiStatusResponse(String href, String responseDescription, int type) { if (!isValidHref(href)) { throw new IllegalArgumentException("Invalid href ('" + href + "')"); } this.href = href; this.responseDescription = responseDescription; this.type = type; } /** * Constructs an WebDAV multistatus response * * @param href * @param status * @param responseDescription */ public MultiStatusResponse(String href, Status status, String responseDescription) { this(href, responseDescription, TYPE_HREFSTATUS); if (status == null) { throw new IllegalArgumentException("Status must not be null in case of a multistatus reponse that consists of href + status only."); } this.status = status; } /** * Constructs an WebDAV multistatus response for a given resource. This * would be used by COPY, MOVE, DELETE, LOCK that require a multistatus in * case of error with a resource other than the resource identified in the * Request-URI.<br> * The response description is set to <code>null</code>. * * @param href * @param statusCode */ public MultiStatusResponse(String href, int statusCode) { this(href, statusCode, null); } /** * Constructs an WebDAV multistatus response for a given resource. This * would be used by COPY, MOVE, DELETE, LOCK that require a multistatus in * case of error with a resource other than the resource identified in the * Request-URI. * * @param href * @param statusCode * @param responseDescription */ public MultiStatusResponse(String href, int statusCode, String responseDescription) { this(href, new Status(statusCode), responseDescription); } /** * Constructs an empty WebDAV multistatus response of type 'PropStat' */ public MultiStatusResponse(String href, String responseDescription) { this(href, responseDescription, TYPE_PROPSTAT); } /** * Constucts a WebDAV multistatus response and retrieves the resource * properties according to the given <code>DavPropertyNameSet</code>. * * @param resource * @param propNameSet */ public MultiStatusResponse(DavResource resource, DavPropertyNameSet propNameSet) { this(resource, propNameSet, PROPFIND_BY_PROPERTY); } /** * Constucts a WebDAV multistatus response and retrieves the resource * properties according to the given <code>DavPropertyNameSet</code>. It * adds all known property to the '200' set, while unknown properties are * added to the '404' set. * <p/> * Note, that the set of property names is ignored in case of a {@link * #PROPFIND_ALL_PROP} and {@link #PROPFIND_PROPERTY_NAMES} propFindType. * * @param resource The resource to retrieve the property from * @param propNameSet The property name set as obtained from the request * body. * @param propFindType any of the following values: {@link * #PROPFIND_ALL_PROP}, {@link #PROPFIND_BY_PROPERTY}, {@link * #PROPFIND_PROPERTY_NAMES} */ public MultiStatusResponse(DavResource resource, DavPropertyNameSet propNameSet, int propFindType) { this(resource.getHref(), null, TYPE_PROPSTAT); // only property names requested if (propFindType == PROPFIND_PROPERTY_NAMES) { PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, true); DavPropertyName[] propNames = resource.getPropertyNames(); for (int i = 0; i < propNames.length; i++) { status200.addContent(propNames[i]); } // all or a specified set of property and their values requested. } else { PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, false); // clone set of property, since several resources could use this again propNameSet = new DavPropertyNameSet(propNameSet); // Add requested properties or all non-protected properties DavPropertyIterator iter = resource.getProperties().iterator(); while (iter.hasNext()) { DavProperty property = iter.nextProperty(); if ((propFindType == PROPFIND_ALL_PROP && !property.isProtected()) || propNameSet.remove(property.getName())) { status200.addContent(property); } } if (!propNameSet.isEmpty() && propFindType != PROPFIND_ALL_PROP) { PropContainer status404 = getPropContainer(DavServletResponse.SC_NOT_FOUND, true); DavPropertyNameIterator iter1 = propNameSet.iterator(); while (iter1.hasNext()) { DavPropertyName propName = iter1.nextPropertyName(); status404.addContent(propName); } } } } /** * Returns the href * * @return href * @see MultiStatusResponse#getHref() */ public String getHref() { return href; } /** * @return responseDescription * @see MultiStatusResponse#getResponseDescription() */ public String getResponseDescription() { return responseDescription; } /** * Return an array listing all 'status' available is this response object. * Note, that a the array contains a single element if this * <code>MultiStatusResponse</code> defines an response consisting of * href and status elements. * * @return */ public Status[] getStatus() { Status[] sts; if (type == TYPE_PROPSTAT) { sts = new Status[statusMap.size()]; Iterator iter = statusMap.keySet().iterator();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -