Source Code Cross Referenced for LockMethod.java in  » Net » SkunkDAV » org » skunk » dav » client » method » 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 » Net » SkunkDAV » org.skunk.dav.client.method 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.DAVMethodName;
028:        import org.skunk.dav.client.Depth;
029:        import org.skunk.dav.client.IfHeader;
030:        import org.skunk.dav.client.LockScope;
031:        import org.skunk.dav.client.PropertyHandler;
032:        import org.skunk.dav.client.Timeout;
033:        import org.skunk.minixml.MalformedXMLException;
034:        import org.skunk.minixml.XMLDocument;
035:        import org.skunk.minixml.XMLElement;
036:        import org.skunk.minixml.XMLParser;
037:        import org.skunk.minixml.XMLViewer;
038:        import org.skunk.trace.Debug;
039:        import java.io.IOException;
040:        import java.text.MessageFormat;
041:        import java.util.ListIterator;
042:        import java.util.Map;
043:
044:        public class LockMethod extends AbstractDAVMethod {
045:            private String lockToken;
046:            private Depth depth = Depth.ZERO;
047:            private Timeout timeout;
048:            private LockScope lockScope;
049:            private boolean isRefresh = false;
050:            private String userHref;
051:            private IfHeader ifHeader = null;
052:
053:            private static final String lockRequestXML = createLockRequestXML();
054:
055:            public LockMethod(String url, String userHref) {
056:                this (url, Depth.ZERO, null, LockScope.EXCLUSIVE, userHref);
057:            }
058:
059:            public LockMethod(String url, Depth depth, Timeout timeout,
060:                    LockScope lockScope, String userHref) {
061:                super (url);
062:                this .depth = depth;
063:                this .timeout = timeout;
064:                this .lockScope = lockScope;
065:                this .userHref = userHref;
066:            }
067:
068:            public void setDepth(Depth depth) {
069:                if (depth == Depth.ONE)
070:                    throw new IllegalArgumentException(
071:                            "lock depth must be zero or infinity");
072:                else
073:                    this .depth = depth;
074:            }
075:
076:            public Depth getDepth() {
077:                return depth;
078:            }
079:
080:            public Timeout getTimeout() {
081:                return timeout;
082:            }
083:
084:            public void setTimeout(Timeout timeout) {
085:                this .timeout = timeout;
086:            }
087:
088:            public LockScope getLockScope() {
089:                return this .lockScope;
090:            }
091:
092:            public void setLockScope(LockScope lockScope) {
093:                this .lockScope = lockScope;
094:            }
095:
096:            private XMLElement getLockScopeElement() {
097:                return new XMLElement(
098:                        (this .lockScope == LockScope.EXCLUSIVE) ? DAVConstants.EXCLUSIVE_ELEM
099:                                : DAVConstants.SHARED_ELEM);
100:            }
101:
102:            public void setIfHeader(IfHeader ifHeader) {
103:                this .ifHeader = ifHeader;
104:            }
105:
106:            public IfHeader getIfHeader() {
107:                return this .ifHeader;
108:            }
109:
110:            public void processRequestHeaders() {
111:                Map headers = getRequestHeaders();
112:                headers.put(DAVConstants.DEPTH_HEADER, depth);
113:                if (timeout != null)
114:                    headers.put(DAVConstants.TIMEOUT_HEADER, timeout);
115:                if (!isRefresh())
116:                    headers.put(DAVConstants.CONTENT_TYPE, "text/xml");
117:                if (ifHeader != null)
118:                    headers.put(DAVConstants.IF_HEADER, ifHeader.toString());
119:            }
120:
121:            public DAVMethodName getRequestMethodName() {
122:                return DAVMethodName.LOCK;
123:            }
124:
125:            public void processResponseHeaders() {
126:                //get lock-token
127:                int s = getStatus();
128:                if (s >= 200 && s > 300) {
129:                    Map headers = getResponseHeaders();
130:                    if (headers.containsKey(DAVConstants.LOCK_TOKEN_HEADER)) {
131:                        Object lockTokenObj = headers
132:                                .get(DAVConstants.LOCK_TOKEN_HEADER);
133:                        this .lockToken = lockTokenObj.toString();
134:                    }
135:                }
136:            }
137:
138:            public void processResponseBody() throws MalformedXMLException {
139:                int status = getStatus();
140:                if (status == 207) {
141:                    super .processResponseBody();
142:
143:                } else if (status == 200) {
144:                    byte[] body = getResponseBody();
145:                    if (body == null || getStatus() >= 400)
146:                        return;
147:                    String s = new String(body).trim();
148:                    XMLParser parser = new XMLParser();
149:                    try {
150:                        XMLDocument doc = parser.parse(s);
151:                        if (Debug.isDebug(this , Debug.DP8)) {
152:                            XMLViewer.viewDocumentDialog(doc);
153:                        }
154:                        //capture locktoken if we don't already have it from the header
155:                        if (lockToken == null) {
156:                            XMLElement elem = doc
157:                                    .getElement("prop/lockdiscovery/activelock/locktoken/href");
158:                            Object bodyLock = (elem != null) ? elem.getChild(0)
159:                                    : null;
160:                            if (bodyLock != null)
161:                                lockToken = bodyLock.toString();
162:                        }
163:                        //populate DAVFile
164:                        XMLElement propElem = doc.getElement("prop");
165:                        if (propElem == null)
166:                            return;
167:                        for (ListIterator lit = propElem.children(); lit
168:                                .hasNext();) {
169:                            Object propChile = lit.next();
170:                            if (propChile instanceof  XMLElement)
171:                                PropertyHandler.handleProperty(getDAVFile(),
172:                                        (XMLElement) propChile);
173:                        }
174:                    } catch (IOException oyVeh) {
175:                        oyVeh.printStackTrace();
176:                        throw new MalformedXMLException(oyVeh.getMessage());
177:                    }
178:                }
179:            }
180:
181:            public void setRefresh(boolean isRefresh) {
182:                this .isRefresh = isRefresh;
183:            }
184:
185:            public boolean isRefresh() {
186:                return isRefresh;
187:            }
188:
189:            public void processRequestBody() {
190:                if (!isRefresh) //for refreshes, do not include request body
191:                {
192:                    String s = MessageFormat
193:                            .format(getLockRequestXML(), new Object[] {
194:                                    getLockScopeElement(), getUserHref() });
195:                    setRequestBody(s.getBytes());
196:                }
197:            }
198:
199:            private static String getLockRequestXML() {
200:                return lockRequestXML;
201:            }
202:
203:            private static String createLockRequestXML() {
204:                try {
205:                    XMLElement lockInfoElem = new XMLElement(
206:                            DAVConstants.LOCKINFO_ELEM).setAttribute(
207:                            DAVConstants.XML_NAMESPACE_ATTR,
208:                            DAVConstants.DAV_NAMESPACE);
209:                    XMLElement lockScopeElem = new XMLElement(
210:                            DAVConstants.LOCKSCOPE_ELEM).addChild("{0}"); //new XMLElement(DAVConstants.EXCLUSIVE_ELEM));
211:                    XMLElement lockTypeElem = new XMLElement(
212:                            DAVConstants.LOCKTYPE_ELEM)
213:                            .addChild(new XMLElement(DAVConstants.WRITE_ELEM));
214:                    XMLElement ownerElem = new XMLElement(
215:                            DAVConstants.OWNER_ELEM).addChild(new XMLElement(
216:                            DAVConstants.HREF_ELEM).addChild("{1}")); //message format code
217:                    lockInfoElem.addChild(lockScopeElem);
218:                    lockInfoElem.addChild(lockTypeElem);
219:                    lockInfoElem.addChild(ownerElem);
220:                    XMLDocument minidoc = new XMLDocument();
221:                    minidoc.addElement(DAVConstants.XML_BOILERPLATE);
222:                    minidoc.addElement(lockInfoElem);
223:                    return minidoc.toString() + DAVConstants.CRLF;
224:                } catch (MalformedXMLException malex) //only thrown in development
225:                {
226:                    Debug.trace(LockMethod.class, Debug.DP1, malex);
227:                    return null;
228:                }
229:            }
230:
231:            public String getLockToken() {
232:                return lockToken;
233:            }
234:
235:            public String getUserHref() {
236:                return userHref;
237:            }
238:        }
239:
240:        /* $Log: LockMethod.java,v $
241:         /* Revision 1.13  2001/07/18 20:20:53  smulloni
242:         /* added IfHeader to LockMethod; fixed peculiar DAVFile bug (in getLock());
243:         /* various fixes, new cases to auto.py
244:         /*
245:         /* Revision 1.12  2001/07/15 18:16:37  smulloni
246:         /* fixed some copyright notices.
247:         /*
248:         /* Revision 1.11  2001/01/02 17:43:38  smulloni
249:         /* changed debug level for XMLViewer popups to Debug.DP8.
250:         /*
251:         /* Revision 1.10  2000/12/03 23:53:26  smulloni
252:         /* added license and copyright preamble to java files.
253:         /*
254:         /* Revision 1.9  2000/11/09 23:35:07  smullyan
255:         /* log added to every Java file, with the help of python.  Lock stealing
256:         /* implemented, and treatment of locks made more robust.
257:         /* */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.