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  import org.abstracthorizon.danube.webdav.xml.dav.request.AbstractSimpleXMLHandler;
17  
18  import org.xml.sax.Attributes;
19  import org.xml.sax.SAXException;
20  
21  /**
22   * This class models WebDAV's owner tag
23   *
24   * @author Daniel Sendula
25   */
26  public class Owner extends AbstractSimpleXMLHandler {
27  
28      /**
29       *  Owner object. It can be of {@link Owner} type or anything else.
30       *  If it is not {@link Owner} then it is most likely just a {@link String}
31       */
32      protected Object owner;
33  
34      /**
35       * Constructor
36       * @param parent parent parser handler
37       */
38      public Owner(XMLParserHandler parent) {
39          super(parent);
40      }
41  
42      @Override
43      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
44          if ("href".equals(tag)) {
45              owner = new HRef(this);
46              return owner;
47          } else {
48              return super.start(current, tag, attributes);
49          }
50      }
51  
52      @Override
53      public Object end(Object current, String tag, String value) throws SAXException {
54          if (this.owner == null) {
55              this.owner = value;
56          }
57          return super.end(current, tag, value);
58      }
59  
60      /**
61       * Returns owner object. It can be {@link Owner}, {@link String} or something else.
62       * @return owner object
63       */
64      public Object getOwner() {
65          return owner;
66      }
67  
68      @Override
69      public String toString() {
70          if (owner != null) {
71              return "Owner[" + owner + "]";
72          } else {
73              return "Owner[]";
74          }
75      }
76  
77  }