jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r368683 [5/8] - in /incubator/jackrabbit/trunk/contrib/jcr-server: client/ client/src/java/org/apache/jackrabbit/webdav/client/methods/ server/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ s...
Date Fri, 13 Jan 2006 11:13:30 GMT
Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/IfHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/IfHeader.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/IfHeader.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/IfHeader.java Fri Jan 13 03:11:35 2006
@@ -15,17 +15,18 @@
  */
 package org.apache.jackrabbit.webdav.header;
 
-import org.apache.log4j.Logger;
 import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.log4j.Logger;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Iterator;
-import java.io.StringReader;
-import java.io.IOException;
-import java.io.Reader;
+import java.util.List;
 
 /**
  * The <code>IfHeader</code> class represents the state lists defined
@@ -38,7 +39,7 @@
      Resource = Coded-URL
      List = "(" 1*(["Not"](State-etag | "[" entity-tag "]")) ")"
      State-etag = Coded-URL
-     Coded-URL = "<" absoluteURI ">"
+     Coded-URL = "&lt;" absoluteURI "&gt;"
  * </pre>
  * <p>
  * Reformulating this specification into proper EBNF as specified by N. Wirth
@@ -47,9 +48,9 @@
  * within words which is considered significant.
  * <pre>
      If = "If:" ( Tagged | Untagged ).
-     Tagged = { "<" Word ">" Untagged } .
+     Tagged = { "&lt;" Word "&gt;" Untagged } .
      Untagged = { "(" IfList ")" } .
-     IfList = { [ "Not" ] ( ("<" Word ">" ) | ( "[" Word "]" ) ) } .
+     IfList = { [ "Not" ] ( ("&lt;" Word "&gt;" ) | ( "[" Word "]" ) ) } .
      Word = characters .
  * </pre>
  * <p>
@@ -74,7 +75,7 @@
  *
  * @author Felix Meschberger
  */
