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 java.util.ArrayList;
21  import java.util.List;
22  
23  import org.xml.sax.Attributes;
24  import org.xml.sax.SAXException;
25  
26  /**
27   * This class models WebDAV's propertyupdate tag
28   *
29   * @author Daniel Sendula
30   */
31  public class PropertyUpdate extends DAVAbstractXMLParser {
32  
33      /** List of request properties to be updated */
34      protected List<RequestProp> list = new ArrayList<RequestProp>();
35  
36      /**
37       * Constructor
38       * @param parent parent parser handler
39       * @param factory
40       */
41      public PropertyUpdate(XMLParserHandler parent, DAVFactory factory) {
42          super(parent, factory);
43      }
44  
45      @Override
46      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
47          if ("set".equals(tag)) {
48              RequestProp set = davFactory.newSet(this);
49              list.add(set);
50              return set;
51          } else if ("remove".equals(tag)) {
52              RequestProp remove = davFactory.newRemove(this);
53              list.add(remove);
54              return remove;
55          } else {
56              return super.start(current, tag, attributes);
57          }
58      }
59  
60      @Override
61      public Object end(Object current, String tag, String value) {
62          return this;
63      }
64  
65      /**
66       * Returns a list of request properties to be updated
67       * @return a list of properties
68       */
69      public List<RequestProp> getProperties() {
70          return list;
71      }
72  
73      @Override
74      public String toString() {
75          StringBuffer res = new StringBuffer("PropertyUpdate[");
76          boolean first = true;
77          for (Object object: list) {
78              if (first) {
79                  first = false;
80              } else {
81                  res.append(',');
82              }
83              res.append(object);
84          }
85          res.append(']');
86          return res.toString();
87      }
88  
89  
90  }