svn commit: r541504 [6/7] - in /xml/xindice/trunk: ./ config/ java/scratchpad/webadmin/ java/src/org/apache/xindice/client/xmldb/embed/ java/src/org/apache/xindice/core/ java/src/org/apache/xindice/core/data/ java/src/org/apache/xindice/core/filer/ jav...

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Options.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Options.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Options.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Options.java Thu May 24 18:43:39 2007
@@ -22,56 +22,38 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.xindice.core.Collection;
-import org.apache.xindice.webadmin.webdav.*;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.Location;
 
-/** 
+/**
  * This class implements the Options command for WebDAV operations on
- * Xindice. 
- * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=OPTIONS
- * @x-avalon.lifestyle type=singleton
- * 
+ * Xindice.
+ *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @author <a href="mailto:[email protected]">Gianugo Rabellino</a>
- * @version $Id $ 
+ * @version $Id $
  */
 
-public class Options extends DefaultContainer implements DAVComponent {
+public class Options implements DAVComponent {
 
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection col) throws ServletException, IOException {
-   
-    // DAV Level 1
-    res.addHeader("DAV", "1");
-    
-    String methodsAllowed = null;
-    methodsAllowed = "OPTIONS, GET, HEAD, POST, DELETE, TRACE, "
-      + "PROPFIND, PROPPATCH, COPY, MOVE, PUT, MKCOL";
-    res.addHeader("Allow", methodsAllowed);
-    
-    // MS support
-    res.addHeader("MS-Author-Via", "DAV");     
-  }
-  
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection parentCol, String resourceName) throws ServletException, IOException {
-
-    // DAV Level 1
-    res.addHeader("DAV", "1");
-    
-    String methodsAllowed = null;
-    methodsAllowed = "OPTIONS, GET, HEAD, POST, DELETE, TRACE, "
-      + "PROPFIND, PROPPATCH, COPY, MOVE";
-    res.addHeader("Allow", methodsAllowed);
-    
-    // MS support
-    res.addHeader("MS-Author-Via", "DAV"); 
-  }  
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        // DAV Level 1
+        res.addHeader("DAV", "1");
+
+        String methodsAllowed;
+        if (target.isRoot()) {
+            methodsAllowed = "OPTIONS, PROPFIND";
+        } else if (target.getName() == null) {
+            methodsAllowed = "OPTIONS, POST, DELETE, PROPFIND, PROPPATCH, COPY, MOVE, PUT, MKCOL";
+        } else {
+            methodsAllowed = "OPTIONS, GET, HEAD, POST, DELETE, PROPFIND, PROPPATCH, COPY, MOVE";
+        }
+
+        res.addHeader("Allow", methodsAllowed);
+
+        // MS support
+        res.addHeader("MS-Author-Via", "DAV");
+    }
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Options.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Post.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Post.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Post.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Post.java Thu May 24 18:43:39 2007
@@ -22,42 +22,29 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.xindice.core.Collection;
-import org.apache.xindice.webadmin.webdav.*;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.Location;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
 
-/** 
- * This class implements the Post command for WebDAV operations on
+/**
+ * This class implements the Post HTTP command for WebDAV operations on
  * Xindice. 
  * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=POST
- * @x-avalon.lifestyle type=singleton
- * 
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @author <a href="mailto:[email protected]">Gianugo Rabellino</a>
  * @version $Id$ 
  */
-public class Post extends DefaultContainer implements DAVComponent {
-
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection col) throws ServletException, IOException {
-
-    if (this.getLogger().isDebugEnabled())
-      this.getLogger().debug("Method Post is not yet implemented");
-    res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
-  }
-  
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection parentCol, String resourceName) throws ServletException, IOException {
+public class Post implements DAVComponent {
+    private static final Log log = LogFactory.getLog(Post.class);
 
-    if (this.getLogger().isDebugEnabled())
-      this.getLogger().debug("Method Post is not yet implemented");
-    res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);    
-  }
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        if (log.isDebugEnabled())
+            log.debug("Method Post is not yet implemented");
+        res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
+    }
 
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Post.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java Thu May 24 18:43:39 2007
@@ -20,659 +20,344 @@
 package org.apache.xindice.webadmin.webdav.components;
 
 import java.io.IOException;
-import java.io.OutputStream;
-import java.text.SimpleDateFormat;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.ArrayList;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Locale;
-import java.util.TimeZone;
+import java.util.HashSet;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.avalon.framework.service.ServiceException;
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
-import org.apache.xindice.core.data.Key;
-import org.apache.xindice.core.data.Record;
-import org.apache.xindice.core.meta.MetaData;
-import org.apache.xindice.util.Configuration;
-import org.apache.xindice.webadmin.util.MimeTable;
-import org.apache.xindice.webadmin.webdav.*;
+import org.apache.xindice.core.Database;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.webadmin.webdav.components.props.CreationDate;
+import org.apache.xindice.webadmin.webdav.components.props.DAVProperty;
+import org.apache.xindice.webadmin.webdav.components.props.LastModified;
+import org.apache.xindice.webadmin.webdav.components.props.DisplayName;
+import org.apache.xindice.webadmin.webdav.components.props.ResourceType;
+import org.apache.xindice.webadmin.webdav.components.props.ContentType;
 import org.apache.xindice.webadmin.webdav.WebdavStatus;
-import org.apache.xindice.xml.TextWriter;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.PartialResponse;
+import org.apache.xindice.webadmin.Location;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
 
-/** 
+/**
  * This class implements the Propfind command for WebDAV operations on
- * Xindice. 
- * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=PROPFIND
- * @x-avalon.lifestyle type=singleton
- * 
+ * Xindice. <br>
+ * <br>
+ * PROPFIND command requests properties defined for resources or collections.
+ * Request can have a body that contians XML document. It is possible
+ * to request particular property values, all property values, or a
+ * list of the names of the resource's properties. A client may choose not
+ * to submit a request body. An empty PROPFIND request body is treated as a
+ * request for the names and values of all properties.<br>
+ * <br>
+ * A client may submit a Depth header with a value of "0", "1", or "infinity"
+ * with a PROPFIND on a collection. By default, the PROPFIND method without a
+ * Depth header acts as if a "Depth: infinity" header was included.<br>
+ * <br>
+ * The default operation status code is 207 (Multi-Status).
+ *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @author <a href="mailto:[email protected]">Gianugo Rabellino</a>
- * @version $Id $ 
+ * @version $Id $
  */
