jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r397819 - /jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java
Date Fri, 28 Apr 2006 09:24:43 GMT
Author: angela
Date: Fri Apr 28 02:24:31 2006
New Revision: 397819

URL: http://svn.apache.org/viewcvs?rev=397819&view=rev
Log:
minor improvement, javadoc

Modified:
    jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java

Modified: jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java?rev=397819&r1=397818&r2=397819&view=diff
==============================================================================
--- jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java
(original)
+++ jackrabbit/trunk/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/UpdateInfo.java
Fri Apr 28 02:24:31 2006
@@ -35,17 +35,20 @@
  * RFC 3253 defines the request body as follows:
  * <pre>
  * &lt;!ELEMENT update ANY&gt;
- * ANY value: A sequence of elements with at most one DAV:version element and at
- * most one DAV:prop element.
+ * ANY value: A sequence of elements with at most one DAV:label-name or
+ * DAV:version element (but not both).
+ * In addition at one DAV:prop element can be present.
+ *
  * &lt;!ELEMENT version (href)&gt;
+ * &lt;!ELEMENT label-name (#PCDATA)&gt; PCDATA value: string
  * prop: see RFC 2518, Section 12.11
  * </pre>
  *
  * In order to reflect the complete range of version restoring and updating
  * of nodes defined by JSR170 the definition has been extended:
  * <pre>
- * &lt;!ELEMENT update ( (version+ | label-name | workspace ) , (prop)?, (removeExisting)?
) &gt;
- * &lt;!ELEMENT version (href) &gt;
+ * &lt;!ELEMENT update ( (version | label-name | workspace ) , (prop)?, (removeExisting)?
) &gt;
+ * &lt;!ELEMENT version (href+) &gt;
  * &lt;!ELEMENT label-name (#PCDATA) &gt;
  * &lt;!ELEMENT workspace (href) &gt;
  * &lt;!ELEMENT prop ANY &gt;
@@ -56,11 +59,29 @@
 
     private static Logger log = LoggerFactory.getLogger(UpdateInfo.class);
 
-    private final Element updateElement;
-    private final DavPropertyNameSet propertyNameSet;
-    private String[] versionHref;
-    private String[] labelName;
-    private String workspaceHref;
+    public static final int UPDATE_BY_VERSION = 0;
+    public static final int UPDATE_BY_LABEL = 1;
+    public static final int UPDATE_BY_WORKSPACE = 2;
+
+    private Element updateElement;
+    private DavPropertyNameSet propertyNameSet = new DavPropertyNameSet();
+
+    private String[] source;
+    private int type;
+
+    public UpdateInfo(String[] updateSource, int updateType, DavPropertyNameSet propertyNameSet)
{
+        if (updateSource == null || updateSource.length == 0) {
+            throw new IllegalArgumentException("Version href array must not be null and have
a minimal length of 1.");
+        }
+        if (updateType < UPDATE_BY_VERSION || updateType > UPDATE_BY_WORKSPACE) {
+            throw new IllegalArgumentException("Illegal type of UpdateInfo.");
+        }
+        this.type = updateType;
+        this.source = (updateType == UPDATE_BY_VERSION) ? updateSource : new String[] {updateSource[0]};
+        if (propertyNameSet != null) {
+            this.propertyNameSet = propertyNameSet;
+        }
+    }
 
     /**
      * Create a new <code>UpdateInfo</code> object.
@@ -82,27 +103,21 @@
             List hrefList = new ArrayList();
             Element el = it.nextElement();
             hrefList.add(DomUtil.getChildText(el, DavConstants.XML_HREF, DavConstants.NAMESPACE));
-            versionHref = (String[])hrefList.toArray(new String[hrefList.size()]);
+            source = (String[])hrefList.toArray(new String[hrefList.size()]);
             done = true;
         }
 
         // alternatively 'DAV:label-name' elements may be present.
-        if (!done) {
-            it = DomUtil.getChildren(updateElement, XML_LABEL_NAME, NAMESPACE);
-            while (it.hasNext()) {
-                List labelList = new ArrayList();
-                Element el = it.nextElement();
-                labelList.add(DomUtil.getText(el));
-                labelName = (String[])labelList.toArray(new String[labelList.size()]);
-                done = true;
-            }
+        if (!done && DomUtil.hasChildElement(updateElement, XML_LABEL_NAME, NAMESPACE))
{
+            source = new String[] {DomUtil.getChildText(updateElement, XML_LABEL_NAME, NAMESPACE)};
+            done = true;
         }
 
         // last possibility: a DAV:workspace element
         if (!done) {
             Element wspElem = DomUtil.getChildElement(updateElement, XML_WORKSPACE, NAMESPACE);
             if (wspElem != null) {
-                workspaceHref = DomUtil.getChildTextTrim(wspElem, DavConstants.XML_HREF,
DavConstants.NAMESPACE);
+                source = new String[] {DomUtil.getChildTextTrim(wspElem, DavConstants.XML_HREF,
DavConstants.NAMESPACE)};
             } else {
                 log.warn("DAV:update element must contain either DAV:version, DAV:label-name
or DAV:workspace child element.");
                 throw new DavException(DavServletResponse.SC_BAD_REQUEST);
@@ -125,7 +140,7 @@
      * @return
      */
     public String[] getVersionHref() {
-       return versionHref;
+       return (type == UPDATE_BY_VERSION) ? source : null;
     }
 
     /**
@@ -133,7 +148,7 @@
      * @return
      */
     public String[] getLabelName() {
-       return labelName;
+       return (type == UPDATE_BY_LABEL) ? source : null;
     }
 
     /**
@@ -141,7 +156,7 @@
      * @return
      */
     public String getWorkspaceHref() {
-       return workspaceHref;
+       return (type == UPDATE_BY_WORKSPACE) ? source[0] : null;
     }
 
     /**
@@ -172,11 +187,29 @@
      * @param document
      */
     public Element toXml(Document document) {
-        Element elem = (Element)document.importNode(updateElement, true);
+        Element elem;
+        if (updateElement != null) {
+            elem = (Element)document.importNode(updateElement, true);
+        } else {
+            elem = DomUtil.createElement(document, XML_UPDATE, NAMESPACE);
+            switch (type) {
+                case UPDATE_BY_VERSION:
+                    Element vE = DomUtil.addChildElement(elem, XML_VERSION, NAMESPACE);
+                    for (int i = 0; i < source.length; i++) {
+                        vE.appendChild(DomUtil.hrefToXml(source[i], document));
+                    }
+                    break;
+                case UPDATE_BY_LABEL:
+                    DomUtil.addChildElement(elem, XML_LABEL_NAME, NAMESPACE, source[0]);
+                    break;
+                case UPDATE_BY_WORKSPACE:
+                    DomUtil.addChildElement(elem, XML_WORKSPACE, NAMESPACE, source[0]);
+                // no default.
+            }
+        }
         if (!propertyNameSet.isEmpty()) {
             elem.appendChild(propertyNameSet.toXml(document));
         }
         return elem;
     }
-
 }



Mime
View raw message