Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,113 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.DavResource; +import org.apache.jackrabbit.webdav.DavException; +import org.apache.jackrabbit.webdav.DavSession; +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.version.report.ReportInfo; +import org.apache.jackrabbit.webdav.version.report.Report; + +/** + * The DeltaVResource encapsultes the functionality common to all + * DeltaV compliant resources. + *

+ * RFC 3253 defines the following required properties: + *

+ *

+ * In addition a DeltaV compliant resource must support the following METHODS: + *

+ * + * @see DavResource + */ +public interface DeltaVResource extends DavResource { + + public String COMPLIANCE_CLASS = "version-control, checkout-in-place, version-history, update, label, merge, workspace"; + + /** + * The generic deltaV complient resource defines one additional method REPORT. + * + * @see DeltaVResource#METHODS + * @see org.apache.jackrabbit.webdav.DavResource#METHODS + */ + public String METHODS = "REPORT, MKWORKSPACE"; + + /** + * Retrieves the information requested in the OPTIONS request body and + * returns the corresponding values. + * + * @param optionsInfo + * @return object to be included to the OPTIONS response body or null + * if the specified optionsInfo was null or empty. + */ + public OptionsResponse getOptionResponse(OptionsInfo optionsInfo); + + /** + * Runs the report specified by the given ReportInfo. + * + * @param reportInfo + * @return the requested report. + * @throws DavException in case an error occured or if the specified ReportInfo + * is either not valid or cannot be run by the given resource. + */ + public Report getReport(ReportInfo reportInfo) throws DavException; + + /** + * Add a new member to this resource, that represents a workspace.
+ * Please note that no resource must exist at the location of the new workspace. + * + * @param workspace resource representing the new workspace to be created as + * member of this resource. + * @throws DavException if creating the new workspace fails. + * @todo MKWORKSPACE may include an xml request body... + */ + public void addWorkspace(DavResource workspace) throws DavException; + + /** + * Returns an array of DavResource objects that are referenced + * by the {@link org.apache.jackrabbit.webdav.property.HrefProperty} with + * the specified {@link DavPropertyName name}. + * + * @param hrefPropertyName + * @return An array of DavResources + * @throws DavException if the given hrefPropertyName does point to an + * unknown property or does not represent the name of a + * {@link org.apache.jackrabbit.webdav.property.HrefProperty href property}. + * Finally the exception may be caused if the property contains the href + * of a non-existing resource, which cannot be resolved. + * @see org.apache.jackrabbit.webdav.property.HrefProperty + */ + public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException; + + /** + * Retrieve the DavSession associated with this resource. + * + * @return session object associated with this resource. + */ + public DavSession getSession(); +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,77 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.DavServletRequest; +import org.apache.jackrabbit.webdav.version.report.ReportInfo; + +/** + * DeltaVServletRequest provides extension useful for functionality + * related to RFC 3253. + */ +public interface DeltaVServletRequest extends DavServletRequest { + + /** + * Returns the Label header or null + * + * @return label header or null + * @see DeltaVConstants#HEADER_LABEL + */ + public String getLabel(); + + /** + * Return the request body as LabelInfo object or null + * if parsing the request body or the creation of the label info failed. + * + * @return LabelInfo object or null + */ + public LabelInfo getLabelInfo(); + + /** + * Return the request body as MergeInfo object or null + * if the creation failed due to invalid format. + * + * @return MergeInfo object or null + */ + public MergeInfo getMergeInfo(); + + /** + * Parses the UPDATE request body a build the corresponding UpdateInfo + * object. If the request body is missing or does not of the required format + * null is returned. + * + * @return the parsed update request body or null + */ + public UpdateInfo getUpdateInfo(); + + /** + * Returns the request body and the Depth header as ReportInfo + * object. The default depth, if no {@link org.apache.jackrabbit.webdav.DavConstants#HEADER_DEPTH + * Depth header}, is {@link org.apache.jackrabbit.webdav.DavConstants#DEPTH_0}. + * If the requuest body could not be parsed into an {@link org.jdom.Element} + * null is returned. + * + * @return ReportInfo or null + */ + public ReportInfo getReportInfo(); + + /** + * Returns the {@link OptionsInfo} present with the request or null. + * + * @return {@link OptionsInfo} or null + */ + public OptionsInfo getOptionsInfo(); +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/DeltaVServletRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,159 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.jdom.Element; + +import java.util.Iterator; + +/** + * LabelInfo encapsulates the request body of a LABEL request + * used to add, set or remove a label from the requested version resource or + * from that version specified with the Label header in case the requested resource + * is a version-controlled resource.

+ * The request body (thus the 'labelElement' passed to the constructore must be + * a DAV:label element: + *
+ * <!ELEMENT label ANY>
+ * ANY value: A sequence of elements with at most one DAV:add,
+ * DAV:set, or DAV:remove element.
+ * <!ELEMENT add (label-name)>
+ * <!ELEMENT set (label-name)>
+ * <!ELEMENT remove (label-name)>
+ * <!ELEMENT label-name (#PCDATA)>
+ * PCDATA value: string
+ * 
+ */ +public class LabelInfo implements DeltaVConstants { + + private static Logger log = Logger.getLogger(LabelInfo.class); + + public static final int TYPE_SET = 0; + public static final int TYPE_REMOVE = 1; + public static final int TYPE_ADD = 2; + + private final Element labelElement; + private final int depth; + + private int type; + private String labelName; + + /** + * Create a new LabelInfo from the given element and depth + * integer. If the specified Xml element does have a {@link DeltaVConstants#XML_LABEL} + * root element or no label name is specified with the action to perform + * the creation will fail. + * + * @param labelElement + * @param depth + * @throws IllegalArgumentException if the specified element does not + * start with a {@link DeltaVConstants#XML_LABEL} element or if the DAV:label + * element contains illegal instructions e.g. contains multiple DAV:add, DAV:set + * or DAV:remove elements. + */ + public LabelInfo(Element labelElement, int depth) { + if (labelElement == null || !labelElement.getName().equals(DeltaVConstants.XML_LABEL)) { + throw new IllegalArgumentException("label element expected"); + } + + this.labelElement = (Element) labelElement.detach(); + + Iterator childrenIter = labelElement.getChildren().iterator(); + while (childrenIter.hasNext()) { + Element child = (Element) childrenIter.next(); + if (!NAMESPACE.equals(child.getNamespace())) { + continue; + } + String name = child.getName(); + if (XML_LABEL_ADD.equals(name)) { + type = TYPE_ADD; + setLabelName(child); + } else if (XML_LABEL_REMOVE.equals(name)) { + type = TYPE_REMOVE; + setLabelName(child); + } else if (XML_LABEL_SET.equals(name)) { + type = TYPE_SET; + setLabelName(child); + } + } + this.depth = depth; + } + + /** + * Create a new LabelInfo from the given element. As depth + * the default value 0 is assumed. + * + * @param labelElement + * @throws IllegalArgumentException + * @see #LabelInfo(org.jdom.Element, int) + */ + public LabelInfo(Element labelElement) { + this(labelElement, 0); + } + + /** + * Return the 'label-name' or null + * + * @return 'label-name' or null + */ + public String getLabelName() { + return labelName; + } + + /** + * Retrieve the text of the 'label-name' child element of the specified + * parent element. + * + * @param parent the is intended to contain a valid 'label-name' child. + * @throws IllegalArgumentException if the labelName has been set before. + */ + private void setLabelName(Element parent) { + // test if any label name is present + if (labelName != null) { + throw new IllegalArgumentException("The DAV:label element may contain at most one DAV:add, DAV:set, or DAV:remove element"); + } + labelName = parent.getChildText(XML_LABEL_NAME, NAMESPACE); + } + + /** + * Return the type of the LABEL request. This might either be {@link #TYPE_SET}, + * {@link #TYPE_ADD} or {@link #TYPE_REMOVE}. + * + * @return type + */ + public int getType() { + return type; + } + + /** + * Return the depth + * + * @return depth + */ + public int getDepth() { + return depth; + } + + /** + * Return the DAV:label element + * + * @return the DAV:label element + */ + public Element getLabelElement() { + return labelElement; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/LabelInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,117 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.apache.jackrabbit.webdav.DavConstants; +import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; +import org.jdom.Element; + +/** + * MergeInfo encapsulates the information present in the DAV:merge + * element, that forms the mandatory request body of a MERGE request.
+ * The DAV:merge element is specified to have the following form. + *
+ * <!ELEMENT merge ANY>
+ * ANY value: A sequence of elements with one DAV:source element, at most one
+ * DAV:no-auto-merge element, at most one DAV:no-checkout element, at most one
+ * DAV:prop element, and any legal set of elements that can occur in a DAV:checkout
+ * element.
+ * <!ELEMENT source (href+)>
+ * <!ELEMENT no-auto-merge EMPTY>
+ * <!ELEMENT no-checkout EMPTY>
+ * prop: see RFC 2518, Section 12.11
+ * 
+ */ +public class MergeInfo implements DeltaVConstants { + + private static Logger log = Logger.getLogger(MergeInfo.class); + + private Element mergeElement; + + /** + * Create a new MergeInfo + * + * @param mergeElement + * @throws IllegalArgumentException if the mergeElement is null + * or not a DAV:merge element. + */ + public MergeInfo(Element mergeElement) { + if (mergeElement == null || !mergeElement.getName().equals(XML_MERGE)) { + throw new IllegalArgumentException("'DAV:merge' element expected"); + } + this.mergeElement = (Element) mergeElement.detach(); + } + + /** + * Returns the URL specified with the DAV:source element or null + * if no such child element is present in the DAV:merge element. + * + * @return href present in the DAV:source child element or null. + */ + public String getSourceHref() { + Element source = mergeElement.getChild(DavConstants.XML_SOURCE, DavConstants.NAMESPACE); + if (source != null) { + return source.getChildText(DavConstants.XML_HREF, DavConstants.NAMESPACE); + } + return null; + } + + /** + * Returns true if the DAV:merge element contains a DAV:no-auto-merge child element. + * + * @return true if the DAV:merge element contains a DAV:no-auto-merge child. + */ + public boolean isNoAutoMerge() { + return mergeElement.getChild(XML_N0_AUTO_MERGE, NAMESPACE) != null; + } + + /** + * Returns true if the DAV:merge element contains a DAV:no-checkout child element. + * + * @return true if the DAV:merge element contains a DAV:no-checkout child + */ + public boolean isNoCheckout() { + return mergeElement.getChild(XML_N0_CHECKOUT, NAMESPACE) != null; + } + + /** + * Returns a {@link DavPropertyNameSet}. If the DAV:merge element contains + * a DAV:prop child element the properties specified therein are included + * in the set. Otherwise an empty set is returned. + * + * @return set listing the properties specified in the DAV:prop element indicating + * those properties that must be reported in the response body. + */ + public DavPropertyNameSet getPropertyNameSet() { + Element propElement = mergeElement.getChild(DavConstants.XML_PROP, DavConstants.NAMESPACE); + if (propElement != null) { + return new DavPropertyNameSet(propElement); + } else { + return new DavPropertyNameSet(); + } + } + + /** + * Returns the DAV:merge element used to create this MergeInfo + * object. + * + * @return DAV:merge element + */ + public Element getMergeElement() { + return mergeElement; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/MergeInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,81 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.jdom.Element; +import org.jdom.Namespace; + +import java.util.List; + +/** + * OptionsInfo represents the Xml request body, that may be present + * with a OPTIONS request. + *
+ * The DAV:options element is specified to have the following form. + * + *
+ * <!ELEMENT options ANY>
+ * ANY value: A sequence of elements each at most onces.
+ * 
+ * + * @see DeltaVConstants#XML_VH_COLLECTION_SET + * @see DeltaVConstants#XML_WSP_COLLECTION_SET + * @see DeltaVConstants#XML_ACTIVITY_COLLECTION_SET + */ +public class OptionsInfo { + + private static Logger log = Logger.getLogger(OptionsInfo.class); + + private final Element optionsElement; + + /** + * Create a new UpdateInfo object. + * + * @param optionsElement + * @throws IllegalArgumentException if the updateElement is null + * or not a DAV:update element or if the element does not match the required + * structure. + */ + public OptionsInfo(Element optionsElement) { + if (optionsElement == null || !optionsElement.getName().equals(DeltaVConstants.XML_OPTIONS)) { + throw new IllegalArgumentException("DAV:options element expected"); + } + this.optionsElement = (Element) optionsElement.detach(); + } + + /** + * Returns the set of elements present in the {@link DeltaVConstants#XML_OPTIONS DAV:options} + * element. These elements define the information the client wishes to retrieve + * the OPTIONS request. + * + * @return set of child elements + */ + public List getElements() { + return optionsElement.getChildren(); + } + + /** + * Returns true if a child element with the given name and namespace is present. + * + * @param name + * @param namespace + * @return true if such a child element exists in the options element. + */ + public boolean containsElement(String name, Namespace namespace) { + return optionsElement.getChild(name, namespace) != null; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,75 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.apache.jackrabbit.webdav.util.XmlUtil; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.Namespace; + +/** + * OptionsResponse encapsulates the DAV:options-response element + * present in the response body of a successful OPTIONS request (with body). + *
+ * The DAV:options-response element is defined to have the following format. + * + *
+ * <!ELEMENT options-response ANY>
+ * ANY value: A sequence of elements
+ * 
+ */ +public class OptionsResponse implements DeltaVConstants { + + private static Logger log = Logger.getLogger(OptionsResponse.class); + + private final Element optionsResponse = new Element(XML_OPTIONS_RESPONSE, NAMESPACE); + + /** + * Add a new entry to this OptionsResponse + * + * @param elem + */ + public void addEntry(Element elem) { + optionsResponse.addContent(elem.detach()); + } + + /** + * Add a new entry to this OptionsResponse and make each + * href present in the String array being a separate {@link org.apache.jackrabbit.webdav.DavConstants#XML_HREF DAV:href} + * element within the entry. + * + * @param name + * @param namespace + * @param hrefs + */ + public void addEntry(String name, Namespace namespace, String[] hrefs) { + Element elem = new Element(name, namespace); + for (int i = 0; i < hrefs.length; i++) { + elem.addContent(XmlUtil.hrefToXml(hrefs[i])); + } + optionsResponse.addContent(elem); + } + + /** + * Return the Xml representation. + * + * @return Xml representation. + */ + public Document toXml() { + return new Document(optionsResponse); + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/OptionsResponse.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,89 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.jdom.Element; + +/** + * The ResourceType extends the {@link org.apache.jackrabbit.webdav.property.ResourceType} + * by DeltaV specific types. + */ +public class ResourceType extends org.apache.jackrabbit.webdav.property.ResourceType + implements DeltaVConstants { + + private static Logger log = Logger.getLogger(ResourceType.class); + + /** + * The version-history resource type + */ + public static final int VERSION_HISTORY = COLLECTION + 1; + + /** + * The activity resource type + */ + public static final int ACTIVITY = VERSION_HISTORY + 1; + + /** + * The baseline resource type + */ + public static final int BASELINE = ACTIVITY + 1; + + /** + * Array containing all possible resourcetype elements + */ + private static final String[] ELEMENT_NAMES = { + null, + XML_COLLECTION, + XML_VERSION_HISTORY, + XML_ACTIVITY, + XML_BASELINE + }; + + + /** + * Create a resource type property + * + * @param resourceType + */ + public ResourceType(int resourceType) { + super(resourceType); + } + + /** + * Return the resource type as Xml element. + * + * @return Xml element representing the internal type or null + * if the resource has no element name assigned (default resource type). + */ + public Object getValue() { + String name = ELEMENT_NAMES[getResourceType()]; + return (name != null) ? new Element(name, DeltaVConstants.NAMESPACE) : null; + } + + /** + * Returns true if the given integer defines a valid resource type. + * + * @param resourceType to be validated. + * @return true if this is a known resource type. + */ + public boolean isValidResourceType(int resourceType) { + if (resourceType < DEFAULT_RESOURCE || resourceType > BASELINE) { + return false; + } + return true; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/ResourceType.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,45 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.apache.jackrabbit.webdav.property.DefaultDavProperty; +import org.jdom.Element; + +/** + * The SupportedMethodSetProperty + */ +public class SupportedMethodSetProperty extends DefaultDavProperty implements DeltaVConstants { + + private static Logger log = Logger.getLogger(SupportedMethodSetProperty.class); + + /** + * Create a new SupportedMethodSetProperty property. + * + * @param methods that are supported by the resource having this property. + */ + public SupportedMethodSetProperty(String[] methods) { + super(DeltaVConstants.SUPPORTED_METHOD_SET, new Element[methods.length], true); + + // fill the array with the proper elements + Element[] value = (Element[]) getValue(); + for (int i = 0; i < methods.length; i++) { + Element methodElem = new Element(DeltaVConstants.XML_SUPPORTED_METHOD, DeltaVConstants.NAMESPACE); + methodElem.setAttribute("name",methods[i], DeltaVConstants.NAMESPACE); + value[i] = methodElem; + } + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/SupportedMethodSetProperty.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,146 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.log4j.Logger; +import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; +import org.apache.jackrabbit.webdav.DavConstants; +import org.jdom.Element; + +import java.util.List; +import java.util.Iterator; + +/** + * UpdateInfo encapsulates the request body of an UPDATE request. + * RFC 3253 defines the request body as follows: + *
+ * <!ELEMENT update ANY>
+ * ANY value: A sequence of elements with at most one DAV:version element and at
+ * most one DAV:prop element.
+ * <!ELEMENT version (href)>
+ * prop: see RFC 2518, Section 12.11
+ * 
+ * + * In order to reflect the complete range of version restoring and updating + * of nodes defined by JSR170 the definition has been extended: + *
+ * <!ELEMENT update ( (version+ | label-name | workspace ) , (prop)?, (removeExisting)? ) >
+ * <!ELEMENT version (href) >
+ * <!ELEMENT label-name (#PCDATA) >
+ * <!ELEMENT workspace (href) >
+ * <!ELEMENT prop ANY >
+ * <!ELEMENT removeExisting EMPTY >
+ * 
+ */ +public class UpdateInfo implements DeltaVConstants { + + private static Logger log = Logger.getLogger(UpdateInfo.class); + + private final Element updateElement; + private String[] versionHref; + private String[] labelName; + private String workspaceHref; + + /** + * Create a new UpdateInfo object. + * + * @param updateElement + * @throws IllegalArgumentException if the updateElement is null + * or not a DAV:update element or if the element does not match the required + * structure. + */ + public UpdateInfo(Element updateElement) { + if (updateElement == null || !updateElement.getName().equals(DeltaVConstants.XML_UPDATE)) { + throw new IllegalArgumentException("DAV:update element expected"); + } + + List targetList; + if (!(targetList = updateElement.getChildren(XML_VERSION, NAMESPACE)).isEmpty()) { + Iterator it = targetList.iterator(); + versionHref = new String[targetList.size()]; + int i = 0; + while (it.hasNext()) { + Element versionElem = (Element) it.next(); + versionHref[i] = versionElem.getChildText(DavConstants.XML_HREF, NAMESPACE); + i++; + } + } else if (!(targetList = updateElement.getChildren(XML_LABEL_NAME, NAMESPACE)).isEmpty()) { + Iterator it = targetList.iterator(); + labelName = new String[targetList.size()]; + int i = 0; + while (it.hasNext()) { + Element labelNameElem = (Element) it.next(); + labelName[i] = labelNameElem.getText(); + i++; + } + } else if (updateElement.getChild(XML_WORKSPACE, NAMESPACE) != null) { + workspaceHref = updateElement.getChild(XML_WORKSPACE, NAMESPACE).getChildText(DavConstants.XML_HREF, NAMESPACE); + } else { + throw new IllegalArgumentException("DAV:update element must contain either DAV:version, DAV:label-name or DAV:workspace child element."); + } + + this.updateElement = (Element) updateElement.detach(); + } + + /** + * + * @return + */ + public String[] getVersionHref() { + return versionHref; + } + + /** + * + * @return + */ + public String[] getLabelName() { + return labelName; + } + + /** + * + * @return + */ + public String getWorkspaceHref() { + return workspaceHref; + } + + /** + * Returns a {@link DavPropertyNameSet}. If the DAV:update element contains + * a DAV:prop child element the properties specified therein are included + * in the set. Otherwise an empty set is returned. + * + * @return set listing the properties specified in the DAV:prop element indicating + * those properties that must be reported in the response body. + */ + public DavPropertyNameSet getPropertyNameSet() { + Element propElement = updateElement.getChild(DavConstants.XML_PROP, DavConstants.NAMESPACE); + if (propElement != null) { + return new DavPropertyNameSet(propElement); + } else { + return new DavPropertyNameSet(); + } + } + + /** + * + * @return + */ + public Element getUpdateElement() { + return updateElement; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,283 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.DavException; +import org.apache.jackrabbit.webdav.MultiStatus; +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.property.DavPropertySet; +import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; + +/** + * The VersionControlledResource represents in contrast to the + * VersionableResource a resource, that has already been put + * under version-control. This resource can be checked-in, checked-out and + * has its on {@link javax.jcr.version.VersionHistory version history}. + *

+ * RFC 3253 defines the following required properties for a + * version-controlled resource (vc-resource): + *

+ * + * checked-in vc-resource: + * + * + * checked-out vc-resource: + * + *

+ * In addition a version-controlled resource must support the following METHODS: + *

+ * + * checked-in vc-resource: + * + * + * checked-out vc-resource: + * + * + * @see DeltaVResource + * @see VersionableResource + */ +public interface VersionControlledResource extends VersionableResource { + + /** + * Methods defined for a checked-in version-controlled resource: CHECKOUT, UNCHECHKOUT, UPDATE, MERGE, LABEL + */ + public String methods_checkedIn = "CHECKOUT, UNCHECHKOUT, UPDATE, MERGE, LABEL"; + /** + * Methods defined for a checked-out version-controlled resource: CHECKIN, MERGE + */ + public String methods_checkedOut = "CHECKIN, MERGE"; + + /** + * The DAV:auto-version property determines how it responds to a method that + * attempts to modify its content or dead properties. Possible responses + * include various combinations of automated checkout, write lock and checkin + * as well as failure until the resource is explicitely checked-out.
+ * See RFC 3253 for a detailed + * description. + */ + public static final DavPropertyName AUTO_VERSION = DavPropertyName.create("auto-version", DeltaVConstants.NAMESPACE); + + /** + * The computed property DAV:version-history identifies the version history + * resource for the DAV:checked-in or DAV:checked-out version of this + * version-controlled resource.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT version-history (href)>
+     * 
+ */ + public static final DavPropertyName VERSION_HISTORY = DavPropertyName.create("version-history", DeltaVConstants.NAMESPACE); + + /** + * The DAV:checked-in property appears on a checked-in version-controlled + * resource, and identifies the base version of this version-controlled + * resource. This property is removed when the resource is checked out, and + * then added back (identifying a new version) when the resource is checked + * back in.
+ * This property is defined to have the following format: + *
+     * <!ELEMENT checked-in (href)>
+     * 
+ */ + public static final DavPropertyName CHECKED_IN = DavPropertyName.create("checked-in", DeltaVConstants.NAMESPACE); + + /** + * The DAV:checked-out property identifies the base version of this resource. + * It is the same that was identified by the DAV:checked-in property at the + * time the resource was checked out. This property is removed when the + * resource is checked in.
+ * This property is defined to have the following format: + *
+     * <!ELEMENT checked-out (href)>
+     * 
+ * + * @see #CHECKED_IN + */ + public static final DavPropertyName CHECKED_OUT = DavPropertyName.create("checked-out", DeltaVConstants.NAMESPACE); + + /** + * The DAV:predecessor-set property of a version-controlled resource points + * to those version resources, that are scheduled to become the predecessors + * of this resource when it is back checked-in. This property is not + * protected, however a server may reject attempts to modify the + * DAV:predecessor-set of a version-controlled resource.
+ * This property is defined to have the following format: + *
+     * <!ELEMENT predecessor-set (href+)>
+     * 
+ * + * @see #checkin() + * @see VersionResource#PREDECESSOR_SET + */ + public static final DavPropertyName PREDECESSOR_SET = DavPropertyName.create("predecessor-set", DeltaVConstants.NAMESPACE); + + /** + * This property determines the DAV:checkin-fork property of the version + * that results from checking in this resource. + */ + public static final DavPropertyName CHECKIN_FORK = DavPropertyName.create("checkin-fork", DeltaVConstants.NAMESPACE); + + /** + * This property determines the DAV:checkout-fork property of the version + * that results from checking in this resource. + */ + public static final DavPropertyName CHECKOUT_FORK = DavPropertyName.create("checkout-fork", DeltaVConstants.NAMESPACE); + + /** + * This property identifies each version that is to be merged into this + * checked-out resource. This property is set, whenever a MERGE request + * with the DAV:no-auto-merge flag succeeded. The client then must confirm + * each single merge by removing the version from the DAV:merge-set or + * moving it the the versions DAV:predecessor-set.
+ * This property is defined to have the following format: + *
+     * <!ELEMENT merge-set (href*)>
+     * 
+ * + * @see #merge(MergeInfo) + * @see #resolveMergeConflict(DavPropertySet, DavPropertyNameSet) + */ + public static final DavPropertyName MERGE_SET = DavPropertyName.create("merge-set", DeltaVConstants.NAMESPACE); + + /** + * The DAV:auto-merge-set property identifies each version that the server + * has merged into this checked-out resource. The client should confirm that + * the merge has been performed correctly before moving a URL from the + * DAV:auto-merge-set to the DAV:predecessor-set of a checked-out resource.
+ * This property is defined to have the following format: + *
+     * <!ELEMENT auto-merge-set (href*)>
+     * 
+ * + * @see #merge(MergeInfo) + * @see #resolveMergeConflict(DavPropertySet, DavPropertyNameSet) + */ + public static final DavPropertyName AUTO_MERGE_SET = DavPropertyName.create("auto-merge-set", DeltaVConstants.NAMESPACE); + + /** + * Perform a checkin on the version controlled resource. + * + * @return String representing the location of the version created by the + * checkin. + * @throws DavException if an error occurs. + */ + public String checkin() throws DavException; + + /** + * Perform a checkout on the version controlled resource. + * + * @throws DavException + */ + public void checkout() throws DavException; + + /** + * Perform an uncheckout on the version controlled resource. + * + * @throws DavException + */ + public void uncheckout() throws DavException; + + /** + * Perform an update on this resource using the specified {@link UpdateInfo}. + * + * @param updateInfo + * @return MultiStatus containing the list of resources that + * have been modified by this update call. + * @throws DavException + */ + public MultiStatus update(UpdateInfo updateInfo) throws DavException; + + /** + * Perform a merge on this resource using the specified {@link MergeInfo}. + * + * @param mergeInfo + * @return MultiStatus containing the list of resources that + * have been modified. + * @throws DavException + */ + public MultiStatus merge(MergeInfo mergeInfo) throws DavException; + + /** + * Resolve one or multiple merge conflicts present on this resource. Please + * note that the 'setProperties' or 'removeProperties' set my contain additional + * resource properties, that need to be changed. Those properties are left + * untouched, whereas the {@link #AUTO_MERGE_SET}, {@link #MERGE_SET} and + * the {@link #PREDECESSOR_SET} are removed from the list upon successful + * resolution of a merge conflict.
+ * If the removeProperties or setProperties set do not contain any of the + * mentioned resource properties or if the value of those properties do + * not allow for a resolution of an existing merge conflict, this METHODS + * returns silently. + * + * @param setProperties + * @param removePropertyNames + * @throws DavException the set or remove property sets attempt to resolve + * a non-existing merge conflict of if another error occurs while resolving + * an existing conflict. + */ + public void resolveMergeConflict(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException; + + /** + * Modify the labels of the version referenced by the DAV:checked-in property + * of this checked-in version-controlled resource. If the resource is not + * checked-in the request must fail. + * + * @param labelInfo + * @throws org.apache.jackrabbit.webdav.DavException + * @see LabelInfo + * @see VersionResource#label(LabelInfo) for the pre- and postcondition of + * a successful LABEL request. + */ + public void label(LabelInfo labelInfo) throws DavException; + + /** + * Returns the VersionHistoryResource, that is referenced in the + * '{@link #VERSION_HISTORY version-history}' property. + * + * @return + * @throws DavException + */ + public VersionHistoryResource getVersionHistory() throws DavException; +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionControlledResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,73 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.DavException; + +/** + * VersionHistoryResource represents a collection that has + * all versions of a given version-controlled resource as members. + *

+ * RFC 3253 defines the following required properties for a version history: + *

+ *

+ * In addition a version history resource must support the following METHODS: + *

+ * + * NOTE: the {@link org.apache.jackrabbit.webdav.DavConstants#PROPERTY_RESOURCETYPE DAV:resourcetype} + * property must indicate 'DAV:version-history'. + * + * @see DeltaVResource + * @see ResourceType#VERSION_HISTORY + */ +public interface VersionHistoryResource extends DeltaVResource { + + // supported METHODS: same as DeltaVResource > set to empty string + public static final String COMPLIANCE_CLASS = ""; + // supported METHODS: same as DeltaVResource > set to empty string + public static final String METHODS = ""; + + /** + * Computed (protected) property identifying the root version of this version + * history. + */ + public static final DavPropertyName ROOT_VERSION = DavPropertyName.create("root-version", DeltaVConstants.NAMESPACE); + + /** + * The protected property DAV:version-set identifies each version of this + * version history. + * + * @see #getVersions() + */ + public static final DavPropertyName VERSION_SET = DavPropertyName.create("version-set", DeltaVConstants.NAMESPACE); + + /** + * Returns an array of VersionResources containing all versions + * that are a member of this resource. + * + * @return all VersionResources that belong to this version history. + * @throws org.apache.jackrabbit.webdav.DavException + * @see #VERSION_SET + */ + public VersionResource[] getVersions() throws DavException; +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionHistoryResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,167 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.DavException; + +/** + * VersionResource is a resource that contains a copy of a particular + * state of a version-controlled resource. A new version resource is created whenever + * a checked-out version-controlled resource is checked-in. The server allocates + * a distinct new URL for each new version, and this URL will never be used to + * identify any resource other than that version. The content and dead properties + * of a version never change. + *

+ * RFC 3253 defines the following required properties for a version resource: + *

+ *

+ * In addition a version resource must support the following METHODS: + *

+ * + * @see DeltaVResource + */ +public interface VersionResource extends DeltaVResource { + + /** + * The version resource defines one additional method LABEL. + * + * @see DeltaVResource#METHODS + * @see org.apache.jackrabbit.webdav.DavResource#METHODS + */ + public String METHODS = "LABEL"; + + /** + * Required protected property 'DAV:label-name-set' for a version of a webdav + * resource introduced with the 'LabelInfo' feature. + * This property contains the labels that currently select this version.
+ * Property structure is defined as follows:
+ *
+     * <!ELEMENT label-name-set (label-name*)>
+     * <!ELEMENT label-name (#PCDATA)>
+     * PCDATA value: string
+     * 
+ */ + public static final DavPropertyName LABEL_NAME_SET = DavPropertyName.create("label-name-set", DeltaVConstants.NAMESPACE); + + /** + * The protected DAV:predecessor property identifies each predecessor of + * this version. Except for the root version, which has no predecessors, + * each version has at least one predecessor.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT predecessor-set (href*)>
+     * 
+ */ + public static final DavPropertyName PREDECESSOR_SET = DavPropertyName.create("predecessor-set", DeltaVConstants.NAMESPACE); + + /** + * The computed property DAV:successor-set identifies each version whose + * DAV:predecessor-set identifies this version.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT successor-set (href*)>
+     * 
+ * + */ + public static final DavPropertyName SUCCESSOR_SET = DavPropertyName.create("successor-set", DeltaVConstants.NAMESPACE); + + /** + * The computed property DAV:checkout-set identifies each checked-out + * resource whose DAV:checked-out property identifies this version.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT checkout-set (href*)>
+     * 
+ * + * @see VersionControlledResource#CHECKED_OUT + */ + public static final DavPropertyName CHECKOUT_SET = DavPropertyName.create("checkout-set", DeltaVConstants.NAMESPACE); + + /** + * The protected property DAV:version-name defines a human readable id for + * this version. The id defined to be unique within the version-history this + * version belongs to.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT version-name (#PCDATA)>
+     * PCDATA value: string
+     * 
+ */ + public static final DavPropertyName VERSION_NAME = DavPropertyName.create("version-name", DeltaVConstants.NAMESPACE); + + /** + * The computed property DAV:version-history identifies the version history + * that contains this version.
+ * The property is defined to have the following format: + *
+     * <!ELEMENT version-history (href)>
+     * 
+ */ + public static final DavPropertyName VERSION_HISTORY = DavPropertyName.create("version-history", DeltaVConstants.NAMESPACE); + + /** + * This property controls the behavior of CHECKOUT when a version already + * is checked out or has a successor. + */ + public static final DavPropertyName CHECKOUT_FORK = DavPropertyName.create("checkout-fork", DeltaVConstants.NAMESPACE); + + /** + * This property controls the behavior of CHECKIN when a version already + * has a successor. + */ + public static final DavPropertyName CHECKIN_FORK = DavPropertyName.create("checkin-fork", DeltaVConstants.NAMESPACE); + + /** + * Modify the labels of this version resource. The modifications (SET, ADD or + * REMOVE) are listed in the specified LabelInfo object.
+ * The case of a label name must be preserved when it is stored and retrieved. + *
If the type of modification is ADD, then the label must not yet occur on + * any other version within the same version history. In contrast a SET + * modification will move the indicated label to this version, if it existed + * with another version before. After a successful LABEL request the label + * must not appear with any other version in the same version history. + * + * @param labelInfo + * @throws org.apache.jackrabbit.webdav.DavException + * @see LabelInfo + */ + public void label(LabelInfo labelInfo) throws DavException; + + /** + * Returns the VersionHistoryResource, that is referenced in the + * {@link #VERSION_HISTORY DAV:version-history} property. + * + * @return + * @throws DavException + */ + public VersionHistoryResource getVersionHistory() throws DavException; +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,68 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version; + +import org.apache.jackrabbit.webdav.DavException; + +/** + * VersionableResource represents an extension to the basic + * {@link DeltaVResource}, that allows to adding version-control support. By + * calling {@link #addVersionControl()} resource is put under version control, + * thus the versionable resource turns into a version controlled resource. + *

+ * RFC 3253 defines the following required properties for a versionable resource: + *

+ *

+ * In addition a versionable resource must support the following METHODS: + *

+ * + * @see DeltaVResource + */ +public interface VersionableResource extends DeltaVResource { + + /** + * No extra compliance class defined, therefore set to empty string + */ + public static final String COMPLIANCE_CLASS = ""; + + /** + * The versionable resource defines one additional method VERSION-CONTROL. + * + * @see DeltaVResource#METHODS + * @see org.apache.jackrabbit.webdav.DavResource#METHODS + */ + public String METHODS = "VERSION-CONTROL"; + + /** + * Converts this versionable resource into a version-controlled resource. If + * this resource is already version-controlled this resource is not affected. + * If however, this resource is not versionable an DavException + * (error code: {@link org.apache.jackrabbit.webdav.DavServletResponse#SC_METHOD_NOT_ALLOWED} + * is thrown. The same applies, if this resource is versionable but its + * current state does not allow to made it a version-controlled one or + * if any other error occurs. + * + * @throws org.apache.jackrabbit.webdav.DavException + */ + public void addVersionControl() throws DavException; +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/VersionableResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/package.html URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/package.html?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/package.html (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/package.html Sun Mar 6 06:02:39 2005 @@ -0,0 +1,4 @@ + +Interfaces and classes used to cover functionality defined by +RFC 3253: Versioning Extensions to WebDAV. + \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/package.html ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java?view=auto&rev=156314 ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java (added) +++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java Sun Mar 6 06:02:39 2005 @@ -0,0 +1,230 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.version.report; + +import org.apache.log4j.Logger; +import org.apache.jackrabbit.webdav.*; +import org.apache.jackrabbit.webdav.property.DavProperty; +import org.apache.jackrabbit.webdav.property.DavPropertyName; +import org.apache.jackrabbit.webdav.property.HrefProperty; +import org.apache.jackrabbit.webdav.property.AbstractDavProperty; +import org.apache.jackrabbit.webdav.version.DeltaVConstants; +import org.apache.jackrabbit.webdav.version.DeltaVResource; +import org.jdom.Element; +import org.jdom.Attribute; +import org.jdom.Namespace; +import org.jdom.Document; + +import java.util.*; + +/** + * ExpandPropertyReport encapsulates the DAV:expand-property report, + * that provides a mechanism for retrieving in one request the properties from + * the resources identified by those DAV:href elements. It should be supported by + * all resources that support the REPORT method. + *

+ * RFC 3253 specifies the following required format for the request body: + *

+ * <!ELEMENT expand-property (property*)>
+ * <!ELEMENT property (property*)>
+ * <!ATTLIST property name NMTOKEN #REQUIRED>
+ * name value: a property element type
+ * <!ATTLIST property namespace NMTOKEN "DAV:">
+ * namespace value: an XML namespace
+ * 
+ * NOTE: any DAV:property elements defined in the request body, that does not + * represent {@link HrefProperty} is treated as in a common PROPFIND request. + * + * @see DeltaVConstants#XML_EXPAND_PROPERTY + * @see DeltaVConstants#XML_PROPERTY + */ +public class ExpandPropertyReport implements Report, DeltaVConstants { + + private static Logger log = Logger.getLogger(ExpandPropertyReport.class); + + private DeltaVResource resource; + private ReportInfo info; + private List properties; + + /** + * Returns {@link ReportType#EXPAND_PROPERTY}. + * + * @return + * @see Report#getType() + */ + public ReportType getType() { + return ReportType.EXPAND_PROPERTY; + } + + /** + * Set the target resource. + * + * @param resource + * @throws IllegalArgumentException if the specified resource is null + * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource) + */ + public void setResource(DeltaVResource resource) throws IllegalArgumentException { + if (resource == null) { + throw new IllegalArgumentException("The resource specified must not be null."); + } + this.resource = resource; + } + + /** + * Set the ReportInfo. + * + * @param info + * @throws IllegalArgumentException if the given ReportInfo + * does not contain a DAV:expand-property element. + * @see Report#setInfo(ReportInfo) + */ + public void setInfo(ReportInfo info) throws IllegalArgumentException { + if (info == null || !XML_EXPAND_PROPERTY.equals(info.getReportElement().getName())) { + throw new IllegalArgumentException("DAV:expand-property element expected."); + } + this.info = info; + properties = info.getReportElement().getChildren(XML_PROPERTY, NAMESPACE); + } + + /** + * Run the report + * + * @return Xml Document as defined by + * RFC 2518 + * @throws DavException + * @see Report#toXml() + */ + public Document toXml() throws DavException { + if (info == null || resource == null) { + throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while running DAV:version-tree report"); + } + + MultiStatus ms = new MultiStatus(); + buildMultiStatus(resource, info.getDepth(), ms); + return ms.toXml(); + } + + /** + * Fills the specified MultiStatus object by generating a + * MultiStatusResponse for the given resource (and + * its member according to the depth value). + * + * @param res + * @param depth + * @param ms + * @throws DavException + * @see #getResponse(DavResource, List) + */ + private void buildMultiStatus(DavResource res, int depth, MultiStatus ms) + throws DavException { + MultiStatusResponse response = getResponse(res, properties); + ms.addResponse(response); + if (depth > 0) { + DavResourceIterator it = res.getMembers(); + while (it.hasNext()) { + buildMultiStatus(it.nextResource(), depth-1, ms); + } + } + } + + /** + * Builds a MultiStatusResponse for the given resource respecting + * the properties specified. Any property that represents a {@link HrefProperty} + * is expanded: It's name equals the name of a valid {@link HrefProperty}. + * However the value of that given property (consisting of one or multiple DAV:href elements) + * is replaced by the Xml representation of a separate + * {@link MultiStatusResponse multistatus responses} for the + * resource referenced by the given DAV:href elements. The responses may + * themselves have properties, which are defined by the separate list. + * + * @param res + * @param propertyList + * @return MultiStatusResponse for the given resource. + * @see ExpandProperty + */ + private MultiStatusResponse getResponse(DavResource res, List propertyList) { + MultiStatusResponse resp = new MultiStatusResponse(res.getHref()); + Iterator propIter = propertyList.iterator(); + while (propIter.hasNext()) { + Element propertyElem = (Element) propIter.next(); + Attribute nameAttr = propertyElem.getAttribute(ATTR_NAME); + if (nameAttr == null) { + // NOTE: this is not valid according to the DTD + continue; + } + Attribute namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE); + + String name = nameAttr.getValue(); + Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr.getValue()) : NAMESPACE; + + DavPropertyName propName = DavPropertyName.create(name, namespace); + DavProperty p = res.getProperty(propName); + if (p != null) { + if (p instanceof HrefProperty && res instanceof DeltaVResource) { + resp.add(new ExpandProperty((DeltaVResource)res, (HrefProperty)p, propertyElem.getChildren(XML_PROPERTY, NAMESPACE))); + } else { + resp.add(p); + } + } else { + resp.add(propName, DavServletResponse.SC_NOT_FOUND); + } + } + return resp; + } + + //--------------------------------------------------------< inner class >--- + /** + * ExpandProperty extends DavProperty. It's name + * equals the name of a valid {@link HrefProperty}. However the value of + * that given property (consisting of one or multiple DAV:href elements) + * is replaced by the Xml representation of a separate + * {@link MultiStatusResponse multistatus responses} for the + * resource referenced to by the given DAV.:href elements. The responses may + * themselves have properties, which are defined by the separate list. + */ + private class ExpandProperty extends AbstractDavProperty { + + private List valueList = new ArrayList(); + + /** + * Create a new ExpandProperty. + * + * @param hrefProperty + * @param propertyList + */ + private ExpandProperty(DeltaVResource deltaVResource, HrefProperty hrefProperty, List propertyList) { + super(hrefProperty.getName(), hrefProperty.isProtected()); + try { + DavResource[] refResource = deltaVResource.getReferenceResources(hrefProperty.getName()); + for (int i = 0; i < refResource.length; i++) { + MultiStatusResponse resp = getResponse(refResource[i], propertyList); + valueList.add(resp.toXml()); + } + } catch (DavException e) { + // invalid references or unknown property + log.error(e.getMessage()); + } + } + + /** + * Returns + * @return + */ + public Object getValue() { + return valueList; + } + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java ------------------------------------------------------------------------------ svn = Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ExpandPropertyReport.java ------------------------------------------------------------------------------ svn:eol-style = native