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.response;
14  
15  import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
16  import org.abstracthorizon.danube.webdav.xml.XMLRenderer;
17  import org.abstracthorizon.danube.webdav.xml.common.XMLUtils;
18  import org.abstracthorizon.danube.webdav.xml.dav.DAVNamespace;
19  
20  import java.io.PrintWriter;
21  
22  /**
23   * This class models WebDAV's owner response tag
24   *
25   * @author Daniel Sendula
26   */
27  public class Owner implements XMLRenderer {
28  
29      /** Tag name */
30      public static final String TAG_NAME = "owner";
31  
32      /** Owner */
33      protected Object owner;
34  
35      /**
36       * Constructor
37       * @param owner owner
38       */
39      public Owner(Object owner) {
40          this.owner = owner;
41      }
42  
43      /**
44       * Returns owner
45       * @return owner
46       */
47      public Object getOwner() {
48          return owner;
49      }
50  
51      @Override
52      public String toString() {
53          if (owner != null) {
54              return "Owner[" + owner + "]";
55          } else {
56              return "Owner[]";
57          }
58      }
59  
60      /**
61       * Renders the tag
62       * @param writer writer
63       * @param provider namespace provider
64       */
65      public void render(PrintWriter writer, NamespacesProvider provider) {
66          if (owner != null) {
67              if (owner instanceof XMLRenderer) {
68                  writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
69                  ((XMLRenderer)owner).render(writer, provider);
70                  writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
71              } else {
72                  writer.print(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
73                  writer.print(owner);
74                  writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
75              }
76          } else {
77              writer.print(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, null));
78          }
79       }
80  
81  }