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.util.NamespacesProvider;
16  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
17  import org.abstracthorizon.danube.webdav.xml.XMLRenderer;
18  import org.abstracthorizon.danube.webdav.xml.common.XMLUtils;
19  import org.abstracthorizon.danube.webdav.xml.dav.request.AbstractSimpleXMLHandler;
20  
21  import java.io.PrintWriter;
22  
23  import org.xml.sax.SAXException;
24  
25  /**
26   * This object models WebDAV's href tag
27   *
28   * @author Daniel Sendula
29   */
30  public class HRef extends AbstractSimpleXMLHandler implements XMLRenderer {
31  
32      /** Tag name */
33      public static final String TAG_NAME = "href";
34  
35      /** URL path */
36      protected String path;
37  
38      /**
39       * Constructor
40       * @param parent parent parser handler
41       */
42      public HRef(XMLParserHandler parent) {
43          super(parent);
44      }
45  
46      /**
47       * Constructor
48       * @param uri URL
49       */
50      public HRef(String uri) {
51          super(null);
52          this.path = uri.replace(" ", "%20");
53      }
54  
55      /**
56       * End tag handling
57       * @param current current object
58       * @param tag tag
59       * @param value tag's value
60       * @return new object
61       * @throws SAXException sax exception
62       */
63      public Object end(Object current, String tag, String value) throws SAXException {
64          path = value;
65          return super.end(current, tag, value);
66      }
67  
68      /**
69       * Returns object's string representation
70       * @return object's string representation
71       */
72      public String toString() {
73          return "HRef[" + path + "]";
74      }
75  
76      /**
77       * Renders the tag
78       * @param writer writer
79       * @param provider namespace provider
80       */
81      public void render(PrintWriter writer, NamespacesProvider provider) {
82          writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, path));
83      }
84  }