001: // DAVFactory.java
002: // $Id: DAVFactory.java,v 1.5 2000/10/16 12:30:22 bmahe Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.www.webdav.xml;
006:
007: import org.w3c.dom.Document;
008: import org.w3c.dom.Element;
009: import org.w3c.dom.Node;
010:
011: import org.w3c.www.webdav.WEBDAV;
012:
013: /**
014: * @version $Revision: 1.5 $
015: * @author Benoît Mahé (bmahe@w3.org)
016: */
017: public class DAVFactory {
018:
019: protected static Element createDAVElement(Document doc, String name) {
020: Element el = doc.createElementNS(WEBDAV.NAMESPACE_URI,
021: WEBDAV.NAMESPACE_PREFIX + ":" + name);
022: return el;
023: }
024:
025: /**
026: * Create a DAVNode
027: * @param el the DOM Element
028: * @return a DAVNode instance
029: */
030: public static DAVNode createDAVNode(Element el) {
031: return new DAVNode(el);
032: }
033:
034: /**
035: * Create a DAVProperties node.
036: * @param document the xml document
037: * @return a DAVProperties instance
038: */
039: public static DAVProperties createProperties(Document document) {
040: Element el = createDAVElement(document, DAVNode.PROP_NODE);
041: return new DAVProperties(el);
042: }
043:
044: /**
045: * Create a DAVProperties node.
046: * @param element the prop node
047: * @return a DAVProperties instance
048: */
049: public static DAVProperties createProperties(Element el) {
050: return new DAVProperties(el);
051: }
052:
053: public static DAVPropStat createPropStat(String status,
054: Document document) {
055: Element el = createDAVElement(document, DAVNode.PROPSTAT_NODE);
056: DAVPropStat dps = new DAVPropStat(el);
057: dps.setStatus(status);
058: return dps;
059: }
060:
061: public static DAVPropStat createPropStat(String status,
062: String propname, Document document) {
063: Element el = createDAVElement(document, DAVNode.PROPSTAT_NODE);
064: DAVPropStat dps = new DAVPropStat(el);
065: dps.setStatus(status);
066: DAVProperties dp = createProperties(document);
067: dp.addProperty(propname);
068: dps.addDAVNode(dp);
069: return dps;
070: }
071:
072: public static DAVPropStat createPropStatNS(String status,
073: Node node, Document document) {
074: Element el = createDAVElement(document, DAVNode.PROPSTAT_NODE);
075: DAVPropStat dps = new DAVPropStat(el);
076: dps.setStatus(status);
077: DAVProperties dp = createProperties(document);
078: dp.addNodeNS(node);
079: dps.addDAVNode(dp);
080: return dps;
081: }
082:
083: public static DAVPropStat createPropStat(String status,
084: DAVProperties props, Document document) {
085: Element el = createDAVElement(document, DAVNode.PROPSTAT_NODE);
086: DAVPropStat dps = new DAVPropStat(el);
087: dps.setStatus(status);
088: dps.addDAVNode(props);
089: return dps;
090: }
091:
092: public static DAVResponse createResponse(String url,
093: Document document) {
094: Element el = createDAVElement(document, DAVNode.RESPONSE_NODE);
095: DAVResponse dr = new DAVResponse(el);
096: dr.addDAVNode(DAVNode.HREF_NODE, url);
097: return dr;
098: }
099:
100: public static DAVResponse createResponse(String url, String status,
101: Document document) {
102: Element el = createDAVElement(document, DAVNode.RESPONSE_NODE);
103: DAVResponse dr = new DAVResponse(el);
104: dr.addDAVNode(DAVNode.HREF_NODE, url);
105: dr.addDAVNode(DAVNode.STATUS_NODE, status);
106: return dr;
107: }
108:
109: public static DAVResponse createResponse(String url, String status,
110: String description, Document document) {
111: Element el = createDAVElement(document, DAVNode.RESPONSE_NODE);
112: DAVResponse dr = new DAVResponse(el);
113: dr.addDAVNode(DAVNode.HREF_NODE, url);
114: dr.addDAVNode(DAVNode.STATUS_NODE, status);
115: dr.addDAVNode(DAVNode.RESPONSEDESC_NODE, description);
116: return dr;
117: }
118:
119: public static DAVResponse createPropStatResponse(String url,
120: String status, DAVProperties props, Document document) {
121: DAVPropStat dps = createPropStat(status, props, document);
122: Element el = createDAVElement(document, DAVNode.RESPONSE_NODE);
123: DAVResponse dr = new DAVResponse(el);
124: dr.addDAVNode(DAVNode.HREF_NODE, url);
125: dr.addDAVNode(dps);
126: return dr;
127: }
128:
129: public static DAVPropAction createPropAction(int type,
130: DAVProperties props, Document document) {
131: Element el = null;
132: if (type == DAVPropAction.SET) {
133: el = createDAVElement(document, DAVNode.SET_NODE);
134: } else {
135: el = createDAVElement(document, DAVNode.REMOVE_NODE);
136: }
137: el.appendChild(props.getNode());
138: return new DAVPropAction(el);
139: }
140:
141: public static DAVPropertyUpdate createPropertyUpdate(
142: DAVPropAction act[], Document document) {
143: Element el = createDAVElement(document,
144: DAVNode.PROPERTYUPDATE_NODE);
145: DAVPropertyUpdate dpu = new DAVPropertyUpdate(el);
146: dpu.setActions(act);
147: return dpu;
148: }
149:
150: public static DAVPropertyUpdate createPropertyUpdate(
151: DAVPropAction act, Document document) {
152: Element el = createDAVElement(document,
153: DAVNode.PROPERTYUPDATE_NODE);
154: DAVPropertyUpdate dpu = new DAVPropertyUpdate(el);
155: DAVPropAction array[] = { act };
156: dpu.setActions(array);
157: return dpu;
158: }
159:
160: public static DAVPropertyUpdate createPropertyUpdate(Element el,
161: DAVPropAction act) {
162: DAVPropertyUpdate dpu = new DAVPropertyUpdate(el);
163: DAVPropAction array[] = { act };
164: dpu.setActions(array);
165: return dpu;
166: }
167:
168: public static DAVMultiStatus createMultiStatus(Element el) {
169: return new DAVMultiStatus(el);
170: }
171:
172: }
|