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.request;
14  
15  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
16  import org.abstracthorizon.danube.webdav.xml.dav.DAVAbstractXMLParser;
17  import org.abstracthorizon.danube.webdav.xml.dav.DAVFactory;
18  import org.abstracthorizon.danube.webdav.xml.dav.RequestProp;
19  
20  import org.xml.sax.Attributes;
21  import org.xml.sax.SAXException;
22  
23  /**
24   * This class models WebDAV's propfind tag
25   *
26   * @author Daniel Sendula
27   */
28  public class PropFind extends DAVAbstractXMLParser {
29  
30      /** All props flag */
31      protected boolean allprop = false;
32  
33      /** Properties names only tag */
34      protected boolean propname = false;
35  
36      /** Request property */
37      protected RequestProp prop;
38  
39      /**
40       * Constructor
41       * @param parent parent parser handler
42       * @param davFactory factory
43       */
44      public PropFind(XMLParserHandler parent, DAVFactory davFactory) {
45          super(parent, davFactory);
46      }
47  
48      @Override
49      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
50          if ("allprop".equals(tag)) {
51              allprop = true;
52              return this;
53          } else if ("propname".equals(tag)) {
54              propname = true;
55              return this;
56          } else if ("prop".equals(tag)) {
57              prop = davFactory.newProp(this);
58              return prop;
59          } else {
60              return super.start(current, tag, attributes);
61          }
62      }
63  
64      @Override
65      public Object end(Object current, String tag, String value) throws SAXException {
66          return current;
67      }
68  
69      /**
70       * Sets allprop flag
71       * @param allprop allprop flag
72       */
73      public void setAllprop(boolean allprop) {
74          this.allprop = allprop;
75      }
76  
77      /**
78       * Returns allprop flag
79       * @return allprop flag
80       */
81      public boolean isAllprop() {
82          return allprop || (!allprop && !propname && (prop == null));
83      }
84  
85      /**
86       * Sets propname flag
87       * @param propname propname flag
88       */
89      public void setPropname(boolean propname) {
90          this.propname = propname;
91      }
92  
93      /**
94       * Returns propname flag
95       * @return propname flag
96       */
97      public boolean isPropname() {
98          return propname;
99      }
100 
101     /**
102      * Returns request property
103      * @return request property
104      */
105     public RequestProp getProp() {
106         return prop;
107     }
108 
109     @Override
110     public String toString() {
111         if (isAllprop()) {
112             return "PropFind[allprop]";
113         } else if (isPropname()) {
114             return "PropFind[propname]";
115         } else {
116             return "PropFind[" + prop + "]";
117         }
118     }
119 }