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.properties;
14  
15  import org.abstracthorizon.danube.http.Status;
16  import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
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 getcontentlength response tag
24   *
25   * @author Daniel Sendula
26   */
27  public class GetContentLength extends ResponseProperty {
28  
29      /** Tag name */
30      public static final String TAG_NAME = "getcontentlength";
31  
32      /** Content length */
33      protected long contentLength = -1;
34  
35      /**
36       * Constructor
37       * @param status status
38       */
39      public GetContentLength(Status status) {
40          super(status);
41      }
42  
43      /**
44       * Constructor
45       * @param contentLength content length
46       */
47      public GetContentLength(long contentLength) {
48          this.contentLength = contentLength;
49      }
50  
51      /**
52       * Returns content length
53       * @return content length
54       */
55      public long getContentLength() {
56          return contentLength;
57      }
58  
59      @Override
60      public String toString() {
61          return "GetContentLength[" + contentLength + "]";
62      }
63  
64      /**
65       * Renders the tag
66       * @param writer writer
67       * @param provider namespace provider
68       */
69      public void render(PrintWriter writer, NamespacesProvider provider) {
70          if (contentLength >= 0) {
71              writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, Long.toString(contentLength)));
72          } else {
73              writer.println(XMLUtils.createEmptyTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
74          }
75      }
76  
77  }