View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.webdav.xml.dav;
14  
15  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
16  
17  import org.xml.sax.Attributes;
18  import org.xml.sax.SAXException;
19  
20  /**
21   * DAV namespace.
22   *
23   * @author Daniel Sendula
24   */
25  public class DAVNamespace implements XMLParserHandler {
26  
27      /** Namespace URL */
28      public static final String DAV_NAMESPACE_URL = "DAV:";
29  
30      /** Namespace prefered prefix */
31      public static final String DAV_NAMESPACE_PREFERRED_PREFIX = "D";
32  
33      /** Factory */
34      protected DAVFactory davFactory = new DAVFactory();
35  
36      /**
37       * Constructor
38       */
39      public DAVNamespace() {
40      }
41  
42      /**
43       * Retruns factory
44       * @return factory
45       */
46      public DAVFactory getDAVFactory() {
47          return davFactory;
48      }
49  
50      /**
51       * Sets factory
52       * @param factory factory
53       */
54      public void setDAVFactory(DAVFactory factory) {
55          this.davFactory = factory;
56      }
57  
58      /**
59       * Returns {@link #DAV_NAMESPACE_URL}
60       * @return {@link #DAV_NAMESPACE_URL}
61       */
62      public String getURLString() {
63          return DAV_NAMESPACE_URL;
64      }
65  
66      /**
67       * Returns {@link #DAV_NAMESPACE_PREFERRED_PREFIX}
68       * @return {@link #DAV_NAMESPACE_PREFERRED_PREFIX}
69       */
70      public String getPreferredPrefix() {
71          return DAV_NAMESPACE_PREFERRED_PREFIX;
72      }
73  
74      /**
75       * Start tag handling
76       * @param current current object
77       * @param tag tag
78       * @param attributes tag attributes
79       * @return new object
80       * @throws SAXException sax exception
81       */
82      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
83  
84          if (current instanceof XMLParserHandler) {
85              return ((XMLParserHandler)current).start(current, tag, attributes);
86          } else {
87              XMLParserHandler parent = this;
88              if (current instanceof XMLParserHandler) {
89                  parent = (XMLParserHandler)current;
90              }
91              if ("propertyupdate".equals(tag)) {
92                  return davFactory.newPropertyUpdate(parent);
93              } else if ("lockinfo".equals(tag)) {
94                  return davFactory.newLockInfo(parent);
95              } else if ("propfind".equals(tag)) {
96                  return davFactory.newPropFind(parent);
97              } else if ("propertybehavior".equals(tag)) {
98                  return davFactory.newPropertyBehavior(parent);
99              } else if ("href".equals(tag)) {
100                 return new HRef(parent);
101             }
102             return current;
103         }
104     }
105 
106     /**
107      * End tag handling
108      * @param current current object
109      * @param tag tag
110      * @param value tag's value
111      * @return new object
112      * @throws SAXException sax exception
113      */
114     public Object end(Object current, String tag, String value) throws SAXException {
115         if (current instanceof XMLParserHandler) {
116             return ((XMLParserHandler)current).end(current, tag, value);
117         } else {
118 
119             // TODO is that right?
120             return current;
121         }
122     }
123 
124 }