jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r156314 [15/15] - in incubator/jackrabbit/trunk/contrib/jcr-server: ./ client/ client/src/ client/src/java/ client/src/java/org/ client/src/java/org/apache/ client/src/java/org/apache/jackrabbit/ client/src/java/org/apache/jackrabbit/client/ server/ server/src/ server/src/java/ server/src/java/org/ server/src/java/org/apache/ server/src/java/org/apache/jackrabbit/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/server/simple/dav/ server/src/java/org/apache/jackrabbit/server/simple/dav/lock/ server/src/java/org/apache/jackrabbit/webdav/ server/src/java/org/apache/jackrabbit/webdav/spi/ server/src/java/org/apache/jackrabbit/webdav/spi/lock/ server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/ server/src/java/org/apache/jackrabbit/webdav/spi/observation/ server/src/java/org/apache/jackrabbit/webdav/spi/search/ server/src/java/org/apache/jackrabbit/webdav/spi/transaction/ server/src/java/org/apache/jackrabbit/webdav/spi/version/ server/src/java/org/apache/jackrabbit/webdav/spi/version/report/ webapp/ webapp/src/ webapp/src/webapp/ webapp/src/webapp/WEB-INF/ webapp/src/webapp/WEB-INF/repository/ webdav/ webdav/src/ webdav/src/java/ webdav/src/java/org/ webdav/src/java/org/apache/ webdav/src/java/org/apache/jackrabbit/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/lock/ webdav/src/java/org/apache/jackrabbit/webdav/observation/ webdav/src/java/org/apache/jackrabbit/webdav/ordering/ webdav/src/java/org/apache/jackrabbit/webdav/property/ webdav/src/java/org/apache/jackrabbit/webdav/search/ webdav/src/java/org/apache/jackrabbit/webdav/transaction/ webdav/src/java/org/apache/jackrabbit/webdav/util/ webdav/src/java/org/apache/jackrabbit/webdav/version/ webdav/src/java/org/apache/jackrabbit/webdav/version/report/
Date Sun, 06 Mar 2005 14:03:12 GMT
Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,161 @@
+/*
+ * 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.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.version.VersionControlledResource;
+import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.jdom.Element;
+import org.jdom.Document;
+
+import java.util.List;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * <code>LocateByHistoryReport</code> encapsulates the DAV:locate-by-hisotry
+ * report, that may be used to locate a version-controlled resource for that
+ * version history. The DAV:locate-by-history report can be applied to a collection
+ * to locate the collection member that is a version-controlled resource for a
+ * specified version history resource.
+ *
+ * <pre>
+ * &lt;!ELEMENT locate-by-history (version-history-set, prop)&gt;
+ * &lt;!ELEMENT version-history-set (href+)&gt;
+ * </pre>
+ */
+public class LocateByHistoryReport implements Report, DeltaVConstants {
+
+    private static Logger log = Logger.getLogger(LocateByHistoryReport.class);
+
+    private ReportInfo info;
+    private HashSet vhHrefSet = new HashSet();
+    private DeltaVResource resource;
+
+    /**
+     *
+     * @return
+     * @see Report#getType()
+     */
+    public ReportType getType() {
+        return ReportType.LOCATE_BY_HISTORY;
+    }
+
+    /**
+     * Set the DeltaVResource.
+     *
+     * @param resource
+     * @throws IllegalArgumentException if the specified resource is not a {@link VersionControlledResource}.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) throws IllegalArgumentException {
+        if (resource instanceof VersionControlledResource) {
+            this.resource = resource;
+        } else {
+            throw new IllegalArgumentException("DAV:version-tree report can only be created
for version-controlled resources and version resources.");
+        }
+    }
+
+    /**
+     * Set the <code>ReportInfo</code>
+     *
+     * @param info
+     * @throws IllegalArgumentException if the given <code>ReportInfo</code>
+     * does not contain a DAV:version-tree element.
+     * @see Report#setInfo(ReportInfo)
+     */
+    public void setInfo(ReportInfo info) throws IllegalArgumentException {
+        if (info == null || !XML_LOCATE_BY_HISTORY.equals(info.getReportElement().getName()))
{
+            throw new IllegalArgumentException("DAV:locate-by-history element expected.");
+        }
+        Element versionHistorySet = info.getReportElement().getChild(XML_VERSION_HISTORY_SET,
NAMESPACE);
+        if (versionHistorySet == null) {
+            throw new IllegalArgumentException("The DAV:locate-by-history element must contain
a DAV:version-history-set child.");
+        }
+
+        List l = versionHistorySet.getChildren(DavConstants.XML_HREF, DavConstants.NAMESPACE);
+        if (l != null && !l.isEmpty()) {
+            Iterator it = l.iterator();
+            while (it.hasNext()) {
+                String href = ((Element)it.next()).getText();
+                if (href != null) {
+                    vhHrefSet.add(href);
+                }
+            }
+        }
+        this.info = info;
+    }
+
+    /**
+     * Run the report.
+     *
+     * @return Xml <code>Document</code> representing the report in the required
+     * format.
+     * @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:locate-by-history report");
+        }
+
+        MultiStatus ms = new MultiStatus();
+        buildResponse(resource, info.getPropertyNameSet(), info.getDepth(), ms);
+        return ms.toXml();
+    }
+
+    /**
+     * Fill the <code>MultiStatus</code> with the <code>MultiStatusResponses</code>
+     * generated for the specified resource and its members according to the
+     * depth value.
+     *
+     * @param res
+     * @param propNameSet
+     * @param depth
+     * @param ms
+     * @throws DavException
+     */
+    private void buildResponse(DavResource res, DavPropertyNameSet propNameSet,
+                               int depth, MultiStatus ms) throws DavException {
+        // loop over members first, since this report only list members
+        DavResourceIterator it = res.getMembers();
+        while (!vhHrefSet.isEmpty() && it.hasNext()) {
+            DavResource childRes = it.nextResource();
+            if (childRes instanceof VersionControlledResource) {
+                try {
+                    VersionHistoryResource vhr = ((VersionControlledResource)childRes).getVersionHistory();
+                    if (vhHrefSet.remove(vhr.getHref())) {
+                        if (propNameSet.isEmpty()) {
+                            ms.addResourceStatus(childRes, DavServletResponse.SC_OK, 0);
+                        } else {
+                            ms.addResourceProperties(childRes, propNameSet, 0);
+                        }
+                    }
+                } catch (DavException e) {
+                    log.info(e.getMessage());
+                }
+            }
+            // traverse subtree
+            if (depth > 0) {
+                buildResponse(it.nextResource(), propNameSet, depth-1, ms);
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/LocateByHistoryReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,64 @@
+/*
+ * 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.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.jdom.Document;
+
+/**
+ * The <code>Report</code> interface defines METHODS needed in order to respond
+ * to a REPORT request. The REPORT method is a required feature to all
+ * DeltaV resources.
+ *
+ * @see DeltaVResource#getReport(ReportInfo)
+ */
+public interface Report {
+
+    /**
+     * Returns the registered type of this report.
+     *
+     * @return the type of this report.
+     */
+    public ReportType getType();
+
+    /**
+     * Set the <code>DeltaVResource</code> for which this report was requested.
+     *
+     * @param resource
+     */
+    public void setResource(DeltaVResource resource);
+
+    /**
+     * Set the <code>ReportInfo</code> as specified by the REPORT request body,
+     * that defines the details for this report.
+     *
+     * @param info providing in detail requirements for this report.
+     */
+    public void setInfo(ReportInfo info);
+
+    /**
+     * Returns the report {@link Document Xml document} defined by the this
+     * <code>ReportType</code>. The document will be returned in the response
+     * body.
+     *
+     * @return Xml <code>Document</code> object representing the generated report
+     * in the proper format.
+     * @throws DavException if an error occurs while running the report or
+     * creating the <code>Document</code>.
+     */
+    public Document toXml() throws DavException;
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/Report.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,83 @@
+/*
+ * 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.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.jdom.Element;
+
+/**
+ * The <code>ReportInfo</code> class encapsulates the body of a REPORT request.
+ * <a href="http://www.ietf.org/rfc/rfc3253.txt">RFC 3253</a> the top Xml element
+ * being the name of the requested report. In addition a Depth header may
+ * be present (default value: {@link DavConstants#DEPTH_0}).
+ */
+public class ReportInfo {
+
+    private static Logger log = Logger.getLogger(ReportInfo.class);
+
+    private final Element reportElement;
+    private final int depth;
+
+    /**
+     * Create a new <code>ReportInfo</code> object.
+     *
+     * @param reportElement
+     * @param depth Depth value as retrieved from the {@link DavConstants#HEADER_DEPTH}.
+     */
+    public ReportInfo(Element reportElement, int depth) {
+        this.reportElement = reportElement;
+        this.depth = depth;
+    }
+
+    /**
+     * Returns the Xml element specifying the requested report.
+     *
+     * @return reportElement
+     */
+    public Element getReportElement() {
+        return reportElement;
+    }
+
+    /**
+     * Returns the depth field. The request must be applied separately to the
+     * collection itself and to all members of the collection that satisfy the
+     * depth value.
+     *
+     * @return depth
+     */
+    public int getDepth() {
+        return depth;
+    }
+
+    /**
+     * Returns a <code>DavPropertyNameSet</code> providing the property names
present
+     * in an eventual {@link DavConstants#XML_PROP} child element. If no such
+     * child element is present an empty set is returned.
+     *
+     * @return {@link DavPropertyNameSet} providing the property names present
+     * in an eventual {@link DavConstants#XML_PROP DAV:prop} child element or an empty set.
+     */
+    public DavPropertyNameSet getPropertyNameSet() {
+        Element propElement = reportElement.getChild(DavConstants.XML_PROP, DavConstants.NAMESPACE);
+        if (propElement != null) {
+            return new DavPropertyNameSet(propElement);
+        } else {
+            return new DavPropertyNameSet();
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,169 @@
+/*
+* Copyright 2004 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.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import java.util.HashMap;
+
+/**
+ * <code>ReportType</code>...
+ */
+public class ReportType implements DeltaVConstants {
+
+    private static Logger log = Logger.getLogger(ReportType.class);
+
+    private static final HashMap types = new HashMap();
+
+    public static final ReportType VERSION_TREE = register(XML_VERSION_TREE, NAMESPACE, VersionTreeReport.class);
+    public static final ReportType EXPAND_PROPERTY = register(XML_EXPAND_PROPERTY, NAMESPACE,
ExpandPropertyReport.class);
+    public static final ReportType LOCATE_BY_HISTORY = register(XML_LOCATE_BY_HISTORY, NAMESPACE,
LocateByHistoryReport.class);
+
+    private final String name;
+    private final Namespace namespace;
+    private final Class reportClass;
+
+    /**
+     * Private constructor
+     *
+     * @see #register(String, Namespace, Class)
+     */
+    private ReportType(String name, Namespace namespace, Class reportClass) {
+	this.name = name;
+	this.namespace = namespace;
+	this.reportClass = reportClass;
+    }
+
+    /**
+     * Creates a new {@link Report} with this type.
+     *
+     * @return
+     * @throws DavException
+     */
+    public Report createReport() throws DavException {
+	try {
+	    return (Report) reportClass.getConstructor(new Class[0]).newInstance(new Object[0]);
+	} catch (Exception e) {
+	    // should never occur
+	    throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to register
Report.");
+	}
+    }
+
+    /**
+     * Returns an Xml element representing this report type
+     *
+     * @return Xml representation
+     */
+    public Element toXml() {
+	return new Element(name, namespace);
+    }
+
+    /**
+     * Returns true if this <code>ReportType</code> is requested by the given
+     * <code>ReportInfo</code>
+     *
+     * @param reqInfo
+     * @return
+     */
+    public boolean isRequestedReportType(ReportInfo reqInfo) {
+	if (reqInfo != null) {
+	    Element elem = reqInfo.getReportElement();
+	    if (elem != null) {
+		return name.equals(elem.getName()) && namespace.equals(elem.getNamespace());
+	    }
+	}
+	return false;
+    }
+
+    /**
+     * Register the report type with the given name, namespace and class, that can
+     * run that report.
+     *
+     * @param name
+     * @param namespace
+     * @param reportClass
+     * @return
+     * @throws IllegalArgumentException if either parameter is <code>null</code>
or
+     * if the given class does not implement the {@link Report} interface or if
+     * it does not provide an empty constructor.
+     */
+    public static ReportType register(String name, Namespace namespace, Class reportClass)
{
+	if (name == null || namespace == null || reportClass == null) {
+	    throw new IllegalArgumentException("A ReportType cannot be registered with a null name,
namespace or report class");
+	}
+
+	String key = buildKey(namespace, name);
+	if (types.containsKey(key)) {
+	    return (ReportType) types.get(key);
+	} else {
+	    // test if this report class has an empty constructor and implements Report interface
+	    boolean isValidClass = false;
+	    Class[] interfaces = reportClass.getInterfaces();
+	    for (int i = 0; i < interfaces.length && !isValidClass; i++) {
+		isValidClass = (interfaces[i] == Report.class);
+	    }
+	    if (!isValidClass) {
+		throw new IllegalArgumentException("The specified report class must implement the Report
interface.");
+	    }
+
+	    try {
+		reportClass.getConstructor(new Class[0]);
+	    } catch (NoSuchMethodException e) {
+		throw new IllegalArgumentException("The specified report class must provide a default constructor.");
+	    }
+
+	    ReportType type = new ReportType(name, namespace, reportClass);
+	    types.put(key, type);
+	    return type;
+	}
+    }
+
+    /**
+     * Return the <code>ReportType</code> requested by the given report info
object.
+     *
+     * @param reportInfo
+     * @return the requested <code>ReportType</code>
+     * @throws IllegalArgumentException if the reportInfo is <code>null</code>
or
+     * if the requested report type has not been registered yet.
+     */
+    public static ReportType getType(ReportInfo reportInfo) {
+	if (reportInfo == null) {
+	    throw new IllegalArgumentException("ReportInfo must not be null.");
+	}
+	String key = buildKey(reportInfo.getReportElement().getNamespace(), reportInfo.getReportElement().getName());
+	if (types.containsKey(key)) {
+	    return (ReportType) types.get(key);
+	} else {
+	    throw new IllegalArgumentException("The request report '"+key+"' has not been registered
yet.");
+	}
+    }
+
+    /**
+     * Build the key from the given namespace and name.
+     *
+     * @param namespace
+     * @param name
+     * @return key identifying the report with the given namespace and name
+     */
+    private static String buildKey(Namespace namespace, String name) {
+	return "{" + namespace.getURI() + "}" + name;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,115 @@
+/*
+ * 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.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
+import org.jdom.Element;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * <code>SupportedReportSetProperty</code> represents the DAV:supported-report-set
+ * property defined by RFC 3253. It identifies the reports that are supported by
+ * the given resource.
+ * <pre>
+ * &lt;!ELEMENT supported-report-set (supported-report*)&gt;
+ * &lt;!ELEMENT supported-report report&gt;
+ * &lt;!ELEMENT report ANY&gt;
+ * ANY value: a report element type
+ * </pre>
+ */
+public class SupportedReportSetProperty extends AbstractDavProperty {
+
+    private static Logger log = Logger.getLogger(SupportedReportSetProperty.class);
+
+    private final HashSet reportTypes = new HashSet();
+
+    /**
+     * Create a new empty <code>SupportedReportSetProperty</code>.
+     */
+    public SupportedReportSetProperty() {
+        super(DeltaVConstants.SUPPORTED_REPORT_SET, true);
+    }
+
+    /**
+     * Create a new <code>SupportedReportSetProperty</code> property.
+     *
+     * @param reportTypes that are supported by the resource having this property.
+     */
+    public SupportedReportSetProperty(ReportType[] reportTypes) {
+        super(DeltaVConstants.SUPPORTED_REPORT_SET, true);
+        for (int i = 0; i < reportTypes.length; i++) {
+            addReportType(reportTypes[i]);
+        }
+    }
+
+    /**
+     * Add an additional report type to this property's value.
+     *
+     * @param reportType
+     */
+    public void addReportType(ReportType reportType) {
+        reportTypes.add(reportType);
+    }
+
+    /**
+     * Returns true if the report type indicated in the specified <code>RequestInfo</code>
+     * object is included in the supported reports.
+     *
+     * @param reqInfo
+     * @return true if the requested report is supported.
+     */
+    public boolean isSupportedReport(ReportInfo reqInfo) {
+        Iterator it = reportTypes.iterator();
+        while (it.hasNext()) {
+            ReportType rt = (ReportType)it.next();
+            if (rt.isRequestedReportType(reqInfo)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the Xml representation of this property.
+     *
+     * @return Xml representation listing all supported reports
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#toXml()
+     */
+    public Element toXml() {
+        Element elem = getName().toXml();
+        Iterator it = reportTypes.iterator();
+        while (it.hasNext()) {
+	    Element sr = new Element(DeltaVConstants.XML_SUPPORTED_REPORT, DeltaVConstants.NAMESPACE);
+            Element r = new Element(DeltaVConstants.XML_REPORT, DeltaVConstants.NAMESPACE);
+	    elem.addContent(sr.addContent(r.addContent(((ReportType)it.next()).toXml())));
+        }
+        return elem;
+    }
+
+    /**
+     * Returns a set of report types.
+     *
+     * @return set of {@link ReportType}.
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#getValue()
+     */
+    public Object getValue() {
+        return reportTypes;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/SupportedReportSetProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.version.*;
+import org.jdom.Document;
+
+/**
+ * <code>VersionTreeReport</code> encapsulates the DAV:version-tree report.
+ * It describes the requested properties of all the versions in the version
+ * history of a version. The DAV:version-tree report must be supported by all
+ * version resources and all version-controlled resources.
+ */
+public class VersionTreeReport implements Report, DeltaVConstants {
+
+    private static Logger log = Logger.getLogger(VersionTreeReport.class);
+
+    private ReportInfo info;
+    private DeltaVResource resource;
+
+    public ReportType getType() {
+        return ReportType.VERSION_TREE;
+    }
+
+    /**
+     * Set the <code>DeltaVResource</code> used to register this report.
+     *
+     * @param resource
+     * @throws IllegalArgumentException if the given resource is neither
+     * {@link VersionControlledResource} nor {@link VersionResource}.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) throws IllegalArgumentException {
+        if (resource instanceof VersionControlledResource || resource instanceof VersionResource)
{
+            this.resource = resource;
+        } else {
+            throw new IllegalArgumentException("DAV:version-tree report can only be created
for version-controlled resources and version resources.");
+        }
+    }
+
+    /**
+     * Set the <code>ReportInfo</code> as specified by the REPORT request body,
+     * that defines the details for this report.
+     *
+     * @param info
+     * @throws IllegalArgumentException if the given <code>ReportInfo</code>
+     * does not contain a DAV:version-tree element.
+     * @see Report#setInfo(ReportInfo)
+     */
+    public void setInfo(ReportInfo info) throws IllegalArgumentException {
+        if (info == null || !XML_VERSION_TREE.equals(info.getReportElement().getName()))
{
+            throw new IllegalArgumentException("DAV:version-tree element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Runs the DAV:version-tree report.
+     *
+     * @return Xml <code>Document</code> representing the report in the required
+     * format.
+     * @throws DavException if the resource or the info field are <code>null</code>
+     * or if any other error occurs.
+     * @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();
+        buildResponse(resource, info.getPropertyNameSet(), info.getDepth(), ms);
+        return ms.toXml();
+    }
+
+    /**
+     *
+     * @param res
+     * @param propNameSet
+     * @param depth
+     * @param ms
+     * @throws DavException
+     */
+    private void buildResponse(DavResource res, DavPropertyNameSet propNameSet,
+                               int depth, MultiStatus ms) throws DavException {
+        VersionResource[] versions = getVersions(res);
+        for (int i = 0; i < versions.length; i++) {
+            if (propNameSet.isEmpty()) {
+                ms.addResourceStatus(versions[i], DavServletResponse.SC_OK, 0);
+            } else {
+                ms.addResourceProperties(versions[i], propNameSet, 0);
+            }
+        }
+        if (depth > 0) {
+            DavResourceIterator it = res.getMembers();
+            while (it.hasNext()) {
+                buildResponse(it.nextResource(), propNameSet, depth-1, ms);
+            }
+        }
+    }
+
+    /**
+     * Retrieve all versions from the version history associated with the given
+     * resource. If the versions cannot be retrieved from the given resource
+     * an exception is thrown.
+     *
+     * @param res
+     * @return array of {@link VersionResource}s or an empty array if the versions
+     * could not be retrieved.
+     * @throws DavException if the version history could not be retrieved from
+     * the given resource or if an error occurs while accessing the versions
+     * from the version history resource.
+     */
+    private static VersionResource[] getVersions(DavResource res) throws DavException {
+        VersionResource[] versions = new VersionResource[0];
+        if (res instanceof VersionControlledResource) {
+            versions = ((VersionControlledResource)res).getVersionHistory().getVersions();
+        } else if (res instanceof VersionResource) {
+            versions = ((VersionResource)res).getVersionHistory().getVersions();
+        }
+        return versions;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/VersionTreeReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/package.html?view=auto&rev=156314
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/package.html
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/package.html
Sun Mar  6 06:02:39 2005
@@ -0,0 +1,3 @@
+<body>
+Report interface and inplementation for default reports defined by RFC 3253.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/package.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message