Source Code Cross Referenced for MethodResponse.java in  » Content-Management-System » harmonise » com » ibm » webdav » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » harmonise » com.ibm.webdav 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibm.webdav;
002:
003:        /*
004:         * (C) Copyright IBM Corp. 2000  All rights reserved.
005:         *
006:         * The program is provided "AS IS" without any warranty express or
007:         * implied, including the warranty of non-infringement and the implied
008:         * warranties of merchantibility and fitness for a particular purpose.
009:         * IBM will not be liable for any damages suffered by you as a result
010:         * of using the Program. In no event will IBM be liable for any
011:         * special, indirect or consequential damages or lost profits even if
012:         * IBM has been advised of the possibility of their occurrence. IBM
013:         * will not be liable for any third party claims against you.
014:         * 
015:         * Portions Copyright (C) Simulacra Media Ltd, 2004.
016:         */
017:
018:        import org.w3c.dom.*;
019:        import java.util.*;
020:        import javax.xml.parsers.*;
021:
022:        /** A MethodResponse describes the effect of a method on a resource. A
023:         * <code> MultiStatus</code> contains a collection of Response instances,
024:         * one for each resource effected by the method sent.
025:         * @author Jim Amsden &lt;jamsden@us.ibm.com&gt;
026:         * @see com.ibm.webdav.PropertyResponse
027:         * @see com.ibm.webdav.MultiStatus
028:         */
029:        public class MethodResponse extends Response {
030:
031:            //------------------------------------------------------------------------
032:
033:            private Vector resources = new Vector(); // other resources that have this
034:            // same status
035:            private int status = WebDAVStatus.SC_OK;
036:
037:            /** Construct a MethodResponse from an XML response element
038:             *
039:             * @param document the document containing the element
040:             * @param element the XML response element that is the source
041:             * of this response
042:             */
043:            public MethodResponse(Document document, Element element)
044:                    throws ServerException {
045:                super (document);
046:                try {
047:                    NodeList hrefs = element.getElementsByTagNameNS("DAV:",
048:                            "href");
049:                    Element href = (Element) hrefs.item(0);
050:                    setResource(((Text) href.getFirstChild()).getData());
051:                    Element hrefn = null;
052:                    for (int i = 1; i < hrefs.getLength(); i++) {
053:                        hrefn = (Element) hrefs.item(i);
054:                        addResource(((Text) hrefn.getFirstChild()).getData());
055:                    }
056:
057:                    Element status = (Element) (element.getElementsByTagNameNS(
058:                            "DAV:", "status").item(0));
059:                    String statusText = ((Text) status.getFirstChild())
060:                            .getData();
061:                    StringTokenizer statusFields = new StringTokenizer(
062:                            statusText, " ");
063:                    statusFields.nextToken(); // skip the HTTP version
064:
065:                    int statusCode = Integer.parseInt(statusFields.nextToken());
066:                    setStatus(statusCode);
067:
068:                    Element responseDescription = (Element) element
069:                            .getElementsByTagNameNS("DAV:",
070:                                    "responsedescription").item(0);
071:                    if (responseDescription != null) {
072:                        setDescription(((Text) responseDescription
073:                                .getFirstChild()).getData());
074:                    }
075:                } catch (Exception exc) {
076:                    exc.printStackTrace();
077:                    throw new ServerException(
078:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
079:                            "Invalid MethodResponse");
080:                }
081:            }
082:
083:            /** Construct an empty Response for some resource.
084:             *
085:             * @param url the URL of the resource this is a response for
086:             * @param status the HTTP status code for the response.
087:             * @see com.ibm.webdav.WebDAVStatus
088:             */
089:            public MethodResponse(String url, int status) {
090:                super (url);
091:                this .status = status;
092:            }
093:
094:            /** Construct an empty Response for some resource.
095:             *
096:             * @param url the URL of the resource this is a response for
097:             * @param status the HTTP status code for the response.
098:             * @see com.ibm.webdav.WebDAVStatus
099:             */
100:            public MethodResponse(String url, WebDAVException exc) {
101:                super (url);
102:                this .status = exc.getStatusCode();
103:                this .setDescription(exc.getMessage());
104:            }
105:
106:            /** Add a URL to a resource that is effected by the method in the
107:             * same way as that returned by <code>getResource()</code>. The
108:             * URL can only be added once to this Response.
109:             *
110:             * @param url the resource URL
111:             * @exception com.ibm.webdav.ServerException thrown if the URL is already in the response
112:             */
113:            public void addResource(String url) throws ServerException {
114:                boolean found = url.equals(getResource());
115:                if (!found) {
116:                    Enumeration urls = getResources();
117:                    while (!found && urls.hasMoreElements()) {
118:                        String aUrl = (String) urls.nextElement();
119:                        found = aUrl.equals(url);
120:                    }
121:                }
122:                if (found) {
123:                    throw new ServerException(
124:                            WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
125:                            "Duplicate URL in a Response");
126:                } else {
127:                    resources.addElement(url);
128:                }
129:            }
130:
131:            /** Translate this MethodResponse into an XML response element.
132:             * @return a DAV:response XML element
133:             */
134:            public Element asXML() {
135:
136:                Element response = document.createElementNS("DAV:",
137:                        "D:response");
138:
139:                Element href = document.createElementNS("DAV:", "D:href");
140:
141:                href.appendChild(document.createTextNode(getResource()));
142:                response.appendChild(href);
143:                Enumeration urls = getResources();
144:                while (urls.hasMoreElements()) {
145:                    String url = (String) urls.nextElement();
146:                    Element hrefn = document.createElementNS("DAV:", "D:href");
147:
148:                    hrefn.appendChild(document.createTextNode(url));
149:                    response.appendChild(hrefn);
150:                }
151:
152:                Element status = document.createElementNS("DAV:", "D:status");
153:
154:                status.appendChild(document.createTextNode(HTTPVersion + " "
155:                        + getStatus() + " "
156:                        + WebDAVStatus.getStatusMessage(getStatus())));
157:                response.appendChild(status);
158:
159:                if (getDescription() != null) {
160:                    Element description = document.createElementNS("DAV:",
161:                            "D:responsedescription");
162:
163:                    description.appendChild(document
164:                            .createTextNode(getDescription()));
165:                    response.appendChild(description);
166:                }
167:                return response;
168:            }
169:
170:            /** Other resources effected by the method that share the
171:             * status response in this MethodResponse
172:             *
173:             * @return an Enumeration of Strings representing URLs of resources that
174:             *     responded in the same way to a request.
175:             */
176:            public Enumeration getResources() {
177:                return resources.elements();
178:            }
179:
180:            /** Get the status of the URLs in this MethodResponse.
181:             *
182:             * @return the HTTP status code for this response
183:             */
184:            public int getStatus() {
185:                return status;
186:            }
187:
188:            /** Check to see if this response does not contain an error.
189:             *
190:             * @return true if all response status code is less that 300, false otherwise.
191:             */
192:            public boolean isOK() {
193:                return status < 300;
194:            }
195:
196:            /** Set the status of the URLs in this MethodResponse.
197:             *
198:             * @param value an HTTP status code
199:             * @see com.ibm.webdav.WebDAVStatus
200:             */
201:            public void setStatus(int value) {
202:                status = value;
203:            }
204:
205:            /** Convert this Response to a PropertyResponse.
206:             * This method is used to convert MethodResponses to PropertyResponses
207:             * when an error occurred accessing the properties of some member.
208:             *
209:             */
210:            public PropertyResponse toPropertyResponse() {
211:                PropertyResponse response = new PropertyResponse(getResource());
212:                response.setDescription(getDescription());
213:                try {
214:                    response.setDocument(DocumentBuilderFactory.newInstance()
215:                            .newDocumentBuilder().newDocument());
216:                } catch (Exception e) {
217:                    e.printStackTrace(System.err);
218:                }
219:                return response;
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.