jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r161660 [7/7] - in incubator/jackrabbit/trunk/contrib/jcr-server: ./ client/ client/src/java/org/apache/jackrabbit/webdav/ client/src/java/org/apache/jackrabbit/webdav/client/ client/src/java/org/apache/jackrabbit/webdav/client/methods/ server/ server/src/java/org/apache/jackrabbit/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ server/src/java/org/apache/jackrabbit/server/jcr/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/server/simple/dav/ server/src/java/org/apache/jackrabbit/webdav/simple/ 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/property/ 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/WEB-INF/ webdav/ webdav/src/java/org/apache/jackrabbit/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/header/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/lock/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/observation/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/property/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/search/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/transaction/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ webdav/src/java/org/apache/jackrabbit/webdav/lock/ webdav/src/java/org/apache/jackrabbit/webdav/search/
Date Sun, 17 Apr 2005 14:52:15 GMT
Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java Sun Apr 17 07:51:59 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.jcr.version;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.*;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.DefaultItemCollection;
+import org.apache.jackrabbit.webdav.*;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Item;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import java.util.ArrayList;
+
+/**
+ * <code>VersionHistoryItemCollection</code> represents a JCR version history.
+ *
+ * @see VersionHistory
+ */
+public class VersionHistoryItemCollection extends DefaultItemCollection
+        implements VersionHistoryResource {
+
+    private static Logger log = Logger.getLogger(VersionHistoryItemCollection.class);
+
+    /**
+     * Create a new <code>VersionHistoryItemCollection</code> resource.
+     *
+     * @param resourcePath
+     * @param session
+     * @param factory
+     */
+    public VersionHistoryItemCollection(DavResourceLocator resourcePath,
+                                        DavSession session, DavResourceFactory factory,
+                                        Item item) {
+        super(resourcePath, session, factory, item);
+        if (item == null || !(item instanceof VersionHistory)) {
+            throw new IllegalArgumentException("VersionHistory item expected.");
+        }
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(ItemResourceConstants.METHODS);
+        sb.append(", ").append(VersionHistoryResource.METHODS);
+        return sb.toString();
+    }
+
+    /**
+     * Removing a version resource is achieved by calling <code>removeVersion</code>
+     * on the versionhistory item this version belongs to.
+     *
+     * @throws DavException if the version does not exist or if an error occurs
+     * while deleting.
+     * @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void removeMember(DavResource member) throws DavException {
+        if (exists()) {
+            VersionHistory versionHistory = (VersionHistory) item;
+            try {
+                versionHistory.removeVersion(getResourceName(member.getHref(), true));
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        } else {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+    }
+    //-----------------------------------< VersionHistoryResource interface >---
+    /**
+     * Return an array of {@link VersionResource}s representing all versions
+     * present in the underlaying JCR version history.
+     *
+     * @return array of {@link VersionResource}s representing all versions
+     * present in the underlaying JCR version history.
+     * @throws DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
+     */
+    public VersionResource[] getVersions() throws DavException {
+        try {
+            VersionIterator vIter = ((VersionHistory)item).getAllVersions();
+            ArrayList l = new ArrayList();
+            while (vIter.hasNext()) {
+                DavResourceLocator versionLoc = getLocatorFromItem(vIter.nextVersion());
+                DavResource vr = createResourceFromLocator(versionLoc);
+                l.add(vr);
+            }
+            return (VersionResource[]) l.toArray(new VersionResource[l.size()]);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+    
+    //--------------------------------------------------------------------------
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        super.initProperties();
+
+        // change resourcetype defined by default item collection
+        properties.add(new ResourceType(ResourceType.VERSION_HISTORY));
+
+        // required root-version property for version-history resource
+        try {
+            String rootVersionResourcePath = ((VersionHistory)item).getRootVersion().getPath();
+            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, getLocatorFromResourcePath(rootVersionResourcePath).getHref(true), true));
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+
+        // required, protected version-set property for version-history resource
+        try {
+            VersionIterator vIter = ((VersionHistory)item).getAllVersions();
+            addHrefProperty(VersionHistoryResource.VERSION_SET, vIter, true);
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,201 @@
+/*
+ * 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.jcr.version;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.DefaultItemCollection;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.property.*;
+import org.apache.jackrabbit.webdav.version.*;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.apache.jackrabbit.JcrConstants;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * <code>VersionItemCollection</code> represents a JCR version.
+ *
+ * @see Version
+ */
+public class VersionItemCollection extends DefaultItemCollection
+        implements VersionResource {
+
+    private static Logger log = Logger.getLogger(VersionItemCollection.class);
+
+    /**
+     * Create a new <code>VersionItemCollection</code>.
+     *
+     * @param locator
+     * @param session
+     * @param factory
+     */
+    public VersionItemCollection(DavResourceLocator locator, DavSession session, DavResourceFactory factory, Item item) {
+        super(locator, session, factory, item);
+        if (item == null || !(item instanceof Version)) {
+            throw new IllegalArgumentException("Version item expected.");
+        }
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(ItemResourceConstants.METHODS);
+        sb.append(", ").append(VersionResource.METHODS);
+        return sb.toString();
+    }
+
+    //------------------------------------------< VersionResource interface >---
+    /**
+     * Modify the labels defined for the underlaying repository version.
+     *
+     * @param labelInfo
+     * @throws DavException
+     * @see VersionResource#label(org.apache.jackrabbit.webdav.version.LabelInfo)
+     * @see VersionHistory#addVersionLabel(String, String, boolean)
+     * @see VersionHistory#removeVersionLabel(String)
+     */
+    public void label(LabelInfo labelInfo) throws DavException {
+        if (labelInfo == null) {
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required.");
+        }
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        try {
+            VersionHistory vh = getVersionHistoryItem();
+            if (labelInfo.getType() == LabelInfo.TYPE_REMOVE) {
+                vh.removeVersionLabel(labelInfo.getLabelName());
+            } else if (labelInfo.getType() == LabelInfo.TYPE_ADD) {
+                // ADD: only add if not yet existing
+                vh.addVersionLabel(item.getName(), labelInfo.getLabelName(), false);
+            } else {
+                // SET: move label if already existing
+                vh.addVersionLabel(item.getName(), labelInfo.getLabelName(), true);
+            }
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Returns the {@link VersionHistory} associated with the repository version.
+     * Note: in contrast to a versionable node, the version history of a version
+     * item is always represented by its nearest ancestor.
+     *
+     * @return the {@link VersionHistoryResource} associated with this resource.
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
+     * @see javax.jcr.Item#getParent()
+     */
+    public VersionHistoryResource getVersionHistory() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+
+        try {
+            VersionHistory vh = getVersionHistoryItem();
+            DavResourceLocator loc = getLocatorFromItem(vh);
+            return (VersionHistoryResource) createResourceFromLocator(loc);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Return the nearest ancestor of the underlaying repository item.
+     *
+     * @return nearest ancestor of the underlaying repository item.
+     * @throws RepositoryException
+     */
+    private VersionHistory getVersionHistoryItem() throws RepositoryException {
+        return (VersionHistory) item.getParent();
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Define the set of reports supported by this resource.
+     *
+     * @see org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty
+     */
+    protected void initSupportedReports() {
+        super.initSupportedReports();
+        if (exists()) {
+            supportedReports.addReportType(ReportType.VERSION_TREE);
+        }
+    }
+
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        super.initProperties();
+
+        if (exists()) {
+            Version v = (Version)item;
+            // created and creationDate properties
+            try {
+                String creationDate = DavConstants.creationDateFormat.format(v.getCreated().getTime());
+                // replace dummy creation date from default collection
+                properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, creationDate));
+
+                // required, protected DAV:version-name property
+                properties.add(new DefaultDavProperty(VERSION_NAME, v.getName(), true));
+
+                // required, protected DAV:label-name-set property
+                String[] labels = getVersionHistoryItem().getVersionLabels(v);
+                Element[] labelElems = new Element[labels.length];
+                for (int i = 0; i < labels.length; i++) {
+                    labelElems[i] = new Element(DeltaVConstants.XML_LABEL_NAME, NAMESPACE).setText(labels[i]);
+                }
+                properties.add(new DefaultDavProperty(LABEL_NAME_SET, labelElems, true));
+
+                // required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
+                addHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
+                addHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
+
+                // required DAV:version-history (computed) property
+                String vhPath = getVersionHistoryItem().getPath();
+                properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, getLocatorFromResourcePath(vhPath).getHref(true), true));
+
+                // required DAV:checkout-set (computed) property
+                PropertyIterator it = v.getReferences();
+                List nodeList = new ArrayList();
+                while (it.hasNext()) {
+                    Property p = it.nextProperty();
+                    if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
+                        Node n = p.getParent();
+                        if (n.isCheckedOut()) {
+                           nodeList.add(n);
+                        }
+                    }
+                }
+                addHrefProperty(CHECKOUT_SET, (Node[]) nodeList.toArray(new Node[nodeList.size()]), true);
+
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html Sun Apr 17 07:51:59 2005
@@ -0,0 +1,9 @@
+<body>
+Contains JCR specific implementations for the following interfaces:
+<ul>
+<li>VersionableResource</li>
+<li>VersionControlledResource</li>
+<li>VersionResource</li>
+<li>VersionHistoryResource</li>
+</ul>
+</body>
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,156 @@
+/*
+ * 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.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.util.Text;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.PathNotFoundException;
+import java.io.*;
+
+/**
+ * <code>ExportViewReport</code> handles REPORT requests for the 'exportview'
+ * report. The 'exportview' report is used to export
+ * {@link Session#exportDocView(String, java.io.OutputStream, boolean, boolean) DocView}
+ * and {@link Session#exportSysView(String, java.io.OutputStream, boolean, boolean) SysView}
+ * of the {@link javax.jcr.Item item} represented by the requested resource.
+ * <p/>
+ * The request body must contain a jcr:exportview element:
+ * <pre>
+ * &lt;!ELEMENT exportview  ( (sysview | docview)?, skipbinary?, norecurse ) &gt;
+ * &lt;!ELEMENT sysview EMPTY &gt;
+ * &lt;!ELEMENT docview EMPTY &gt;
+ * &lt;!ELEMENT skipbinary EMPTY &gt;
+ * &lt;!ELEMENT norecurse EMPTY &gt;
+ * </pre>
+ * If no view type is specified the DocView is generated.
+ */
+public class ExportViewReport implements Report {
+
+    private static Logger log = Logger.getLogger(ExportViewReport.class);
+
+    private static final String REPORT_NAME = "exportview";
+
+    /**
+     * The exportview report type
+     */
+    public static final ReportType EXPORTVIEW_REPORT = ReportType.register(REPORT_NAME, ItemResourceConstants.NAMESPACE, ExportViewReport.class);
+
+    private String absPath;
+    private Session session;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #EXPORTVIEW_REPORT} report type.
+     *
+     * @return {@link #EXPORTVIEW_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return EXPORTVIEW_REPORT;
+    }
+
+    /**
+     * @param resource The resource this report is generated from. NOTE: the
+     * {@link org.apache.jackrabbit.webdav.DavResource#getResourcePath() resource path}
+     * of the resource is used as 'absPath' argument for exporting the specified
+     * view.
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     * if the session object provided with the resource is <code>null</code>.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession davSession = resource.getSession();
+        if (davSession == null || davSession.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        session = davSession.getRepositorySession();
+        absPath = resource.getResourcePath();
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified {@link ReportInfo info}
+     * object does not contain a jcr:exportview element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !REPORT_NAME.equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:exportview element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Creates a Xml document from the generated view.
+     *
+     * @return Xml document representing the output of the specified view.
+     * @throws DavException if the report document could not be created.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        Element reportElem = info.getReportElement();
+        boolean skipBinary = reportElem.getChild("skipbinary", ItemResourceConstants.NAMESPACE) != null;
+        boolean noRecurse = reportElem.getChild("norecurse", ItemResourceConstants.NAMESPACE) != null;
+
+        try {
+            // create tmpFile in default system-tmp directory
+            String prefix = "_tmp_" + Text.getLabel(absPath);
+            File tmpfile = File.createTempFile(prefix, null, null);
+            tmpfile.deleteOnExit();
+            FileOutputStream out = new FileOutputStream(tmpfile);
+
+            if (reportElem.getChild("sysview", ItemResourceConstants.NAMESPACE) != null) {
+                session.exportSystemView(absPath, out, skipBinary, noRecurse);
+            } else {
+                // default is docview
+                session.exportDocumentView(absPath, out, skipBinary, noRecurse);
+            }
+            out.close();
+
+            SAXBuilder builder = new SAXBuilder(false);
+            InputStream in = new FileInputStream(tmpfile);
+            return builder.build(in);
+
+        } catch (FileNotFoundException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        } catch (IOException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        } catch (PathNotFoundException e) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        } catch (JDOMException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,122 @@
+/*
+ * 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.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.jdom.Document;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>LocateByUuidReport</code> handles REPORT requests for the 'locate-by-uuid'
+ * report.
+ * <p/>
+ * The request body must be a 'jcr:locate-by-uuid' XML element:
+ * <pre>
+ * &lt;!ELEMENT locate-by-uuid ( href , prop? ) &gt;
+ * </pre>
+ * The response to a successful report request will be a Multi-Status response.
+ */
+public class LocateByUuidReport implements Report {
+
+    private static Logger log = Logger.getLogger(LocateByUuidReport.class);
+
+    private static final String REPORT_NAME = "locate-by-uuid";
+
+    /**
+     * The exportview report type
+     */
+    public static final ReportType LOCATE_BY_UUID_REPORT = ReportType.register(REPORT_NAME, ItemResourceConstants.NAMESPACE, LocateByUuidReport.class);
+
+    private DeltaVResource resource;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #LOCATE_BY_UUID_REPORT} report type.
+     *
+     * @return {@link #LOCATE_BY_UUID_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return LOCATE_BY_UUID_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     * if the session object provided with the resource is <code>null</code>.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession davSession = resource.getSession();
+        if (davSession == null || davSession.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        this.resource = resource;
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified {@link ReportInfo info}
+     * object does not contain a jcr:exportview element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !REPORT_NAME.equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:locate-by-uuid element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Creates a Xml document from the generated view.
+     *
+     * @return Xml document representing the output of the specified view.
+     * @throws DavException if the report document could not be created.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        String uuid = info.getReportElement().getChildText(DavConstants.XML_HREF, DavConstants.NAMESPACE);
+        DavPropertyNameSet propNameSet = info.getPropertyNameSet();
+
+        try {
+            DavSession session = resource.getSession();
+            DavResourceLocator resourceLoc = resource.getLocator();
+
+            Node n = session.getRepositorySession().getNodeByUUID(uuid);
+
+            DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath());
+            DavResource res = resource.getFactory().createResource(loc, session);
+
+            MultiStatus ms = new MultiStatus();
+            ms.addResourceProperties(res, propNameSet, 0);
+            return ms.toXml();
+
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,221 @@
+/*
+ * 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.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.webdav.jcr.nodetype.PropertyDefinitionImpl;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeDefinitionImpl;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.core.util.IteratorHelper;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import javax.jcr.nodetype.*;
+import javax.jcr.*;
+import java.util.*;
+
+/**
+ * <code>NodeTypesReport</code> allows to retrieve the definition of a single
+ * or multiple node types. The request body must be a 'jcr:nodetypes' element:
+ * <pre>
+ * &lt;!ELEMENT nodetypes ( nodetype+ | all-nodetypes | mixin-nodetypes | primary-nodetypes ) &gt;
+ *
+ * &lt;!ELEMENT nodetype ( nodetype-name ) &gt;
+ * &lt;!ELEMENT nodetype-name (#PCDATA) &gt;
+ *
+ * &lt;!ELEMENT all-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT mixin-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT primary-nodetypes EMPTY &gt;
+ * </pre>
+ *
+ * @todo currently the nodetype report is not consistent with the general way of representing nodetype names (with NodetypeElement) in order to be compatible with the jackrabbit nodetype registry...
+ * @todo for the same reason, not the complete nodetype-definition, but only the nodetype def as stored is represented.
+ * @todo no namespace definition with response (> jackrabbit)... and nodetype element has same name as the one used with dav-properties
+ */
+public class NodeTypesReport implements Report, NodeTypeConstants {
+
+    private static Logger log = Logger.getLogger(NodeTypesReport.class);
+
+    /**
+     * The registered type of this report.
+     */
+    public static final ReportType NODETYPES_REPORT = ReportType.register("nodetypes", NodeTypeConstants.NAMESPACE, NodeTypesReport.class);
+
+    private Session session;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #NODETYPES_REPORT} type.
+     * @return {@link #NODETYPES_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return NODETYPES_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource or the session retrieved
+     * from the specified resource is <code>null</code>
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession session = resource.getSession();
+        if (session == null || session.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        this.session = session.getRepositorySession();
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified info does not contain
+     * a jcr:nodetypes element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !"nodetypes".equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:nodetypes element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Returns a Xml representation of the node type definition(s) according
+     * to the info object.
+     *
+     * @return Xml representation of the node type definition(s)
+     * @throws DavException if the specified nodetypes are not known or if another
+     * error occurs while retrieving the nodetype definitions.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        if (info == null || session == null) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while running jcr:nodetypes report");
+        }
+        try {
+            Element report = new Element(XML_NODETYPES);
+            // make sure all namespace declarations are present on the root element.
+            // since the nodetype-manager uses session-local jcr names, prefix/namespace
+            // pairs are retrieved from the session and not from the namespace registry.
+            String[] prefixes = session.getNamespacePrefixes();
+            for (int i = 0; i < prefixes.length; i++) {
+                report.addNamespaceDeclaration(Namespace.getNamespace(prefixes[i], session.getNamespaceURI(prefixes[i])));
+            }
+            // retrieve the requested nodetypes
+            NodeTypeIterator ntIter = getNodeTypes();
+            while (ntIter.hasNext()) {
+                NodeType nt = ntIter.nextNodeType();
+                Element ntDef = new Element(XML_NODETYPE);
+                ntDef.setAttribute(NAME_ATTRIBUTE, nt.getName());
+                ntDef.setAttribute(ISMIXIN_ATTRIBUTE, Boolean.toString(nt.isMixin()));
+                ntDef.setAttribute(HASORDERABLECHILDNODES_ATTRIBUTE, Boolean.toString(nt.hasOrderableChildNodes()));
+
+		// declared supertypes
+		NodeType[] snts = nt.getDeclaredSupertypes();
+                Element supertypes = new Element(SUPERTYPES_ELEMENT);
+		for (int i = 0; i < snts.length; i++) {
+		    supertypes.addContent(new Element(SUPERTYPE_ELEMENT).setText(snts[i].getName()));
+		}
+		ntDef.addContent(supertypes);
+
+		// declared childnode defs
+		NodeDefinition[] cnd = nt.getChildNodeDefinitions();
+		for (int i = 0; i < cnd.length; i++) {
+		    if (cnd[i].getDeclaringNodeType().getName().equals(nt.getName())) {
+			ntDef.addContent(NodeDefinitionImpl.create(cnd[i]).toXml());
+		    }
+		}
+
+		// declared propertyDefs
+		PropertyDefinition[] pd = nt.getPropertyDefinitions();
+		for (int i = 0; i < pd.length; i++) {
+		    if (pd[i].getDeclaringNodeType().getName().equals(nt.getName())) {
+			ntDef.addContent(PropertyDefinitionImpl.create(pd[i]).toXml());
+		    }
+		}
+
+                String primaryItemName = nt.getPrimaryItemName();
+                if (primaryItemName != null) {
+                    ntDef.setAttribute(PRIMARYITEMNAME_ATTRIBUTE, primaryItemName);
+                }
+                report.addContent(ntDef);
+            }
+
+            Document reportDoc = new Document(report);
+            return reportDoc;
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Parse the Xml element in the info object an return an interator over
+     * the specified node types.
+     *
+     * @return
+     * @throws RepositoryException
+     * @throws DavException
+     */
+    private NodeTypeIterator getNodeTypes() throws RepositoryException, DavException {
+        NodeTypeIterator ntIter = null;
+        NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
+        Iterator it = info.getReportElement().getChildren().iterator();
+        while (it.hasNext() && ntIter == null) {
+            Element elem = (Element) it.next();
+            if (elem.getNamespace().equals(NAMESPACE)) {
+                String name = elem.getName();
+                if (XML_REPORT_ALLNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getAllNodeTypes();
+                } else if (XML_REPORT_MIXINNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getMixinNodeTypes();
+                } else if (XML_REPORT_PRIMARYNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getPrimaryNodeTypes();
+                }
+            }
+        }
+        // None of the simple types. test if a report for individual nodetypes
+        // was request. If not, the request body is not valid.
+        if (ntIter == null) {
+            List ntList = new ArrayList();
+            List elemList = info.getReportElement().getChildren(XML_NODETYPE, NAMESPACE);
+            if (elemList.isEmpty()) {
+                // throw exception if the request body does not contain a single jcr:nodetype element
+                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "NodeTypes report: request body has invalid format.");
+            }
+            Iterator elemIter = elemList.iterator();
+            while (elemIter.hasNext()) {
+                String nodetypeName = ((Element)elemIter.next()).getChildText(XML_NODETYPENAME, NAMESPACE);
+                if (nodetypeName != null) {
+                    ntList.add(ntMgr.getNodeType(nodetypeName));
+                }
+            }
+            ntIter = new IteratorHelper(Collections.unmodifiableCollection(ntList));
+        }
+
+        return ntIter;
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,131 @@
+/*
+ * 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.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.jdom.Document;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>NodeTypesReport</code> allows to retrieve the definition of a single
+ * or multiple node types. The request body must be a 'jcr:nodetypes' element:
+ * <pre>
+ * &lt;!ELEMENT nodetypes ( nodetype+ | all-nodetypes | mixin-nodetypes | primary-nodetypes ) &gt;
+ *
+ * &lt;!ELEMENT nodetype ( nodetype-name ) &gt;
+ * &lt;!ELEMENT nodetype-name (#PCDATA) &gt;
+ *
+ * &lt;!ELEMENT all-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT mixin-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT primary-nodetypes EMPTY &gt;
+ * </pre>
+ */
+public class RegisteredNamespacesReport implements Report, ItemResourceConstants {
+
+    private static Logger log = Logger.getLogger(RegisteredNamespacesReport.class);
+
+    /**
+     * The registered type of this report.
+     */
+    public static final ReportType REGISTERED_NAMESPACES_REPORT = ReportType.register("registerednamespaces", ItemResourceConstants.NAMESPACE, RegisteredNamespacesReport.class);
+
+    private NamespaceRegistry nsReg;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #REGISTERED_NAMESPACES_REPORT} type.
+     * @return {@link #REGISTERED_NAMESPACES_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return REGISTERED_NAMESPACES_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource or the session retrieved
+     * from the specified resource is <code>null</code>
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        try {
+            DavSession session = resource.getSession();
+            if (session == null || session.getRepositorySession() == null) {
+                throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+            }
+            nsReg = session.getRepositorySession().getWorkspace().getNamespaceRegistry();
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified info does not contain
+     * a jcr:nodetypes element.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !"registerednamespaces".equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:registerednamespaces element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Returns a Xml representation of the node type definition(s) according
+     * to the info object.
+     *
+     * @return Xml representation of the node type definition(s)
+     * @throws org.apache.jackrabbit.webdav.DavException if the specified nodetypes are not known or if another
+     * error occurs while retrieving the nodetype definitions.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        if (info == null || nsReg == null) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while running jcr:registerednamespaces report");
+        }
+        try {
+	    String[] prefixes = nsReg.getPrefixes();
+	    List namespaceList = new ArrayList();
+	    for (int i = 0; i < prefixes.length; i++) {
+		Element elem = new Element(XML_NAMESPACE, NAMESPACE);
+		elem.addContent(new Element(XML_NSPREFIX, NAMESPACE).setText(prefixes[i]));
+		elem.addContent(new Element(XML_NSURI, NAMESPACE).setText(nsReg.getURI(prefixes[i])));
+		namespaceList.add(elem);
+	    }
+	    Element report = new Element("registerednamespaces-report", NAMESPACE).addContent(namespaceList);
+            Document reportDoc = new Document(report);
+            return reportDoc;
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+}
\ No newline at end of file

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

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html Sun Apr 17 07:51:59 2005
@@ -0,0 +1,3 @@
+<body>
+Contains JCR specific reports.
+</body>
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,196 @@
+/*
+ * 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.lock;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.util.Text;
+
+/**
+ * Simple manager for webdav locks.<br>
+ * NOTE: the timeout requested is always replace by a infinite timeout and
+ * expiration of locks is not checked.
+ */
+public class SimpleLockManager implements LockManager {
+
+    /** map of locks */
+    private HashMap locks = new HashMap();
+
+    /**
+     *
+     * @param lockToken
+     * @param resource
+     * @return
+     * @see LockManager#hasLock(String, org.apache.jackrabbit.webdav.DavResource)
+     */
+    public boolean hasLock(String lockToken, DavResource resource) {
+	ActiveLock lock = (ActiveLock) locks.get(resource.getResourcePath());
+	if (lock != null && lock.getToken().equals(lockToken)) {
+	    return true;
+	}
+	return false;
+    }
+
+    /**
+     * Returns the lock applying to the given resource or <code>null</code> if
+     * no lock can be found.
+     *
+     * @param type
+     * @param scope
+     * @param resource
+     * @return lock that applies to the given resource or <code>null</code>.
+     */
+    public ActiveLock getLock(Type type, Scope scope, DavResource resource) {
+	if (!(Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope))) {
+	    return null;
+	}
+	String key = resource.getResourcePath();
+	ActiveLock lock = (locks.containsKey(key)) ? (ActiveLock)locks.get(key) : null;
+
+	// look for an inherited lock
+	if (lock == null) {
+	    // cut path instead of retrieving the parent resource
+	    String parentPath = Text.getRelativeParent(key, 1);
+	    boolean found = false;
+	    /* stop as soon as parent lock is found:
+	    if the lock is deep or the parent is a collection the lock
+	    applies to the given resource. */
+	    while (!"/".equals(parentPath) && !(found = locks.containsKey(parentPath))) {
+		parentPath = Text.getRelativeParent(parentPath, 1);
+	    }
+	    if (found) {
+		ActiveLock parentLock = (ActiveLock)locks.get(parentPath);
+		if (parentLock.isDeep()) {
+		    lock = parentLock;
+		}
+	    }
+	}
+	// since locks have infinite timeout, check for expired lock is omitted.
+	return lock;
+    }
+
+    /**
+     * Adds the lock for the given resource, replacing any existing lock.
+     *
+     * @param lockInfo
+     * @param resource being the lock holder
+     */
+    public synchronized ActiveLock createLock(LockInfo lockInfo, DavResource resource)
+	    throws DavException {
+	if (lockInfo == null || resource == null) {
+	    throw new IllegalArgumentException("Neither lockInfo nor resource must be null.");
+	}
+
+	String resourcePath = resource.getResourcePath();
+	// test if there is already a lock present on this resource
+	if (locks.containsKey(resourcePath)) {
+	    throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already holds a lock.");
+	}
+	// test if the new lock would conflict with any lock inherited from the
+	// collection or with a lock present on any member resource.
+	Iterator it = locks.keySet().iterator();
+	while (it.hasNext()) {
+	    String key = (String) it.next();
+	    // TODO: is check for lock on internal-member correct?
+	    if (Text.isDescendant(key, resourcePath)) {
+		ActiveLock l = (ActiveLock) locks.get(key);
+		if (l.isDeep() || (key.equals(Text.getRelativeParent(resourcePath, 1)) && !resource.isCollection())) {
+		    throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already inherits a lock by its collection.");
+		}
+	    } else if (Text.isDescendant(resourcePath, key)) {
+		if (lockInfo.isDeep() || isInternalMember(resource, key)) {
+		    throw new DavException(DavServletResponse.SC_CONFLICT, "Resource '" + resource.getResourcePath() + "' cannot be locked due to a lock present on the member resource '" + key + "'.");
+		}
+
+	    }
+	}
+	ActiveLock lock = new DefaultActiveLock(lockInfo);
+	// Lazy: reset the timeout to 'Infinite', in order to omit the tests for
+	// lock expiration.
+	lock.setTimeout(DavConstants.INFINITE_TIMEOUT);
+	locks.put(resource.getResourcePath(), lock);
+	return lock;
+    }
+
+    /**
+     *
+     * @param lockInfo
+     * @param lockToken
+     * @param resource
+     * @return
+     * @throws DavException
+     * @see DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String)
+     */
+    public ActiveLock refreshLock(LockInfo lockInfo, String lockToken, DavResource resource)
+	    throws DavException {
+	// timeout is always infinite > no test for expiration or adjusting timeout needed.
+	ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope(), resource);
+	if (lock == null) {
+	    throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
+	} else if (!lock.getToken().equals(lockToken)) {
+	    throw new DavException(DavServletResponse.SC_LOCKED);
+	}
+	return lock;
+    }
+
+    /**
+     * Remove the lock hold by the given resource.
+     *
+     * @param lockToken
+     * @param resource that is the lock holder
+     */
+    public synchronized void releaseLock(String lockToken, DavResource resource)
+	    throws DavException {
+	if (!locks.containsKey(resource.getResourcePath())) {
+	    throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
+	}
+	// since locks have infinite timeout, check for expiration is omitted.
+
+	ActiveLock lock = (ActiveLock) locks.get(resource.getResourcePath());
+	if (lock.getToken().equals(lockToken)) {
+	    locks.remove(resource.getResourcePath());
+	} else {
+	    throw new DavException(DavServletResponse.SC_LOCKED);
+	}
+    }
+
+    /**
+     * Return true, if the resource with the given memberPath is a internal
+     * non-collection member of the given resource, thus affected by a
+     * non-deep lock present on the resource.
+     *
+     * @param resource
+     * @param memberPath
+     * @return
+     */
+    private static boolean isInternalMember(DavResource resource, String memberPath) {
+	if (resource.getResourcePath().equals(Text.getRelativeParent(memberPath, 1))) {
+	    // find the member with the given path
+	    DavResourceIterator it = resource.getMembers();
+	    while (it.hasNext()) {
+		DavResource member = it.nextResource();
+		if (member.getResourcePath().equals(memberPath)) {
+		    // return true if that member is not a collection
+		    return !member.isCollection();
+		}
+	    }
+	}
+	return false;
+    }
+}
+

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java
------------------------------------------------------------------------------
    svn = 

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

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/QueryGrammerSet.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/QueryGrammerSet.java?view=diff&r1=161659&r2=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/QueryGrammerSet.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/QueryGrammerSet.java Sun Apr 17 07:51:59 2005
@@ -34,6 +34,14 @@
     private List queryLanguages = new ArrayList();
 
     /**
+     * Create a new empty <code>QueryGrammerSet</code>. Supported query grammers
+     * may be added by calling {@link #addQueryLanguage(String, Namespace).
+     */
+    public QueryGrammerSet() {
+       this(null);
+    }
+
+    /**
      * Create a new <code>QueryGrammerSet</code> from the given query languages
      * string array. The default {@link SearchConstants#NAMESPACE} is assumed.
      * @param qLanguages

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchConstants.java?view=diff&r1=161659&r2=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchConstants.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchConstants.java Sun Apr 17 07:51:59 2005
@@ -58,8 +58,8 @@
     /**
      * Xml element name for the required request body of a SEARCH request.
      *
-     * @see SearchRequest
-     * @see SearchResource#search(SearchRequest)
+     * @see SearchInfo
+     * @see SearchResource#search(SearchInfo)
      */
     public static final String XML_SEARCHREQUEST = "searchrequest";
 
@@ -68,7 +68,6 @@
      * in order to access a given query schema.
      */
     public static final String XML_QUERY_SCHEMA_DISCOVERY = "query-schema-discovery";
-
 
     /**
      * Predefined basic query grammer.

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchInfo.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchInfo.java?view=auto&rev=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchInfo.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchInfo.java Sun Apr 17 07:51:59 2005
@@ -0,0 +1,118 @@
+/*
+ * 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.search;
+
+import org.apache.log4j.Logger;
+import org.jdom.*;
+
+/**
+ * <code>SearchInfo</code> parses the 'searchrequest' element of a SEARCH
+ * request body and performs basic validation. Both query language and the
+ * query itself can be access from the resulting object.<br>
+ * NOTE: The query is expected to be represented by the text contained in the
+ * Xml element specifying the query language, thus the 'basicsearch' defined
+ * by the Webdav Search Internet Draft is not supported by this implementation.
+ * <p/>
+ *
+ * Example of a valid 'searchrequest' body
+ * <pre>
+ * &lt;d:searchrequest xmlns:d="DAV:" jcr:="http://www.day.com/jcr/webdav/1.0" &gt;
+ *    &lt;jcr:xpath>//sv:node[@sv:name='myapp:paragraph'][1]&lt;/jcr:xpath&gt;
+ * &lt;/d:searchrequest&gt;
+ * </pre>
+ *
+ * Would return the following values:
+ * <pre>
+ *    getLanguageName() -&gt; xpath
+ *    getQuery()        -&gt; //sv:node[@sv:name='myapp:paragraph'][1]
+ * </pre>
+ *
+ */
+public class SearchInfo implements SearchConstants {
+
+    private static Logger log = Logger.getLogger(SearchInfo.class);
+
+    private final Element languageElem;
+
+    /**
+     * Create a new <code>SearchInfo</code> instance.
+     *
+     * @param language
+     * @param languageNamespace
+     * @param query
+     */
+    public SearchInfo(String language, Namespace languageNamespace, String query) {
+        languageElem = new Element(language, languageNamespace).setText(query);
+    }
+
+    /**
+     * Create a new <code>SearchInfo</code> from the specifying document
+     * retrieved from the request body.
+     *
+     * @param searchDocument
+     * @throws IllegalArgumentException if the root element's name is other than
+     * 'searchrequest' or if it does not contain a single child element specifying
+     * the query language to be used.
+     */
+    public SearchInfo(Document searchDocument) {
+        Element searchRequest = searchDocument.getRootElement();
+        if (searchRequest == null || !XML_SEARCHREQUEST.equals(searchRequest.getName()))  {
+            throw new IllegalArgumentException("The root element must be 'searchrequest'.");
+        } else if (searchRequest.getChildren().size() != 1) {
+            throw new IllegalArgumentException("A single child element is expected with the 'searchrequest'.");
+        }
+        Element child = (Element)searchRequest.getChildren().get(0);
+        languageElem = (Element) child.detach();
+    }
+
+    /**
+     * Returns the name of the query language to be used.
+     *
+     * @return name of the query language
+     */
+    public String getLanguageName() {
+        return languageElem.getName();
+    }
+
+    /**
+     * Returns the namespace of the language specified with the search request element.
+     *
+     * @return namespace of the requestes language.
+     */
+    public Namespace getLanguageNameSpace() {
+        return languageElem.getNamespace();
+    }
+
+    /**
+     * Return the query string.
+     *
+     * @return query string
+     */
+    public String getQuery() {
+        return languageElem.getText();
+    }
+
+    /**
+     * Return the xml representation of this <code>SearchInfo</code> instance.
+     *
+     * @return xml representation
+     */
+    public Document toXml() {
+        Element sRequestElem = new Element(XML_SEARCHREQUEST, NAMESPACE);
+        sRequestElem.addContent(languageElem);
+        return new Document(sRequestElem);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchInfo.java
------------------------------------------------------------------------------
    svn = 

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

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchResource.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchResource.java?view=diff&r1=161659&r2=161660
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchResource.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/search/SearchResource.java Sun Apr 17 07:51:59 2005
@@ -47,14 +47,14 @@
     public QueryGrammerSet getQueryGrammerSet();
 
     /**
-     * Runs a search with the language and query defined in the {@link SearchRequest}
+     * Runs a search with the language and query defined in the {@link SearchInfo}
      * object specified and returns a {@link MultiStatus} object listing the
      * results.
      *
-     * @param sRequest <code>SearchRequest</code> element encapsulating the SEARCH
+     * @param sInfo <code>SearchInfo</code> element encapsulating the SEARCH
      * request body.
      * @return <code>MultiStatus</code> object listing the results.
      * @throws DavException
      */
-    public MultiStatus search(SearchRequest sRequest) throws DavException;
+    public MultiStatus search(SearchInfo sInfo) throws DavException;
 }



Mime
View raw message