01: // MultiStatusException.java
02: // $Id: MultiStatusException.java,v 1.2 2000/10/13 13:44:52 bmahe Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05: package org.w3c.jigsaw.webdav;
06:
07: import org.w3c.dom.Document;
08: import org.w3c.dom.DOMException;
09: import org.w3c.dom.Element;
10:
11: import org.w3c.www.webdav.xml.DAVBody;
12: import org.w3c.www.webdav.xml.DAVFactory;
13: import org.w3c.www.webdav.xml.DAVMultiStatus;
14: import org.w3c.www.webdav.xml.DAVNode;
15: import org.w3c.www.webdav.xml.DAVResponse;
16:
17: /**
18: * @version $Revision: 1.2 $
19: * @author Benoît Mahé (bmahe@w3.org)
20: */
21: public class MultiStatusException extends Exception {
22:
23: // flag
24: private boolean multi = false;
25:
26: // only one status
27: private String url = null;
28: private String status = null;
29: private String msg = null;
30:
31: // several status
32: private Document document = null;
33:
34: public Document getDocument() {
35: if (document == null) {
36: document = DAVBody.createDocument(DAVNode.MULTISTATUS_NODE);
37: DAVResponse dr = null;
38: if (msg != null) {
39: dr = DAVFactory.createResponse(url, status, msg,
40: document);
41: } else {
42: dr = DAVFactory.createResponse(url, status, document);
43: }
44: document.getDocumentElement().appendChild(dr.getNode());
45: }
46: return document;
47: }
48:
49: public void addResponses(Document doc, DAVMultiStatus dms) {
50: if (multi) {
51: // get our own dms
52: Element odms = document.getDocumentElement();
53: try {
54: DAVNode.exportChildren(doc, dms.getNode(), odms, true);
55: } catch (DOMException ex) {
56: ex.printStackTrace();
57: }
58: } else {
59: DAVResponse dr = null;
60: if (msg != null) {
61: dr = DAVFactory.createResponse(url, status, msg, doc);
62: } else {
63: dr = DAVFactory.createResponse(url, status, doc);
64: }
65: dms.addDAVNode(dr);
66: }
67: }
68:
69: public MultiStatusException(Document document) {
70: super ("Forwarded");
71: this .document = document;
72: this .multi = true;
73: }
74:
75: public MultiStatusException(String url, String status, String msg) {
76: super (url + " [" + status + "] " + msg);
77: this .url = url;
78: this .status = status;
79: this .msg = msg;
80: this .multi = false;
81: }
82:
83: public MultiStatusException(String url, String status) {
84: super (url + " [" + status + "]");
85: this .url = url;
86: this .status = status;
87: this .multi = false;
88: }
89:
90: }
|