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 depth response property tag
24   *
25   * @author Daniel Sendula
26   */
27  public class Depth implements XMLRenderer {
28  
29      /**
30       * Depth array to be used when making tags. Array follows {@link org.abstracthorizon.danube.webdav.util.Depth#ZERO},
31       * {@link org.abstracthorizon.danube.webdav.util.Depth#ONE} and {@link org.abstracthorizon.danube.webdav.util.Depth#INFINITY}
32       * constants
33       */
34      public static final Depth[] DEPTHS = new Depth[]{
35          new Depth(org.abstracthorizon.danube.webdav.util.Depth.ZERO),
36          new Depth(org.abstracthorizon.danube.webdav.util.Depth.ONE),
37          new Depth(org.abstracthorizon.danube.webdav.util.Depth.INFINITY)
38      };
39  
40      /** Tag name "depth" */
41      public static final String TAG_NAME = "depth";
42  
43      /** Depth */
44      protected int depth;
45  
46      /**
47       * Constructor
48       * @param depth depth
49       */
50      public Depth(int depth) {
51          this.depth =  depth;
52      }
53  
54      /**
55       * Returns depth
56       * @return
57       */
58      public int getDepth() {
59          return depth;
60      }
61  
62      @Override
63      public String toString() {
64          return "Depth[" + org.abstracthorizon.danube.webdav.util.Depth.toString(depth) + "]";
65      }
66  
67      /**
68       * Renders the tag
69       * @param writer writer
70       * @param provider namespace provider
71       */
72      public void render(PrintWriter writer, NamespacesProvider provider) {
73          if (depth == org.abstracthorizon.danube.webdav.util.Depth.INFINITY) {
74              writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, "Infinity"));
75          } else if (depth == org.abstracthorizon.danube.webdav.util.Depth.ONE) {
76              writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, "1"));
77          } else if (depth == org.abstracthorizon.danube.webdav.util.Depth.ZERO) {
78              writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, "0"));
79          } else {
80              writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, null));
81          }
82      }
83  
84  }