-public class IfHeader {
+public class IfHeader implements Header {
 
     /**
      * default logger
@@ -82,14 +83,40 @@
     private static final Logger log = Logger.getLogger(IfHeader.class);
 
     /**
+     * The string representation of the header value
+     */
+    private final String headerValue;
+
+    /**
      * The list of untagged state entries
      */
     private final IfHeaderInterface ifHeader;
 
     /**
-     * The list of all tokens present in the If header.
+     * The list of all positive tokens present in the If header.
      */
     private List allTokens = new ArrayList();
+    /**
+     * The list of all NOT tokens present in the If header.
+     */
+    private List allNotTokens = new ArrayList();
+
+    /**
+     * Create a Untagged <code>IfHeader</code> if the given lock tokens.
+     *
+     * @param tokens
+     */
+    public IfHeader(String[] tokens) {
+        allTokens.addAll(Arrays.asList(tokens));
+        StringBuffer b = new StringBuffer();
+        for (int i = 0; i < tokens.length; i++) {
+            b.append("(").append("<");
+            b.append(tokens[i]);
+            b.append(">").append(")");
+        }
+        headerValue = b.toString();
+        ifHeader = parse();
+    }
 
     /**
      * Parses the <em>If</em> header and creates and internal representation
@@ -98,45 +125,8 @@
      * @param req The request object
      */
     public IfHeader(HttpServletRequest req) {
-
-	String ifHeaderValue = req.getHeader(DavConstants.HEADER_IF);
-        if (ifHeaderValue != null && ifHeaderValue.length() > 0) {
-
-            StringReader reader = null;
-            int firstChar = 0;
-
-            try {
-                reader = new StringReader(ifHeaderValue);
-
-                // get the first character to decide - expect '(' or '<'
-                try {
-                    reader.mark(1);
-                    firstChar = readWhiteSpace(reader);
-                    reader.reset();
-                } catch (IOException ignore) {
-                    // may be thrown according to API but is only thrown by the
-                    // StringReader class if the reader is already closed.
-                }
-
-                if (firstChar == '(') {
-                    ifHeader = parseUntagged(reader);
-                } else if (firstChar == '<') {
-                    ifHeader = parseTagged(reader);
-                } else {
-                    logIllegalState("If", firstChar, "(<", null);
-                    ifHeader = null;
-                }
-
-            } finally  {
-                if (reader != null) {
-                    reader.close();
-                }
-            }
-
-        } else {
-            log.debug("IfHeader: No If header in request");
-            ifHeader = null;
-        }
+	headerValue = req.getHeader(DavConstants.HEADER_IF);
+        ifHeader = parse();
     }
 
     /**
@@ -150,6 +140,16 @@
     }
 
     /**
+     * Return the String representation of the If header present on
+     * the given request or <code>null</code>.
+     *
+     * @return If header value as String or <code>null</code>.
+     */
+    public String getHeaderValue() {
+        return headerValue;
+    }
+
+    /**
      * Returns true if an If header was present in the given request. False otherwise.
      *
      * @return  true if an If header was present.
@@ -189,13 +189,65 @@
     }
 
     /**
-     * 
-     * @return
+     * @return an interator over all tokens present in the if header, that were
+     * not denied by a leading NOT statement.
      */
     public Iterator getAllTokens() {
         return allTokens.iterator();
     }
 
+    /**
+     * @return an interator over all NOT tokens present in the if header, that
+     * were explicitely denied.
+     */
+    public Iterator getAllNotTokens() {
+        return allNotTokens.iterator();
+    }
+
+    /**
+     * Parse the original header value and build th internal IfHeaderInterface
+     * object that is easy to query.
+     */
+    private IfHeaderInterface parse() {
+        IfHeaderInterface ifHeader;
+        if (headerValue != null && headerValue.length() > 0) {
+            StringReader reader = null;
+            int firstChar = 0;
+
+            try {
+                reader = new StringReader(headerValue);
+                // get the first character to decide - expect '(' or '<'
+                try {
+                    reader.mark(1);
+                    firstChar = readWhiteSpace(reader);
+                    reader.reset();
+                } catch (IOException ignore) {
+                    // may be thrown according to API but is only thrown by the
+                    // StringReader class if the reader is already closed.
+                }
+
+                if (firstChar == '(') {
+                    ifHeader = parseUntagged(reader);
+                } else if (firstChar == '<') {
+                    ifHeader = parseTagged(reader);
+                } else {
+                    logIllegalState("If", firstChar, "(<", null);
+                    ifHeader = null;
+                }
+
+            } finally  {
+                if (reader != null) {
+                    reader.close();
+                }
+            }
+
+        } else {
+            log.debug("IfHeader: No If header in request");
+            ifHeader = null;
+        }
+        return ifHeader;
+    }
+
     //---------- internal IF header parser -------------------------------------
     /**
      * Parses a tagged type <em>If</em> header. This method implements the
@@ -331,7 +383,11 @@
                     if (word != null) {
                         res.add(new IfListEntryToken(word, positive));
                         // also add the token to the list of all tokens
+                        if (positive) {
                         allTokens.add(word);
+                        } else {
+                            allNotTokens.add(word);
+                        }
                         positive = true;
                     }
                     break;

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/LabelHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/LabelHeader.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/LabelHeader.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/LabelHeader.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.header;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.WebdavRequest;
+
+/**
+ * <code>LabelHeader</code>...
+ */
+public class LabelHeader implements Header {
+
+    private static Logger log = Logger.getLogger(LabelHeader.class);
+
+    private final String label;
+
+    public LabelHeader(String label) {
+        if (label == null) {
+            throw new IllegalArgumentException("null is not a valid label.");
+        }
+        this.label = label;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public String getHeaderName() {
+        return DeltaVConstants.HEADER_LABEL;
+    }
+
+    public String getHeaderValue() {
+        return Text.escape(label);
+    }
+
+    public static LabelHeader parse(WebdavRequest request) {
+        String hv = request.getHeader(DeltaVConstants.HEADER_LABEL);
+        if (hv == null) {
+            return null;
+        } else {
+            return new LabelHeader(Text.unescape(hv));
+        }
+    }
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/LabelHeader.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/OverwriteHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/OverwriteHeader.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/OverwriteHeader.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/OverwriteHeader.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.header;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavConstants;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <code>OverwriteHeader</code>...
+ */
+public class OverwriteHeader implements Header {
+
+    private static Logger log = Logger.getLogger(OverwriteHeader.class);
+
+    public static final String OVERWRITE_TRUE = "T";
+    public static final String OVERWRITE_FALSE = "F";
+
+    private boolean doOverwrite;
+
+    public OverwriteHeader(boolean doOverwrite) {
+        this.doOverwrite = doOverwrite;
+    }
+
+    public OverwriteHeader(HttpServletRequest request) {
+        String overwriteHeader = request.getHeader(DavConstants.HEADER_OVERWRITE);
+        if (overwriteHeader != null) {
+            doOverwrite = overwriteHeader.equalsIgnoreCase(OVERWRITE_TRUE);
+        }
+    }
+
+    public String getHeaderName() {
+        return DavConstants.HEADER_OVERWRITE;
+    }
+
+    public String getHeaderValue() {
+        return (doOverwrite) ? OVERWRITE_TRUE : OVERWRITE_FALSE;
+    }
+
+    public boolean isOverwrite() {
+        return doOverwrite;
+    }
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/OverwriteHeader.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/TimeoutHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/TimeoutHeader.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/TimeoutHeader.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/TimeoutHeader.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,84 @@
+/*
+ * 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.header;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavConstants;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <code>TimeoutHeader</code>...
+ */
+public class TimeoutHeader implements Header, DavConstants {
+
+    private static Logger log = Logger.getLogger(TimeoutHeader.class);
+
+    private final long timeout;
+
+    public TimeoutHeader(long timeout) {
+        this.timeout = timeout;
+    }
+
+    public String getHeaderName() {
+        return DavConstants.HEADER_TIMEOUT;
+    }
+
+    public String getHeaderValue() {
+        return String.valueOf(timeout);
+    }
+
+    public long getTimeout() {
+        return timeout;
+    }
+
+    /**
+     * Parse the request timeout header and convert the timeout value
+     * into a long indicating the number of milliseconds until expiration time
+     * is reached.<br>
+     * NOTE: If the requested timeout is 'infinite' {@link Long.MAX_VALUE}
+     * is returned. If the header is missing or is in an invalid format that
+     * cannot be parsed, the default value is returned.
+     *
+     * @param request
+     * @param defaultValue
+     * @return long representing the timeout present in the header or the default
+     * value if the header is missing or could not be parsed.
+     */
+    public static TimeoutHeader parse(HttpServletRequest request, long defaultValue) {
+        String timeoutStr = request.getHeader(HEADER_TIMEOUT);
+        long timeout = defaultValue;
+        if (timeoutStr != null && timeoutStr.length() > 0) {
+            int secondsInd = timeoutStr.indexOf("Second-");
+            if (secondsInd >= 0) {
+                secondsInd += 7; // read over "Second-"
+                int i = secondsInd;
+                while (i < timeoutStr.length() && Character.isDigit(timeoutStr.charAt(i))) {
+                    i++;
+                }
+                try {
+                    timeout = 1000L * Long.parseLong(timeoutStr.substring(secondsInd, i));
+                } catch (NumberFormatException ignore) {
+                    // ignore and return 'undefined' timeout
+                    log.error("Invalid timeout format: " + timeoutStr);
+                }
+            } else if (timeoutStr.equalsIgnoreCase(TIMEOUT_INFINITE)) {
+                timeout = INFINITE_TIMEOUT;
+            }
+        }
+        return new TimeoutHeader(timeout);
+    }
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/TimeoutHeader.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractActiveLock.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractActiveLock.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractActiveLock.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractActiveLock.java Fri Jan 13 03:11:35 2006
@@ -16,8 +16,9 @@
 package org.apache.jackrabbit.webdav.lock;
 
 import org.apache.jackrabbit.webdav.DavConstants;
-import org.apache.jackrabbit.webdav.util.XmlUtil;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 /**
  * <code>AbstractActiveLock</code>...
@@ -29,43 +30,34 @@
      * as defined by RFC 2518.
      *
      * @return Xml representation
+     * @param document
      */
-    public Element toXml() {
-        Element activeLock = new Element(XML_ACTIVELOCK, NAMESPACE);
-
-        // locktype property
-        Element property = new Element(XML_LOCKTYPE, NAMESPACE);
-        property.addContent(getType().toXml());
-        activeLock.addContent(property);
+    public Element toXml(Document document) {
+        Element activeLock = DomUtil.createElement(document, XML_ACTIVELOCK, NAMESPACE);
 
         // lockscope property
-        property = new Element(XML_LOCKSCOPE, NAMESPACE);
-        property.addContent(getScope().toXml());
-        activeLock.addContent(property);
-
+        activeLock.appendChild(getScope().toXml(document));
+        // locktype property
+        activeLock.appendChild(getType().toXml(document));
         // depth
-        activeLock.addContent(XmlUtil.depthToXml(isDeep()));
+        activeLock.appendChild(DomUtil.depthToXml(isDeep(), document));
         // timeout
         long timeout = getTimeout();
         if (!isExpired() && timeout != UNDEFINED_TIMEOUT) {
-            activeLock.addContent(XmlUtil.timeoutToXml(timeout));
+            activeLock.appendChild(DomUtil.timeoutToXml(timeout, document));
         }
 
         // owner
         if (getOwner() != null) {
-            property = new Element(XML_OWNER, NAMESPACE);
-            property.setText(getOwner());
-            activeLock.addContent(property);
+            DomUtil.addChildElement(activeLock, XML_OWNER, NAMESPACE, getOwner());
         }
 
         // locktoken
         if (getToken() != null) {
-            property = new Element(XML_LOCKTOKEN, NAMESPACE);
-            Element href = new Element(XML_HREF, NAMESPACE);
-            href.setText(getToken());
-            property.addContent(href);
-            activeLock.addContent(property);
+            Element lToken = DomUtil.addChildElement(activeLock, XML_LOCKTOKEN, NAMESPACE);
+            lToken.appendChild(DomUtil.hrefToXml(getToken(), document));
         }
         return activeLock;
     }
+
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractLockEntry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractLockEntry.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractLockEntry.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/AbstractLockEntry.java Fri Jan 13 03:11:35 2006
@@ -17,10 +17,12 @@
 
 import org.apache.log4j.Logger;
 import org.apache.jackrabbit.webdav.DavConstants;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 /**
- * <code>AbstractLockEntry</code> provides the generic {@link #toXml} method.
+ * <code>AbstractLockEntry</code> provides the generic {@link org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml} method.
  */
 public abstract class AbstractLockEntry implements LockEntry, DavConstants {
 
@@ -30,15 +32,14 @@
      * Returns the Xml representation of this <code>LockEntry</code>.
      *
      * @return Xml representation
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     * @param document
      */
-    public Element toXml() {
-        Element entry = new Element(XML_LOCKENTRY, NAMESPACE);
-        Element prop = new Element(XML_LOCKSCOPE, NAMESPACE);
-        prop.addContent(getScope().toXml());
-        entry.addContent(prop);
-        prop = new Element(XML_LOCKTYPE, NAMESPACE);
-        prop.addContent(getType().toXml());
-        entry.addContent(prop);
+    public Element toXml(Document document) {
+        Element entry = DomUtil.createElement(document, XML_LOCKENTRY, NAMESPACE);
+        entry.appendChild(getScope().toXml(document));
+        entry.appendChild(getType().toXml(document));
         return entry;
     }
+
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/ActiveLock.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/ActiveLock.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/ActiveLock.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/ActiveLock.java Fri Jan 13 03:11:35 2006
@@ -15,13 +15,13 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 
 /**
  * <code>ActiveLock</code> encapsulates the lock information for a
  * {@link org.apache.jackrabbit.webdav.DavResource}.
  */
-public interface ActiveLock {
+public interface ActiveLock extends XmlSerializable {
 
     /**
      * Return true, if the given token matches the lock token present in this
@@ -104,11 +104,4 @@
      * @return scope
      */
     public Scope getScope();
-
-    /**
-     * Return the Xml representation of this lock.
-     *
-     * @return Xml representation of this lock
-     */
-    public Element toXml();
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockDiscovery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockDiscovery.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockDiscovery.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockDiscovery.java Fri Jan 13 03:11:35 2006
@@ -15,9 +15,10 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.List;
 import java.util.ArrayList;
@@ -75,29 +76,31 @@
     }
 
     /**
+     * Returns the list of active locks.
+     *
+     * @return list of active locks
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#getValue()
+     */
+    public Object getValue() {
+        return activeLocks;
+    }
+
+    /**
      * Creates a JDOM  <code>&lt;lockdiscovery&gt;</code> element in order to respond to a LOCK
      * request or to the lockdiscovery property of a PROPFIND request.<br>
      * NOTE: if the {@link #activeLocks} list is empty an empty lockdiscovery
      * property is created ( <code>&lt;lockdiscovery/&gt;</code>)
      * @return A JDOM element of the &lt;active> lock tag.
+     * @param document
      */
-    public Element toXml() {
-        Element lockdiscovery = getName().toXml();
+    public Element toXml(Document document) {
+        Element lockdiscovery = getName().toXml(document);
         Iterator it = activeLocks.iterator();
         while (it.hasNext()) {
             ActiveLock lock = (ActiveLock) it.next();
-            lockdiscovery.addContent(lock.toXml());
+            lockdiscovery.appendChild(lock.toXml(document));
 	}
 	return lockdiscovery;
     }
 
-    /**
-     * Returns the list of active locks.
-     *
-     * @return list of active locks
-     * @see org.apache.jackrabbit.webdav.property.DavProperty#getValue()
-     */
-    public Object getValue() {
-        return activeLocks;
-    }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockEntry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockEntry.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockEntry.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockEntry.java Fri Jan 13 03:11:35 2006
@@ -15,12 +15,12 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 
 /**
  * <code>LockEntry</code>...
  */
-public interface LockEntry {
+public interface LockEntry extends XmlSerializable {
 
     /**
      * Returns the type of this lock entry
@@ -35,11 +35,4 @@
      * @return scope of this lock entry.
      */
     public Scope getScope();
-
-    /**
-     * Returns the Xml representation of this entry.
-     *
-     * @return Xml representation
-     */
-    public Element toXml();
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockInfo.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockInfo.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockInfo.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/LockInfo.java Fri Jan 13 03:11:35 2006
@@ -16,10 +16,11 @@
 package org.apache.jackrabbit.webdav.lock;
 
 import org.apache.jackrabbit.webdav.DavConstants;
-import org.jdom.Element;
-
-import java.util.List;
-import java.util.Iterator;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 /**
  * <code>LockInfo</code> is a simple utility class encapsulating the information
@@ -31,7 +32,7 @@
  * given, since this left to those objects responsible for the lock creation
  * on the requested resource.
  */
-public class LockInfo {
+public class LockInfo implements DavConstants, XmlSerializable {
 
     private Type type;
     private Scope scope;
@@ -42,6 +43,38 @@
     private boolean isRefreshLock;
 
     /**
+     * Create a new <code>LockInfo</code> used for refreshing an existing lock.
+     * 
+     * @param timeout
+     */
+    public LockInfo(long timeout) {
+        this.timeout = (timeout > 0) ? timeout : INFINITE_TIMEOUT;
+        this.isRefreshLock = true;
+    }
+
+    /**
+     * Create a new <code>LockInfo</code>
+     *
+     * @param scope
+     * @param type
+     * @param owner
+     * @param timeout
+     * @param isDeep
+     */
+    public LockInfo(Scope scope, Type type, String owner, long timeout, boolean isDeep) {
+        this.timeout = (timeout > 0) ? timeout : INFINITE_TIMEOUT;
+        this.isDeep = isDeep;
+
+        if (scope == null || type == null) {
+            this.isRefreshLock = true;
+        } else {
+            this.scope = scope;
+            this.type = type;
+            this.owner = owner;
+        }
+    }
+
+    /**
      * Create a new <code>LockInfo</code> object from the given information. If
      * <code>liElement</code> is <code>null</code> this lockinfo is assumed to
      * be issued from a 'Refresh Lock' request.
@@ -57,29 +90,28 @@
      * <code>null</null> but does not start with an 'lockinfo' element.
      */
     public LockInfo(Element liElement, long timeout, boolean isDeep) {
-        this.timeout = timeout;
+        this.timeout = (timeout > 0) ? timeout : INFINITE_TIMEOUT;
         this.isDeep = isDeep;
 
         if (liElement != null) {
-            if (!DavConstants.XML_LOCKINFO.equals(liElement.getName())) {
-                throw new IllegalArgumentException("Element must have name 'lockinfo'.");
+            if (!DomUtil.matches(liElement, XML_LOCKINFO, NAMESPACE)) {
+                throw new IllegalArgumentException("'DAV:lockinfo' element expected.");
             }
 
-            List childList = liElement.getChildren();
-            for (int i = 0; i < childList.size(); i++) {
-                Element child = (Element) childList.get(i);
-                String nodeName = child.getName();
-                if (DavConstants.XML_LOCKTYPE.equals(nodeName)) {
-                    Element typeElement = getFirstChildElement(child);
-                    type = Type.create(typeElement);
-                } else if (DavConstants.XML_LOCKSCOPE.equals(nodeName)) {
-                    Element scopeElement = getFirstChildElement(child);
-                    scope = Scope.create(scopeElement);
-                } else if (DavConstants.XML_OWNER.equals(nodeName)) {
-                    owner = child.getChildTextTrim(DavConstants.XML_HREF);
+            ElementIterator it = DomUtil.getChildren(liElement);
+            while (it.hasNext()) {
+                Element child = it.nextElement();
+                String childName = child.getLocalName();
+                if (XML_LOCKTYPE.equals(childName)) {
+                    type = Type.createFromXml(child);
+                } else if (XML_LOCKSCOPE.equals(childName)) {
+                    scope = Scope.createFromXml(child);
+                } else if (XML_OWNER.equals(childName)) {
+                    // first try if 'owner' is inside a href element
+                    owner = DomUtil.getChildTextTrim(child, XML_HREF, NAMESPACE);
                     if (owner==null) {
-                        // check if child is a text element
-                        owner = child.getTextTrim();
+                        // otherwise: assume owner is a simple text element
+                        owner = DomUtil.getTextTrim(child);
                     }
                 }
             }
@@ -90,25 +122,6 @@
     }
 
     /**
-     * Retrieve the first element from the content list of the specified Xml element.
-     *
-     * @param elem
-     * @return
-     */
-    private static Element getFirstChildElement(Element elem) {
-        if (elem.getContentSize() > 0) {
-            Iterator it = elem.getContent().iterator();
-            while (it.hasNext()) {
-                Object content = it.next();
-                if (content instanceof Element) {
-                    return (Element) content;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
      * Returns the lock type or <code>null</null> if no 'lockinfo' element was
      * passed to the constructor or did not contain an 'type' element and the
      * type has not been set otherwise.
@@ -188,4 +201,29 @@
     public boolean isRefreshLock() {
         return isRefreshLock;
     }
+
+    /**
+     * Returns the xml representation of this lock info.<br>
+     * NOTE however, that the depth and the timeout are not included
+     * in the xml. They will be passed to the server using the corresponding
+     * request headers.
+     *
+     * @param document
+     * @return xml representation of this lock info.
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     */
+    public Element toXml(Document document) {
+        if (isRefreshLock) {
+            return null;
+        } else {
+            Element lockInfo = DomUtil.createElement(document, XML_LOCKINFO, NAMESPACE);
+            lockInfo.appendChild(scope.toXml(document));
+            lockInfo.appendChild(type.toXml(document));
+            if (owner != null) {
+                DomUtil.addChildElement(lockInfo, XML_OWNER, NAMESPACE, owner);
+            }
+            return lockInfo;
+        }
+    }
+
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Scope.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Scope.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Scope.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Scope.java Fri Jan 13 03:11:35 2006
@@ -15,33 +15,37 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
-import org.jdom.Namespace;
 import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.Namespace;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
-import java.util.*;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * The <code>Scope</code> class abstracts the lock scope as defined by RFC 2518.
  */
-public class Scope {
+public class Scope implements XmlSerializable {
 
     private static final Map scopes = new HashMap();
 
     public static final Scope EXCLUSIVE = Scope.create(DavConstants.XML_EXCLUSIVE, DavConstants.NAMESPACE);
     public static final Scope SHARED = Scope.create(DavConstants.XML_SHARED, DavConstants.NAMESPACE);
 
-    private final String name;
+    private final String localName;
     private final Namespace namespace;
 
     /**
      * Private constructor
      *
-     * @param name
+     * @param localName
      * @param namespace
      */
-    private Scope(String name, Namespace namespace) {
-        this.name = name;
+    private Scope(String localName, Namespace namespace) {
+        this.localName = localName;
         this.namespace = namespace;
     }
 
@@ -50,9 +54,29 @@
      * the LOCK request and response body and in the {@link LockDiscovery}.
      *
      * @return Xml representation
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
      */
-    public Element toXml() {
-        return new Element(name, namespace);
+    public Element toXml(Document document) {
+        Element lockScope = DomUtil.createElement(document, DavConstants.XML_LOCKSCOPE, DavConstants.NAMESPACE);
+        DomUtil.addChildElement(lockScope, localName, namespace);
+        return lockScope;
+    }
+
+    /**
+     * Returns <code>true</code> if this Scope is equal to the given one.
+     *
+     * @param obj
+     * @return
+     */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Scope) {
+            Scope other = (Scope) obj;
+            return localName.equals(other.localName) && namespace.equals(other.namespace);
+        }
+        return false;
     }
 
     /**
@@ -61,46 +85,33 @@
      * @param lockScope
      * @return Scope object.
      */
-    public static Scope create(Element lockScope) {
+    public static Scope createFromXml(Element lockScope) {
+        if (lockScope != null && DavConstants.XML_LOCKSCOPE.equals(lockScope.getLocalName())) {
+            // we have the parent element and must retrieve the scope first
+            lockScope = DomUtil.getFirstChildElement(lockScope);
+        }
         if (lockScope == null) {
-            throw new IllegalArgumentException("'null' is not valid lock scope entry.");
+            throw new IllegalArgumentException("'null' is not a valid lock scope entry.");
         }
-        return create(lockScope.getName(), lockScope.getNamespace());
+        Namespace namespace = Namespace.getNamespace(lockScope.getPrefix(), lockScope.getNamespaceURI());
+        return create(lockScope.getLocalName(), namespace);
     }
 
     /**
      * Create a <code>Scope</code> object from the given name and namespace.
      *
-     * @param name
+     * @param localName
      * @param namespace
      * @return Scope object.
      */
-    public static Scope create(String name, Namespace namespace) {
-	String key = "{" + namespace.getURI() + "}" + name;
+    public static Scope create(String localName, Namespace namespace) {
+        String key = DomUtil.getQualifiedName(localName, namespace);
         if (scopes.containsKey(key)) {
             return (Scope) scopes.get(key);
         } else {
-            Scope scope = new Scope(name, namespace);
+            Scope scope = new Scope(localName, namespace);
             scopes.put(key, scope);
             return scope;
         }
     }
-
-    /**
-     * Returns <code>true</code> if this Scope is equal to the given one.
-     *
-     * @param obj
-     * @return
-     */
-    public boolean equals(Object obj) {
-	if (this == obj) {
-	    return true;
-	}
-	if (obj instanceof Scope) {
-	    Scope other = (Scope) obj;
-	    return name.equals(other.name) && namespace.equals(other.namespace);
-	}
-	return false;
-    }
-
 }

Modified: 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?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SimpleLockManager.java Fri Jan 13 03:11:35 2006
@@ -18,8 +18,11 @@
 import java.util.HashMap;
 import java.util.Iterator;
 
-import org.apache.jackrabbit.webdav.*;
 import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavResourceIterator;
 
 /**
  * Simple manager for webdav locks.<br>

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SupportedLock.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SupportedLock.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SupportedLock.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/SupportedLock.java Fri Jan 13 03:11:35 2006
@@ -15,9 +15,10 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -96,13 +97,14 @@
      * Creates a JDOM element that represents the &lt;supportedlock> tag.
      * 
      * @return A JDOM element of this lock support.
+     * @param document
      */
-    public Element toXml() {
-        Element support = getName().toXml();
+    public Element toXml(Document document) {
+        Element support = getName().toXml(document);
         Iterator iter = entries.iterator();
         while (iter.hasNext()) {
             LockEntry le = (LockEntry) iter.next();
-            support.addContent(le.toXml());
+            support.appendChild(le.toXml(document));
         }
 	return support;
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Type.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Type.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Type.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/lock/Type.java Fri Jan 13 03:11:35 2006
@@ -15,22 +15,26 @@
  */
 package org.apache.jackrabbit.webdav.lock;
 
-import org.jdom.Element;
-import org.jdom.Namespace;
 import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.Namespace;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * The <code>Type</code> class encapsulates the lock type as defined by RFC 2518.
  */
-public class Type {
+public class Type implements XmlSerializable {
 
     private static Map types = new HashMap();
 
     public static final Type WRITE = Type.create(DavConstants.XML_WRITE, DavConstants.NAMESPACE);
 
-    private final String name;
+    private final String localName;
     private final Namespace namespace;
 
     /**
@@ -40,7 +44,7 @@
      * @param namespace
      */
     private Type(String name, Namespace namespace) {
-        this.name = name;
+        this.localName = name;
         this.namespace = namespace;
     }
 
@@ -48,9 +52,29 @@
      * Returns the Xml representation of this lock <code>Type</code>.
      *
      * @return Xml representation
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
      */
-    public Element toXml() {
-        return new Element(name, namespace);
+    public Element toXml(Document document) {
+        Element lockType = DomUtil.createElement(document, DavConstants.XML_LOCKTYPE, DavConstants.NAMESPACE);
+        DomUtil.addChildElement(lockType, localName, namespace);
+        return lockType;
+    }
+
+    /**
+     * Returns <code>true</code> if this Type is equal to the given one.
+     *
+     * @param obj
+     * @return
+     */
+    public boolean equals(Object obj) {
+	if (this == obj) {
+	    return true;
+	}
+	if (obj instanceof Type) {
+	    Type other = (Type) obj;
+	    return localName.equals(other.localName) && namespace.equals(other.namespace);
+	}
+	return false;
     }
 
     /**
@@ -59,45 +83,33 @@
      * @param lockType
      * @return <code>Type</code> object.
      */
-    public static Type create(Element lockType) {
+    public static Type createFromXml(Element lockType) {
+        if (lockType != null && DavConstants.XML_LOCKTYPE.equals(lockType.getLocalName())) {
+            // we have the parent element and must retrieve the type first
+            lockType = DomUtil.getFirstChildElement(lockType);
+        }
         if (lockType == null) {
             throw new IllegalArgumentException("'null' is not valid lock type entry.");
         }
-        return create(lockType.getName(), lockType.getNamespace());
+        Namespace namespace = Namespace.getNamespace(lockType.getPrefix(), lockType.getNamespaceURI());
+        return create(lockType.getLocalName(), namespace);
     }
 
     /**
-     * Create a <code>Type</code> object from the given name and namespace.
+     * Create a <code>Type</code> object from the given localName and namespace.
      *
-     * @param name
+     * @param localName
      * @param namespace
      * @return <code>Type</code> object.
      */
-    public static Type create(String name, Namespace namespace) {
-	String key = "{" + namespace.getURI() + "}" + name;
+    public static Type create(String localName, Namespace namespace) {
+        String key = DomUtil.getQualifiedName(localName, namespace);
         if (types.containsKey(key)) {
             return (Type) types.get(key);
         } else {
-            Type type = new Type(name, namespace);
+            Type type = new Type(localName, namespace);
             types.put(key, type);
             return type;
         }
-    }
-
-    /**
-     * Returns <code>true</code> if this Type is equal to the given one.
-     *
-     * @param obj
-     * @return
-     */
-    public boolean equals(Object obj) {
-	if (this == obj) {
-	    return true;
-	}
-	if (obj instanceof Type) {
-	    Type other = (Type) obj;
-	    return name.equals(other.name) && namespace.equals(other.namespace);
-	}
-	return false;
     }
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventBundle.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventBundle.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventBundle.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventBundle.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,28 @@
+/*
+ * 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.observation;
+
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+
+/**
+ * <code>EventBundle</code> defines an empty interface used to represent a bundle
+ * of events.
+ *
+ * @see EventDiscovery#addEventBundle(EventBundle) 
+ */
+public interface EventBundle extends XmlSerializable {
+
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventBundle.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventDiscovery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventDiscovery.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventDiscovery.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventDiscovery.java Fri Jan 13 03:11:35 2006
@@ -16,10 +16,14 @@
 package org.apache.jackrabbit.webdav.observation;
 
 import org.apache.log4j.Logger;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * <code>EventDiscovery</code> represents the request body of a successfull
@@ -27,7 +31,7 @@
  * definition what events that particular subscription is interested in was
  * specified with the initial SUBSCRIPTION that started the event listening.
  */
-public class EventDiscovery implements ObservationConstants {
+public class EventDiscovery implements ObservationConstants, XmlSerializable {
 
     private static Logger log = Logger.getLogger(EventDiscovery.class);
 
@@ -41,7 +45,7 @@
      * @param eventBundle
      * @see Subscription
      */
-    public void addEventBundle(Element eventBundle) {
+    public void addEventBundle(EventBundle eventBundle) {
         if (eventBundle != null) {
             bundles.add(eventBundle);
         }
@@ -52,10 +56,17 @@
      * being present in the POLL response body.
      *
      * @return Xml representation
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     * @param document
      */
-    public Element toXml() {
-        Element ed = new Element(XML_EVENTDISCOVERY, NAMESPACE);
-        ed.addContent(bundles);
+    public Element toXml(Document document) {
+        Element ed = DomUtil.createElement(document, XML_EVENTDISCOVERY, NAMESPACE);
+        Iterator it = bundles.iterator();
+        while (it.hasNext()) {
+            EventBundle bundle = (EventBundle)it.next();
+            ed.appendChild(bundle.toXml(document));
+        }
         return ed;
     }
+
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventType.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventType.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventType.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,29 @@
+/*
+ * 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.observation;
+
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.Namespace;
+
+/**
+ * <code>EventType</code>...
+ */
+public interface EventType extends XmlSerializable {
+
+    public String getName();
+
+    public Namespace getNamespace();
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/EventType.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Filter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Filter.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Filter.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Filter.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.observation;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.Namespace;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+/**
+ * <code>Filter</code>...
+ */
+public class Filter implements XmlSerializable {
+
+    private static Logger log = Logger.getLogger(Filter.class);
+
+    private final String filterName;
+    private final Namespace filterNamespace;
+    private final String filterValue;
+
+    public Filter(String filterName, Namespace filterNamespace, String filterValue) {
+        if (filterName == null) {
+            throw new IllegalArgumentException("filterName must not be null.");
+        }
+        this.filterName = filterName;
+        this.filterNamespace = filterNamespace;
+        this.filterValue = filterValue;
+    }
+
+    public Filter(Element filterElem) {
+        filterName = filterElem.getLocalName();
+        filterNamespace = DomUtil.getNamespace(filterElem);
+        filterValue = DomUtil.getTextTrim(filterElem);
+    }
+
+    public String getName() {
+        return filterName;
+    }
+
+    public Namespace getNamespace() {
+        return filterNamespace;
+    }
+
+    public String getValue() {
+        return filterValue;
+    }
+
+    public boolean isMatchingFilter(String localName, Namespace namespace) {
+        boolean matchingNsp = (filterNamespace == null) ? namespace == null : filterNamespace.equals(namespace);
+        return filterName.equals(localName) && matchingNsp;
+    }
+
+    public Element toXml(Document document) {
+        return DomUtil.createElement(document, filterName, filterNamespace, filterValue);
+    }
+
+}
\ No newline at end of file

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

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Filter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/ObservationConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/ObservationConstants.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/ObservationConstants.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/ObservationConstants.java Fri Jan 13 03:11:35 2006
@@ -15,8 +15,8 @@
  */
 package org.apache.jackrabbit.webdav.observation;
 
-import org.jdom.Namespace;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.xml.Namespace;
 
 /**
  * <code>ObservationConstants</code> interface provide constants for request

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Subscription.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Subscription.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Subscription.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/Subscription.java Fri Jan 13 03:11:35 2006
@@ -15,13 +15,18 @@
  */
 package org.apache.jackrabbit.webdav.observation;
 
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 
 /**
  * <code>Subscription</code> represents public representation of the event
- * listener created (or modified) by a successful SUBSCRIBE request.
+ * listener created (or modified) by a successful SUBSCRIBE request.<br>
+ * Please note that this interface extends the <code>XmlSerializable</code>
+ * interface. Tthe Xml representation of a <code>Subscription</code> is
+ * returned in the response to a successful SUBSCRIBE request as well
+ * as in a PROPFIND request. In both cases the subscription is packed into
+ * a {@link SubscriptionDiscovery} property object.
  */
-public interface Subscription {
+public interface Subscription extends XmlSerializable {
 
     /**
      * Returns the id of this subscription, that must be used for unsubscribing
@@ -30,15 +35,4 @@
      * @return subscriptionId
      */
     public String getSubscriptionId();
-
-    /**
-     * Return the Xml representation of this <code>Subscription</code> that is
-     * returned in the response to a successful SUBSCRIBE request as well
-     * as in a PROPFIND request. In both cases the subscription is packed into
-     * a {@link SubscriptionDiscovery} property object.
-     *
-     * @return Xml representation
-     */
-    public Element toXml();
-
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionDiscovery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionDiscovery.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionDiscovery.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionDiscovery.java Fri Jan 13 03:11:35 2006
@@ -16,7 +16,8 @@
 package org.apache.jackrabbit.webdav.observation;
 
 import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
-import org.jdom.Element;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 /**
  * <code>SubscriptionDiscovery</code> encapsulates the 'subscriptiondiscovery'
@@ -53,26 +54,28 @@
     }
 
     /**
+     * Returns an array of {@link Subscription}s.
+     *
+     * @return an array of {@link Subscription}s
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#getValue()
+     */
+    public Object getValue() {
+        return subscriptions;
+    }
+
+    /**
      * Returns the Xml representation of the subscription discovery.
      *
      * @return Xml representation
-     * @see org.apache.jackrabbit.webdav.property.DavProperty#toXml()
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     * @param document
      */
-    public Element toXml() {
-        Element elem = getName().toXml();
+    public Element toXml(Document document) {
+        Element elem = getName().toXml(document);
         for (int i = 0; i < subscriptions.length; i++) {
-            elem.addContent(subscriptions[i].toXml());
+            elem.appendChild(subscriptions[i].toXml(document));
         }
         return elem;
     }
 
-    /**
-     * Returns an array of {@link Subscription}s.
-     *
-     * @return an array of {@link Subscription}s
-     * @see org.apache.jackrabbit.webdav.property.DavProperty#getValue()
-     */
-    public Object getValue() {
-        return subscriptions;
-    }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionInfo.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionInfo.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionInfo.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/observation/SubscriptionInfo.java Fri Jan 13 03:11:35 2006
@@ -16,24 +16,82 @@
 package org.apache.jackrabbit.webdav.observation;
 
 import org.apache.log4j.Logger;
-import org.apache.jackrabbit.webdav.util.XmlUtil;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.webdav.xml.Namespace;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
  * <code>SubscriptionInfo</code> class encapsulates the subscription info
- * that forms the request body of a SUBSCRIBE request.
+ * that forms the request body of a SUBSCRIBE request.<br>
+ * The following xml layout is defined for the subscription info:
+ * <pre>
+ * &lt;!ELEMENT subscriptioninfo ( eventtype, nolocal?, filter? ) &gt;
+ * &lt;!ELEMENT eventtype ANY &gt;
+ *
+ * ANY defines any sequence of elements where at least one defines a valid
+ * eventtype. Note that a single eventtype must not occur multiple times.
+
+ * &lt;!ELEMENT nolocal EMPTY &gt;
+ * &lt;!ELEMENT filter ANY &gt;
+ *
+ * ANY: any sequence of elements identifying a filter for event listening but
+ * at least a single element.
+ * </pre>
  * @see ObservationConstants#XML_SUBSCRIPTIONINFO
  */
-public class SubscriptionInfo implements ObservationConstants {
+public class SubscriptionInfo implements ObservationConstants, XmlSerializable {
 
     private static Logger log = Logger.getLogger(SubscriptionInfo.class);
 
-    private Element info;
-    private List eventTypes;
-    private long timeout;
-    private boolean isDeep;
+    private final EventType[] eventTypes;
+    private final Filter[] filters;
+    private final boolean noLocal;
+    private final boolean isDeep;
+    private final long timeout;
+
+    /**
+     * Create a new <code>SubscriptionInfo</code>
+     *
+     * @param eventTypes
+     * @param isDeep
+     * @param timeout
+     */
+    public SubscriptionInfo(EventType[] eventTypes, boolean isDeep, long timeout) {
+        this(eventTypes, null, false, isDeep, timeout);
+    }
+
+    /**
+     * Create a new <code>SubscriptionInfo</code>
+     *
+     * @param eventTypes
+     * @param filters
+     * @param noLocal
+     * @param isDeep
+     * @param timeout
+     */
+    public SubscriptionInfo(EventType[] eventTypes, Filter[] filters, boolean noLocal, boolean isDeep, long timeout) {
+        if (eventTypes == null || eventTypes.length == 0) {
+            throw new IllegalArgumentException("'subscriptioninfo' must at least indicate a single event type.");
+        }
+
+        this.eventTypes = eventTypes;
+        this.noLocal = noLocal;
+
+        if (filters != null) {
+            this.filters = filters;
+        } else {
+            this.filters = new Filter[0];
+        }
+
+        this.isDeep = isDeep;
+        this.timeout = timeout;
+    }
 
     /**
      * Create a new <code>SubscriptionInfo</code>
@@ -44,57 +102,79 @@
      * @throws IllegalArgumentException if the reqInfo element does not contain the mandatory elements.
      */
     public SubscriptionInfo(Element reqInfo, long timeout, boolean isDeep) {
-        if (!XML_SUBSCRIPTIONINFO.equals(reqInfo.getName())) {
+        if (!DomUtil.matches(reqInfo, XML_SUBSCRIPTIONINFO, NAMESPACE)) {
             throw new IllegalArgumentException("Element with name 'subscriptioninfo' expected");
         }
-        if (reqInfo.getChild(XML_EVENTTYPE, NAMESPACE) == null ) {
+        List typeList = new ArrayList();
+        Element el = DomUtil.getChildElement(reqInfo, XML_EVENTTYPE, NAMESPACE);
+        if (el != null) {
+            ElementIterator it = DomUtil.getChildren(el);
+            while (it.hasNext()) {
+                Element typeElem = it.nextElement();
+                EventType et = new SimpleEventType(typeElem.getLocalName(), DomUtil.getNamespace(typeElem));
+                typeList.add(et);
+            }
+        } else {
             throw new IllegalArgumentException("'subscriptioninfo' must contain an 'eventtype' child element.");
         }
 
-        eventTypes = reqInfo.getChild(XML_EVENTTYPE, NAMESPACE).getChildren();
-        if (eventTypes.size() == 0) {
+        if (typeList.isEmpty()) {
             throw new IllegalArgumentException("'subscriptioninfo' must at least indicate a single event type.");
         }
+        eventTypes = (EventType[]) typeList.toArray(new EventType[typeList.size()]);
 
-        // detach the request info, in order to remove the reference to the parent
-        this.info = (Element)reqInfo.detach();
+        List filters = new ArrayList();
+        el = DomUtil.getChildElement(reqInfo, XML_FILTER, NAMESPACE);
+        if (el != null) {
+            ElementIterator it = DomUtil.getChildren(el);
+            while (it.hasNext()) {
+                Filter f = new Filter(it.nextElement());
+                filters.add(f);
+            }
+        }
+        this.filters = (Filter[])filters.toArray(new Filter[filters.size()]);
+
+        this.noLocal = DomUtil.hasChildElement(reqInfo, XML_NOLOCAL, NAMESPACE);
         this.isDeep = isDeep;
-        setTimeOut(timeout);
+        this.timeout = timeout;
     }
 
     /**
-     * Return list of event types Xml elements present in the subscription info.
-     * NOTE: the elements need to be detached in order to be added as content
-     * to any other Xml element.
+     * Return array of event type names present in the subscription info.
      *
-     * @return List of Xml elements defining which events this subscription should
-     * listen to.
+     * @return array of String defining the names of the events this subscription
+     * should listen to.
      *
      */
-    public List getEventTypes() {
+    public EventType[] getEventTypes() {
         return eventTypes;
     }
 
     /**
+     * Return all filters defined for this <code>SubscriptionInfo</code>
+     *
+     * @return all filters or an empty Filter array.
+     */
+    public Filter[] getFilters() {
+        return filters;
+    }
+
+    /**
      * Return array of filters with the specified name.
      *
-     * @param name the filter elments must provide.
+     * @param localName the filter elments must provide.
+     * @param namespace
      * @return array containing the text of the filter elements with the given
      * name.
      */
-    public String[] getFilters(String name) {
-        String[] filters = null;
-        Element filter = info.getChild(XML_FILTER);
-        if (filter != null) {
-            List li = filter.getChildren(name);
-            if (!li.isEmpty()) {
-                filters = new String[li.size()];
+    public Filter[] getFilters(String localName, Namespace namespace) {
+        List l = new ArrayList();
                 for (int i = 0; i < filters.length; i++) {
-                    filters[i] = ((Element)li.get(i)).getText();
+            if (filters[i].isMatchingFilter(localName, namespace)) {
+               l.add(filters[i]);
                 }
             }
-        }
-        return filters;
+        return (Filter[])l.toArray(new Filter[l.size()]);
     }
 
     /**
@@ -104,7 +184,7 @@
      * @return if {@link #XML_NOLOCAL} element is present.
      */
     public boolean isNoLocal() {
-        return info.getChild(XML_NOLOCAL, NAMESPACE) != null;
+        return noLocal;
     }
 
     /**
@@ -128,21 +208,57 @@
     }
 
     /**
-     * Set the timeout. NOTE: no validation is made.
+     * Xml representation of this <code>SubscriptionInfo</code>.
      *
-     * @param timeout as defined by the {@link org.apache.jackrabbit.webdav.DavConstants#HEADER_TIMEOUT}.
+     * @return Xml representation
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     * @param document
      */
-    public void setTimeOut(long timeout) {
-        this.timeout = timeout;
+    public Element toXml(Document document) {
+        Element subscrInfo = DomUtil.createElement(document, XML_SUBSCRIPTIONINFO, NAMESPACE);
+        Element eventType = DomUtil.addChildElement(subscrInfo, XML_EVENTTYPE, NAMESPACE);
+        for (int i = 0; i < eventTypes.length; i++) {
+            eventType.appendChild(eventTypes[i].toXml(document));
+        }
+
+        if (filters.length > 0) {
+            Element filter = DomUtil.addChildElement(subscrInfo, XML_FILTER, NAMESPACE);
+            for (int i = 0; i < filters.length; i++) {
+                filter.appendChild(filters[i].toXml(document));
+            }
+        }
+
+        if (noLocal) {
+            DomUtil.addChildElement(subscrInfo, XML_NOLOCAL, NAMESPACE);
+        }
+        return subscrInfo;
     }
 
+    //--------------------------------------------------------< inner class >---
     /**
-     * Xml representation of this <code>SubscriptionInfo</code>.
-     *
-     * @return Xml representation
+     * Simple EventType implementation that only consists of a qualified event
+     * name.
      */
-    public Element[] toXml() {
-        Element[] elems = { info, XmlUtil.depthToXml(isDeep), XmlUtil.timeoutToXml(timeout)};
-        return elems;
+    private class SimpleEventType implements EventType {
+
+        private String localName;
+        private Namespace namespace;
+
+        SimpleEventType(String localName, Namespace namespace) {
+            this.localName = localName;
+            this.namespace = namespace;
+        }
+
+        public Element toXml(Document document) {
+            return DomUtil.createElement(document, localName, namespace);
+        }
+
+        public String getName() {
+            return localName;
+        }
+
+        public Namespace getNamespace() {
+            return namespace;
+        }
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderPatch.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderPatch.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderPatch.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderPatch.java Fri Jan 13 03:11:35 2006
@@ -17,10 +17,13 @@
 
 import org.apache.log4j.Logger;
 import org.apache.jackrabbit.webdav.DavConstants;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.List;
-import java.util.Iterator;
 import java.util.ArrayList;
 
 /**
@@ -37,7 +40,7 @@
  * &lt;!ELEMENT after segment &gt;
  * </pre>
  */
-public class OrderPatch implements OrderingConstants{
+public class OrderPatch implements OrderingConstants, XmlSerializable {
 
     private static Logger log = Logger.getLogger(OrderPatch.class);
 
@@ -47,35 +50,11 @@
     /**
      * Create a new <code>OrderPath</code> object.
      *
-     * @param orderPatchElement
-     * @throws IllegalArgumentException if the specified Xml element was not valid.
+     * @param orderingType
+     * @param instruction
      */
-    public OrderPatch(Element orderPatchElement) {
-        if (!OrderingConstants.XML_ORDERPATCH.equals(orderPatchElement.getName()) ||
-                orderPatchElement.getChild(OrderingConstants.XML_ORDERING_TYPE) == null) {
-            throw new IllegalArgumentException("ORDERPATH request body must start with an 'orderpatch' element, which must contain an 'ordering-type' child element.");
-        }
-        // retrieve the orderingtype element
-        orderingType = orderPatchElement.getChild(OrderingConstants.XML_ORDERING_TYPE).getChildText(DavConstants.XML_HREF);
-
-        // set build the list of ordering instructions
-        List oMembers = orderPatchElement.getChildren(OrderingConstants.XML_ORDER_MEMBER, DavConstants.NAMESPACE);
-        Iterator it = oMembers.iterator();
-        int cnt = 0;
-        List tmpInst = new ArrayList();
-        while (it.hasNext()) {
-            Element member = (Element) it.next();
-            try {
-                String segment = member.getChildText(OrderingConstants.XML_SEGMENT);
-                Position pos = new Position(member.getChild(OrderingConstants.XML_POSITION));
-                Member om = new Member(segment, pos);
-                tmpInst.add(om);
-                cnt++;
-            } catch (IllegalArgumentException e) {
-                log.error("Invalid element in 'orderpatch' request body: " + e.getMessage());
-            }
-        }
-        instructions = (Member[]) tmpInst.toArray(new Member[cnt]);
+    public OrderPatch(String orderingType, Member instruction) {
+        this(orderingType, new Member[] {instruction});
     }
 
     /**
@@ -85,6 +64,9 @@
      * @param instructions
      */
     public OrderPatch(String orderingType, Member[] instructions) {
+        if (orderingType == null || instructions == null) {
+            throw new IllegalArgumentException("ordering type and instructions cannot be null.");
+        }
         this.orderingType = orderingType;
         this.instructions = instructions;
     }
@@ -108,12 +90,71 @@
         return instructions;
     }
 
+    //------------------------------------------< XmlSerializable interface >---
+    /**
+     *
+     * @return
+     * @param document
+     */
+    public Element toXml(Document document) {
+        Element orderPatch = DomUtil.createElement(document, XML_ORDERPATCH, NAMESPACE);
+        // add DAV:ordering-type below DAV:orderpatch
+        Element otype = DomUtil.addChildElement(orderPatch, XML_ORDERING_TYPE, NAMESPACE);
+        otype.appendChild(DomUtil.hrefToXml(orderingType, document));
+        // add DAV:member elements below DAV:orderpatch
+        for (int i = 0; i < instructions.length; i++) {
+            orderPatch.appendChild(instructions[i].toXml(document));
+        }
+        return null;
+    }
+
+    //------------------------------------------------------< static method >---
+    /**
+     * Create a new <code>OrderPath</code> object.
+     *
+     * @param orderPatchElement
+     * @throws IllegalArgumentException if the specified Xml element was not valid.
+     */
+    public static OrderPatch createFromXml(Element orderPatchElement) {
+        if (!DomUtil.matches(orderPatchElement, XML_ORDERPATCH, NAMESPACE)) {
+            throw new IllegalArgumentException("ORDERPATH request body must start with an 'orderpatch' element.");
+        }
+
+        // retrieve the href of the orderingtype element
+        String orderingType;
+        Element otype = DomUtil.getChildElement(orderPatchElement, XML_ORDERING_TYPE, NAMESPACE);
+        if (otype != null) {
+            orderingType = DomUtil.getChildText(otype, DavConstants.XML_HREF, DavConstants.NAMESPACE);
+        } else {
+            throw new IllegalArgumentException("ORDERPATH request body must contain an 'ordering-type' child element.");
+        }
+
+        // set build the list of ordering instructions
+        List tmpList = new ArrayList();
+        ElementIterator it = DomUtil.getChildren(orderPatchElement, XML_ORDER_MEMBER, NAMESPACE);
+        while (it.hasNext()) {
+            Element el = it.nextElement();
+            try {
+                // retrieve text 'DAV:segment' child of this DAV:order-member element
+                String segment = DomUtil.getChildText(el, XML_SEGMENT, NAMESPACE);
+                // retrieve the 'DAV:position' child element
+                Position pos = Position.createFromXml(DomUtil.getChildElement(el, XML_POSITION, NAMESPACE));
+                Member om = new Member(segment, pos);
+                tmpList.add(om);
+            } catch (IllegalArgumentException e) {
+                log.error("Invalid element in 'orderpatch' request body: " + e.getMessage());
+            }
+        }
+        Member[] instructions = (Member[]) tmpList.toArray(new Member[tmpList.size()]);
+        return new OrderPatch(orderingType, instructions);
+    }
+
     //--------------------------------------------------------------------------
     /**
      * Internal class <code>Member</code> represents the 'Order-Member' children
      * elements of an 'OrderPatch' request body present in the ORDERPATCH request.
      */
-    public class Member {
+    public static class Member implements XmlSerializable {
 
         private String memberHandle;
         private Position position;
@@ -148,5 +189,17 @@
         public Position getPosition() {
             return position;
         }
+
+        //--------------------------------------< XmlSerializable interface >---
+        /**
+         * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+         */
+        public Element toXml(Document document) {
+            Element memberElem = DomUtil.createElement(document, XML_ORDER_MEMBER, NAMESPACE);
+            DomUtil.addChildElement(memberElem, XML_SEGMENT, NAMESPACE, memberHandle);
+            memberElem.appendChild(position.toXml(document));
+            return memberElem;
+        }
+
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingConstants.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingConstants.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingConstants.java Fri Jan 13 03:11:35 2006
@@ -17,6 +17,7 @@
 
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.xml.Namespace;
 
 /**
  * <code>OrderingConstants</code> provide constants for request and response
@@ -24,6 +25,11 @@
  * <a href="http://www.ietf.org/rfc/rfc3648.txt">RFC 3648</a>.
  */
 public interface OrderingConstants {
+
+    /**
+     * The namespace
+     */
+    public static final Namespace NAMESPACE = DavConstants.NAMESPACE;
 
     /**
      * The "Ordering-Type" request header.

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingDavServletRequest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingDavServletRequest.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingDavServletRequest.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingDavServletRequest.java Fri Jan 13 03:11:35 2006
@@ -16,6 +16,7 @@
 package org.apache.jackrabbit.webdav.ordering;
 
 import org.apache.jackrabbit.webdav.DavServletRequest;
+import org.apache.jackrabbit.webdav.DavException;
 
 /**
  * <code>OrderingDavServletRequest</code> provides extensions to the
@@ -48,6 +49,6 @@
      *
      * @return <code>OrderPatch</code> object encapsulating the request body.
      */
-    public OrderPatch getOrderPatch();
+    public OrderPatch getOrderPatch() throws DavException;
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingType.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingType.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/ordering/OrderingType.java Fri Jan 13 03:11:35 2006
@@ -15,9 +15,7 @@
  */
 package org.apache.jackrabbit.webdav.ordering;
 
-import org.jdom.Element;
-import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
-import org.apache.jackrabbit.webdav.util.XmlUtil;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
 
 /**
  * <code>OrderingType</code> represents the {@link #ORDERING_TYPE
@@ -29,31 +27,25 @@
  *
  * @see org.apache.jackrabbit.webdav.property.DavProperty#isProtected()
  */
-public class OrderingType extends DefaultDavProperty implements OrderingConstants {
+public class OrderingType extends HrefProperty implements OrderingConstants {
 
     /**
-     * Create an OrderingType with the given ordering.<br>
-     * NOTE: the ordering-type property is defined to be protected.
-     *
-     * @param href
-     * @see org.apache.jackrabbit.webdav.property.DavProperty#isProtected()
+     * Creates a <code>OrderingType</code> with the default type (e.g. default
+     * value). The default value is specified to be {@link #ORDERING_TYPE_UNORDERED}.
      */
-    public OrderingType(String href) {
-        super(ORDERING_TYPE, href, true);
+    public OrderingType() {
+        this(null);
     }
 
     /**
-     * Returns the Xml representation of this property. If the property has
-     * a <code>null</code> value, the default ({@link #ORDERING_TYPE_UNORDERED
-     * DAV:unordered}) is assumed.
+     * Create an <code>OrderingType</code> with the given ordering.<br>
+     * NOTE: the ordering-type property is defined to be protected.
      *
-     * @return Xml representation
+     * @param href
+     * @see org.apache.jackrabbit.webdav.property.DavProperty#isProtected()
      */
-    public Element toXml() {
-        Element elem = getName().toXml();
-        // spec requires that the default is 'DAV:unordered'
-        String href = (getValue() != null) ? getValue().toString() : ORDERING_TYPE_UNORDERED;
-        XmlUtil.hrefToXml(href);
-        return elem;
+    public OrderingType(String href) {
+        // spec requires that the default value is 'DAV:unordered'
+        super(ORDERING_TYPE, (href != null) ? href : ORDERING_TYPE_UNORDERED, true);
     }
 }



Mime
View raw message