KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > http > PropFindMethod


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.http;
21
22 import java.io.IOException JavaDoc;
23 import java.io.StringWriter JavaDoc;
24
25 import net.n3.nanoxml.IXMLElement;
26 import net.n3.nanoxml.XMLElement;
27 import net.n3.nanoxml.XMLWriter;
28
29 /**
30  *
31  * @author Lee David Painter <a HREF="mailto:lee@3sp.com">&lt;lee@3sp.com&gt;</a>
32  */

33 public class PropFindMethod extends HttpMethod {
34
35     String JavaDoc depth;
36
37     public PropFindMethod(String JavaDoc uri, String JavaDoc depth) {
38         super("PROPFIND", uri); //$NON-NLS-1$
39
this.depth = depth;
40     }
41
42     public HttpResponse execute(HttpRequest request, HttpConnection con) throws IOException JavaDoc {
43
44         request.setHeaderField("Host", con.getHostHeaderValue()); //$NON-NLS-1$
45
if (depth != null)
46             request.setHeaderField("Depth", depth); //$NON-NLS-1$
47
request.setHeaderField("Content-Type", "text/xml; charset=\"UTF-8\""); //$NON-NLS-1$ //$NON-NLS-2$
48

49         IXMLElement root = new XMLElement(WebDAVConstants.PROPFIND_ELEM, WebDAVConstants.XML_DAV_NAMESPACE);
50         root.addChild(new XMLElement(WebDAVConstants.ALLPROP_ELEM));
51
52         StringWriter JavaDoc xml = new StringWriter JavaDoc();
53         XMLWriter writer = new XMLWriter(xml);
54         writer.write(root);
55
56         String JavaDoc str = WebDAVConstants.XML_TEMPLATE + "\r\n" + xml.toString(); //$NON-NLS-1$
57
byte[] content = str.getBytes("UTF8"); //$NON-NLS-1$
58

59         request.setHeaderField("Content-Length", String.valueOf(content.length)); //$NON-NLS-1$
60

61         request.performRequest(this, con);
62         con.getOutputStream().write(content);
63
64         return new HttpResponse(con);
65     }
66
67 }
68
Popular Tags