-public class Propfind
-  extends DefaultContainer implements DAVComponent {
+public class Propfind implements DAVComponent {
 
-  /**
-   * Simple date format for the creation date ISO representation (partial).
-   */
-  protected static final SimpleDateFormat creationDateFormat =
-          new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
-
-  /**
-   * Simple date format for the modification date representation.
-   */
-  protected static final SimpleDateFormat modificationDateFormat =
-          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
-
-  /**
-   * default creation date.
-   */
-  protected static final String defaultCreationDate;
-  
-  /**
-   * default mdification date.
-   */
-  protected static final String defaultModificationDate;
-
-  /**
-   * default value for creation and modification date.
-   */
-  protected static final long defaultLongDate = 0;
-
-  static {
-    creationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
-    defaultCreationDate = (new StringBuffer(creationDateFormat
-      .format(new Date(defaultLongDate)))).toString();
-    modificationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
-    defaultModificationDate = (new StringBuffer(modificationDateFormat
-      .format(new Date(defaultLongDate)))).toString();    
-  }
-
-  protected static final int FIND_PROPERTY_NAMES = 0;
-  
-  protected static final int FIND_ALL_PROP = 1;
-  
-  protected static final int FIND_BY_PROPERTY = 2;
-  
-  protected static final String IDX_NS_URI = "http://apache.org/xindice/indexer";
-  
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection col) throws ServletException, IOException {
-
-    try {
-      String content = getResponse(true, req, res, col, null);
-      writeMultistatusResponse(res, content);
-    } catch(DBException e) {
-      e.printStackTrace();
-      throw new ServletException(e);
-    }
-  }
-  
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection parentCol, String resourceName) throws ServletException, IOException {
-    
-    try {
-      Document doc = null;
-      try {
-        doc = parentCol.getDocument(resourceName);
-      } catch(DBException e) {
-        doc = null;
-      }
-
-      if(doc == null) {
-      	if(getLogger().isDebugEnabled()) {
-      		getLogger().debug("[send 404] resource "+resourceName+" from request "
-      				+req.getPathInfo()+" not found!");
-      	}
-        res.sendError(HttpServletResponse.SC_NOT_FOUND);
-        return;
-      }
-      
-      String content = getResponse(false, req, res, parentCol, resourceName);
-      writeMultistatusResponse(res, content);
-
-    } catch(DBException e) {
-      e.printStackTrace();
-      throw new ServletException(e);
-    }
-  }
-
-  protected String getResponse(boolean isCollection, HttpServletRequest req,
-    HttpServletResponse res, Collection col, String name)
-    throws ServletException, DBException {
-
-    int type = FIND_ALL_PROP;
-    
-    DAVProperties searchedProps = null;
-    Document document = parseRequestContent(req);
-    if(document != null) {
-      Node propNode = null;
-      NodeList childList = document.getDocumentElement().getChildNodes();
-      for (int i=0; i < childList.getLength(); i++) {
-        Node currentNode = childList.item(i);
-        if(currentNode.getNodeType() == Node.ELEMENT_NODE) {
-          if (currentNode.getNodeName().endsWith("prop")) {
-            type = FIND_BY_PROPERTY;
-            propNode = currentNode;              
-          }          
-          if (currentNode.getNodeName().endsWith("propname")) {
-            type = FIND_PROPERTY_NAMES;
-          }
-          if (currentNode.getNodeName().endsWith("allprop")) {
-            type = FIND_ALL_PROP;
-          }
-        }
-      }
-      searchedProps = parsePropertyNames(propNode);
-    }
-    
-    String servletPath = getServletPath(req);
-    String requestPath = req.getPathInfo();
-    
-    StringBuffer response = new StringBuffer();
-    response.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
-      .append("<multistatus xmlns=\"DAV:\">\n");
-    if(isCollection) {
-      int depth = getDepth(req);
-      if(requestPath != null && !requestPath.equals("/")) { // no root
-        // requested collection
-        writePropertiesOfObject(true, col, null, searchedProps,
-            type, servletPath, response);
-        if(depth > 0) {
-          // child collections
-          try {
-            String[] childCols = col.listCollections();
-            for(int i = 0; i < childCols.length; i++) {
-              Collection childCol = col.getCollection(childCols[i]);
-              writePropertiesOfObject(true, childCol, null, searchedProps,
-                  type, servletPath, response);
-            }
-          } catch(DBException e) {
-            //TODO -> if debug -> print
-          }
-          // child resources
-          try {
-            String[] childResources = col.listDocuments();
-            for(int i = 0; i < childResources.length; i++) {
-              writePropertiesOfObject(false, col, childResources[i], searchedProps,
-                  type, servletPath, response);
-            }
-          } catch(DBException e) {
-            //TODO -> if debug -> print
-          }
-        }
-      } else { // root requested //TODO
-        // root
-        int split = servletPath.lastIndexOf('/');
-        String rootName = servletPath.substring(split+1, servletPath.length());
-        writePropertiesOfObject(true, null, rootName, searchedProps,
-            type, servletPath, response);
-        // list database
-        if(depth > 0) {
-          writePropertiesOfObject(true, col, null, searchedProps,
-              type, servletPath, response);
-        }
-      }      
-    } else {
-      writePropertiesOfObject(false, col, name, searchedProps,
-          type, servletPath, response);
-    }
-    response.append("</multistatus>\n");
-    String content = response.toString();
-    if(this.getLogger().isDebugEnabled()) {
-      this.getLogger().debug("response:\n"+content);
-    }
-    return content;
-  }
-
-  protected Document parseRequestContent(HttpServletRequest req)
-      throws ServletException {
-    // no content
-    if(req.getContentLength() == 0) {
-      return null; 
-    }
-
-    try {
-      DocumentBuilder documentBuilder = DocumentBuilderFactory
-        .newInstance().newDocumentBuilder();
-      Document document = documentBuilder.parse
-        (new InputSource(req.getInputStream()));      
-      return document;
+    public static final int FIND_BY_PROPERTY = 1;
+    public static final int FIND_PROPERTY_NAMES = 2;
+    public static final int FIND_ALL_PROP = 3;
+
+    private static final HashMap PROPS_MAP = new HashMap();
+    static {
+        DAVProperty[] props = {
+                new CreationDate(),
+                new LastModified(),
+                new DisplayName(),
+                new ResourceType(),
+                new ContentType()
+        };
+
+        for (int i = 0; i < props.length; i++) {
+            PROPS_MAP.put(props[i].getName(), props[i]);
+        }
+    }
+
+    private static final Log log = LogFactory.getLog(Propfind.class);
+
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        if (!target.isRoot() && target.getCollection() == null) {
+            res.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
 
-    } catch(ParserConfigurationException e) {
-            throw new ServletException(e);
-    } catch(Exception e) { //TODO
-      e.printStackTrace();
-      return null;
-    }
-  }
-
-  protected DAVProperties parsePropertyNames(Node propertyNode) {
-    DAVProperties properties = new DAVProperties();
-    try {
-      NodeList childList = propertyNode.getChildNodes();
-      for (int i=0; i < childList.getLength(); i++) {
-        Node currentNode = childList.item(i);
-        if(currentNode.getNodeType() == Node.ELEMENT_NODE) {
-          String nodeName = currentNode.getNodeName();
-          String propertyName = null;
-          if (nodeName.indexOf(':') != -1) {
-            propertyName = nodeName.substring(nodeName.indexOf(':') + 1);
-          } else {
-            propertyName = nodeName;
-          }
-          properties.set(propertyName);
-        }
-      }
-    } catch(Exception e ) { //TODO
-      return null;
-    }
-    if(this.getLogger().isDebugEnabled()) {
-      this.getLogger().debug("parsed request: "+properties.toString());
-    }
-    return properties;
-  }
-
-  /**
-   * returns the path to calling servlet.
-   * (not null and no ending '/')
-   *
-   * @param req servlet request.
-   */
-  protected String getServletPath(HttpServletRequest req) {  
-    String servletPath = req.getContextPath();
-    if(servletPath.endsWith("/")) {
-      servletPath = servletPath.substring(0, servletPath.length()-1);    
-    }
-    servletPath += req.getServletPath();
-    if(servletPath.endsWith("/")) {
-      servletPath = servletPath.substring(0, servletPath.length()-1);
-    }
-    return servletPath;
-  }
-
-  /**
-   * returns the maximal search depth.
-   * 
-   * @param req servlet request.
-   */
-  protected int getDepth(HttpServletRequest req) {  
-    int depth = 1; // Depth: infitiy
-    String depthStr = req.getHeader("Depth");
-    if (depthStr != null && depthStr.equals("0")) {
-      depth = 0;
-    }
-    return depth;
-  }
-
-  protected void writeMultistatusResponse(HttpServletResponse res,
-      String content) throws ServletException, IOException {
-    
-    res.setStatus(WebdavStatus.SC_MULTI_STATUS);
-    res.setContentType("text/xml; charset=utf-8");
-    byte[] resultBytes = content.getBytes("utf-8");
-    res.setContentLength(resultBytes.length);
-    OutputStream output = res.getOutputStream();
-    output.write(resultBytes);
-    output.flush();
-  }   
- 
-  /**
-   * prints the properties of a collection or resource to the StringBuffer output.
-   *
-   * @param isCollection true if the requested object is a collection.
-   * @param col requested collection or parent collection.
-   * @param resourceName name of the requested resource
-   *          (null if a collection is requested).
-   * @param searchedProperties requested properties by the client (null if the 
-   *          client requested FIND_ALL_PROP).
-   * @param requestType type of request.
-   *          (FIND_ALL_PROP / FIND_BY_PROPERTY / FIND_PROPERTY_NAMES )
-   * @param servletPath path to the calling servlet (not null, no ending '/').
-   * @param output buffer to write the data.
-   *
-   * @throws DBException if an error with the database occurs.
-   */
-  protected void writePropertiesOfObject(boolean isCollection, Collection col, 
-      String resourceName, DAVProperties searchedProps, int requestType, 
-      String servletPath, StringBuffer output) throws DBException{
-    
-    // get properties ----------------------------------------
-    String name = resourceName;
-    String href = servletPath;
-    Record record = null;
-    if(isCollection && col != null) { // collection (not root)
-      name = col.getName();
-      href += col.getCanonicalName();
-    } else if(!isCollection) { // resource
-      href += col.getCanonicalDocumentName(new Key(name));
-      if(requestType != FIND_PROPERTY_NAMES) {
         try {
-          record = col.getFiler().readRecord(new Key(name));
-        } catch(Exception e) {
+            process(req, res, target.getCollection(), target.getName());
+        } catch (DBException e) {
+            log.error(e);
+            throw new ServletException(e);
         }
-      }
     }
-    if(isCollection) {
-      href += "/";
+
+    private void process(DAVRequest req, DAVResponse res, Collection col, String name) throws DBException, IOException {
+        res.setProtocol(req.getProtocol());
+        Document requestDoc = req.getRequestDoc();
+        int type = getPropFindType(requestDoc);
+
+        Set requestedProps = null;
+        if (type == FIND_BY_PROPERTY) {
+            requestedProps = getRequestPropertyNames(requestDoc);
+        }
+
+        String contextPath = req.getContextPath();
+        if (name == null) {
+            int depth = req.getDepth();
+            String requestPath = req.getPath();
+
+            if (requestPath == null || requestPath.equals("/")) { // root
+                col = null;
+            }
+
+            HashMap values = getProperties(col, null, requestedProps, type);
+            addPropfindResponse(res, getLocation(contextPath, col), values);
+
+            if (depth != 0) {
+                processChildren(res, contextPath, col, requestedProps, type, depth);
+            }
+
+        } else {
+            Entry entry = col.getEntry(name);
+            if (entry == null) {
+                res.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            } else {
+                HashMap values = getProperties(col, entry, requestedProps, type);
+                addPropfindResponse(res, getLocation(contextPath, col, name), values);
+            }
+        }
+
+        res.closeMultistatusResponse();
     }
 
-    long longCreationDate = 0;
-    long longModificationDate = 0;
-    int length = 0;
-    if(requestType != FIND_PROPERTY_NAMES && record != null) {
-      try {
-        longCreationDate = 
-          ((Long)record.getMetaData(Record.CREATED)).longValue();
-        longModificationDate = 
-          ((Long)record.getMetaData(Record.MODIFIED)).longValue();
-      } catch(Exception e) {
-      }      
-      if(!isCollection) {
-        try {
-          length = record.getValue().getLength();
-        } catch(Exception e) {
+    private void processChildren(DAVResponse res, String contextPath, Collection col, Set requestedProps, int type, int depth)
+            throws DBException, IOException {
+        String[] children;
+        if (col == null) {
+            children = Database.listDatabases();
+        } else {
+            children = col.listCollections();
         }
-      }
-    }    
-    
-    // print properties ----------------------------------------
-    output.append("<response>\n");
-    // href
-    output.append("<href>").append(href).append("</href>\n");
-    // start props
-    output.append("<propstat>\n<prop>\n");
-    if(requestType == FIND_PROPERTY_NAMES) { // all property names
-      output.append("<displayname/>\n")
-        .append("<creationdate/>\n")
-        .append("<getlastmodified/>\n")
-        .append("<resourcetype/>\n");
-      if(!isCollection) {
-        output.append("<getcontentlength/>\n")
-          .append("<getetag/>\n");
-      }
-    } else {
-      // displayname
-      if(requestType == FIND_ALL_PROP || searchedProps.contains("displayname")) {
-        output.append("<displayname>").append(name)
-          .append("</displayname>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("displayname");
-        }
-      }
-      // creation date
-      if(requestType == FIND_ALL_PROP || searchedProps.contains("creationdate")) {
-        StringBuffer tmpCreation = new StringBuffer(creationDateFormat.format(
-              new Date(longCreationDate)));
-        output.append("<creationdate>")
-          .append(tmpCreation.toString())
-          .append("</creationdate>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("creationdate");
-        }
-      }
-      // modification date
-      if(requestType == FIND_ALL_PROP || searchedProps.contains("getlastmodified")) {
-        StringBuffer tmpModification = new StringBuffer(modificationDateFormat.format(
-              new Date(longModificationDate)));
-        output.append("<getlastmodified>")
-          .append(tmpModification.toString())
-          .append("</getlastmodified>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("getlastmodified");
-        }
-      }
-      // contentlength
-      if(!isCollection && 
-          (requestType == FIND_ALL_PROP || searchedProps.contains("getcontentlength")) ) {
-        output.append("<getcontentlength>").append(length)
-          .append("</getcontentlength>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("getcontentlength");
-        }
-      }
-      // getetag
-      if(!isCollection && 
-          (requestType == FIND_ALL_PROP || searchedProps.contains("getetag")) ) {
-        output.append("<getetag>")
-          .append(length).append("-").append(longCreationDate)
-          .append("</getetag>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("getetag");
-        }
-      }      
-      // getcontenttype
-      if(!isCollection && 
-          (requestType == FIND_ALL_PROP || searchedProps.contains("getcontenttype")) ) {
-		output.append("<getcontenttype>");
-        try {
-          MimeTable mimeTable = (MimeTable) m_serviceManager
-            .lookup(MimeTable.ROLE);
-          output.append(mimeTable.getMimeType(resourceName));
-        } catch (ServiceException e) {
-          e.printStackTrace();
-          output.append(MimeTable.XML_MIME_TYPE);
-        }
-		output.append("</getcontenttype>\n");
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("getcontenttype");
-        }
-      }
-      // resourcetype
-      if(requestType == FIND_ALL_PROP || searchedProps.contains("resourcetype")) {
-        if(isCollection) {
-          output.append("<resourcetype><collection /></resourcetype>\n");
+
+        if (depth != 0) {
+            // child resources
+            if (col != null) {
+                String[] childResources = col.listDocuments();
+                for (int i = 0; i < childResources.length; i++) {
+                    HashMap values = getProperties(col, col.getEntry(childResources[i]), requestedProps, type);
+                    addPropfindResponse(res, getLocation(contextPath, col, childResources[i]), values);
+                }
+            }
+
+            // child collections
+            for (int i = 0; i < children.length; i++) {
+                Collection childCol = col != null ?
+                        col.getCollection(children[i]) :
+                        Database.getDatabase(children[i]);
+
+                HashMap values = getProperties(childCol, null, requestedProps, type);
+                addPropfindResponse(res, getLocation(contextPath, childCol), values);
+                processChildren(res, contextPath, childCol, requestedProps, type, depth - 1 );
+            }
+        }
+    }
+
+    private HashMap getProperties(Collection col, Entry entry, Set requestedProps, int type) {
+        HashMap values = null;
+        switch (type) {
+            case FIND_PROPERTY_NAMES:
+                values = getPropertyNames(col, entry);
+                break;
+            case FIND_ALL_PROP:
+                values = getAllPropertiesValues(col, entry);
+                break;
+            case FIND_BY_PROPERTY:
+                values = getPropertiesValues(col, entry, requestedProps);
+                break;
+        }
+
+        return values;
+    }
+
+    private HashMap getPropertyNames(Collection col, Entry entry) {
+        ArrayList values = new ArrayList();
+
+        for (Iterator i = PROPS_MAP.keySet().iterator(); i.hasNext(); ) {
+            String property = (String) i.next();
+
+            if (getProperty(col, entry, property) != null) {
+                values.add(new PartialResponse.Content(property));
+            }
+        }
+
+        HashMap status = new HashMap();
+        status.put(new Integer(WebdavStatus.SC_OK), values);
+        return status;
+    }
+
+    private HashMap getPropertiesValues(Collection col, Entry entry, Set requestProps) {
+        ArrayList values = new ArrayList();
+        ArrayList notFound = new ArrayList();
+
+        for (Iterator i = requestProps.iterator(); i.hasNext(); ) {
+            String requestProp = (String) i.next();
+            if (PROPS_MAP.containsKey(requestProp)) { // supported property
+
+                PartialResponse.Content part = getProperty(col, entry, requestProp);
+
+                if (part != null) {
+                    values.add(part);
+                } else {
+                    notFound.add(new PartialResponse.Content(requestProp));
+                }
+            } else { // requested property not supported
+                notFound.add(new PartialResponse.Content(requestProp));
+            }
+        }
+
+        HashMap status = new HashMap();
+        status.put(new Integer(WebdavStatus.SC_OK), values);
+        status.put(new Integer(WebdavStatus.SC_NOT_FOUND), notFound);
+        return status;
+    }
+
+    private HashMap getAllPropertiesValues(Collection col, Entry entry) {
+        ArrayList values = new ArrayList();
+
+        Set props = PROPS_MAP.keySet();
+        for (Iterator i = props.iterator(); i.hasNext(); ) {
+            String requestProp = (String) i.next();
+
+            PartialResponse.Content part = getProperty(col, entry, requestProp);
+
+            if (part != null) {
+                values.add(part);
+            }
+        }
+
+        HashMap status = new HashMap();
+        status.put(new Integer(WebdavStatus.SC_OK), values);
+        return status;
+    }
+
+    private PartialResponse.Content getProperty(Collection col, Entry entry, String propName) {
+        DAVProperty prop = (DAVProperty) PROPS_MAP.get(propName);
+
+        PartialResponse.Content part;
+        if (entry != null) {
+            part = prop.getProperty(entry);
+        } else if (col != null) {
+            part = prop.getProperty(col);
         } else {
-          output.append("<resourcetype/>\n");
+            part = prop.getRootProperty();
+        }
+
+        return part;
+    }
+
+    private Set getRequestPropertyNames(Document doc) {
+        NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS("DAV:", "prop");
+
+        HashSet properties = new HashSet();
+        NodeList childList = nodes.item(0).getChildNodes();
+        for (int i = 0; i < childList.getLength(); i++) {
+            Node currentNode = childList.item(i);
+            if (currentNode.getNodeType() == Node.ELEMENT_NODE && currentNode.getNamespaceURI().equals("DAV:")) {
+                properties.add(currentNode.getLocalName());
+            }
         }
-        if(requestType == FIND_BY_PROPERTY) {
-          searchedProps.visit("resourcetype");
+        if (log.isDebugEnabled()) {
+            log.debug("Requested properties: " + properties.toString());
         }
-      }
+
+        return properties;
     }
-    // other properties
-    writeNondavProperties(isCollection, col, resourceName,
-        searchedProps, requestType, output);
-    // end props
-    output.append("</prop>\n<status>HTTP/1.1 ").append(WebdavStatus.SC_OK)
-      .append(" ").append(WebdavStatus.getStatusText(WebdavStatus.SC_OK))
-      .append("</status>\n</propstat>\n");
-    // write not found properties
-    if(requestType == FIND_BY_PROPERTY) {
-      String[] notFound = searchedProps.getNotVisited();
-      if(notFound.length != 0) {
-        output.append("<propstat>\n<prop>\n");
-        for(int i = 0; i < notFound.length; i++) {
-          output.append("<").append(notFound[i]).append("/>\n");
-        }
-        output.append("</prop>\n<status>HTTP/1.1 ").append(WebdavStatus.SC_NOT_FOUND)
-          .append(" ").append(WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND))
-          .append("</status>\n</propstat>\n");
-      }
-      searchedProps.resetAll();
-    }
-    // end response
-    output.append("</response>\n");
-  }
-
-  /**
-   * prints the properties of a collection or resource to the StringBuffer output.
-   *
-   * @param isCollection true if the requested object is a collection.
-   * @param col requested collection or parent collection.
-   * @param name name of the requested resource or collection.
-   * @param searchedProperties requested properties by the client (null if the 
-   *          client requested FIND_ALL_PROP).
-   * @param requestType type of request.
-   *          (FIND_ALL_PROP / FIND_BY_PROPERTY / FIND_PROPERTY_NAMES )
-   * @param output buffer to write the data.
-   *
-   * @throws DBException if an error with the database occurs.
-   */
-  protected void writeNondavProperties(boolean isCollection, Collection col, 
-    String name, DAVProperties searchedProps, int requestType, 
-    StringBuffer output) throws DBException{
-    
-    //write indexers    
-    if(col != null && isCollection) {
-    	String[] indexers;
-		try {
-			indexers = col.listIndexers();
-		} catch (DBException e1) { // no indexer -> db
-			indexers = new String[0];
-		}
-    	for(int i = 0; i < indexers.length; i++){
-    		Configuration idxConfig = col.getIndexer(indexers[i]).getConfig();
-			String[] idxAttributes = idxConfig.listAttributes();
-			if(idxAttributes.length > 0) {
-				/*output.append("<").append(indexers[i])
-					.append(" xmlns=\"").append(IDX_NS_URI)
-					.append("\"><index")
-					.append(" xmlns=\"").append(IDX_NS_URI)
-					.append("\" ");					
-				for(int j = 0; j < idxAttributes.length; j++) {
-					output.append(" ").append(idxAttributes[j]).append("=\"")
-						.append(idxConfig.getAttribute(idxAttributes[j], ""))
-						.append("\"");
-				}
-				output.append(" /></").append(indexers[i]).append(">");*/
-				
-				output.append("<index_"+i+" ")
-					.append(" xmlns=\"").append(IDX_NS_URI).append("\">");
-				for(int j = 0; j < idxAttributes.length; j++) {
-					output.append("<").append(idxAttributes[j])
-						.append(" xmlns=\"").append(IDX_NS_URI).append("\">")
-						.append(idxConfig.getAttribute(idxAttributes[j], ""))
-						.append("</").append(idxAttributes[j]).append(">");
-				}
-				output.append("</index_"+i+">\n");
-			}
-    	}    		
-    }
-    
-    // MetaData
-    if(col != null && col.isMetaEnabled()) {
-    	MetaData meta = null;
-    	try {
-    		if(isCollection) {
-    			meta = col.getCollectionMeta();
-    		} else {
-				meta = col.getDocumentMeta(name);
-			}
-    	}  catch (DBException e) {
-			// binary or system collection
-			meta = null;
-		}
-    	
-    	if(meta != null) {	
-    		// write attributes
-    		for(Enumeration e = meta.getAttributeKeys(); e.hasMoreElements();) {
-    			String attrName = (String) e.nextElement();
-    			if(requestType == FIND_ALL_PROP
-    				|| searchedProps.contains(attrName)) {
-    					String value = (String) meta.getAttribute(attrName);
-    					output.append("<").append(attrName)
-    						.append(" xmlns=\"").append(MetaData.NS_URI)
-    						.append("\">").append(value).append("</")
-    						.append(attrName).append(">");
-    			}
-    		}
-			// write custom
-			Document customDoc = meta.getCustomDocument();
-			if(customDoc != null) {
-				output.append(TextWriter.toString(customDoc.getDocumentElement()));
-			}
-    	}
-    }
-  }
-
- 
-  // DAVProperties Innner Class
-
-  protected class DAVProperties {
-
-    Hashtable properties;
-    
-    DAVProperties() {
-      properties = new Hashtable();
-    }
-
-    protected void set(String propertyName) {
-      properties.put(propertyName, new Visited());
-    }
-
-    protected boolean contains(String propertyName) {
-      return properties.containsKey(propertyName);
-    }
-
-    protected boolean isVisited(String propertyName) {
-      return ((Visited)properties.get(propertyName)).isVisited;
-    }
-
-    protected void visit(String propertyName) {
-      ((Visited)properties.get(propertyName)).isVisited = true;
-    }
-
-    protected void reset(String propertyName) {
-      ((Visited)properties.get(propertyName)).isVisited = false;
-    }
-
-    protected void resetAll() {
-      for (Enumeration e = properties.elements(); e.hasMoreElements() ;) {
-        ((Visited)e.nextElement()).isVisited = false;
-      }
-    }
-
-    protected String[] getNotVisited() {
-      ArrayList notVisited = new ArrayList(properties.size());
-      for (Enumeration e = properties.keys(); e.hasMoreElements() ;) {
-        String propertyName = (String)e.nextElement();
-        if(!((Visited)properties.get(propertyName)).isVisited) {
-          notVisited.add(propertyName);
-        }
-      }
-      return (String[])notVisited.toArray(new String[0]);
-    }
-
-    public String toString() {
-      StringBuffer contents = new StringBuffer();
-      contents.append("#DAVProperties[");
-      Enumeration e = properties.keys();
-      if(e.hasMoreElements()) {
-        contents.append((String)e.nextElement());
-      }
-      while(e.hasMoreElements()) {
-        contents.append(", ").append((String)e.nextElement());
-      }
-      contents.append("]");
-      return contents.toString();
-    }
-
-    // Visited Inner Class
-
-    protected class Visited {
-      protected boolean isVisited;
-      Visited() {
-        isVisited = false;
-      }
+
+    private int getPropFindType(Document doc) {
+        if (doc == null) {
+            return FIND_ALL_PROP;
+        }
+
+        int type = FIND_ALL_PROP;
+        Node propfind = doc.getDocumentElement();
+        if (propfind != null && isNodeNamed(propfind, "propfind")) {
+            NodeList childList = propfind.getChildNodes();
+
+            for (int i = 0; i < childList.getLength(); i++) {
+                Node currentNode = childList.item(i);
+                if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
+                    if (isNodeNamed(currentNode, "prop")) {
+                        type = FIND_BY_PROPERTY;
+                        break;
+                    } else if (isNodeNamed(currentNode, "propname")) {
+                        type = FIND_PROPERTY_NAMES;
+                        break;
+                    } else if (isNodeNamed(currentNode, "allprop")) {
+                        type = FIND_ALL_PROP;
+                        break;
+                    }
+                }
+            }
+        }
+
+        return type;
+    }
+
+    private boolean isNodeNamed(Node node, String name) {
+        return node.getNamespaceURI().equals("DAV:") && node.getLocalName().equals(name);
+    }
+
+    private String getLocation(String context, Collection col) {
+        return context + (col != null ? col.getCanonicalName() : "") + "/";
+    }
+
+    private String getLocation(String context, Collection col, String resource) {
+        return context + col.getCanonicalDocumentName(resource);
+    }
+
+    public void addPropfindResponse(DAVResponse res, String location, HashMap statusList) throws IOException {
+        PartialResponse response = new PartialResponse(location);
+
+        for (Iterator i = statusList.keySet().iterator(); i.hasNext(); ) {
+            Integer status = (Integer) i.next();
+            ArrayList props = (ArrayList) statusList.get(status);
+
+            if (props != null && props.size() > 0) {
+                PartialResponse.Content propstat = new PartialResponse.Content("propstat");
+
+                PartialResponse.Content prop = new PartialResponse.Content("prop");
+
+                for (Iterator j = props.iterator(); j.hasNext(); ) {
+                    PartialResponse.Content node = (PartialResponse.Content) j.next();
+                    prop.addChild(node);
+                }
+
+                propstat.addChild(prop);
+
+                PartialResponse.Content st = new PartialResponse.Content("status");
+                st.setValue(res.getProtocol() + " " + status + " " + WebdavStatus.getStatusText(status.intValue()));
+                propstat.addChild(st);
+                response.addContent(propstat);
+            }
+        }
+
+        res.sendMultiStatusResponse(response);
     }
-    
-  }
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Proppatch.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Proppatch.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Proppatch.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Proppatch.java Thu May 24 18:43:39 2007
@@ -22,42 +22,29 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.xindice.core.Collection;
-import org.apache.xindice.webadmin.webdav.*;
+import org.apache.xindice.webadmin.Location;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-/** 
+/**
  * This class implements the Proppatch command for WebDAV operations on
  * Xindice. 
  * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=PROPPATCH
- * @x-avalon.lifestyle type=singleton
- * 
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @author <a href="mailto:[email protected]">Gianugo Rabellino</a>
  * @version $Id$ 
  */
 
-public class Proppatch extends DefaultContainer implements DAVComponent {
-
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection col) throws ServletException, IOException {
-
-    if (this.getLogger().isDebugEnabled())
-      this.getLogger().debug("Method Proppath is not yet implemented");
-    res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
-  }
-  
-  public void execute(HttpServletRequest req, HttpServletResponse res,
-    Collection parentCol, String resourceName) throws ServletException, IOException {
+public class Proppatch implements DAVComponent {
+    private static final Log log = LogFactory.getLog(Proppatch.class);
 
-    if (this.getLogger().isDebugEnabled())
-      this.getLogger().debug("Method Proppath is not yet implemented");
-    res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);    
-  }
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        if (log.isDebugEnabled())
+            log.debug("Method Proppath is not yet implemented");
+        res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
+    }
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Proppatch.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Put.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Put.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Put.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Put.java Thu May 24 18:43:39 2007
@@ -22,168 +22,111 @@
 import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.xindice.core.Collection;
 import org.apache.xindice.core.DBException;
+import org.apache.xindice.core.data.Key;
 import org.apache.xindice.util.XindiceException;
 import org.apache.xindice.webadmin.util.CollectionConfigurationHelper;
-import org.apache.xindice.webadmin.webdav.*;
 import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.Location;
 import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Document;
 
-/** 
- * This class implements the Put command for WebDAV operations on
- * Xindice. 
- * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=PUT
- * @x-avalon.lifestyle type=singleton
- * 
+/**
+ * This class implements the Put HTTP command for WebDAV operations on
+ * Xindice.
+ *
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @author <a href="mailto:[email protected]">Gianugo Rabellino</a>
- * @version $Id$ 
+ * @version $Id$
  */
 
-public class Put extends DefaultContainer implements DAVComponent {
+public class Put implements DAVComponent {
+    private static final Log log = LogFactory.getLog(Put.class);
 
     /** Size of file transfer buffer in bytes.  */
     protected static final int BUFFER_SIZE = 4096;
 
-    public void execute(
-        HttpServletRequest req,
-        HttpServletResponse res,
-        Collection col)
-        throws ServletException, IOException {
-
-        if (this.getLogger().isDebugEnabled()) {
-            this.getLogger().debug(
-                "Method Put is not implemented for collections: use Mkcol");
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        if (target.isRoot()) {
+            res.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+            return;
         }
-        res.sendError(HttpServletResponse.SC_CONFLICT);
-    }
-
-    public void execute(
-        HttpServletRequest req,
-        HttpServletResponse res,
-        Collection parentCol,
-        String resourceName)
-        throws ServletException, IOException {
 
-        // lookup resource
-        Document resource = null;
-        byte[] binary = null;
-        try {
-            resource = parentCol.getDocument(resourceName);
-        } catch (DBException e) {
-            resource = null;
+        if (target.getCollection() == null) {
+            // one or more intermediate collections do not exist
+            res.setStatus(WebdavStatus.SC_CONFLICT);
+        } else if (target.getName() == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Method Put is not implemented for collections: use Mkcol");
+            }
+            res.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+        } else {
+            Collection col = target.getCollection();
+            String name = target.getName();
             try {
-                binary = parentCol.getBinary(resourceName);
-            } catch (DBException e1) {
-                binary = null;
+                res.setStatus(storeResource(col, name, req.getInputStream()));
+            } catch (DBException e) {
+                log.error("Failed to create resource " + name + " in the collection " + col.getCanonicalName(), e);
+                throw new ServletException(e);
             }
         }
+    }
 
+    private int storeResource(Collection col, String name, InputStream input) throws IOException, DBException {
         // read input
-        Document newResource = null;
-        byte[] newBinary = null;
-        // read input
-        ByteArrayOutputStream rawBinCache =
-            new ByteArrayOutputStream(10 * BUFFER_SIZE);
-        int numBytesRead;
+        ByteArrayOutputStream rawBinCache = new ByteArrayOutputStream(10 * BUFFER_SIZE);
+        BufferedInputStream in = new BufferedInputStream(input, BUFFER_SIZE);
+
+        int bytesRead;
         byte[] transferBuffer = new byte[BUFFER_SIZE];
-        BufferedInputStream requestBufInStream =
-            new BufferedInputStream(req.getInputStream(), BUFFER_SIZE);
-        while ((numBytesRead = requestBufInStream.read(transferBuffer))
-            != -1) {
-            rawBinCache.write(transferBuffer, 0, numBytesRead);
+        while ((bytesRead = in.read(transferBuffer)) != -1) {
+            rawBinCache.write(transferBuffer, 0, bytesRead);
         }
-        requestBufInStream.close();
+        in.close();
         byte[] binCache = rawBinCache.toByteArray();
 
+        Document document = null;
+        byte[] binary = null;
         try {
-            newResource = DOMParser.toDocument(binCache);
-        } catch (XindiceException e) { // binary ?
-            newBinary = binCache;
+            document = DOMParser.toDocument(binCache);
+        } catch (XindiceException e) { // binary resource
+            binary = binCache;
         }
 
-        try {
-            if (resource == null
-                && newResource != null) { // create new resource
-                parentCol.insertDocument(resourceName, newResource);
-                res.setStatus(HttpServletResponse.SC_CREATED);
-            } else if (
-                resource != null && newResource != null) { // update resource
-                parentCol.setDocument(resourceName, newResource);
-                res.setStatus(HttpServletResponse.SC_NO_CONTENT);
-            } else if (binary == null && newBinary != null) { // create binary
-                // check if the db is Meta enabled
-                if (parentCol.isMetaEnabled()) {
-                    CollectionConfigurationHelper helper;
-                    try {
-                        Object object =
-                            m_serviceManager.lookup(
-                                CollectionConfigurationHelper.ROLE);
-                        if (object instanceof ServiceSelector) {
-                            helper =
-                                (CollectionConfigurationHelper)
-                                    ((ServiceSelector)object).select(
-                                    "col-config");
-                        } else {
-                            helper = (CollectionConfigurationHelper)object;
-                        }
-                    } catch (ServiceException e) {
-                        e.printStackTrace();
-                        getLogger().warn(
-                            "Cannot get CollectionConfigurationHelper",
-                            e);
-                        throw new ServletException(e);
-                    }
-
-                    if (!helper.isInlineMetaEnabled(parentCol)
-                        && helper.isAutoEnableInlineMeta()) {
-                        // enable Metadata
-                        try {
-                            helper.enableCollectionInlineMetadata(parentCol);
-                        } catch (XindiceException e) {
-                            e.printStackTrace();
-                            if (getLogger().isDebugEnabled()) {
-                                getLogger().debug(
-                                    "Could not enable Collection Inline Metadata: "
-                                        + e.getMessage());
-                            }
-                            res.sendError(WebdavStatus.SC_CONFLICT);
-                            return;
-                        }
-                    }
-
-                    if (!helper.isInlineMetaEnabled(parentCol)) {
-                        if (getLogger().isDebugEnabled()) {
-                            getLogger().debug(
-                                "Collection Inline Metadata is not enabled!");
-                        }
-                        res.sendError(WebdavStatus.SC_CONFLICT);
-                        return;
-                    }
-
-                    parentCol.insertBinary(resourceName, newBinary);
-                } else if (binary != null && newBinary != null) {
-                    parentCol.insertBinary(resourceName, newBinary);
-                } else {
-                    res.sendError(WebdavStatus.SC_CONFLICT);
+        if (document != null) { // update resource
+
+            if (col.setDocument(new Key(name), document)) {
+                return HttpServletResponse.SC_CREATED;
+            } else {
+                return HttpServletResponse.SC_NO_CONTENT;
+            }
+        } else if (binary != null) { // create binary
+            // check if the collection inline meta is enabled
+            if (!CollectionConfigurationHelper.isInlineMetaEnabled(col)) {
+                if (log.isWarnEnabled()) {
+                    log.warn("Collection Inline Metadata is not enabled!");
                 }
+                return WebdavStatus.SC_FORBIDDEN;
+            }
+
+            if (col.setBinary(new Key(name), binary)) {
+                return HttpServletResponse.SC_CREATED;
+            } else {
+                return WebdavStatus.SC_NO_CONTENT;
             }
-        } catch (DBException e) {
-            e.printStackTrace();
-            res.sendError(WebdavStatus.SC_CONFLICT);
         }
+
+        return WebdavStatus.SC_INTERNAL_SERVER_ERROR;
     }
+
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Put.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Search.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Search.java?view=diff&rev=541504&r1=541498&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Search.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Search.java Thu May 24 18:43:39 2007
@@ -22,14 +22,15 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.apache.avalon.fortress.impl.DefaultContainer;
-import org.apache.xindice.core.Collection;
-import org.apache.xindice.webadmin.webdav.*;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.webadmin.Location;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-/** 
+/**
  * This class implements the Serach command for WebDAV DASL search
  * operations on Xindice.
  *  
@@ -56,34 +57,18 @@
  * &lt;/searchrequest&gt;
  * </pre>
  * 
- * @avalon.component
- * @avalon.service type=DAVComponent
- * @x-avalon.info name=SEARCH
- * @x-avalon.lifestyle type=singleton
- * 
  * @author <a href="mailto:[email protected]">Jan Metzner</a>
  * @version $Id$ 
  */
 
-public class Search extends DefaultContainer implements DAVComponent {
-	
-	public void execute(HttpServletRequest req, HttpServletResponse res,
-		Collection col) throws ServletException, IOException {
-			
-		if (this.getLogger().isDebugEnabled()) {
-			this.getLogger().debug("Method Search is not yet implemented");	
-		}
-		res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
-	}
-  
-	public void execute(HttpServletRequest req, HttpServletResponse res,
-		Collection parentCol, String resourceName)
-		throws ServletException, IOException {
-			
-		if (this.getLogger().isDebugEnabled()) {
-			this.getLogger().debug("Method Search is not yet implemented");	
-		}
-		res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);		
-	}
+public class Search implements DAVComponent {
+    private static final Log log = LogFactory.getLog(Search.class);
+
+    public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
+        if (log.isDebugEnabled()) {
+            log.debug("Method Search is not yet implemented");
+        }
+        res.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED);
+    }
 
 }

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Search.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu May 24 18:43:39 2007
@@ -1 +1 @@
-Author Date Id Revision
+Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java Thu May 24 18:43:39 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.webadmin.PartialResponse;
+import org.apache.xindice.webadmin.util.MimeTable;
+
+/**
+ * ContentType creates a response node that identifies content type of
+ * the collection entry. It is not applicable for collections and always
+ * contains "text/xml" for documents. For binary entries ContentType
+ * attemps to guess content type, if unsuccessful, it will assume default
+ * binary type of "application/octet-stream".
+ * <br/><br/>
+ * Example:
+ * <pre>
+ * &lt;getcontenttype&gt;
+ *     text/xml
+ * &lt;/getcontenttype&gt;
+ * </pre>
+ */
+public class ContentType implements DAVProperty {
+    private static final String CONTENT_TYPE = "getcontenttype";
+
+    public String getName() {
+        return CONTENT_TYPE;
+    }
+
+    public PartialResponse.Content getRootProperty() {
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Collection col) {
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Entry entry) {
+        if (entry.getEntryType() == Entry.DOCUMENT) {
+            return new PartialResponse.Content(CONTENT_TYPE, MimeTable.XML_MIME_TYPE);
+        } else {
+            return new PartialResponse.Content(CONTENT_TYPE, MimeTable.getMimeType(entry.getKey().toString()));
+        }
+    }
+
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ContentType.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java Thu May 24 18:43:39 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.DBException;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.core.meta.MetaData;
+import org.apache.xindice.webadmin.PartialResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.text.SimpleDateFormat;
+
+/**
+ * CreationDate creates a response node that contains the time when resource
+ * was created in the format "yyyy-MM-dd'T'HH:mm:ss'Z'" if creation time is
+ * available.<br/><br/>
+ * See {@link java.text.SimpleDateFormat} for date format information.<br>
+ * <br>
+ * Example:
+ * <pre>
+ * &lt;creationdate&gt;
+ *     2007-05-09T09:22:00Z
+ * &lt;/creationdate&gt;
+ * </pre>
+ */
+public class CreationDate implements DAVProperty {
+    private static final String CREATION_TIME = "creationdate";
+    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+    private static final Log log = LogFactory.getLog(CreationDate.class);
+
+    public String getName() {
+        return CREATION_TIME;
+    }
+
+    public PartialResponse.Content getRootProperty() {
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Collection col) {
+        try {
+            MetaData meta = col.getCollectionMeta();
+            long date = meta.getCreatedTime();
+            if (date != 0) {
+                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+                return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
+            }
+        } catch (DBException e) {
+            log.error("Getting creation time for collection " + col.getCanonicalName() + " failed", e);
+            return null;
+        }
+
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Entry entry) {
+        long date = entry.getCreationTime();
+        if (date != 0) {
+            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+            sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+            return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
+        } else {
+            // creation time is not available
+            return null;
+        }
+    }
+
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/CreationDate.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java Thu May 24 18:43:39 2007
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.webadmin.PartialResponse;
+
+/**
+ * DAVProperty represents resources' properties. Property value may vary
+ * depending on resource type and value, and may be available for all the
+ * resources or only for specific types of resources.
+ */
+public interface DAVProperty {
+    /**
+     * Returns property name
+     * @return property name
+     */
+    public String getName();
+
+    /**
+     * Builds a property content tree for the root node ("/").
+     * @return Property content tree or null, if property is not applicable.
+     */
+    public PartialResponse.Content getRootProperty();
+
+    /**
+     * Builds a property content tree for collection.
+     * @param col Collection
+     * @return Property content tree or null, if property is not applicable.
+     */
+    public PartialResponse.Content getProperty(Collection col);
+
+    /**
+     * Builds a property content tree for collection entry.
+     * @param entry Collection entry
+     * @return Property content tree or null, if property is not applicable.
+     */
+    public PartialResponse.Content getProperty(Entry entry);
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DAVProperty.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java Thu May 24 18:43:39 2007
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.webadmin.PartialResponse;
+import org.apache.xindice.util.StringUtilities;
+
+/**
+ * DisplayName creates a response node that contains resource name, which is
+ * a collection name for collections and key for collection entries.
+ * <br/><br/>
+ * Example:
+ * <pre>
+ * &lt;displayname&gt;
+ *     System
+ * &lt;/displayname&gt;
+ * </pre>
+ */
+public class DisplayName implements DAVProperty {
+    private static final String DISPLAY_NAME = "displayname";
+
+    public String getName() {
+        return DISPLAY_NAME;
+    }
+
+    public PartialResponse.Content getRootProperty() {
+        return new PartialResponse.Content(DISPLAY_NAME, "/");
+    }
+
+    public PartialResponse.Content getProperty(Collection col) {
+        return new PartialResponse.Content(DISPLAY_NAME, StringUtilities.escapeXml(col.getName()));
+    }
+
+    public PartialResponse.Content getProperty(Entry entry) {
+        return new PartialResponse.Content(DISPLAY_NAME, StringUtilities.escapeXml(entry.getKey().toString()));
+    }
+
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/DisplayName.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java Thu May 24 18:43:39 2007
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.DBException;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.core.meta.MetaData;
+import org.apache.xindice.webadmin.PartialResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * LastModified creates a response node that contains the time when resource
+ * was last modified in the format "EEE, dd MMM yyyy HH:mm:ss zzz" if last
+ * modification time is available.<br/><br/>
+ * See {@link java.text.SimpleDateFormat} for date format information.<br>
+ * <br>
+ * Example:
+ * <pre>
+ * &lt;getlastmodified&gt;
+ *     Wednesday, 9 May 2007 09:22:00 GMT
+ * &lt;/getlastmodified&gt;
+ * </pre>
+ */
+public class LastModified implements DAVProperty {
+    private static final String MODIFICATION_TIME = "getlastmodified";
+    private static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
+    private static final Log log = LogFactory.getLog(LastModified.class);
+
+    public String getName() {
+        return MODIFICATION_TIME;
+    }
+
+    public PartialResponse.Content getRootProperty() {
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Collection col) {
+        try {
+            MetaData meta = col.getCollectionMeta();
+            if (meta == null) {
+                return null;
+            }
+
+            long date = meta.getLastModifiedTime();
+            if (date != 0) {
+                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+                return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
+            }
+
+        } catch (DBException e) {
+            log.error("Getting last modified time for collection " + col.getCanonicalName() + " failed", e);
+            return null;
+        }
+
+        return null;
+    }
+
+    public PartialResponse.Content getProperty(Entry entry) {
+        long date = entry.getModificationTime();
+        if (date != 0) {
+            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+            sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+            return new PartialResponse.Content(MODIFICATION_TIME, sdf.format(new Date(date)));
+        } else {
+            return null;
+        }
+    }
+
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/LastModified.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java?view=auto&rev=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java (added)
+++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java Thu May 24 18:43:39 2007
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin.webdav.components.props;
+
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.data.Entry;
+import org.apache.xindice.webadmin.PartialResponse;
+
+/**
+ * ResourceType creates a response node that identifies resource type
+ * (collection or collection entry).<br/>
+ * <br/>
+ * When invoked for collections, it will generate
+ * <pre>
+ * &lt;resourcetype&gt;
+ *     &lt;collection/&gt;
+ * &lt;/resourcetype&gt;
+ * </pre>
+ *
+ * For collection entries, it will be
+ * <pre>
+ * &lt;resourcetype/&gt;
+ * </pre>
+ */
+public class ResourceType implements DAVProperty {
+    private static final String RESOURCE_TYPE = "resourcetype";
+    private static final String COLLECTION = "collection";
+
+    public String getName() {
+        return RESOURCE_TYPE;
+    }
+
+    public PartialResponse.Content getRootProperty() {
+        PartialResponse.Content node = new PartialResponse.Content(RESOURCE_TYPE);
+        node.addChild(COLLECTION);
+
+        return node;
+    }
+
+    public PartialResponse.Content getProperty(Collection col) {
+        PartialResponse.Content node = new PartialResponse.Content(RESOURCE_TYPE);
+        node.addChild(COLLECTION);
+
+        return node;
+    }
+
+    public PartialResponse.Content getProperty(Entry entry) {
+        return new PartialResponse.Content(RESOURCE_TYPE);
+    }
+
+}

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/props/ResourceType.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/TextWriter.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/TextWriter.java?view=diff&rev=541504&r1=541503&r2=541504
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/TextWriter.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/TextWriter.java Thu May 24 18:43:39 2007
@@ -21,6 +21,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.xindice.util.StringUtilities;
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
@@ -139,7 +140,7 @@
                 Attr att = (Attr) node;
                 writer.write(att.getName());
                 writer.write("=\"");
-                writeEscapedText(writer, att.getValue());
+                writer.write(StringUtilities.escapeXml(att.getValue()));
                 writer.write("\"");
                 break;
 
@@ -174,7 +175,7 @@
                 break;
 
             case Node.TEXT_NODE:
-                writeEscapedText(writer, node.getNodeValue());
+                writer.write(StringUtilities.escapeXml(node.getNodeValue()));
                 break;
 
             case Node.CDATA_SECTION_NODE:
@@ -201,49 +202,6 @@
         int size = l.getLength();
         for (int i = 0; i < size; i++) {
             writeNode(writer, l.item(i));
-        }
-    }
-
-    private static void writeEscapedText(Writer writer, String text) throws IOException {
-        char[] value = text.toCharArray();
-        int start = 0;
-        int len = 0;
-
-        for (int i = 0; i < value.length; i++) {
-            String outval = null;
-            switch (value[i]) {
-                case '&':
-                    outval = "&amp;";
-                    break;
-                case '\'':
-                    outval = "&apos;";
-                    break;
-                case '\"':
-                    outval = "&quot;";
-                    break;
-                case '<':
-                    outval = "&lt;";
-                    break;
-                case '>':
-                    outval = "&gt;";
-                    break;
-                default :
-                    len++;
-                    break;
-            }
-
-            if (outval != null) {
-                if (len > 0) {
-                    writer.write(value, start, len);
-                }
-                writer.write(outval);
-                start = i + 1;
-                len = 0;
-            }
-        }
-
-        if (len > 0) {
-            writer.write(value, start, len);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.