001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.method;
024:
025: import org.skunk.dav.client.AbstractDAVMethod;
026: import org.skunk.dav.client.DAVConstants;
027: import org.skunk.dav.client.DAVFile;
028: import org.skunk.dav.client.DAVMethodName;
029: import org.skunk.dav.client.DAVProperty;
030: import org.skunk.dav.client.Depth;
031: import org.skunk.dav.client.PropertyHandler;
032: import org.skunk.minixml.MalformedXMLException;
033: import org.skunk.minixml.XMLDocument;
034: import org.skunk.minixml.XMLElement;
035: import org.skunk.trace.Debug;
036: import java.io.IOException;
037: import java.util.ListIterator;
038: import java.util.Map;
039: import java.util.StringTokenizer;
040:
041: /**
042: *
043: */
044: public class PropFindMethod extends AbstractDAVMethod {
045: private Depth depth;
046: private PropFindQueryType queryType;
047: private DAVProperty[] queryProps;
048:
049: public PropFindMethod(String url) {
050: super (url);
051: this .depth = Depth.ONE;
052: this .queryType = PropFindQueryType.ALLPROP;
053: }
054:
055: public PropFindMethod(String url, Depth depth, boolean allprop) {
056: this (url, depth, ((allprop) ? PropFindQueryType.ALLPROP
057: : PropFindQueryType.PROPNAME), null);
058: }
059:
060: public PropFindMethod(String url, Depth depth,
061: PropFindQueryType queryType, DAVProperty[] queryProps) {
062: super (url);
063: this .depth = depth;
064: this .queryType = queryType;
065: this .queryProps = queryProps;
066: }
067:
068: public PropFindMethod(String url, Depth depth,
069: DAVProperty[] queryProps) {
070: this (url, depth, PropFindQueryType.PROP, queryProps);
071: }
072:
073: public PropFindQueryType getQueryType() {
074: return queryType;
075: }
076:
077: public Depth getDepth() {
078: return depth;
079: }
080:
081: public void processRequestHeaders() {
082: Map headerMap = getRequestHeaders();
083: headerMap.put(DAVConstants.DEPTH_HEADER, depth);
084: }
085:
086: public void processRequestBody() {
087: try {
088: String namespaceCode = "D"; //could be anything
089: XMLElement propfindElem = new XMLElement(
090: DAVConstants.PROPFIND_ELEM, namespaceCode,
091: DAVConstants.DAV_NAMESPACE);
092: XMLElement queryTypeElem = new XMLElement(queryType
093: .toString(), namespaceCode);
094: if (queryType.equals(PropFindQueryType.PROP)) {
095: //add properties to be queried.
096: if (queryProps != null) {
097: for (int i = 0; i < queryProps.length; i++)
098: queryTypeElem.addChild(queryProps[i]);
099: }
100: }
101: propfindElem.addChild(queryTypeElem);
102: XMLDocument doc = new XMLDocument();
103: doc.addElement(DAVConstants.XML_BOILERPLATE);
104: doc.addElement(propfindElem);
105: setRequestBody(new String(doc.toString()
106: + DAVConstants.CRLF).getBytes());
107: } catch (MalformedXMLException malex) {
108: Debug.trace(this , Debug.DP1, malex);
109: }
110: }
111:
112: public void processResponseHeaders() {
113: //nothing to do
114: }
115:
116: /**
117: * by default, passes the properties off to PropertyHandler
118: */
119: protected void processPropElement(DAVFile file, XMLElement elem) {
120: if (queryType == PropFindQueryType.PROPNAME) {
121: //cycle through children of propElem and store props in available list
122: for (ListIterator lit = elem.children(); lit.hasNext();) {
123: Object temp = lit.next();
124: if (!(temp instanceof XMLElement))
125: continue;
126: XMLElement propElem = (XMLElement) temp;
127: file.addAvailableProperty(new DAVProperty(propElem));
128: }
129: } else if (queryType == PropFindQueryType.PROP) //this is rather unnecessary
130: {
131: //cycle through queryProps
132: if (queryProps != null) {
133: for (int i = 0; i < queryProps.length; i++) {
134: DAVProperty dp = queryProps[i];
135: XMLElement propElem = elem.getChild(dp
136: .getElementName(), dp.getNamespace());
137: if (propElem == null) {
138: Debug
139: .trace(
140: this ,
141: Debug.DP2,
142: "the property requested "
143: + dp
144: + " was not found in response for "
145: + file.getName());
146: } else {
147: PropertyHandler.handleProperty(file, propElem);
148: }
149: }
150: }
151: } else
152: super .processPropElement(file, elem);
153: }
154:
155: public DAVMethodName getRequestMethodName() {
156: return DAVMethodName.PROPFIND;
157: }
158: }
159:
160: /* $Log: PropFindMethod.java,v $
161: /* Revision 1.15 2001/07/15 18:16:37 smulloni
162: /* fixed some copyright notices.
163: /*
164: /* Revision 1.14 2000/12/03 23:53:27 smulloni
165: /* added license and copyright preamble to java files.
166: /*
167: /* Revision 1.13 2000/11/09 23:35:08 smullyan
168: /* log added to every Java file, with the help of python. Lock stealing
169: /* implemented, and treatment of locks made more robust.
170: /* */
|