[jboss-svn-commits] JBL Code SVN: r20729 - in labs/jbossrules/trunk/drools-eclipse: org.eclipse.webdav and 26 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jun 24 09:32:27 EDT 2008
Author: john.graham at jboss.org
Date: 2008-06-24 09:32:27 -0400 (Tue, 24 Jun 2008)
New Revision: 20729
Added:
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.classpath
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.cvsignore
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.project
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/org.eclipse.jdt.core.prefs
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/MANIFEST.MF
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/about.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/bin/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/build.properties
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/buildnotes_platform-webdav.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/plugin.properties
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/AbstractResourceHandle.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/CollectionHandle.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/DAVClient.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/LocalDAVClient.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/Policy.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/PropertyStatus.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RemoteDAVClient.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RequestBodyWriter.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResourceHandle.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResponseInputStream.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTable.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WebDAVFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WorkspaceHandle.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/messages.properties
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/package.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/BufferPool.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ContentType.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpClient.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpConnection.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IAuthenticator.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IRequestBodyWriter.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ISocketFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IStatusCodes.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Message.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Request.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/RequestInputStream.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Response.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/package.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticateChallenge.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticationInfo.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthorizationAuthority.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/BasicAuthority.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestAuthority.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestOutputStream.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/HexConverter.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Parser.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/ParserException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContext.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContextFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocator.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocatorFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IResponse.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServer.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServerFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/Policy.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ActiveLock.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Assert.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/AssertionFailedException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/BaselineControl.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Bindings.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Conflict.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ConflictReportResponse.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/HrefSet.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Label.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockDiscovery.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockEntry.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockInfo.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MalformedElementException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Mkworkspace.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MultiStatus.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Namespaces.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Owner.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Prop.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropFind.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropStat.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Property.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyBehavior.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyUpdate.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedName.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedNameImpl.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResourceID.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResponseBody.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Status.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/SupportedLock.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Update.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/package.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLDecoder.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLEncoder.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/messages.properties
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/package.html
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ClientException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Condition.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionFactor.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionTerm.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Context.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ContextFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAV4JRuntimeException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVRuntimeException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentMarshaler.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ElementHelper.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/EntityTag.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentMarshaler.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/InvalidPropertyNameException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Locator.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LocatorFactory.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LockToken.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Message.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Policy.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Precondition.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/QualifiedNameImpl.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/RedirectionException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Response.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ServerException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/StateToken.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Status.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/SystemException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVConstants.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPreconditionFailures.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyNames.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyValues.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/messages.properties
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/Assert.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/AssertionFailedException.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/DateTime.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EmptyEnumeration.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationConverter.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationFilter.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/ExcludingEnumeration.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/MergedEnumeration.java
labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/NestedHashtable.java
Log:
Initial commit of org.eclipse.webdav plug-in
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.classpath (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.classpath 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/client"/>
+ <classpathentry kind="src" path="src/interface"/>
+ <classpathentry kind="src" path="src/kernel"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.classpath
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.cvsignore
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.cvsignore (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.cvsignore 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1 @@
+bin
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.cvsignore
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.project
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.project (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.project 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.webdav</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.project
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/org.eclipse.jdt.core.prefs 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,7 @@
+#Tue Nov 14 10:19:47 EST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/.settings/org.eclipse.jdt.core.prefs
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/MANIFEST.MF
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/MANIFEST.MF (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/MANIFEST.MF 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.webdav
+Bundle-Version: 3.0.101.qualifier
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Export-Package: org.eclipse.webdav,
+ org.eclipse.webdav.client,
+ org.eclipse.webdav.dom,
+ org.eclipse.webdav.http.client,
+ org.eclipse.webdav.internal.authentication;x-internal:=true,
+ org.eclipse.webdav.internal.kernel;x-internal:=true,
+ org.eclipse.webdav.internal.kernel.utils;x-internal:=true,
+ org.eclipse.webdav.internal.utils;x-internal:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.4,
+ CDC-1.0/Foundation-1.0,
+ J2SE-1.3
+Import-Package: javax.xml.parsers,
+ javax.xml.transform,
+ org.w3c.dom,
+ org.xml.sax
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/META-INF/MANIFEST.MF
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/about.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/about.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/about.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 2, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/about.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/build.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/build.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/build.properties 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,18 @@
+###############################################################################
+# Copyright (c) 2000, 2006 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+source..=src/client/,src/kernel/,src/interface/
+src.includes=about.html
+bin.includes = .,\
+ plugin.properties,\
+ about.html,\
+ META-INF/
+javadoc.packages=org.eclipse.*
+
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/build.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/buildnotes_platform-webdav.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/buildnotes_platform-webdav.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/buildnotes_platform-webdav.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,219 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; I) [Netscape]">
+ <title>Eclipse Platform Release Notes Core</title>
+<!-- saved from url=(0079)http://home.ott.oti.com/hubba/drops/sdk/latest-javadoc/doc/buildnotes_core.html -->
+<!-- saved from url=(0079)http://home.ott.oti.com/hubba/drops/sdk/latest-javadoc/doc/buildnotes_core.html -->
+</head>
+<body>
+<h1> Eclipse Platform Build Notes<br>
+ WebDAV</h1>
+Eclipse SDK Build 3.0 RC4
+<h2> What's new in this drop</h2>
+<h3> API changes</h3>
+<ul>
+ <li> None.</li>
+</ul>
+<h3> Other highlights</h3>
+<ul>
+ <li> No new work was done on this component for the 3.0 release of Eclipse.</li>
+</ul>
+<h3> Resolved Bugs</h3>
+<ul>
+ <li> <a href="https://bugs.eclipse.org/bugs/buglist.cgi?short_desc_type=allwordssubstr&short_desc=&product=Platform&component=WebDAV&long_desc_type=allwordssubstr&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&keywords_type=anywords&keywords=&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&emailassigned_to1=1&emailtype1=substring&email1=&emailreporter2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&changedin=&chfield=bug_status&chfieldfrom=2003-03-27&chfieldto=2004-06-24&chfieldvalue=&cmdtype=doit&namedcmd=5votes&newqueryname=&order=Reuse%2Bsame%2Bsort%2Bas%2Blast%2Btime&field0-0-0=noop&type0-0-0=noop&value0-0-0=">Click
+ here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+ since the last integration build.</li>
+</ul>
+<h1></h1>
+<hr>
+<h1></h1>
+<h1>Eclipse Platform Build Notes<br>
+ WebDAV</h1>
+Eclipse SDK Build 20030327
+<h2> What's new in this drop</h2>
+<h3> API changes</h3>
+<ul>
+ <li> None.</li>
+</ul>
+<h3> Other highlights</h3>
+<ul>
+ <li> None.</li>
+</ul>
+<h3> Resolved Bugs</h3>
+<ul>
+ <li> <a href="http://bugs.eclipse.org/bugs/buglist.cgi?short_desc_type=allwordssubstr&short_desc=&product=Platform&component=WebDAV&version=2.0&long_desc_type=allwordssubstr&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&keywords_type=anywords&keywords=&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&emailassigned_to1=1&emailtype1=substring&email1=&emailreporter2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&changedin=&chfield=bug_status&chfieldfrom=2002-04-30&chfieldto=2003-03-27&chfieldvalue=&cmdtype=doit&namedcmd=core-2.1&newqueryname=&order=Reuse%2Bsame%2Bsort%2Bas%2Blast%2Btime&field0-0-0=noop&type0-0-0=noop&value0-0-0=">Click
+ here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+ since the last integration build.</li>
+</ul>
+<h1></h1>
+<hr>
+<h1>Eclipse Platform Build Notes<br>
+ WebDAV</h1>
+Eclipse SDK Build 20020430
+<h2>
+What's new in this drop</h2>
+
+<h3>
+API changes</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Other highlights</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Resolved Bugs</h3>
+
+<ul>
+<li>
+<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfield=bug_status&chfieldfrom=2001-12-25&chfieldto=2002-04-30&chfieldvalue=&product=Platform&version=2.0&component=WebDAV&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&order=Bug+Number">Click
+here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+since the last integration build.</li>
+</ul>
+
+<h1>
+
+<hr WIDTH="100%">Eclipse Platform Build Notes<br>
+WebDAV</h1>
+Eclipse SDK Build 20020425
+<h2>
+What's new in this drop</h2>
+
+<h3>
+API changes</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Other highlights</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Resolved Bugs</h3>
+
+<ul>
+<li>
+<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfield=bug_status&chfieldfrom=2001-12-17&chfieldto=2002-04-25&chfieldvalue=&product=Platform&version=2.0&component=WebDAV&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&namedcmd=Active&newqueryname=&order=Bug+Number">Click
+here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+since the last integration build.</li>
+</ul>
+
+<h1>
+
+<hr WIDTH="100%">Eclipse Platform Build Notes<br>
+WebDAV</h1>
+Eclipse SDK Build 20011218
+<h2>
+What's new in this drop</h2>
+
+<h3>
+API changes</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Other highlights</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Resolved Bugs</h3>
+
+<ul>
+<li>
+<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfield=bug_status&chfieldfrom=2001-12-11&chfieldto=2001-12-17&chfieldvalue=&product=Platform&version=2.0&component=WebDAV&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&namedcmd=ant&newqueryname=&order=Bug+Number">Click
+here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+since the last integration build.</li>
+</ul>
+
+<h1>
+
+<hr WIDTH="100%">Eclipse Platform Build Notes<br>
+WebDAV</h1>
+Eclipse SDK Build 20011211
+<h2>
+What's new in this drop</h2>
+
+<h3>
+API changes</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Other highlights</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+<h3>
+Resolved Bugs</h3>
+
+<ul>
+<li>
+<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfield=bug_status&chfieldfrom=2001-11-27&chfieldto=2001-12-10&chfieldvalue=&product=Platform&version=2.0&component=WebDAV&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&namedcmd=Active&newqueryname=&order=Bug+Number">Click
+here</a> to see PRs which have been marked as RESOLVED, VERIFIED or CLOSED
+since the last integration build.</li>
+</ul>
+
+<h1>
+
+<hr WIDTH="100%">Eclipse Platform Build Notes<br>
+WebDAV</h1>
+Eclipse SDK Build 20011120 (v211)
+<h2>
+What's new in this drop</h2>
+
+<h3>
+API changes</h3>
+
+<ul>
+<li>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=5410">5410</a>
+DAVClient doesn't close down the http client</li>
+
+<ul>
+<li>
+API clients are now expected to close() instances of DAVClient. For
+remote clients, this will have the effect of closing the http client instance
+and interrupting the connection recycler.</li>
+</ul>
+</ul>
+
+<h3>
+Other highlights</h3>
+
+<ul>
+<li>
+None.</li>
+</ul>
+
+</body>
+</html>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/buildnotes_platform-webdav.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/plugin.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/plugin.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/plugin.properties 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,12 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+pluginName=WebDAV Client
+providerName=Eclipse.org
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/plugin.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/AbstractResourceHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/AbstractResourceHandle.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/AbstractResourceHandle.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1511 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+import org.eclipse.webdav.*;
+import org.eclipse.webdav.dom.*;
+import org.eclipse.webdav.internal.kernel.*;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.eclipse.webdav.internal.kernel.utils.EmptyEnumeration;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The <code>AbstractResourceHandle</code> class is the abstract
+ * superclass for all types of resource references. A resource
+ * handle is a client-side 'proxy' for the server resource. Instances
+ * of handle classes understand the methods appropriate for the
+ * corresponding server resource and provide a convenient high-level
+ * API for sending WebDAV methods to the server to manipulate
+ * the resource.
+ * <p>
+ * It is certainly posible to create a stale or invalid handle in
+ * numerous ways. For example, the existance of a handle does not
+ * imply the existance of a corresponding server resource (indeed
+ * resource can be created by sending create() to a handle, or deleted
+ * using delete() -- so the life cycles are not coupled. It is also
+ * possible to create, say, a collection handle on a regular resource
+ * and invoke invalid WebDAV methods. These will typically result
+ * in an exception.</p>
+ * <p>
+ * The API on these classes are intended to convenience methods for
+ * the most common operations on server resources. They make some
+ * assumptions about the way you want to receive the results. To
+ * get finer (but possibly less convenient) control over the WebDAV
+ * methods use the <code>Server</code> interface of <code>DAVClient
+ * </code> directly.</p>
+ */
+public abstract class AbstractResourceHandle implements WebDAVPropertyNames, WebDAVPropertyValues {
+
+ // The DAVClient that is used to access the WebDAV server.
+ // Given during initialization, this object contains the
+ // authentication and proxy information etc.
+ protected DAVClient davClient;
+
+ // The Locator represents the universal identifier of the server
+ // resource.
+ protected ILocator locator;
+
+ /**
+ * Creates a new <code>AbstractResourceHandle</code> with the given
+ * DAV client and <code>Locator</code>.
+ *
+ * @param davClient the <code>DAVClient</code> that contains the server
+ * reference and proxy/authentication information.
+ * @param locator the <code>Locator</code> identity of the resource.
+ */
+ public AbstractResourceHandle(DAVClient davClient, ILocator locator) {
+ Assert.isNotNull(davClient);
+ Assert.isNotNull(locator);
+ this.davClient = davClient;
+ this.locator = locator;
+ }
+
+ /**
+ * Answer a new collection handle on the same underlying server resource.
+ * Since the handle represents a means of accessing the resource, it is valid to
+ * consider a collection resource as a collection or regular resource depending
+ * upon how it is being accessed. Note that not all resources have collection
+ * semantics.
+ *
+ * @return an equivalent collection handle on the resource.
+ */
+ public CollectionHandle asCollectionHandle() {
+ return new CollectionHandle(davClient, locator);
+ }
+
+ /**
+ * Answer a new resource handle on the same underlying server resource.
+ * Since the handle represents a means of accessing the resource, it is valid to
+ * consider a collection resource as a collection or regular resource depending
+ * upon how it is being accessed.
+ *
+ * @return an equivalent handle on the resource.
+ */
+ public ResourceHandle asResourceHandle() {
+ return new ResourceHandle(davClient, locator);
+ }
+
+ /**
+ * Return a boolean value indicating whether or not the server for this resource
+ * is DAV compliant.
+ *
+ * @return boolean <code>true</code> if the server can respond to DAV
+ * requests, or <code>false</code> otherwise.
+ * @exception DAVException if there was a problem checking for DAV compliance
+ */
+ public boolean canTalkDAV() throws DAVException {
+ IResponse response = null;
+ try {
+ // Send an options request.
+ response = davClient.options(locator, newContext());
+ examineResponse(response);
+
+ // Check for at least DAV level 1.
+ String davHeader = response.getContext().getDAV();
+ return !((davHeader == null) || (davHeader.indexOf("1") == -1)); //$NON-NLS-1$
+ } catch (IOException exception) {
+ throw new SystemException(exception);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Check-in this resource. Returns a handle on the new version.
+ * <p>
+ * Note that versioned collections do not have internal members
+ * so they are represented by <code>ResourceHandle</code> handles.</p>
+ * <p>
+ * If the receiver is a working resource it becomes invalid after
+ * the check in (because the server deletes the working resource),
+ * however, if the receiver is a version-controlled resource the
+ * receiver can be used as a checked-in resource.</p>
+ *
+ * @return a handle to the newly created version.
+ * @throws DAVException if a problem occurs with the check in on
+ * the WebDAV server.
+ */
+ public ResourceHandle checkIn() throws DAVException {
+ ILocator versionLocator = protectedCheckIn();
+ return new ResourceHandle(davClient, versionLocator);
+ }
+
+ /**
+ * Check out this resource. Returns a resource handle on the checked out
+ * version-controlled resource, or the working resource if a version is checked
+ * out.
+ * <p>
+ * Note that a checked-out version-controlled collection has members that are
+ * themselves version-controlled resources, or unversioned resources; however,
+ * working collection members are always version history resources.</p>
+ *
+ * @throws DAVException if a problem occurs checking out the resource.
+ */
+ public abstract AbstractResourceHandle checkOut() throws DAVException;
+
+ /**
+ * Helper method to close a response from the server.
+ * <p>
+ * Note that the argument MAY be <code>null</code> in which case
+ * the call has no effect.</p>
+ *
+ * @param response the response from the server, or <cod>null</code>
+ * denoting a no-op.
+ * @throws SystemException if a problem occurred closing the response.
+ */
+ protected void closeResponse(IResponse response) throws SystemException {
+ if (response == null)
+ return;
+ try {
+ response.close();
+ } catch (IOException e) {
+ throw new SystemException(e);
+ }
+ }
+
+ /**
+ * Make a copy of this resource and place it at the location defined
+ * by the given locator.
+ * <p>
+ * Uses default values of depth: infinity and overwrite: false for
+ * the copy.</p>
+ *
+ * @param destination the <code>Locator</code> to the destination of the copy.
+ * @exception DAVException if there was a problem copying this resource.
+ * @see IServer#copy(ILocator, ILocator, IContext, Document)
+ */
+ public void copy(ILocator destination) throws DAVException {
+ copy(destination, IContext.DEPTH_INFINITY, false, null);
+ }
+
+ /**
+ * Make a copy of this resource and place it at the location specified
+ * by the given destination locator.
+ *
+ * @param destination the location to put the copy.
+ * @param depth how deep to make the copy.
+ * @param overwrite how to react if a resource already exists at the destination.
+ * @param propertyNames <code>Collection</code> of <code>QualifiedName</code>s
+ * of properties that MUST be copied as live properties. Specifying <code>null</code>
+ * mean that <i>all</i> properties must be kept alive; specifying an empty collection allows for
+ * no properties to be kept live. (ref http://andrew2.andrew.cmu.edu/rfc/rfc2518.html#sec-12.12.1)
+ * @exception DAVException if there was a problem copying this resource.
+ * @see IServer#copy(ILocator, ILocator, IContext, Document)
+ */
+ public void copy(ILocator destination, String depth, boolean overwrite, Collection propertyNames) throws DAVException {
+ // Define the request context.
+ IContext context = newContext();
+ context.setDepth(depth);
+ context.setOverwrite(overwrite);
+
+ // Set up the request body to specify which properties should be kept alive.
+ Document document = newDocument();
+ PropertyBehavior propertyBehavior = PropertyBehavior.create(document);
+
+ if (propertyNames == null)
+ propertyBehavior.setIsKeepAllAlive(true);
+ else {
+ Iterator namesItr = propertyNames.iterator();
+ while (namesItr.hasNext()) {
+ QualifiedName name = (QualifiedName) namesItr.next();
+ String nameURI = name.getQualifier() + "/" + name.getLocalName(); //$NON-NLS-1$
+ propertyBehavior.addProperty(nameURI);
+ } // end-while
+ } // end-if
+
+ // Call the server to perform the copy.
+ IResponse response = null;
+ try {
+ response = davClient.copy(locator, destination, context, document);
+ examineResponse(response);
+ examineMultiStatusResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Create this resource in the repository.
+ * <p>
+ * Subclasses should override this method with the correct behavior
+ * for their type.</p>
+ *
+ * @exception DAVException if there was a problem creating
+ * this resource.
+ */
+ public abstract void create() throws DAVException;
+
+ /**
+ * Delete this resource from the repository.
+ * <p>
+ * As a convenience, if the resource does not exist this method will
+ * do nothing (rather than throw an exception). If the caller needs to know
+ * if a resource was deleted they can use delete(boolean).
+ *
+ * @exception DAVException if there was a problem deleting this resource.
+ * @see #delete(boolean)
+ * @see IServer#delete(Locator, Context)
+ */
+ public void delete() throws DAVException {
+ // As a convenience, we will assume an attempt to
+ // delete a missing resource is a successful outcome.
+ delete(false);
+ }
+
+ /**
+ * Answers true iff the receiver and the argument are considered equal,
+ * otherwise answers false.
+ * <p>
+ * Note that this is a handle equivalence test, and does not imply
+ * that the resources are the same resource on the server. Indeed,
+ * the method does not contact the server.</p>
+ *
+ * @param obj the target of the comparison.
+ * @return whether the two objects are equal.
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof AbstractResourceHandle))
+ return false;
+ AbstractResourceHandle otherHandle = (AbstractResourceHandle) obj;
+ // It all comes down to locator equality.
+ return locator.equals(otherHandle.locator);
+ }
+
+ /**
+ * Answers the hashcode of the receiver as defined by <code>Object#hashCode()</code>.
+ *
+ * @return the receiver's hash code.
+ */
+ public int hashCode() {
+ return locator.hashCode();
+ }
+
+ /**
+ * If the given response contains a multistatus body, the bodies status'
+ * are checked for errors. If an error is found, an exception is thrown.
+ *
+ * @param response the response from the server to examine.
+ * @throws DAVException if the given response contains a multistatus
+ * body that contains a status code signalling an error.
+ */
+ protected void examineMultiStatusResponse(IResponse response) throws DAVException {
+ // If it is not a multistatus we don't look at it.
+ if (response.getStatusCode() != IResponse.SC_MULTI_STATUS)
+ return;
+
+ // It is declared a multistatus, so if there is no response body
+ // then that is a problem.
+ if (!response.hasDocumentBody())
+ throw new DAVException(Policy.bind("exception.responseMustHaveDocBody")); //$NON-NLS-1$
+
+ // Extract the XML document from the response.
+ Element documentElement;
+ try {
+ documentElement = response.getDocumentBody().getDocumentElement();
+ if (documentElement == null)
+ throw new DAVException(Policy.bind("exception.invalidDoc")); //$NON-NLS-1$
+ } catch (IOException exception) {
+ throw new SystemException(exception);
+ }
+
+ // Enumerate all the responses in the multistat and check that
+ // they are indicating success (i.e. are 200-series response codes).
+ try {
+ MultiStatus multistatus = new MultiStatus(documentElement);
+ Enumeration responseEnum = multistatus.getResponses();
+ while (responseEnum.hasMoreElements()) {
+ ResponseBody responseBody = (ResponseBody) responseEnum.nextElement();
+ Enumeration propstatEnum = responseBody.getPropStats();
+ while (propstatEnum.hasMoreElements()) {
+ PropStat propstat = (PropStat) propstatEnum.nextElement();
+ examineStatusCode(propstat.getStatusCode(), propstat.getResponseDescription());
+ } // end-while
+ } // end-while
+ } catch (MalformedElementException e) {
+ throw new SystemException(e);
+ }
+ }
+
+ /**
+ * Check the status code of the given response and throw a WebDAV
+ * exception if the code indicates failure.
+ *
+ * @param response the response to check
+ * @exception WebDAVException if the server returned an HTTP/WebDAV
+ * error code (i.e., anything outside the 200-series codes).
+ */
+ protected void examineResponse(IResponse response) throws WebDAVException {
+ examineStatusCode(response.getStatusCode(), response.getStatusMessage());
+ }
+
+ /**
+ * Helper method to extract the property status response from
+ * a multi status reponse, and populate a URLTable with the
+ * results.
+ *
+ * @param multiStatus an editor on the response from the server.
+ * @return all the property status in a <code>URLTable</code>.
+ * @throws IOException if there is a problem parsing the resource URLs.
+ * @throws MalformedElementException if the XML is badly formed.
+ */
+ protected URLTable extractPropStats(MultiStatus multiStatus) throws IOException, MalformedElementException {
+ // Construct a URLTable to return to the user.
+ URLTable reply = new URLTable();
+
+ // For each response (resource).
+ Enumeration responses = multiStatus.getResponses();
+ while (responses.hasMoreElements()) {
+ ResponseBody responseBody = (ResponseBody) responses.nextElement();
+ String href = responseBody.getHref();
+
+ // The href may be relative to the request URL.
+ URL resourceURL = new URL(new URL(locator.getResourceURL()), href);
+ Hashtable properties = new Hashtable();
+ reply.put(resourceURL, properties);
+
+ // For each property status grouping.
+ Enumeration propstats = responseBody.getPropStats();
+ while (propstats.hasMoreElements()) {
+ PropStat propstat = (PropStat) propstats.nextElement();
+ org.eclipse.webdav.dom.Status status = new org.eclipse.webdav.dom.Status(propstat.getStatus());
+
+ // For each property with this status.
+ Enumeration elements = propstat.getProp().getProperties();
+ while (elements.hasMoreElements()) {
+ Element element = (Element) elements.nextElement();
+ QualifiedName name = ElementEditor.getQualifiedName(element);
+ // Add a property status object to the result set.
+ PropertyStatus propertyStatus = new PropertyStatus(element, status.getStatusCode(), status.getStatusMessage());
+ properties.put(name, propertyStatus);
+ } // end-while
+ } // end-while
+ } // end-while
+
+ return reply;
+ }
+
+ /**
+ * Return the content of this resource as an input stream. The input
+ * stream should be closed by the user.
+ *
+ * @return the input stream
+ * @exception DAVException if there was a problem getting the contents
+ * @see IServer#get(Locator, Context)
+ */
+ public ResponseInputStream getContent() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.get(locator, newContext());
+ examineResponse(response);
+ } catch (IOException e) {
+ closeResponse(response);
+ throw new SystemException(e);
+ }
+ return new ResponseInputStream(response);
+ }
+
+ /**
+ * Answer the DAVClient being used by this resource handle for accessing
+ * the resource.
+ *
+ * @return the receiver's <code>DAVClient</code>.
+ */
+ public DAVClient getDAVClient() {
+ return davClient;
+ }
+
+ /**
+ * Return the locator for this resource.
+ *
+ * @return the locator for this resource
+ */
+ public ILocator getLocator() {
+ return locator;
+ }
+
+ /**
+ * Return an Enumeration over ActiveLocks which lists the locks currently
+ * held on this resource. Return an empty enumeration if the lock discovery
+ * property is not found on the resource.
+ *
+ * @return the enumeration of active locks
+ * @exception DAVException if there was a problem getting the locks
+ * @see #getProperty(QualifiedName)
+ */
+ public Enumeration getLocks() throws DAVException {
+ LockDiscovery lockdiscovery = null;
+ try {
+ Element element = getProperty(DAV_LOCK_DISCOVERY).getProperty();
+ lockdiscovery = new LockDiscovery(element);
+ return lockdiscovery.getActiveLocks();
+ } catch (WebDAVException exception) {
+ if (exception.getStatusCode() == IResponse.SC_NOT_FOUND)
+ return new EmptyEnumeration();
+ throw exception;
+ } catch (MalformedElementException elemException) {
+ throw new SystemException(elemException);
+ }
+ }
+
+ /**
+ * Returns a collection handle for the parent of this resource.
+ * <p>
+ * Note that this method does NOT perform a method call to the
+ * server to ensure that the collection exists.</p>
+ * <p>
+ * Returns <code>null</code> if this resource is the root.
+ *
+ * <em>NOTE</em>
+ * The parent of a resource is, in general, ambiguous and may not
+ * be immediately discernable from a resource locator. For example,
+ * a locator with a 'label' qualifier will identify a version of a version-
+ * controlled resource, and the parent will not be found by a simple URL
+ * operation. Where a handle is created on a stable URL (i.e. a version URL)
+ * there is no concept of a 'parent' resource.
+ * Clients require further contextual information to determine
+ * the 'parent' of a resource in these cases.
+ *
+ * @return the handle for the parent of this resource, or
+ * <code>null</code>.
+ */
+ public CollectionHandle getParent() throws DAVException {
+ Assert.isTrue(locator.getLabel() == null);
+ Assert.isTrue(!locator.isStable());
+
+ try {
+ URL url = URLTool.getParent(locator.getResourceURL());
+ if (url == null)
+ return null;
+ String parentName = url.toString();
+ ILocator parentLocator = davClient.getDAVFactory().newLocator(parentName);
+ return new CollectionHandle(davClient, parentLocator);
+
+ } catch (MalformedURLException e) {
+ throw new SystemException(e);
+ }
+ }
+
+ /**
+ * Return a <code>URLTable</code> which contains all of this resources
+ * properties to the given depth. The returned <code>URLTable</code>
+ * maps resource <code>URL</code>s to <code>Hashtable</code>s
+ * which in turn maps property <code>QualifiedName</code>s to
+ * <code>PropertyStatus</code>.
+ *
+ * @param depth the depth of the request; for example,
+ * <code>Context.DEPTH_ZERO</code>.
+ * @return a <code>URLTable</code> containing properties.
+ * @exception DAVException if there was a problem retrieving the properties.
+ * @see #getProperties(Collection, String)
+ */
+ public URLTable getProperties(String depth) throws DAVException {
+ return getProperties((Collection) null, depth);
+ }
+
+ /**
+ * Fetches and returns the specified properties for this resource and its
+ * children to the given depth. The returned table is a URLTable of
+ * hashtables. The keys in the first table are the <code>URL</code>s of
+ * the resources. The nested table is a table where the keys are the names
+ * (<code>QualifiedName</code>) of the properties and the values are the
+ * properties' values (<code>PropertyStatus</code>).
+ *
+ * @param propertyNames collection of property names to search for
+ * (<code>QualifiedName</code>), or <code>null</code> to retrieve
+ * all properties.
+ * @param depth the depth of the search (eg. <code>Context.DEPTH_INFINITY</code>)
+ * @return URLTable of hashtables keyed by resource <code>URLKey</code>
+ * then by property name.
+ * @exception DAVException if there was a problem fetching the properties.
+ * @see IServer#propfind(Locator, Context, Document)
+ */
+ public URLTable getProperties(Collection propertyNames, String depth) throws DAVException {
+ // Set up the request context.
+ IContext context = newContext();
+ context.setDepth(depth);
+
+ // Set up the request body.
+ Document document = newDocument();
+ PropFind propfind = PropFind.create(document);
+
+ // null is a special value meaning 'all properties'.
+ if (propertyNames == null)
+ propfind.setIsAllProp(true);
+ else {
+ // Add all the property names to the request body.
+ Prop prop = propfind.setProp();
+ Iterator namesItr = propertyNames.iterator();
+ while (namesItr.hasNext())
+ prop.addPropertyName((QualifiedName) namesItr.next());
+ }
+
+ // Were ready to make the server call.
+ IResponse response = null;
+ try {
+ // This contacts the server.
+ response = davClient.propfind(locator, context, document);
+ examineResponse(response);
+
+ // Create a multi-status element editor on the response.
+ if (!response.hasDocumentBody())
+ throw new DAVException(Policy.bind("exception.respMustShareXMLDoc")); //$NON-NLS-1$
+ Element documentElement = response.getDocumentBody().getDocumentElement();
+ if (documentElement == null)
+ throw new DAVException(Policy.bind("exception.respHasInvalidDoc")); //$NON-NLS-1$
+ MultiStatus multiStatus = new MultiStatus(documentElement);
+
+ // Construct a URLTable of results to return to the user.
+ return extractPropStats(multiStatus);
+
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } catch (MalformedElementException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Return the property status for the property with the given name.
+ *
+ * @param propertyName the name of the property
+ * @return the property status
+ * @exception DAVException if there was a problem getting the property
+ * @see #getProperties(Collection, String)
+ */
+ public PropertyStatus getProperty(QualifiedName propertyName) throws DAVException {
+ Collection names = new HashSet();
+ names.add(propertyName);
+ URLTable result = getProperties(names, IContext.DEPTH_ZERO);
+
+ URL url = null;
+ try {
+ url = new URL(locator.getResourceURL());
+ } catch (MalformedURLException e) {
+ throw new SystemException(e);
+ }
+
+ Hashtable propTable = (Hashtable) result.get(url);
+ if (propTable == null)
+ throw new DAVException(Policy.bind("exception.lookup", url.toExternalForm())); //$NON-NLS-1$
+ return (PropertyStatus) propTable.get(propertyName);
+ }
+
+ /**
+ * Fetch and return the property names for the resource, and the children
+ * resources to the specified depth. Returns <code>URLTable</code>
+ * mapping resource URLs to enumerations over the property names for that
+ * resource.
+ *
+ * @param depth eg. <code>Context.DEPTH_ZERO</code>
+ * @return a <code>URLTable</code> of <code>Enumerations</code> over
+ * <code>QualfiedNames</code>
+ * @throws DAVException if there was a problem getting the property names
+ * @see IServer#propfind(Locator, Context, Document)
+ */
+ public URLTable getPropertyNames(String depth) throws DAVException {
+
+ // create and send the request
+ IContext context = newContext();
+ context.setDepth(depth);
+
+ IResponse response = null;
+ try {
+ Document document = newDocument();
+ PropFind propfind = PropFind.create(document);
+ propfind.setIsPropName(true);
+
+ response = davClient.propfind(locator, context, document);
+ examineResponse(response);
+
+ if (!response.hasDocumentBody()) {
+ throw new DAVException(Policy.bind("exception.respMustHaveElmtBody")); //$NON-NLS-1$
+ }
+ Element documentElement = response.getDocumentBody().getDocumentElement();
+ if (documentElement == null) {
+ throw new DAVException(Policy.bind("exception.bodyMustHaveElmt")); //$NON-NLS-1$
+ }
+ MultiStatus multistatus = new MultiStatus(documentElement);
+
+ //construct the URLTable to return to the user
+ URLTable reply = new URLTable(10);
+ Enumeration responses = multistatus.getResponses();
+ while (responses.hasMoreElements()) {
+ ResponseBody responseBody = (ResponseBody) responses.nextElement();
+ String href = responseBody.getHref();
+ URL resourceUrl = new URL(new URL(locator.getResourceURL()), href);
+ Enumeration propstats = responseBody.getPropStats();
+ Vector vector = new Vector();
+ while (propstats.hasMoreElements()) {
+ PropStat propstat = (PropStat) propstats.nextElement();
+ Prop prop = propstat.getProp();
+ Enumeration names = prop.getPropertyNames();
+ while (names.hasMoreElements()) {
+ QualifiedName dname = (QualifiedName) names.nextElement();
+ vector.addElement(dname);
+ }
+ }
+ reply.put(resourceUrl, vector.elements());
+ }
+ return reply;
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } catch (MalformedElementException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Retrieve the version tree infomration for the receiver, assuming
+ * that the receiver is a version or a version-controlled resource.
+ * <p>
+ * The version tree info comprises a <code>URLTable</code> whose keys
+ * are the <code>URL</code>s of each version in the version history,
+ * and whose values are <code>Vector</code>s of the resource's immediate
+ * predecessor <code>URL</code>s. Note that the root version is
+ * (uniquely) identified by an empty set of predecessors.</p>
+ *
+ * @return the map from resource URL to predecessor set.
+ */
+ public URLTable getVersionTree() throws DAVException {
+
+ // Issue a version tree report against the receiver to retrieve
+ // the successor set of all the versions.
+ Document document = newDocument();
+ Element root = ElementEditor.create(document, "version-tree"); //$NON-NLS-1$
+ Element propElement = ElementEditor.appendChild(root, "prop"); //$NON-NLS-1$
+ ElementEditor.appendChild(propElement, "predecessor-set"); //$NON-NLS-1$
+
+ IResponse response = null;
+ try {
+ // Run the REPORT and check for errors.
+ response = davClient.report(locator, newContext(), document);
+ examineResponse(response);
+
+ if (!response.hasDocumentBody())
+ throw new DAVException(Policy.bind("exception.respMustHaveElmtBody")); //$NON-NLS-1$
+
+ // Get the body as a MultiStatus.
+ Element documentElement = response.getDocumentBody().getDocumentElement();
+ if (documentElement == null)
+ throw new DAVException(Policy.bind("exception.bodyMustHaveElmt")); //$NON-NLS-1$
+ MultiStatus multistatus = new MultiStatus(documentElement);
+
+ // Construct the predecessor table.
+ // This will contain the result.
+ URLTable predecessorTable = new URLTable();
+
+ // For each response.
+ Enumeration responses = multistatus.getResponses();
+ while (responses.hasMoreElements()) {
+ ResponseBody responseBody = (ResponseBody) responses.nextElement();
+
+ // Get the absolute URL of the resource.
+ String href = responseBody.getHref();
+ URL resourceURL = new URL(new URL(locator.getResourceURL()), href);
+
+ // Add an entry to the predecessor table.
+ Vector predecessors = new Vector();
+ predecessorTable.put(resourceURL, predecessors);
+
+ // For each propstat.
+ Enumeration propstats = responseBody.getPropStats();
+ while (propstats.hasMoreElements()) {
+ PropStat propstat = (PropStat) propstats.nextElement();
+
+ // We are going to assume that the status is OK, or error out.
+ if (propstat.getStatusCode() != IResponse.SC_OK)
+ throw new DAVException(Policy.bind("exception.errorRetrievingProp")); //$NON-NLS-1$
+
+ // For each property in the prop (there should only be one).
+ Prop prop = propstat.getProp();
+ Enumeration elements = prop.getProperties();
+ while (elements.hasMoreElements()) {
+ Element element = (Element) elements.nextElement();
+
+ // Look explicitly for the DAV:predecessor-set
+ QualifiedName name = ElementEditor.getQualifiedName(element);
+ if (name.equals(DAV_PREDECESSOR_SET)) {
+ Enumeration e = new HrefSet(element, DAV_PREDECESSOR_SET).getHrefs();
+ while (e .hasMoreElements()) {
+ URL predURL = new URL((String) e.nextElement());
+ predecessors.add(predURL);
+ } // end-while
+ } //end-if
+ } // end-while
+ } // end-while
+ } //end-while
+
+ // Phew, were done.
+ return predecessorTable;
+
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } catch (MalformedElementException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ public CollectionHandle[] getWorkspaceCollections() throws DAVException {
+
+ PropertyStatus propertyStatus = getProperty(DAV_WORKSPACE_COLLECTION_SET);
+
+ Vector v = new Vector(5);
+ Element element = propertyStatus.getProperty();
+
+ if (!ElementEditor.isDAVElement(element, "workspace-collection-set")) //$NON-NLS-1$
+ throw new DAVException(Policy.bind("exception.malformedElement")); //$NON-NLS-1$
+
+ Element child = ElementEditor.getFirstChild(element, "href"); //$NON-NLS-1$
+ while (child != null) {
+ String href = ElementEditor.getFirstText(child);
+ ILocator locator = davClient.getDAVFactory().newLocator(href);
+ v.addElement(new CollectionHandle(davClient, locator));
+ child = ElementEditor.getNextSibling(child);
+ }
+
+ CollectionHandle[] result = new CollectionHandle[v.size()];
+ v.copyInto(result);
+ return result;
+ }
+
+ /**
+ * Return the header from a message send to the server.
+ *
+ * @return a context with the message header contents
+ * @exception DAVException if there was a problem sending the message
+ * @see IServer#head(Locator, Context)
+ */
+ public IContext head() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.head(locator, newContext());
+ examineResponse(response);
+ return response.getContext();
+ } catch (IOException exception) {
+ throw new SystemException(exception);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Return a boolean value indicating whether or not this resource is a
+ * collection.
+ * <p>
+ * A resource is a collection (i.e., implements collection semantics) if
+ * it's resource type includes a <DAV:collection> element.</p>
+ *
+ * @return boolean <code>true</code> if the resource implements collection
+ * semantics, and <code>false</code> otherwise.
+ */
+ public boolean isCollection() throws DAVException {
+ return propertyHasChild(DAV_RESOURCE_TYPE, DAV_COLLECTION_RESOURCE_TYPE);
+ }
+
+ /**
+ * Return a boolean value indicating whether or not this resource
+ * is currently locked.
+ *
+ * @return boolean indicator
+ * @exception DAVException if there was a problem getting the locks
+ * @see #getLocks()
+ */
+ public boolean isLocked() throws DAVException {
+ // see if there are any active locks
+ return getLocks().hasMoreElements();
+ }
+
+ /**
+ * Lock this resource with default values.
+ *
+ * <p>Note: default values of DEPTH_ZERO for depth and -1 for timeout are used.</p>
+ *
+ * @return the lock token
+ * @exception DAVException if there was a problem locking this resource
+ * @see #lock(boolean, String, int, String)
+ */
+ public LockToken lock() throws DAVException {
+ return lock(false, IContext.DEPTH_ZERO, -1, null);
+ }
+
+ /**
+ * Lock this resource using the specified parameters.
+ *
+ * @param isShared true if the lock is shared, false if the lock is exclusive
+ * @param depth eg. <code>Context.DEPTH_ZERO</code>
+ * @param timeout the timeout value for the lock
+ * @param owner the owner of the lock
+ * @return the lock token
+ * @exception DAVException if there was a problem locking this resource
+ * @see IServer#lock(Locator, Context, Document)
+ */
+ public LockToken lock(boolean isShared, String depth, int timeout, String owner) throws DAVException {
+
+ // Define the request context.
+ IContext context = newContext();
+ context.setDepth(depth);
+ context.setTimeout(timeout);
+
+ // Create the request body.
+ Document document = newDocument();
+ LockInfo lockinfo = LockInfo.create(document);
+ lockinfo.setIsShared(isShared);
+
+ // Add the owner if it is given.
+ if (owner != null) {
+ Owner ownerEditor = lockinfo.setOwner();
+ ownerEditor.getElement().appendChild(document.createTextNode(owner));
+ }
+
+ // Send the lock request.
+ IResponse response = null;
+ try {
+ response = davClient.lock(locator, context, document);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+
+ // Extract the token from the resulting context.
+ LockToken token = new LockToken(response.getContext().getLockToken());
+ //fServerManager.addLock(newURL(fLocator.getResourceURL()), token, depth);
+ return token;
+ }
+
+ /**
+ * Move this resource to the destination specified by the given locator.
+ * Use default values for overwrite and properties to move.
+ *
+ * @param destination the location to move this resource to
+ * @exception DAVException if there was a problem moving this resource
+ * @see #move(Locator, boolean, Enumeration)
+ */
+ public void move(ILocator destination) throws DAVException {
+ move(destination, false, null);
+ }
+
+ /**
+ * Move this resource to the location specified by the given locator.
+ * If a resource already exists at the destination and the overwrite
+ * boolean is true, then write over top of the existing resource. Otherwise
+ * do not. The enumeration is over qualified names which are the names of
+ * the properties to move.
+ *
+ * @param destination the location to move to
+ * @param overwrite how to react if a resource already exists at the
+ * destination
+ * @param names <code>Enumeration</code> over <code>QualifiedNames</code>
+ * @exception DAVException if there was a problem moving this resource
+ * @see IServer#move(Locator, Locator, Context, Document)
+ */
+ public void move(ILocator destination, boolean overwrite, Enumeration names) throws DAVException {
+ IContext context = newContext();
+ context.setOverwrite(overwrite);
+
+ Document document = newDocument();
+ PropertyBehavior propertyBehavior = PropertyBehavior.create(document);
+
+ if (names == null) {
+ propertyBehavior.setIsKeepAllAlive(true);
+ } else {
+ while (names.hasMoreElements()) {
+ Object obj = names.nextElement();
+ Assert.isTrue(obj instanceof QualifiedName, Policy.bind("assert.propNameMustBeEnumOverQual")); //$NON-NLS-1$
+ // fix this...can we really add property names to href elements?
+ propertyBehavior.addProperty(((QualifiedName) obj).getLocalName());
+ }
+ }
+
+ IResponse response = null;
+ try {
+ response = davClient.move(locator, destination, context, document);
+ examineResponse(response);
+ examineMultiStatusResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Answer a new empty context for requests sent to the
+ * receivers server.
+ *
+ * @return a new request <code>Context</code>.
+ */
+ protected IContext newContext() {
+ return davClient.getDAVFactory().newContext();
+ }
+
+ /**
+ * Answer a new empty DOM Document suitable for creating requests
+ * to the receiver's server.
+ *
+ * @return a new DOM <code>Document</code>.
+ */
+ protected Document newDocument() {
+ return davClient.getDAVFactory().newDocument();
+ }
+
+ /**
+ * Check in the receiver and answer a new Locator on the
+ * resulting version resource.
+ *
+ * @return the <code>Locator</code> to the receiver's version.
+ * @throws DAVException if a problem occurs with the check in request.
+ */
+ protected ILocator protectedCheckIn() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.checkin(locator, newContext(), null);
+ examineResponse(response);
+ String versionUrl = response.getContext().getLocation();
+ return davClient.getDAVFactory().newStableLocator(versionUrl);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Check out the receiver and answer a new Locator on the
+ * resulting checked out resource. The result MAY be the same
+ * as the receiver's Locator if the server did not create
+ * a new resource as a consequence of the check out (i.e.
+ * if it was checking out a vesion-controlled resource rather
+ * than a version).
+ *
+ * @return the <code>Locator</code> to the receiver's version.
+ * @throws DAVException if a problem occurs with the check in request.
+ */
+ protected ILocator protectedCheckOut() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.checkout(locator, newContext(), null);
+ examineResponse(response);
+ String resourceUrl = response.getContext().getLocation();
+ return davClient.getDAVFactory().newStableLocator(resourceUrl);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Refresh the lock on this resource with the given lock token. Use
+ * the specified timeout value.
+ *
+ * @param lockToken the lock token to refresh
+ * @param timeout the new timeout value to use
+ * @exception DAVException if there was a problem refreshing the lock
+ */
+ public void refreshLock(LockToken lockToken, int timeout) throws DAVException {
+ // Set up the request in the context.
+ IContext context = newContext();
+ context.setTimeout(timeout);
+ context.setLockToken(lockToken.getToken());
+
+ // Send the request to the server.
+ IResponse response = null;
+ try {
+ response = davClient.lock(locator, context, null);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Remove the properties with the given names, from this resource.
+ *
+ * @param propertyNames <code>Enumeration</code> over
+ * <code>QualifiedNames</code>
+ * @exception DAVException if there was a problem removing the
+ * properties
+ * @see IServer#proppatch(Locator, Context, Document)
+ */
+ public void removeProperties(Collection propertyNames) throws DAVException {
+ Assert.isNotNull(propertyNames);
+
+ // Removing no properties is easy.
+ if (propertyNames.isEmpty())
+ return;
+
+ // Add the names of the properties to remove to the request body.
+ Document document = newDocument();
+ PropertyUpdate propertyUpdate = PropertyUpdate.create(document);
+ Prop prop = propertyUpdate.addRemove();
+ Iterator namesItr = propertyNames.iterator();
+ while (namesItr.hasNext())
+ prop.addPropertyName((QualifiedName) namesItr.next());
+
+ // Send the PROPPATCH request.
+ IResponse response = null;
+ try {
+ response = davClient.proppatch(locator, newContext(), document);
+ examineResponse(response);
+ examineMultiStatusResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Remove the property with the given name from this resource.
+ *
+ * @param propertyName the name of the property to remove
+ * @exception DAVException if there was a problem removing the property
+ * @see #removeProperties(Collection)
+ */
+ public void removeProperty(QualifiedName propertyName) throws DAVException {
+ Collection propertyNames = new Vector(1);
+ propertyNames.add(propertyName);
+ removeProperties(propertyNames);
+ }
+
+ /**
+ * Set the content of this resource to be the untyped data stored in the given
+ * input stream.
+ * The stream will automatically be closed after the data
+ * is consumed. If the resource does not exist it is created with the
+ * given content.
+ *
+ * @param input the inputstream containing the resource contents.
+ * @exception DAVException if there was a problem setting the contents.
+ * @see #setContent(String, InputStream)
+ * @see IServer#put(Locator, Context, InputStream)
+ */
+ public void setContent(InputStream input) throws DAVException {
+ setContent("application/octet-stream", input); //$NON-NLS-1$
+ }
+
+ /**
+ * Set the content of this resource to be the data stored in the given
+ * input stream. The type encoding is given in the content type argument, and
+ * should be in the media format described by RFC2616 Sec 3.7.
+ * The stream will automatically be closed after the data
+ * is consumed. If the resource does not exist it is created with the
+ * given content.
+ *
+ * @param contentType the media type for the data on the input stream.
+ * @param input the inputstream containing the resource contents.
+ * @exception DAVException if there was a problem setting the contents.
+ * @see IServer#put(Locator, Context, InputStream)
+ */
+ public void setContent(String contentType, InputStream input) throws DAVException {
+ IResponse response = null;
+ try {
+ IContext context = newContext();
+ context.setContentType(contentType);
+ response = davClient.put(locator, context, input);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Set the given properties on this resource.
+ *
+ * @param properties a <code>Collection</code> of property <code>Element</code>s.
+ * @exception DAVException if there was a problem setting the properties.
+ * @see IServer#proppatch(Locator, Context, Document)
+ */
+ public void setProperties(Collection properties) throws DAVException {
+ Assert.isNotNull(properties);
+
+ // Setting no properties is a no-op.
+ if (properties.isEmpty())
+ return;
+
+ // Build the request body to describe the properties to set.
+ Document document = newDocument();
+ PropertyUpdate propertyUpdate = PropertyUpdate.create(document);
+ Prop prop = propertyUpdate.addSet();
+
+ Iterator propertiesItr = properties.iterator();
+ while (propertiesItr.hasNext()) {
+ Element element = (Element) propertiesItr.next();
+ try {
+ prop.addProperty(element);
+ } catch (MalformedElementException exception) {
+ throw new SystemException(exception);
+ }
+ } // end-while
+
+ // Send the request to the server and examine the response for failures.
+ IResponse response = null;
+ try {
+ response = davClient.proppatch(locator, newContext(), document);
+ examineResponse(response);
+ examineMultiStatusResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Set the given property on this resource.
+ *
+ * @param property the property to set
+ * @exception DAVException if there was a problem setting the property
+ * @see #setProperties(Collection)
+ */
+ public void setProperty(Element property) throws DAVException {
+ Collection properties = new Vector(1);
+ properties.add(property);
+ setProperties(properties);
+ }
+
+ /**
+ * Return a string representation of this resource. Used for
+ * debugging purposes only.
+ *
+ * @return this resource, as a string
+ */
+ public String toString() {
+ return locator.getResourceURL();
+ }
+
+ /**
+ * Send a message to the server. The contents of the resulting
+ * input stream should be the message that was sent, echoed
+ * back to the client.
+ * <p>
+ * The input stream should be closed by the user.</p>
+ *
+ * @return an input stream on the request as received.
+ * @exception DAVException if there was a problem sending the
+ * request to the server.
+ * @see IServer#trace(Locator, Context)
+ */
+ public ResponseInputStream trace() throws DAVException {
+
+ IResponse response = null;
+ try {
+ response = davClient.trace(locator, newContext());
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } catch (DAVException e) {
+ closeResponse(response);
+ throw e;
+ }
+ return new ResponseInputStream(response);
+ }
+
+ /**
+ * Unlock this resource with the given lock token.
+ *
+ * @param token the lock token to remove from this resource
+ * @exception DAVException if there was a problem unlocking this resource
+ * @see IServer#unlock(Locator, Context)
+ */
+ public void unlock(LockToken token) throws DAVException {
+ // Send the lock token in the header of the request.
+ IContext context = newContext();
+ context.setLockToken("<" + token.getToken() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ IResponse response = null;
+ try {
+ response = davClient.unlock(locator, context);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Perform an UPDATE on the receiver to set the version it
+ * is based upon.
+ *
+ * @param version the <code>Locator</code> of the version that
+ * is the target of the update request.
+ * @throws DAVException if a problem occurs executing the update
+ * on the WebDAV server.
+ */
+ public void update(ILocator version) throws DAVException {
+ Document document = newDocument();
+ Update.createVersion(document, version.getResourceURL());
+
+ IResponse response = null;
+ try {
+ response = davClient.update(locator, newContext(), document);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Bring the receiver under version control. This means that
+ * the receiver is replaced by a version-controlled resource.
+ * Note that the client may send version control to a resource
+ * that is already under version control with no adverse effects.
+ *
+ * @throws DAVException if a problem occurs bringing the
+ * resource under version control.
+ */
+ public void versionControl() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.versionControl(locator, newContext(), null);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Delete this resource from the repository, optionally succeeding
+ * in the delete if the resource was not found on the server.
+ *
+ * @param mustExist if <code>true</code> then the delete will
+ * fail if the resource was not on the server at the time of the
+ * delete request. If <code>false</code> the delete will succeed if
+ * there was no such resource to delete.
+ * @exception DAVException if there was a problem deleting
+ * this resource.
+ * @see IServer#delete(Locator, Context)
+ */
+ public void delete(boolean mustExist) throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.delete(locator, newContext());
+ if (!mustExist && (response.getStatusCode() == IResponse.SC_NOT_FOUND))
+ return;
+ examineResponse(response);
+ examineMultiStatusResponse(response);
+ } catch (IOException exception) {
+ throw new SystemException(exception);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Check the given status code and throw a WebDAV
+ * exception if the code indicates failure. If the code
+ * is success, this method does nothing.
+ *
+ * @param code the status code to check.
+ * @param message the status message accompanying the code.
+ * @exception WebDAVException if the server returned an HTTP/WebDAV
+ * error code (i.e., anything outside the 200-series codes).
+ */
+ protected void examineStatusCode(int code, String message) throws WebDAVException {
+ if (code >= 300 && code <= 399)
+ throw new RedirectionException(code, message);
+ if (code >= 400 && code <= 499)
+ throw new ClientException(code, message);
+ if (code >= 500 && code <= 599)
+ throw new ServerException(code, message);
+ }
+
+ /**
+ * Return a boolean value indicating whether or not this resource
+ * exists on the server.
+ * <p>
+ * This implementation uses the HTTP HEAD method so the URL may or
+ * may not exist in the DAV namespace. The DAV RESOURCE_TYPE property
+ * is NOT checked.</p>
+ *
+ * @return boolean <code>true</code> if the resource exists on the server
+ * or <code>false</code> otherwise.
+ * @exception DAVException if there was a problem checking for
+ * existence.
+ */
+ public boolean exists() throws DAVException {
+
+ // Test existance by issuing a HEAD request.
+ IResponse response = null;
+ try {
+ response = davClient.head(locator, newContext());
+ // If the resource was not found, then that answers the question.
+ if (response.getStatusCode() == IResponse.SC_NOT_FOUND)
+ return false;
+
+ // Otherwise check for errors.
+ examineResponse(response);
+
+ // No problems by this point, so the resource is there and OK.
+ return true;
+ } catch (IOException exception) {
+ throw new SystemException(exception);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Check to see if the resource is checked in (i.e., is an immutable
+ * resource).
+ * <p>
+ * The resource is checked in if it has a <DAV:checked-in>
+ * property.</p>
+ *
+ * @return <code>true</code> if the resource is checked in
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isCheckedIn() throws DAVException {
+ return supportsLiveProperty(DAV_CHECKED_IN);
+ }
+
+ /**
+ * Check to see if the resource is checked-out.
+ * <p>
+ * The resource is checked out if it has a <DAV:checked-out>
+ * property.</p>
+ *
+ * @return <code>true</code> if the resource is checked out
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isCheckedOut() throws DAVException {
+ return supportsLiveProperty(DAV_CHECKED_OUT);
+ }
+
+ /**
+ * Check to see if the resource is a version.
+ * <p>
+ * The resource is a version if it has <DAV:version-name>
+ * in the <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a version
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isVersion() throws DAVException {
+ return supportsLiveProperty(DAV_VERSION_NAME);
+ }
+
+ /**
+ * Check to see if the resource is under version control.
+ * <p>
+ * The resource is version controlled if it has <DAV:auto-checkout>
+ * in the <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is under version
+ * control and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isVersionControlled() throws DAVException {
+ return supportsLiveProperty(DAV_AUTO_CHECKOUT);
+ }
+
+ /**
+ * Check to see if the resource is a working resource.
+ * <p>
+ * The resource is a working resource if it has
+ * <DAV:checked-out> and does not have <DAV:auto-checkout>
+ * in the <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a working resource
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isWorkingResource() throws DAVException {
+ PropertyStatus propertyStat = getProperty(DAV_SUPPORTED_LIVE_PROPERTY_SET);
+ // If the live-property-set is not supported, then the answer is 'no'.
+ if (propertyStat.getStatusCode() == IResponse.SC_NOT_FOUND)
+ return false;
+ // If there was a problem getting the live property set, throw an exception.
+ examineStatusCode(propertyStat.getStatusCode(), propertyStat.getStatusMessage());
+ // Check to see if the required properties are/are not in the supported set.
+ try {
+ Element propertySet = propertyStat.getProperty();
+ return ((ElementEditor.hasChild(propertySet, DAV_CHECKED_OUT)) && !(ElementEditor.hasChild(propertySet, DAV_AUTO_CHECKOUT)));
+ } catch (MalformedElementException exception) {
+ throw new SystemException(exception);
+ }
+ }
+
+ /**
+ * This is a helper method to check to see if the resource has a
+ * property with the given name that in turn has a child with a
+ * given name.
+ *
+ * @return <code>true</code> if the resource does have such a
+ * property with a named child and <code>false</code> if it does
+ * not have such a property or does not have such a child of the
+ * property.
+ * @throws DAVException if a problem occurs determining result
+ * from the server.
+ */
+ protected boolean propertyHasChild(QualifiedName propertyName, QualifiedName childName) throws DAVException {
+ // If the property is not found, then the answer is 'no'.
+ PropertyStatus propertyStat = getProperty(propertyName);
+ if (propertyStat.getStatusCode() == IResponse.SC_NOT_FOUND)
+ return false;
+ // If there was a problem getting the property, throw an exception.
+ examineStatusCode(propertyStat.getStatusCode(), propertyStat.getStatusMessage());
+ // Check to see if the named child is in the retrieved property.
+ try {
+ return ElementEditor.hasChild(propertyStat.getProperty(), childName);
+ } catch (MalformedElementException exception) {
+ throw new SystemException(exception);
+ }
+ }
+
+ /**
+ * Check to see if the resource supports the named live property.
+ *
+ * @return <code>true</code> if the resource does support the live
+ * property and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining result
+ * from the server.
+ */
+ public boolean supportsLiveProperty(QualifiedName propertyName) throws DAVException {
+ return propertyHasChild(DAV_SUPPORTED_LIVE_PROPERTY_SET, propertyName);
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/AbstractResourceHandle.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/CollectionHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/CollectionHandle.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/CollectionHandle.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,340 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+import org.eclipse.webdav.*;
+import org.eclipse.webdav.dom.ElementEditor;
+import org.eclipse.webdav.dom.MalformedElementException;
+import org.eclipse.webdav.internal.kernel.*;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The <code>CollectionHandle</code> class represents a resource on the
+ * WebDAV server that supports collection semantics.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class CollectionHandle extends AbstractResourceHandle {
+
+ /**
+ * Creates a new <code>CollectionHandle</code> from the given
+ * <code>DAVClient</code> and <code>Locator</code>.
+ * <p>
+ * A CollectionHandle is a resource handle for DAV resources
+ * with internal members.</p>
+ *
+ * @param davClient the client used to access the WebDAV server.
+ * @param locator the reference to the collection resource on the
+ * server.
+ */
+ public CollectionHandle(DAVClient davClient, ILocator locator) {
+ super(davClient, locator);
+ }
+
+ /**
+ * Bring the receiver under baseline control.
+ *
+ * @throws DAVException if the baseline control operation failed.
+ * @see IServer#baselineControl(Locator, Context, Document)
+ */
+ public void baselineControl() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.baselineControl(locator, newContext(), null);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Create a new version-controlled configuration on the given baseline.
+ *
+ * @throws DAVException if the baseline control operation failed.
+ * @see IServer#baselineControl(Locator, Context, Document)
+ */
+ public void baselineControl(ILocator baseline) throws DAVException {
+ Assert.isNotNull(baseline);
+
+ // Build the document body to describe the baseline control element.
+ Document document = newDocument();
+ Element root = ElementEditor.create(document, "baseline-control"); //$NON-NLS-1$
+ ElementEditor.addChild(root, "baseline", //$NON-NLS-1$
+ baseline.getResourceURL(), new String[] {"baseline"}, //$NON-NLS-1$
+ true);
+
+ // Send the baseline control method to the server and check the response.
+ IResponse response = null;
+ try {
+ response = davClient.baselineControl(locator, newContext(), document);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Binds the given member in this collection to the resource identified
+ * by the given source locator. If the member already exists, or is
+ * already bound to a resource, it is not replaced.
+ *
+ * @param member a member in this collection
+ * @param source the location of a resource
+ * @throws DAVException if the binding could not be created
+ * @see #bind(String, Locator, boolean)
+ * @see IServer#bind(Locator, Locator, Context)
+ */
+ public void bind(String member, ILocator source) throws DAVException {
+ bind(member, source, false);
+ }
+
+ /**
+ * Binds the given member in this collection to the resource identified
+ * by the given source locator. If overwrite is <code>false</code> and
+ * such a member already exists, or such a member is already bound to a
+ * resource, it is not replaced. Otherwise, if overwrite is
+ * <code>true</code> and such a member already exists, or such a member
+ * is already bound to a resource, it is replaced.
+ *
+ * @param member a member in this collection
+ * @param source the location of a resource
+ * @param overwrite a boolean indicating whether or not any existing
+ * resource or binding is replaced
+ * @throws DAVException if the binding could not be created
+ * @see #bind(String, Locator, boolean)
+ * @see IServer#bind(Locator, Locator, Context)
+ */
+ public void bind(String member, ILocator source, boolean overwrite) throws DAVException {
+ IContext context = newContext();
+ context.setOverwrite(overwrite);
+ ILocator destination = getMember(member);
+
+ IResponse response = null;
+ try {
+ response = davClient.bind(source, destination, context);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Check out this resource. Returns a resource handle on the checked out
+ * version selector, or the working resource if a version is checked out.
+ * <p>
+ * Note that a checked-out version-controlled collection has members that are
+ * themselves version-controlled resources, or unversioned resources; however,
+ * working collection members are always version history resources.</p>
+ *
+ * @return the checked out resource as a <code>CollectionHandle</code>.
+ * @throws DAVException if there is a problem checking out the receiver.
+ */
+ public AbstractResourceHandle checkOut() throws DAVException {
+ ILocator locator = protectedCheckOut();
+ return new CollectionHandle(davClient, locator);
+ }
+
+ /**
+ * Create this collection in the repository.
+ * <p>
+ * This corresponds to a WebDAV MKCOL method.</p>
+ *
+ * @exception DAVException if there was a problem creating this collection
+ * @see IServer#mkcol(ILocator, IContext, IElement)
+ */
+ public void create() throws DAVException {
+ IResponse response = null;
+ try {
+ response = davClient.mkcol(locator, newContext(), null);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Create the receiver and any parent collections that must be created
+ * on the path to the receiver.
+ *
+ * @throws DAVException if there is a problem creating the collections.
+ */
+ public void mkdirs() throws DAVException {
+ mkdirs(this);
+ }
+
+ protected void mkdirs(CollectionHandle handle) throws DAVException {
+ IResponse response = null;
+ try {
+ // Attempt to create the collection.
+ response = davClient.mkcol(handle.locator, newContext(), null);
+
+ int status = response.getStatusCode();
+ if (status == IResponse.SC_METHOD_NOT_ALLOWED) {
+ // A resource already exists at this location.
+ // Check that it is a collection resource (otherwise fall through to examine response)
+ if (handle.isCollection())
+ return;
+ }
+
+ if (status == IResponse.SC_FORBIDDEN) {
+ // if this is a collection and exists return
+ if (handle.isCollection() && handle.exists())
+ return;
+ }
+
+ if (status == IResponse.SC_CONFLICT) {
+ // close the response and try to create the parents
+ closeResponse(response);
+ // Intermediate collections are missing.
+ CollectionHandle parent = handle.getParent();
+ mkdirs(parent);
+ // re-attempt to create the folder after the parents have been created
+ response = davClient.mkcol(handle.locator, newContext(), null);
+ }
+ // We got some other response code, so check for failures.
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+
+ /**
+ * Answer the given member of the receiver as a collection handle.
+ *
+ * @throws DAVException if there is a problem creating the new handle.
+ */
+ public CollectionHandle getCollectionHandle(String name) throws DAVException {
+ return new CollectionHandle(davClient, getMember(name));
+ }
+
+ /**
+ * Return the locator of the member of this collection, with the given
+ * name. Does NOT perform a call to the server to check the existence
+ * of the member.
+ *
+ * @param memberName the name of the receiver's internal member.
+ * @return the Locator for the member.
+ */
+ public ILocator getMember(String memberName) {
+ Assert.isTrue(locator.getLabel() == null);
+ Assert.isTrue(!locator.isStable());
+ String parentName = locator.getResourceURL();
+ String childName;
+ if (parentName.endsWith("/")) //$NON-NLS-1$
+ childName = parentName + memberName;
+ else
+ childName = parentName + "/" + memberName; //$NON-NLS-1$
+ return davClient.getDAVFactory().newLocator(childName);
+ }
+
+ /**
+ * Return a set of handles representing the members of this
+ * collection.
+ * <p>
+ * Each member of the set will be typed to be a <code>ResourceHandle</code>
+ * or a <code>CollectionHandle</code> depending upon whether it implements
+ * collection semantics. Note that workspaces will be returned as
+ * regular collection handles and should be converted to workspace handles
+ * if required (test using isWorkspace()).</p>
+ *
+ * @return a <code>Set</code> of <code>ResourceHandle</code> and/or <code>
+ * CollectionHandle</code> or an empty set if the receiver has no members.
+ * @exception DAVException if there was a problem getting the members.
+ */
+ public Set getMembers() throws DAVException {
+
+ // Query the DAV:resource-type property to depth one.
+ Collection querySet = new Vector();
+ querySet.add(DAV_RESOURCE_TYPE);
+ URLTable resourceTable = getProperties(querySet, IContext.DEPTH_ONE);
+
+ // Create a collection for the reply, and remove
+ // ourselves from the answer.
+ Set reply = new HashSet();
+ try {
+ resourceTable.remove(locator.getResourceURL());
+ } catch (MalformedURLException exception) {
+ throw new DAVException(Policy.bind("exception.malformedLocator")); //$NON-NLS-1$
+ }
+
+ // The keys of the result correspond to the receiver's internal members.
+ Enumeration resourceNameEnum = resourceTable.keys();
+ while (resourceNameEnum.hasMoreElements()) {
+ URL url = (URL) resourceNameEnum.nextElement();
+
+ // Get the props for that resource
+ Hashtable propertyTable = (Hashtable) resourceTable.get(url);
+ Assert.isNotNull(propertyTable);
+ PropertyStatus propertyStatus = (PropertyStatus) propertyTable.get(DAV_RESOURCE_TYPE);
+ Assert.isNotNull(propertyStatus);
+
+ // If we have a DAV:collection element, then create a collection handle,
+ // all other resource types are created as regular resource handles.
+ ILocator newLocator = davClient.getDAVFactory().newLocator(url.toString());
+ Element property = propertyStatus.getProperty();
+ try {
+ if (ElementEditor.hasChild(property, DAV_COLLECTION_RESOURCE_TYPE))
+ reply.add(new CollectionHandle(davClient, newLocator));
+ else
+ reply.add(new ResourceHandle(davClient, newLocator));
+ } catch (MalformedElementException exception) {
+ throw new SystemException(exception);
+ }
+ } // end-while
+
+ return reply;
+ }
+
+ public ResourceHandle getResourceHandle(String name) throws DAVException {
+ return new ResourceHandle(davClient, getMember(name));
+ }
+
+ public WorkspaceHandle getWorkspaceHandle(String name) throws DAVException {
+ return new WorkspaceHandle(davClient, getMember(name));
+ }
+
+ /**
+ * Check to see if the receiver is a workspace resource.
+ * <p>
+ * The resource is a workspace resource if it has
+ * <DAV:workspace-checkout-set> in the
+ * <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a workspace
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isWorkspace() throws DAVException {
+ return supportsLiveProperty(DAV_WORKSPACE_CHECKOUT_SET);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/CollectionHandle.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/DAVClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/DAVClient.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/DAVClient.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.net.MalformedURLException;
+import org.eclipse.webdav.*;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * <code>Dav Client</code>s implement the <code>IServer</code> interface
+ * and represent a client's connection to a server.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public abstract class DAVClient implements IServer {
+
+ protected WebDAVFactory davFactory = null;
+
+ /**
+ * Creates a new DAV client from a clone of the given DAV client.
+ *
+ * @param davClient the DAV client to clone
+ */
+ public DAVClient(DAVClient davClient) {
+ davFactory = davClient.davFactory;
+ }
+
+ /**
+ * Creates a new DAV client.
+ *
+ * @param davFactory
+ */
+ public DAVClient(WebDAVFactory davFactory) {
+ Assert.isNotNull(davFactory);
+ this.davFactory = davFactory;
+ }
+
+ /**
+ * @see Object#clone()
+ */
+ protected abstract Object clone();
+
+ public WebDAVFactory getDAVFactory() {
+ return davFactory;
+ }
+
+ /**
+ * Returns a new context that is based on the given context.
+ *
+ * @param userContext
+ * @param locator
+ *
+ * @return a new context that is based on the given context
+ */
+ protected IContext newContext(IContext userContext, ILocator locator) throws MalformedURLException {
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(locator);
+ IContext context = davFactory.newContext(userContext);
+ if (locator.getLabel() != null)
+ context.setLabel(locator.getLabel());
+ return context;
+ }
+
+ /**
+ * Shut down the client for future use, and release any system resources associated with the
+ * instance. Callers should not expect the client to succeed with further API calls once the
+ * client has been closed.
+ */
+ public void close() {
+ // Default is to do nothing.
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/DAVClient.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/LocalDAVClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/LocalDAVClient.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/LocalDAVClient.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,238 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.eclipse.webdav.*;
+import org.w3c.dom.Document;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public class LocalDAVClient extends DAVClient {
+
+ private IServer server;
+
+ /**
+ * Creates a new local DAV client from a clone of the given local DAV
+ * client.
+ *
+ * @param localDAVClient the local DAV client to clone
+ */
+ public LocalDAVClient(LocalDAVClient localDAVClient) {
+ super(localDAVClient);
+ server = localDAVClient.server;
+ }
+
+ /**
+ * Creates a new local DAV client that talks to the server at the
+ * specified origin. The origin server <code>URL</code> and the server
+ * must not be <code>null</code>.
+ */
+ public LocalDAVClient(WebDAVFactory webDAVFactory, IServer server) {
+ super(webDAVFactory);
+ this.server = server;
+ }
+
+ /**
+ * @see IServer#baselineControl(ILocator, IContext, Document)
+ */
+ public IResponse baselineControl(ILocator locator, IContext context, Document body) throws IOException {
+ return server.baselineControl(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#bind(ILocator, ILocator, IContext)
+ */
+ public IResponse bind(ILocator source, ILocator destination, IContext context) throws IOException {
+ return server.bind(source, destination, newContext(context, source));
+ }
+
+ /**
+ * @see IServer#checkin(ILocator, IContext, Document)
+ */
+ public IResponse checkin(ILocator locator, IContext context, Document body) throws IOException {
+ return server.checkin(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#checkout(ILocator, IContext, Document)
+ */
+ public IResponse checkout(ILocator locator, IContext context, Document body) throws IOException {
+ return server.checkout(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see Object#clone()
+ */
+ protected Object clone() {
+ return new LocalDAVClient(this);
+ }
+
+ /**
+ * @see IServer#copy(ILocator, ILocator, IContext, Document)
+ */
+ public IResponse copy(ILocator source, ILocator destination, IContext context, Document body) throws IOException {
+ return server.copy(source, destination, newContext(context, source), body);
+ }
+
+ /**
+ * @see IServer#delete(ILocator, IContext)
+ */
+ public IResponse delete(ILocator locator, IContext context) throws IOException {
+ return server.delete(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#get(ILocator, IContext)
+ */
+ public IResponse get(ILocator locator, IContext context) throws IOException {
+ return server.get(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#head(ILocator, IContext)
+ */
+ public IResponse head(ILocator locator, IContext context) throws IOException {
+ return server.head(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#label(ILocator, IContext, Document)
+ */
+ public IResponse label(ILocator locator, IContext context, Document body) throws IOException {
+ return server.label(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#lock(ILocator, IContext, Document)
+ */
+ public IResponse lock(ILocator locator, IContext context, Document body) throws IOException {
+ return server.lock(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#merge(ILocator, IContext, Document)
+ */
+ public IResponse merge(ILocator locator, IContext context, Document body) throws IOException {
+ return server.merge(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#mkactivity(ILocator, IContext, Document)
+ */
+ public IResponse mkactivity(ILocator locator, IContext context, Document body) throws IOException {
+ return server.mkactivity(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#mkcol(ILocator, IContext, Document)
+ */
+ public IResponse mkcol(ILocator locator, IContext context, Document element) throws IOException {
+ return server.mkcol(locator, newContext(context, locator), element);
+ }
+
+ /**
+ * @see IServer#mkworkspace(ILocator, IContext, Document)
+ */
+ public IResponse mkworkspace(ILocator locator, IContext context, Document body) throws IOException {
+ return server.mkworkspace(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#move(ILocator, ILocator, IContext, Document)
+ */
+ public IResponse move(ILocator source, ILocator destination, IContext context, Document body) throws IOException {
+ return server.move(source, destination, newContext(context, source), body);
+ }
+
+ /**
+ * @see IServer#options(ILocator, IContext)
+ */
+ public IResponse options(ILocator locator, IContext context) throws IOException {
+ return server.options(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#post(ILocator, IContext, InputStream)
+ */
+ public IResponse post(ILocator locator, IContext context, InputStream input) throws IOException {
+ return server.post(locator, newContext(context, locator), input);
+ }
+
+ /**
+ * @see IServer#propfind(ILocator, IContext, Document)
+ */
+ public IResponse propfind(ILocator locator, IContext context, Document body) throws IOException {
+ return server.propfind(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#proppatch(ILocator, IContext, Document)
+ */
+ public IResponse proppatch(ILocator locator, IContext context, Document body) throws IOException {
+ return server.proppatch(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#put(ILocator, IContext, InputStream)
+ */
+ public IResponse put(ILocator locator, IContext context, InputStream input) throws IOException {
+ return server.put(locator, newContext(context, locator), input);
+ }
+
+ /**
+ * @see IServer#report(ILocator, IContext, Document)
+ */
+ public IResponse report(ILocator locator, IContext context, Document body) throws IOException {
+ return server.report(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#trace(ILocator, IContext)
+ */
+ public IResponse trace(ILocator locator, IContext context) throws IOException {
+ return server.trace(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#uncheckout(ILocator, IContext)
+ */
+ public IResponse uncheckout(ILocator locator, IContext context) throws IOException {
+ return server.uncheckout(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#unlock(ILocator, IContext)
+ */
+ public IResponse unlock(ILocator locator, IContext context) throws IOException {
+ return server.unlock(locator, newContext(context, locator));
+ }
+
+ /**
+ * @see IServer#update(ILocator, IContext, Document)
+ */
+ public IResponse update(ILocator locator, IContext context, Document body) throws IOException {
+ return server.update(locator, newContext(context, locator), body);
+ }
+
+ /**
+ * @see IServer#versionControl(ILocator, IContext, Document)
+ */
+ public IResponse versionControl(ILocator locator, IContext context, Document body) throws IOException {
+ return server.versionControl(locator, newContext(context, locator), body);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/LocalDAVClient.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/Policy.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/Policy.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/Policy.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.text.MessageFormat;
+import java.util.*;
+
+public class Policy {
+ private static String bundleName = "org.eclipse.webdav.client.messages"; //$NON-NLS-1$
+ private static ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+
+ /**
+ * Lookup the message with the given ID in this catalog
+ */
+ public static String bind(String id) {
+ return bind(id, (String[]) null);
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string.
+ */
+ public static String bind(String id, String binding) {
+ return bind(id, new String[] {binding});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given strings.
+ */
+ public static String bind(String id, String binding1, String binding2) {
+ return bind(id, new String[] {binding1, binding2});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string values.
+ */
+ public static String bind(String id, String[] bindings) {
+ if (id == null)
+ return "No message available";//$NON-NLS-1$
+ String message = null;
+ try {
+ message = bundle.getString(id);
+ } catch (MissingResourceException e) {
+ // If we got an exception looking for the message, fail gracefully by just returning
+ // the id we were looking for. In most cases this is semi-informative so is not too bad.
+ return "Missing message: " + id + "in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (bindings == null)
+ return message;
+ return MessageFormat.format(message, bindings);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/Policy.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/PropertyStatus.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/PropertyStatus.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/PropertyStatus.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import org.eclipse.webdav.dom.*;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.w3c.dom.Element;
+
+/**
+ * A <code>PropertyStatus</code> holds the WebDAV server's response from
+ * a client's request to retrieve a particular property.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class PropertyStatus {
+ private Element property;
+ private int statusCode;
+ private String statusMessage;
+
+ /**
+ * Create a new property status from the given property and the
+ * specified status.
+ *
+ * @param property the requested property
+ * @param statusCode the resulting status code
+ * @param statusMessage the resulting status message
+ */
+ public PropertyStatus(Element property, int statusCode, String statusMessage) {
+ Assert.isNotNull(property);
+ Assert.isNotNull(statusMessage);
+ this.property = property;
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
+ }
+
+ /**
+ * Return the requested property as an <code>Element</code>. The
+ * element will not have any children if the property could not be
+ * retrieved as indicated by the status.
+ */
+ public Element getProperty() {
+ return property;
+ }
+
+ /**
+ * Return the requested property's name.
+ */
+ public QualifiedName getPropertyName() throws MalformedElementException {
+ return ElementEditor.getQualifiedName(property);
+ }
+
+ /**
+ * Return the status code that resulted from retrieving (or attempting
+ * to retrieve) this property status' property.
+ */
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * Return the status message that resulted from retrieving (or
+ * attempting to retrieve) this property status' property.
+ */
+ public String getStatusMessage() {
+ return statusMessage;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/PropertyStatus.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RemoteDAVClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RemoteDAVClient.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RemoteDAVClient.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,395 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.eclipse.webdav.*;
+import org.eclipse.webdav.http.client.HttpClient;
+import org.eclipse.webdav.http.client.Request;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.eclipse.webdav.internal.utils.URLEncoder;
+import org.w3c.dom.Document;
+
+/**
+ * The <code>ServerProxy</code> class implements the <code>IServer</code>
+ * interface and represents a client's local proxy to a remote server.
+ * This object is used to talk with the server.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class RemoteDAVClient extends DAVClient {
+
+ protected HttpClient httpClient = null;
+
+ /**
+ * Creates a new remote DAV client from a clone of the given remote
+ * DAV client.
+ *
+ * @param davClient the DAV client to clone
+ */
+ public RemoteDAVClient(RemoteDAVClient davClient) {
+ super(davClient);
+ }
+
+ /**
+ * Creates a new remote DAV client.
+ *
+ * @param webDAVFactory
+ */
+ public RemoteDAVClient(WebDAVFactory webDAVFactory, HttpClient httpClient) {
+ super(webDAVFactory);
+ this.httpClient = httpClient;
+ }
+
+ /**
+ * @see IServer#baselineControl(ILocator, IContext, Document)
+ */
+ public IResponse baselineControl(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "BASELINE-CONTROL"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#bind(ILocator, ILocator, IContext)
+ */
+ public IResponse bind(ILocator source, ILocator destination, IContext userContext) throws IOException {
+ Assert.isNotNull(source);
+ Assert.isNotNull(destination);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, source);
+ context.setDestination(URLEncoder.encode(destination.getResourceURL()));
+ Request request = newRequest(source, context, "BIND"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#checkin(ILocator, IContext, Document)
+ */
+ public IResponse checkin(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "CHECKIN"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#checkout(ILocator, IContext, Document)
+ */
+ public IResponse checkout(ILocator locator, IContext userContext, Document body) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, body, "CHECKOUT"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see Object#clone()
+ */
+ protected Object clone() {
+ return new RemoteDAVClient(this);
+ }
+
+ /**
+ * Close down the client for futire API calls. Once a client has been clsed then callers
+ * should not expect further API cals to be sucessful.
+ */
+ public void close() {
+ httpClient.close();
+ super.close();
+ }
+
+ /**
+ * @see IServer#copy(ILocator, ILocator, IContext, Document)
+ */
+ public IResponse copy(ILocator source, ILocator destination, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(source);
+ Assert.isNotNull(destination);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, source);
+ context.setDestination(URLEncoder.encode(destination.getResourceURL()));
+ Request request = newRequest(source, context, document, "COPY"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#delete(ILocator, IContext)
+ */
+ public IResponse delete(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "DELETE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#get(ILocator, IContext)
+ */
+ public IResponse get(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "GET"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * Returns this DAV clients HTTP client.
+ */
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ /**
+ * @see IServer#head(ILocator, IContext)
+ */
+ public IResponse head(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "HEAD"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#label(ILocator, IContext, Document)
+ */
+ public IResponse label(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(document);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "LABEL"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#lock(ILocator, IContext, Document)
+ */
+ public IResponse lock(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "LOCK"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#merge(ILocator, IContext, Document)
+ */
+ public IResponse merge(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(document);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "MERGE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#mkactivity(ILocator, IContext, Document)
+ */
+ public IResponse mkactivity(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "MKACTIVITY"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#mkcol(ILocator, IContext, Document)
+ */
+ public IResponse mkcol(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "MKCOL"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#mkworkspace(ILocator, IContext, Document)
+ */
+ public IResponse mkworkspace(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "MKWORKSPACE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#move(ILocator, ILocator, IContext, Document)
+ */
+ public IResponse move(ILocator source, ILocator destination, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(source);
+ Assert.isNotNull(destination);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, source);
+ context.setDestination(URLEncoder.encode(destination.getResourceURL()));
+ Request request = newRequest(source, context, document, "MOVE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ private Request newRequest(ILocator locator, IContext context, InputStream is, String methodName) throws IOException {
+ return new Request(methodName, URLEncoder.encode(new URL(locator.getResourceURL())), context, is);
+ }
+
+ private Request newRequest(ILocator locator, IContext context, String methodName) throws IOException {
+ return new Request(methodName, URLEncoder.encode(new URL(locator.getResourceURL())), context);
+ }
+
+ private Request newRequest(ILocator locator, IContext context, Document document, String methodName) throws IOException {
+ context.setContentType("text/xml; charset=\"UTF8\""); //$NON-NLS-1$
+ if (document == null)
+ return new Request(methodName, URLEncoder.encode(new URL(locator.getResourceURL())), context);
+ RequestBodyWriter writer = new RequestBodyWriter(document, "UTF8"); //$NON-NLS-1$
+ return new Request(methodName, URLEncoder.encode(new URL(locator.getResourceURL())), context, writer);
+ }
+
+ /**
+ * @see IServer#options(ILocator, IContext)
+ */
+ public IResponse options(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "OPTIONS"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#post(ILocator, IContext, InputStream)
+ */
+ public IResponse post(ILocator locator, IContext userContext, InputStream is) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(is);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, is, "POST"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#propfind(ILocator, IContext, Document)
+ */
+ public IResponse propfind(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "PROPFIND"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#proppatch(ILocator, IContext, Document)
+ */
+ public IResponse proppatch(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(document);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "PROPPATCH"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#put(ILocator, IContext, InputStream)
+ */
+ public IResponse put(ILocator locator, IContext userContext, InputStream is) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(is);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, is, "PUT"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#report(ILocator, IContext, Document)
+ */
+ public IResponse report(ILocator locator, IContext userContext, Document document) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ Assert.isNotNull(document);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, document, "REPORT"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#trace(ILocator, IContext)
+ */
+ public IResponse trace(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "TRACE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#uncheckout(ILocator, IContext)
+ */
+ public IResponse uncheckout(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "UNCHECKOUT"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#unlock(ILocator, IContext)
+ */
+ public IResponse unlock(ILocator locator, IContext userContext) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, "UNLOCK"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#update(ILocator, IContext, Document)
+ */
+ public IResponse update(ILocator locator, IContext userContext, Document body) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, body, "UPDATE"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+
+ /**
+ * @see IServer#versionControl(ILocator, IContext, Document)
+ */
+ public IResponse versionControl(ILocator locator, IContext userContext, Document body) throws IOException {
+ Assert.isNotNull(locator);
+ Assert.isNotNull(userContext);
+ IContext context = newContext(userContext, locator);
+ Request request = newRequest(locator, context, body, "VERSION-CONTROL"); //$NON-NLS-1$
+ return httpClient.invoke(request);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RemoteDAVClient.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RequestBodyWriter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RequestBodyWriter.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RequestBodyWriter.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.*;
+import org.eclipse.webdav.http.client.IRequestBodyWriter;
+import org.eclipse.webdav.internal.kernel.DocumentMarshaler;
+import org.eclipse.webdav.internal.kernel.IDocumentMarshaler;
+import org.w3c.dom.Document;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public class RequestBodyWriter implements IRequestBodyWriter {
+
+ private Document body;
+ private String characterEncoding;
+
+ public RequestBodyWriter(Document document, String characterEncoding) {
+ body = document;
+ this.characterEncoding = characterEncoding;
+ }
+
+ public void writeRequestBody(OutputStream os) throws IOException {
+ IDocumentMarshaler marshaler = new DocumentMarshaler();
+ OutputStreamWriter writer = new OutputStreamWriter(os, characterEncoding);
+ marshaler.print(body, writer, "utf-8"); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/RequestBodyWriter.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResourceHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResourceHandle.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResourceHandle.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import org.eclipse.webdav.ILocator;
+import org.eclipse.webdav.internal.kernel.*;
+
+/**
+ * The <code>ResourceHandle</code> class represents an
+ * ordinary resource in the system. It subclasses <code>AbstractResourceHandle</code>
+ * and overrides some of its methods in order to provide specific behaviour for
+ * this resource type.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class ResourceHandle extends AbstractResourceHandle {
+
+ /**
+ * Creates a new <code>ResourceHandle</code> from the given
+ * <code>DAVClient</code> and <code>Locator</code>.
+ *
+ * @param davClient
+ * @param locator
+ */
+ public ResourceHandle(DAVClient davClient, ILocator locator) {
+ super(davClient, locator);
+ }
+
+ /**
+ * Check out this resource. Returns a resource handle on the checked out
+ * version selector, or the working resource if a version is checked out.
+ */
+ public AbstractResourceHandle checkOut() throws DAVException {
+ ILocator locator = protectedCheckOut();
+ return new ResourceHandle(davClient, locator);
+ }
+
+ /**
+ * Persistently create this resource instance in the repository.
+ * <p>
+ * Note that the usual method for creating an instance of a non-collection
+ * resource would be setContent(InputStream).
+ *
+ * @exception DAVException if there was a problem creating this resource
+ * @see AbstractResourceHandle#setContent(InputStream)
+ */
+ public void create() throws DAVException {
+ setContent(new ByteArrayInputStream(new byte[0]));
+ }
+
+ /**
+ * Check to see if the resource is an activity resource.
+ * <p>
+ * The resource is an activity resource if it has
+ * <DAV:subactivity-set> in the
+ * <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is an activity
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isActivity() throws DAVException {
+ return supportsLiveProperty(DAV_SUBACTIVITY_SET);
+ }
+
+ /**
+ * Check to see if the resource is a baseline resource.
+ * <p>
+ * The resource is a baseline resource if it has
+ * <DAV:baseline-collection> in the
+ * <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a baseline
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isBaseline() throws DAVException {
+ return supportsLiveProperty(DAV_BASELINE_COLLECTION);
+ }
+
+ /**
+ * Check to see if the resource is a version-controlled configuration
+ * resource.
+ * <p>
+ * The resource is a version-controlled configuration resource if it has
+ * <DAV:baseline-controlled-collection> in the
+ * <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a version-controlled
+ * configuration and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isVersionControlledConfiguration() throws DAVException {
+ return supportsLiveProperty(DAV_BASELINE_CONTROLLED_COLLECTION);
+ }
+
+ /**
+ * Check to see if the resource is a version history resource.
+ * <p>
+ * The resource is a version history resource if it has
+ * <DAV:root-version> in the
+ * <DAV:supported-live-properties-set>.</p>
+ *
+ * @return <code>true</code> if the resource is a version history
+ * and <code>false</code> otherwise.
+ * @throws DAVException if a problem occurs determining the state
+ * of the resource.
+ */
+ public boolean isVersionHistory() throws DAVException {
+ return supportsLiveProperty(DAV_ROOT_VERSION);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResourceHandle.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResponseInputStream.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResponseInputStream.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResponseInputStream.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * An <code>InputStream</code> on a response from a WebDAV server.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class ResponseInputStream extends FilterInputStream {
+ private IResponse response;
+
+ /**
+ * Creates a new input stream on the given response.
+ *
+ * @param response a response from a WebDAV server
+ */
+ public ResponseInputStream(IResponse response) {
+ super(response.getInputStream());
+ this.response = response;
+ }
+
+ /**
+ * Closes the response and frees all system resources associated with
+ * this input stream.
+ */
+ public void close() throws IOException {
+ response.close();
+ }
+
+ /**
+ * Returns the http header of the response from the WebDAV server on
+ * which this input stream is based. The context contains information
+ * that may be useful such as the content length and content type of
+ * this input stream.
+ */
+ public IContext getContext() {
+ return response.getContext();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/ResponseInputStream.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTable.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTable.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTable.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,258 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A <code>URLTable</code> is a simple hashtable whose keys are
+ * <code>URL</code>s. A <code>URL<code> key with a trailing slash is
+ * considered by the table to be equal to the same <code>URL</code>
+ * without a trailing slash.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class URLTable {
+
+ private Hashtable table;
+
+ /**
+ * A <code>URLKey</code> is an equality wrapper class for
+ * <code>URL</code>s. The wrapper treats <code>URL</code>s with and
+ * without a trailing slash as equal. The <code>equals</code> method
+ * works with <code>URLKey</code>s, <code>URL</code>s, and
+ * <code>String</code>s.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+ class URLKey {
+ URL url;
+ int hashCode = -1;
+
+ /**
+ * Creates a new <code>URLKey</code> from the given <code>URL</code>.
+ *
+ * @param url the <code>URL</code> to wrap
+ */
+ public URLKey(URL url) {
+ this.url = url;
+ }
+
+ /**
+ * Returns <code>true</code> if this <code>URLKey</code> is equal to the
+ * given object. Returns <code>false</code> otherwise. The object may be
+ * a <code>URLKey<code>, <code>String</code>, or <code>URL</code>.
+ *
+ * @param obj the object to compare with this <code>URLKey</code>
+ * @return a boolean indicating whether or not this
+ * <code>URLKey</code> is equal to the given object
+ */
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (this == obj)
+ return true;
+ if (obj instanceof URLKey)
+ return equals(((URLKey) obj).getURL());
+ if (obj instanceof String) {
+ try {
+ return equals(new URL((String) obj));
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
+ if (!(obj instanceof URL))
+ return false;
+ if (url == (URL) obj)
+ return true;
+ URL url1 = URLTool.removeTrailingSlash(url);
+ URL url2 = URLTool.removeTrailingSlash((URL) obj);
+ return url1.equals(url2);
+ }
+
+ /**
+ * Returns the <code>URL</code> that this <code>URLKey</code> wraps.
+ *
+ * @return the <code>URL</code> that this <code>URLKey</code> wraps
+ */
+ public URL getURL() {
+ return url;
+ }
+
+ /**
+ * Returns an integer suitable for indexing this <code>URLKey</code> in
+ * a hash table.
+ *
+ * @return an integer suitable for hash table indexing
+ */
+ public int hashCode() {
+ if (hashCode == -1)
+ hashCode = URLTool.removeTrailingSlash(url).hashCode();
+ return hashCode;
+ }
+
+ /**
+ * Returns this <code>URLKey</code>s <code>URL</code> as a
+ * <code>String</code>.
+ *
+ * @return a string
+ */
+ public String toString() {
+ return url.toString();
+ }
+ } // end-class URLKey
+
+ /**
+ * Construct an empty <code>URLTable</code>.
+ */
+ public URLTable() {
+ table = new Hashtable();
+ }
+
+ /**
+ * Construct an empty <code>URLTable</code> with the given size.
+ */
+ public URLTable(int size) {
+ table = new Hashtable(size);
+ }
+
+ /**
+ * Returns the value to which the given URL is mapped to in the table. If
+ * the given URL not mapped to any value, or is malformed, returns
+ * <code>null</code>.
+ *
+ * @param url a URL as a <code>String</code>
+ * @return the value to which the given URL is mapped to in the table,
+ * or <code>null</code>
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public Object get(String url) throws MalformedURLException {
+ Assert.isNotNull(url);
+ return get(new URL(url));
+ }
+
+ /**
+ * Returns the value to which the given <code>URL</code> is mapped to in
+ * the table. If the given <code>URL</code> not mapped to any value,
+ * returns <code>null</code>.
+ *
+ * @param url a <code>URL</code>
+ * @return the value to which the given <code>URL</code> is mapped to
+ * in the table, or <code>null</code>
+ */
+ public Object get(URL url) {
+ Assert.isNotNull(url);
+ return get(new URLKey(url));
+ }
+
+ /**
+ * Returns the value to which the specified URL is mapped to in the
+ * table. If the specified URL is not mapped to any value, returns
+ * <code>null</code>.
+ *
+ * @param url a <code>URLKey</code>
+ * @return the value to which the specified URL is mapped to in the
+ * table, or <code>null</code>
+ */
+ private Object get(URLKey url) {
+ Assert.isNotNull(url);
+ return table.get(url);
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over the keys in this
+ * <code>URLTable</code>.
+ *
+ * @return an <code>Enumeration</code> over <code>URL</code>s
+ */
+ public Enumeration keys() {
+ final Enumeration keys = table.keys();
+ Enumeration e = new Enumeration() {
+ public boolean hasMoreElements() {
+ return keys.hasMoreElements();
+ }
+
+ public Object nextElement() {
+ return ((URLKey) keys.nextElement()).getURL();
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Maps the given URL to the given value in this table.
+ *
+ * @param url a URL as a <code>String</code>
+ * @param value an object
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public void put(String url, Object value) throws MalformedURLException {
+ Assert.isNotNull(url);
+ Assert.isNotNull(value);
+ put(new URL(url), value);
+ }
+
+ /**
+ * Maps the given <code>URL</code> to the given value in this table.
+ *
+ * @param url a <code>URL</code>
+ * @param value an object
+ */
+ public void put(URL url, Object value) {
+ Assert.isNotNull(url);
+ Assert.isNotNull(value);
+ put(new URLKey(url), value);
+ }
+
+ /**
+ * Maps the specified URL to the given value in this table.
+ *
+ * @param url a <code>URLKey</code>
+ * @param value an object
+ */
+ private void put(URLKey url, Object value) {
+ Assert.isNotNull(url);
+ Assert.isNotNull(value);
+ // Remove the old entry so the url key is replaced
+ if (table.get(url) != null)
+ table.remove(url);
+ table.put(url, value);
+ }
+
+ public void remove(String url) throws MalformedURLException {
+ Assert.isNotNull(url);
+ remove(new URL(url));
+ }
+
+ public void remove(URL url) {
+ Assert.isNotNull(url);
+ remove(new URLKey(url));
+ }
+
+ private void remove(URLKey url) {
+ Assert.isNotNull(url);
+ table.remove(url);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTable.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,506 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Vector;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A utility for manipulating <code>URL</code>s.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class URLTool {
+ /**
+ * Returns the given URL with a trailing slash appended to it. If the URL
+ * already has a trailing slash the URL is returned unchanged.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Returned URL</th>
+ * <tr>
+ * <td>"http://hostname/folder"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>"http://hostname/folder/"</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the given URL with a trailing slash
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static URL appendTrailingSlash(String url) throws MalformedURLException {
+ return appendTrailingSlash(new URL(url));
+ }
+
+ /**
+ * Returns the given <code>URL</code> with a trailing slash appended to
+ * it. If the <code>URL</code> already has a trailing slash the
+ * <code>URL</code> is returned unchanged.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Returned URL</th>
+ * <tr>
+ * <td>"http://hostname/folder"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>"http://hostname/folder/"</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the given URL with a trailing slash
+ */
+ public static URL appendTrailingSlash(URL url) {
+ String file = url.getFile();
+ if (file.endsWith("/")) { //$NON-NLS-1$
+ return url;
+ }
+ try {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), file + "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * Returns the child URL formed by joining the given member with the
+ * given parent URL.
+ *
+ * @return a child URL of the given parent
+ * @throws MalformedURLException if the given parent is malformed
+ */
+ public static URL getChild(String parent, String member) throws MalformedURLException {
+ return getChild(new URL(parent), member);
+ }
+
+ /**
+ * Returns the child URL formed by joining the given member with the
+ * given parent URL.
+ *
+ * @return a child URL of the given parent
+ */
+ public static URL getChild(URL parent, String member) {
+ String file = parent.getFile();
+ if (!file.endsWith("/")) //$NON-NLS-1$
+ file = file + "/"; //$NON-NLS-1$
+ try {
+ return new URL(parent.getProtocol(), parent.getHost(), parent.getPort(), file + member);
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * Returns all elements in the given URLs path.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Element</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>[]</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>[folder]</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>[folder, file]</td>
+ * </table>
+ * @param url a URL
+ * @return all elements in the given URLs path
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static Vector getElements(String url) throws MalformedURLException {
+ return getElements(new URL(url));
+ }
+
+ /**
+ * Returns all elements in the given URLs path.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Element</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>[]</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>[folder]</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>[folder, file]</td>
+ * </table>
+ * @param url a URL
+ * @return all elements in the given URLs path
+ */
+ public static Vector getElements(URL url) {
+ Vector result = new Vector(5);
+ String lastElement = null;
+ while ((lastElement = getLastElement(url)) != null) {
+ result.insertElementAt(lastElement, 0);
+ url = getParent(url);
+ }
+ return result;
+ }
+
+ /**
+ * Returns the last element in the given URLs path, or <code>null</code>
+ * if the URL is the root.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Last Element</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>null</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>folder</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>file</td>
+ * </table>
+ * @param url a URL
+ * @return the last element in the given URLs path, or
+ * <code>null</code> if the URL is the root
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static String getLastElement(String url) throws MalformedURLException {
+ return getLastElement(new URL(url));
+ }
+
+ /**
+ * Returns the last element in the given URLs path, or <code>null</code>
+ * if the URL is the root.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Last Element</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>null</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>folder</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>file</td>
+ * </table>
+ * @param url a URL
+ * @return the last element in the given URLs path, or
+ * <code>null</code> if the URL is the root
+ */
+ public static String getLastElement(URL url) {
+ String file = url.getFile();
+ int len = file.length();
+
+ if (len == 0 || len == 1 && file.charAt(0) == '/') {
+ return null;
+ }
+
+ int lastSlashIndex = -1;
+ for (int i = len - 2; lastSlashIndex == -1 && i >= 0; --i) {
+ if (file.charAt(i) == '/') {
+ lastSlashIndex = i;
+ }
+ }
+
+ boolean isDirectory = file.charAt(len - 1) == '/';
+ if (lastSlashIndex == -1) {
+ if (isDirectory)
+ return file.substring(0, len - 1);
+ return file;
+ }
+ if (isDirectory)
+ return file.substring(lastSlashIndex + 1, len - 1);
+ return file.substring(lastSlashIndex + 1, len);
+ }
+
+ /**
+ * Returns the parent URL of the given URL, or <code>null</code> if the
+ * given URL is the root.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Parent URL</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>null</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>"http://hostname/folder/</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the parent of the given URL
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static URL getParent(String url) throws MalformedURLException {
+ return getParent(new URL(url));
+ }
+
+ /**
+ * Returns the parent URL of the given URL, or <code>null</code> if the
+ * given URL is the root.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Parent URL</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>null</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>"http://hostname/folder/</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the parent of the given URL
+ */
+ public static URL getParent(URL url) {
+ String file = url.getFile();
+ int len = file.length();
+
+ if (len == 0 || len == 1 && file.charAt(0) == '/')
+ return null;
+
+ int lastSlashIndex = -1;
+ for (int i = len - 2; lastSlashIndex == -1 && i >= 0; --i) {
+ if (file.charAt(i) == '/')
+ lastSlashIndex = i;
+ }
+
+ if (lastSlashIndex == -1)
+ file = ""; //$NON-NLS-1$
+ else
+ file = file.substring(0, lastSlashIndex + 1);
+
+ try {
+ url = new URL(url.getProtocol(), url.getHost(), url.getPort(), file);
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, e.getMessage());
+ }
+
+ return url;
+ }
+
+ /**
+ * Returns the root URL of the given URL.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Root URL</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>"http://hostname/"</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>"http://hostname/"</td>
+ * </table>
+ *
+ * @param urlString a URL
+ * @return the root url of the given URL
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static URL getRoot(String urlString) throws MalformedURLException {
+ return getRoot(new URL(urlString));
+ }
+
+ /**
+ * Returns the root URL of the given URL.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Root URL</th>
+ * <tr>
+ * <td>"http://hostname/"</td>
+ * <td>"http://hostname/"</td>
+ * <tr>
+ * <td>"http://hostname/folder/file</td>
+ * <td>"http://hostname/"</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the root URL of the given URL
+ */
+ public static URL getRoot(URL url) {
+ try {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * Returns the given URL with its trailing slash removed. If the URL has
+ * no trailing slash, the URL is returned unchanged.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Returned URL</th>
+ * <tr>
+ * <td>"http://hostname/folder"</td>
+ * <td>"http://hostname/folder"</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>"http://hostname/folder"</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the given URL with its last slash removed
+ * @throws MalformedURLException if the given URL is malformed
+ */
+ public static URL removeTrailingSlash(String url) throws MalformedURLException {
+ return removeTrailingSlash(new URL(url));
+ }
+
+ /**
+ * Returns the given URL with its trailing slash removed. If the URL has
+ * no trailing slash, the URL is returned unchanged.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>Given URL</th>
+ * <th>Returned URL</th>
+ * <tr>
+ * <td>"http://hostname/folder"</td>
+ * <td>"http://hostname/folder"</td>
+ * <tr>
+ * <td>"http://hostname/folder/</td>
+ * <td>"http://hostname/folder"</td>
+ * </table>
+ *
+ * @param url a URL
+ * @return the given URL with its last slash removed
+ */
+ public static URL removeTrailingSlash(URL url) {
+ String file = url.getFile();
+
+ if (file.endsWith("/")) { //$NON-NLS-1$
+ file = file.substring(0, file.length() - 1);
+ try {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), file);
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, e.getMessage());
+ }
+ } else {
+ return url;
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a boolean indicating whether the given URLs overlap.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>First URL</th>
+ * <th>Second URL</th>
+ * <th>Do they overlap</th>
+ * <tr>
+ * <td>"http://hostname/folder/"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder/"</td>
+ * <td>"http://hostname/folder/file"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder/file"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder1/"</td>
+ * <td>"http://hostname/folder2/"</td>
+ * <td>false</td>
+ * </table>
+ * @param url1 firt URL
+ * @param url2 second URL
+ * @return a boolean indicating whether the given URLs overlap
+ */
+ public static boolean urlsOverlap(String url1, String url2) throws MalformedURLException {
+ return urlsOverlap(new URL(url1), new URL(url2));
+ }
+
+ /**
+ * Returns a boolean indicating whether the given URLs overlap.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>First URL</th>
+ * <th>Second URL</th>
+ * <th>Do they overlap</th>
+ * <tr>
+ * <td>"http://hostname/folder/"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder/"</td>
+ * <td>"http://hostname/folder/file"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder/file"</td>
+ * <td>"http://hostname/folder/"</td>
+ * <td>true</td>
+ * <tr>
+ * <td>"http://hostname/folder1/"</td>
+ * <td>"http://hostname/folder2/"</td>
+ * <td>false</td>
+ * <tr>
+ * <td>"http://hostname1/folder/"</td>
+ * <td>"http://hostname2/folder/"</td>
+ * <td>false</td>
+ * </table>
+ * @param url1 firt URL
+ * @param url2 second URL
+ * @return a boolean indicating whether the given URLs overlap
+ */
+ public static boolean urlsOverlap(URL url1, URL url2) {
+ if (!getRoot(url1).equals(getRoot(url2))) {
+ return false;
+ }
+ Vector elements1 = URLTool.getElements(url1);
+ Vector elements2 = URLTool.getElements(url2);
+ for (int i = 0; i < elements1.size() && i < elements2.size(); ++i) {
+ String element1 = (String) elements1.elementAt(i);
+ String element2 = (String) elements2.elementAt(i);
+ if (!element1.equals(element2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/URLTool.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WebDAVFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WebDAVFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WebDAVFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import org.eclipse.webdav.*;
+import org.eclipse.webdav.dom.QualifiedName;
+import org.eclipse.webdav.dom.QualifiedNameImpl;
+import org.eclipse.webdav.internal.kernel.*;
+import org.w3c.dom.Document;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public class WebDAVFactory implements ILocatorFactory, IContextFactory, IDocumentFactory {
+
+ public static IContextFactory contextFactory = new ContextFactory();
+ public static IDocumentFactory documentFactory = new DocumentFactory();
+ public static ILocatorFactory locatorFactory = new LocatorFactory();
+
+ /**
+ * WebDavFactory constructor comment.
+ */
+ public WebDAVFactory() {
+ super();
+ }
+
+ public IContext newContext() {
+ return contextFactory.newContext();
+ }
+
+ public IContext newContext(IContext baseContext) {
+ return contextFactory.newContext(baseContext);
+ }
+
+ public Document newDocument() {
+ return documentFactory.newDocument();
+ }
+
+ public ILocator newLocator(String resourceURL) {
+ return locatorFactory.newLocator(resourceURL);
+ }
+
+ /**
+ * Answer a new resource locator that identifies a particular
+ * server resource by it's URL and label.
+ *
+ * @param resourceURL the URL of the resource.
+ * @param label the version label of the resource.
+ * @return the Locator to the resource.
+ */
+ public ILocator newLocator(String resourceURL, String label) {
+ return locatorFactory.newLocator(resourceURL, label);
+ }
+
+ public QualifiedName newQualifiedName(String qualifier, String localName) {
+ return new QualifiedNameImpl(qualifier, localName);
+ }
+
+ public ILocator newStableLocator(String resourceURL) {
+ return locatorFactory.newStableLocator(resourceURL);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WebDAVFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WorkspaceHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WorkspaceHandle.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WorkspaceHandle.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.client;
+
+import java.io.IOException;
+import org.eclipse.webdav.ILocator;
+import org.eclipse.webdav.IResponse;
+import org.eclipse.webdav.dom.Mkworkspace;
+import org.eclipse.webdav.internal.kernel.DAVException;
+import org.eclipse.webdav.internal.kernel.SystemException;
+import org.w3c.dom.Document;
+
+/**
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class WorkspaceHandle extends CollectionHandle {
+
+ public WorkspaceHandle(DAVClient davClient, ILocator locator) {
+ super(davClient, locator);
+ }
+
+ /**
+ * Check out this resource. Returns a resource handle on the checked out
+ * version selector, or the working resource if a version is checked out.
+ */
+ public AbstractResourceHandle checkOut() throws DAVException {
+ ILocator locator = protectedCheckOut();
+ return new WorkspaceHandle(davClient, locator);
+ }
+
+ /**
+ * Create a new workspace in the location described by this handle.
+ * <p>
+ * A new workspace is created using a MKWORKSPACE method call.</p>
+ *
+ * @throws DAVException if a problem occured creating the workspace
+ * on the WebDAV server.
+ */
+ public void create() throws DAVException {
+ Document document = newDocument();
+ Mkworkspace.create(document);
+ IResponse response = null;
+ try {
+ response = davClient.mkworkspace(locator, newContext(), document);
+ examineResponse(response);
+ } catch (IOException e) {
+ throw new SystemException(e);
+ } finally {
+ closeResponse(response);
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/WorkspaceHandle.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/messages.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/messages.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/messages.properties 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,42 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+### org.eclipse.webdav.client message catalog
+
+
+### Assert
+assert.notImplemented = not implemented
+assert.propNameMustBeEnumOverQual = Property names must be Enumeration over QualifiedName.
+assert.internalError = Internal error.
+
+### Exception
+exception.responseMustHaveDocBody = Response must have document body.
+exception.invalidDoc = Invalid document received from server.
+exception.malformedResp = Malformed response from the server.
+exception.respMustShareXMLDoc = Response from server must have XML document body.
+exception.respHasInvalidDoc = Response from server contains invalid document body.
+exception.respMustHaveElmtBody = Response from server must have element body.
+exception.bodyMustHaveElmt = Document body from server must have document element.
+exception.errorRetrievingProp = Error retrieving system property.
+exception.malformedElement = Malformed element.
+exception.malformedLocator = Malformed locator.
+exception.malformedContentType = Malformed content type: {0}.
+exception.contentLengthUnderflow = Content-Length underflow.
+exception.closed = Closed.
+exception.contentLengthExceeded = Content-Length exceeded
+exception.malformedContentLength = Malformed content length.
+exception.malformedHeaderField = Malformed header field.
+exception.unexpectedEndStream = Unexpected end of stream.
+exception.malformedStatusLine = Malformed status line.
+exception.missingRealm = Missing realm.
+exception.missingNextnonce = Missing nextnonce.
+exception.unregognizedAlgo = Unrecognized algorithm: {0}.
+exception.unregognizedQop = Unrecognized qop: {0}.
+exception.lookup = Could not lookup URL {0}.
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/messages.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/package.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/package.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/package.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides support for the WebDAV protocol.
+<h2>
+Package Specification</h2>
+This package defines a set of classes which enable clients to talk to WebDAV
+servers.
+</body>
+</html>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/client/package.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/BufferPool.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/BufferPool.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/BufferPool.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.util.Vector;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A <code>BufferPool</code> holds on to a collection of buffers (byte
+ * arrays) so they can be reused without having to allocate and release
+ * memory.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class BufferPool {
+ /**
+ * The size of each buffer in the pool.
+ */
+ private static int BUFFER_SIZE = 8 * 1024;
+
+ /**
+ * The maximum number of buffers in the pool.
+ */
+ private static int MAX_BUFFERS = 5;
+
+ /**
+ * The buffer pool.
+ */
+ private Vector pool = new Vector(MAX_BUFFERS);
+
+ /**
+ * Returns a buffer (byte array) of size <code>BUFFER_SIZE</code> from the
+ * pool. When the buffer is no longer needed, it should be put back in the
+ * pool for future use by calling <code>putBuffer</code>.
+ *
+ * @return a buffer
+ * @see #putBuffer(byte[])
+ */
+ public synchronized byte[] getBuffer() {
+ if (pool.isEmpty())
+ return new byte[BUFFER_SIZE];
+ byte[] buffer = (byte[]) pool.lastElement();
+ pool.removeElementAt(pool.size() - 1);
+ return buffer;
+ }
+
+ /**
+ * Puts the given buffer into the pool for future use. The size of the
+ * buffer must be <code>BUFFER_SIZE</code>.
+ *
+ * @param buffer the buffer to be put back into the buffer pool
+ * @see #getBuffer()
+ */
+ public synchronized void putBuffer(byte[] buffer) {
+ Assert.isNotNull(buffer);
+ Assert.isTrue(buffer.length == BUFFER_SIZE);
+ if (pool.size() < MAX_BUFFERS)
+ pool.addElement(buffer);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/BufferPool.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ContentType.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ContentType.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ContentType.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import org.eclipse.webdav.client.Policy;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * Parses an HTTP Content-Type entity-header field. See section 14.18 of
+ * RFC2068 for more information on this field.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class ContentType {
+ private String contentType;
+ private int position;
+ private boolean foundDelim;
+
+ private String type;
+ private String subtype;
+ private Hashtable parameters = new Hashtable(5);
+
+ /**
+ * Parses the given HTTP Content-Type entity-header field. For example,
+ * if the content type is "text/xml; charset="ISO-8859-4"" the type is
+ * "text", the subtype is "xml", and the value of the attribute "charset"
+ * is "ISO-8859-4".
+ *
+ * @param contentType the value of the content type field to parse
+ * @throws IllegalArgumentException if the content type is
+ * malformed
+ */
+ public ContentType(String contentType) throws IllegalArgumentException {
+ Assert.isNotNull(contentType);
+ this.contentType = contentType;
+ position = 0;
+ parse();
+ }
+
+ private void checkPosition() throws IllegalArgumentException {
+ if (position >= contentType.length())
+ illegalArgument();
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> of this content type's attributes.
+ * For example, if the content type is "text/xml; charset="ISO-8859-4"",
+ * it has one attribute namely, "charset".
+ *
+ * @return an <code>Enumeration</code> of <code>String</code>s
+ */
+ public Enumeration getAttributes() {
+ return parameters.keys();
+ }
+
+ /**
+ * Returns this content type's subtype. For example, if the content type
+ * is "text/xml; charset="ISO-8859-4"", the the subtype is "xml".
+ *
+ * @return this content type's subtype
+ */
+ public String getSubtype() {
+ return subtype;
+ }
+
+ /**
+ * Returns this content type's type. For example, if the content type is
+ * "text/xml; charset="ISO-8859-4"", the the type is "text".
+ *
+ * @return this content type's type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Returns the value of the given attribute for this content type. For
+ * example, if the content type is "text/xml; charset="ISO-8859-4"", then
+ * the value for the attribute "charset" is "IS-8859-4".
+ *
+ * @return the value of the given attribute for this content type
+ */
+ public String getValue(String attribute) {
+ return (String) parameters.get(attribute);
+ }
+
+ private void illegalArgument() throws IllegalArgumentException {
+ throw new IllegalArgumentException(Policy.bind("exception.malformedContentType", contentType)); //$NON-NLS-1$
+ }
+
+ private String nextToken(char delim, boolean trim) throws IllegalArgumentException {
+ int start = position;
+ int end = start;
+
+ boolean done = false;
+ boolean trimming = false;
+
+ while (!done) {
+ if (position == contentType.length()) {
+ done = true;
+ foundDelim = false;
+ } else {
+ char c = contentType.charAt(position);
+ if (Character.isWhitespace(c)) {
+ if (trim) {
+ trimming = true;
+ } else {
+ illegalArgument();
+ }
+ } else {
+ if (c == delim) {
+ done = true;
+ foundDelim = true;
+ } else {
+ if (trimming) {
+ illegalArgument();
+ }
+ end = position + 1;
+ }
+ }
+ ++position;
+ }
+ }
+
+ return contentType.substring(start, end);
+ }
+
+ private void parse() throws IllegalArgumentException {
+ checkPosition();
+ skipWhiteSpace();
+ checkPosition();
+ type = nextToken('/', false);
+ checkPosition();
+ subtype = nextToken(';', true);
+ skipWhiteSpace();
+ if (foundDelim) {
+ checkPosition();
+ }
+
+ while (position < contentType.length()) {
+ String attribute = nextToken('=', false);
+ checkPosition();
+ String value = nextToken(';', true);
+ if (value.startsWith("\"") && value.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(1, value.length() - 1);
+ }
+ skipWhiteSpace();
+ if (foundDelim) {
+ checkPosition();
+ }
+ parameters.put(attribute, value);
+ }
+ }
+
+ private void skipWhiteSpace() {
+ while (position < contentType.length() && Character.isWhitespace(contentType.charAt(position))) {
+ ++position;
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ContentType.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpClient.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpClient.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1091 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.client.WebDAVFactory;
+import org.eclipse.webdav.internal.authentication.AuthorizationAuthority;
+import org.eclipse.webdav.internal.kernel.Context;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * <p>An HTTP 1.0 or 1.1 client. Single instances of this client enable
+ * users to talk with multiple origin servers. Moreover, connections
+ * to origin servers are maintained for reuse.
+ *
+ * <p>Conveniences are provided for managing proxy servers, handling
+ * authentication, and setting up request headers.
+ *
+ * <p>Here is some sample code:
+ *
+ * <code>
+ * HttpClient client = new HttpClient();
+ * try {
+ * Request request = null;
+ * Response response = null;
+ * try {
+ * URL resourceUrl = new URL("http://hostname/index.html");
+ * request = new Request("GET", resourceUrl, (Context) null);
+ * response = client.invoke(request);
+ * System.out.print(response);
+ * InputStream is = response.getInputStream();
+ * int c;
+ * while ((c = is.read()) != -1) {
+ * System.out.print((char) c);
+ * }
+ * } catch (IOException e) {
+ * e.printStackTrace();
+ * } finally {
+ * if (request != null) {
+ * try {
+ * request.close();
+ * } catch (IOException e) {
+ * e.printStackTrace();
+ * }
+ * }
+ * if (response != null) {
+ * try {
+ * response.close();
+ * } catch (IOException e) {
+ * e.printStackTrace();
+ * }
+ * }
+ * }
+ * } finally {
+ * client.close();
+ * }
+ * </code>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class HttpClient implements IStatusCodes {
+ /**
+ * The HTTP version of this client.
+ */
+ private double httpVersion = 1.1;
+
+ /**
+ * Indicates whether this client is closed.
+ */
+ private boolean closed = true;
+
+ /**
+ * The connections recycler is responsible for closing and discarding
+ * unused connections that have become stale.
+ */
+ private ConnectionsRecycler connectionsRecycler = new ConnectionsRecycler("Connections Recycler"); //$NON-NLS-1$
+
+ /**
+ * The authorization authority authorizes requests.
+ */
+ private AuthorizationAuthority authority = null;
+
+ /**
+ * A <code>Hashtable</code> mapping origin server <code>URL</code>s
+ * to <code>Context</code>s. The contexts in this table are preferred
+ * over the default context.
+ */
+ private Hashtable contexts = new Hashtable(5);
+
+ /**
+ * The default context is used when one hasn't been set for a
+ * particular origin server.
+ */
+ private IContext defaultContext = null;
+
+ /**
+ * The <code>URL</code> of the default proxy server. The default is
+ * not used if the particular origin server matches a proxy server
+ * exception, or if there is already a proxy server associated with
+ * the origin server.
+ */
+ private URL defaultProxyServerUrl = null;
+
+ /**
+ * A <code>Hashtable</code> mapping origin server <code>URL</code>s
+ * to proxy server <code>URL</code>s. If an origin server
+ * <code>URL</code> has an entry in this table, the proxy server
+ * with the mapped <code>URL</code> is used.
+ */
+ private Hashtable proxyServerUrls = new Hashtable(5);
+
+ /**
+ * A set of proxy server exception patterns used to bypass the
+ * default proxy server. Any origin server whos host and port
+ * match the pattern do not use the default proxy server.
+ */
+ private Hashtable proxyServerExceptions = new Hashtable(5);
+
+ /**
+ * The maximum number of times a request is retried after an
+ * <code>IOException</code> occurs.
+ */
+ private int maxRetries = 1;
+
+ /**
+ * The maximum number of <code>URL</code> location redirects.
+ */
+ private int maxRedirects = 4;
+
+ /**
+ * The socket timeout (in milliseconds).
+ */
+ private int socketTimeout = 0;
+
+ /**
+ * The factory used to create <code>Socket</code>s.
+ */
+ private ISocketFactory socketFactory = null;
+
+ /**
+ * The factory used to create <code>Context</code>s.
+ */
+ private WebDAVFactory webDAVFactory = new WebDAVFactory();
+
+ /**
+ * The <code>ConnectionsRecycler</code> manages a collection of
+ * persistent <code>HttpConnection</code>s. Connections that remain
+ * unused for a given period of time are closed and discarded.
+ */
+ public class ConnectionsRecycler extends Thread {
+ /**
+ * The time (in milliseconds) that a connection remains unused
+ * before it is closed and discared.
+ */
+ private long connectionTimeout = 10000;
+
+ /**
+ * A <code>Hashtable</code> who's keys are origin server
+ * <code>URL</code>s that map to vectors of connections that are
+ * currently unused.
+ */
+ private Hashtable unusedConnections = new Hashtable(5);
+
+ /**
+ * A <code>Hashtable</code> who's keys are origin server
+ * <code>URL</code>s that map to vectors of connections that are
+ * currently in use.
+ */
+ private Hashtable usedConnections = new Hashtable(5);
+
+ /**
+ * Creates a new <code>ConnectionsRecycler</code> with the given
+ * name.
+ *
+ * @param name the name of the new connections recycler
+ */
+ public ConnectionsRecycler(String name) {
+ super(name);
+ this.setDaemon(true);
+ }
+
+ /**
+ * Closes this connections recycler. All of its connections are
+ * closed and discarded.
+ */
+ public synchronized void close() {
+ interrupt();
+ closeConnections(unusedConnections);
+ closeConnections(usedConnections);
+ }
+
+ private synchronized void closeConnections(Hashtable connections) {
+ Enumeration originServerUrls = connections.keys();
+ while (originServerUrls.hasMoreElements()) {
+ URL originServerUrl = (URL) originServerUrls.nextElement();
+ Vector connectionsVector = (Vector) connections.get(originServerUrl);
+ Enumeration connectionsEnum = connectionsVector.elements();
+ while (connectionsEnum.hasMoreElements()) {
+ HttpConnection connection = (HttpConnection) connectionsEnum.nextElement();
+ try {
+ connection.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ connections.clear();
+ }
+
+ /**
+ * Returns an unused connection that is connected to the origin
+ * server at the given <code>URL</code>. The connection is marked
+ * as in use before it is returned.
+ *
+ * @param originServerUrl the <code>URL</code> of an origin
+ * server
+ * @return an unused connection that is connected to the origin
+ * server at the given <code>URL</code>
+ * @see #putConnection(HttpConnection)
+ */
+ public synchronized HttpConnection getConnection(URL originServerUrl) {
+ HttpConnection connection = null;
+
+ Vector unusedConnections = (Vector) this.unusedConnections.get(originServerUrl);
+ if (unusedConnections == null || unusedConnections.isEmpty()) {
+ connection = new HttpConnection(originServerUrl);
+ } else {
+ connection = (HttpConnection) unusedConnections.lastElement();
+ unusedConnections.removeElementAt(unusedConnections.size() - 1);
+ }
+
+ Vector usedConnections = (Vector) this.usedConnections.get(originServerUrl);
+ if (usedConnections == null) {
+ usedConnections = new Vector(5);
+ this.usedConnections.put(originServerUrl, usedConnections);
+ }
+
+ usedConnections.addElement(connection);
+ connection.setTimestamp(new Date());
+
+ return connection;
+ }
+
+ public long getConnectionTimeout() {
+ return connectionTimeout;
+ }
+
+ /**
+ * Marks the given connection that is in use as unused.
+ *
+ * @param connection a connection that is in use
+ * @see #getConnection(URL)
+ */
+ public synchronized void putConnection(HttpConnection connection) {
+ URL resourceUrl = connection.getResourceUrl();
+
+ URL originServerUrl = null;
+ try {
+ originServerUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ // ignore?
+ }
+
+ Vector usedConnections = (Vector) this.usedConnections.get(originServerUrl);
+ usedConnections.remove(connection);
+
+ Vector unusedConnections = (Vector) this.unusedConnections.get(originServerUrl);
+ if (unusedConnections == null) {
+ unusedConnections = new Vector(5);
+ this.unusedConnections.put(originServerUrl, unusedConnections);
+ }
+
+ unusedConnections.addElement(connection);
+ connection.setTimestamp(new Date());
+ }
+
+ private synchronized void recycle() {
+ Vector staleOriginServerUrls = new Vector(3);
+ Enumeration originServerUrls = unusedConnections.keys();
+ while (originServerUrls.hasMoreElements()) {
+ URL originServerUrl = (URL) originServerUrls.nextElement();
+ Vector connectionsVector = (Vector) unusedConnections.get(originServerUrl);
+
+ if (connectionsVector.isEmpty()) {
+ staleOriginServerUrls.add(originServerUrl);
+ break;
+ }
+
+ Vector staleConnections = new Vector(5);
+ Enumeration connectionsEnum = connectionsVector.elements();
+ while (connectionsEnum.hasMoreElements()) {
+ HttpConnection connection = (HttpConnection) connectionsEnum.nextElement();
+
+ long currentTime = System.currentTimeMillis();
+ long connectionTime = connection.getTimestamp().getTime();
+
+ if (currentTime - connectionTime >= connectionTimeout) {
+ staleConnections.addElement(connection);
+ }
+ } // end-while
+
+ connectionsEnum = staleConnections.elements();
+ while (connectionsEnum.hasMoreElements()) {
+ HttpConnection connection = (HttpConnection) connectionsEnum.nextElement();
+ connectionsVector.remove(connection);
+
+ try {
+ connection.close();
+ } catch (IOException e) {
+ // ignore?
+ }
+ } // end-while
+ } // end-while
+
+ Enumeration staleOriginServerUrlsEnum = staleOriginServerUrls.elements();
+ while (staleOriginServerUrlsEnum.hasMoreElements()) {
+ unusedConnections.remove(staleOriginServerUrlsEnum.nextElement());
+ }
+ }
+
+ public void run() {
+ while (!interrupted()) {
+ try {
+ Thread.sleep(connectionTimeout);
+ recycle();
+ } catch (InterruptedException e) {
+ interrupt();
+ }
+ }
+ }
+
+ public void setConnectionTimeout(long connectionTimeout) {
+ this.connectionTimeout = connectionTimeout;
+ }
+ }
+
+ /**
+ * This type of input stream is passed back to the user in message
+ * responses. It serves to keep the stream's connection alive by
+ * returning it to this client's unused connections when the stream
+ * is closed.
+ *
+ * @see Response
+ */
+ class PersistentInputStream extends FilterInputStream {
+ /**
+ * This input stream's connection.
+ */
+ private HttpConnection connection;
+
+ /**
+ * Creates a new persistent input stream on the given connection.
+ *
+ * @param connection this input stream's connection
+ */
+ PersistentInputStream(HttpConnection connection) throws IOException {
+ super(null);
+
+ try {
+ in = connection.getInputStream();
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * @see InputStream#available()
+ */
+ public int available() throws IOException {
+ try {
+ return super.available();
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+
+ /**
+ * @see InputStream#close()
+ */
+ public void close() throws IOException {
+ try {
+ super.close();
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ } finally {
+ connectionsRecycler.putConnection(connection);
+ }
+ }
+
+ private void closeConnection() {
+ try {
+ connection.close();
+ } catch (IOException e) {
+ // ignore?
+ }
+ }
+
+ /**
+ * @see InputStream#read()
+ */
+ public int read() throws IOException {
+ try {
+ return super.read();
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+
+ /**
+ * @see InputStream#read(byte[])
+ */
+ public int read(byte b[]) throws IOException {
+ try {
+ return super.read(b);
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+
+ /**
+ * @see InputStream#read(byte[], int, int)
+ */
+ public int read(byte b[], int off, int len) throws IOException {
+ try {
+ return super.read(b, off, len);
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+
+ /**
+ * @see InputStream#reset()
+ */
+ public synchronized void reset() throws IOException {
+ try {
+ super.reset();
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+
+ /**
+ * @see InputStream#skip(long)
+ */
+ public long skip(long n) throws IOException {
+ try {
+ return super.skip(n);
+ } catch (IOException e) {
+ closeConnection();
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Creates a new <code>HttpClient</code>.
+ */
+ public HttpClient() {
+ open();
+ }
+
+ /**
+ * Adds the given proxy server exception pattern to this client.
+ * Origin servers whose hostname match the pattern do not communicate
+ * through the defualt proxy server. The pattern must contain zero or
+ * one stars (*). A star must appear at either the beginning or the
+ * end of the pattern. A star matches zero or more characters. The
+ * following are valid patterns:
+ * <ul>
+ * <li>www.company.com:80</li>
+ * <li>*.company.com</li>
+ * <li>www.company.*</li>
+ * </ul>
+ *
+ * @param pattern a proxy server exception pattern, for example:
+ * "*.company.com".
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerExceptions()
+ * @see #getProxyServerUrl(URL)
+ * @see #removeProxyServerException(String)
+ * @see #setDefaultProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public void addProxyServerException(String pattern) {
+ Assert.isNotNull(pattern);
+ proxyServerExceptions.put(pattern, pattern);
+ }
+
+ /**
+ * Closes this client.
+ */
+ public void close() {
+ if (!closed) {
+ connectionsRecycler.close();
+ closed = true;
+ }
+ }
+
+ public long getConnectionTimeout() {
+ return connectionsRecycler.getConnectionTimeout();
+ }
+
+ /**
+ * Returns the context for the origin server at the given
+ * <code>URL</code>.
+ *
+ * @param originServerUrl the <code>URL</code> of an origin server
+ * @return the context for the origin server at the given
+ * <code>URL</code>
+ * @see #getDefaultContext()
+ * @see #setDefaultContext(Context)
+ * @see #setContext(URL, Context)
+ */
+ public IContext getContext(URL originServerUrl) {
+ Assert.isNotNull(originServerUrl);
+ return (IContext) contexts.get(originServerUrl);
+ }
+
+ /**
+ * Returns the default context. The default context is used for servers
+ * that do not have a context set. Initially the default context is
+ * <code>null</code>.
+ *
+ * @return the default context, or <code>null</code>
+ * @see #getContext(URL)
+ * @see #setContext(URL, Context)
+ * @see #setDefaultContext(Context)
+ */
+ public IContext getDefaultContext() {
+ return defaultContext;
+ }
+
+ /**
+ * Returns the <code>URL</code> of the default proxy server which is
+ * used for all servers that do not have their proxy server set and
+ * do not match a proxy server exception. If the default proxy server
+ * <code>URL</code> is <code>null</code>, no default proxy server is
+ * used. Initially the default proxy server <code>URL</code> is
+ * <code>null</code>.
+ *
+ * @return the <code>URL</code> of the default proxy server, or
+ * <code>null</code>
+ * @see #addProxyServerException(String)
+ * @see #getProxyServerExceptions()
+ * @see #getProxyServerUrl(URL)
+ * @see #removeProxyServerException(String)
+ * @see #setDefaultProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public URL getDefaultProxyServerUrl() {
+ return defaultProxyServerUrl;
+ }
+
+ /**
+ * Returns the version of HTTP this client uses for communication with
+ * servers. HTTP/1.1 is used by default.
+ *
+ * @return the version of HTTP this client uses for communication with
+ * servers
+ * @see #setHttpVersion(double)
+ */
+ public double getHttpVersion() {
+ return httpVersion;
+ }
+
+ /**
+ * Returns the maximum number of <code>URL</code> location redirects. The
+ * maximum is 4 by default.
+ *
+ * @return the maximum number of <code>URL</code> location redirects
+ */
+ public int getMaxRedirects() {
+ return maxRedirects;
+ }
+
+ /**
+ * Returns the maximum number of times a request is retried after an
+ * <code>IOException</code> occurs. The maximum is 1 by default.
+ *
+ * @return the maximum number of retries
+ * @see #setMaxRetries(int)
+ */
+ public int getMaxRetries() {
+ return maxRetries;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over the origin server
+ * <code>URL</code>s known to this client. The known origin server
+ * <code>URL</code>s are gleaned from this client's mapped contexts and
+ * mapped proxy server <code>URL</code>s.
+ *
+ * @return an <code>Enumeration</code> over the origin server
+ * <code>URL</code>s known to this client
+ * @see #getContext(URL)
+ * @see #setContext(URL, Context)
+ * @see #getProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public Enumeration getOriginServerUrls() {
+ final Enumeration enum1 = contexts.keys();
+ final Enumeration enum2 = proxyServerUrls.keys();
+
+ Enumeration e = new Enumeration() {
+ public boolean hasMoreElements() {
+ return enum1.hasMoreElements() || enum2.hasMoreElements();
+ }
+
+ public Object nextElement() {
+ if (enum1.hasMoreElements())
+ return enum1.nextElement();
+ return enum2.nextElement();
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this client's proxy server
+ * exception patterns.
+ *
+ * @return an <code>Enumeration</code> over this client's proxy server
+ * exception patterns
+ * @see #addProxyServerException(String)
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerUrl(URL)
+ * @see #removeProxyServerException(String)
+ * @see #setDefaultProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public Enumeration getProxyServerExceptions() {
+ return proxyServerExceptions.keys();
+ }
+
+ /**
+ * Returns the <code>URL</code> of the proxy server that the origin
+ * server at the given <code>URL</code> uses, or <code>null</code> if
+ * no proxy server is used.
+ *
+ * @param originServerUrl the <code>URL<code> of an origin server
+ * @return the <code>URL</code> of a proxy server, or <code>null</code>
+ * @see #addProxyServerException(String)
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerExceptions()
+ * @see #removeProxyServerException(String)
+ * @see #setDefaultProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public URL getProxyServerUrl(URL originServerUrl) {
+ Assert.isNotNull(originServerUrl);
+ return (URL) proxyServerUrls.get(originServerUrl);
+ }
+
+ /**
+ * Returns the socket read timeout (in milliseconds) for this client. A
+ * value of zero indicates that a socket read operation will block
+ * indefinitely waiting for data. The value is zero by default.
+ *
+ * @return the socket read timeout (in milliseconds) for this client
+ * @see #setSoTimeout(int)
+ */
+ public int getSoTimeout() {
+ return socketTimeout;
+ }
+
+ /**
+ * Sends the given request to the server and returns the server's
+ * response.
+ *
+ * @param request the request to send to the server
+ * @return the server's response
+ * @throws IOException if an I/O error occurs. Reasons include:
+ * <ul>
+ * <li>The client is closed.
+ * <li>The client could not connect to the server
+ * <li>An I/O error occurs while communicating with the server
+ * <ul>
+ */
+ public Response invoke(Request request) throws IOException {
+ Assert.isNotNull(request);
+
+ try {
+ open();
+
+ URL resourceUrl = request.getResourceUrl();
+ URL originServerUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+
+ URL proxyServerUrl = getProxyServerUrl(originServerUrl);
+ if (proxyServerUrl == null && !matchesProxyServerException(originServerUrl)) {
+ proxyServerUrl = getDefaultProxyServerUrl();
+ }
+
+ IContext context = webDAVFactory.newContext(request.getContext());
+
+ IContext defaultContext = getContext(originServerUrl);
+ if (defaultContext == null) {
+ defaultContext = getDefaultContext();
+ }
+
+ if (defaultContext != null) {
+ Enumeration e = defaultContext.keys();
+ while (e.hasMoreElements()) {
+ String key = (String) e.nextElement();
+ context.put(key, defaultContext.get(key));
+ }
+ }
+
+ if (authority != null) {
+ authority.authorize(request, null, context, proxyServerUrl, true);
+ authority.authorize(request, null, context, proxyServerUrl, false);
+ }
+
+ return invoke1(request, context, proxyServerUrl, originServerUrl, 0, 0);
+ } finally {
+ request.close();
+ }
+ }
+
+ private Response invoke1(Request request, IContext context, URL proxyServerUrl, URL originServerUrl, int retries, int redirects) throws IOException {
+ Response response = null;
+
+ try {
+ response = invoke2(request, context, proxyServerUrl, originServerUrl, false);
+ int sc = response.getStatusCode();
+
+ if (sc == HTTP_UNAUTHORIZED || sc == HTTP_PROXY_AUTHENTICATION_REQUIRED) {
+ if (authority == null || !authority.authorize(request, response, context, proxyServerUrl, sc == IStatusCodes.HTTP_PROXY_AUTHENTICATION_REQUIRED)) {
+ return response;
+ }
+ response.close();
+ return invoke1(request, context, proxyServerUrl, originServerUrl, 0, 0);
+
+ } else if (sc >= 300 && sc < 400) {
+ if (redirects >= maxRedirects) {
+ return response;
+ }
+
+ String location = response.getContext().getLocation();
+ if (location == null) {
+ return response;
+ }
+
+ URL url = new URL(location);
+
+ if (sc == HTTP_USE_PROXY) {
+ proxyServerUrl = url;
+ } else {
+ originServerUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/"); //$NON-NLS-1$
+ request.setResourceUrl(url);
+ }
+
+ response.close();
+
+ return invoke1(request, context, proxyServerUrl, originServerUrl, 0, redirects + 1);
+ }
+
+ if (authority != null) {
+ authority.confirm(request, response, proxyServerUrl);
+ }
+
+ return response;
+ } catch (IOException e) {
+ if (response != null) {
+ response.close();
+ }
+
+ if (retries < maxRetries) {
+ return invoke1(request, context, proxyServerUrl, originServerUrl, retries + 1, 0);
+ }
+
+ throw e;
+ }
+ }
+
+ private Response invoke2(Request request, IContext context, URL proxyServerUrl, URL originServerUrl, boolean expect100Continue) throws IOException {
+ HttpConnection connection = null;
+
+ try {
+ // get the connection
+ connection = connectionsRecycler.getConnection(originServerUrl);
+
+ // set the http version
+ connection.setHttpVersion(httpVersion);
+
+ // set the method, resource url, and proxy server url
+ connection.setRequestMethod(request.getMethod());
+ connection.setResourceUrl(request.getResourceUrl());
+ connection.setProxyServerUrl(proxyServerUrl);
+
+ // set the request header
+ connection.clearRequestHeader();
+ Enumeration e = context.keys();
+ while (e.hasMoreElements()) {
+ String key = (String) e.nextElement();
+ connection.setRequestHeaderField(key, context.get(key));
+ }
+
+ // set the content length
+ long contentLength = request.getContentLength();
+ if (contentLength >= 0 && context.getContentLength() == -1) {
+ connection.setRequestHeaderField("Content-Length", "" + contentLength); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // set the chunked encoding
+ String method = request.getMethod();
+ boolean sendChunked = contentLength == -1 && httpVersion > 0 && !(method.equals("PROPPATCH") || method.equals("PROPFIND")); //$NON-NLS-1$ //$NON-NLS-2$
+ connection.setSendChunked(sendChunked);
+
+ // make the connection persistent
+ connection.setPersistent(httpVersion > 0);
+
+ // set the socket timeout
+ connection.setSoTimeout(socketTimeout);
+
+ // set the socket factory
+ connection.setSocketFactory(socketFactory);
+
+ // send the request header
+ IContext responseHeader = null;
+ if (expect100Continue && (contentLength > 0 && httpVersion > 0 || sendChunked)) {
+ if (!"100-continue".equalsIgnoreCase(context.get("Expect"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ connection.setRequestHeaderField("Expect", "100-continue"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ responseHeader = readResponseHeader(connection);
+ if (connection.getStatusCode() != IStatusCodes.HTTP_CONTINUE) {
+ return new Response(connection.getStatusCode(), connection.getStatusMessage(), responseHeader, new PersistentInputStream(connection));
+ }
+ }
+
+ // send the request body
+ if (contentLength != 0) {
+ OutputStream os = connection.getOutputStream();
+ request.write(os);
+ os.close();
+ }
+
+ // get the response header
+ responseHeader = readResponseHeader(connection);
+
+ // return the response
+ return new Response(connection.getStatusCode(), connection.getStatusMessage(), responseHeader, new PersistentInputStream(connection));
+ } catch (IOException e1) {
+ try {
+ connection.close();
+ } catch (IOException e2) {
+ // ignore?
+ }
+ connectionsRecycler.putConnection(connection);
+
+ throw e1;
+ } // end-catch
+ }
+
+ private boolean matchesProxyServerException(URL originServerUrl) {
+ String host = originServerUrl.getHost();
+ int port = originServerUrl.getPort();
+ String originServerUrlString = host + (port == -1 ? "" : ":" + port); //$NON-NLS-1$ //$NON-NLS-2$
+
+ boolean found = false;
+ Enumeration keys = proxyServerExceptions.keys();
+
+ while (!found && keys.hasMoreElements()) {
+ String httpProxyException = (String) keys.nextElement();
+ int len = httpProxyException.length();
+ found = originServerUrlString.equals(httpProxyException);
+ if (!found) {
+ if (httpProxyException.startsWith("*")) { //$NON-NLS-1$
+ found = originServerUrlString.endsWith(httpProxyException.substring(1, len));
+ } else if (httpProxyException.endsWith("*")) { //$NON-NLS-1$
+ found = originServerUrlString.startsWith(httpProxyException.substring(0, len - 1));
+ }
+ }
+ }
+
+ return found;
+ }
+
+ private void open() {
+ if (closed) {
+ connectionsRecycler.start();
+ closed = false;
+ }
+ }
+
+ private IContext readResponseHeader(HttpConnection httpConnection) throws IOException {
+ IContext responseHeader = webDAVFactory.newContext();
+
+ int position = 0;
+ String fieldName = null;
+ while ((fieldName = httpConnection.getResponseHeaderFieldName(position)) != null) {
+ // TBD : Should combine multiple headers
+ if (responseHeader.get(fieldName.toLowerCase()) == null)
+ responseHeader.put(fieldName.toLowerCase(), httpConnection.getResponseHeaderFieldValue(position));
+ ++position;
+ }
+
+ return responseHeader;
+ }
+
+ /**
+ * Removes the given proxy server exception pattern from this client.
+ *
+ * @param pattern a proxy server exception pattern
+ * @see #addProxyServerException(String)
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerExceptions()
+ * @see #getProxyServerUrl(URL)
+ * @see #setDefaultProxyServerUrl(URL)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public void removeProxyServerException(String pattern) {
+ Assert.isNotNull(pattern);
+ proxyServerExceptions.remove(pattern);
+ }
+
+ /**
+ * Sets the authenticator. Authenticators store authentication
+ * information and are required to access protected resources. If the
+ * authenticator is <code>null</code> protected resources cannot be
+ * accessed. The authenticator is <code>null</code> by default.
+ *
+ * @param authenticator the authenticator, or <code>null</code>
+ */
+ public void setAuthenticator(IAuthenticator authenticator) {
+ authority = authenticator == null ? null : new AuthorizationAuthority(authenticator);
+ }
+
+ public void setConnectionTimeout(long connectionTimeout) {
+ connectionsRecycler.setConnectionTimeout(connectionTimeout);
+ }
+
+ /**
+ * Set the context for the origin server at the given <code>URL</code>.
+ * If the given context is <code>null</code>, the context for the
+ * specified origin server is removed.
+ *
+ * @param originServerUrl the <code>URL</code> of an origin server
+ * @param context the context for the specified origin server
+ * @see #getContext(URL)
+ * @see #getDefaultContext()
+ * @see #setDefaultContext(Context)
+ */
+ public void setContext(URL originServerUrl, IContext context) {
+ Assert.isNotNull(originServerUrl);
+ if (context == null)
+ contexts.remove(originServerUrl);
+ else
+ contexts.put(originServerUrl, context);
+ }
+
+ /**
+ * Sets the default context which is used by all servers that do not
+ * already have a context set.
+ *
+ * @param context the default context
+ * @see #getContext(URL)
+ * @see #getDefaultContext()
+ * @see #setContext(URL, Context)
+ */
+ public void setDefaultContext(IContext context) {
+ defaultContext = context;
+ }
+
+ /**
+ * Sets the <code>URL</code> of the default proxy server that is used by
+ * all servers that do not have their proxy server set and do not match
+ * a proxy server exception pattern. If the given proxy server
+ * <code>URL</code> is <code>null</code>, no default proxy server is
+ * used.
+ *
+ * @param proxyServerUrl the <code>URL</code> of the default proxy server
+ * @see #addProxyServerException(String)
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerExceptions()
+ * @see #getProxyServerUrl(URL)
+ * @see #removeProxyServerException(String)
+ * @see #setProxyServerUrl(URL, URL)
+ */
+ public void setDefaultProxyServerUrl(URL proxyServerUrl) {
+ defaultProxyServerUrl = proxyServerUrl;
+ }
+
+ /**
+ * Sets the version of HTTP this client uses for communication with
+ * servers. HTTP/1.1 is used by default.
+ *
+ * @param httpVersion the version of HTTP this client uses for
+ * communication with servers
+ * @see #getHttpVersion()
+ */
+ public void setHttpVersion(double httpVersion) {
+ Assert.isTrue(httpVersion == 1.0 || httpVersion == 1.1);
+ this.httpVersion = httpVersion;
+ }
+
+ /**
+ * Sets the maximum number of <code>URL</code> location redirects. The
+ * maximum is 4 by default.
+ *
+ * @param maxRedirects the maximum number of <code>URL</code> redirects
+ */
+ public void setMaxRedirects(int maxRedirects) {
+ Assert.isTrue(maxRedirects >= 0);
+ this.maxRedirects = maxRedirects;
+ }
+
+ /**
+ * Sets the maximum number of times a request is retried after an
+ * <code>IOException</code> occurs. The maximum is 1 by default.
+ *
+ * @param maxRetries the maximum number of times a request is retried
+ * after an <code>IOException</code> occurs
+ * @see #getMaxRetries()
+ */
+ public void setMaxRetries(int maxRetries) {
+ Assert.isTrue(maxRetries >= 0);
+ this.maxRetries = maxRetries;
+ }
+
+ /**
+ * Sets the <code>URL</code> of the proxy server that this client uses
+ * to communicate with the origin server at the given <code>URL</code>.
+ * If the proxy server <code>URL</code> is <code>null</code>, the
+ * default proxy server is used if the specified origin server does not
+ * match a proxy server exception pattern.
+ *
+ * @param originServerUrl the <code>URL</code> of on origin server
+ * @param proxyServerUrl the <code>URL</code> of a proxy server, or
+ * <code>null</code>
+ * @see #addProxyServerException(String)
+ * @see #getDefaultProxyServerUrl()
+ * @see #getProxyServerExceptions()
+ * @see #getProxyServerUrl(URL)
+ * @see #removeProxyServerException(String)
+ * @see #setDefaultProxyServerUrl(URL)
+ */
+ public void setProxyServerUrl(URL originServerUrl, URL proxyServerUrl) {
+ Assert.isNotNull(originServerUrl);
+ if (proxyServerUrl == null)
+ proxyServerUrls.remove(originServerUrl);
+ else
+ proxyServerUrls.put(originServerUrl, proxyServerUrl);
+ }
+
+ /**
+ * Sets the factory that this client uses to create sockets.
+ *
+ * @param socketFactory the factory that this client uses to create
+ * sockets
+ */
+ public void setSocketFactory(ISocketFactory socketFactory) {
+ this.socketFactory = socketFactory;
+ }
+
+ /**
+ * Sets the socket read timeout (in milliseconds) for this client. A
+ * value of zero indicates that a socket read operation will block
+ * indefinitely waiting for data. The value is zero by default.
+ *
+ * @param timeout the socket read timeout
+ * @see #getSoTimeout()
+ */
+ public void setSoTimeout(int timeout) {
+ socketTimeout = timeout;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpClient.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpConnection.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpConnection.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpConnection.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1339 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import java.net.*;
+import java.util.Date;
+import java.util.Vector;
+import org.eclipse.webdav.client.Policy;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A connection to an HTTP/1.0 or HTTP/1.1 compatable server.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class HttpConnection implements IStatusCodes {
+ // The HTTP version to use (1.0 or 1.1).
+ private double httpVersion = 1.1;
+
+ // The request method.
+ private String method = "GET"; //$NON-NLS-1$
+
+ // The URL of the requested resource.
+ private URL resourceUrl = null;
+
+ // The URL of the proxy server.
+ private URL proxyServerUrl = null;
+
+ // The request and response headers.
+ protected Header requestHeader = new Header();
+ protected Header responseHeader = new Header();
+ protected Header internalHeader = new Header();
+
+ // The status code and status message of the response.
+ private int statusCode;
+ private String statusMessage;
+
+ // The socket factory, socket, and socket settings.
+ private ISocketFactory socketFactory = null;
+ private Socket socket = null;
+ private int receiveBufferSize = 0;
+ private int sendBufferSize = 0;
+ private int soLinger = -1;
+ private int soTimeout = 0;
+ private boolean tcpNoDelay = false;
+
+ // The actual socket streams.
+ protected InputStream socketIn = null;
+ protected OutputStream socketOut = null;
+
+ // The user's socket streams.
+ private InputStream is = null;
+ private OutputStream os = null;
+
+ // A boolean indicating whether the connection should be closed after
+ // the current request.
+ private boolean closeConnection;
+
+ // A boolean indicating whether the client wishes the connection to
+ // remain open after the current request.
+ private boolean persistent = true;
+
+ // A boolean indicating whether the client wishes the request's
+ // content to be sent chunked encoded.
+ private boolean sendChunked = true;
+
+ // A boolean indicating whether this connection is currently
+ // connected to a server.
+ private boolean connected = false;
+
+ // A boolean indicating whether the current request has been sent.
+ private boolean sentRequest = false;
+
+ // This connection's timestamp.
+ private Date timestamp = null;
+
+ /**
+ * A request or response header.
+ */
+ public class Header {
+ // This header's field names
+ private Vector fieldNames = new Vector(5);
+
+ // This header's field values
+ private Vector fieldValues = new Vector(5);
+
+ /**
+ * Adds the specified header field to this header.
+ *
+ * @param fieldName the new header field's name
+ * @param fieldValue the new header field's value
+ */
+ public void addField(String fieldName, String fieldValue) {
+ Assert.isNotNull(fieldName);
+ Assert.isNotNull(fieldValue);
+ fieldNames.addElement(fieldName);
+ fieldValues.addElement(fieldValue);
+ }
+
+ /**
+ * Removes all header fields from this header.
+ */
+ public void clear() {
+ fieldNames.removeAllElements();
+ fieldValues.removeAllElements();
+ }
+
+ /**
+ * Returns the field value of the header field at the given
+ * position, or <code>null</code> if there is no such postition.
+ *
+ * @param position the position of a header field
+ * @return the field value of the header field at the given
+ * position
+ */
+ public String getFieldValue(int position) {
+ if (position < 0 || position >= fieldValues.size())
+ return null;
+ return (String) fieldValues.elementAt(position);
+ }
+
+ /**
+ * Returns the field value of the header field with the given
+ * field name, or <code>null</code> if there is no such field
+ * name.
+ *
+ * @param fieldName the name of a header field
+ * @return the field value of the header field with the given
+ * field name
+ */
+ public String getFieldValue(String fieldName) {
+ Assert.isNotNull(fieldName);
+ return getFieldValue(fieldNames.indexOf(fieldName));
+ }
+
+ /**
+ * Returns the field name of the header field at the given
+ * position, or <code>null</code> if there is no such position.
+ *
+ * @param position the position of a header field in this header
+ * @return the field name of the header field at the given
+ * position
+ */
+ public String getFieldName(int position) {
+ if (position < 0 || position >= fieldNames.size())
+ return null;
+ return (String) fieldNames.elementAt(position);
+ }
+
+ /**
+ * Returns the number of header fields in this header.
+ *
+ * @return the number of header fields in this header
+ */
+ public int size() {
+ return fieldNames.size();
+ }
+ }
+
+ /**
+ * A limited input stream reads up to a given number of bytes from
+ * this connection's underlying socket input stream.
+ */
+ private class LimitedInputStream extends InputStream {
+ /**
+ * The number of bytes remaining in this stream.
+ */
+ private int bytesRemaining;
+
+ /**
+ * Creates a new limited input stream that reads up to
+ * <code>length</code> bytes of data from this connection's
+ * underlying socket input stream.
+ *
+ * @param length the length of this input stream
+ */
+ public LimitedInputStream(int length) {
+ Assert.isTrue(length >= 0);
+ bytesRemaining = length;
+ }
+
+ /**
+ * @see InputStream#available()
+ */
+ public int available() throws IOException {
+ return Math.min(socketIn.available(), bytesRemaining);
+ }
+
+ /**
+ * @see InputStream#close()
+ */
+ public void close() throws IOException {
+ while (skip(4096) > 0);
+ }
+
+ /**
+ * @see InputStream#read()
+ */
+ public int read() throws IOException {
+ if (bytesRemaining <= 0)
+ return -1;
+ --bytesRemaining;
+ return socketIn.read();
+ }
+
+ /**
+ * @see InputStream#read(byte[], int, int)
+ */
+ public int read(byte[] buf, int offset, int length) throws IOException {
+ if (bytesRemaining <= 0)
+ return -1;
+ int result = socketIn.read(buf, offset, Math.min(length, bytesRemaining));
+ if (result > 0)
+ bytesRemaining -= result;
+ return result;
+ }
+
+ /**
+ * @see InputStream#skip(int)
+ */
+ public long skip(int amount) throws IOException {
+ if (bytesRemaining <= 0)
+ return -1;
+ long result = socketIn.skip(Math.min(amount, bytesRemaining));
+ if (result > 0)
+ bytesRemaining -= result;
+ return result;
+ }
+ }
+
+ /**
+ * A chunked input stream reads bytes, that have been chunked
+ * transfer encoded, from this connection's underlying socket input
+ * stream.
+ */
+ private class ChunkedInputStream extends InputStream {
+
+ /**
+ * The number of bytes remaining in this stream's current chunk.
+ */
+ private int bytesRemaining = -1;
+
+ /**
+ * A boolean indicating whether the end of this stream has been
+ * reached.
+ */
+ private boolean atEnd = false;
+
+ /**
+ * @see InputStream#available()
+ */
+ public int available() throws IOException {
+ return Math.min(socketIn.available(), bytesRemaining);
+ }
+
+ /**
+ * @see InputStream#close()
+ */
+ public void close() throws IOException {
+ while (skip(4096) > 0);
+ }
+
+ /**
+ * @see InputStream#read()
+ */
+ public int read() throws IOException {
+ if (!atEnd && bytesRemaining <= 0)
+ readChunkSize();
+ if (atEnd)
+ return -1;
+ --bytesRemaining;
+ return socketIn.read();
+ }
+
+ /**
+ * @see InputStream#read(byte[], int, int)
+ */
+ public int read(byte[] buf, int offset, int length) throws IOException {
+ if (!atEnd && bytesRemaining <= 0)
+ readChunkSize();
+ if (atEnd)
+ return -1;
+ int result = socketIn.read(buf, offset, Math.min(length, bytesRemaining));
+ if (result > 0)
+ bytesRemaining -= result;
+ return result;
+ }
+
+ /**
+ * Read the size of the next chunk of data.
+ */
+ private void readChunkSize() throws IOException {
+ if (bytesRemaining == 0)
+ readln();
+ String size = readln();
+ int index = size.indexOf(";"); //$NON-NLS-1$
+ if (index >= 0)
+ size = size.substring(0, index);
+ try {
+ bytesRemaining = Integer.parseInt(size.trim(), 16);
+ } catch (NumberFormatException exception) {
+ throw new IOException(exception.getMessage());
+ }
+ if (bytesRemaining == 0) {
+ atEnd = true;
+ readHeader(responseHeader);
+ }
+ }
+
+ /**
+ * @see InputStream#skip(int)
+ */
+ public long skip(int amount) throws IOException {
+ if (!atEnd && bytesRemaining <= 0)
+ readChunkSize();
+ if (atEnd)
+ return -1;
+ long result = socketIn.skip(Math.min(amount, bytesRemaining));
+ if (result > 0)
+ bytesRemaining -= result;
+ return result;
+ }
+ }
+
+ /**
+ * A limited output stream writes up to a given number of bytes to
+ * this connection's underlying socket input stream.
+ */
+ private class LimitedOutputStream extends OutputStream {
+ // The maximum number of bytes that can be written to this
+ // stream.
+ private int limit;
+
+ // A boolean indicating whether this stream is closed.
+ private boolean closed = false;
+
+ /**
+ * Creates a new limited output stream that writes up to the
+ * given limit of bytes to this connection's underlying socket
+ * output stream.
+ *
+ * @param limit the maximum number of bytes that can be written
+ * to this stream
+ */
+ public LimitedOutputStream(int limit) {
+ Assert.isTrue(limit >= 0);
+ this.limit = limit;
+ }
+
+ /**
+ * @see OutputStream#close()
+ */
+ public void close() throws IOException {
+ if (closed)
+ return;
+ try {
+ flush();
+ if (limit > 0)
+ throw new IOException(Policy.bind("exception.contentLengthUnderflow")); //$NON-NLS-1$
+ readServerResponse();
+ } finally {
+ closed = true;
+ }
+ }
+
+ /**
+ * @see OutputStream#flush()
+ */
+ public void flush() throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ socketOut.flush();
+ }
+
+ /**
+ * @see OutputStream#write(int)
+ */
+ public void write(int data) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ if (limit == 0)
+ throw new IOException(Policy.bind("exception.contentLengthExceeded")); //$NON-NLS-1$
+ --limit;
+ socketOut.write(data);
+ }
+
+ /**
+ * @see OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] buffer, int offset, int count) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ if (count > limit)
+ throw new IOException(Policy.bind("exception.contentLengthExceeded")); //$NON-NLS-1$
+ limit -= count;
+ socketOut.write(buffer, offset, count);
+ }
+ }
+
+ /**
+ * A chunked output stream writes bytes to this connection's
+ * underlying socket output stream. The bytes are chunked transfer
+ * encoded before they are written to the stream.
+ */
+ private class ChunkedOutputStream extends OutputStream {
+ // The maximum size of this output stream's buffer
+ private static final int MAX_BUFFER_SIZE = 1024;
+
+ // A buffer that holds the next chunk of data to be written to
+ // this output stream.
+ private ByteArrayOutputStream buffer = new ByteArrayOutputStream(MAX_BUFFER_SIZE);
+
+ // A boolean indicating whether this output stream is closed.
+ private boolean closed = false;
+
+ /**
+ * @see OutputStream#close()
+ */
+ public void close() throws IOException {
+ if (closed)
+ return;
+ try {
+ sendBuffer();
+ output(socketOut, "0\r\n\r\n"); //$NON-NLS-1$
+ readServerResponse();
+ } finally {
+ closed = true;
+ }
+ }
+
+ /**
+ * @see OutputStream#flush()
+ */
+ public void flush() throws IOException {
+ if (closed)
+ throw new IOException("closed"); //$NON-NLS-1$
+ sendBuffer();
+ socketOut.flush();
+ }
+
+ /**
+ * Writes the content of the buffer to this stream.
+ */
+ public void sendBuffer() throws IOException {
+ int chunkSize = buffer.size();
+ if (chunkSize > 0) {
+ output(socketOut, Integer.toHexString(chunkSize) + "\r\n"); //$NON-NLS-1$
+ buffer.writeTo(socketOut);
+ buffer.reset();
+ output(socketOut, "\r\n"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @see OutputStream#write(int)
+ */
+ public void write(int data) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ buffer.write(data);
+ if (buffer.size() >= MAX_BUFFER_SIZE)
+ sendBuffer();
+ }
+
+ /**
+ * @see OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] buf, int off, int len) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ int bufferSize = buffer.size();
+ if (bufferSize + len < MAX_BUFFER_SIZE) {
+ buffer.write(buf, off, len);
+ } else {
+ output(socketOut, Integer.toHexString(bufferSize + len) + "\r\n"); //$NON-NLS-1$
+ buffer.writeTo(socketOut);
+ buffer.reset();
+ socketOut.write(buf, off, len);
+ output(socketOut, "\r\n"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * A cached output stream writes bytes to a cache before sending the
+ * data to the underlying socket output stream. This is done so the
+ * content length can be determined.
+ */
+ private class CachedOutputStream extends OutputStream {
+ // The initial size of this output stream's cache
+ private static final int INITIAL_CACHE_SIZE = 1024;
+
+ // A cache that stores the bytes written to this output stream.
+ private ByteArrayOutputStream cache = new ByteArrayOutputStream(INITIAL_CACHE_SIZE);
+
+ // A boolean indicating whether this output stream is closed.
+ private boolean closed = false;
+
+ /**
+ * @see OutputStream#close()
+ */
+ public void close() throws IOException {
+ if (closed)
+ return;
+ try {
+ String contentLength = Integer.toString(cache.size());
+ internalHeader.addField("Content-Length", contentLength); //$NON-NLS-1$
+ sendRequest();
+ cache.writeTo(socketOut);
+ readServerResponse();
+ } finally {
+ closed = true;
+ }
+ }
+
+ /**
+ * @see OutputStream#flush()
+ */
+ public void flush() throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see OutputStream#write(int)
+ */
+ public void write(int data) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ cache.write(data);
+ }
+
+ /**
+ * @see OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] buffer, int offset, int count) throws IOException {
+ if (closed)
+ throw new IOException(Policy.bind("exception.closed")); //$NON-NLS-1$
+ cache.write(buffer, offset, count);
+ }
+ }
+
+ /**
+ * Creates a new connection on the specified resource.
+ *
+ * @param resourceUrl the <code>URL</code> of a resource
+ */
+ public HttpConnection(URL resourceUrl) {
+ Assert.isNotNull(resourceUrl);
+ this.resourceUrl = resourceUrl;
+ }
+
+ /**
+ * Creates a new connection on the specified resource. This connection
+ * communicates through the proxy at the given proxy server
+ * <code>URL</code>.
+ *
+ * @param proxyServerUrl the <code>URL</code> of a proxy server
+ * @param resourceUrl the <code>URL</code> of a resource
+ */
+ public HttpConnection(URL proxyServerUrl, URL resourceUrl) {
+ Assert.isNotNull(proxyServerUrl);
+ Assert.isNotNull(resourceUrl);
+ this.proxyServerUrl = proxyServerUrl;
+ this.resourceUrl = resourceUrl;
+ }
+
+ /**
+ * Clear the request header.
+ */
+ public void clearRequestHeader() {
+ endRequest();
+ requestHeader.clear();
+ }
+
+ /**
+ * Close this connection.
+ *
+ * @exception IOException if there is an I/O error closing the socket
+ */
+ public void close() throws IOException {
+ endRequest();
+ if (connected) {
+ connected = false;
+ socket.close();
+ }
+ }
+
+ private void connect() throws IOException {
+ if (!connected) {
+ String protocol;
+ String host;
+ int port;
+ if (proxyServerUrl == null) {
+ protocol = resourceUrl.getProtocol();
+ host = resourceUrl.getHost();
+ port = getPort(resourceUrl);
+ } else {
+ protocol = proxyServerUrl.getProtocol();
+ host = proxyServerUrl.getHost();
+ port = getPort(proxyServerUrl);
+ }
+
+ if (socketFactory == null) {
+ socket = new Socket(host, port);
+ } else {
+ socket = socketFactory.createSocket(protocol, host, port);
+ }
+
+ if (receiveBufferSize > 0) {
+ socket.setReceiveBufferSize(receiveBufferSize);
+ }
+
+ if (sendBufferSize > 0) {
+ socket.setSendBufferSize(sendBufferSize);
+ }
+
+ socket.setSoLinger(soLinger >= 0, soLinger >= 0 ? soLinger : 0);
+ socket.setSoTimeout(soTimeout);
+ socket.setTcpNoDelay(tcpNoDelay);
+
+ socketOut = new BufferedOutputStream(socket.getOutputStream());
+ socketIn = new BufferedInputStream(socket.getInputStream());
+
+ closeConnection = httpVersion == 1.0 || !persistent;
+
+ connected = true;
+ }
+ }
+
+ private void endRequest() {
+ if (sentRequest) {
+ boolean failed = false;
+
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ failed = true;
+ }
+ }
+
+ try {
+ getInputStream().close();
+ } catch (IOException e) {
+ failed = true;
+ }
+
+ sentRequest = false;
+
+ if (closeConnection || failed) {
+ try {
+ connected = false;
+ socket.close();
+ } catch (IOException e) {
+ // ignore or log?
+ }
+ }
+ }
+
+ os = null;
+ is = null;
+
+ internalHeader.clear();
+ }
+
+ /**
+ * Returns the version of HTTP this connection uses for communication
+ * with servers. HTTP/1.1 is used by default.
+ *
+ * @return the version of HTTP this connection uses for communication
+ * with servers
+ * @see #setHttpVersion(double)
+ */
+ public double getHttpVersion() {
+ return httpVersion;
+ }
+
+ /**
+ * Returns this connection's <code>InputStream</code>.
+ *
+ * @return this connection's <code>InputStream</code>
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ */
+ public InputStream getInputStream() throws IOException {
+ if (is != null)
+ return is;
+ sendRequest();
+ String transferEncoding = responseHeader.getFieldValue("Transfer-Encoding"); //$NON-NLS-1$
+ String contentLength = responseHeader.getFieldValue("Content-Length"); //$NON-NLS-1$
+ if ("chunked".equalsIgnoreCase(transferEncoding)) { //$NON-NLS-1$
+ is = new ChunkedInputStream();
+ } else if (method.equals("HEAD") && statusCode == HTTP_OK) { //$NON-NLS-1$
+ is = new LimitedInputStream(0);
+ } else if (contentLength != null) {
+ try {
+ is = new LimitedInputStream(Integer.parseInt(contentLength));
+ } catch (NumberFormatException e) {
+ throw new IOException(e.getMessage());
+ }
+ } else if ((statusCode >= 100 && statusCode < 200) || statusCode == HTTP_NO_CONTENT || statusCode == HTTP_NOT_MODIFIED) {
+ is = new LimitedInputStream(0);
+ } else {
+ closeConnection = true;
+ is = socketIn;
+ }
+ return is;
+ }
+
+ /**
+ * Returns this connection's <code>OutputStream</code>.
+ *
+ * @return this connection's <code>OutputStream</code>
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ */
+ public OutputStream getOutputStream() throws IOException {
+ if (os != null)
+ return os;
+ String contentLength = requestHeader.getFieldValue("Content-Length"); //$NON-NLS-1$
+ if (sendChunked && httpVersion > 1.0) {
+ os = new ChunkedOutputStream();
+ } else if (contentLength != null) {
+ try {
+ os = new LimitedOutputStream(Integer.parseInt(contentLength));
+ } catch (NumberFormatException e) {
+ throw new IOException(Policy.bind("exception.malformedContentLength")); //$NON-NLS-1$
+ }
+ } else {
+ os = new CachedOutputStream();
+ return os;
+ }
+ sendRequest();
+ return os;
+ }
+
+ /**
+ * Returns a boolean indicating whether this connection should remain
+ * open after each request.
+ *
+ * @return a boolean indicating whether this connection should remain
+ * open after each request
+ * @see #setPersistent(boolean)
+ */
+ public boolean getPersistent() {
+ return persistent;
+ }
+
+ private int getPort(URL url) {
+ String protocol = url.getProtocol();
+ int port = url.getPort();
+
+ if (port == -1) {
+ if (protocol.equals("http")) //$NON-NLS-1$
+ return 80;
+ if (protocol.equals("https")) //$NON-NLS-1$
+ return 443;
+ return -1;
+ }
+
+ return port;
+ }
+
+ /**
+ * Returns the <code>URL</code> of the proxy server this connection uses
+ * to communicate with the origin server, or <code>null</code> if a proxy
+ * server is not used.
+ *
+ * @return the <code>URL</code> of the proxy server this connection uses
+ * to communicate with the origin server
+ * @see #setProxyServerUrl(URL)
+ */
+ public URL getProxyServerUrl() {
+ return proxyServerUrl;
+ }
+
+ /**
+ * @see Socket#getReceiveBufferSize()
+ * @see #setReceiveBufferSize(int)
+ */
+ public int getReceiveBufferSize() throws IOException {
+ if (connected)
+ return socket.getReceiveBufferSize();
+ return receiveBufferSize;
+ }
+
+ /**
+ * Returns the request header value associated with the given field name,
+ * or <code>null</code> if there is no such field name.
+ *
+ * @param fieldName the request header field name
+ * @return the request header value associated with the given field name
+ * @see #setRequestHeaderField(String, String)
+ */
+ public String getRequestHeaderFieldValue(String fieldName) {
+ Assert.isNotNull(fieldName);
+ return requestHeader.getFieldValue(fieldName);
+ }
+
+ /**
+ * Returns the request method. "GET" is used by default.
+ *
+ * @return the request method
+ * @see #setRequestMethod(String)
+ */
+ public String getRequestMethod() {
+ return method;
+ }
+
+ /**
+ * Returns the <code>URL</code> of this connection's resource.
+ *
+ * @return the <code>URL</code> of this connection's resource
+ * @see #setResourceUrl(URL)
+ */
+ public URL getResourceUrl() {
+ return resourceUrl;
+ }
+
+ /**
+ * Returns the response header field name at the given position, or
+ * <code>null</code> if there is no field name at that position.
+ *
+ * @param position a position in the response header greater than or
+ * equal to zero
+ * @return the response header field name at the given postion
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ * @see #getResponseHeaderFieldValue(int)
+ * @see #getResponseHeaderFieldValue(String)
+ */
+ public String getResponseHeaderFieldName(int position) throws IOException {
+ Assert.isTrue(position >= 0);
+ sendRequest();
+ return responseHeader.getFieldName(position);
+ }
+
+ /**
+ * Returns the response header field value at the given position, or
+ * <code>null</code> if there is no value at that position.
+ *
+ * @param position a position in the response header greater than or
+ * equal to zero
+ * @return the response header field value at the given postion
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ * @see #getResponseHeaderFieldName(int)
+ * @see #getResponseHeaderFieldValue(String)
+ */
+ public String getResponseHeaderFieldValue(int position) throws IOException {
+ Assert.isTrue(position >= 0);
+ sendRequest();
+ return responseHeader.getFieldValue(position);
+ }
+
+ /**
+ * Returns the response header field value that is associated with the
+ * given field name, or <code>null</code> if there is no value associated
+ * with that field name.
+ *
+ * @param fieldName the name of a response header field
+ * @return the response header field value that is associated with the
+ * given field name
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ * @see #getResponseHeaderFieldValue(int)
+ * @see #getResponseHeaderFieldName(int)
+ */
+ public String getResponseHeaderFieldValue(String fieldName) throws IOException {
+ Assert.isNotNull(fieldName);
+ sendRequest();
+ return responseHeader.getFieldValue(fieldName);
+ }
+
+ /**
+ * @see Socket#getSendBufferSize()
+ * @see #setSendBufferSize(int)
+ */
+ public int getSendBufferSize() throws IOException {
+ if (connected)
+ return socket.getSendBufferSize();
+ return sendBufferSize;
+ }
+
+ /**
+ * Returns a boolean indicating whether the request's body should be sent
+ * chunked encoded.
+ *
+ * @return a boolean indicating whether the request's body should be sent
+ * chunked encoded
+ * @see #setSendChunked(boolean)
+ */
+ public boolean getSendChunked() {
+ return sendChunked;
+ }
+
+ /**
+ * @see Socket#getSoLinger()
+ * @see #setSoLinger(boolean, int)
+ */
+ public int getSoLinger() {
+ return soLinger;
+ }
+
+ /**
+ * @see Socket#getSoTimeout()
+ * @see #setSoTimeout(int)
+ */
+ public int getSoTimeout() {
+ return soTimeout;
+ }
+
+ /**
+ * Returns the status code of the server's response.
+ *
+ * @return the status code of the server's response
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ * @see #getStatusMessage()
+ */
+ public int getStatusCode() throws IOException {
+ sendRequest();
+ return statusCode;
+ }
+
+ /**
+ * Returns the status message of the server's response.
+ *
+ * @return the status message of the server's response
+ * @exception IOException if an I/O error occurs while sending the
+ * request
+ * @see #getStatusCode()
+ */
+ public String getStatusMessage() throws IOException {
+ sendRequest();
+ return statusMessage;
+ }
+
+ /**
+ * @see Socket#getTcpNoDelay()
+ * @see #setTcpNoDelay(boolean)
+ */
+ public boolean getTcpNoDelay() {
+ return tcpNoDelay;
+ }
+
+ /**
+ * Returns this connection's timestamp.
+ *
+ * @return this connection's timestamp
+ * @see #setTimestamp(Date)
+ */
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ protected void output(OutputStream stream, String output) throws IOException {
+ stream.write(output.getBytes("UTF8")); //$NON-NLS-1$
+ }
+
+ protected void readHeader(Header header) throws IOException {
+ String line = null;
+
+ while ((line = readln()).length() > 0) {
+ int index = line.indexOf(":"); //$NON-NLS-1$
+
+ if (index < 0)
+ throw new IOException(Policy.bind("exception.malformedHeaderField")); //$NON-NLS-1$
+ String fieldName = line.substring(0, index);
+ String fieldValue = line.substring(index + 1).trim();
+ header.addField(fieldName, fieldValue);
+ }
+
+ String fieldValue = header.getFieldValue("Connection"); //$NON-NLS-1$
+ if (fieldValue != null && fieldValue.equalsIgnoreCase("close")) { //$NON-NLS-1$
+ closeConnection = true;
+ }
+ }
+
+ protected String readln() throws IOException {
+ boolean foundCR = false;
+ StringBuffer result = new StringBuffer();
+
+ while (true) {
+ int c = socketIn.read();
+
+ if (c < 0) {
+ throw new IOException(Policy.bind("exception.unexpectedEndStream")); //$NON-NLS-1$
+ }
+
+ if (foundCR) {
+ if (c == '\n')
+ break;
+ result.append('\r');
+ }
+
+ if (c == '\r') {
+ foundCR = true;
+ } else {
+ result.append((char) c);
+ }
+ }
+ return result.toString();
+ }
+
+ protected void readServerResponse() throws IOException {
+ socketOut.flush();
+
+ String statusLine = readln();
+
+ if (!statusLine.startsWith("HTTP/")) { //$NON-NLS-1$
+ throw new IOException(Policy.bind("exception.malformedStatusLine")); //$NON-NLS-1$
+ }
+
+ int firstSpace = statusLine.indexOf(' ', 5);
+ if (firstSpace == -1) {
+ throw new IOException(Policy.bind("exception.malformedStatusLine")); //$NON-NLS-1$
+ }
+
+ int secondSpace = statusLine.indexOf(' ', firstSpace + 1);
+ if (secondSpace == -1) {
+ throw new IOException(Policy.bind("exception.malformedStatusLine")); //$NON-NLS-1$
+ }
+
+ double protocolVersion;
+
+ try {
+ protocolVersion = Double.parseDouble(statusLine.substring(5, firstSpace));
+ statusCode = Integer.parseInt(statusLine.substring(firstSpace + 1, secondSpace));
+ statusMessage = statusLine.substring(secondSpace + 1);
+ } catch (NumberFormatException e) {
+ throw new IOException(Policy.bind("exception.malformedStatusLine")); //$NON-NLS-1$
+ }
+
+ if (protocolVersion == 1.0) {
+ httpVersion = 1.0;
+ closeConnection = true;
+ }
+
+ responseHeader.clear();
+ readHeader(responseHeader);
+ }
+
+ protected void sendRequest() throws IOException {
+ if (sentRequest)
+ return;
+ connect();
+ if (requestHeader.getFieldValue("Host") == null) { //$NON-NLS-1$
+ internalHeader.addField("Host", //$NON-NLS-1$
+ resourceUrl.getHost() + (resourceUrl.getPort() == -1 ? "" : ":" + resourceUrl.getPort())); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (httpVersion > 1.0 && !persistent && requestHeader.getFieldValue("Connection") == null) { //$NON-NLS-1$
+ internalHeader.addField("Connection", "close"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (os != null || "100-continue".equals(requestHeader.getFieldValue("Expect"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (requestHeader.getFieldValue("Content-Type") == null) { //$NON-NLS-1$
+ internalHeader.addField("Content-Type", "application/x-www-form-urlencoded"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (httpVersion > 1.0 && sendChunked) {
+ internalHeader.addField("Transfer-Encoding", "chunked"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ output(socketOut, method);
+ output(socketOut, " "); //$NON-NLS-1$
+ output(socketOut, proxyServerUrl == null ? resourceUrl.getFile() : resourceUrl.toString());
+ output(socketOut, " HTTP/1.1\r\n"); //$NON-NLS-1$
+
+ writeHeader(internalHeader);
+ writeHeader(requestHeader);
+ output(socketOut, "\r\n"); //$NON-NLS-1$
+
+ sentRequest = true;
+
+ if (os == null) {
+ readServerResponse();
+ }
+ }
+
+ /**
+ * Sets the version of HTTP this connection uses for communication with
+ * servers. HTTP/1.1 is used by default.
+ *
+ * @param version the version of HTTP this connection uses for
+ * communication with servers
+ * @see #getHttpVersion()
+ */
+ public void setHttpVersion(double version) {
+ Assert.isTrue(version == 1.0 || version == 1.1);
+ endRequest();
+ httpVersion = version;
+ }
+
+ /**
+ * Sets a boolean indicating whether this connection should remain open
+ * after each request.
+ *
+ * @param close a boolean indicating whether this connection should
+ * remain open after each request
+ * @see #getPersistent()
+ */
+ public void setPersistent(boolean close) {
+ endRequest();
+ persistent = close;
+ }
+
+ /**
+ * Sets the <code>URL</code> of the proxy server this connection uses to
+ * communicate with the origin server. If <code>null</code> is given, no
+ * proxy server is used.
+ *
+ * @param proxyServerUrl the <code>URL</code> of a proxy server
+ * @see #getProxyServerUrl()
+ */
+ public void setProxyServerUrl(URL proxyServerUrl) {
+ endRequest();
+ if (proxyServerUrl == null && this.proxyServerUrl == null)
+ return;
+ boolean closeConnection = true;
+
+ if (proxyServerUrl != null && this.proxyServerUrl != null) {
+ URL oldProxyServerUrl = null;
+ URL newProxyServerUrl = null;
+
+ try {
+ oldProxyServerUrl = new URL(this.proxyServerUrl.getProtocol(), this.proxyServerUrl.getHost(), this.proxyServerUrl.getPort(), "/"); //$NON-NLS-1$
+ newProxyServerUrl = new URL(proxyServerUrl.getProtocol(), proxyServerUrl.getHost(), proxyServerUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ // ignore or log?
+ }
+
+ if (oldProxyServerUrl.equals(newProxyServerUrl)) {
+ closeConnection = false;
+ }
+ }
+
+ if (closeConnection) {
+ try {
+ close();
+ } catch (IOException e) {
+ // ignore or log?
+ }
+ }
+
+ this.proxyServerUrl = proxyServerUrl;
+ }
+
+ /**
+ * @see Socket#setReceiveBufferSize(int)
+ * @see #getReceiveBufferSize()
+ */
+ public void setReceiveBufferSize(int size) throws IOException {
+ Assert.isTrue(size > 0);
+ if (size != getReceiveBufferSize()) {
+ receiveBufferSize = size;
+ if (connected) {
+ socket.setReceiveBufferSize(receiveBufferSize);
+ }
+ }
+ }
+
+ /**
+ * Sets the request header value associated with the given field.
+ *
+ * @param fieldName the request header field
+ * @param fieldValue the request header value
+ * @see #getRequestHeaderFieldValue(String)
+ */
+ public void setRequestHeaderField(String fieldName, String fieldValue) {
+ Assert.isNotNull(fieldName);
+ Assert.isNotNull(fieldValue);
+ endRequest();
+ requestHeader.addField(fieldName, fieldValue);
+ }
+
+ /**
+ * Sets the request method. "GET" is used by default.
+ *
+ * @param method the request method
+ * @see #getRequestMethod()
+ */
+ public void setRequestMethod(String method) {
+ Assert.isNotNull(method);
+ endRequest();
+ this.method = method;
+ }
+
+ /**
+ * Sets the <code>URL</code> of this connection's resource.
+ *
+ * @param resourceUrl the <code>URL</code> of this connection's resource
+ * @see #getResourceUrl()
+ */
+ public void setResourceUrl(URL resourceUrl) {
+ Assert.isNotNull(resourceUrl);
+ endRequest();
+ URL oldOriginServerUrl = null;
+ URL newOriginServerUrl = null;
+ try {
+ oldOriginServerUrl = new URL(this.resourceUrl.getProtocol(), this.resourceUrl.getHost(), this.resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ newOriginServerUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ // ignore?
+ }
+ if (!oldOriginServerUrl.equals(newOriginServerUrl)) {
+ try {
+ close();
+ } catch (IOException e) {
+ // ignore?
+ }
+ }
+ this.resourceUrl = resourceUrl;
+ }
+
+ /**
+ * @see Socket#setSendBufferSize(int)
+ * @see #getSendBufferSize()
+ */
+ public void setSendBufferSize(int size) throws IOException {
+ Assert.isTrue(size > 0);
+ if (size != getSendBufferSize()) {
+ sendBufferSize = size;
+ if (connected) {
+ socket.setSendBufferSize(sendBufferSize);
+ }
+ }
+ }
+
+ /**
+ * Sets a boolean indicating whether the request's body should be sent
+ * chunked encoded.
+ *
+ * @param chunked a boolean indicating whether the request's body should
+ * be sent chunked encoded
+ * @see #getSendChunked()
+ */
+ public void setSendChunked(boolean chunked) {
+ endRequest();
+ sendChunked = chunked;
+ }
+
+ /**
+ * Sets the factory this connection uses to create sockets. If the given
+ * socket factory is <code>null</code> the default socket is used.
+ *
+ * @param socketFactory the factory this connection uses to create
+ * sockets
+ */
+ public void setSocketFactory(ISocketFactory socketFactory) {
+ endRequest();
+ if (socketFactory == this.socketFactory)
+ return;
+ try {
+ close();
+ } catch (IOException e) {
+ // ignore?
+ }
+ this.socketFactory = socketFactory;
+ }
+
+ /**
+ * @see Socket#setSoLinger(boolean, int)
+ * @see #getSoLinger()
+ */
+ public void setSoLinger(boolean on, int linger) throws IOException {
+ Assert.isTrue(linger >= 0);
+ if (!on && soLinger != -1 || on && linger != soLinger) {
+ soLinger = on ? linger : -1;
+ if (connected) {
+ socket.setSoLinger(on, linger);
+ }
+ }
+ }
+
+ /**
+ * @see Socket#setSoTimeout(int)
+ * @see #getSoTimeout()
+ */
+ public void setSoTimeout(int timeout) throws IOException {
+ Assert.isTrue(timeout >= 0);
+ if (timeout != soTimeout) {
+ soTimeout = timeout;
+ if (connected) {
+ socket.setSoTimeout(soTimeout);
+ }
+ }
+ }
+
+ /**
+ * @see Socket#setTcpNoDelay(boolean)
+ * @see #getTcpNoDelay()
+ */
+ public void setTcpNoDelay(boolean on) throws IOException {
+ if (on != tcpNoDelay) {
+ tcpNoDelay = on;
+ if (connected) {
+ socket.setTcpNoDelay(tcpNoDelay);
+ }
+ }
+ }
+
+ /**
+ * Sets this connection's timestamp.
+ *
+ * @param date this connection's timestamp
+ * @see #getTimestamp()
+ */
+ public void setTimestamp(Date date) {
+ timestamp = date;
+ }
+
+ private void writeHeader(Header header) throws IOException {
+ for (int i = 0; i < header.size(); ++i) {
+ String fieldName = header.getFieldName(i);
+ String fieldValue = header.getFieldValue(fieldName);
+ output(socketOut, fieldName);
+ output(socketOut, ": "); //$NON-NLS-1$
+ output(socketOut, fieldValue);
+ output(socketOut, "\r\n"); //$NON-NLS-1$
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/HttpConnection.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IAuthenticator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IAuthenticator.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IAuthenticator.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * Implementations of this interface are used by clients to store and
+ * retrieve information for authentication purposes.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface IAuthenticator {
+
+ /**
+ * Adds the given authentication information to the store. The
+ * information is relevant for the specified protection space and the
+ * given authentication scheme. The protection space is defined by the
+ * combination of the given server URL and realm. The authentication
+ * scheme determines what the authentication information contains and how
+ * it should be used. The authentication information is a <code>Map</code>
+ * of <code>String</code> to <code>String</code> and typically
+ * contain information such as usernames and passwords.
+ *
+ * @param serverUrl the URL identifying the server for this authentication
+ * information. For example, "http://www.hostname.com/".
+ * @param realm the subsection of the given server to which this
+ * authentication information applies. For example,
+ * "realm1 at hostname.com" or "" for no realm.
+ * @param scheme the scheme for which this authentication information
+ * applies. For example, "Basic" or "" for no authentication scheme
+ * @param info a <code>Map</code> containing authentication information
+ * such as usernames and passwords
+ */
+ public void addAuthenticationInfo(URL serverUrl, String realm, String scheme, Map info);
+
+ /**
+ * Adds the specified resource to the protection space specified by the
+ * given realm. All resources at or deeper than the depth of the last
+ * symbolic element in the path of the given resource URL are assumed to
+ * be in the same protection space.
+ *
+ * @param resourceUrl the URL identifying the resources to be added to
+ * the specified protection space. For example,
+ * "http://www.hostname.com/folder/".
+ * @param realm the name of the protection space. For example,
+ * "realm1 at hostname.com"
+ */
+ public void addProtectionSpace(URL resourceUrl, String realm);
+
+ /**
+ * Returns the authentication information for the specified protection
+ * space and given authentication scheme. The protection space is defined
+ * by the given server URL and realm. Returns <code>null</code> if no
+ * such information exists.
+ * <p>This method is similar to <code>requestAuthenticationInfo</code>
+ * except the user is not prompted for the result. Instead, the store is
+ * queried for the information (such as username and password).
+ *
+ * @param serverUrl the URL identifying the server for the authentication
+ * information. For example, "http://www.hostname.com/".
+ * @param realm the subsection of the given server to which the
+ * authentication information applies. For example,
+ * "realm1 at hostname.com" or "" for no realm.
+ * @param scheme the scheme for which the authentication information
+ * applies. For example, "Basic" or "" for no authentication scheme
+ * @return the authentication information for the specified protection
+ * space and given authentication scheme, or <code>null</code> if no
+ * such information exists
+ * @see #requestAuthenticationInfo(URL, String, String)
+ */
+ public Map getAuthenticationInfo(URL serverUrl, String realm, String scheme);
+
+ /**
+ * Returns the protection space (realm) for the specified resource, or
+ * <code>null</code> if the realm is unknown.
+ *
+ * @param resourceUrl the URL of the resource whose protection space is
+ * returned. For example, "http://www.hostname.com/folder/".
+ * @return the protection space (realm) for the specified resource, or
+ * <code>null</code> if the realm is unknown
+ */
+ public String getProtectionSpace(URL resourceUrl);
+
+ /**
+ * Returns the authentication information for the specified protection
+ * space and given authentication scheme. The protection space is defined
+ * by the given server URL and realm. Returns <code>null</code> if no
+ * such information exists.
+ * <p>This method is similar to <code>getAuthenticationInfo</code> except
+ * the store is usually not queried for the result. Instead, the user is
+ * prompted for the information (such as username and password).
+ *
+ * @param resourceUrl the URL identifying the server for the authentication
+ * information. For example, "http://www.hostname.com/".
+ * @param realm the subsection of the given server to which the
+ * authentication information applies. For example,
+ * "realm1 at hostname.com" or "" for no realm.
+ * @param scheme the scheme for which the authentication information
+ * applies. For example, "Basic" or "" for no authentication scheme
+ * @return the authentication information for the specified protection
+ * space and given authentication scheme, or <code>null</code> if no
+ * such information exists
+ * @see #getAuthenticationInfo(URL, String, String)
+ */
+ public Map requestAuthenticationInfo(URL resourceUrl, String realm, String scheme);
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IAuthenticator.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IRequestBodyWriter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IRequestBodyWriter.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IRequestBodyWriter.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import org.eclipse.webdav.IContext;
+
+/**
+ * An object writer for <code>Request</code>s whose body is in object
+ * form and shouldn't be flattened until an output stream is available.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Request#Request(String, URL, IContext, IRequestBodyWriter)
+ * @see Request#getRequestBodyWriter()
+ */
+public interface IRequestBodyWriter {
+ /**
+ * Writes a request body to the given output stream.
+ *
+ * @throws IOException if there is a problem writing to the stream
+ */
+ public void writeRequestBody(OutputStream os) throws IOException;
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IRequestBodyWriter.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ISocketFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ISocketFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ISocketFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public interface ISocketFactory {
+ public Socket createSocket(String protocol, String host, int port) throws IOException;
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/ISocketFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IStatusCodes.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IStatusCodes.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IStatusCodes.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+/**
+ * HTTP status codes.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface IStatusCodes {
+ public static final int HTTP_CONTINUE = 100;
+ public static final int HTTP_SWITCHING_PROTOCOLS = 101;
+ public static final int HTTP_OK = 200;
+ public static final int HTTP_CREATED = 201;
+ public static final int HTTP_ACCEPTED = 202;
+ public static final int HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
+ public static final int HTTP_NO_CONTENT = 204;
+ public static final int HTTP_RESET_CONTENT = 205;
+ public static final int HTTP_PARTIAL_CONTENT = 206;
+ public static final int HTTP_MULTIPLE_CHOICES = 300;
+ public static final int HTTP_MOVED_PERMANENTLY = 301;
+ public static final int HTTP_MOVED_TEMPORARILY = 302;
+ public static final int HTTP_SEE_OTHER = 303;
+ public static final int HTTP_NOT_MODIFIED = 304;
+ public static final int HTTP_USE_PROXY = 305;
+ public static final int HTTP_TEMPORARY_REDIRECT = 307;
+ public static final int HTTP_BAD_REQUEST = 400;
+ public static final int HTTP_UNAUTHORIZED = 401;
+ public static final int HTTP_PAYMENT_REQUIRED = 402;
+ public static final int HTTP_FORBIDDEN = 403;
+ public static final int HTTP_NOT_FOUND = 404;
+ public static final int HTTP_METHOD_NOT_ALLOWED = 405;
+ public static final int HTTP_NOT_ACCEPTABLE = 406;
+ public static final int HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
+ public static final int HTTP_REQUEST_TIMEOUT = 408;
+ public static final int HTTP_CONFLICT = 409;
+ public static final int HTTP_GONE = 410;
+ public static final int HTTP_LENGTH_REQUIRED = 411;
+ public static final int HTTP_PRECONDITION_FAILED = 412;
+ public static final int HTTP_REQUEST_TOO_LONG = 413;
+ public static final int HTTP_REQUEST_URI_TOO_LONG = 414;
+ public static final int HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
+ public static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
+ public static final int HTTP_EXPECTATION_FAILED = 417;
+ public static final int HTTP_INTERNAL_SERVER_ERROR = 500;
+ public static final int HTTP_NOT_IMPLEMENTED = 501;
+ public static final int HTTP_BAD_GATEWAY = 502;
+ public static final int HTTP_SERVICE_UNAVAILABLE = 503;
+ public static final int HTTP_GATEWAY_TIMEOUT = 504;
+ public static final int HTTP_HTTP_VERSION_NOT_SUPPORTED = 505;
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/IStatusCodes.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Message.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Message.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Message.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.client.Policy;
+import org.eclipse.webdav.client.WebDAVFactory;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A common superclass for HTTP messages. There are two kinds of HTTP
+ * message; requests and responses. They both have in common a context
+ * and an input stream. This class factors out these similarities.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public abstract class Message {
+ protected static BufferPool bufferPool = new BufferPool();
+ protected InputStream is;
+ protected boolean inputRead = false;
+ protected boolean hasInputStream = false;
+ protected IContext context;
+
+ /**
+ * Creates a message.
+ *
+ * @param context the message header, or <code>null</code> for an empty
+ * header
+ * @param is an input stream containing the message's body, or
+ * <code>null</code> for an empty body
+ */
+ public Message(IContext context, InputStream is) {
+ this.context = context;
+ if (context == null)
+ this.context = WebDAVFactory.contextFactory.newContext();
+ this.is = is;
+ if (is == null)
+ this.is = new ByteArrayInputStream(new byte[0]);
+ }
+
+ /**
+ * Closes this message to free up any system resources. All messages
+ * must be closed before finalization.
+ *
+ * @exception IOException if there is an I/O error
+ */
+ public void close() throws IOException {
+ is.close();
+ }
+
+ /**
+ * Returns the content length of this message's body, or -1 if the
+ * content length is unknown.
+ *
+ * @return the content length of this message's body
+ */
+ public long getContentLength() {
+ long contentLength = context.getContentLength();
+ if (contentLength != -1)
+ return contentLength;
+ if (is instanceof ByteArrayInputStream)
+ return ((ByteArrayInputStream) is).available();
+ return -1;
+ }
+
+ /**
+ * Returns this message's context.
+ *
+ * @return this message's context
+ */
+ public IContext getContext() {
+ return context;
+ }
+
+ /**
+ * Returns this message's input stream.
+ *
+ * @return this message's input stream
+ */
+ public InputStream getInputStream() {
+ hasInputStream = true;
+ return is;
+ }
+
+ public String toString() {
+ return context.toString();
+ }
+
+ /**
+ * Writes this messages body to the given output stream. This method may
+ * only be called once during the lifetime of this message.
+ *
+ * @param os an output stream
+ * @exception IOException if there is an I/O error
+ */
+ public void write(OutputStream os) throws IOException {
+ Assert.isTrue(!inputRead);
+ Assert.isTrue(!hasInputStream);
+
+ int bytesRead = 0;
+ int totalBytesRead = 0;
+ byte[] buffer = bufferPool.getBuffer();
+ long contentLength = getContentLength();
+
+ try {
+ while (bytesRead != -1 && (contentLength == -1 || contentLength > totalBytesRead)) {
+ if (contentLength == -1) {
+ bytesRead = is.read(buffer);
+ } else {
+ bytesRead = is.read(buffer, 0, (int) Math.min(buffer.length, contentLength - totalBytesRead));
+ }
+ if (bytesRead == -1) {
+ if (contentLength >= 0) {
+ throw new IOException(Policy.bind("exception.unexpectedEndStream")); //$NON-NLS-1$
+ }
+ } else {
+ totalBytesRead += bytesRead;
+ os.write(buffer, 0, bytesRead);
+ }
+ }
+ } finally {
+ bufferPool.putBuffer(buffer);
+ inputRead = true;
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Message.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Request.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Request.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Request.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import java.net.URL;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * An HTTP request message.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Request extends Message {
+ private String method;
+ private URL resourceUrl;
+ private IRequestBodyWriter requestBodyWriter;
+
+ /**
+ * Creates a request.
+ *
+ * @param method the type of request, for example: "PUT"
+ * @param resourceUrl the URL of the target resource
+ * @param context the request's header, or <code>null</code> for an empty
+ * header
+ */
+ public Request(String method, URL resourceUrl, IContext context) {
+ super(context, new RequestInputStream(new byte[0]));
+ Assert.isNotNull(method);
+ Assert.isNotNull(resourceUrl);
+ this.method = method;
+ this.resourceUrl = resourceUrl;
+ }
+
+ /**
+ * Creates a request. For efficiency, the given input stream should be a
+ * <code>RequestInputStream</code> or a <code>ByteArrayInputStream</code>.
+ *
+ * @param method the type of request, for example: "PUT"
+ * @param resourceUrl the URL of the target resource
+ * @param context the request's header, or <code>null</code> for an empty
+ * header
+ * @param is an input stream containing the message's body, or
+ * <code>null</code> for an empty body
+ * @exception IOException if there is an I/O error
+ * @see RequestInputStream
+ */
+ public Request(String method, URL resourceUrl, IContext context, InputStream is) throws IOException {
+ super(context, is == null ? new RequestInputStream(new byte[0]) : is instanceof RequestInputStream ? is : is instanceof ByteArrayInputStream ? new RequestInputStream((ByteArrayInputStream) is) : new RequestInputStream(is, -1));
+ Assert.isNotNull(method);
+ Assert.isNotNull(resourceUrl);
+ this.method = method;
+ this.resourceUrl = resourceUrl;
+ }
+
+ /**
+ * Creates a request.
+ *
+ * @param method the type of request, for example: "PUT"
+ * @param resourceUrl the URL of the target resource
+ * @param context the message header, or <code>null</code> for an empty
+ * header
+ * @param requestBodyWriter for obtaining the message's body
+ */
+ public Request(String method, URL resourceUrl, IContext context, IRequestBodyWriter requestBodyWriter) {
+ super(context, new RequestInputStream(new byte[0]));
+ Assert.isNotNull(method);
+ Assert.isNotNull(resourceUrl);
+ Assert.isNotNull(requestBodyWriter);
+ this.method = method;
+ this.resourceUrl = resourceUrl;
+ this.requestBodyWriter = requestBodyWriter;
+ }
+
+ /**
+ * Returns the content length of this message's body, or -1 if the
+ * content length is unknown.
+ *
+ * @return the content length of this message's body
+ */
+ public long getContentLength() {
+ long contentLength = super.getContentLength();
+ if (contentLength != -1)
+ return contentLength;
+ if (requestBodyWriter == null)
+ return ((RequestInputStream) is).length();
+ return -1;
+ }
+
+ /**
+ * Returns the type of this request, for example: "PUT".
+ *
+ * @return the type of this request, for example: "PUT"
+ */
+ public String getMethod() {
+ return method;
+ }
+
+ /**
+ * Returns this request's request body writer, or <code>null</code> if
+ * this request does not have one.
+ *
+ * @return this request's request body writer, or <code>null</code>
+ */
+ public IRequestBodyWriter getRequestBodyWriter() {
+ return requestBodyWriter;
+ }
+
+ /**
+ * Returns the URL of this request's target resource.
+ *
+ * @return the URL of this request's target resource
+ */
+ public URL getResourceUrl() {
+ return resourceUrl;
+ }
+
+ void setResourceUrl(URL resourceUrl) {
+ this.resourceUrl = resourceUrl;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(method);
+ buffer.append(' ');
+ buffer.append(resourceUrl);
+ buffer.append('\n');
+ buffer.append(super.toString());
+ return buffer.toString();
+ }
+
+ /**
+ * Writes this request's body to the given output stream. This method may
+ * be called more than once during the lifetime of this request.
+ *
+ * @param os an output stream
+ * @exception IOException if there is an I/O error
+ */
+ public void write(OutputStream os) throws IOException {
+ if (requestBodyWriter == null) {
+ if (inputRead) {
+ is.reset();
+ inputRead = false;
+ }
+ super.write(os);
+ } else {
+ requestBodyWriter.writeRequestBody(os);
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Request.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/RequestInputStream.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/RequestInputStream.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/RequestInputStream.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import org.eclipse.webdav.client.Policy;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A resettable <code>InputStream</code>.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class RequestInputStream extends InputStream {
+ private long length = -1;
+ private long totalBytesRead = 0;
+ private InputStream is = null;
+ private File file = null;
+ private FileOutputStream fos = null;
+ private boolean deleteFile = false;
+
+ /**
+ * Creates a <code>RequestInputStream</code> on the given byte array.
+ *
+ * @param b the underlying byte array
+ */
+ public RequestInputStream(byte[] b) {
+ length = b.length;
+ is = new ByteArrayInputStream(b);
+ }
+
+ /**
+ * Creates a <code>RequestInputStream</code> on the given
+ * <code>ByteArrayInputStream</code>.
+ *
+ * @param bais the underlying input stream
+ */
+ public RequestInputStream(ByteArrayInputStream bais) {
+ Assert.isNotNull(bais);
+ length = bais.available();
+ is = bais;
+ }
+
+ /**
+ * Creates a <code>RequestInputStream</code> on the given file.
+ *
+ * @param file the underlying file
+ * @exception IOException if there is a problem opening the file
+ */
+ public RequestInputStream(File file) throws IOException {
+ Assert.isNotNull(file);
+ length = file.length();
+ is = new FileInputStream(file);
+ this.file = file;
+ }
+
+ /**
+ * Creates a <code>RequestInputStream</code> on the given
+ * <code>InputStream</code>. The length of the stream is set to be the
+ * given length. If the length of the stream is unknown, the given length
+ * must be -1.
+ * <p>Note that to enable reset on streams created using this constructor,
+ * the streams content is written to a temporary file while the stream
+ * is read. This results in a loss of performance, so use this
+ * constructor as a last resort.
+ *
+ * @param is the underlying input stream
+ * @param length the length of the stream, or -1 if the length is unknown
+ * @exception IOException if there is a problem creating or opening the
+ * temporary file
+ */
+ public RequestInputStream(InputStream is, long length) throws IOException {
+ Assert.isNotNull(is);
+ Assert.isTrue(length >= -1);
+ this.length = length;
+ this.is = is;
+ file = File.createTempFile("ris", ".tmp"); //$NON-NLS-1$ //$NON-NLS-2$
+ fos = new FileOutputStream(file);
+ deleteFile = true;
+ }
+
+ /**
+ * @see InputStream#close()
+ */
+ public void close() throws IOException {
+ is.close();
+ if (fos != null)
+ fos.close();
+ if (deleteFile)
+ file.delete();
+ }
+
+ /**
+ * Returns the length of the stream, or -1 if the length of the stream is
+ * unknown. Note the length of the stream is always known once the stream
+ * has been reset.
+ *
+ * @return the length of the stream
+ */
+ public long length() {
+ return length;
+ }
+
+ /**
+ * @see InputStream#read()
+ */
+ public int read() throws IOException {
+ int b = is.read();
+
+ if (b == -1) {
+ if (length != -1 && totalBytesRead < length) {
+ throw new IOException(Policy.bind("exception.unexpectedEndStream")); //$NON-NLS-1$
+ }
+ } else {
+ ++totalBytesRead;
+ if (fos != null) {
+ fos.write(b);
+ }
+ }
+
+ return b;
+ }
+
+ /**
+ * @see InputStream#read(byte[], int, int)
+ */
+ public int read(byte b[], int off, int len) throws IOException {
+ int bytesRead = is.read(b, off, len);
+ if (bytesRead == -1) {
+ if (length != -1 && totalBytesRead < length) {
+ throw new IOException(Policy.bind("exception.unexpectedEndStream")); //$NON-NLS-1$
+ }
+ } else {
+ totalBytesRead += bytesRead;
+ if (fos != null) {
+ fos.write(b, off, len);
+ }
+ }
+ return bytesRead;
+ }
+
+ /**
+ * Resets the stream to its beginning so it can be read again.
+ *
+ * @exception IOException if there is an I/O error
+ */
+ public void reset() throws IOException {
+ if (file == null) {
+ ((ByteArrayInputStream) is).reset();
+ } else {
+ if (fos != null) {
+ while (skip(4096) > 0);
+ fos.close();
+ fos = null;
+ if (length == -1) {
+ length = totalBytesRead;
+ }
+ }
+ is.close();
+ is = new FileInputStream(file);
+ }
+
+ totalBytesRead = 0;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/RequestInputStream.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Response.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Response.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Response.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.http.client;
+
+import java.io.*;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.IResponse;
+import org.eclipse.webdav.internal.kernel.DocumentMarshaler;
+import org.eclipse.webdav.internal.kernel.IDocumentMarshaler;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.w3c.dom.Document;
+
+/**
+ * An HTTP response message.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Response extends Message implements IResponse, IStatusCodes {
+ protected int statusCode;
+ protected String statusMessage;
+ protected boolean hasDocumentBody;
+ protected Document document;
+
+ /**
+ * Creates a response.
+ *
+ * @param context the response's header, or <code>null</code> for an
+ * empty header
+ * @param inputStream an input stream containing the response's body, or
+ * <code>null</code> for an empty body
+ * @param statusCode the response's status code
+ * @param statusMessage the response's status message
+ */
+ public Response(int statusCode, String statusMessage, IContext context, InputStream inputStream) {
+ super(context, inputStream);
+
+ Assert.isTrue(statusCode >= 100 && statusCode < 600);
+ Assert.isNotNull(statusMessage);
+
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
+ this.hasDocumentBody = false;
+
+ // Now determine if the response has a document (XML) body
+ // or is raw bytes.
+ ContentType contentType = getContentType();
+ if (contentType != null) {
+ hasDocumentBody = "xml".equals(contentType.getSubtype()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns the content length of this message's body, or -1 if the
+ * content length is unknown.
+ *
+ * @return the content length of this message's body
+ */
+ public long getContentLength() {
+
+ // Get the declared content length.
+ long contentLength = context.getContentLength();
+
+ // If it is defined send the answer.
+ if (contentLength != -1)
+ return contentLength;
+
+ // Certain messages are defined as having zero length
+ // message bodies.
+ int statusCode = getStatusCode();
+ if (statusCode == IResponse.SC_NO_CONTENT || statusCode == IResponse.SC_NOT_MODIFIED || statusCode >= 100 && statusCode < 200)
+ return 0;
+
+ // We don't know how long the body is.
+ return -1;
+ }
+
+ /**
+ * Returns the content type of this response's body, or <code>null</code>
+ * if the content type is unknown.
+ *
+ * @return the content type of this response's body
+ */
+ public ContentType getContentType() {
+ String contentTypeString = context.getContentType();
+ if (contentTypeString == null)
+ return null;
+ ContentType contentType = null;
+ try {
+ contentType = new ContentType(contentTypeString);
+ } catch (IllegalArgumentException e) {
+ // ignore or log?
+ }
+ return contentType;
+ }
+
+ /**
+ * Returns this response's body as a DOM <code>Document</code>. This
+ * response must have a document body.
+ *
+ * @exception IOException if there is an I/O error
+ */
+ public Document getDocumentBody() throws IOException {
+ Assert.isTrue(hasDocumentBody);
+ Assert.isTrue(!hasInputStream);
+ // Lazily parse the message body.
+ if (document == null) {
+ String characterEncoding = null;
+ ContentType contentType = getContentType();
+ if (contentType != null) {
+ characterEncoding = contentType.getValue("charset"); //$NON-NLS-1$
+ }
+ if (characterEncoding == null) {
+ characterEncoding = "ASCII"; //$NON-NLS-1$
+ }
+ IDocumentMarshaler marshaler = new DocumentMarshaler();
+ document = marshaler.parse(new InputStreamReader(is, characterEncoding));
+ }
+ return document;
+ }
+
+ /**
+ * Returns this response's status code.
+ *
+ * @return this response's status code
+ */
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * Returns this response's status message.
+ *
+ * @return this response's status message
+ */
+ public String getStatusMessage() {
+ return statusMessage;
+ }
+
+ /**
+ * Returns a boolean indicating whether this response has a body that can
+ * be marshaled to become a DOM <code>Document</code>.
+ *
+ * @return a boolean indicating whether this response has a body that can
+ * be marshaled to become a DOM <code>Document</code>
+ * @see Document
+ */
+ public boolean hasDocumentBody() {
+ return hasDocumentBody;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(statusCode);
+ buffer.append(' ');
+ buffer.append(statusMessage);
+ buffer.append('\n');
+ buffer.append(super.toString());
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/Response.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/package.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/package.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/package.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides support for the HTTP protocol.
+<h2>
+Package Specification</h2>
+This package defines a set of classes which enable clients to talk to HTTP servers.
+</body>
+</html>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/http/client/package.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticateChallenge.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticateChallenge.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticateChallenge.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.util.Hashtable;
+import org.eclipse.webdav.client.Policy;
+
+/**
+ * Parses the HTTP "WWW-Authenticate" and "Proxy-Authenticate" header
+ * fields. These header fields have the following form:
+ *
+ * <code>
+ * challenge = auth-scheme 1*SP 1#auth-param
+ * auth-scheme = token
+ * auth-param = token "=" ( token | quoted-string )
+ * </code>
+ *
+ * The authentication parameter realm is defined for all authentication
+ * schemes:
+ *
+ * <code>
+ * realm = "realm" "=" realm-value
+ * realm-value = quoted-string
+ * </code>
+ *
+ * A challenge may look like this:
+ *
+ * <code>
+ * WWW-Authenticate: Digest
+ * realm="testrealm at host.com",
+ * qop="auth,auth-int",
+ * nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
+ * opaque="5ccc069c403ebaf9f0171e9517f40e41"
+ * </code>
+ */
+public class AuthenticateChallenge {
+ private String challenge;
+ private Parser parser;
+
+ private String authScheme;
+ private Hashtable authParams;
+
+ /**
+ * Parses the given authenticate challenge.
+ *
+ * @param challenge
+ * @throws ParserException if the challenge is malformed
+ */
+ public AuthenticateChallenge(String challenge) throws ParserException {
+ this.challenge = challenge;
+ this.parser = new Parser(challenge);
+ parse();
+ }
+
+ /**
+ * Returns the value of the given authentication parameter, or
+ * <code>null</code> if the param does not exist.
+ */
+ public String get(String param) {
+ return (String) authParams.get(param);
+ }
+
+ /**
+ * Returns the authentication scheme. For example, "Basic" or "Digest".
+ */
+ public String getAuthScheme() {
+ return authScheme;
+ }
+
+ /**
+ * Returns the authenticate challenge, unparsed.
+ */
+ public String getChallenge() {
+ return challenge;
+ }
+
+ /**
+ * Returns the realm authentication parameter, which must exist.
+ */
+ public String getRealm() {
+ return get("realm"); //$NON-NLS-1$
+ }
+
+ private void parse() throws ParserException {
+ authParams = new Hashtable(5);
+ authScheme = parser.nextToken();
+ parser.skipWhiteSpace();
+
+ boolean done = false;
+ while (!done) {
+ String param = parser.nextToken();
+ parser.match('=');
+ String value = null;
+ parser.checkPosition();
+ if (challenge.charAt(parser.pos) == '"') { //$NON-NLS-1$
+ value = parser.nextQuotedString();
+ } else {
+ value = parser.nextToken();
+ }
+ authParams.put(param, value);
+ parser.skipWhiteSpace();
+ done = parser.pos == challenge.length();
+ if (!done) {
+ parser.match(',');
+ parser.skipWhiteSpace();
+ }
+ }
+
+ if (getRealm() == null) {
+ throw new ParserException(Policy.bind("exception.missingRealm")); //$NON-NLS-1$
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticateChallenge.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticationInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticationInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticationInfo.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.util.Hashtable;
+import org.eclipse.webdav.client.Policy;
+
+/**
+ * Parses the HTTP "Authentication-Info" header field. The header field
+ * has the following form:
+ *
+ * <code>
+ * auth-info = 1#(nextnonce | [ message-qop ]
+ * | [ response-auth ] | [ cnonce ]
+ * | [ nonce-count ] )
+ * nextnonce = "nextnonce" "=" nonce-value
+ * nonce-value = quoted-string
+ * message-qop = "qop" "=" qop-value
+ * qop-value = "auth" | "auth-int" | token
+ * response-auth = "rspauth" "=" response-digest
+ * response-digest = <"> *LHEX <">
+ * cnonce = "cnonce" "=" cnonce-value
+ * cnonce-value = nonce-value
+ * nonce-count = "nc" "=" nc-value
+ * nc-value = 8LHEX
+ * </code>
+ *
+ * An auth-info may look like this:
+ *
+ * <code>
+ * Authentication-Info:
+ * nextnonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
+ * qop="auth",
+ * rspauth="5ccc069c403ebaf9f0171e9517f40e41",
+ * cnonce="0a4f113b",
+ * nc=00000001
+ * </code>
+ */
+public class AuthenticationInfo {
+ private String authInfo;
+ private Parser parser;
+ private Hashtable info;
+
+ /**
+ * Parses the given authentication info.
+ *
+ * @param authInfo
+ * @throws ParserException if the info is malformed
+ */
+ public AuthenticationInfo(String authInfo) throws ParserException {
+ this.authInfo = authInfo;
+ this.parser = new Parser(authInfo);
+ parse();
+ }
+
+ /**
+ * Returns the value of the cnonce parameter, or <code>null</code> if
+ * the parameter does not exist.
+ */
+ public String getCNonce() {
+ return (String) info.get("cnonce"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the value of the qop parameter, or <code>null</code> if
+ * the parameter does not exist.
+ */
+ public String getMessageQop() {
+ return (String) info.get("qop"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the value of the nextnonce parameter, which must exist.
+ */
+ public String getNextNonce() {
+ return (String) info.get("nextnonce"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the value of the nc parameter, or <code>null</code> if
+ * the parameter does not exist.
+ */
+ public String getNonceCount() {
+ return (String) info.get("nc"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the value of the rspauth parameter, or <code>null</code> if
+ * the parameter does not exist.
+ */
+ public String getResponseAuth() {
+ return (String) info.get("rspauth"); //$NON-NLS-1$
+ }
+
+ private void parse() throws ParserException {
+ info = new Hashtable(5);
+
+ boolean done = false;
+ while (!done) {
+ String param = parser.nextToken();
+ parser.match('=');
+ String value = null;
+ parser.checkPosition();
+ if (authInfo.charAt(parser.pos) == '"') { //$NON-NLS-1$
+ value = parser.nextQuotedString();
+ } else {
+ value = parser.nextToken();
+ }
+ info.put(param, value);
+ parser.skipWhiteSpace();
+ done = parser.pos == authInfo.length();
+ if (!done) {
+ parser.match(',');
+ parser.skipWhiteSpace();
+ }
+ }
+
+ if (getNextNonce() == null) {
+ throw new ParserException(Policy.bind("exception.missingNextnonce")); //$NON-NLS-1$
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthenticationInfo.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthorizationAuthority.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthorizationAuthority.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthorizationAuthority.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,355 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.IResponse;
+import org.eclipse.webdav.http.client.IAuthenticator;
+import org.eclipse.webdav.http.client.Request;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * The <code>AuthorizationAuthority</code> authorizes client
+ * <code>Request</codes>s for communication with HTTP servers. Subclasses
+ * provide the necessary behavior for different authentication schemes.
+ */
+public class AuthorizationAuthority {
+
+ public static String[] authenticationSchemes = {"Digest", "Basic"}; //$NON-NLS-1$ //$NON-NLS-2$
+ protected IAuthenticator authenticatorStore = null;
+
+ /**
+ * Creates a new authenticator that stores its authentication information
+ * in the given authenticator store.
+ *
+ * @param authenticatorStore a store that holds authentication
+ * information
+ */
+ public AuthorizationAuthority(IAuthenticator authenticatorStore) {
+ Assert.isNotNull(authenticatorStore);
+ this.authenticatorStore = authenticatorStore;
+ }
+
+ /**
+ * Authorizes the given request by setting its authorization credentials
+ * in the given context. If the given response is not <code>null</code>,
+ * it is assumed to contain an authenticate challenge that is used to
+ * derive the authorization credentials. Returns true if the authorization
+ * succeeds, and false otherwise.
+ *
+ * @param request the request to authorize
+ * @param response the response containing the authenticate challenge
+ * @param context the context where the authorization credentials are set
+ * @param proxyServerUrl the URL of the proxy server, or <code>null</code>
+ * if there is no proxy server
+ * @param isProxyAuthorization a boolean indicating whether the
+ * authorization credentials should be computed for the proxy server or
+ * the origin server
+ * @return a boolean indicating whether the request was successfully
+ * authorized
+ */
+ public boolean authorize(Request request, IResponse response, IContext context, URL proxyServerUrl, boolean isProxyAuthorization) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(context);
+
+ URL serverUrl = null;
+ URL protectionSpaceUrl = null;
+
+ if (isProxyAuthorization) {
+ if (proxyServerUrl == null) {
+ return false;
+ }
+ serverUrl = proxyServerUrl;
+ protectionSpaceUrl = proxyServerUrl;
+ } else {
+ URL resourceUrl = request.getResourceUrl();
+ try {
+ serverUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ protectionSpaceUrl = resourceUrl;
+ }
+
+ if (response != null) {
+ String challengeString = null;
+ if (isProxyAuthorization) {
+ challengeString = response.getContext().getProxyAuthenticate();
+ } else {
+ challengeString = response.getContext().getWWWAuthenticate();
+ }
+
+ if (challengeString == null) {
+ return false;
+ }
+
+ AuthenticateChallenge challenge = null;
+ try {
+ challenge = new AuthenticateChallenge(challengeString);
+ } catch (ParserException e) {
+ return false;
+ }
+
+ String authScheme = challenge.getAuthScheme();
+ String realm = challenge.getRealm();
+
+ AuthorizationAuthority authority = getAuthorizationAuthority(authScheme);
+ if (authority == null) {
+ return false;
+ }
+
+ Map oldInfo = authenticatorStore.getAuthenticationInfo(serverUrl, realm, authScheme);
+ Map info = authority.getAuthenticationInfo(challenge, oldInfo, serverUrl, protectionSpaceUrl);
+ if (info == null) {
+ return false;
+ }
+
+ authenticatorStore.addAuthenticationInfo(serverUrl, realm, authScheme, info);
+ authenticatorStore.addProtectionSpace(protectionSpaceUrl, realm);
+ }
+
+ String realm = authenticatorStore.getProtectionSpace(protectionSpaceUrl);
+ if (realm == null) {
+ return false;
+ }
+
+ Map info = null;
+ String authScheme = null;
+
+ for (int i = 0; i < authenticationSchemes.length; ++i) {
+ authScheme = authenticationSchemes[i];
+ info = authenticatorStore.getAuthenticationInfo(serverUrl, realm, authScheme);
+ if (info != null) {
+ break;
+ }
+ }
+
+ if (info == null) {
+ return false;
+ }
+
+ AuthorizationAuthority authority = getAuthorizationAuthority(authScheme);
+ if (authority == null) {
+ return false;
+ }
+
+ String authorization = authority.getAuthorization(request, info, serverUrl, protectionSpaceUrl, proxyServerUrl);
+ if (authorization == null) {
+ return false;
+ }
+
+ if (isProxyAuthorization) {
+ if (authorization.equals(context.getProxyAuthorization()))
+ return false; // we already had that auth so it must've failed
+ context.setProxyAuthorization(authorization);
+ } else {
+ if (authorization.equals(context.getAuthorization()))
+ return false; // we already had that auth so it must've failed
+ context.setAuthorization(authorization);
+ }
+
+ return true;
+ }
+
+ /**
+ * Confirms whether the given response is valid by proving the server
+ * knows the client's authentication secret (password). Moreover, the
+ * server may wish to communicate some authentication information in the
+ * response for the purposes of authorizing future request.
+ *
+ * @param request the request that has already been sent
+ * @param response the response back from the server to be verified
+ * @param proxyServerUrl the URL of the proxy server, or <code>null</code>
+ * if there is none
+ * @returns a boolean indicating whether the given response is valid
+ */
+ public boolean confirm(Request request, IResponse response, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(response);
+
+ URL resourceUrl = request.getResourceUrl();
+
+ URL serverUrl = null;
+ try {
+ serverUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ return false;
+ }
+
+ String realm = authenticatorStore.getProtectionSpace(resourceUrl);
+ if (realm == null) {
+ return false;
+ }
+
+ Map info = null;
+ String authScheme = null;
+
+ for (int i = 0; i < authenticationSchemes.length; ++i) {
+ authScheme = authenticationSchemes[i];
+ info = authenticatorStore.getAuthenticationInfo(serverUrl, realm, authScheme);
+ if (info != null) {
+ break;
+ }
+ }
+
+ if (info == null) {
+ return false;
+ }
+
+ AuthorizationAuthority authority = getAuthorizationAuthority(authScheme);
+ if (authority == null) {
+ return false;
+ }
+
+ return authority.confirmResponse(request, response, proxyServerUrl);
+ }
+
+ /**
+ * Confirms whether the given response is valid by proving the server
+ * knows the client's authentication secret (password). Moreover, the
+ * server may wish to communicate some authentication information in the
+ * response for the purposes of authorizing future request.
+ * <p>This method should be overridden by schema specific authenticators.
+ *
+ * @param request the request that has already been sent
+ * @param response the response back from the server to be verified
+ * @param proxyServerUrl the URL of the proxy server, or <code>null</code>
+ * if there is none
+ * @returns a boolean indicating whether the given response is valid
+ */
+ protected boolean confirmResponse(Request request, IResponse response, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(response);
+ return false;
+ }
+
+ /**
+ * Returns the new authentication information gleaned from the given
+ * authenticate challenge and the given old authentication information.
+ * The old authentication information may be <code>null</code>.
+ * The authentication information usually contains directives such as
+ * usernames and passwords.
+ * <p>This method should be overridden by schema specific authenticators.
+ *
+ * @param challenge the authenticate challenge from the server
+ * @param oldInfo the old authentication information
+ * @param serverUrl the URL of the server
+ * @param protectionSpaceUrl the URL of the protected resource
+ * @return new authentication information
+ */
+ protected Map getAuthenticationInfo(AuthenticateChallenge challenge, Map oldInfo, URL serverUrl, URL protectionSpaceUrl) {
+ Assert.isNotNull(challenge);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+ return null;
+ }
+
+ /**
+ * Returns the authorization credentials for the given request. The
+ * authorization credentials are derived from the given authentication
+ * info. The authentication info may contain directives such as usernames
+ * and passwords.
+ * <p>This method should be overridden by schema specific authenticators.
+ *
+ * @param request the request being authorized
+ * @param info the authentication information used to derive the
+ * authorization credentials
+ * @param serverUrl the URL of the server
+ * @param protectionSpaceUrl the URL of the protected resource
+ * @param proxyServerUrl the URL of the proxy server, or <code>null</code>
+ * if there is none
+ * @return the authorization credentials for the given request
+ */
+ protected String getAuthorization(Request request, Map info, URL serverUrl, URL protectionSpaceUrl, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(info);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+ return null;
+ }
+
+ /**
+ * Returns an authorization authority for the given authentication
+ * scheme, or <code>null</code> if there is no such authority.
+ *
+ * @param scheme an authentication scheme, for example: "Basic"
+ * @return an authorization authority for the given authentication scheme
+ */
+ private AuthorizationAuthority getAuthorizationAuthority(String scheme) {
+ try {
+ scheme = Character.toUpperCase(scheme.charAt(0)) + scheme.substring(1).toLowerCase();
+ String packageName = "org.eclipse.webdav.internal.authentication"; //$NON-NLS-1$
+ String className = scheme + "Authority"; //$NON-NLS-1$
+ Class clazz = Class.forName(packageName + "." + className); //$NON-NLS-1$
+ Constructor constructor = clazz.getConstructor(new Class[] {IAuthenticator.class});
+ return (AuthorizationAuthority) constructor.newInstance(new Object[] {authenticatorStore});
+ } catch (ClassCastException e) {
+ // ignore or log?
+ } catch (Exception e) {
+ // ignore or log?
+ }
+ return null;
+ }
+
+ /**
+ * Computes the MD5 hash value of the given <code>String</code> and
+ * returns the result as a HEX <code>String</code>.
+ *
+ * @param s
+ * @return a HEX <code>String</code> containing the MD5 hash value of the
+ * given <code>String</code>
+ * @exception NoSuchAlgorithmException
+ * @exception UnsupportedEncodingException
+ */
+ protected String md5(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException {
+ MessageDigest md5 = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
+ byte[] hash = md5.digest(s.getBytes("UTF8")); //$NON-NLS-1$
+ return HexConverter.toHex(hash);
+ }
+
+ /**
+ * Computes the MD5 hash value of the body of the given request and
+ * returns the result as a HEX <code>String</code>.
+ *
+ * @param request
+ * @return a HEX <code>String</code> containing the MD5 hash value of the
+ * body of the given request
+ * @exception NoSuchAlgorithmException
+ * @exception IOException
+ */
+ protected String md5(Request request) throws NoSuchAlgorithmException, IOException {
+ DigestOutputStream dos = new DigestOutputStream("MD5"); //$NON-NLS-1$
+ request.write(dos);
+ String result = HexConverter.toHex(dos.digest());
+ dos.close();
+ return result;
+ }
+
+ /**
+ * Returns the given <code>String</code> with its quotes removed.
+ *
+ * @param s a <code>String</code>
+ * @return the given <code>String</code> with its quotes removed
+ */
+ protected String unquote(String s) {
+ if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') //$NON-NLS-1$ //$NON-NLS-2$
+ return s.substring(1, s.length() - 1);
+ return s;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/AuthorizationAuthority.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * This class implements a BASE64 character encoder as specified in
+ * RFC1521.
+ */
+public final class Base64Encoder {
+ /**
+ * Returns the BASE64 encoded <code>String</code> of the given data.
+ *
+ * @param data the bytes to be BASE64 encoded
+ * @return the BASE64 encoded <code>String</code> of the given data
+ */
+ public static String encode(byte[] data) {
+ Assert.isNotNull(data);
+
+ StringBuffer buf = new StringBuffer();
+
+ byte b = 0;
+ int bits = 2;
+
+ for (int i = 0; i < data.length; ++i) {
+ b = (byte) ((b | (data[i] >> bits)) & 0x003f);
+ buf.append(encode(b));
+ b = (byte) ((data[i] << 6 - bits) & 0x003f);
+ bits += 2;
+ if (bits == 8) {
+ buf.append(encode((byte) (b & 0x003f)));
+ b = 0;
+ bits = 2;
+ }
+ }
+
+ if (bits == 4) {
+ buf.append(encode(b));
+ buf.append("=="); //$NON-NLS-1$
+ } else if (bits == 6) {
+ buf.append(encode(b));
+ buf.append('=');
+ }
+
+ return buf.toString();
+ }
+
+ private static char encode(byte b) {
+ if (b >= 0 && b <= 25)
+ return (char) (b + 65);
+ if (b >= 26 && b <= 51)
+ return (char) (b + 71);
+ if (b >= 52 && b <= 61)
+ return (char) (b - 4);
+ if (b == 62)
+ return '+';
+ if (b == 63)
+ return '/';
+ return '=';
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Base64Encoder.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/BasicAuthority.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/BasicAuthority.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/BasicAuthority.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.io.UnsupportedEncodingException;
+import java.net.Authenticator;
+import java.net.URL;
+import java.util.Map;
+import org.eclipse.webdav.http.client.IAuthenticator;
+import org.eclipse.webdav.http.client.Request;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * The <code>BasicAuthority</code> provides the necessary behavior to
+ * authorizes client <code>Request</codes>s for communication with HTTP
+ * servers using the Basic authentication scheme.
+ *
+ * @see AuthorizationAuthority
+ */
+public class BasicAuthority extends AuthorizationAuthority {
+
+ /**
+ * Creates a new authenticator that stores its authentication information
+ * in the given authentication store.
+ * <p>The <code>BasicAuthenticator</code> authenticates according to the
+ * "Basic" authentication scheme.
+ * <p>Instances of this class must not be created directly, instead, use
+ * an instance of the class <code>Authenticator</code> to authorize
+ * requests.
+ *
+ * @param authenticationStore a store that holds authentication
+ * information
+ */
+ public BasicAuthority(IAuthenticator authenticationStore) {
+ super(authenticationStore);
+ }
+
+ /**
+ * Returns the Basic authorization credentials for the given username and
+ * password. The credentials have the following form:
+ * <code>
+ * credentials = "Basic" basic-credentials
+ * basic-credentials = base64-user-pass
+ * base64-user-pass = <base64 encoding of user-pass, except not
+ * limited to 76 char/line>
+ * user-pass = userid ":" password
+ * userid = *<TEXT excluding ":">
+ * password = *TEXT
+ * </code>
+ * <P>Userids might be case sensitive.
+ * <P>For example, if the user's name is "Aladdin" and the user's
+ * password is "open sesame", the following credentials are supplied:
+ * <code>
+ * Basic QWxhZGRpbjpvcGVuIHN1c2FtZQ==
+ * </code>
+ * @param username
+ * @param password
+ * @return the Basic authorization credentials for the given
+ * username and password
+ */
+ private String credentials(String username, String password) {
+ Assert.isNotNull(username);
+ Assert.isNotNull(password);
+
+ String userpass = username + ":" + password; //$NON-NLS-1$
+ byte[] data = null;
+
+ try {
+ data = userpass.getBytes("UTF8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ data = userpass.getBytes();
+ }
+
+ return "Basic " + Base64Encoder.encode(data); //$NON-NLS-1$
+ }
+
+ /**
+ * @see Authenticator#getAuthenticationInfo(AuthenticateChallenge, Map, URL, URL)
+ */
+ protected Map getAuthenticationInfo(AuthenticateChallenge challenge, Map oldInfo, URL serverUrl, URL protectionSpaceUrl) {
+ Assert.isNotNull(challenge);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+
+ return authenticatorStore.requestAuthenticationInfo(protectionSpaceUrl, challenge.getRealm(), challenge.getAuthScheme());
+ }
+
+ /**
+ * @see Authenticator#getAuthorization(Request, Map, URL, URL, URL)
+ */
+ protected String getAuthorization(Request request, Map info, URL serverUrl, URL protectionSpaceUrl, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(info);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+
+ String username = (String) info.get("username"); //$NON-NLS-1$
+ String password = (String) info.get("password"); //$NON-NLS-1$
+
+ if (username == null || password == null) {
+ return null;
+ }
+ return credentials(username, password);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/BasicAuthority.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestAuthority.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestAuthority.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestAuthority.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,538 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ * Boris Pruessmann - Patch for bug 22374
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.net.*;
+import java.security.SecureRandom;
+import java.util.*;
+import org.eclipse.webdav.IResponse;
+import org.eclipse.webdav.client.Policy;
+import org.eclipse.webdav.http.client.*;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * The <code>DigestAuthority</code> provides the necessary behavior to
+ * authorizes client <code>Request</codes>s for communication with HTTP
+ * servers using the Digest authentication scheme.
+ *
+ * @see AuthorizationAuthority
+ */
+public class DigestAuthority extends AuthorizationAuthority {
+
+ /**
+ * Creates a new authenticator that stores its authentication information
+ * in the given authentication store.
+ * <p>The <code>DigestAuthenticator</code> authenticates according to the
+ * "Digest" authentication scheme.
+ * <p>Instances of this class must not be created directly, instead, use
+ * an instance of the class <code>Authenticator</code> to authorize
+ * requests.
+ *
+ * @param authenticatorStore a store that holds authentication
+ * information
+ */
+ public DigestAuthority(IAuthenticator authenticatorStore) {
+ super(authenticatorStore);
+ }
+
+ /**
+ * @see Authenticator#confirmResponse(Request, Response, URL)
+ */
+ protected boolean confirmResponse(Request request, IResponse response, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(response);
+
+ String authInfoString = response.getContext().get("Authentication-Info"); //$NON-NLS-1$
+ if (authInfoString == null) {
+ return false;
+ }
+
+ AuthenticationInfo authInfo = null;
+ try {
+ authInfo = new AuthenticationInfo(authInfoString);
+ } catch (ParserException e) {
+ return false;
+ }
+
+ String nextNonce = authInfo.getNextNonce();
+ String messageQop = authInfo.getMessageQop();
+ String responseAuth = authInfo.getResponseAuth();
+ String cnonce = authInfo.getCNonce();
+ String nonceCount = authInfo.getNonceCount();
+
+ URL resourceUrl = request.getResourceUrl();
+ URL serverUrl = null;
+ try {
+ serverUrl = new URL(resourceUrl.getProtocol(), resourceUrl.getHost(), resourceUrl.getPort(), "/"); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ return false;
+ }
+
+ String realm = authenticatorStore.getProtectionSpace(resourceUrl);
+ if (realm == null) {
+ return false;
+ }
+
+ Map info = authenticatorStore.getAuthenticationInfo(serverUrl, realm, "Digest"); //$NON-NLS-1$
+ if (info == null) {
+ return false;
+ }
+
+ String username = (String) info.get("username"); //$NON-NLS-1$
+ String password = (String) info.get("password"); //$NON-NLS-1$
+ String algorithm = (String) info.get("algorithm"); //$NON-NLS-1$
+ String nonce = (String) info.get("nonce"); //$NON-NLS-1$
+ String iNonceCount = (String) info.get("nc"); //$NON-NLS-1$
+ String iCnonce = (String) info.get("cnonce"); //$NON-NLS-1$
+
+ if (username == null || password == null || nonce == null) {
+ return false;
+ }
+
+ if (cnonce != null && !cnonce.equals(iCnonce)) {
+ return false;
+ }
+
+ if (nonceCount != null && !nonceCount.equals(iNonceCount)) {
+ return false;
+ }
+
+ if (responseAuth != null) {
+ try {
+ String digestUri = resourceUrl.toString();
+ if (proxyServerUrl == null) {
+ digestUri = resourceUrl.getFile();
+ String ref = resourceUrl.getRef();
+ if (ref != null) {
+ digestUri += "#" + ref; //$NON-NLS-1$
+ }
+ }
+ String iResponseAuth = response(request, realm, username, password, algorithm, messageQop, nonce, nonceCount, cnonce, request.getMethod(), digestUri);
+ if (!responseAuth.equals(iResponseAuth)) {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ info.put("nonce", nextNonce); //$NON-NLS-1$
+
+ return true;
+ }
+
+ /**
+ * Returns the Digest authorization credentials for the given directives.
+ * The credentials have the following form:
+ * <code>
+ * credentials = "Digest" digest-response
+ * digest-response = 1#( username | realm | nonce | digest-uri
+ * | response | [ algorithm ] | [cnonce] |
+ * [opaque] | [message-qop] |
+ * [nonce-count] | [auth-param] )
+ * username = "username" "=" username-value
+ * username-value = quoted-string
+ * realm = "realm" "=" realm-value
+ * realm-value = quoted-string
+ * nonce = "nonce" "=" nonce-value
+ * nonce-value = quoted-string
+ * digest-uri = "uri" "=" digest-uri-value
+ * digest-uri-value = request-uri ; As specified by HTTP/1.1
+ * response = "response" "=" request-digest
+ * request-digest = <"> 32LHEX <">
+ * LHEX = "0" | "1" | "2" | "3" |
+ * "4" | "5" | "6" | "7" |
+ * "8" | "9" | "a" | "b" |
+ * "c" | "d" | "e" | "f"
+ * algorithm = "algorithm" "=" ("MD5" | "MD5-sess" | token)
+ * cnonce = "cnonce" "=" cnonce-value
+ * cnonce-value = nonce-value
+ * opaque = "opaque" "=" quoted-string
+ * message-qop = "qop" "=" qop-value
+ * nonce-count = "nc" "=" nc-value
+ * nc-value = 8LHEX
+ * </code>
+ * <P>If the "qop" value is "auth" or "auth-int":
+ * <code>
+ * request-digest = <"> < KD ( H(A1), unq(nonce-value)
+ * ":" nc-value
+ * ":" unq(cnonce-value)
+ * ":" unq(qop-value)
+ * ":" H(A2)
+ * ) <">
+ * KD(secret, data) = H(concat(secret, ":", data))
+ * H(data) = MD5(data)
+ * unq(data) = unqouted(data)
+ * </code>
+ * <P>If the "qop" directive is not present:
+ * <code>
+ * request-digest = <"> < KD ( H(A1),
+ * unq(nonce-value)
+ * ":" H(A2)
+ * ) <">
+ * </code>
+ * <P>If the "algorithm" directive's value is "MD5" or is unspecified,
+ * then A1 is:
+ * <code>
+ * A1 = unq(username-value) ":" unq(realm-value) ":" passwd
+ * passwd = < user's password >
+ * </code>
+ * <P>If the "algorithm" directive's value is "MD5-sess", then A1 is:
+ * <code>
+ * A1 = H( unq(username-value) ":" unq(realm-value)
+ * ":" passwd )
+ * ":" unq(nonce-value) ":" unq(cnonce-value)
+ * </code>
+ * <P>If the "qop" directive's value is "auth" or is unspecified, then
+ * A2 is:
+ * <code>
+ * A2 = Method ":" digest-uri-value
+ * </code>
+ * <P>If the "qop" value is "auth-int", then A2 is:
+ * <code>
+ * A2 = Method ":" digest-uri-value ":" H(entity-body)
+ * </code>
+ * @param request
+ * @param realm
+ * @param username
+ * @param password
+ * @param algorithm
+ * @param messageQop
+ * @param nonce
+ * @param nonceCount
+ * @param opaque
+ * @param cnonce
+ * @param method
+ * @param digestUri
+ * @return the Digest authorization credentials for the given
+ * directives
+ */
+ private String credentials(Request request, String realm, String username, String password, String algorithm, String messageQop, String nonce, String nonceCount, String opaque, String cnonce, String method, String digestUri) throws Exception {
+ Assert.isNotNull(request);
+ Assert.isNotNull(realm);
+ Assert.isNotNull(username);
+ Assert.isNotNull(password);
+ Assert.isNotNull(nonce);
+ Assert.isNotNull(method);
+ Assert.isNotNull(digestUri);
+
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("Digest username=\""); //$NON-NLS-1$
+ buf.append(username);
+ buf.append("\""); //$NON-NLS-1$
+
+ buf.append(", realm="); //$NON-NLS-1$
+ buf.append(realm);
+
+ if (messageQop != null) {
+ buf.append(", qop=\""); //$NON-NLS-1$
+ buf.append(messageQop);
+ buf.append("\""); //$NON-NLS-1$
+ }
+
+ if (algorithm != null) {
+ buf.append(", algorithm="); //$NON-NLS-1$
+ buf.append(algorithm);
+ }
+
+ buf.append(", uri=\""); //$NON-NLS-1$
+ buf.append(digestUri);
+ buf.append("\""); //$NON-NLS-1$
+
+ buf.append(", nonce="); //$NON-NLS-1$
+ buf.append(nonce);
+
+ if (nonceCount != null) {
+ buf.append(", nc="); //$NON-NLS-1$
+ buf.append(nonceCount);
+ }
+
+ if (cnonce != null) {
+ buf.append(", cnonce=\""); //$NON-NLS-1$
+ buf.append(cnonce);
+ buf.append("\""); //$NON-NLS-1$
+ }
+
+ if (opaque != null) {
+ buf.append(", opaque="); //$NON-NLS-1$
+ buf.append(opaque);
+ }
+
+ String response = response(request, realm, username, password, algorithm, messageQop, nonce, nonceCount, cnonce, method, digestUri);
+ if (response == null) {
+ return null;
+ }
+
+ buf.append(", response=\""); //$NON-NLS-1$
+ buf.append(response);
+ buf.append("\""); //$NON-NLS-1$
+
+ return buf.toString();
+ }
+
+ /**
+ * @see Authenticator#getAuthenticationInfo(AuthenticateChallenge, Map, URL, URL)
+ */
+ protected Map getAuthenticationInfo(AuthenticateChallenge challenge, Map oldInfo, URL serverUrl, URL protectionSpaceUrl) {
+ Assert.isNotNull(challenge);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+
+ Hashtable info = new Hashtable(5);
+
+ String stale = challenge.get("stale"); //$NON-NLS-1$
+ if (oldInfo == null || stale == null || !Boolean.valueOf(stale).booleanValue()) {
+ Map userpass = authenticatorStore.requestAuthenticationInfo(protectionSpaceUrl, challenge.getRealm(), challenge.getAuthScheme());
+ if (userpass == null) {
+ return null;
+ }
+ info.put("username", userpass.get("username")); //$NON-NLS-1$ //$NON-NLS-2$
+ info.put("password", userpass.get("password")); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ info.put("username", oldInfo.get("username")); //$NON-NLS-1$ //$NON-NLS-2$
+ info.put("password", oldInfo.get("password")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ String realm = challenge.getRealm();
+ String domain = challenge.get("domain"); //$NON-NLS-1$
+
+ boolean addRoot = true;
+ if (domain != null && domain.charAt(0) == '"' //$NON-NLS-1$
+ && domain.charAt(domain.length() - 1) == '"') { //$NON-NLS-1$
+ int start = 1;
+ boolean inSpace = false;
+ for (int i = 1; i < domain.length(); ++i) {
+ if (Character.isWhitespace(domain.charAt(i)) || i == domain.length() - 1) {
+ if (!inSpace) {
+ inSpace = true;
+ String urlString = domain.substring(start, i);
+ URL url = null;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e1) {
+ try {
+ url = new URL(serverUrl, urlString);
+ } catch (MalformedURLException e2) {
+ // ignore or log?
+ }
+ }
+ if (url != null) {
+ authenticatorStore.addProtectionSpace(url, realm);
+ addRoot = false;
+ }
+ }
+ } else {
+ if (inSpace) {
+ inSpace = false;
+ start = i;
+ }
+ }
+ }
+ }
+
+ if (addRoot) {
+ authenticatorStore.addProtectionSpace(serverUrl, realm);
+ }
+
+ String nonce = challenge.get("nonce"); //$NON-NLS-1$
+ if (nonce == null) {
+ return null;
+ }
+ info.put("nonce", nonce); //$NON-NLS-1$
+
+ String opaque = challenge.get("opaque"); //$NON-NLS-1$
+ if (opaque != null) {
+ info.put("opaque", opaque); //$NON-NLS-1$
+ }
+
+ String algorithm = challenge.get("algorithm"); //$NON-NLS-1$
+ if (algorithm != null) {
+ info.put("algorithm", algorithm); //$NON-NLS-1$
+ }
+
+ String qop = challenge.get("qop"); //$NON-NLS-1$
+ if (qop != null && qop.charAt(0) == '"' //$NON-NLS-1$
+ && qop.charAt(qop.length() - 1) == '"') { //$NON-NLS-1$
+ boolean foundAuth = false;
+ boolean foundAuthInt = false;
+
+ try {
+ String token = null;
+ boolean first = true;
+ Parser parser = new Parser(qop.substring(1, qop.length() - 1));
+ while (parser.pos < parser.s.length()) {
+ if (first) {
+ parser.skipWhiteSpace();
+ first = false;
+ } else {
+ parser.match(',');
+ parser.skipWhiteSpace();
+ }
+ token = parser.nextToken();
+ if (token.equalsIgnoreCase("auth")) { //$NON-NLS-1$
+ foundAuth = true;
+ } else if (token.equalsIgnoreCase("auth-int")) { //$NON-NLS-1$
+ foundAuthInt = true;
+ }
+ parser.skipWhiteSpace();
+ }
+ } catch (ParserException e) {
+ // ignore or log?
+ }
+
+ if (foundAuthInt) {
+ info.put("qop", "auth-int"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (foundAuth) {
+ info.put("qop", "auth"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ return info;
+ }
+
+ /**
+ * @see Authenticator#getAuthorization(Request, Map, URL, URL, URL)
+ */
+ protected String getAuthorization(Request request, Map info, URL serverUrl, URL protectionSpaceUrl, URL proxyServerUrl) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(info);
+ Assert.isNotNull(serverUrl);
+ Assert.isNotNull(protectionSpaceUrl);
+
+ String username = (String) info.get("username"); //$NON-NLS-1$
+ String password = (String) info.get("password"); //$NON-NLS-1$
+ String algorithm = (String) info.get("algorithm"); //$NON-NLS-1$
+ String messageQop = (String) info.get("qop"); //$NON-NLS-1$
+ String nonce = (String) info.get("nonce"); //$NON-NLS-1$
+ String nonceCount = (String) info.get("nc"); //$NON-NLS-1$
+ String opaque = (String) info.get("opaque"); //$NON-NLS-1$
+ String cnonce = null;
+
+ if (username == null || password == null || nonce == null) {
+ return null;
+ }
+
+ if (messageQop != null) {
+ if (nonceCount == null) {
+ nonceCount = "00000001"; //$NON-NLS-1$
+ } else {
+ int nc = Integer.parseInt(nonceCount, 16) + 1;
+ nonceCount = HexConverter.toHex(new int[] {nc});
+ }
+ info.put("nc", nonceCount); //$NON-NLS-1$
+
+ long milliseconds = new Date().getTime();
+ SecureRandom random = new SecureRandom();
+ random.setSeed(milliseconds);
+ byte[] bytes = new byte[16];
+ random.nextBytes(bytes);
+ cnonce = HexConverter.toHex(bytes);
+ info.put("cnonce", cnonce); //$NON-NLS-1$
+ }
+
+ String realm = authenticatorStore.getProtectionSpace(protectionSpaceUrl);
+ if (realm == null) {
+ return null;
+ }
+
+ String method = request.getMethod();
+ URL resourceUrl = request.getResourceUrl();
+ String digestUri = resourceUrl.toString();
+ if (proxyServerUrl != null) {
+ digestUri = resourceUrl.getFile();
+ String ref = resourceUrl.getRef();
+ if (ref != null) {
+ digestUri += "#" + ref; //$NON-NLS-1$
+ }
+ }
+
+ try {
+ return credentials(request, realm, username, password, algorithm, messageQop, nonce, nonceCount, opaque, cnonce, method, digestUri);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private String ha1(String realm, String username, String password, String algorithm, String nonce, String cnonce) throws Exception {
+ Assert.isNotNull(realm);
+ Assert.isNotNull(username);
+ Assert.isNotNull(password);
+ Assert.isNotNull(nonce);
+
+ String ha1 = md5(unquote(username) + ":" + unquote(realm) + ":" + password); //$NON-NLS-1$ //$NON-NLS-2$
+ if (algorithm != null && !algorithm.equalsIgnoreCase("MD5")) { //$NON-NLS-1$
+ if (algorithm.equalsIgnoreCase("MD5-sess")) { //$NON-NLS-1$
+ if (cnonce == null) {
+ return null;
+ }
+ ha1 = md5(ha1 + ":" + unquote(nonce) + ":" + unquote(cnonce)); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ throw new Exception(Policy.bind("exception.unregognizedAlgo", algorithm)); //$NON-NLS-1$
+ }
+ }
+
+ return ha1;
+ }
+
+ private String ha2(Request request, String qop, String method, String digestUri) throws Exception {
+ Assert.isNotNull(request);
+ Assert.isNotNull(method);
+ Assert.isNotNull(digestUri);
+
+ String a2 = null;
+ if (qop == null || qop.equalsIgnoreCase("auth")) { //$NON-NLS-1$
+ a2 = md5((method == null ? "" : method) + ":" + digestUri); //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (qop.equalsIgnoreCase("auth-int")) { //$NON-NLS-1$
+ a2 = md5((method == null ? "" : method) + ":" + digestUri + md5(request)); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ throw new Exception(Policy.bind("exception.unregognizedQop", qop)); //$NON-NLS-1$
+ }
+
+ return a2;
+ }
+
+ private String response(Request request, String realm, String username, String password, String algorithm, String qop, String nonce, String nonceCount, String cnonce, String method, String digestUri) throws Exception {
+ Assert.isNotNull(request);
+ Assert.isNotNull(realm);
+ Assert.isNotNull(username);
+ Assert.isNotNull(password);
+ Assert.isNotNull(nonce);
+ Assert.isNotNull(method);
+ Assert.isNotNull(digestUri);
+
+ String ha1 = ha1(realm, username, password, algorithm, nonce, cnonce);
+ if (ha1 == null) {
+ return null;
+ }
+
+ String ha2 = ha2(request, qop, method, digestUri);
+ if (ha2 == null) {
+ return null;
+ }
+
+ if (qop == null) {
+ return md5(ha1 + ":" + unquote(nonce) + ":" + ha2); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (nonceCount == null || cnonce == null || qop == null) {
+ return null;
+ }
+
+ return md5(ha1 + ":" //$NON-NLS-1$
+ + unquote(nonce) + ":" //$NON-NLS-1$
+ + nonceCount + ":" //$NON-NLS-1$
+ + unquote(cnonce) + ":" //$NON-NLS-1$
+ + unquote(qop) + ":" //$NON-NLS-1$
+ + ha2);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestAuthority.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestOutputStream.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestOutputStream.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestOutputStream.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+import java.io.*;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * <P>An <code>OutputStream</code> that filters its data through a
+ * <code>MessageDigest</code> to compute a hash value over the data.
+ */
+public class DigestOutputStream extends FilterOutputStream {
+
+ private static class NullOutputStream extends OutputStream {
+ public void write(int b) throws IOException {
+ // do nothing
+ }
+ }
+
+ private MessageDigest messageDigest = null;
+ private byte[] digest = null;
+
+ /**
+ * Creates a new <code>DigestOutputStream</code> that filters its data
+ * through a <code>MessageDigest</code> that hashes its input using the
+ * given algorithm.
+ *
+ * @param out the data is also written to the given output stream
+ * @param algorithm a hashing algorithm, for example: "MD5"
+ */
+ public DigestOutputStream(OutputStream out, String algorithm) throws NoSuchAlgorithmException {
+
+ super(out);
+ messageDigest = MessageDigest.getInstance(algorithm);
+ }
+
+ /**
+ * Creates a new <code>DigestOutputStream</code> that filters its data
+ * through a <code>MessageDigest</code> that hashes its input using the
+ * given algorithm.
+ *
+ * @param algorithm a hashing algorithm, for example: "MD5"
+ */
+ public DigestOutputStream(String algorithm) throws NoSuchAlgorithmException {
+ this(new NullOutputStream(), algorithm);
+ }
+
+ /**
+ * Completes the hash computation and resets the digest.
+ *
+ * @returns the hash value
+ */
+ public byte[] digest() {
+ if (digest == null)
+ digest = messageDigest.digest();
+ return digest;
+ }
+
+ /**
+ * @see OutputStream#write(byte[], int, int)
+ */
+ public void write(byte b[], int off, int len) throws IOException {
+ out.write(b, off, len);
+ messageDigest.update(b, off, len);
+ }
+
+ /**
+ * @see OutputStream#write(int)
+ */
+ public void write(int b) throws IOException {
+ out.write(b);
+ messageDigest.update((byte) b);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/DigestOutputStream.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/HexConverter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/HexConverter.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/HexConverter.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+/**
+ * This class provides a function that converts byte arrays to their
+ * equivalent hexadecimal string.
+ */
+public final class HexConverter {
+ /**
+ * Converts the given byte array to its equivalent hexadecimal string
+ * and returns the result.
+ */
+ public static String toHex(byte[] arr) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < arr.length; ++i) {
+ buf.append(Integer.toHexString((arr[i] >> 4) & 0x0f));
+ buf.append(Integer.toHexString(arr[i] & 0x0f));
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Converts the given int array to its equivalent hexadecimal string
+ * and returns the result.
+ */
+ public static String toHex(int[] arr) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < arr.length; ++i) {
+ buf.append(Integer.toHexString((arr[i] >> 28) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 24) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 20) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 16) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 12) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 8) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i] >> 4) & 0x0000000f));
+ buf.append(Integer.toHexString((arr[i]) & 0x0000000f));
+ }
+ return buf.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/HexConverter.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Parser.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Parser.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Parser.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+/**
+ * A simple parser that is mainly used to parse HTTP header fields.
+ */
+public class Parser {
+ /**
+ * The string being parsed.
+ */
+ public String s;
+
+ /**
+ * The index of the next character in s to be parsed.
+ */
+ public int pos;
+
+ /**
+ * Creates a new parser on the given string.
+ *
+ * @param s the string to be parsed
+ */
+ public Parser(String s) {
+ this.s = s;
+ }
+
+ /**
+ * Throws a <code>ParserException</code> if <code>pos</code> is out of
+ * range.
+ */
+ public void checkPosition() throws ParserException {
+ if (pos < 0 || pos >= s.length())
+ throw new ParserException();
+ }
+
+ /**
+ * Skips the next character in s if it matches c, otherwise a
+ * <code>ParserException</code> is thrown.
+ *
+ * @param c
+ * @throws ParserException
+ */
+ public void match(char c) throws ParserException {
+ checkPosition();
+ if (s.charAt(pos) != c)
+ throw new ParserException();
+ ++pos;
+ }
+
+ /**
+ * Returns the next quoted string is s (quotes included). Throws a
+ * <code>ParserException</code> if the next substring in s is not a
+ * quoted string.
+ *
+ * @return the next quoted string in s (quotes included)
+ * @throws ParserException
+ */
+ public String nextQuotedString() throws ParserException {
+ int start = pos;
+ match('"');
+
+ checkPosition();
+ while (s.charAt(pos) != '"') {
+ ++pos;
+ checkPosition();
+ }
+ match('"');
+
+ return s.substring(start, pos);
+ }
+
+ /**
+ * Returns the next token in s. Throws a <code>ParserException</code> if
+ * the next substring in s is not a token.
+ *
+ * @return the next token in s
+ * @throws ParserException
+ */
+ public String nextToken() throws ParserException {
+ int start = pos;
+
+ checkPosition();
+ boolean done = false;
+
+ while (!done && pos < s.length()) {
+ int c = s.charAt(pos);
+ if (c <= 31 //
+ || c == 127 //
+ || c == '(' //
+ || c == ')' //
+ || c == '<' //
+ || c == '>' //
+ || c == '@' //
+ || c == ',' //
+ || c == ';' //
+ || c == ':' //
+ || c == '\\' //
+ || c == '"' //
+ || c == '/' //
+ || c == '[' //
+ || c == ']' //
+ || c == '?' //
+ || c == '=' //
+ || c == '{' //
+ || c == '}' //
+ || Character.isWhitespace((char) c)) {
+ done = true;
+ } else {
+ ++pos;
+ }
+ }
+
+ if (start == pos) {
+ throw new ParserException();
+ }
+
+ return s.substring(start, pos);
+ }
+
+ /**
+ * Skips the next sequence of white space in s. An exception is not
+ * thrown if there is no matching white space.
+ */
+ public void skipWhiteSpace() {
+ while (pos < s.length() && Character.isWhitespace(s.charAt(pos)))
+ ++pos;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/Parser.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/ParserException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/ParserException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/ParserException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.authentication;
+
+/**
+ * A <code>ParserException</code> is thrown by the <code>Parser</code>
+ * when there is a problem parsing a <code>String</code>.
+ *
+ * @see Parser
+ */
+public class ParserException extends Exception {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new <code>ParserException</code>.
+ */
+ public ParserException() {
+ super();
+ }
+
+ /**
+ * Creates a new <code>ParserException</code> with the given message.
+ *
+ * @param message
+ */
+ public ParserException(String message) {
+ super(message);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/client/org/eclipse/webdav/internal/authentication/ParserException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContext.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContext.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContext.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1017 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+import java.util.Enumeration;
+
+/**
+ * The <code>IContext</code> interface provides access methods
+ * for most HTTP and WebDAV message header fields. Those that are
+ * not explicitly enumerated can be accessed using <code>
+ * Context#get(String)</code> and <code>Context#put(String,String)
+ * </code>. All context keys are available with <code>
+ * Context#keys()</code>.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface IContext {
+
+ // Depth directive header values.
+
+ /** Depth constant indicating apply the method to the target resource.
+ * @see #getDepth()
+ */
+ public static final String DEPTH_ZERO = "0"; //$NON-NLS-1$
+
+ /** Depth constant indicating apply the method to the target resource.
+ * and (where the resource is a collection) its immediate members.
+ * @see #getDepth()
+ */
+ public static final String DEPTH_ONE = "1"; //$NON-NLS-1$
+
+ /** Depth constant indicating apply the method to the target resource.
+ * and (where the resource is a collection) recursively to all
+ * its members.
+ * @see #getDepth()
+ */
+ public static final String DEPTH_INFINITY = "infinity"; //$NON-NLS-1$
+
+ // Locking constants
+
+ /** Lock type constant indicating an exclusive lock.
+ * Only one exclusive lock can be granted at any time on a resource.
+ */
+ public static final String EXCLUSIVE_LOCK = "exclusive"; //$NON-NLS-1$
+
+ /** Lock type constant indicating a shared lock.
+ * A resource may have many concurrent shared locks which indicate an
+ * intention to change the resource in some way. It is the responsibilty
+ * of the shared lock owners to coordinate their updates appropriately
+ * through other means.
+ */
+ public static final String SHARED_LOCK = "shared"; //$NON-NLS-1$
+
+ /** Lock type constant indicating a write lock.
+ * Write locks allow a resource to be updated or deleted.
+ */
+ public static final String WRITE_LOCK = "write"; //$NON-NLS-1$
+
+ /** Constant indicating an indefinite timeout period.
+ */
+ public static final int NO_EXPIRY_LOCK = -1;
+
+ /** Constant used in the Cache-Control header indicating that clients and
+ * proxies MUST not cache the response of a method since it has
+ * non-idempotent semantics.
+ */
+ public static final String NO_CACHE = "no-cache"; //$NON-NLS-1$
+
+ /**
+ * Collapse teh receiver by copying all the keys and values from the
+ * default context into the receiver. This effectively makes the Context
+ * stand-alone so that subsequent changes to shared contexts are no
+ * longer seen by the receiver.
+ */
+ public void collapse();
+
+ /**
+ * Returns the value for the given key, or <code>null</code>
+ * if the given key has no value.
+ * @param key the key to look up
+ * @return the value for the key
+ */
+ public String get(String key);
+
+ /**
+ * Returns the media types that are acceptable for a response.
+ * @return the value for <code>"Accept"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAccept();
+
+ /**
+ * Returns the character sets that are acceptable for a response.
+ * @return the value for <code>"Accept-Charset"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAcceptCharset();
+
+ /**
+ * Retruns what content-encoding values are acceptable for a response.
+ * @return the value for <code>"Accept-Encoding"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAcceptEncoding();
+
+ /**
+ * Returns the natural languages that are acceptable for a response.
+ * @return the value for <code>"Accept-Language"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAcceptLanguage();
+
+ /**
+ * Returns the range requests acceptable to a server.
+ * @return the value for <code>"Accept-Ranges"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAcceptRanges();
+
+ /**
+ * Returns the integer value of sender's estimate of the time since the
+ * response was generated, or -1 if the value is not set.
+ * @return the integer value for <code>"Age"</code> key,
+ * or -1 if not set.
+ */
+ public int getAge();
+
+ /**
+ * Returns the string value for the ALL_BINDINGS key.
+ * @return the value for <code>"All-Bindings"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAllBindings();
+
+ /**
+ * Returns the methods allowed on a resource
+ * @return the value for <code>"Allow"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAllow();
+
+ /**
+ * Returns the user's credentials for the realm of the resource being requested.
+ * @return the value for <code>"Authorization"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getAuthorization();
+
+ /**
+ * Returns the cache control directives that must be obeyed.
+ * @return the value for <code>"Cache-Control"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getCacheControl();
+
+ /**
+ * Returns the sender connection options.
+ * @return the value for <code>"Connection"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getConnection();
+
+ /**
+ * Returns the URL string value for the CONTENT_BASE key.
+ * @return the value for <code>"Content-Base"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentBase();
+
+ /**
+ * Returns what additional content encodings have been applied to the entity body.
+ * @return the value for <code>"Content-Encoding"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentEncoding();
+
+ /**
+ * Returns the natural language of the intended audience for the entity body.
+ * @return the value for <code>"Content-Language"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentLanguage();
+
+ /**
+ * Returns the content length in bytes of the entity body.
+ * @return the value for <code>"Content-Length"</code> key,
+ * or -1 if that key has no value.
+ */
+ public long getContentLength();
+
+ /**
+ * Returns the URL that locates the content.
+ * @return the value for <code>"Content-Location"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentLocation();
+
+ /**
+ * Returns the string value for the CONTENT_MD5 key.
+ * @return the value for <code>"Content-MD5"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentMD5();
+
+ /**
+ * Returns the string value for the CONTENT_RANGE key.
+ * @return the value for <code>"Content-Range"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentRange();
+
+ /**
+ * Returns the MIME type for the response contents.
+ * @return the value for <code>"Content-Type"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getContentType();
+
+ /**
+ * Returns the date the request was made.
+ * @return the value for <code>"Date"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getDate();
+
+ /**
+ * Returns the DAV level supported by the server.
+ * [missing: what are these values]
+ */
+ public String getDAV();
+
+ /**
+ * Returns the string value for the "Depth" key.
+ * @return one of <code>DEPTH_ZERO</code>,
+ * <code>DEPTH_ONE</code>, or <code>DEPTH_INFINITY</code>
+ * @see #DEPTH_ZERO
+ * @see #DEPTH_ONE
+ * @see #DEPTH_INFINITY
+ */
+ public String getDepth();
+
+ /**
+ * Returns the destination URL for a copy or move operation.
+ * @return the value for <code>"Destination"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getDestination();
+
+ /**
+ * Returns the entity tag for the associated entity.
+ * @return the value for <code>"ETag"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getETag();
+
+ /**
+ * Returns the date/time after which the response should be
+ * considered stale.
+ * @return the value for <code>"Expires"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getExpires();
+
+ /**
+ * Returns the string value for the FROM key.
+ * @return the value for <code>"From"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getFrom();
+
+ /**
+ * Returns the Internet host and port of the resource being requested.
+ * @return the value for <code>"Host"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getHost();
+
+ /**
+ * Returns the string value for the IF key.
+ * @return the value for <code>"If"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfKey();
+
+ /**
+ * Returns the string value for the IF_MATCH key.
+ * @return the value for <code>"If-Match"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfMatch();
+
+ /**
+ * Returns the string value for the IF_MODIFIED_SINCE key.
+ * @return the value for <code>"If-Modified-Since"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfModifiedSince();
+
+ /**
+ * Returns the string value for the IF_NONE_MATCH key.
+ * @return the value for <code>"If-None-Match"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfNoneMatch();
+
+ /**
+ * Returns the string value for the IF_RANGE key.
+ * @return the value for <code>"If-Range"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfRange();
+
+ /**
+ * Returns the string value for the IF_UNMODIFIED_SINCE key.
+ * @return the value for <code>"If-Unmodified-Since"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getIfUnmodifiedSince();
+
+ /**
+ * Returns the label header value.
+ * @return the value for <code>"Label"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getLabel();
+
+ /**
+ * Returns when the resource was last modified.
+ * @return the value for <code>"Last-Modified"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getLastModified();
+
+ /**
+ * Returns the URI of the redirect location.
+ * @return the value for <code>"Location"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getLocation();
+
+ /**
+ * Returns the lock token for the resource, or null if it is not set.
+ * @return the value for <code>"Lock-Token"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getLockToken();
+
+ /**
+ * Returns the integer value for the MAX_FORWARDS key.
+ * @return the value for <code>"Max-Forwards"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public int getMaxForwards();
+
+ /**
+ * Returns the string value for the ORDERED key.
+ * @return the value for <code>"Ordered"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getOrdered();
+
+ /**
+ * Returns the flag that indicates if copy or move should overwrite
+ * an existing destination.
+ * @return the value for <code>"Overwrite"</code> key,
+ * or <code>false</code> if that key has no value.
+ */
+ public boolean getOverwrite();
+
+ /**
+ * Returns the boolean value for the PASSTHROUGH key.
+ * @return the value for <code>"Passthrough"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public boolean getPassthrough();
+
+ /**
+ * Returns the string value for the POSITION key.
+ * @return the value for <code>"Position"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getPosition();
+
+ /**
+ * Returns the string value for the PRAGMA key.
+ * @return the value for <code>"Pragma"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getPragma();
+
+ /**
+ * Returns the string value for the PROXY_AUTHENTICATE key.
+ * @return the value for <code>"Proxy-Authenticate"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getProxyAuthenticate();
+
+ /**
+ * Returns the string value for the PROXY_AUTHORIZATION key.
+ * @return the value for <code>"Proxy-Authorization"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getProxyAuthorization();
+
+ /**
+ * Returns the string value for the PUBLIC_KEY key.
+ * @return the value for <code>"Public-Key"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getPublicKey();
+
+ /**
+ * Returns the string value for the RANGE key.
+ * @return the value for <code>"Range"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getRange();
+
+ /**
+ * Returns the URI string of the resource from which the request was obtained.
+ * @return the value for <code>"Referer"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getReferer();
+
+ /**
+ * Returns the URI string for the REF_TARGET key.
+ * @return the value for <code>"Ref-Target"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getRefTarget();
+
+ /**
+ * Returns the string value for the RESOURCE_TYPE key.
+ * @return the value for <code>"Resource-Type"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getResourceType();
+
+ /**
+ * Returns the string value for the RETRY_AFTER key.
+ * @return the value for <code>"Retry-After"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getRetryAfter();
+
+ /**
+ * Returns information about the software used by the origin server
+ * to handle the request.
+ * @return the value for <code>"Server"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getServer();
+
+ /**
+ * Returns the URI string of the resource whose method is in process.
+ * @return the value for <code>"Status-URI"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getStatusURI();
+
+ /**
+ * Returns the lock timeout value.
+ * @return the integer value for <code>"Timeout"</code> key,
+ * where -1 means that the value was not set, and -2 means
+ * that the value was infinity.
+ */
+ public int getTimeout();
+
+ /**
+ * Returns the string value for the TRANSFER_ENCODING key.
+ * @return the value for <code>"Transfer-Encoding"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getTransferEncoding();
+
+ /**
+ * Returns the string value for the UPGRADE key.
+ * @return the value for <code>"Upgrade"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getUpgrade();
+
+ /**
+ * Returns information about the user agent originating the request.
+ * @return the value for <code>"User-Agent"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getUserAgent();
+
+ /**
+ * Returns the string value for the VARY key.
+ * @return the value for <code>"Vary"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getVary();
+
+ /**
+ * Returns the string value for the VIA key.
+ * @return the value for <code>"Via"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getVia();
+
+ /**
+ * Returns the string value for the WARNING key.
+ * @return the value for <code>"Warning"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getWarning();
+
+ /**
+ * Returns the string value for the WWW_AUTHENTICATE key.
+ * @return the value for <code>"WWW-Authenticate"</code> key,
+ * or <code>null</code> if that key has no value.
+ */
+ public String getWWWAuthenticate();
+
+ /**
+ * Returns keys of the context, as an enumeration
+ *
+ * @return an enumeration over the context keys
+ * (<code>String</code>s).
+ */
+ public Enumeration keys();
+
+ /**
+ * Adds or replaces the given key-value pair into the context.
+ *
+ * @param key the key
+ * @param value its associated value
+ */
+ public void put(String key, String value);
+
+ /**
+ * Removes the given key from this context. Does nothing if the
+ * given key is not set.
+ *
+ * @param key the key to remove
+ */
+ public void removeKey(String key);
+
+ /**
+ * Sets what media types are acceptable for a response.
+ * Sets the string value for the ACCEPT key.
+ *
+ * @param value the value for ACCEPT
+ */
+ public void setAccept(String value);
+
+ /**
+ * Sets which character sets are acceptable for a response.
+ * Sets the string value for the ACCEPT_CHARSET key.
+ *
+ * @param value the value for ACCEPT_CHARSET
+ */
+ public void setAcceptCharset(String value);
+
+ /**
+ * Sets the content-encoding values which are acceptable for a response.
+ * Sets the string value for the ACCEPT_ENCODING key.
+ *
+ * @param value the value for ACCEPT_ENCODING
+ */
+ public void setAcceptEncoding(String value);
+
+ /**
+ * Sets which natural languages are acceptable for a response.
+ * Sets the string value for the ACCEPT_LANGUAGE key.
+ *
+ * @param value the value for ACCEPT_LANGUAGE
+ */
+ public void setAcceptLanguage(String value);
+
+ /**
+ * Sets the range requests acceptable to a server.
+ * Sets the string value for the ACCEPT_RANGES key.
+ *
+ * @param value the value for ACCEPT_RANGES
+ */
+ public void setAcceptRanges(String value);
+
+ /**
+ * Sets the sender's estimate of the time since the response was generated.
+ * Sets the int value for the AGE key. Set the value to -1 to remove the key.
+ *
+ * @param seconds the value for AGE
+ */
+ public void setAge(int seconds);
+
+ /**
+ * Sets the string value for the ALL_BINDINGS key.
+ *
+ * @param value the value for ALL_BINDINGS
+ */
+ public void setAllBindings(String value);
+
+ /**
+ * Sets methods allowed on a resource
+ * Sets the string value for the ALLOW key.
+ *
+ * @param value the value for ALLOW
+ */
+ public void setAllow(String value);
+
+ /**
+ * Sets the user's credentials for the realm of the resource being requested.
+ * Sets the string value for the AUTHORIZATION key.
+ *
+ * @param value the value for AUTHORIZATION
+ */
+ public void setAuthorization(String value);
+
+ /**
+ * Sets the cache control directives that must be obeyed.
+ * Sets the string value for the CACHE_CONTROL key.
+ *
+ * @param value the value for CACHE_CONTROL
+ */
+ public void setCacheControl(String value);
+
+ /**
+ * Sets sender connection options.
+ * Sets the string value for the CONNECTION key.
+ *
+ * @param value the value for CONNECTION
+ */
+ public void setConnection(String value);
+
+ /**
+ * Sets the URL string value for the CONTENT_BASE key.
+ *
+ * @param stringURL the value for CONTENT_BASE
+ */
+ public void setContentBase(String stringURL);
+
+ /**
+ * Sets the additional content encodings that have been applied to the entity body.
+ * Sets the string value for the CONTENT_ENCODING key.
+ *
+ * @param value the value for CONTENT_ENCODING
+ */
+ public void setContentEncoding(String value);
+
+ /**
+ * Sets the natural language of the intended audience for the entity body.
+ * Sets the string value for the CONTENT_LANGUAGE key.
+ *
+ * @param value the value for CONTENT_LANGUAGE
+ */
+ public void setContentLanguage(String value);
+
+ /**
+ * Sets the content length in bytes of the entity body.
+ * Sets the value for the CONTENT_LENGTH key.
+ * Passes the value -1 to remove the key.
+ *
+ * @param value the value for CONTENT_LENGTH
+ */
+ public void setContentLength(long value);
+
+ /**
+ * Sets the URL string value for the CONTENT_LOCATION key.
+ *
+ * @param stringURL the value for CONTENT_LOCATION
+ */
+ public void setContentLocation(String stringURL);
+
+ /**
+ * Sets the string value for the CONTENT_MD5 key.
+ *
+ * @param value the value for CONTENT_MD5
+ */
+ public void setContentMD5(String value);
+
+ /**
+ * Sets the string value for the CONTENT_RANGE key.
+ *
+ * @param value the value for CONTENT_RANGE
+ */
+ public void setContentRange(String value);
+
+ /**
+ * Sets the MIME type for the response contents.
+ * Sets the string value for the CONTENT_TYPE key.
+ *
+ * @param value the value for CONTENT_TYPE
+ */
+ public void setContentType(String value);
+
+ /**
+ * Sets the date the request was made.
+ * Sets the string value for the DATE key.
+ *
+ * @param value the value for DATE
+ */
+ public void setDate(String value);
+
+ /**
+ * Sets the DAV level supported by the server.
+ * Sets the string value for the DAV key.
+ *
+ * @param value the value for DAV
+ */
+ public void setDAV(String value);
+
+ /**
+ * Sets the string value for the DEPTH key.
+ * @param depth one of <code>DEPTH_ZERO</code>,
+ * <code>DEPTH_ONE</code>, or <code>DEPTH_INFINITY</code>
+ * @see #DEPTH_ZERO
+ * @see #DEPTH_ONE
+ * @see #DEPTH_INFINITY
+ */
+ public void setDepth(String depth);
+
+ /**
+ * Sets the destination URI for a copy or move operation.
+ * Sets the URI value for the DESTINATION key.
+ *
+ * @param stringURL the value for DESTINATION
+ */
+ public void setDestination(String stringURL);
+
+ /**
+ * Sets the entity tag for the associated entity.
+ * Sets the string value for the ETAG key.
+ *
+ * @param value the value for ETAG
+ */
+ public void setETag(String value);
+
+ /**
+ * Sets the date/time after which the response should be considered stale.
+ * Sets the string value for the EXPIRES key.
+ *
+ * @param value the value for EXPIRES
+ */
+ public void setExpires(String value);
+
+ /**
+ * Sets the string value for the FROM key.
+ *
+ * @param value the value for FROM
+ */
+ public void setFrom(String value);
+
+ /**
+ * Sets the Internet host and port of the resource being requested.
+ * Sets the string value for the HOST key.
+ *
+ * @param value the value for HOST
+ */
+ public void setHost(String value);
+
+ /**
+ * Sets the string value for the IF key.
+ *
+ * @param value the value for IF
+ */
+ public void setIfKey(String value);
+
+ /**
+ * Sets the string value for the IF_MATCH key.
+ *
+ * @param value the value for IF_MATCH
+ */
+ public void setIfMatch(String value);
+
+ /**
+ * Sets the string value for the IF_MODIFIED_SINCE key.
+ *
+ * @param value the value for IF_MODIFIED_SINCE
+ */
+ public void setIfModifiedSince(String value);
+
+ /**
+ * Sets the string value for the IF_NONE_MATCH key.
+ *
+ * @param value the value for IF_NONE_MATCH
+ */
+ public void setIfNoneMatch(String value);
+
+ /**
+ * Sets the string value for the IF_RANGE key.
+ *
+ * @param value the value for IF_RANGE
+ */
+ public void setIfRange(String value);
+
+ /**
+ * Sets the string value for the IF_UNMODIFIED_SINCE key.
+ *
+ * @param value the value for IF_UNMODIFIED_SINCE
+ */
+ public void setIfUnmodifiedSince(String value);
+
+ /**
+ * Sets when the label header value.
+ * Sets the string value for the LABEL key.
+ *
+ * @param value the value for LABEL
+ */
+ public void setLabel(String value);
+
+ /**
+ * Sets when the resource was last modified.
+ * Sets the string value for the LAST_MODIFIED key.
+ *
+ * @param value the value for LAST_MODIFIED
+ */
+ public void setLastModified(String value);
+
+ /**
+ * Sets the redirect location.
+ * Sets the URI value for the LOCATION key.
+ *
+ * @param stringURL the value for LOCATION
+ */
+ public void setLocation(String stringURL);
+
+ /**
+ * Sets the lock token for the resource.
+ * Sets the lock token value for the LOCK_TOKEN key.
+ *
+ * @param lockToken the value for LOCK_TOKEN
+ */
+ public void setLockToken(String lockToken);
+
+ /**
+ * Sets the integer value for the MAX_FORWARDS key.
+ *
+ * @param value the value for MAX_FORWARDS
+ */
+ public void setMaxForwards(int value);
+
+ /**
+ * Sets the string value for the ORDERED key.
+ *
+ * @param value the value for ORDERED
+ */
+ public void setOrdered(String value);
+
+ /**
+ * Sets if copy or move should overwrite an existing destination.
+ * Sets the boolean value for the OVERWRITE key.
+ *
+ * @param value the value for OVERWRITE
+ */
+ public void setOverwrite(boolean value);
+
+ /**
+ * Sets the boolean value for the PASSTHROUGH key.
+ *
+ * @param value the value for PASSTHROUGH
+ */
+ public void setPassthrough(boolean value);
+
+ /**
+ * Sets the string value for the POSITION key.
+ *
+ * @param value the value for POSITION
+ */
+ public void setPosition(String value);
+
+ /**
+ * Sets the string value for the PRAGMA key.
+ *
+ * @param value the value for PRAGMA
+ */
+ public void setPragma(String value);
+
+ /**
+ * Sets the string value for the PROXY_AUTHENTICATE key.
+ *
+ * @param value the value for PROXY_AUTHENTICATE
+ */
+ public void setProxyAuthenticate(String value);
+
+ /**
+ * Sets the string value for the PROXY_AUTHORIZATION key.
+ *
+ * @param value the value for PROXY_AUTHORIZATION
+ */
+ public void setProxyAuthorization(String value);
+
+ /**
+ * Sets the string value for the PUBLIC_KEY key.
+ *
+ * @param value the value for PUBLIC_KEY
+ */
+ public void setPublicKey(String value);
+
+ /**
+ * Sets the string value for the RANGE key.
+ *
+ * @param value the value for RANGE
+ */
+ public void setRange(String value);
+
+ /**
+ * Sets the URI of the resource from which the request was obtained.
+ * Sets the URI value for the REFERER key.
+ *
+ * @param stringURL the value for REFERER
+ */
+ public void setReferer(String stringURL);
+
+ /**
+ * Sets the URI value for the REF_TARGET key.
+ *
+ * @param stringURL the value for REF_TARGET
+ */
+ public void setRefTarget(String stringURL);
+
+ /**
+ * Sets the string value for the RESOURCE_TYPE key.
+ *
+ * @param value the value for RESOURCE_TYPE
+ */
+ public void setResourceType(String value);
+
+ /**
+ * Sets the string value for the RETRY_AFTER key.
+ *
+ * @param value the value for RETRY_AFTER
+ */
+ public void setRetryAfter(String value);
+
+ /**
+ * Sets information about the software used by the origin server
+ * to handle the request. Sets the string value for the SERVER key.
+ *
+ * @param value the value for SERVER
+ */
+ public void setServer(String value);
+
+ /**
+ * Sets the URI of the resource whose method is in process.
+ * Sets the URI value for the STATUS_URI key.
+ *
+ * @param statusURI the value for STATUS_URI
+ */
+ public void setStatusURI(String statusURI);
+
+ /**
+ * Sets the lock timeout value in seconds. Pass -1 to clear the
+ * value, pass -2 to set "Infinity". Sets the integer value for the
+ * TIMEOUT key.
+ *
+ * @param value the value for TIMEOUT
+ */
+ public void setTimeout(int value);
+
+ /**
+ * Sets the string value for the TRANSFER_ENCODING key.
+ *
+ * @param value the value for TRANSFER_ENCODING
+ */
+ public void setTransferEncoding(String value);
+
+ /**
+ * Sets the string value for the UPGRADE key.
+ *
+ * @param value the value for UPGRADE
+ */
+ public void setUpgrade(String value);
+
+ /**
+ * Sets information about the user agent originating the request.
+ * Sets the string value for the USER_AGENT key.
+ *
+ * @param value the value for USER_AGENT
+ */
+ public void setUserAgent(String value);
+
+ /**
+ * Sets the string value for the VARY key.
+ *
+ * @param value the value for VARY
+ */
+ public void setVary(String value);
+
+ /**
+ * Sets the string value for the VIA key.
+ *
+ * @param value the value for VIA
+ */
+ public void setVia(String value);
+
+ /**
+ * Sets the string value for the WARNING key.
+ *
+ * @param value the value for WARNING
+ */
+ public void setWarning(String value);
+
+ /**
+ * Sets the string value for the WWW_AUTHENTICATE key.
+ *
+ * @param value the value for WWW_AUTHENTICATE
+ */
+ public void setWWWAuthenticate(String value);
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContext.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContextFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContextFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContextFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+import org.eclipse.webdav.internal.kernel.Context;
+
+/**
+ * Factory for constructing WebDAV contexts.
+ * <p>
+ * The context corresponds to the header portion of
+ * a WebDAV request or response.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Context
+ */
+public interface IContextFactory {
+ /**
+ * Create a new empty context.
+ *
+ * @return the new empty <code>Context</code>.
+ */
+ public IContext newContext();
+
+ /**
+ * Creates a new context based on the given context.
+ * <p>
+ * The newly created context acts like an acetate layer
+ * over the base context: any changes made to the new
+ * context are confined to that layer and do not affect
+ * the base context; but changes to the base context show
+ * through to the new context unless masked by another
+ * change made to the new context (c.f. properties).</p>
+ *
+ * @param baseContext the default values for the new context.
+ * @return the new wrapping <code>Context</code>.
+ */
+ public IContext newContext(IContext baseContext);
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IContextFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocator.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocator.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+/**
+ * Locators encapsulate a resource URL, whether it is
+ * a stable URL (such as a version URL) or a dynamic URL,
+ * and optional label selector.
+ * <p>
+ * The locator 'knows' if the resource URL is stable or not.
+ * Note that a stable URL cannot also have a label selector.</p>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface ILocator {
+ /**
+ * Returns the label selector value of this locator,
+ * or <code>null</code> if there is no label selector.
+ * <p>
+ * For certain methods (e.g. GET, PROPFIND), if the
+ * request-URL identifies a version-controlled resource,
+ * a label can be specified in a Label request header
+ * to cause the method to be applied to the version
+ * selected by that label from the version history of
+ * that version-controlled resource.</p>
+ * <p>
+ * Note that a stable URL must not have a locator label.</p>
+ *
+ * @return the label as a <code>String</code> or <code>null
+ * </code> if there is no label specified.
+ */
+ public String getLabel();
+
+ /**
+ * Returns a resource URL.
+ * <p>
+ * If there is no label specified, the URL properly identifies the
+ * resource. However, if there is a label, the resource URL
+ * identiifes a version-controlled resource whose history contains
+ * the version whose label is the target of this locator.</p>
+ * <p>
+ * In typical usage, and with no label header, this URL may be the
+ * HTTP request URI or the destination header URI.</p>
+ *
+ * @return the String representation of the resource URL.
+ */
+ public String getResourceURL();
+
+ /**
+ * Returns whether the resource URL of this locator is stable.
+ * <p>
+ * A stable URL is a server-generated URL that cannot be moved
+ * and do not mecessarily conform to the DAV namespace. For
+ * example, version URLs are server generated and do not have
+ * to appear in any DAV collection. Version URLs and version
+ * history URLs are stable URLs.</p>
+ *
+ * @return true if the resource URL is stable, and false otherwise.
+ */
+ public boolean isStable();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocator.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocatorFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocatorFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocatorFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+/**
+ * Factory for constructing resource locators.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see ILocator
+ */
+public interface ILocatorFactory {
+
+ /**
+ * Returns a locator with the given resource URL that
+ * (implicitly) uses the standard way of resolving resource
+ * URLs.
+ * <p>
+ * Version-unaware clients use this kind of locator exclusively.
+ *
+ * @param resourceURL the URL identifier of the resource as a
+ * <code>String</code>.
+ */
+ public ILocator newLocator(String resourceURL);
+
+ /**
+ * Returns a locator with the given resource URL and
+ * label.
+ * <p>
+ * This kind of locator is used only by version-aware clients.
+ * It allows a versioning client to specify a version-controlled
+ * resource URL and the label of a version in the corresponding
+ * history. The resulting locator identifies the
+ * <em>version</em>.</p>
+ * <p>
+ * The resource URL MUST NOT be a stable URL.</p>
+ *
+ * @param requestURL the <code>String</code> representation of
+ * the version-controlled resource URL.
+ * @param label the label of the version to select from the
+ * corresponding history.
+ */
+ public ILocator newLocator(String requestURL, String label);
+
+ /**
+ * Returns a locator given a stable resource URL.
+ * <p>
+ * This kind of locator is used only by version-aware clients.
+ * The stable URL is generated by the server. Clients may
+ * reliably store the URL and use it to identify the same
+ * resource in subsequent operations. Resources identified by
+ * a stable URL cannot be moved but they may be deleted.
+ * The stable URL cannot be bound to a different resource
+ * by the client or server).</p>
+ * <p>
+ * Note that locators with stable URLs cannot have also have a
+ * label.</p>
+ *
+ * @param resourceURL the stable URL to a versioning resource
+ * as a <code>String</code>.
+ */
+ public ILocator newStableLocator(String resourceURL);
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/ILocatorFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IResponse.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IResponse.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IResponse.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,455 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.w3c.dom.Document;
+
+/**
+ * Represents a response from a WebDAV server.
+ * <p>
+ * A response contains an open input stream, which is obtained
+ * by <code>getInputStream()</code>.</p>
+ * <p>
+ * The client (i.e., the party that invoked the <code>Server</code>
+ * method) is responsible for indicating that they're done with
+ * the response object by calling its <code>close()</code> method;
+ * this discards any remaining unread bytes, closes the stream,
+ * and frees up any associated OS resources.</p>
+ * <p>
+ * Failing to close the response may lead to spurious bytes being
+ * left on the response socket and causing unspecified behavior on
+ * subsequent request/response interactions.</p>
+ * <p>
+ * The recommended basic usage pattern is as follows:
+ * <pre>
+ * Response r = server.mkcol(source, context);
+ * try {
+ * if (r.getStatus() == Response.SC_OK) {
+ * ... // handle standard response
+ * } else {
+ * ... // handle non-standard response
+ * }
+ * } finally {
+ * r.close();
+ * }
+ * </pre>
+ * Certain kinds of responses (e.g., certain status codes,
+ * responses to certain methods) contain a WebDAV-specified
+ * XML element in the response body. The presence (or expected
+ * presence) of an XML element body is indicated by
+ * <code>hasDocumentBody</code> returning <code>true</code>,
+ * in which case the client should access this element with
+ * <code>readDocumentBody()</code>; in other cases,
+ * <code>hasDocumentBody</code> returns<code>false</code>,
+ * and the client should access the stream of raw bytes with
+ * <code>getInputStream()</code>.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface IResponse {
+
+ /*
+ * HTTP/1.1 status codes; see RFC 1945 and the WebDAV specification (RFC 2518).
+ */
+
+ /**
+ * Status code (100) indicating the client may continue with
+ * its request. This interim response is used to inform the
+ * client that the initial part of the request has been
+ * received and has not yet been rejected by the server.
+ */
+ public final int SC_CONTINUE = 100;
+
+ /**
+ * Status code (101) indicating the server is switching protocols
+ * according to Upgrade header.
+ */
+ public final int SC_SWITCHING_PROTOCOLS = 101;
+
+ /**
+ * Status code (102) indicating the server is still processing the request.
+ */
+ public final int SC_PROCESSING = 102;
+
+ // Request was successfully received, understood, and accepted.
+
+ /**
+ * Status code (200) indicating the request succeeded normally.
+ */
+ public final int SC_OK = 200;
+
+ /**
+ * Status code (201) indicating the request succeeded and created
+ * a new resource on the server.
+ */
+ public final int SC_CREATED = 201;
+
+ /**
+ * Status code (202) indicating that a request was accepted for
+ * processing, but was not completed.
+ */
+ public final int SC_ACCEPTED = 202;
+
+ /**
+ * Status code (203) indicating that the meta information presented
+ * by the client did not originate from the server.
+ */
+ public final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
+
+ /**
+ * Status code (204) indicating that the request succeeded but that
+ * there was no new information to return.
+ */
+ public final int SC_NO_CONTENT = 204;
+
+ /**
+ * Status code (205) indicating that the agent SHOULD reset the document
+ * view which caused the request to be sent.
+ */
+ public final int SC_RESET_CONTENT = 205;
+
+ /**
+ * Status code (206) indicating that the server has fulfilled the partial
+ * GET request for the resource.
+ */
+ public final int SC_PARTIAL_CONTENT = 206;
+
+ /**
+ * Status code (207) indicating that the response provides status for multiple
+ * independent operations.
+ */
+ public final int SC_MULTI_STATUS = 207;
+
+ // Redirection: indicates further action needs to be taken by the user.
+
+ /** Status code (300) indicating that the requested resource corresponds to any one of
+ * a set of representations, each with its own specific location
+ */
+ public final int SC_MULTIPLE_CHOICES = 300;
+
+ /**
+ * Status code (301) indicating that the resource has permanently
+ * moved to a new location, and that future references should use a
+ * new URI with their requests.
+ */
+ public final int SC_MOVED_PERMANENTLY = 301;
+
+ /**
+ * Status code (302) indicating that the resource has temporarily
+ * moved to another location, but that future references should
+ * still use the original URI to access the resource.
+ */
+ public final int SC_MOVED_TEMPORARILY = 302;
+
+ /**
+ * Status code (303) indicating that the response to the request can
+ * be found under a different URI.
+ */
+ public final int SC_SEE_OTHER = 303;
+
+ /**
+ * Status code (304) indicating that a conditional GET operation
+ * found that the resource was available and not modified.
+ */
+ public final int SC_NOT_MODIFIED = 304;
+
+ /**
+ * Status code (305) indicating that the requested resource MUST be accessed
+ * through the proxy given by the Location field.
+ */
+ public final int SC_USE_PROXY = 305;
+
+ // Client error
+
+ /**
+ * Status code (400) indicating the request sent by the client was
+ * syntactically incorrect.
+ */
+ public final int SC_BAD_REQUEST = 400;
+
+ /**
+ * Status code (401) indicating that the request requires HTTP
+ * authentication.
+ */
+ public final int SC_UNAUTHORIZED = 401;
+
+ /**
+ * Status code (402) reserved for future use.
+ */
+ public final int SC_PAYMENT_REQUIRED = 402;
+
+ /**
+ * Status code (403) indicating the server understood the request
+ * but refused to fulfill it.
+ */
+ public final int SC_FORBIDDEN = 403;
+
+ /**
+ * Status code (404) indicating that the requested resource is not
+ * available.
+ */
+ public final int SC_NOT_FOUND = 404;
+
+ /**
+ * Status code (405) indicating the method specified is not
+ * allowed for the resource.
+ */
+ public final int SC_METHOD_NOT_ALLOWED = 405;
+
+ /**
+ * Status code (406) indicating the resource identified by the
+ * request is only capable of generating response entities
+ * which have content characteristics not acceptable according
+ * to the accept headerssent in the request.
+ */
+ public final int SC_NOT_ACCEPTABLE = 406;
+
+ /**
+ * Status code (407) indicating the client MUST first authenticate
+ * itself with the proxy.
+ */
+ public final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
+
+ /**
+ * Status code (408) indicating the client did not produce a request within
+ * the time that the server was prepared to wait.
+ */
+ public final int SC_REQUEST_TIMEOUT = 408;
+
+ /**
+ * Status code (409) indicating that the request could not be
+ * completed due to a conflict with the current state of the
+ * resource.
+ */
+ public final int SC_CONFLICT = 409;
+
+ /**
+ * Status code (410) indicating the server did not receive a timely
+ * response from the upstream server while acting as a gateway or proxy.
+ */
+ public final int SC_GONE = 410;
+
+ /**
+ * Status code (411) indicating the request cannot be handled
+ * without a defined Content-Length.
+ */
+ public final int SC_LENGTH_REQUIRED = 411;
+
+ /**
+ * Status code (412) indicating the precondition given in one
+ * or more of the request-header fields evaluated to false
+ * when it was tested on the server.
+ */
+ public final int SC_PRECONDITION_FAILED = 412;
+
+ /**
+ * Status code (413) indicating the server is refusing to
+ * process a request because the request entity is larger
+ * than the server is willing or able to process.
+ */
+ public final int SC_REQUEST_TOO_LONG = 413;
+
+ /**
+ * Status code (414) indicating the server is refusing to
+ * service the request because the Request-URI is longer
+ * than the server is willing to interpret.
+ */
+ public final int SC_REQUEST_URI_TOO_LONG = 414;
+
+ /**
+ * Status code (415) indicating the server is refusing to service
+ * the request because the entity of the request is in a format
+ * not supported by the requested resource for the requested
+ * method.
+ */
+ public final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
+
+ /**
+ * Status code (422) indicating the server understands the content type of the
+ * request entity, but was unable to process the contained instructions.
+ */
+ public final int SC_UNPROCESSABLE_ENTITY = 422;
+
+ /**
+ * Status code (423) indicating the source or destination resource of a
+ * method is locked.
+ */
+ public final int SC_LOCKED = 423;
+
+ /**
+ * Status code (424) indicating the method was not executed on
+ * a particular resource within its scope because some part of
+ * the method's execution failed causing the entire method to be
+ * aborted.
+ */
+ public final int SC_FAILED_DEPENDENCY = 424;
+
+ /**
+ * Status code (425) indicating that the resource does not have sufficient
+ * space to record the state of the resource after the execution of the method.
+ */
+ public final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 425;
+
+ // Server errors
+
+ /**
+ * Status code (500) indicating an error inside the HTTP service
+ * which prevented it from fulfilling the request.
+ */
+ public final int SC_INTERNAL_SERVER_ERROR = 500;
+
+ /**
+ * Status code (501) indicating the HTTP service does not support
+ * the functionality needed to fulfill the request.
+ */
+ public final int SC_NOT_IMPLEMENTED = 501;
+
+ /**
+ * Status code (502) indicating that the HTTP server received an
+ * invalid response from a server it consulted when acting as a
+ * proxy or gateway.
+ */
+ public final int SC_BAD_GATEWAY = 502;
+
+ /**
+ * Status code (503) indicating that the HTTP service is
+ * temporarily overloaded, and unable to handle the request.
+ */
+ public final int SC_SERVICE_UNAVAILABLE = 503;
+
+ /**
+ * Status code (504) indicating the server did not receive a
+ * timely response from the upstream server while acting as a
+ * gateway or proxy.
+ */
+ public final int SC_GATEWAY_TIMEOUT = 504;
+
+ /**
+ * Status code (505) indicating the server does not support or
+ * refuses to support the HTTP protocol version that was used
+ * in the request message.
+ */
+ public final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
+
+ /**
+ * Status code (506) indicating the server terminated an operation
+ * because it encountered an infinite loop while processing a request
+ * with "Depth: infinity".
+ */
+ public final int SC_LOOP_DETECTED = 506;
+
+ /**
+ * Status code (507) indicating the server is unable to create the
+ * requested binding because it would bind a segment in a collection
+ * on one server to a resource on a different server.
+ */
+ public final int SC_CROSS_SERVER_BINDING_FORBIDDEN = 507;
+
+ /**
+ * Closes this response. Any unread bytes that make up
+ * the body of this response are discarded; any underlying
+ * OS resources associated with this response are freed.
+ * <p>
+ * This method should be invoked on every response returned
+ * from the server <b>without exception</b>.</p>
+ *
+ * @exception IOException if there was a problem closing this
+ * response
+ */
+ public void close() throws IOException;
+
+ /**
+ * Returns this response's header fields.
+ *
+ * @return the <code>Context</code> containing the header
+ * key, value pairs.
+ */
+ public IContext getContext();
+
+ /**
+ * Gets the contents of the response body as a DOM
+ * <code>Document</code>.
+ * <p>
+ * This response MUST have an XML body (i.e., <code>
+ * hasDocumentBody()</code> must return <code>true</code>).</p>
+ * <p>
+ * Once the body has been read as an <code>InputStream</code>
+ * it cannot be subsequently read as a <code>Document</code>
+ * (the bytes have been consumed).
+ * <p>
+ * If a problem occurs parsing the document body an <code>
+ * IOException</code> is thrown.
+ *
+ * @return DOM document obtained from the XML body.
+ * @exception IOException if there was a problem receiving the
+ * response or interpreting it as XML.
+ */
+ public Document getDocumentBody() throws IOException;
+
+ /**
+ * Returns an open input stream for reading the
+ * the body of this response.
+ * <p>
+ * This response must not have an XML body (i.e.,
+ * <code>hasElementBody()</code> must return <code>false
+ * </code>).</p>
+ * <p>
+ * The client may close the stream early, however, the
+ * resulting stream will be closed if necessary when
+ * the client closes this response.</p>
+ *
+ * @return the bytes of the response as an <code>InputStream</code>.
+ */
+ public InputStream getInputStream();
+
+ /**
+ * Returns the HTTP response status code.
+ * <p>
+ * As a convenience, the status code should be
+ * one of the <code>SC_* </code> constants
+ * defined in this class.</p>
+ *
+ * @return the response status code.
+ */
+ public int getStatusCode();
+
+ /**
+ * Returns the response status message.
+ * <p>
+ * The status message is the HTTP string that follows
+ * the status code on the first line of the response.</p>
+ *
+ * @return the status message verbatim.
+ */
+ public String getStatusMessage();
+
+ /**
+ * Returns whether this response has an XML element
+ * as a body; this is the element that would be read
+ * if <code>readDocumentBody()</code> was called.
+ * <p>
+ * This method can be called numerous times, and can
+ * be called after the body has been read either as
+ * an InputStream or a Document -- all with no bad
+ * effect.</p>
+ *
+ * @return <code>true</code> if this message has a
+ * document body and <code>false</code> otherwise.
+ */
+ public boolean hasDocumentBody();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IResponse.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServer.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServer.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServer.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,423 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.w3c.dom.Document;
+
+/**
+ * Represents a WebDAV server API.
+ * <p>
+ * There is a one-to-one correspondence between the methods
+ * in this interface and methods in the HTTP and WebDAV
+ * protocols.</p>
+ * <p>
+ * The methods all return a response object; it is the
+ * client's responsibility to <code>close()</code> the response
+ * when they are done with it.</p>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public interface IServer {
+
+ /**
+ * Corresponds to the BASELINE-CONTROL method defined in the WebDAV
+ * Versioning Specification.
+ * The <code>IResponse</code> body is undefined.
+ *
+ * @param locator the location of the collection to put under baseline control.
+ * @param context key-value pairings defined by the user.
+ * @param body the DOM document for the DAV:baseline element.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it.
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response.
+ */
+ public IResponse baselineControl(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Binds the given source locator, to the given destination. An overwrite boolean may
+ * be defined in the user context. Corresponds to the WebDAV method BIND defined
+ * in the WebDAV Bindings Specification (part of the Advanced Collections Protocol)
+ *
+ * @param source the location of the resource
+ * @param destination the location of the resource's desired parent
+ * @param context key-value pairings as set by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse bind(ILocator source, ILocator destination, IContext context) throws IOException;
+
+ /**
+ * Corresponds to the CHECKIN method defined in the WebDAV
+ * Versioning Specification.
+ * The <code>IResponse</code> body is undefined.
+ *
+ * @param locator the location of the resource to check in.
+ * @param context key-value pairings defined by the user.
+ * @param body DOM document for DAV:checkin.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it.
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response.
+ */
+ public IResponse checkin(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Corresponds to the CHECKOUT method defined in the WebDAV
+ * Versioning Specification.
+ * The <code>IResponse</code> body is undefined.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body the XML elements that describe the parameters
+ * of the checkout in a DAV:checkout element.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it.
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response.
+ */
+ public IResponse checkout(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Copies the resource with the given locator, to the given
+ * destination. Corresponds to the COPY method defined in
+ * the WebDAV Specification.
+ *
+ * @param source the location of the resource
+ * @param destination the desired location of the resource copy
+ * @param context key-value pairings as defined by the user
+ * @param body XML document describing the properties to copy
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse copy(ILocator source, ILocator destination, IContext context, Document body) throws IOException;
+
+ /**
+ * Deletes the resource with the given locator. Corresponds to
+ * the DELETE method defined in the HTTP/1.1 Specfication.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings as defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse delete(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Gets the content of the resource with the given locator.
+ * Corresponds to the GET method defined in the HTTP/1.1 specification.
+ * <p>
+ * The input stream in the resulting response body should be closed
+ * by the user.</p>
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings as defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse get(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Returns the message headers from a message send to the server.
+ * Corresponds to the HEAD method defined in the HTTP/1.1 specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings as defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse head(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Corresponds to the LABEL method defined in the WebDAV
+ * Versioning Specification.
+ * The <code>IResponse</code> body is undefined.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body DOM document for DAV:label element
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse label(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Locks the resource with the given locator. Use the information
+ * contained in the context and DAV:lockinfo element. Corresponds
+ * to the LOCK method defined in the WebDAV specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body XML document containing lock information
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse lock(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Corresponds to the MERGE method defined in the WebDAV
+ * Versioning Specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body XML document containing MERGE parameters
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse merge(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Creates an activity as specified by the given locator.
+ * Corresponds to the MKACTIVITY method as defined by the
+ * Delta-V Versioning Specification.
+ *
+ * @param locator the location of the new resource.
+ * @param context key-value pairings defined by the user.
+ * @param element an undefined XML body document.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response.
+ */
+ public IResponse mkactivity(ILocator locator, IContext context, Document element) throws IOException;
+
+ /**
+ * Creates the collection specified by the given locator.
+ * Corresponds to the MKCOL method as defined by the WebDAV specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param element XML document containing properties
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse mkcol(ILocator locator, IContext context, Document element) throws IOException;
+
+ /**
+ * Creates a workspace as specified by the given locator. Corresponds to the
+ * MKWORKSPACE method as defined by the Delta-V Versioning Specification.
+ *
+ * @param locator the location of the new resource.
+ * @param context key-value pairings defined by the user.
+ * @param element an undefined XML body document.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response.
+ */
+ public IResponse mkworkspace(ILocator locator, IContext context, Document element) throws IOException;
+
+ /**
+ * Moves the resource with the given source locator, to the
+ * specified destination. Corresponds to the MOVE method as
+ * defined by the WebDAV specification.
+ *
+ * @param source the location of the resource
+ * @param destination the desired location for the resource
+ * @param context key-value pairing defined by the user
+ * @param body XML document specifying the properties to move
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse move(ILocator source, ILocator destination, IContext context, Document body) throws IOException;
+
+ /**
+ * Performs an options call to the server. Answers a list of
+ * characteristics of the target resource.
+ * <p>
+ * Corresponds to the OPTIONS method as defined by the HTTP/1.1
+ * Specification.</p>
+ * <p>
+ * If the resource URL (in the locator) is "*", the server's
+ * general capabilities are queried.</p>
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse options(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Corresponds to the POST method as defined by the HTTP/1.1
+ * specification.
+ * <p>
+ * The given input stream will be closed by the server after
+ * the contents have been consumed.</p>
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param input the input stream containing the resource data
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse post(ILocator locator, IContext context, InputStream input) throws IOException;
+
+ /**
+ * Performs a property find on the server. Corresponds to the
+ * PROPFIND method as defined by the WebDAV specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body XML document as defined by the spec
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse propfind(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Performs a property patch call on the server. Corresponds to the
+ * PROPPATCH method as defined by the WebDAV specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body XML document as defined by the spec
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse proppatch(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Puts the given contents onto the server into the specified
+ * location. Corresponds to the PUT method as defined by the
+ * HTTP/1.1 specification.
+ * <p>
+ * The given input stream will be closed by the server after the
+ * contents have been consumed.</p>
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param input the input stream containing the resource data
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse put(ILocator locator, IContext context, InputStream input) throws IOException;
+
+ /**
+ * Corresponds to the REPORT method defined in the WebDAV
+ * Versioning Specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @param body XML document containing REPORT parameters
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse report(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Does a trace call to the server. Corresponds to the TRACE method
+ * as defined by the HTTP/1.1 specification.
+ * <p>
+ * The input stream in the response body should be closed by the user.</p>
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse trace(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Corresponds to the UNCHECKOUT method defined in the WebDAV
+ * Versioning Specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse uncheckout(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Unlocks the resource with the given locator. Corresponds to the
+ * UNLOCK method as defined by the WebDAV specification.
+ *
+ * @param locator the location of the resource
+ * @param context key-value pairings defined by the user
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse unlock(ILocator locator, IContext context) throws IOException;
+
+ /**
+ * Performs an update call on the server. Corresponds to the
+ * UPDATE method as defined by the Delta-V specification.
+ *
+ * @param locator the location of the version-controlled resource.
+ * @param context key-value pairings defined by the client.
+ * @param body DAV:update XML document as defined by the spec.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse update(ILocator locator, IContext context, Document body) throws IOException;
+
+ /**
+ * Corresponds to the VERSION-CONTROL method defined in the WebDAV
+ * Versioning Specification.
+ *
+ * @param locator the location of the versionable resource.
+ * @param context key-value pairings defined by the user.
+ * @param body the request body elements as a DOM document.
+ * @return the response from the server; the client
+ * must send <code>close()</code> to the response when done with it
+ * @exception IOException if there was a problem sending the request
+ * or receiving the response
+ */
+ public IResponse versionControl(ILocator locator, IContext context, Document body) throws IOException;
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServer.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServerFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServerFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+/**
+ * Factory for constructing WebDAV servers.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see IServer
+ */
+public interface IServerFactory {
+
+ /**
+ * Returns a new server for the WebDAV server with
+ * the given URL.
+ */
+ public IServer newServer(String serverURL);
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/IServerFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/Policy.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/Policy.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/Policy.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav;
+
+import java.text.MessageFormat;
+import java.util.*;
+
+public class Policy {
+ private static String bundleName = "org.eclipse.webdav.messages";//$NON-NLS-1$
+ private static ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+
+ /**
+ * Lookup the message with the given ID in this catalog
+ */
+ public static String bind(String id) {
+ return bind(id, (String[]) null);
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string.
+ */
+ public static String bind(String id, String binding) {
+ return bind(id, new String[] {binding});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given strings.
+ */
+ public static String bind(String id, String binding1, String binding2) {
+ return bind(id, new String[] {binding1, binding2});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string values.
+ */
+ public static String bind(String id, String[] bindings) {
+ if (id == null)
+ return "No message available";//$NON-NLS-1$
+ String message = null;
+ try {
+ message = bundle.getString(id);
+ } catch (MissingResourceException e) {
+ // If we got an exception looking for the message, fail gracefully by just returning
+ // the id we were looking for. In most cases this is semi-informative so is not too bad.
+ return "Missing message: " + id + "in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (bindings == null)
+ return message;
+ return MessageFormat.format(message, bindings);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/Policy.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ActiveLock.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ActiveLock.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ActiveLock.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.Policy;
+import org.eclipse.webdav.internal.kernel.Context;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * An element editor for the WebDAV activelock element. See RFC2518
+ * section 12.1 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see LockDiscovery
+ * @see Owner
+ */
+public class ActiveLock extends ElementEditor {
+
+ // An ordered collection of the element names of the activelock
+ // element's children.
+ protected static final String[] childNames = new String[] {"lockscope", //$NON-NLS-1$
+ "locktype", //$NON-NLS-1$
+ "depth", //$NON-NLS-1$
+ "owner", //$NON-NLS-1$
+ "timeout", //$NON-NLS-1$
+ "locktoken"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV activelock element. The
+ * element is assumed to be well formed.
+ *
+ * @param root an activelock element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public ActiveLock(Element root) throws MalformedElementException {
+ super(root, "activelock"); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds the given href to this activelock's locktoken. The href must not
+ * be <code>null</code>.
+ *
+ * @param href the href to add
+ */
+ public void addLockTokenHref(String href) {
+ Assert.isNotNull(href);
+ Element locktoken = getLastChild(root, "locktoken"); //$NON-NLS-1$
+ if (locktoken == null)
+ locktoken = setChild(root, "locktoken", childNames, false); //$NON-NLS-1$
+ appendChild(locktoken, "href", encodeHref(href)); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the depth of this activelock; for example,
+ * <code>Context.DEPTH_ZERO</code>.
+ *
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ * @see Context
+ */
+ public String getDepth() throws MalformedElementException {
+ String depth = getChildText(root, "depth", false); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingDepthElmt"), depth); //$NON-NLS-1$
+ ensure(depth.equals(IContext.DEPTH_ZERO) || depth.equals(IContext.DEPTH_ONE) || depth.equals(IContext.DEPTH_INFINITY), Policy.bind("ensure.invalidDepth", depth)); //$NON-NLS-1$
+ return depth;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> of <code>String</code>s
+ * containing this activelock's lock token hrefs.
+ *
+ * @return an <code>Enumeration</code> of <code>String</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getLockTokenHrefs() throws MalformedElementException {
+ Element locktoken = getLastChild(root, "locktoken"); //$NON-NLS-1$
+ Element firstHref = null;
+ if (locktoken != null) {
+ firstHref = getFirstChild(locktoken, "href"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), firstHref); //$NON-NLS-1$
+ }
+ final Node node = firstHref;
+ Enumeration e = new Enumeration() {
+ Node currentHref = node;
+
+ public boolean hasMoreElements() {
+ return currentHref != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements()) {
+ throw new NoSuchElementException();
+ }
+ String href = getFirstText((Element) currentHref);
+ currentHref = getTwin((Element) currentHref, true);
+ return decodeHref(href);
+ }
+ };
+
+ return e;
+ }
+
+ /**
+ * Returns this activelock's owner, or <code>null</code> if this
+ * active lock has no owner.
+ *
+ * @return this activelock's owner, or <code>null</code>
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Owner getOwner() throws MalformedElementException {
+ Element owner = getLastChild(root, "owner"); //$NON-NLS-1$
+ if (owner == null)
+ return null;
+ return new Owner(owner);
+ }
+
+ /**
+ * Returns this activelock's timeout, or <code>null</code> if this
+ * active lock has no timeout.
+ *
+ * @return this activelock's timeout, or <code>null</code>
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getTimeout() throws MalformedElementException {
+ return getChildText(root, "timeout", false); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns <code>true</code> if this activelock is shared, or
+ * <code>false</code> if it is exclusive.
+ *
+ * @return a boolean indicating whether this activelock is shared or
+ * exclusive
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isShared() throws MalformedElementException {
+
+ Element lockscope = getFirstChild(root, "lockscope"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingLockscopeElmt "), lockscope); //$NON-NLS-1$
+
+ String[] names = new String[] {"shared", "exclusive"}; //$NON-NLS-1$ //$NON-NLS-2$
+ Element sharedOrExclusive = getFirstChild(lockscope, names);
+ ensureNotNull(Policy.bind("ensure.missingSharedOrExclusiveElmt"), sharedOrExclusive); //$NON-NLS-1$
+
+ boolean isShared = isDAVElement(sharedOrExclusive, "shared"); //$NON-NLS-1$
+ ensure(getNextSibling(sharedOrExclusive, names) == null, Policy.bind("ensure.conflictingSharedOrExclusiveElmt")); //$NON-NLS-1$
+
+ return isShared;
+ }
+
+ /**
+ * Sets the depth of this activelock to the given depth. The depth must
+ * not be null and must be one of:
+ * <ul>
+ * <li><code>Context.DEPTH_ZERO</code>
+ * <li><code>Context.DEPTH_ONE</code>
+ * <li><code>Context.DEPTH_INFINITY</code>
+ * </ul>
+ *
+ * @param depth the depth for this activelock
+ * @see Context
+ */
+ public void setDepth(String depth) {
+ Assert.isNotNull(depth);
+ Assert.isTrue(depth.equals(IContext.DEPTH_ZERO) || depth.equals(IContext.DEPTH_ONE) || depth.equals(IContext.DEPTH_INFINITY));
+ setChild(root, "depth", depth, childNames, false); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets whether this activelock is shared or exclusive. If isShared is
+ * <code>true</code>, the activelock is set as shared, otherwise, the
+ * activelock is set as exclusive.
+ *
+ * @param isShared a boolean indicating whether this activelock will be
+ * set to be shared or exclusive
+ */
+ public void setIsShared(boolean isShared) {
+ Element lockscope = setChild(root, "lockscope", childNames, true); //$NON-NLS-1$
+ if (isShared)
+ appendChild(lockscope, "shared"); //$NON-NLS-1$
+ else
+ appendChild(lockscope, "exclusive"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates and sets an owner element on this activelock and returns an
+ * editor on it.
+ *
+ * @return an editor on an owner element
+ */
+ public Owner setOwner() {
+ Element owner = setChild(root, "owner", childNames, false); //$NON-NLS-1$
+ Owner result = null;
+ try {
+ result = new Owner(owner);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Sets the timeout on this activelock to the given timeout. If the
+ * timeout is <code>null</code> the current timeout is removed.
+ *
+ * @param timeout the timeout value for this activelock, or
+ * <code>null</code> for no timeout
+ */
+ public void setTimeout(String timeout) {
+ if (timeout == null) {
+ Element child = getLastChild(root, "timeout"); //$NON-NLS-1$
+ if (child != null)
+ root.removeChild(child);
+ } else
+ setChild(root, "timeout", timeout, childNames, false); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ActiveLock.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Assert.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Assert.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Assert.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+
+/**
+ * <code>Assert</code> is useful for for embedding runtime sanity checks
+ * in code.
+ * The predicate methods all test a condition and throw some
+ * type of unchecked exception if the condition does not hold.
+ * <p>
+ * Assertion failure exceptions, like most runtime exceptions, are
+ * thrown when something is misbehaving. Assertion failures are invariably
+ * unspecified behavior; consequently, clients should never rely on
+ * these being thrown (and certainly should not being catching them
+ * specifically).
+ * </p>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+/* package */class Assert {
+ /** Asserts that the given object is not <code>null</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ */
+ public static void isNotNull(Object o) {
+ isNotNull(o, ""); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given object is not <code>null</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ */
+ public static void isNotNull(Object o, String message) {
+ if (o == null)
+ throw new AssertionFailedException(Policy.bind("assert.nullArgument", message)); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given boolean is <code>true</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ */
+ public static boolean isTrue(boolean expression) {
+ return isTrue(expression, ""); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given boolean is <code>true</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ */
+ public static boolean isTrue(boolean expression, String message) {
+ if (!expression)
+ throw new AssertionFailedException(Policy.bind("assert.failed", message)); //$NON-NLS-1$
+ return expression;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Assert.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/AssertionFailedException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/AssertionFailedException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/AssertionFailedException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+/**
+ * <code>AssertionFailedException</code> is a runtime exception thrown
+ * by some of the methods in <code>Assert</code>.
+ * <p>
+ * This class is not declared public to prevent some misuses; programs that catch
+ * or otherwise depend on assertion failures are susceptible to unexpected
+ * breakage when assertions in the code are added or removed.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+/* package */class AssertionFailedException extends RuntimeException {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Constructs a new exception.
+ */
+ public AssertionFailedException() {
+ super();
+ }
+
+ /** Constructs a new exception with the given message.
+ */
+ public AssertionFailedException(String detail) {
+ super(detail);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/AssertionFailedException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/BaselineControl.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/BaselineControl.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/BaselineControl.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV baseline control element. See
+ * the latest Delta-V protocol document for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class BaselineControl extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the resourceid
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"href"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV baseline control element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a baseline control element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public BaselineControl(Element root) throws MalformedElementException {
+ super(root, "baseline-control"); //$NON-NLS-1$
+ }
+
+ /**
+ * Answer the href passed in the body of the baseline control element.
+ */
+ public String getHref() throws MalformedElementException {
+ String href = getChildText(root, "href", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), href); //$NON-NLS-1$
+ return decodeHref(href);
+ }
+
+ /**
+ * Sets this baseline control elment description to the given href.
+ *
+ * @param href the href of the baseline.
+ */
+ public void setHref(String href) {
+ Assert.isNotNull(href);
+ setChild(root, "href", encodeHref(href), childNames, true); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/BaselineControl.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Bindings.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Bindings.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Bindings.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * An element editor for the WebDAV bindings element. See INTERNET DRAFT
+ * draft-ietf-webdav-binding-protocol-02 section 13.1 for the element's
+ * definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Bindings extends Property {
+ /**
+ * An ordered collection of the element names of the bindings
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"href", "segment"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * This class represent a single binding.
+ *
+ * @see Bindings#getBindings()
+ */
+ public class Binding {
+ private String fHref = null;
+ private String fSegment = null;
+
+ /**
+ * Construct a new binding with the given href and segment. The
+ * href and segment must not be null.
+ *
+ * @param href the binding's href
+ * @param segment the binding's segment
+ */
+ public Binding(String href, String segment) {
+ Assert.isNotNull(href);
+ Assert.isNotNull(segment);
+ fHref = href;
+ fSegment = segment;
+ }
+
+ /**
+ * Return this binding's href.
+ */
+ public String getHref() {
+ return fHref;
+ }
+
+ /**
+ * Return this binding's segment.
+ */
+ public String getSegment() {
+ return fSegment;
+ }
+ }
+
+ /**
+ * Creates a new editor on the given WebDAV bindings element. The
+ * element is assumed to be well formed.
+ *
+ * @param root bindings element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Bindings(Element root) throws MalformedElementException {
+ super(root, "bindings"); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds the specified binding to this editor's bindings element. The
+ * given href and segment must not be <code>null</code>.
+ *
+ * @param href the href part of the binding to add
+ * @param segment the segment part of the binding to add
+ */
+ public void addBinding(String href, String segment) {
+ Assert.isNotNull(href);
+ Assert.isNotNull(segment);
+ appendChild(root, "href", encodeHref(href)); //$NON-NLS-1$
+ appendChild(root, "segment", segment); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this bindings
+ * <code>Binding</code>s.
+ *
+ * @return an <code>Enumeration</code> of <code>Bindings.Binding</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getBindings() throws MalformedElementException {
+
+ final Node firstHref = getFirstChild(root, "href"); //$NON-NLS-1$
+ Node segment = null;
+ if (firstHref != null)
+ segment = getNextSibling((Element) firstHref, "segment"); //$NON-NLS-1$
+
+ final Node firstSegment = segment;
+
+ Enumeration e = new Enumeration() {
+ Node fCurrentHref = firstHref;
+ Node fCurrentSegment = firstSegment;
+
+ public boolean hasMoreElements() {
+
+ return fCurrentHref != null && fCurrentSegment != null;
+ }
+
+ public Object nextElement() {
+
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+
+ String nextHref = getFirstText((Element) fCurrentHref);
+ String nextSegment = getFirstText((Element) fCurrentSegment);
+ Binding nextBinding = new Binding(decodeHref(nextHref), nextSegment);
+
+ fCurrentHref = getNextSibling((Element) fCurrentSegment, "href"); //$NON-NLS-1$
+ fCurrentSegment = null;
+ if (fCurrentHref != null)
+ fCurrentSegment = getNextSibling((Element) fCurrentHref, "segment"); //$NON-NLS-1$
+
+ return nextBinding;
+ }
+ };
+
+ return e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Bindings.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Conflict.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Conflict.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Conflict.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV conflict element. See INTERNET-DRAFT
+ * draft-ietf-deltav-versioning-03.1 section 12.1.2 for the element's
+ * definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see ConflictReportResponse
+ */
+public class Conflict extends ElementEditor {
+ /**
+ * Creates a new editor on the given WebDAV conflict element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a conflict element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Conflict(Element root) throws MalformedElementException {
+ super(root, "conflict"); //$NON-NLS-1$
+ }
+
+ public void addContributor(String contributor) {
+ // do nothing
+ }
+
+ public String getCommonAncestor() throws MalformedElementException {
+ return null;
+ }
+
+ public Enumeration getContributors() throws MalformedElementException {
+ return null;
+ }
+
+ public String getHref() throws MalformedElementException {
+ return null;
+ }
+
+ public void setCommonAncestor(String commonAncestor) {
+ // do nothing
+ }
+
+ public void setContributor(String contributor) {
+ // do nothing
+ }
+
+ public void setHref(String href) {
+ // do nothing
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Conflict.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ConflictReportResponse.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ConflictReportResponse.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ConflictReportResponse.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV conflict-report-response element.
+ * See INTERNET-DRAFT draft-ietf-deltav-versioning-03.1 section 12.1.2
+ * for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Conflict
+ */
+public class ConflictReportResponse extends ElementEditor {
+ /**
+ * Creates a new editor on the given WebDAV conflict-report-response
+ * element. The element is assumed to be well formed.
+ *
+ * @param root a conflict-report-response element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public ConflictReportResponse(Element root) throws MalformedElementException {
+ super(root, "conflict-report-response"); //$NON-NLS-1$
+ }
+
+ public Conflict addConflict() {
+ return null;
+ }
+
+ public Enumeration getConflicts() throws MalformedElementException {
+ return null;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ConflictReportResponse.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1799 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import org.eclipse.webdav.Policy;
+import org.eclipse.webdav.internal.utils.URLDecoder;
+import org.eclipse.webdav.internal.utils.URLEncoder;
+import org.w3c.dom.*;
+import org.w3c.dom.CharacterData;
+
+/**
+ * Abstract superclass of all element editors. An element editor is a
+ * convenience for manipulating DOM elements. Specific subclasses declared
+ * in this package correspond to the major DOM element types for the WebDAV
+ * protocol; e.g., the class <code>ResponseBody</code> corresponds to
+ * <DAV:response>.
+ * <p>
+ * Element editors contain no state of their own; all they they hang onto
+ * is a single DOM <code>Element</code>; all information is stored in the DOM
+ * itself. Thus element editors are really just lightweight, throw-away
+ * wrappers.</p>
+ * <p>
+ * Element editors assume that they are working with elements that are "up to
+ * spec". When an element editor encounters an element that is not how it
+ * should be, it throws a <code>MalformedElementException</code> (a checked
+ * exception). The editor does not provide any further diagnosis of what's
+ * wrong. Clients catching this exception will generally conclude that they're
+ * talking to a non-compliant (or malfunctioning) WebDAV server.</p>
+ * <p>
+ * Fully-capable element editors can be written using the DOM API. No access
+ * is required to any concrete implementation of the DOM. The element editors
+ * in this package all have this property.</p>
+ * <p>
+ * This class also provides rudimentary XML namespace support and element
+ * navigation and manipulation methods that are useful when writing element
+ * editors.</p>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public abstract class ElementEditor {
+
+ // The root element upon which this editor is based.
+ // This field is never <code>null</code>.
+ // However, it cannot be assumed that this element conforms
+ // to the appropriate specification (the DOM can be changed
+ // from underneath its editor).
+ protected Element root;
+
+ // The official URI for WebDAV namespace.
+ protected static final String DAV_NS = "DAV:"; //$NON-NLS-1$
+
+ // The official prefix for XML namespace declarations,
+ // namely "xmlns" (note: no colon).
+ protected static final String XML_PREFIX = "xmlns"; //$NON-NLS-1$
+
+ // The official XML namespace prefix.
+ protected static final String XML_NS_PREFIX = "xml"; //$NON-NLS-1$
+
+ // The official XML namespace name.
+ protected static final String XML_NS_NAME = "http://www.w3.org/XML/1998/namespace"; //$NON-NLS-1$
+
+ /**
+ * Constructs a new element editor for the given element. The element
+ * must not be <code>null</code>.
+ *
+ * @param root the element to be edited
+ * @throws MalformedElementException if the element is not null
+ */
+ protected ElementEditor(Element root) throws MalformedElementException {
+ Assert.isNotNull(root);
+ this.root = root;
+ }
+
+ /**
+ * Constructs a new element editor for the given element. The element
+ * must not be <code>null</code>.
+ *
+ * @param root the element to be edited
+ * @throws MalformedElementException if the element is not null
+ */
+ protected ElementEditor(Element root, String expectedType) throws MalformedElementException {
+ Assert.isNotNull(root);
+ Assert.isNotNull(expectedType);
+ this.root = root;
+ ensureDAVElement(root, expectedType, Policy.bind("ensure.expectingAnElmt", expectedType)); //$NON-NLS-1$
+ }
+
+ /**
+ * <p>Creates a WebDAV element with the given name and adds it as a
+ * child of the given parent. Returns the child element.
+ * <p>Children are positioned in the order specified by the given names.
+ * If children with the same name as the child already exist, the child
+ * is inserted after the rightmost child. If firstToLast is true, the
+ * search for the child's position starts at the parent's first child,
+ * otherwise, the search starts at the parent's last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child's name must not be <code>null</code>. The
+ * parent's valid child names must not be <code>null</code>, and must
+ * contain the name of the child.
+ *
+ * @param parent the parent to which the child is added
+ * @param name the name of the child which is created and added
+ * to the parent
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ * @return the child element that is created
+ */
+ public static Element addChild(Element parent, String name, String[] names, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Assert.isNotNull(names);
+ String nsPrefix = getNSPrefix(parent);
+ String tagName = nsPrefix == null ? name : nsPrefix + ":" + name; //$NON-NLS-1$
+ Element child = parent.getOwnerDocument().createElement(tagName);
+ addChild(parent, child, names, firstToLast);
+ return child;
+ }
+
+ /**
+ * <p>Creates a WebDAV element with the given name and adds it as a
+ * child of the given parent. In addition, a text node created from the
+ * given data is created and appended to the child. Returns the child
+ * element.
+ * <p>Children are positioned in the order specified by the given names.
+ * If children with the same name as the child already exist, the child
+ * is inserted after the rightmost child. If firstToLast is true, the
+ * search for the child's position starts at the parent's first child,
+ * otherwise, the search starts at the parent's last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child's name and data must not be <code>null</code>.
+ * The parent's valid child names must not be <code>null</code>, and
+ * must contain the name of the child.
+ *
+ * @param parent the parent to which the child is added
+ * @param name the name of the child which is created and added
+ * to the parent
+ * @param data the data of the text node which is created and
+ * added to the child
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ * @return the child element that is created
+ */
+ public static Element addChild(Element parent, String name, String data, String[] names, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Assert.isNotNull(data);
+ Assert.isNotNull(names);
+ Element child = addChild(parent, name, names, firstToLast);
+ child.appendChild(child.getOwnerDocument().createTextNode(data));
+ return child;
+ }
+
+ /**
+ * Adds the given child element as a child of the given parent.
+ * <p>
+ * Children are positioned in the order specified by the given names.
+ * If children with the same name as the child already exist, the child
+ * is inserted after the rightmost child. If firstToLast is true, the
+ * search for the child's position starts at the parent's first child,
+ * otherwise, the search starts at the parent's last child.</p>
+ * <p>
+ * The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child must not be null and its namespace prefix must
+ * resolve to the WebDAV namespace URL in the parent. The parent's valid
+ * child names must not be <code>null</code>, and must contain the name
+ * of the child.</p>
+ *
+ * @param parent the parent to which the child is added
+ * @param child the child which is added to the parent
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ */
+ public static void addChild(Element parent, Element child, String[] names, boolean firstToLast) {
+
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(child);
+ Assert.isTrue(DAV_NS.equals(resolve(getNSPrefix(child), parent)));
+ Assert.isNotNull(names);
+
+ boolean found = false;
+ String name = getNSLocalName(child);
+ for (int i = 0; !found && i < names.length; ++i)
+ found = names[i].equals(name);
+ Assert.isTrue(found);
+
+ Node sibling = getChild(parent, name, names, firstToLast);
+
+ if (firstToLast) {
+ if (sibling == null)
+ parent.appendChild(child);
+ else {
+ Node lastTwin = null;
+ while (isDAVElement(sibling, name)) {
+ lastTwin = sibling;
+ sibling = getTwin((Element) sibling, firstToLast);
+ }
+ if (lastTwin == null)
+ parent.insertBefore(child, sibling);
+ else {
+ Node refChild = lastTwin.getNextSibling();
+ if (refChild == null)
+ parent.appendChild(child);
+ else
+ parent.insertBefore(child, refChild);
+ }
+ }
+ } else {
+ Node refChild = null;
+ if (sibling == null) {
+ refChild = parent.getFirstChild();
+ } else {
+ refChild = sibling.getNextSibling();
+ }
+ if (refChild == null) {
+ parent.appendChild(child);
+ } else {
+ parent.insertBefore(child, refChild);
+ }
+ }
+ }
+
+ /**
+ * Creates a WebDAV element with the given name and appends it as a
+ * child of the given parent. Returns the child element. The parent must
+ * not be <code>null</code> and must be a WebDAV element. The name of
+ * the child must not be <code>null</code>.
+ *
+ * @param parent the parent element to which the child is added
+ * @param name the name of the child element that is created and added
+ * as a child of the parent
+ * @return the child element that is created
+ */
+ public static Element appendChild(Element parent, String name) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ String nsPrefix = getNSPrefix(parent);
+ String tagName = nsPrefix == null ? name : nsPrefix + ":" + name; //$NON-NLS-1$
+ Element child = parent.getOwnerDocument().createElement(tagName);
+ parent.appendChild(child);
+ return child;
+ }
+
+ /**
+ * Creates a WebDAV element with the given name and appends it as a
+ * child of the given parent. In addition, a text node created from the
+ * given data is created and appended to the child. Returns the child
+ * element. The parent must not be <code>null</code> and must be a
+ * WebDAV element. The name of the child must not be <code>null</code>.
+ * The data must not be <code>null</code>.
+ *
+ * @param parent the parent element to which the child is added
+ * @param name the name of the child element that is created and added
+ * as a child of the parent
+ * @param data the data of the text node which is created and added to
+ * the child
+ * @return the child element that is created
+ */
+ public static Element appendChild(Element parent, String name, String data) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Assert.isNotNull(data);
+ Element child = appendChild(parent, name);
+ child.appendChild(child.getOwnerDocument().createTextNode(data));
+ return child;
+ }
+
+ /**
+ * Returns a clone of the given node. The given document becomes the
+ * owner document of the clone.
+ *
+ * @param document the owner document of the clone
+ * @param node the node to clone
+ * @return a clone of the given node
+ */
+ public static Node cloneNode(Document document, Node node) {
+
+ Node nodeClone = null;
+
+ switch (node.getNodeType()) {
+ case Node.ELEMENT_NODE :
+ {
+ nodeClone = document.createElement(((Element) node).getTagName());
+ NamedNodeMap namedNodeMap = node.getAttributes();
+ for (int i = 0; i < namedNodeMap.getLength(); ++i) {
+ Attr attr = (Attr) namedNodeMap.item(i);
+ Attr attrClone = document.createAttribute(attr.getName());
+ attrClone.setValue(attr.getValue());
+ ((Element) nodeClone).setAttributeNode(attrClone);
+ }
+ }
+ break;
+ case Node.TEXT_NODE :
+ nodeClone = document.createTextNode(((CharacterData) node).getData());
+ break;
+ case Node.CDATA_SECTION_NODE :
+ nodeClone = document.createCDATASection(((CharacterData) node).getData());
+ break;
+ case Node.ENTITY_REFERENCE_NODE :
+ nodeClone = document.createEntityReference(node.getNodeName());
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ nodeClone = document.createProcessingInstruction(((ProcessingInstruction) node).getTarget(), ((ProcessingInstruction) node).getData());
+ break;
+ case Node.COMMENT_NODE :
+ nodeClone = document.createComment(((CharacterData) node).getData());
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE :
+ nodeClone = document.createDocumentFragment();
+ break;
+ case Node.DOCUMENT_NODE :
+ case Node.DOCUMENT_TYPE_NODE :
+ case Node.NOTATION_NODE :
+ case Node.ATTRIBUTE_NODE :
+ case Node.ENTITY_NODE :
+ Assert.isTrue(false, Policy.bind("assert.notSupported")); //$NON-NLS-1$
+ break;
+ default :
+ Assert.isTrue(false, Policy.bind("assert.unknownNodeType")); //$NON-NLS-1$
+ }
+
+ return nodeClone;
+ }
+
+ /**
+ * Creates a WebDAV element with the given name and adds it as the root
+ * of the given document. In addition, the WebDAV namespace is declared
+ * on the new element. Returns the new element. The document must not be
+ * <code>null</code> and must not already have a root element. The name
+ * of the element to be created must not be <code>null</code>.
+ *
+ * @param document the document in which the new element is rooted
+ * @param name the name of the element to be created
+ * @return the rooted element
+ */
+ public static Element create(Document document, String name) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getDocumentElement() == null);
+ Assert.isNotNull(name);
+ Element element = document.createElement(name);
+ declareNS(element, null, DAV_NS);
+ document.appendChild(element);
+ return element;
+ }
+
+ /**
+ * Adds a namespace declaration to the given element. If only the prefix
+ * is <code>null</code>, a default namespace is declared. If the prefix
+ * and the namespaceUrl are <code>null</code> the default namespace is
+ * removed. The element must not be <code>null</code>. If the
+ * namespaceUrl is <code>null</code>, the <code>prefix</code> must also
+ * be <code>null</code>.
+ *
+ * @param element the element to receive the namespace attribute
+ * @param prefix the prefix to be used (without a colon); for
+ * example, "D", or <code>null</code>
+ * @param namespaceUrl the URL of the namespace; for example, "DAV:", or
+ * <code>null</code>
+ */
+ public static void declareNS(Element element, String prefix, String namespaceUrl) {
+ Assert.isNotNull(element);
+ Assert.isTrue(namespaceUrl != null || prefix == null && namespaceUrl == null);
+ String name = XML_PREFIX + (prefix == null ? "" : ":" + prefix); //$NON-NLS-1$ //$NON-NLS-2$
+ String value = namespaceUrl == null ? "" : namespaceUrl; //$NON-NLS-1$
+ element.setAttribute(name, value);
+ }
+
+ /**
+ * Decodes the given href from a form that is safe for transport.
+ *
+ * @param href the href to be decoded
+ */
+ public static String decodeHref(String href) {
+ return URLDecoder.decode(href);
+ }
+
+ /**
+ * Encodes the given href to a form that is safe for transport.
+ *
+ * @param href the href to be encoded
+ */
+ public static String encodeHref(String href) {
+ return URLEncoder.encode(href);
+ }
+
+ /**
+ * Ensures that the given value is <code>true</code>.
+ *
+ * @param message the message for the exception that is thrown if the
+ * given value is <code>false</code>
+ * @param value a boolean indicating whether or not a malformed
+ * element exception should be thrown
+ * @throws MalformedElementException with the given message if
+ * the given value is <code>false</code>
+ * @deprecated
+ */
+ protected static void ensure(String message, boolean value) throws MalformedElementException {
+ if (!value)
+ throw new MalformedElementException(message);
+ }
+
+ /**
+ * Ensures that the given value is <code>true</code>.
+ *
+ * @param message the message for the exception that is thrown if the
+ * given value is <code>false</code>
+ * @param value a boolean indicating whether or not a malformed
+ * element exception should be thrown
+ * @throws MalformedElementException with the given message if
+ * the given value is <code>false</code>
+ */
+ protected static void ensure(boolean value, String message) throws MalformedElementException {
+ if (!value)
+ throw new MalformedElementException(message);
+ }
+
+ /**
+ * Ensures that the given node is a WebDAV element with the given name,
+ * returning it as an <code>Element</code> if it is.
+ *
+ * @param message the message for the exception that is thrown if the
+ * node is not a WebDAV element with the given name
+ * @param node the node, or <code>null</code>
+ * @param name the expected local name of the WebDAV element
+ * @returns the node as an <code>Element</code>
+ * @throws MalformedElementException with the given message if it
+ * is not a WebDAV element with the given name
+ * @deprecated
+ */
+ protected static Element ensureDAVElement(String message, Node node, String name) throws MalformedElementException {
+ Assert.isNotNull(name);
+ if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
+ throw new MalformedElementException(message);
+ Element element = (Element) node;
+ if (!name.equals(getNSLocalName(element)) || !DAV_NS.equals(getNSName(element)))
+ throw new MalformedElementException(message);
+ return element;
+ }
+
+ /**
+ * Ensures that the given node is a WebDAV element with the given name.
+ *
+ * @param node the node, or <code>null</code>
+ * @param name the expected local name of the WebDAV element
+ * @param message the message for the exception that is thrown if the
+ * node is not a WebDAV element with the given name
+ * @throws MalformedElementException with the given message if it
+ * is not a WebDAV element with the given name
+ */
+ protected static void ensureDAVElement(Node node, String name, String message) throws MalformedElementException {
+ Assert.isNotNull(name);
+ if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
+ throw new MalformedElementException(message);
+ Element element = (Element) node;
+ if (!name.equals(getNSLocalName(element)) || !DAV_NS.equals(getNSName(element)))
+ throw new MalformedElementException(message);
+ }
+
+ /**
+ * Ensures that the given object is not <code>null</code>.
+ *
+ * @param message the message for the exception that is thrown if the
+ * object is <code>null</code>
+ * @param object the object, or <code>null</code>
+ * @throws MalformedElementException if the given object is
+ * <code>null</code>
+ */
+ protected static void ensureNotNull(String message, Object object) throws MalformedElementException {
+ if (object == null)
+ throw new MalformedElementException(message);
+ }
+
+ /**
+ * Ensures that the given object is <code>null</code>.
+ *
+ * @param message the message for the exception that is thrown if the
+ * object is not <code>null</code>
+ * @param object the object, or <code>null</code>
+ * @throws MalformedElementException if the given object is not
+ * <code>null</code>
+ */
+ protected static void ensureNull(String message, Object object) throws MalformedElementException {
+ if (object != null)
+ throw new MalformedElementException(message);
+ }
+
+ /**
+ * Ensures that the given node is a text node, returning it as a
+ * <code>Text</code> node if it is.
+ *
+ * @param message the message for the exception that is thrown if the
+ * node is not a <code>Text</code> node
+ * @param node the node, or <code>null</code>
+ * @returns the node as a <code>Text</code> node
+ * @exception MalformedElementException if the node is
+ * <code>null</code> or not a text node
+ */
+ protected static Text ensureText(String message, Node node) throws MalformedElementException {
+ if (node == null || node.getNodeType() != Node.TEXT_NODE)
+ throw new MalformedElementException(message);
+ return (Text) node;
+ }
+
+ /**
+ * Clones the given element, and its subtrees, and sets it as the root
+ * of the given document. Returns the cloned element. The document must
+ * not have a root and must not be <code>null</code>. The element must
+ * not be <code>null</code>.
+ *
+ * @param document the document that will become the owner and parent
+ * of the cloned element
+ * @param element the element to be cloned
+ * @returns a clone of the element
+ * @throws MalformedElementException if an element exists in the
+ * subtree to be cloned whose namespace can't be
+ * resolved
+ */
+ public static Element extractElement(Document document, Element element) throws MalformedElementException {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getDocumentElement() == null);
+ Assert.isNotNull(element);
+ return (Element) extractNode(document, element);
+ }
+
+ /**
+ * Clones the given node, and its subtrees, and sets it as the root of
+ * the given parent node. Returns the cloned node. The parent node and
+ * the node to be cloned must not be <code>null</code>.
+ *
+ * @param parent the node that will become the parent of the cloned
+ * node
+ * @param node the node to be cloned
+ * @returns a clone of the element
+ * @throws MalformedElementException if an element exists in the
+ * subtree to be cloned whose namespace can't be resolved
+ */
+ public static Node extractNode(Node parent, Node node) throws MalformedElementException {
+
+ // Get a handle to the root of the parent node tree.
+ Document document;
+ if (parent.getNodeType() == Node.DOCUMENT_NODE)
+ document = (Document) parent;
+ else
+ document = parent.getOwnerDocument();
+
+ // Create a clone of the node owned by the document, and add to the parent.
+ Node nodeClone = cloneNode(document, node);
+ parent.appendChild(nodeClone);
+
+ // If the node is an Element
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+
+ // Figure out its namespace information.
+ String nsPrefix = getNSPrefix((Element) node);
+ String nsName = getNSName((Element) node);
+
+ // Is this namespace already defined on the clone? If not declare it.
+ String nsNameClone = resolve(nsPrefix, (Element) nodeClone);
+ if (nsName != nsNameClone && (nsName == null || !nsName.equals(nsNameClone)))
+ declareNS((Element) nodeClone, nsPrefix, nsName);
+
+ // Do the same namespace fix-up for each of the node's attributes.
+ NamedNodeMap nodeMap = nodeClone.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); ++i) {
+ Attr attr = (Attr) nodeMap.item(i);
+ nsPrefix = getNSPrefix(attr.getName());
+ if (nsPrefix != null && !nsPrefix.equals(XML_PREFIX)) {
+ nsName = resolve(nsPrefix, (Element) node);
+ nsNameClone = resolve(nsPrefix, (Element) nodeClone);
+ if (nsName != nsNameClone && (nsName == null || !nsName.equals(nsNameClone)))
+ declareNS((Element) nodeClone, nsPrefix, nsName);
+ }
+ }
+ }
+
+ // Recursively clone each of the node's children.
+ Node child = node.getFirstChild();
+ while (child != null) {
+ extractNode(nodeClone, child);
+ child = child.getNextSibling();
+ }
+
+ // Finished cloning this node.
+ return nodeClone;
+ }
+
+ /**
+ * Returns the first child of the given parent that is a WebDAV element
+ * with one of the given names, or <code>null</code> if no such child
+ * exists.
+ * <p>
+ * If firstToLast is true, the search for the child starts at the parent's
+ * first child, otherwise, the search starts at the parent's last child.
+ * The parent must not be <code>null</code> and must be a WebDAV element.
+ * The names of children to search for must not be <code>null</code>.</p>
+ *
+ * @param parent the parent of the child to search.
+ * @param names all possible names of the child to search for.
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child among the parent's children.
+ * @return the specified child of the parent, or
+ * <code>null<code> if no such child exists.
+ */
+ private static Element getChild(Element parent, String[] names, boolean firstToLast) {
+
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(names);
+
+ // Get the first candidate.
+ Node child = null;
+ if (firstToLast)
+ child = parent.getFirstChild();
+ else
+ child = parent.getLastChild();
+
+ // While there are children left to consider.
+ while (child != null) {
+
+ // See if the child name matches any being sought.
+ for (int i = 0; i < names.length; ++i)
+ if (isDAVElement(child, names[i]))
+ return (Element) child;
+
+ // Try the next child.
+ if (firstToLast)
+ child = child.getNextSibling();
+ else
+ child = child.getPreviousSibling();
+ }
+
+ // A matching child was not found.
+ return null;
+ }
+
+ /**
+ * <p>Returns the child WebDAV element of the given parent that is
+ * nearest in position to a WebDAV element with the given name, or
+ * <code>null</code> if no such child exists.
+ * <p>Children are expected to be in the order specified by the given
+ * names. If firstToLast is true, the search for the child starts at the
+ * parent's first child, otherwise, the search starts at the parent's
+ * last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The name of the child to search for must not be
+ * <code>null</code>. The parent's valid child names must not be
+ * <code>null</code>, and must contain the name of the child being
+ * searched for.
+ * <p>The returned child is as follows:
+ * <ul>
+ * <li>Searching first to last</li>
+ * <ul>
+ * <li>returns <code>null</code> if an element with the given name
+ * should appear as the last child</li>
+ * <li>returns the first occurring child if an element with the given
+ * name is a child</li>
+ * <li>returns a child if an element with the given name would appear
+ * before it</li>
+ * </ul>
+ * <li>Searching last to first</li>
+ * <ul>
+ * <li>returns <code>null</code> if an element with the given name
+ * would appear as the first child</li>
+ * <li>returns the last occurring child if an element with the given
+ * name is a child</li>
+ * <li>returns a child if an element with the given name would appear
+ * after it</li>
+ * </ul>
+ * </ul>
+ * @param parent the parent of the child being searched for
+ * @param name the name of the child being searched for
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the specified child among the parent's children
+ * @return a child of the parent, or <code>null</code>
+ */
+ public static Element getChild(Element parent, String name, String[] names, boolean firstToLast) {
+ Assert.isNotNull(parent);
+ Assert.isNotNull(name);
+ Assert.isNotNull(names);
+
+ boolean found = false;
+ for (int i = 0; !found && i < names.length; ++i) {
+ found = names[i].equals(name);
+ }
+ Assert.isTrue(found);
+
+ int i;
+ Node child = null;
+
+ if (firstToLast) {
+ i = 0;
+ child = parent.getFirstChild();
+ } else {
+ i = names.length - 1;
+ child = parent.getLastChild();
+ }
+
+ while (child != null && !names[i].equals(name)) {
+ int mark = i;
+ while (!isDAVElement(child, names[i]) && !names[i].equals(name)) {
+ if (firstToLast) {
+ ++i;
+ } else {
+ --i;
+ }
+ }
+
+ if (!names[i].equals(name)) {
+ if (firstToLast) {
+ child = child.getNextSibling();
+ } else {
+ child = child.getPreviousSibling();
+ }
+ } else if (!isDAVElement(child, names[i])) {
+ int pos = i;
+ found = false;
+ while (!found && (pos >= 0 && pos < names.length)) {
+ found = isDAVElement(child, names[pos]);
+ if (firstToLast) {
+ ++pos;
+ } else {
+ --pos;
+ }
+ }
+ if (!found) {
+ i = mark;
+ if (firstToLast) {
+ child = child.getNextSibling();
+ } else {
+ child = child.getPreviousSibling();
+ }
+ }
+ }
+ }
+
+ return (Element) child;
+ }
+
+ /**
+ * Returns the first child element of the given parent element, or
+ * <code>null</code> if no such child exists. If firstToLast is true,
+ * the search for the child starts at the parent's first child,
+ * otherwise, the search starts at the parent's last child. The parent
+ * must not be <code>null</code>.
+ *
+ * @param parent the parent of the child element to search for
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child element among the parent's children
+ * @return the child element, or <code>null</code> if no such
+ * child exists
+ */
+ public static Element getChildElement(Element parent, boolean firstToLast) {
+ Assert.isNotNull(parent);
+ Node child = null;
+ if (firstToLast)
+ child = parent.getFirstChild();
+ else
+ child = parent.getLastChild();
+ while (child != null && !isElement(child)) {
+ if (firstToLast)
+ child = child.getNextSibling();
+ else
+ child = child.getPreviousSibling();
+ }
+ return (Element) child;
+ }
+
+ /**
+ * Returns the data of the first child text node of the first WebDAV
+ * child with the given name of the given parent, or the empty
+ * <code>String</code> if no such child text node exists, or
+ * <code>null</code> if no such child exists. If firstToLast is true, the
+ * search for the child starts at the parent's first child, otherwise,
+ * the search starts at the parent's last child. The parent must not be
+ * <code>null</code> and must be a WebDAV element. The name of the child
+ * must not be <code>null</code>.
+ *
+ * @param parent the parent of the child with the child text node
+ * to search for
+ * @param name the name of the child with the child text node to
+ * search for
+ * @param firstToLast a boolean specifying the direction to search for
+ * the specified child among the parent's children
+ * @return the data of the child's child text node, or the
+ * empty <code>String</code> if no such child exists,
+ * or <code>null</code> if no such child exists
+ */
+ public static String getChildText(Element parent, String name, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Element child;
+ if (firstToLast)
+ child = getFirstChild(parent, name);
+ else
+ child = getLastChild(parent, name);
+ if (child != null)
+ return getText(child, firstToLast);
+ return null;
+ }
+
+ /**
+ * Returns the first WebDAV child of the given parent, or
+ * <code>null</code> if no such child exists. The parent must not be
+ * <code>null</code> and must be a WebDAV element.
+ *
+ * @param parent the parent of the child to search for
+ * @return the first WebDAV child of the parent, or null
+ */
+ public static Element getDAVChild(Element parent) {
+ Assert.isTrue(isDAVElement(parent));
+ Node child = parent.getFirstChild();
+ while (child != null && !isDAVElement(child))
+ child = child.getNextSibling();
+ return (Element) child;
+ }
+
+ /**
+ * Returns the root element upon which this editor is based. It cannot
+ * be assumed that this element necessarily conforms to the appropriate
+ * specification.
+ *
+ * @return the root element upon which this editor is based
+ */
+ public Element getElement() {
+ return root;
+ }
+
+ /**
+ * Returns the first child of the given parent that is a WebDAV element
+ * with one of the given names, or <code>null</code> if no such child
+ * exists.
+ * <p>
+ * The search for the child starts at the parent's first child.
+ * The parent must not be <code>null</code> and must be a WebDAV element.
+ * The names of children to search for must not be <code>null</code>.</p>
+ *
+ * @param parent the parent of the child to search.
+ * @param names all possible names of the child to search for.
+ * @return the specified child of the parent, or
+ * <code>null<code> if no such child exists.
+ */
+ public static Element getFirstChild(Element parent, String[] names) {
+ return getChild(parent, names, true);
+ }
+
+ /**
+ * Returns the first child of the given parent that is a WebDAV element
+ * with the given name, or <code>null</code> if no such child exists.
+ * <p>
+ * The search for the child starts at the parent's first child.
+ * The parent must not be <code>null</code> and must be a DAV: namespace
+ * element. The name of the child to search for must not be
+ * <code>null</code>.
+ *
+ * @param parent the parent of the child to search.
+ * @param name the name of the child to search for.
+ * @return the specified child of the parent, or <code>null
+ * </code> if no such child exists.
+ */
+ public static Element getFirstChild(Element parent, String name) {
+ Assert.isNotNull(name);
+ return getChild(parent, new String[] {name}, true);
+ }
+
+ /**
+ * Returns the data of the given parent's first text node, or the empty
+ * <code>String</code> if no such text node exists. The search for the
+ * text node starts at the parent's first child. The parent must not be
+ * <code>null</code>.
+ *
+ * @param parent the parent of the text node to search for
+ * @return the data of the text node being searched for, or
+ * the empty <code>String</code> if no such text node
+ * exists
+ */
+ public static String getFirstText(Element parent) {
+ Assert.isNotNull(parent);
+ Node child = parent.getFirstChild();
+ while (child != null && !isText(child))
+ child = child.getNextSibling();
+ if (child == null)
+ return ""; //$NON-NLS-1$
+ return ((Text) child).getData();
+ }
+
+ /**
+ * Returns the last child of the given parent that is a WebDAV element
+ * with the given name, or <code>null</code> if no such child exists.
+ * <p>
+ * The search starts at the parent's last child.
+ * The parent must not be <code>null</code> and must be a DAV: namespace
+ * element. The name of the child to search for must not be
+ * <code>null</code>.
+ *
+ * @param parent the parent of the child to search.
+ * @param name the name of the child to search for.
+ * @return the specified child of the parent, or <code>null
+ * </code> if no such child exists.
+ */
+ public static Element getLastChild(Element parent, String name) {
+ Assert.isNotNull(name);
+ return getChild(parent, new String[] {name}, false);
+ }
+
+ /**
+ * Returns the given element's namespace declarations. The element must
+ * not be <code>null</code>.
+ *
+ * @param element the element whose namespace declarations are returned
+ * @return the element's namespace declarations
+ */
+ public static Namespaces getNamespaces(Element element) {
+ Assert.isNotNull(element);
+ Node parent = element.getParentNode();
+ while (parent != null && !isElement(parent))
+ parent = parent.getParentNode();
+ Namespaces namespaces = null;
+ if (parent != null)
+ namespaces = getNamespaces((Element) parent);
+ return getNamespaces(element, namespaces, false);
+ }
+
+ /**
+ * Returns the given element's namespace declarations. The given
+ * namespace declarations should be the element's parent's, or
+ * <code>null</code> if the element has no parent. If
+ * removeDuplicateNSDeclarations is <code>true</code>, duplicate
+ * namespace declarations are removed from the element's attributes. The
+ * element must not be <code>null</code>.
+ *
+ * @param element the element whose namespace declaration is returned
+ * @param namespaces the namespace declarations for the element's
+ * parent's or <code>null</code> if it has no parent
+ * @param removeDuplicateNSDeclarations a boolean indicating whether
+ * duplicate namespace declarations should be removed
+ * from the element's attributes
+ * @return the given element's namespace declarations
+ */
+ protected static Namespaces getNamespaces(Element element, Namespaces namespaces, boolean removeDuplicateNSDeclarations) {
+
+ // Create a container to hold the new namespace definitions.
+ Namespaces newNamespaces = null;
+ if (namespaces == null)
+ newNamespaces = new Namespaces();
+ else
+ newNamespaces = new Namespaces(namespaces);
+
+ Vector oldAttributes = new Vector();
+
+ // For each attribute on the given element.
+ NamedNodeMap nodeMap = element.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); ++i) {
+ Attr attr = (Attr) nodeMap.item(i);
+
+ // Is it a name space declaration?
+ String name = attr.getName();
+ if (name.startsWith(XML_PREFIX)) {
+ String nsName = attr.getValue();
+
+ // Is it setting or clearing the default namespace?
+ // (i.e. has no prefix part)
+ if (name.length() == XML_PREFIX.length()) {
+ if (nsName.equals("")) //$NON-NLS-1$
+ newNamespaces.setDefaultNSName(null);
+ else
+ newNamespaces.setDefaultNSName(nsName);
+ } else if (name.charAt(XML_PREFIX.length()) == ':') {
+ // It is a namespace declaration.
+ String nsPrefix = name.substring(XML_PREFIX.length() + 1);
+ if (nsPrefix.length() > 0 && nsName.length() > 0) {
+ // Ensure it is in the new namespaces list.
+ newNamespaces.putNSName(nsPrefix, nsName);
+ boolean prefixExists = newNamespaces.getNSPrefix(nsName) != null;
+ if (!prefixExists)
+ newNamespaces.putNSPrefix(nsName, nsPrefix);
+ // If it is due for removal, rememebr it in the oldAttributes list.
+ if (removeDuplicateNSDeclarations && (prefixExists || nsName.equals(newNamespaces.getDefaultNSName())))
+ oldAttributes.addElement(attr);
+ }
+ }
+ }
+ }
+
+ // Remove all the duplicates on the given element.
+ Enumeration e = oldAttributes.elements();
+ while (e.hasMoreElements())
+ element.removeAttributeNode((Attr) e.nextElement());
+
+ // Answer the new list of namespaces for this element.
+ return newNamespaces;
+ }
+
+ /**
+ * Returns the next sibling element of the given element, or
+ * <code>null</code> if no such sibling exists. Only the sibling's
+ * next children are searched. The element must not be <code>null</code>.
+ *
+ * @param element the element whose sibling element is being
+ * searched for
+ * @return the sibling element, or <code>null</code>
+ */
+ public static Element getNextSibling(Element element) {
+ Assert.isNotNull(element);
+ Node sibling = element;
+ do {
+ sibling = sibling.getNextSibling();
+ } while (sibling != null && !isElement(sibling));
+ return (Element) sibling;
+ }
+
+ /**
+ * Returns the first WebDAV sibling of the given element that has one of
+ * the given names, or <code>null</code> if no such sibling exists. Only
+ * the sibling's next children (not the previous children) are searched.
+ * The element must not be <code>null</code> and must be a WebDAV element.
+ * The possible names of the sibling to search for must not be
+ * <code>null</code>.
+ *
+ * @param element the element whose sibling is being searched for
+ * @param names the possible names of the sibling being search for
+ * @return the sibling with the specified name, or
+ * <code>null</code>
+ */
+ public static Element getNextSibling(Element element, String[] names) {
+ Assert.isTrue(isDAVElement(element));
+ Assert.isNotNull(names);
+ Node sibling = element.getNextSibling();
+ while (sibling != null) {
+ for (int i = 0; i < names.length; ++i)
+ if (isDAVElement(sibling, names[i]))
+ return (Element) sibling;
+ sibling = sibling.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the next WebDAV sibling of the given element that has the
+ * given name, or <code>null</code> if no such sibling exists. Only
+ * the sibling's next children are searched. The element must not be
+ * <code>null</code> and must be a WebDAV element. The name of the
+ * sibling to search for must not be <code>null</code>.
+ *
+ * @param element the element whose sibling is being searched for
+ * @param name the name of the sibling being search for
+ * @return the sibling with the given name, or
+ * <code>null</code>
+ */
+ public static Element getNextSibling(Element element, String name) {
+ return getNextSibling(element, new String[] {name});
+ }
+
+ /**
+ * Returns the local part of the given name, or <code>null</code> if its
+ * name has no local part. The name must not be <code>null</code>.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>name</th>
+ * <th>local name</th>
+ * <tr>
+ * <td>D:foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>D:</td>
+ * <td>null</td>
+ * <tr>
+ * <td>:foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>:</td>
+ * <td>null</td>
+ * </table>
+ *
+ * @param name the name whose local part is returned
+ * @return the name's local part, or <code>null</code>
+ */
+ public static String getNSLocalName(String name) {
+ Assert.isNotNull(name);
+ int p = name.lastIndexOf(':');
+ if (p == -1)
+ return name;
+ if (p == name.length() - 1)
+ return null;
+ return name.substring(p + 1);
+ }
+
+ /**
+ * Returns the local part of the name of the given element, or
+ * <code>null</code> if its name has no local part. The element must not
+ * be <code>null</code>.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>tag name</th>
+ * <th>local name</th>
+ * <tr>
+ * <td>D:foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>D:</td>
+ * <td>null</td>
+ * <tr>
+ * <td>:foo</td>
+ * <td>foo</td>
+ * <tr>
+ * <td>:</td>
+ * <td>null</td>
+ * </table>
+ *
+ * @param element the element whose local name is returned
+ * @return the element's local name, or <code>null</code>
+ */
+ public static String getNSLocalName(Element element) {
+ Assert.isNotNull(element);
+ return getNSLocalName(element.getTagName());
+ }
+
+ /**
+ * Returns the URL of the given element's namespace, or
+ * <code>null</code> if it has no namespace. The element must not be
+ * <code>null</code>.
+ *
+ * @param element the element whose namespace is returned
+ * @return the namespace of the element, or <code>null</code>
+ * @throws MalformedElementException if the name of the given
+ * element has a namespace prefix which could not be
+ * resolved
+ */
+ public static String getNSName(Element element) throws MalformedElementException {
+ Assert.isNotNull(element);
+ String nsPrefix = getNSPrefix(element);
+ String nsName = resolve(nsPrefix, element);
+ if (nsPrefix != null && nsName == null)
+ throw new MalformedElementException(Policy.bind("exception.namespacePrefixNotResolved", nsPrefix)); //$NON-NLS-1$
+ return nsName;
+ }
+
+ /**
+ * Returns the namespace prefix part of the given name, or
+ * <code>null</code> if its name has no prefix. The name must not be
+ * <code>null</code>.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>name</th>
+ * <th>namespace prefix</th>
+ * <tr>
+ * <td>D:foo</td>
+ * <td>D</td>
+ * <tr>
+ * <td>foo</td>
+ * <td>null</td>
+ * <tr>
+ * <td>D:</td>
+ * <td>D</td>
+ * <tr>
+ * <td>:foo</td>
+ * <td>null</td>
+ * <tr>
+ * <td>:</td>
+ * <td>null</td>
+ * </table>
+ *
+ * @param name the name whose namespace prefix is returned
+ * @return the name's namespace prefix, or <code>null</code>
+ */
+ public static String getNSPrefix(String name) {
+ Assert.isNotNull(name);
+ int p = name.lastIndexOf(':');
+ if (p <= 0)
+ return null;
+ return name.substring(0, p);
+ }
+
+ /**
+ * Returns the namespace prefix part of the name of the given element,
+ * or <code>null</code> if its name has no prefix. The element must not
+ * be <code>null</code>.
+ * <table>
+ * <caption>Example</caption>
+ * <tr>
+ * <th>tag name</th>
+ * <th>namespace prefix</th>
+ * <tr>
+ * <td>D:foo</td>
+ * <td>D</td>
+ * <tr>
+ * <td>foo</td>
+ * <td>null</td>
+ * <tr>
+ * <td>D:</td>
+ * <td>D</td>
+ * <tr>
+ * <td>:foo</td>
+ * <td>null</td>
+ * <tr>
+ * <td>:</td>
+ * <td>null</td>
+ * </table>
+ *
+ * @param element the element whose namespace prefix is returned
+ * @return the element's namespace prefix, or <code>null</code>
+ */
+ public static String getNSPrefix(Element element) {
+ Assert.isNotNull(element);
+ return getNSPrefix(element.getTagName());
+ }
+
+ /**
+ * Returns a qualified name that is formed from the given element's
+ * namespace name and namespace local name. The qualified name's
+ * qualifier is the element's namespace name and the qualified name's
+ * local name is the element's local name. The element must not be
+ * <code>null</code>.
+ *
+ * @param element the element whose qualified name is returned
+ * @return the qualified name that is formed from the given
+ * element's namespace name and namespace local name
+ * @exception MalformedElementException if the name of the element has a
+ * namespace prefix which could not be resolved, or the
+ * element does not have a local name
+ */
+ public static QualifiedName getQualifiedName(Element element) throws MalformedElementException {
+ Assert.isNotNull(element);
+ String nsName = getNSName(element);
+ String nsLocalName = getNSLocalName(element);
+ if (nsLocalName == null)
+ throw new MalformedElementException(Policy.bind("exception.noLocalNameForElmt")); //$NON-NLS-1$
+ return new QualifiedNameImpl(nsName, nsLocalName);
+ }
+
+ /**
+ * Returns the first WebDAV sibling of the given element that has the
+ * given name, or <code>null</code> if no such sibling exists. If
+ * firstToLast is true, only the sibling's next children are searched,
+ * otherwise, only the siblings previous children are searched. The
+ * element must not be <code>null</code> and must be a WebDAV element.
+ * The name of the sibling to search for must not be <code>null</code>.
+ *
+ * @param element the element whose sibling is being searched for
+ * @param name the name of the sibling being search for
+ * @param firstToLast a boolean specifying the direction to search for
+ * the sibling among the element's siblings
+ * @return the sibling with the given name, or
+ * <code>null</code>
+ * @deprecated
+ */
+ public static Element getSibling(Element element, String name, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(element));
+ Assert.isNotNull(name);
+ Node sibling = element;
+ do {
+ if (firstToLast)
+ sibling = sibling.getNextSibling();
+ else
+ sibling = sibling.getPreviousSibling();
+ } while (sibling != null && !isDAVElement(sibling, name));
+ return (Element) sibling;
+ }
+
+ /**
+ * Returns the data of the given parent's first text node, or the empty
+ * <code>String</code> if no such text node exists. If firstToLast is
+ * true, the search for the text node starts at the parent's first
+ * child, otherwise, the search starts at the parent's last child. The
+ * parent must not be <code>null</code>.
+ *
+ * @param parent the parent of the text node to search for
+ * @param firstToLast a boolean specifying the direction to search for
+ * the text node among the parent's children
+ * @return the data of the text node being searched for, or
+ * the empty <code>String</code> if no such text node
+ * exists
+ * @deprecated
+ */
+ public static String getText(Element parent, boolean firstToLast) {
+ Assert.isNotNull(parent);
+ Node child = null;
+ if (firstToLast)
+ child = parent.getFirstChild();
+ else
+ child = parent.getLastChild();
+ while (child != null && !isText(child)) {
+ if (firstToLast)
+ child = child.getNextSibling();
+ else
+ child = child.getPreviousSibling();
+ }
+ if (child != null)
+ return ((Text) child).getData();
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the first WebDAV sibling of the given element that has the
+ * same name as the element, or <code>null</code> if no such sibling
+ * exists. If firstToLast is true, only the sibling's next children are
+ * searched, otherwise, only the siblings previous children are
+ * searched. The element must not be <code>null</code> and must be a
+ * WebDAV element.
+ *
+ * @param element the element whose sibling is being searched for
+ * @param firstToLast a boolean specifying the direction to search for
+ * the sibling among the element's siblings
+ * @return the sibling with the same name as the given
+ * element, or <code>null</code> if no such element
+ * exists
+ */
+ public static Element getTwin(Element element, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(element));
+ String name = getNSLocalName(element);
+ return getSibling(element, name, firstToLast);
+ }
+
+ public static boolean hasChild(Element parent, QualifiedName childName) throws MalformedElementException {
+ // Get the first candidate.
+ Node child = parent.getFirstChild();
+ // While there are children left to consider.
+ while (child != null) {
+ if (child instanceof Element) {
+ QualifiedName name = getQualifiedName((Element) child);
+ if (name.equals(childName))
+ return true;
+ }
+ // Try the next child.
+ child = child.getNextSibling();
+ }
+ // A matching child was not found.
+ return false;
+ }
+
+ /**
+ * Creates a WebDAV element with the given name and inserts it before
+ * the given sibling. Returns the new sibling. The sibling must not be
+ * <code>null</code> and must be a WebDAV element. The name of the
+ * new sibling must not be <code>null</code>.
+ *
+ * @param sibling the existing sibling element
+ * @param name the name of the new sibling element that is created
+ * and inserted before the existing sibling element
+ * @return the new sibling element that is created
+ */
+ public static Element insertBefore(Element sibling, String name) {
+ Assert.isTrue(isDAVElement(sibling));
+ Assert.isNotNull(name);
+ String nsPrefix = getNSPrefix(sibling);
+ String tagName = nsPrefix == null ? name : nsPrefix + ":" + name; //$NON-NLS-1$
+ Element newSibling = sibling.getOwnerDocument().createElement(tagName);
+ sibling.getParentNode().insertBefore(newSibling, sibling);
+ return newSibling;
+ }
+
+ /**
+ * Creates a WebDAV element with the given name and inserts it before
+ * the given sibling. In addition, a text node created from the given
+ * data and appended to the new sibling. Returns the new sibling. The
+ * sibling must not be <code>null</code> and must be a WebDAV element.
+ * The name of the new sibling must not be <code>null</code>. The data
+ * must not be <code>null</code>.
+ *
+ * @param sibling the existing sibling element
+ * @param name the name of the sibling element that is created and
+ * inserted before the existing sibling element
+ * @param data the data of the text node which is created and
+ * appended to the new sibling
+ * @return the new sibling element that is created
+ */
+ public static Element insertBefore(Element sibling, String name, String data) {
+ Assert.isTrue(isDAVElement(sibling));
+ Assert.isNotNull(name);
+ Assert.isNotNull(data);
+ Element child = insertBefore(sibling, name);
+ child.appendChild(child.getOwnerDocument().createTextNode(data));
+ return child;
+ }
+
+ /**
+ * Returns a boolean indicating whether or not the given node is a
+ * WebDAV element. The node may be <code>null</code> in which case
+ * <code>false</code> is returned.
+ *
+ * @param node a node, or <code>null</code>
+ * @return a boolean indicating whether or not the given node is a
+ * WebDAV element
+ */
+ public static boolean isDAVElement(Node node) {
+ if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
+ return false;
+ try {
+ if (!DAV_NS.equals(getNSName((Element) node)))
+ return false;
+ } catch (MalformedElementException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a boolean indicating whether or not the given node is a
+ * WebDAV element with the given name. The node may be <code>null</code>
+ * in which case <code>false</code> is returned. The name must not be
+ * <code>null</code>.
+ *
+ * @param node a node, or <code>null</code>
+ * @return a boolean indicating whether or not the given node is a
+ * WebDAV element with the given name
+ */
+ public static boolean isDAVElement(Node node, String name) {
+ Assert.isNotNull(name);
+ if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
+ return false;
+ try {
+ Element element = (Element) node;
+ if (!name.equals(getNSLocalName(element)) || !DAV_NS.equals(getNSName(element))) {
+ return false;
+ }
+ } catch (MalformedElementException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a boolean indicating whether or not the given node is an
+ * element. The node may be <code>null</code> in which case
+ * <code>false</code> is returned.
+ *
+ * @param node a node, or <code>null</code>
+ * @return a boolean indicating whether or not the given node is an
+ * element
+ */
+ public static boolean isElement(Node node) {
+ if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns a boolean indicating whether or not the given node is a text
+ * node. The node may be <code>null</code> in which case
+ * <code>false</code> is returned.
+ *
+ * @param node a node, or <code>null</code>
+ * @return a boolean indicating whether or not the given node is a
+ * text node
+ */
+ public static boolean isText(Node node) {
+ return (node != null) && (node.getNodeType() == Node.TEXT_NODE);
+ }
+
+ public static void makeNSStandalone(Element element) {
+ Assert.isTrue(false, Policy.bind("assert.notImplemented")); //$NON-NLS-1$
+ }
+
+ /**
+ * Removes redundant namespace declarations from this element and all
+ * its children to maximum depth. The element must not be
+ * <code>null</code>.
+ *
+ * @param element the element whose namespace declarations are to be
+ * reduced
+ * @return the element, or a new element with an equivalent
+ * qualified name but whose tag name has changed
+ * @throws MalformedElementException if the name of the given
+ * element, or one of its attributes, has a namespace
+ * prefix which could not be resolved
+ */
+ public static Element reduceNS(Element element) throws MalformedElementException {
+ return (Element) reduceNS(element, null);
+ }
+
+ /**
+ * Removes redundant namespace declarations from the given node and all
+ * its children to maximum depth. The node must not be
+ * <code>null</code>.
+ *
+ * @param node the node whose namespace declarations are to be reduced
+ * @return the node, or a new node (element) with an equivalent
+ * qualified name but whose tag name has changed
+ * @throws MalformedElementException if the name of the given node
+ * (element), or one of its attributes, has a namespace
+ * prefix which could not be resolved
+ */
+ public static Node reduceNS(Node node, Namespaces parentNamespaces) throws MalformedElementException {
+ Namespaces namespaces = parentNamespaces;
+
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) node;
+ namespaces = getNamespaces(element, parentNamespaces, false);
+
+ String nsPrefix = getNSPrefix(element);
+ String nsLocalName = getNSLocalName(element);
+
+ if (nsPrefix != null) {
+ String nsName = namespaces.getNSName(nsPrefix);
+ ensureNotNull(Policy.bind("ensure.missingNamespaceForPrefix", nsPrefix), nsName); //$NON-NLS-1$
+
+ String tagName = null;
+ if (nsName.equals(namespaces.getDefaultNSName())) {
+ tagName = nsLocalName;
+ } else {
+ tagName = namespaces.getNSPrefix(nsName) + ":" + nsLocalName; //$NON-NLS-1$
+ }
+
+ if (!tagName.equals(element.getTagName())) {
+ Document document = element.getOwnerDocument();
+ Element newElement = document.createElement(tagName);
+ NamedNodeMap nodeMap = element.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); ++i) {
+ Attr attr = (Attr) nodeMap.item(i);
+ newElement.setAttribute(attr.getName(), attr.getValue());
+ }
+ Node child = element.getFirstChild();
+ while (child != null) {
+ element.removeChild(child);
+ newElement.appendChild(child);
+ child = element.getFirstChild();
+ }
+ element.getParentNode().replaceChild(newElement, element);
+ element = newElement;
+ }
+ }
+
+ Vector oldAttributes = new Vector();
+ Vector newAttributes = new Vector();
+ NamedNodeMap nodeMap = element.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); ++i) {
+ Attr attr = (Attr) nodeMap.item(i);
+ String name = attr.getName();
+ String value = attr.getValue();
+ String newName = name;
+ nsPrefix = getNSPrefix(name);
+ nsLocalName = getNSLocalName(name);
+
+ if (nsPrefix != null && !nsPrefix.equals(XML_PREFIX)) {
+ String nsName = namespaces.getNSName(nsPrefix);
+ ensureNotNull(Policy.bind("ensure.missingNamespaceForPrefix", nsPrefix), nsName); //$NON-NLS-1$
+ String newNSPrefix = namespaces.getNSPrefix(nsName);
+ if (!newNSPrefix.equals(nsPrefix)) {
+ newName = newNSPrefix + ":" + nsLocalName; //$NON-NLS-1$
+ }
+ }
+
+ boolean newAttribute = true;
+ if (parentNamespaces != null) {
+ if (nsPrefix == null && XML_PREFIX.equals(nsLocalName)) {
+ if (value.equals(parentNamespaces.getDefaultNSName())) {
+ newAttribute = false;
+ }
+ }
+ if (nsPrefix != null && XML_PREFIX.equals(nsPrefix)) {
+ if (parentNamespaces.getNSPrefix(value) != null) {
+ newAttribute = false;
+ }
+ }
+ }
+
+ oldAttributes.addElement(attr);
+ if (newAttribute) {
+ newAttributes.addElement(new String[] {newName, value});
+ }
+ }
+
+ Enumeration oldAttrs = oldAttributes.elements();
+ while (oldAttrs.hasMoreElements()) {
+ element.removeAttributeNode((Attr) oldAttrs.nextElement());
+ }
+
+ Enumeration newAttrs = newAttributes.elements();
+ while (newAttrs.hasMoreElements()) {
+ String[] newAttr = (String[]) newAttrs.nextElement();
+ element.setAttribute(newAttr[0], newAttr[1]);
+ }
+
+ node = element;
+ }
+
+ Node child = node.getFirstChild();
+ while (child != null) {
+ child = reduceNS(child, namespaces);
+ child = child.getNextSibling();
+ }
+
+ return node;
+ }
+
+ /**
+ * Resolves the given namespace prefix in the namespace of the given
+ * element. If the given prefix is <code>null</code>, the default
+ * namespace is resolved. Returns the URL of the namespace, or
+ * <code>null</code> if the prefix could not be resolved.
+ *
+ * @param prefix the namespace prefix to be resolved, or
+ * <code>null<code> for the default namespace
+ * @param element the element supplying the namespace
+ * @return the URL of the namespace, or <code>null</code> if the
+ * prefix could not be resolved
+ */
+ public static String resolve(String prefix, Element element) {
+ Assert.isNotNull(element);
+
+ /* The prefix xml is by definition bound to the namespace name
+ * <code>XML_NS_NAME</code>.
+ */
+ if (XML_NS_PREFIX.equals(prefix)) {
+ return XML_NS_NAME;
+ }
+
+ /* Search from given element up parent chain to root (document)
+ * looking for a XML namespace declaration (represented as
+ * an element attribute with a name beginning in
+ * XML_PREFIX ("xmlns")).
+ */
+ Node current = element;
+ do {
+ NamedNodeMap attrs = current.getAttributes();
+ int n = attrs.getLength();
+ for (int i = 0; i < n; i++) {
+ Attr attr = (Attr) attrs.item(i);
+ String name = attr.getName();
+ if (name.startsWith(XML_PREFIX)) {
+ if (name.length() == XML_PREFIX.length()) {
+ // no prefix e.g., xmlns="foo:"
+ if (prefix == null) {
+ String nsName = attr.getValue();
+ if (nsName.equals("")) { //$NON-NLS-1$
+ return null;
+ }
+ return nsName;
+ }
+ } else {
+ if (prefix != null && name.equals(XML_PREFIX + ":" + prefix)) { //$NON-NLS-1$
+ return attr.getValue();
+ }
+ }
+ }
+ }
+ do {
+ current = current.getParentNode();
+ } while (current != null && current.getNodeType() != Node.ELEMENT_NODE);
+ } while (current != null);
+ return null;
+ }
+
+ /**
+ * <p>Creates a WebDAV element with the given name and sets it as a
+ * child of the given parent. Returns the child element.
+ * <p>Children are positioned in the order specified by the given names.
+ * If a child with the same name as the child already exist, the child
+ * is replaced. If firstToLast is true, the search for the child's
+ * position starts at the parent's first child, otherwise, the search
+ * starts at the parent's last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child's name must not be <code>null</code>. The
+ * parent's valid child names must not be <code>null</code>, and must
+ * contain the name of the child.
+ *
+ * @param parent the parent to which the child is added
+ * @param name the name of the child which is created and added
+ * to the parent
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ * @return the child element that is created
+ */
+ public static Element setChild(Element parent, String name, String[] names, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Assert.isNotNull(names);
+ String nsPrefix = getNSPrefix(parent);
+ String tagName = nsPrefix == null ? name : nsPrefix + ":" + name; //$NON-NLS-1$
+ Element child = parent.getOwnerDocument().createElement(tagName);
+ setChild(parent, child, names, firstToLast);
+ return child;
+ }
+
+ /**
+ * <p>Creates a WebDAV element with the given name and sets it as a
+ * child of the given parent. In addition, a text node created from the
+ * given data is created and appended to the child. Returns the child
+ * element.
+ * <p>Children are positioned in the order specified by the given names.
+ * If a child with the same name already exists, it is replaced. If
+ * firstToLast is true, the search for the child's position starts at the
+ * parent's first child, otherwise, the search starts at the parent's
+ * last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child's name and data must not be <code>null</code>.
+ * The parent's valid child names must not be <code>null</code>, and
+ * must contain the name of the child.
+ *
+ * @param parent the parent to which the child is added
+ * @param name the name of the child which is created and added
+ * to the parent
+ * @param data the data of the text node which is created and
+ * added to the child
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ * @return the child element that is created
+ */
+ public static Element setChild(Element parent, String name, String data, String[] names, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(name);
+ Assert.isNotNull(data);
+ Assert.isNotNull(names);
+ Element child = setChild(parent, name, names, firstToLast);
+ child.appendChild(parent.getOwnerDocument().createTextNode(data));
+ return child;
+ }
+
+ /**
+ * <p>Sets the given child element as a child of the given parent.
+ * <p>Children are positioned in the order specified by the given names.
+ * If a child with the same name already exists, it is replaced. If
+ * firstToLast is true, the search for the child's position starts at
+ * the parent's first child, otherwise, the search starts at the
+ * parent's last child.
+ * <p>The parent must not be <code>null</code> and must be a WebDAV
+ * element. The child must not be null and its namespace prefix must
+ * resolve to the WebDAV namespace URL in the parent. The parent's valid
+ * child names must not be <code>null</code>, and must contain the name
+ * of the child.
+ *
+ * @param parent the parent to which the child is added
+ * @param child the child which is added to the parent
+ * @param names the ordered collection of valid child names for
+ * the parent
+ * @param firstToLast a boolean specifying the direction to search for
+ * the child's position among the parent's children
+ */
+ public static void setChild(Element parent, Element child, String[] names, boolean firstToLast) {
+ Assert.isTrue(isDAVElement(parent));
+ Assert.isNotNull(child);
+ Assert.isTrue(DAV_NS.equals(resolve(getNSPrefix(child), parent)));
+ Assert.isNotNull(names);
+
+ boolean found = false;
+ String name = getNSLocalName(child);
+ for (int i = 0; !found && i < names.length; ++i) {
+ found = names[i].equals(name);
+ }
+ Assert.isTrue(found);
+
+ Node sibling = getChild(parent, name, names, firstToLast);
+
+ if (isDAVElement(sibling, name)) {
+ parent.replaceChild(child, sibling);
+ } else if (firstToLast) {
+ if (sibling == null) {
+ parent.appendChild(child);
+ } else {
+ parent.insertBefore(child, sibling);
+ }
+ } else {
+ Node refChild = null;
+ if (sibling == null) {
+ refChild = parent.getFirstChild();
+ } else {
+ refChild = sibling.getNextSibling();
+ }
+ if (refChild == null) {
+ parent.appendChild(child);
+ } else {
+ parent.insertBefore(child, refChild);
+ }
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/HrefSet.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/HrefSet.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/HrefSet.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for sets of hrefs, for example, the WebDAV
+ * predecessor-set element.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class HrefSet extends ElementEditor {
+ /**
+ * Creates a new editor on the given href set element with the given
+ * name. The element is assumed to be well formed.
+ *
+ * @param root an href element
+ * @param name the name of the element that this editor is expected
+ * to manipulate.
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public HrefSet(Element root, QualifiedName name) throws MalformedElementException {
+ super(root, name.getLocalName());
+ ensure(DAV_NS.equals(name.getQualifier()), Policy.bind("ensure.mustHaveDAVQualifier")); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds the given href to the end of the set of hrefs. If the href
+ * already exists it is not added.
+ *
+ * @param href the href to add to the end of the set of hrefs
+ */
+ public void addHref(String href) {
+ String encodedHref = encodeHref(href);
+ if (isDuplicate(encodedHref))
+ return;
+ appendChild(root, "href", encodedHref); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new href set element with the given name and sets it as
+ * the root of the given document. Returns an editor on the new href set
+ * element. The document must not be <code>null</code>, and must not
+ * already have a root element.
+ *
+ * @param document the document that will become the root of a new
+ * href set element
+ * @return an element editor on a href set element
+ */
+ public static HrefSet create(Document document, QualifiedName name) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Assert.isNotNull(name);
+ Assert.isTrue(DAV_NS.equals(name.getQualifier()));
+ Element element = create(document, name.getLocalName());
+ try {
+ return new HrefSet(element, name);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over the set of hrefs.
+ *
+ * @return an <code>Enumeration</code> of href <code>String</code>s
+ */
+ public Enumeration getHrefs() {
+ final Element firstHref = getFirstChild(root, "href"); //$NON-NLS-1$
+ Enumeration e = new Enumeration() {
+ Element currentHref = firstHref;
+
+ public boolean hasMoreElements() {
+ return currentHref != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ String href = getFirstText(currentHref);
+ currentHref = getNextSibling(currentHref, "href"); //$NON-NLS-1$
+ return decodeHref(href);
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Inserts the given newHref after the given refHref in the set of
+ * hrefs. If newHref already exists it is not inserted.
+ *
+ * @param refHref the existing href
+ * @param newHref the new href to be inserted after the existing href
+ */
+ public void insertHrefAfter(String refHref, String newHref) {
+ String refHrefEncoded = encodeHref(refHref);
+ String newHrefEncoded = encodeHref(newHref);
+ if (isDuplicate(newHrefEncoded))
+ return;
+ Element child = getFirstChild(root, "href"); //$NON-NLS-1$
+ while (child != null) {
+ if (refHrefEncoded.equals(getFirstText(child))) {
+ Element nextSibling = getNextSibling(child, "href"); //$NON-NLS-1$
+ if (nextSibling == null)
+ appendChild(root, "href", newHrefEncoded); //$NON-NLS-1$
+ else
+ insertBefore(nextSibling, "href", newHrefEncoded); //$NON-NLS-1$
+ return;
+ }
+ child = getNextSibling(child, "href"); //$NON-NLS-1$
+ }
+ Assert.isTrue(false, Policy.bind("assert.noHrefRef")); //$NON-NLS-1$
+ }
+
+ /**
+ * Inserts the given newHref before the given refHref in the set of
+ * hrefs. If newHref already exists it is not inserted.
+ *
+ * @param refHref the existing href
+ * @param newHref the new href to be inserted before the existing href
+ */
+ public void insertHrefBefore(String newHref, String refHref) {
+ String refHrefEncoded = encodeHref(refHref);
+ String newHrefEncoded = encodeHref(newHref);
+ if (isDuplicate(newHrefEncoded))
+ return;
+ Element child = getFirstChild(root, "href"); //$NON-NLS-1$
+ while (child != null) {
+ if (refHrefEncoded.equals(getFirstText(child))) {
+ insertBefore(child, "href", newHrefEncoded); //$NON-NLS-1$
+ return;
+ }
+ child = getNextSibling(child, "href"); //$NON-NLS-1$
+ }
+ Assert.isTrue(false, Policy.bind("assert.noHrefRef")); //$NON-NLS-1$
+ }
+
+ protected boolean isDuplicate(String encodedHref) {
+ Element child = getFirstChild(root, "href"); //$NON-NLS-1$
+ while (child != null) {
+ if (encodedHref.equals(getFirstText(child)))
+ return true;
+ child = getNextSibling(child, "href"); //$NON-NLS-1$
+ }
+ return false;
+ }
+
+ /**
+ * Remove the given href from the set of hrefs.
+ *
+ * @param href the href to remove from the set of hrefs
+ */
+ public void removeHref(String href) {
+ String encodedHref = encodeHref(href);
+ Element child = getFirstChild(root, "href"); //$NON-NLS-1$
+ while (child != null) {
+ if (encodedHref.equals(getFirstText(child))) {
+ root.removeChild(child);
+ return;
+ }
+ child = getNextSibling(child, "href"); //$NON-NLS-1$
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/HrefSet.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Label.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Label.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Label.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public class Label extends ElementEditor {
+
+ // An ordered collection of the element names of the label
+ // element's possible children.
+ protected static final String[] childNames = new String[] {"add", "set", "remove"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ public Label(Element root) throws MalformedElementException {
+ super(root, "label"); //$NON-NLS-1$
+ }
+
+ public String getLabelName() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.missingElmt"), child); //$NON-NLS-1$
+ String labelName = getChildText(child, "label-name", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingLabel"), labelName); //$NON-NLS-1$
+ return labelName;
+ }
+
+ public boolean isAdd() {
+ Element child = getFirstChild(root, childNames);
+ return getNSLocalName(child).equals("add"); //$NON-NLS-1$
+ }
+
+ public boolean isRemove() {
+ Element child = getFirstChild(root, childNames);
+ return getNSLocalName(child).equals("remove"); //$NON-NLS-1$
+ }
+
+ public boolean isSet() {
+ Element child = getFirstChild(root, childNames);
+ return getNSLocalName(child).equals("set"); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Label.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockDiscovery.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockDiscovery.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockDiscovery.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * An element editor for the WebDAV lockdiscovery element. See RFC2518
+ * section 13.8 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see ActiveLock
+ */
+public class LockDiscovery extends Property {
+ /**
+ * An ordered collection of the element names of the lockdiscovery
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"activelock"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV lockdiscovery element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a lockdiscovery element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public LockDiscovery(Element root) throws MalformedElementException {
+ super(root, "lockdiscovery"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates and adds a new activelock on this lockdiscovery and returns
+ * an editor on it.
+ *
+ * @return an editor on an activelock element
+ */
+ public ActiveLock addActiveLock() {
+ Element activelock = addChild(root, "activelock", childNames, false); //$NON-NLS-1$
+ Element locktype = appendChild(activelock, "locktype"); //$NON-NLS-1$
+ appendChild(locktype, "write"); //$NON-NLS-1$
+ ActiveLock result = null;
+ try {
+ result = new ActiveLock(activelock);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this lockdiscovery's
+ * <code>ActiveLock</code>s.
+ *
+ * @return an <code>Enumeration</code> of <code>ActiveLock</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getActiveLocks() throws MalformedElementException {
+ final Node firstActiveLock = getFirstChild(root, "activelock"); //$NON-NLS-1$
+ Enumeration e = new Enumeration() {
+ Node currentActiveLock = firstActiveLock;
+
+ public boolean hasMoreElements() {
+ return currentActiveLock != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ ActiveLock result = null;
+ try {
+ result = new ActiveLock((Element) currentActiveLock);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ currentActiveLock = getTwin((Element) currentActiveLock, true);
+ return result;
+ }
+ };
+ return e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockDiscovery.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockEntry.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockEntry.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV lockentry element. See RFC2518
+ * section 12.5 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see SupportedLock
+ */
+public class LockEntry extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the lockentry
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"lockscope", "locktype"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Creates a new editor on the given WebDAV lockentry element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a lockentry element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public LockEntry(Element root) throws MalformedElementException {
+ super(root, "lockentry"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns <code>true</code> if this lockentry is shared and
+ * <code>false</code> if it is exclusive.
+ *
+ * @return a boolean indicating whether this lockentry is shared or
+ * exclusive
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isShared() throws MalformedElementException {
+ Element lockscope = getFirstChild(root, "lockscope"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingLockscopeElmt"), lockscope); //$NON-NLS-1$
+ String[] names = new String[] {"shared", "exclusive"}; //$NON-NLS-1$ //$NON-NLS-2$
+ Element sharedOrExclusive = getFirstChild(lockscope, names);
+ ensureNotNull(Policy.bind("ensure.missingSharedOrExclusiveElmt"), sharedOrExclusive); //$NON-NLS-1$
+ boolean isShared = isDAVElement(sharedOrExclusive, "shared"); //$NON-NLS-1$
+ ensure(getNextSibling(sharedOrExclusive, names) == null, Policy.bind("ensure.conflictingSharedOrExclusiveElmt")); //$NON-NLS-1$
+ return isShared;
+ }
+
+ /**
+ * Sets whether this lockentry is shared or exclusive. If isShared is
+ * <code>true</code>, the lockentry is set as shared, otherwise, the
+ * lockentry is set as exclusive.
+ *
+ * @param isShared a boolean indicating whether this lockentry will be
+ * set to be shared or exclusive
+ */
+ public void setIsShared(boolean isShared) {
+ Element lockscope = setChild(root, "lockscope", childNames, true); //$NON-NLS-1$
+ if (isShared)
+ appendChild(lockscope, "shared"); //$NON-NLS-1$
+ else
+ appendChild(lockscope, "exclusive"); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockEntry.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockInfo.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV lockinfo element. See RFC2518
+ * section 12.6 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Owner
+ */
+public class LockInfo extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the lockinfo
+ * element's children.
+ */
+ public static final String[] childNames = new String[] {"lockscope", "locktype", "owner"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /**
+ * Creates a new editor on the given WebDAV lockinfo element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a lockinfo element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public LockInfo(Element root) throws MalformedElementException {
+ super(root, "lockinfo"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new WebDAV lockinfo element and sets it as the root of the
+ * given document. Returns an editor on the new lockinfo element. The
+ * document must not be <code>null</code>, and must not already have a
+ * root element.
+ *
+ * @param document the document that will become the root of a new
+ * lockinfo element
+ * @return an element editor on a lockinfo element
+ */
+ public static LockInfo create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Element element = create(document, "lockinfo"); //$NON-NLS-1$
+ Element locktype = appendChild(element, "locktype"); //$NON-NLS-1$
+ appendChild(locktype, "write"); //$NON-NLS-1$
+ LockInfo result = null;
+ try {
+ result = new LockInfo(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Returns this lockinfo's owner, or <code>null</code> if this lockinfo
+ * has no owner.
+ *
+ * @return this lockinfo's owner, or <code>null</code>
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Owner getOwner() throws MalformedElementException {
+ Element owner = getLastChild(root, "owner"); //$NON-NLS-1$
+ if (owner == null)
+ return null;
+ return new Owner(owner);
+ }
+
+ /**
+ * Returns <code>true</code> if this lockinfo is shared and
+ * <code>false</code> if it is exclusive.
+ *
+ * @return a boolean indicating whether this lockinfo is shared or
+ * exclusive
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isShared() throws MalformedElementException {
+ Element lockscope = getFirstChild(root, "lockscope"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingLockscopeElmt"), lockscope); //$NON-NLS-1$
+ String[] names = new String[] {"shared", "exclusive"}; //$NON-NLS-1$ //$NON-NLS-2$
+ Element sharedOrExclusive = getFirstChild(lockscope, names);
+ ensureNotNull(Policy.bind("ensure.missingSharedOrExclusiveElmt"), sharedOrExclusive); //$NON-NLS-1$
+ boolean isShared = isDAVElement(sharedOrExclusive, "shared"); //$NON-NLS-1$
+ ensure(getNextSibling(sharedOrExclusive, names) == null, Policy.bind("ensure.conflictingSharedOrExclusiveElmt")); //$NON-NLS-1$
+ return isShared;
+ }
+
+ /**
+ * Sets whether this lockinfo is shared or exclusive. If isShared is
+ * <code>true</code>, the lockinfo is set as shared, otherwise, the
+ * lockinfo is set as exclusive.
+ *
+ * @param isShared a boolean indicating whether this lockinfo will be
+ * set to be shared or exclusive
+ */
+ public void setIsShared(boolean isShared) {
+ Element lockscope = setChild(root, "lockscope", childNames, true); //$NON-NLS-1$
+ if (isShared)
+ appendChild(lockscope, "shared"); //$NON-NLS-1$
+ else
+ appendChild(lockscope, "exclusive"); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets the owner on this lockinfo and returns an editor on it.
+ */
+ public Owner setOwner() {
+ Element owner = setChild(root, "owner", childNames, false); //$NON-NLS-1$
+ Owner result = null;
+ try {
+ result = new Owner(owner);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/LockInfo.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MalformedElementException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MalformedElementException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MalformedElementException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+/**
+ * <code>MalformedElementException</code> is a checked exception thrown
+ * when a malformed element is encountered.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class MalformedElementException extends Exception {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Constructs a new exception.
+ */
+ public MalformedElementException() {
+ super();
+ }
+
+ /** Constructs a new exception with the given message.
+ */
+ public MalformedElementException(String detail) {
+ super(detail);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MalformedElementException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Mkworkspace.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Mkworkspace.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Mkworkspace.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The mkworkspace element editor is simple since it is a placeholder
+ * for future enhancements and implementation specific arguments.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Mkworkspace extends ElementEditor {
+ /**
+ * Mkworkspace constructor.
+ *
+ * @param root Element forming the root of the mkworkspace tree.
+ * @throws MalformedElementException if the root element is malformed.
+ */
+ public Mkworkspace(Element root) throws MalformedElementException {
+ super(root, "mkworkspace"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new WebDAV mkworkspace element and sets it as the root of
+ * the given document. Returns an editor on the new root element.
+ * <p>
+ * The document must not be <code>null</code>, and must not already have
+ * a root element.</p>
+ *
+ * @param document the document that will become the root of a new
+ * mkworkspace element
+ * @return an element editor on a mkworkspace element
+ */
+ public static Mkworkspace create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Element element = create(document, "mkworkspace"); //$NON-NLS-1$
+ try {
+ return new Mkworkspace(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Mkworkspace.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MultiStatus.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MultiStatus.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MultiStatus.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV multistatus element. See RFC2518
+ * section 12.9 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see ResponseBody
+ */
+public class MultiStatus extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the multistatus
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"response", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Creates a new editor on the given WebDAV multistatus element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a multistatus element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public MultiStatus(Element root) throws MalformedElementException {
+ super(root, "multistatus"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates and adds a response element to this multistatus and returns
+ * an editor on it.
+ *
+ * @return an editor on a response element
+ */
+ public ResponseBody addResponse() {
+ Element response = addChild(root, "response", childNames, true); //$NON-NLS-1$
+ try {
+ return new ResponseBody(response);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Creates a new WebDAV multistatus element and sets it as the root of
+ * the given document. Returns an editor on the new multistatus element.
+ * <p>
+ * The document must not be <code>null</code>, and must not already have
+ * a root element.</p>
+ *
+ * @param document the document that will become the root of a new
+ * multistatus element
+ * @return an element editor on a multistatus element
+ */
+ public static MultiStatus create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Element element = create(document, "multistatus"); //$NON-NLS-1$
+ try {
+ return new MultiStatus(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Returns this multistatus' response description, or <code>null</code>
+ * if it has none.
+ *
+ * @return this multistatus' response description, or <code>null</code>
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getResponseDescription() throws MalformedElementException {
+ return getChildText(root, "responsedescription", false); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this multistatus' responses.
+ *
+ * @return an <code>Enumeration</code> of <code>ResponseBody</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getResponses() throws MalformedElementException {
+
+ final Element firstResponse = getFirstChild(root, "response"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingResponseElmt"), firstResponse); //$NON-NLS-1$
+
+ Enumeration e = new Enumeration() {
+ Element currentResponse = firstResponse;
+
+ public boolean hasMoreElements() {
+
+ return currentResponse != null;
+ }
+
+ public Object nextElement() {
+
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+
+ ResponseBody responseBody = null;
+ try {
+ responseBody = new ResponseBody(currentResponse);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+
+ currentResponse = getTwin(currentResponse, true);
+
+ return responseBody;
+ }
+ };
+
+ return e;
+ }
+
+ /**
+ * Sets this multistatus' response description to the given value. If
+ * the value is <code>null</code> and a response description has already
+ * been set, it is removed.
+ *
+ * @param value a response description, or <code>null</code>
+ */
+ public void setResponseDescription(String value) {
+ if (value == null) {
+ Element child = getLastChild(root, "responsedescription"); //$NON-NLS-1$
+ if (child != null)
+ root.removeChild(child);
+ } else
+ setChild(root, "responsedescription", value, childNames, false); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/MultiStatus.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Namespaces.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Namespaces.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Namespaces.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Properties;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public class Namespaces {
+ private String fDefaultNSName = null;
+ private Properties fNSNames = null;
+ private Properties fNSPrefixes = null;
+
+ public Namespaces() {
+ fNSNames = new Properties();
+ fNSPrefixes = new Properties();
+ }
+
+ public Namespaces(Namespaces namespaces) {
+ fDefaultNSName = namespaces.fDefaultNSName;
+ fNSNames = new Properties(namespaces.fNSNames);
+ fNSPrefixes = new Properties(namespaces.fNSPrefixes);
+ }
+
+ public String getDefaultNSName() {
+ return fDefaultNSName;
+ }
+
+ public String getNSName(String nsPrefix) {
+ return fNSNames.getProperty(nsPrefix);
+ }
+
+ public String getNSPrefix(String nsName) {
+ return fNSPrefixes.getProperty(nsName);
+ }
+
+ public void putNSName(String nsPrefix, String nsName) {
+ fNSNames.put(nsPrefix, nsName);
+ }
+
+ public void putNSPrefix(String nsName, String nsPrefix) {
+ fNSPrefixes.put(nsName, nsPrefix);
+ }
+
+ public void setDefaultNSName(String nsName) {
+ fDefaultNSName = nsName;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Namespaces.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Owner.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Owner.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Owner.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV owner element. See RFC2518 section
+ * 12.10 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see ActiveLock
+ * @see LockInfo
+ */
+public class Owner extends ElementEditor {
+ /**
+ * Creates a new editor on the given WebDAV owner element. The element
+ * is assumed to be well formed.
+ *
+ * @param root a owner element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Owner(Element root) throws MalformedElementException {
+ super(root, "owner"); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Owner.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Prop.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Prop.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Prop.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.*;
+
+/**
+ * An element editor for the WebDAV prop element. See RFC2518 section
+ * 12.11 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see PropStat
+ * @see PropertyUpdate
+ * @see PropFind
+ * @see Property
+ */
+public class Prop extends ElementEditor {
+ /**
+ * Creates a new editor on the given WebDAV prop element. The element
+ * is assumed to be well formed.
+ *
+ * @param root a prop element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Prop(Element root) throws MalformedElementException {
+ super(root, "prop"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a clone of the given element and adds it to this prop. The
+ * element must not be <code>null</code>.
+ *
+ * @param element any element
+ * @throws MalformedElementException if there is reason to
+ * believe that the given element is not well formed
+ */
+ public void addProperty(Element element) throws MalformedElementException {
+ Assert.isNotNull(element);
+ extractNode(root, element);
+ }
+
+ /**
+ * Creates a new element with the given name and adds it to this prop.
+ * The name must not be <code>null</code> and its qualifier and local
+ * name must not be <code>null</code> and must not be the empty string.
+ *
+ * @param name the <code>QualifiedName</code> of the property to add
+ */
+ public void addPropertyName(QualifiedName name) {
+ Assert.isNotNull(name);
+ String nsName = name.getQualifier();
+ Assert.isTrue(!"".equals(nsName)); //$NON-NLS-1$
+ String localName = name.getLocalName();
+ Assert.isNotNull(localName);
+ Assert.isTrue(!localName.equals("")); //$NON-NLS-1$
+ Document document = root.getOwnerDocument();
+ Element element = document.createElement(localName);
+ declareNS(element, null, nsName);
+ root.appendChild(element);
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this prop's property
+ * <code>Element</code>s.
+ *
+ * @returns an <code>Enumeration</code> of </code>Element</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getProperties() throws MalformedElementException {
+ Node firstChild = getChildElement(root, true);
+ final Node firstElement = firstChild;
+ Enumeration e = new Enumeration() {
+ Node currentElement = firstElement;
+
+ public boolean hasMoreElements() {
+ return currentElement != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ Node nextElement = currentElement;
+ currentElement = getNextSibling((Element) currentElement);
+ return nextElement;
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this prop's property
+ * <code>QualifiedName</code>s.
+ *
+ * @returns an <code>Enumeration</code> of </code>QualifiedName</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getPropertyNames() throws MalformedElementException {
+ Node firstChild = getChildElement(root, true);
+ final Node firstElement = firstChild;
+ Enumeration e = new Enumeration() {
+ Node currentElement = firstElement;
+
+ public boolean hasMoreElements() {
+ return currentElement != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ String nsName = null;
+ try {
+ nsName = getNSName((Element) currentElement);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ String localName = getNSLocalName((Element) currentElement);
+ QualifiedNameImpl name = new QualifiedNameImpl(nsName, localName);
+ currentElement = getNextSibling((Element) currentElement);
+ return name;
+ }
+ };
+ return e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Prop.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropFind.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropFind.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropFind.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV propfind element. See RFC2518
+ * section 12.14 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Prop
+ */
+public class PropFind extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the propfind
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"allprop", "propname", "prop"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /**
+ * Creates a new editor on the given WebDAV propfind element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a propfind element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public PropFind(Element root) throws MalformedElementException {
+ super(root, "propfind"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new WebDAV propfind element and sets it as the root of the
+ * given document. Returns an editor on the new propfind element. The
+ * document must not be <code>null</code>, and must not already have a
+ * root element.
+ *
+ * @param document the document that will become the root of a new
+ * propfind element
+ * @return an element editor on a propfind element
+ */
+ public static PropFind create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getDocumentElement() == null);
+ Element element = create(document, "propfind"); //$NON-NLS-1$
+ try {
+ return new PropFind(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ * Returns this propfind's prop.
+ *
+ * @return this propfind's prop
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or if
+ * this propfind is not in the "prop" form
+ */
+ public Prop getProp() throws MalformedElementException {
+ Element prop = getFirstChild(root, "prop"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingPropElmt"), prop); //$NON-NLS-1$
+ return new Prop(prop);
+ }
+
+ /**
+ * Returns <code>true</code> iff this propfind is in the "all prop"
+ * form.
+ *
+ * @return a boolean indicating whether this propfind is in the "all
+ * prop" form
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isAllProp() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.missingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ boolean isAllProp = isDAVElement(child, "allprop"); //$NON-NLS-1$
+ child = getNextSibling(child, childNames);
+ ensureNull(Policy.bind("ensure.conflictingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ return isAllProp;
+ }
+
+ /**
+ * Returns <code>true</code> iff this propfind is in the "prop" form.
+ *
+ * @return a boolean indicating whether this propfind is in the "prop"
+ * form
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isProp() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.missingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ boolean isProp = isDAVElement(child, "prop"); //$NON-NLS-1$
+ child = getNextSibling(child, childNames);
+ ensureNull(Policy.bind("ensure.conflictingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ return isProp;
+ }
+
+ /**
+ * Returns <code>true</code> iff this propfind is in the "prop name"
+ * form.
+ *
+ * @return a boolean indicating whether this propfind is in the
+ * "propname" form
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isPropName() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.missingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ boolean isPropName = isDAVElement(child, "propname"); //$NON-NLS-1$
+ child = getNextSibling(child, childNames);
+ ensureNull(Policy.bind("ensure.conflictingAllpropOrPropnameOrPropElmt"), child); //$NON-NLS-1$
+ return isPropName;
+ }
+
+ /**
+ * Sets whether this propfind is in the "all prop" form.
+ *
+ * @param isAllProp boolean indicating whether this propfind will be in the
+ * "all prop" form
+ */
+ public void setIsAllProp(boolean isAllProp) {
+ Element child = getFirstChild(root, childNames);
+ boolean isAlreadyAllProp = isDAVElement(child, "allprop"); //$NON-NLS-1$
+ if (isAllProp) {
+ if (!isAlreadyAllProp) {
+ if (child != null)
+ root.removeChild(child);
+ appendChild(root, "allprop"); //$NON-NLS-1$
+ }
+ } else if (isAlreadyAllProp)
+ root.removeChild(child);
+ }
+
+ /**
+ * Sets whether this propfind is in the "prop name" form.
+ *
+ * @param isPropName boolean indicating whether this propfind will be in the
+ * "prop name" form
+ */
+ public void setIsPropName(boolean isPropName) {
+ Element child = getFirstChild(root, childNames);
+ boolean isAlreadyPropName = isDAVElement(child, "propname"); //$NON-NLS-1$
+ if (isPropName) {
+ if (!isAlreadyPropName) {
+ if (child != null)
+ root.removeChild(child);
+ appendChild(root, "propname"); //$NON-NLS-1$
+ }
+ } else if (isAlreadyPropName)
+ root.removeChild(child);
+ }
+
+ /**
+ * Creates and sets a new prop on this propfind and returns an editor on
+ * it. This propfind must not already be in the "all prop" or "prop
+ * name" form.
+ *
+ * @return an editor on a new prop element
+ */
+ public Prop setProp() {
+ Assert.isTrue(getFirstChild(root, new String[] {"allprop", "propname"}) == null); //$NON-NLS-1$ //$NON-NLS-2$
+ Element prop = setChild(root, "prop", new String[] {"prop"}, true); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ return new Prop(prop);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropFind.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropStat.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropStat.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropStat.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV propstat element. See RFC2518
+ * section 12.9.1.1 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see org.eclipse.webdav.http.client.Response
+ * @see Prop
+ */
+public class PropStat extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the propstat
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"prop", "status", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /**
+ * Creates a new editor on the given WebDAV propstat element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a propstat element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public PropStat(Element root) throws MalformedElementException {
+ super(root, "propstat"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns this propstat's prop.
+ *
+ * @return this propstat's prop
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Prop getProp() throws MalformedElementException {
+ Element prop = getFirstChild(root, "prop"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingPropElmt"), prop); //$NON-NLS-1$
+ return new Prop(prop);
+ }
+
+ /**
+ * Returns this propstat's response description.
+ *
+ * @return this propstat's response description
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getResponseDescription() throws MalformedElementException {
+ return getChildText(root, "responsedescription", false); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns this propstat's status.
+ *
+ * @return this propstat's status
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getStatus() throws MalformedElementException {
+ String status = getChildText(root, "status", false); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingStatusElmt"), status); //$NON-NLS-1$
+ return status;
+ }
+
+ /**
+ * Returns this propstat's status code.
+ *
+ * @return this propstat's status code
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public int getStatusCode() throws MalformedElementException {
+ return new Status(getStatus()).getStatusCode();
+ }
+
+ /**
+ * Creates and sets a new prop on this propstat and returns an editor on
+ * it.
+ *
+ * @return an editor on a new prop element
+ */
+ public Prop setProp() {
+ Element prop = setChild(root, "prop", childNames, true); //$NON-NLS-1$
+ try {
+ return new Prop(prop);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Sets this propstat's response description to the given value. If the
+ * value is <code>null</code> and a response description has already
+ * been set, it is removed.
+ *
+ * @param value a response description, or <code>null</code>
+ */
+ public void setResponseDescription(String value) {
+ if (value == null) {
+ Element child = getLastChild(root, "responsedescription"); //$NON-NLS-1$
+ if (child != null)
+ root.removeChild(child);
+ } else
+ setChild(root, "responsedescription", value, childNames, false); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets the status on this propstat to the given status. The status
+ * must not be <code>null</code>.
+ *
+ * @param status the status for this propstat
+ */
+ public void setStatus(String status) {
+ Assert.isNotNull(status);
+ setChild(root, "status", status, childNames, true); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropStat.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Property.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Property.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Property.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.w3c.dom.Element;
+
+/**
+ * An element editor that is the superclass of all WebDAV property
+ * elements. This class only exists to group property editors under a
+ * common class and to separate them from other types of editors.
+ * Property elements always appear as a child of the WebDAV prop
+ * element.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Prop
+ */
+public abstract class Property extends ElementEditor {
+ /**
+ * Creates a new editor on the given property element. The element is
+ * assumed to be well formed.
+ *
+ * @param element a property element
+ * @param expectedType the tag name for the element tht this editor
+ * is expected to manipulate.
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Property(Element element, String expectedType) throws MalformedElementException {
+ super(element, expectedType);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Property.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyBehavior.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyBehavior.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyBehavior.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV propertybehavior element. See
+ * RFC2518 section 12.12 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class PropertyBehavior extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the
+ * propertybehavior element's children.
+ */
+ protected static final String[] childNames = new String[] {"omit", "keepalive"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * An ordered collection of the element names of the
+ * propertybehavior element's children in the "omit" form
+ */
+ public static String[] fgNamesOmit = new String[] {"omit"}; //$NON-NLS-1$
+
+ /**
+ * An ordered collection of the element names of the
+ * propertybehavior element's children in the "keep alive" form
+ */
+ public static String[] fgNamesKeepAlive = new String[] {"keepalive"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV propertybehavior element.
+ * The element is assumed to be well formed.
+ *
+ * @param root a propertybehavior element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public PropertyBehavior(Element root) throws MalformedElementException {
+ super(root, "propertybehavior"); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds the given property href to this propertybehavior's list of live
+ * properties. The property href must not be <code>null</code> and the
+ * form of this property behavior must not already be omit or
+ * keepAllAlive.
+ *
+ * @param propertyHref the property href to add
+ */
+ public void addProperty(String propertyHref) {
+ Assert.isNotNull(propertyHref);
+ Assert.isTrue(getFirstChild(root, "omit") == null); //$NON-NLS-1$
+ Element keepalive = getFirstChild(root, "keepalive"); //$NON-NLS-1$
+ if (keepalive == null)
+ keepalive = addChild(root, "keepalive", fgNamesKeepAlive, true); //$NON-NLS-1$
+ else
+ Assert.isTrue(!"*".equals(getFirstText(keepalive))); //$NON-NLS-1$
+ addChild(keepalive, "href", //$NON-NLS-1$
+ encodeHref(propertyHref), new String[] {"href"}, //$NON-NLS-1$
+ false);
+ }
+
+ /**
+ * Creates a new WebDAV propertybehavior element and sets it as the root
+ * of the given document. Returns an editor on the new propertybehavior
+ * element. The document must not be <code>null</code>, and must not
+ * already have a root element.
+ *
+ * @param document the document that will become the root of a new
+ * propertybehavior element
+ * @return an element editor on a propertybehavior element
+ */
+ public static PropertyBehavior create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Element element = create(document, "propertybehavior"); //$NON-NLS-1$
+ PropertyBehavior result = null;
+ try {
+ result = new PropertyBehavior(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this propertybehavior's
+ * property hrefs. The methods <code>isMerge()</code> and
+ * <code>isKeepAllAlive</code> return false if this propertybehavior is
+ * in the "keep some alive" form.
+ *
+ * @return an <code>Enumeration</code> of <code>String</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or this
+ * propertybehavior is not in the "keep some alive" form
+ * @see #isKeepAllAlive()
+ * @see #isOmit()
+ */
+ public Enumeration getProperties() throws MalformedElementException {
+
+ Element keepalive = getFirstChild(root, "keepalive"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingKeealiveElmt"), keepalive); //$NON-NLS-1$
+ ensure(!"*".equals(getFirstText(keepalive)), //$NON-NLS-1$
+ Policy.bind("ensure.wrongForm")); //$NON-NLS-1$
+
+ final Element firstHref = getFirstChild(keepalive, "href"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), firstHref); //$NON-NLS-1$
+
+ Enumeration e = new Enumeration() {
+ Element currentHref = firstHref;
+
+ public boolean hasMoreElements() {
+ return currentHref != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ String href = getFirstText(currentHref);
+ currentHref = getTwin(currentHref, true);
+ return decodeHref(href);
+ }
+ };
+
+ return e;
+ }
+
+ /**
+ * Returns <code>true</code> if this propertybehavior is in the
+ * "keep all alive" form, otherwise, returns <code>false</code>.
+ *
+ * @return a boolean indicating whether this propertybehavior is in the
+ * "keep all alive" form or not
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isKeepAllAlive() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.expectingOmitOrKeepaliveElmt"), child); //$NON-NLS-1$
+ boolean isKeepAllAlive = false;
+ if (isDAVElement(child, "keepalive")) { //$NON-NLS-1$
+ isKeepAllAlive = "*".equals(getFirstText(child)); //$NON-NLS-1$
+ ensureNull(Policy.bind("ensure.conflictingHrefElmt"), getFirstChild(child, "href")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ child = getNextSibling(child, childNames);
+ ensureNull(Policy.bind("ensure.conflictingOmitOrKeepaliveElmt"), child); //$NON-NLS-1$
+ return isKeepAllAlive;
+ }
+
+ /**
+ * Returns <code>true</code> if this propertybehavior is in the
+ * "omit" form, otherwise, returns <code>false</code>.
+ *
+ * @return a boolean indicating whether this propertybehavior is in the
+ * "omit" form or not
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isOmit() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.expectingOmitOrKeepaliveElmt"), child); //$NON-NLS-1$
+ boolean isOmit = isDAVElement(child, "omit"); //$NON-NLS-1$
+ child = getNextSibling(child, childNames);
+ ensureNull(Policy.bind("ensure.conflictingOmitOrKeepaliveElmt"), child); //$NON-NLS-1$
+ return isOmit;
+ }
+
+ /**
+ * Sets whether this propertybehavior is in the "keep all alive" form or
+ * not.
+ *
+ * @param isKeepAllAlive a boolean indicating whether this
+ * propertybehavior will be in the "keep all
+ * alive" form
+ */
+ public void setIsKeepAllAlive(boolean isKeepAllAlive) {
+ Element child = getFirstChild(root, childNames);
+ boolean isAlreadyKeepAllAlive = false;
+ if (isDAVElement(child, "keepalive")) //$NON-NLS-1$
+ isAlreadyKeepAllAlive = "*".equals(getFirstText(child)); //$NON-NLS-1$
+ if (isKeepAllAlive) {
+ if (!isAlreadyKeepAllAlive) {
+ if (child != null)
+ root.removeChild(child);
+ appendChild(root, "keepalive", "*"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } else if (isAlreadyKeepAllAlive)
+ root.removeChild(child);
+ }
+
+ /**
+ * Sets whether this propertybehavior is in the "omit" form or not.
+ *
+ * @param isOmit a boolean indicating whether this propertybehavior will
+ * be in the "omit" form
+ */
+ public void setIsOmit(boolean isOmit) {
+ Element child = getFirstChild(root, childNames);
+ boolean isAlreadyOmit = isDAVElement(child, "omit"); //$NON-NLS-1$
+ if (isOmit) {
+ if (!isAlreadyOmit) {
+ if (child != null)
+ root.removeChild(child);
+ appendChild(root, "omit"); //$NON-NLS-1$
+ }
+ } else if (isAlreadyOmit)
+ root.removeChild(child);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyBehavior.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyUpdate.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyUpdate.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyUpdate.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.*;
+
+/**
+ * An element editor for the WebDAV propertyupdate element. See RFC2518
+ * section 12.13 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see Prop
+ */
+public class PropertyUpdate extends ElementEditor {
+ /**
+ * An editor for a generic element that is a child of a WebDAV prop
+ * element, which, in turn, is a child of a WebDAV set or remove
+ * element.
+ */
+ public class Directive extends ElementEditor {
+
+ /**
+ * Creates a new editor on the given element.
+ *
+ * @param element a generic element
+ * @throws MalformedElementException if there is reason
+ * to believe that this editor's underlying
+ * element is not well formed
+ */
+ public Directive(Element element) throws MalformedElementException {
+ super(element);
+ Node parent = element.getParentNode();
+ ensureDAVElement(parent, "prop", Policy.bind("ensure.expectingPropElmt")); //$NON-NLS-1$ //$NON-NLS-2$
+ Node grandparent = parent.getParentNode();
+ ensure(isDAVElement(grandparent, "remove") || isDAVElement(grandparent, "set"), //$NON-NLS-1$ //$NON-NLS-2$
+ Policy.bind("ensure.expectingRemoveOrSetElmt")); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns this editor's underlying element, which may be any
+ * generic element.
+ *
+ * @return this editor's underlying element
+ */
+ public Element getProperty() throws MalformedElementException {
+ return root;
+ }
+
+ /**
+ * Returns <code>true</code> if this directive's property
+ * decends from a WebDAV remove element and <code>false</code>
+ * if it decends from a WebDAV set element.
+ *
+ * @return a boolean indicating whether this directive is a
+ * remove or not
+ * @throws MalformedElementException if there is reason to
+ * believe that this editor's underlying element is not
+ * well formed
+ */
+ public boolean isRemove() throws MalformedElementException {
+ Node parent = root.getParentNode();
+ ensureDAVElement(parent, "prop", Policy.bind("ensure.expectingPropElmt")); //$NON-NLS-1$ //$NON-NLS-2$
+ Node grandparent = parent.getParentNode();
+ return isDAVElement(grandparent, "remove"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns <code>true</code> if this directive's property
+ * decends from a WebDAV set element and <code>false</code>
+ * if it decends from a WebDAV remove element.
+ *
+ * @return a boolean indicating whether this directive is a
+ * set or not
+ * @throws MalformedElementException if there is reason to
+ * believe that this editor's underlying element is not
+ * well formed
+ */
+ public boolean isSet() throws MalformedElementException {
+ Node parent = root.getParentNode();
+ ensureDAVElement(parent, "prop", Policy.bind("ensure.expectingPropElmt")); //$NON-NLS-1$ //$NON-NLS-2$
+ Node grandparent = parent.getParentNode();
+ return isDAVElement(grandparent, "set"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates a new editor on the given WebDAV propertyupdate element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a propertyupdate element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public PropertyUpdate(Element root) throws MalformedElementException {
+ super(root, "propertyupdate"); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds a remove to the given propertyupdate and returns an editor on
+ * its prop.
+ *
+ * @return an editor on a new prop
+ */
+ public Prop addRemove() {
+ Element remove = appendChild(root, "remove"); //$NON-NLS-1$
+ Element prop = appendChild(remove, "prop"); //$NON-NLS-1$
+ Prop result = null;
+ try {
+ result = new Prop(prop);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Adds a set to the given propertyupdate and returns an editor on its
+ * prop.
+ *
+ * @return an editor on a new prop
+ */
+ public Prop addSet() {
+ Element set = appendChild(root, "set"); //$NON-NLS-1$
+ Element prop = appendChild(set, "prop"); //$NON-NLS-1$
+ try {
+ return new Prop(prop);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Creates a new WebDAV propertyupdate element and sets it as the root
+ * of the given document. Returns an editor on the new propertyupdate
+ * element. The document must not be <code>null</code>, and must not
+ * already have a root element.
+ *
+ * @param document the document that will become the root of a new
+ * propertyupdate element
+ * @return an element editor on a propertyupdate element
+ */
+ public static PropertyUpdate create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getDocumentElement() == null);
+ Element element = create(document, "propertyupdate"); //$NON-NLS-1$
+ PropertyUpdate result = null;
+ try {
+ result = new PropertyUpdate(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this propertyupdate's set
+ * and remove property elements.
+ *
+ * @return an <code>Enumeration</code> of
+ * <code>PropertyUpdate.Directive</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getSetsAndRemoves() throws MalformedElementException {
+
+ Node setOrRemove = getFirstChild(root, new String[] {"remove", "set"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ensureNotNull(Policy.bind("ensure.missingRemoveOrSetElmt"), setOrRemove); //$NON-NLS-1$
+ Node property = null;
+
+ while (setOrRemove != null && property == null) {
+ Node prop = getFirstChild((Element) setOrRemove, "prop"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingPropElmt"), prop); //$NON-NLS-1$
+ property = getChildElement((Element) prop, true);
+
+ if (property == null)
+ setOrRemove = getNextSibling((Element) setOrRemove, new String[] {"remove", "set"}); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ final Node a = setOrRemove;
+ final Node c = property;
+
+ Enumeration e = new Enumeration() {
+ Node currentSetOrRemove = a;
+ Node currentProperty = c;
+
+ public boolean hasMoreElements() {
+
+ return currentProperty != null;
+ }
+
+ public Object nextElement() {
+
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ Directive result = null;
+ try {
+ result = new Directive((Element) currentProperty);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ currentProperty = getNextSibling((Element) currentProperty);
+ while (currentSetOrRemove != null && currentProperty == null) {
+ currentSetOrRemove = getNextSibling((Element) currentSetOrRemove, new String[] {"remove", "set"}); //$NON-NLS-1$ //$NON-NLS-2$
+ if (currentSetOrRemove != null) {
+ Node prop = getFirstChild((Element) currentSetOrRemove, "prop"); //$NON-NLS-1$
+ if (prop != null)
+ currentProperty = getChildElement((Element) prop, true);
+ }
+ }
+ return result;
+ }
+ };
+
+ return e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/PropertyUpdate.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedName.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedName.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedName.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+/**
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public interface QualifiedName {
+ /**
+ * Returns the local part of this name.
+ * The local part cannot be <code>null</code>.
+ *
+ * @return the local name.
+ */
+ public String getLocalName();
+
+ /**
+ * Returns the qualifier part for this qualifed name,
+ * or <code>null</code> if none.
+ * <p>
+ * Note that the qualifier is a URI i.e. it follows
+ * the syntax of RFC1630.</p>
+ *
+ * @return the name qualifier as a <code>String</code> URI
+ * or <code>null</code> if there is no qualifier.
+ */
+ public String getQualifier();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedName.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedNameImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedNameImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedNameImpl.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+
+/**
+ * Qualified names are two-part names: qualifier and local name.
+ * The qualifier must be in URI form (see RFC2396).
+ * Note however that the qualifier may be <code>null</code> if
+ * the default name space is being used. The empty space is
+ * not a valid qualifier.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class QualifiedNameImpl implements QualifiedName {
+
+ /** Qualifier part (potentially <code>null</code>). */
+ protected String qualifier = null;
+
+ /** Local name part. */
+ protected String localName = null;
+
+ /**
+ * Creates and returns a new qualified name with the given qualifier
+ * and local name. The local name must not be the empty string.
+ * The qualifier may be <code>null</code>.
+ */
+ public QualifiedNameImpl(String qualifier, String localName) {
+ Assert.isTrue(localName != null && localName.length() != 0);
+ this.qualifier = qualifier;
+ this.localName = localName;
+ }
+
+ /**
+ * Returns <code>true</code> if this qualified name is equivalent to the given object.
+ * <p>
+ * Qualified names are equal if and only if they have the same
+ * qualified parts and local parts.
+ * Qualified names are not equal to objects other than qualified names.
+ *
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (!(obj instanceof QualifiedName))
+ return false;
+ // There may or may not be a qualifier.
+ QualifiedName qName = (QualifiedName) obj;
+ if (qualifier == null && qName.getQualifier() != null)
+ return false;
+ if (qualifier != null && !qualifier.equals(qName.getQualifier()))
+ return false;
+ return localName.equals(qName.getLocalName());
+ }
+
+ /**
+ * Returns the local part of this name.
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * Returns the qualifier part for this qualifed name, or <code>null</code>
+ * if none.
+ */
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ /**
+ * Returns the hash code for this qualified name.
+ */
+ public int hashCode() {
+ return (qualifier == null ? 0 : qualifier.hashCode()) + localName.hashCode();
+ }
+
+ /**
+ * Converts this qualified name into a string, suitable for
+ * display (unsuitable for parsing back to a qualified name!).
+ */
+ public String toString() {
+ return Policy.bind("qualifiedNameImpl.namespace") + ": \"" + //$NON-NLS-1$ //$NON-NLS-2$
+ (getQualifier() == null ? "null" : getQualifier()) + //$NON-NLS-1$
+ "\", " + Policy.bind("qualifiedNameImpl.localPart") + ": \"" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ getLocalName() + "\""; //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/QualifiedNameImpl.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResourceID.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResourceID.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResourceID.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV resourceid element. See INTERNET
+ * DRAFT draft-ietf-webdav-binding-protocol-02 section 13.2 for the
+ * element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class ResourceID extends Property {
+ /**
+ * An ordered collection of the element names of the resourceid
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"href"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV resourceid element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a resourceid element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public ResourceID(Element root) throws MalformedElementException {
+ super(root, "resourceid"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns this resourceid's href.
+ *
+ * @return this resourceid's href
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getHref() throws MalformedElementException {
+ String href = getChildText(root, "href", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), href); //$NON-NLS-1$
+ return decodeHref(href);
+ }
+
+ /**
+ * Sets this resourceid's href to the given href.
+ *
+ * @param href the href to set this resourceid's href to
+ */
+ public void setHref(String href) {
+ Assert.isNotNull(href);
+ setChild(root, "href", encodeHref(href), childNames, true); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResourceID.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResponseBody.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResponseBody.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResponseBody.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,488 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.*;
+
+/**
+ * An element editor for the WebDAV response element. See RFC2518
+ * section 12.9.1 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see MultiStatus
+ * @see PropStat
+ */
+public class ResponseBody extends ElementEditor {
+ /**
+ * An ordered collection of the element names of the responsebody
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"href", "href", "status", "propstat", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+
+ /**
+ * An ordered collection of the element names of the responsebody
+ * element's children in the "status" form.
+ */
+ public static String[] fgNamesStatus = new String[] {"href", "href", "status", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ /**
+ * An ordered collection of the element names of the responsebody
+ * element's children in the "propstat" form.
+ */
+ public static String[] fgNamesPropStat = new String[] {"href", "propstat", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ /**
+ * Creates a new editor on the given WebDAV response element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a response element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public ResponseBody(Element root) throws MalformedElementException {
+ super(root, "response"); //$NON-NLS-1$
+ }
+
+ /**
+ * Gets this response's first propstat with the given status and adds an
+ * element created from the given property name as a property of the
+ * propstat's prop. If such a propstat does not exists, it is created.
+ * The propstat's response description is set to the given response
+ * description, or removed if the response description is
+ * <code>null</code>. Returns the propstat. The property name must not
+ * be <code>null</code> and its qualifier and local part must not be
+ * <code>null</code> and must not be the empty string. The status must
+ * not be <code>null</code>. This response must not already be in the
+ * "status" form.
+ *
+ * @param propertyName the name of the property to create and add
+ * @param status the status of the propstat to add the
+ * property element to
+ * @param responseDescription the new response description of the
+ * propstat, or <code>null</code> to remove
+ * the old one
+ * @return a propstat with the specified property
+ * element, status, and response description
+ */
+ public PropStat accumulatePropStat(QualifiedName propertyName, String status, String responseDescription) {
+
+ Assert.isNotNull(propertyName);
+ Assert.isNotNull(status);
+
+ Element child = getFirstChild(root, new String[] {"href", "status"}); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.isTrue(child == null || isDAVElement(child, "href") //$NON-NLS-1$
+ && getNextSibling(child, new String[] {"href", "status"}) == null); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String nsName = propertyName.getQualifier();
+ Assert.isTrue(!"".equals(nsName)); //$NON-NLS-1$
+
+ String localName = propertyName.getLocalName();
+ Assert.isNotNull(localName);
+ Assert.isTrue(!localName.equals("")); //$NON-NLS-1$
+
+ Document document = root.getOwnerDocument();
+ Element element = document.createElement(localName);
+ declareNS(element, null, nsName);
+
+ try {
+ return accumulatePropStat(element, status, responseDescription);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Gets this response's first propstat with the given status and adds a
+ * clone of the given element as a property of its prop. If such a
+ * propstat does not exists, it is created. The propstat's response
+ * description is set to the given response description, or removed if
+ * the response description is <code>null</code>. Returns the propstat.
+ * The element and status must not be <code>null</code>. This response
+ * must not already be in the "status" form.
+ *
+ * @param element the property element being added
+ * @param status the status of the propstat to add the
+ * property element to
+ * @param responseDescription the new response description of the
+ * propstat, or <code>null</code> to remove
+ * the old one
+ * @return a propstat with the given property
+ * element, status, and response description
+ * @throws MalformedElementException if there is
+ * reason to believe that the given element
+ * is not well formed
+ */
+ public PropStat accumulatePropStat(Element element, String status, String responseDescription) throws MalformedElementException {
+
+ Assert.isNotNull(element);
+ Assert.isNotNull(status);
+
+ Element child = getFirstChild(root, new String[] {"href", "status"}); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.isTrue(child == null || isDAVElement(child, "href") //$NON-NLS-1$
+ && getNextSibling(child, new String[] {"href", "status"}) == null); //$NON-NLS-1$ //$NON-NLS-2$
+
+ boolean found = false;
+ Element propstat = getFirstChild(root, "propstat"); //$NON-NLS-1$
+
+ while (!found && propstat != null) {
+ String text = getChildText(propstat, "status", false); //$NON-NLS-1$
+ if (text != null && text.equals(status))
+ found = true;
+ else
+ propstat = getTwin(propstat, true);
+
+ }
+
+ Element prop = null;
+
+ if (propstat == null) {
+ propstat = addChild(root, "propstat", fgNamesPropStat, false); //$NON-NLS-1$
+ prop = setChild(propstat, "prop", PropStat.childNames, true); //$NON-NLS-1$
+ setChild(propstat, "status", status, PropStat.childNames, false); //$NON-NLS-1$
+ } else {
+ prop = getFirstChild(propstat, "prop"); //$NON-NLS-1$
+ if (prop == null)
+ prop = setChild(propstat, "prop", PropStat.childNames, true); //$NON-NLS-1$
+ }
+
+ if (responseDescription == null) {
+ Element responsedescription = getLastChild(propstat, "responsedescription"); //$NON-NLS-1$
+ if (responsedescription != null)
+ propstat.removeChild(responsedescription);
+ } else
+ setChild(propstat, "responsedescription", //$NON-NLS-1$
+ responseDescription, PropStat.childNames, false);
+
+ extractNode(prop, element);
+
+ try {
+ return new PropStat(propstat);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Adds the given href to this response. If <code>setHref(String)</code>
+ * hasn't been called and no hrefs have been added, this method sets
+ * the first href and is thus equivalent to
+ * <code>setHref(String)</code>. The href must not be <code>null</code>.
+ * This response must not already be in "propstat" form.
+ *
+ * @param href the href to add
+ */
+ public void addHref(String href) {
+ Assert.isNotNull(href);
+ Assert.isTrue(getLastChild(root, "propstat") == null); //$NON-NLS-1$
+ addChild(root, "href", encodeHref(href), fgNamesStatus, false); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates and adds a propstat element on this response and returns an
+ * editor on it.
+ *
+ * @return an editor on a propstat element
+ */
+ public PropStat addPropStat() {
+ Element firstHref = getFirstChild(root, "href"); //$NON-NLS-1$
+ Assert.isTrue(firstHref == null || getNextSibling(firstHref, new String[] {"href", "status"}) == null); //$NON-NLS-1$ //$NON-NLS-2$
+ Element element = addChild(root, "propstat", fgNamesPropStat, false); //$NON-NLS-1$
+ try {
+ return new PropStat(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Changes all of this response's propstats with the given old status
+ * to have the given new status. In addition, their response
+ * descriptions are changed to be the given response description or
+ * removed if the given response description is <code>null</code>. The
+ * old status and new status must not be <code>null</null>. This
+ * response must not be in the "status" form.
+ *
+ * @param oldStatus the old status of the propstat's that are
+ * changed
+ * @param newStatus the new status of the propstat's that are
+ * changed
+ * @param responseDescription the new response description of the
+ * propstat's that are changed, or
+ * <code>null</null>
+ */
+ public void changePropStatStatus(String oldStatus, String newStatus, String responseDescription) {
+ Assert.isNotNull(oldStatus);
+ Assert.isNotNull(newStatus);
+ Element firstHref = getFirstChild(root, "href"); //$NON-NLS-1$
+ Assert.isTrue(firstHref == null || getNextSibling(firstHref, new String[] {"href", "status"}) == null); //$NON-NLS-1$ //$NON-NLS-2$
+ Element propstat = getFirstChild(root, "propstat"); //$NON-NLS-1$
+ while (propstat != null) {
+ String status = getChildText(propstat, "status", true); //$NON-NLS-1$
+ if (oldStatus.equals(status)) {
+ setChild(propstat, "status", newStatus, PropStat.childNames, true); //$NON-NLS-1$
+ if (responseDescription == null) {
+ Element responsedescription = getLastChild(propstat, "responsedescription"); //$NON-NLS-1$
+ if (responsedescription != null)
+ propstat.removeChild(responsedescription);
+ } else
+ setChild(propstat, "responsedescription", //$NON-NLS-1$
+ responseDescription, PropStat.childNames, false);
+ }
+ propstat = getTwin(propstat, true);
+ }
+ }
+
+ /**
+ * Creates a new WebDAV response element and sets it as the root of the
+ * given document. Returns an editor on the new response element. The
+ * document must not be <code>null</code>, and must not already have a
+ * root element.
+ *
+ * @param document the document that will become the root of a new
+ * response element
+ * @return an element editor on a response element
+ */
+ public static ResponseBody create(Document document) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getDocumentElement() == null);
+ Element element = create(document, "response"); //$NON-NLS-1$
+ ResponseBody result = null;
+ try {
+ result = new ResponseBody(element);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Returns this response's first href.
+ *
+ * @return this response's first href.
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getHref() throws MalformedElementException {
+ String href = getChildText(root, "href", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), href); //$NON-NLS-1$
+ return decodeHref(href);
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> of this response's hrefs (not
+ * including the first href).
+ *
+ * @return an <code>Enumeration</code> of this response's href
+ * <code>String<code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or if
+ * this response is not in "status" form
+ */
+ public Enumeration getHrefs() throws MalformedElementException {
+ final Node firstHref = getFirstChild(root, "href"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), firstHref); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingStatusElmt"), //$NON-NLS-1$
+ getNextSibling((Element) firstHref, "status")); //$NON-NLS-1$
+ Enumeration e = new Enumeration() {
+ Node currentHref = getTwin((Element) firstHref, true);
+
+ public boolean hasMoreElements() {
+ return currentHref != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ String href = getFirstText((Element) currentHref);
+ currentHref = getTwin((Element) currentHref, true);
+ return decodeHref(href);
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> of this response's
+ * <code>Propstat</code>s.
+ *
+ * @return an <code>Enumeration</code> of this response's
+ * <code>PropStat</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or if
+ * this response is not in "propstat" form
+ */
+ public Enumeration getPropStats() throws MalformedElementException {
+ final Element firstPropStat = getFirstChild(root, "propstat"); //$NON-NLS-1$
+ ensureNotNull("ensure.missingPropstatElmt", firstPropStat); //$NON-NLS-1$
+ Enumeration e = new Enumeration() {
+ Element currentPropStat = firstPropStat;
+
+ public boolean hasMoreElements() {
+ return currentPropStat != null;
+ }
+
+ public Object nextElement() {
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+ PropStat result = null;
+ try {
+ result = new PropStat(currentPropStat);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ currentPropStat = getTwin(currentPropStat, true);
+ return result;
+ }
+ };
+ return e;
+ }
+
+ /**
+ * Returns this response's response description, or <code>null</code> if
+ * it has none.
+ *
+ * @return this response's response description, or <code>null</code>
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getResponseDescription() throws MalformedElementException {
+ return getChildText(root, "responsedescription", false); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns this response's status.
+ *
+ * @return this response's status
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or if
+ * this response is not in "status" form
+ */
+ public String getStatus() throws MalformedElementException {
+ Element status = getFirstChild(root, "status"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingStatusElmt"), status); //$NON-NLS-1$
+ return getFirstText(status);
+ }
+
+ /**
+ * Returns this response's status code.
+ *
+ * @return this response's status code
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed, or if
+ * this response is not in "status" form
+ */
+ public int getStatusCode() throws MalformedElementException {
+ return new Status(getStatus()).getStatusCode();
+ }
+
+ /**
+ * Returns <code>true</code> if this response is in "propstat" form and
+ * <code>false</code> if it is in "status" form.
+ *
+ * @return a boolean indicating whether this response is in "propstat"
+ * or "status" form
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isPropStat() throws MalformedElementException {
+ Element child = getFirstChild(root, new String[] {"status", "propstat"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ensureNotNull(Policy.bind("ensure.missingStatusOrPropstatElmt"), child); //$NON-NLS-1$
+ boolean isPropStat = isDAVElement(child, "propstat"); //$NON-NLS-1$
+ if (isPropStat)
+ child = getNextSibling(child, "status"); //$NON-NLS-1$
+ else
+ child = getNextSibling(child, "propstat"); //$NON-NLS-1$
+ ensureNull(Policy.bind("ensure.conflictingStatusOrPropstatElmt"), child); //$NON-NLS-1$
+ return isPropStat;
+ }
+
+ /**
+ * Returns <code>true</code> if this response is in "status" form and
+ * <code>false</code> if it is in "propstat" form.
+ *
+ * @return a boolean indicating whether this response is in "status"
+ * or "propstat" form
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public boolean isStatus() throws MalformedElementException {
+ return !isPropStat();
+ }
+
+ /**
+ * Sets this response's first href to the given href. The href must not
+ * be <code>null</code>.
+ *
+ * @param href the href to set this response's first href to
+ */
+ public void setHref(String href) {
+ Assert.isNotNull(href);
+ setChild(root, "href", href, childNames, true); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets this response's response description to the given value. If the
+ * value is <code>null</code> and a response description has already
+ * been set, it is removed.
+ *
+ * @param value a response description, or <code>null</code>
+ */
+ public void setResponseDescription(String value) {
+ if (value == null) {
+ Element child = getLastChild(root, "responsedescription"); //$NON-NLS-1$
+ if (child != null)
+ root.removeChild(child);
+ } else
+ setChild(root, "responsedescription", value, childNames, false); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets this response's response description to the given value. If the
+ * value is <code>null</code> and a response description has already
+ * been set, it is removed.
+ *
+ * @param value a response description, or <code>null</code>
+ */
+ public void setResponseDescription(Element value) {
+ Element child = getLastChild(root, "responsedescription"); //$NON-NLS-1$
+ if (child != null)
+ root.removeChild(child);
+ if (value == null) {
+ child = setChild(root, "responsedescription", childNames, false); //$NON-NLS-1$
+ child.appendChild(value);
+ }
+ }
+
+ /**
+ * Sets the status on this response to the given status. The status
+ * must not be <code>null</code>. This response must not already be in
+ * the "propstat" form.
+ *
+ * @param status the status for this response
+ */
+ public void setStatus(String status) {
+ Assert.isNotNull(status);
+ Assert.isTrue(getLastChild(root, "propstat") == null); //$NON-NLS-1$
+ setChild(root, "status", status, fgNamesStatus, true); //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ResponseBody.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Status.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Status.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Status.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.eclipse.webdav.http.client.Response;
+
+/**
+ * A <code>Status</code> parses an http status string.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Status {
+
+ private int fStatusCode;
+ private String fStatusMessage;
+
+ /**
+ * Creates a new status from the given http status string.
+ *
+ * @param status the http status string; for example, "HTTP/1.1 200 OK"
+ * @throws MalformedElementException if the given status is malformed
+ */
+ public Status(String status) throws MalformedElementException {
+ status = status.trim();
+ int len = status.length();
+
+ int end;
+ int start = 0;
+
+ while (start < len && !Character.isWhitespace(status.charAt(start))) {
+ ++start;
+ }
+ while (start < len && Character.isWhitespace(status.charAt(start))) {
+ ++start;
+ }
+
+ if (start >= len) {
+ throw new MalformedElementException(Policy.bind("exception.malformedStatus", status)); //$NON-NLS-1$
+ }
+
+ end = start;
+ while (end < len && Character.isDigit(status.charAt(end))) {
+ ++end;
+ }
+
+ if (end == start || end >= len) {
+ throw new MalformedElementException(Policy.bind("exception.malformedStatus", status)); //$NON-NLS-1$
+ }
+
+ fStatusCode = Integer.parseInt(status.substring(start, end));
+
+ start = end;
+ while (start < len && Character.isWhitespace(status.charAt(start))) {
+ ++start;
+ }
+
+ if (start >= len) {
+ throw new MalformedElementException(Policy.bind("exception.malformedStatus", status)); //$NON-NLS-1$
+ }
+
+ fStatusMessage = status.substring(start, len);
+ }
+
+ /**
+ * Returns this status' status code. For example, if the http status
+ * string was "HTTP/1.1 200 OK", the status code would be 200.
+ *
+ * @return this status' status code
+ * @see Response
+ */
+ public int getStatusCode() {
+ return fStatusCode;
+ }
+
+ /**
+ * Returns this status' status message; for example, if the http status
+ * string was "HTTP/1.1 200 OK", the status message would be "OK".
+ *
+ * @return this status' status message
+ */
+ public String getStatusMessage() {
+ return fStatusMessage;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Status.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/SupportedLock.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/SupportedLock.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/SupportedLock.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * An element editor for the WebDAV supportedlock element. See RFC2518
+ * section 13.11 for the element's definition.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @see LockEntry
+ */
+public class SupportedLock extends Property {
+ /**
+ * An ordered collection of the element names of the supportedlock
+ * element's children.
+ */
+ protected static final String[] childNames = new String[] {"lockentry"}; //$NON-NLS-1$
+
+ /**
+ * Creates a new editor on the given WebDAV supportedlock element. The
+ * element is assumed to be well formed.
+ *
+ * @param root a supportedlock element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public SupportedLock(Element root) throws MalformedElementException {
+ super(root, "supportedlock"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new lockentry and adds it to this supported lock. Returns
+ * an editor on the new lockentry.
+ *
+ * @return an editor on a new lockentry for this supportedlock
+ */
+ public LockEntry addLockEntry() {
+
+ Element lockentry = addChild(root, "lockentry", childNames, false); //$NON-NLS-1$
+ Element locktype = appendChild(lockentry, "locktype"); //$NON-NLS-1$
+ appendChild(locktype, "write"); //$NON-NLS-1$
+
+ LockEntry result = null;
+ try {
+ result = new LockEntry(lockentry);
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns an <code>Enumeration</code> over this supportedlock's
+ * <code>LockEntry</code>s.
+ *
+ * @return an <code>Enumeration</code> of <code>LockEntry</code>s
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public Enumeration getLockEntries() throws MalformedElementException {
+
+ final Node firstLockEntry = getFirstChild(root, "lockentry"); //$NON-NLS-1$
+
+ Enumeration e = new Enumeration() {
+ Node currentLockEntry = firstLockEntry;
+
+ public boolean hasMoreElements() {
+
+ return currentLockEntry != null;
+ }
+
+ public Object nextElement() {
+
+ if (!hasMoreElements())
+ throw new NoSuchElementException();
+
+ LockEntry result = null;
+ try {
+ result = new LockEntry((Element) currentLockEntry);
+ } catch (MalformedElementException ex) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+
+ currentLockEntry = getTwin((Element) currentLockEntry, true);
+ return result;
+ }
+ };
+
+ return e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/SupportedLock.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Update.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Update.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Update.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.dom;
+
+import org.eclipse.webdav.Policy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An element editor for the WebDAV update element.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ */
+public class Update extends ElementEditor {
+
+ // An ordered collection of the element names of the update
+ // element's children.
+ public static String[] childNames = new String[] {"label-name", "version"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Creates a new editor on the given WebDAV set target element. The
+ * element is assumed to be well formed.
+ *
+ * @param root an activelock element
+ * @throws MalformedElementException if there is reason to
+ * believe that the element is not well formed
+ */
+ public Update(Element root) throws MalformedElementException {
+ super(root, "set-target"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new WebDAV update element and sets it as the root of
+ * the given document. Returns an editor on the new element.
+ * <p>
+ * The document must not be <code>null</code>, and must not already have
+ * a root element.</p>
+ *
+ * @param document the document that will become the root of a new
+ * update element.
+ * @return an element editor on an update element.
+ */
+ public static Update createLabel(Document document, String label) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Assert.isNotNull(label);
+ Element element = create(document, "update"); //$NON-NLS-1$
+ try {
+ Update editor = new Update(element);
+ editor.setLabelName(label);
+ return editor;
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ /**
+ * Creates a new WebDAV update element and sets it as the root of
+ * the given document. Returns an editor on the new element.
+ * <p>
+ * The document must not be <code>null</code>, and must not already have
+ * a root element.</p>
+ *
+ * @param document the document that will become the root of a new
+ * update element
+ * @return an element editor on a set-target element
+ */
+ public static Update createVersion(Document document, String href) {
+ Assert.isNotNull(document);
+ Assert.isTrue(document.getOwnerDocument() == null);
+ Assert.isNotNull(href);
+ Element element = create(document, "update"); //$NON-NLS-1$
+ try {
+ Update editor = new Update(element);
+ editor.setVersion(href);
+ return editor;
+ } catch (MalformedElementException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ return null; // Never reached.
+ }
+ }
+
+ public String getLabel() throws MalformedElementException {
+ String label = getChildText(root, "label", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingLabelElmt"), label); //$NON-NLS-1$
+ return label;
+ }
+
+ /**
+ * Returns this response's first DAV:version child element.
+ *
+ * @return this response's first version href.
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public String getVersion() throws MalformedElementException {
+ Element version = getFirstChild(root, "version"); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingVersionElmt"), version); //$NON-NLS-1$
+ String href = getChildText(version, "href", true); //$NON-NLS-1$
+ ensureNotNull(Policy.bind("ensure.missingHrefElmt"), href); //$NON-NLS-1$
+ return decodeHref(href);
+ }
+
+ public boolean isVersion() throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ ensureNotNull(Policy.bind("ensure.missingTargetDesc"), child); //$NON-NLS-1$
+ return getNSLocalName(child).equals("version"); //$NON-NLS-1$
+ }
+
+ /**
+ * Sets the DAV:label child element.
+ *
+ * @param label the string label to the version.
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public void setLabelName(String label) throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ // If there is a version child already there remove it.
+ if (isDAVElement(child, "version")) //$NON-NLS-1$
+ root.removeChild(child);
+ // Add/update the label-name element.
+ setChild(child, "label-name", label, new String[] {"label-name"}, true); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Sets the DAV:version child element.
+ *
+ * @param href the string href to the version.
+ * @throws MalformedElementException if there is reason to believe that
+ * this editor's underlying element is not well formed
+ */
+ public void setVersion(String href) throws MalformedElementException {
+ Element child = getFirstChild(root, childNames);
+ // If there is a label-name child remove it.
+ if (isDAVElement(child, "label-name")) //$NON-NLS-1$
+ root.removeChild(child);
+ // Add/update a version element with the href of the version target.
+ Element newChild = setChild(root, "version", new String[] {"version"}, true); //$NON-NLS-1$ //$NON-NLS-2$
+ setChild(newChild, "href", encodeHref(href), new String[] {"href"}, true); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/Update.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/package.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/package.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/package.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <meta name="GENERATOR" content=" ">
+ <meta name="ProgId" content=" ">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides a set of "editors" for manipulating the XML data exchanged
+with WebDAV servers.
+<h2>
+Package Specification</h2>
+This package defines a set of XML DOM editors useful for manipulating the XML
+typically passed between WebDAV clients and servers.
+</body>
+</html>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/dom/package.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLDecoder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLDecoder.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLDecoder.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.StringTokenizer;
+import org.eclipse.webdav.Policy;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * Decodes a <code>URL</code> from an <code>ASCII</code> readable
+ * <code>URL</code> that is safe for transport.
+ *
+ * @see URLEncoder
+ */
+public final class URLDecoder {
+
+ private static final byte[] hexChars = {(byte) '0', //
+ (byte) '1', //
+ (byte) '2', //
+ (byte) '3', //
+ (byte) '4', //
+ (byte) '5', //
+ (byte) '6', //
+ (byte) '7', //
+ (byte) '8', //
+ (byte) '9', //
+ (byte) 'a', //
+ (byte) 'b', //
+ (byte) 'c', //
+ (byte) 'd', //
+ (byte) 'e', //
+ (byte) 'f', //
+ (byte) 'A', //
+ (byte) 'B', //
+ (byte) 'C', //
+ (byte) 'D', //
+ (byte) 'E', //
+ (byte) 'F'};
+ private static final byte[] hexCharValues = {(byte) ('0' - '0'), //
+ (byte) ('1' - '0'), //
+ (byte) ('2' - '0'), //
+ (byte) ('3' - '0'), //
+ (byte) ('4' - '0'), //
+ (byte) ('5' - '0'), //
+ (byte) ('6' - '0'), //
+ (byte) ('7' - '0'), //
+ (byte) ('8' - '0'), //
+ (byte) ('9' - '0'), //
+ (byte) ('a' - 'a' + 10), //
+ (byte) ('b' - 'a' + 10), //
+ (byte) ('c' - 'a' + 10), //
+ (byte) ('d' - 'a' + 10), //
+ (byte) ('e' - 'a' + 10), //
+ (byte) ('f' - 'a' + 10), //
+ (byte) ('A' - 'A' + 10), //
+ (byte) ('B' - 'A' + 10), //
+ (byte) ('C' - 'A' + 10), //
+ (byte) ('D' - 'A' + 10), //
+ (byte) ('E' - 'A' + 10), //
+ (byte) ('F' - 'A' + 10)};
+
+ /**
+ * Prevents instances from being created.
+ */
+ private URLDecoder() {
+ super();
+ }
+
+ /**
+ * Decodes the given <code>URL</code> from an <code>ASCII</code>
+ * readable <code>URL</code> that is safe for transport. Returns the
+ * result.
+ *
+ * @return the result of decoding the given <code>URL</code> from an
+ * <code>ASCII</code> readable <code>URL</code> that is safe for
+ * transport
+ */
+ public static String decode(String url) {
+ try {
+ return decode(new URL(url)).toString();
+ } catch (MalformedURLException e) {
+ // ignore or log?
+ }
+
+ String file;
+ String ref = null;
+
+ int lastSlashIndex = url.lastIndexOf('/');
+ int lastHashIndex = url.lastIndexOf('#');
+ if ((lastHashIndex - lastSlashIndex > 1) && lastHashIndex < url.length() - 1) {
+ file = url.substring(0, lastHashIndex);
+ ref = url.substring(lastHashIndex + 1, url.length());
+ } else {
+ file = url;
+ }
+
+ return decode(file, ref);
+ }
+
+ /**
+ * Decodes the file and reference parts of a <code>URL</code> from an
+ * <code>ASCII</code> readable <code>URL</code> that is safe for
+ * transport. Returns the result.
+ *
+ * @return the result of decoding the file and reference parts of a
+ * <code>URL</code> from an <code>ASCII</code> readable
+ * <code>URL</code> that is safe for transport
+ */
+ public static String decode(String file, String ref) {
+ StringBuffer buf = new StringBuffer();
+ StringTokenizer tokenizer = new StringTokenizer(file, "/", true); //$NON-NLS-1$
+
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ if (token.equals("/")) { //$NON-NLS-1$
+ buf.append(token);
+ } else {
+ buf.append(decodeSegment(token));
+ }
+ }
+
+ if (ref != null) {
+ buf.append('#');
+ buf.append(decodeSegment(ref));
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Decodes the given <code>URL</code> from an <code>ASCII</code>
+ * readable <code>URL</code> that is safe for transport. Returns the
+ * result.
+ *
+ * @return the result of decoding the given <code>URL</code> from an
+ * <code>ASCII</code> readable <code>URL</code> that is safe for
+ * transport
+ */
+ public static URL decode(URL url) {
+ String file = url.getFile();
+ String ref = url.getRef();
+ try {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), decode(file, ref));
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public static String decodeSegment(String segment) {
+ byte[] encodedBytes = segment.getBytes();
+ byte[] decodedBytes = new byte[encodedBytes.length];
+ int decodedLength = 0;
+
+ for (int i = 0; i < encodedBytes.length; i++) {
+ byte b = encodedBytes[i];
+ try {
+ if (b == '%') {
+ byte enc1 = encodedBytes[++i];
+ byte enc2 = encodedBytes[++i];
+ b = (byte) ((hexToByte(enc1) << 4) + hexToByte(enc2));
+ }
+ decodedBytes[decodedLength++] = b;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ Assert.isTrue(false, Policy.bind("assert.decodeSegment")); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ Assert.isTrue(false, Policy.bind("assert.decodeSegment")); //$NON-NLS-1$
+ }
+ }
+ try {
+ return new String(decodedBytes, 0, decodedLength, "UTF8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException exception) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ // avoid compiler error
+ return null;
+ }
+ }
+
+ private final static byte hexToByte(byte ch) {
+ for (int i = 0; i < hexChars.length; i++)
+ if (hexChars[i] == ch)
+ return hexCharValues[i];
+ throw new IllegalArgumentException();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLDecoder.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLEncoder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLEncoder.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLEncoder.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.StringTokenizer;
+import org.eclipse.webdav.Policy;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * Encodes a <code>URL</code> into an <code>ASCII</code> readable
+ * <code>URL</code> that is safe for transport. Encoded
+ * <code>URL</code>s can be decoded using the <code>URLDecoder</code>.
+ *
+ * @see URLDecoder
+ */
+public final class URLEncoder {
+ /**
+ * Prevents instances from being created.
+ */
+ private URLEncoder() {
+ super();
+ }
+
+ /**
+ * Encodes the given <code>URL</code> into an <code>ASCII</code>
+ * readable <code>URL</code> that is safe for transport. Returns the
+ * result.
+ *
+ * @return the result of encoding the given <code>URL</code> into an
+ * <code>ASCII</code> readable <code>URL</code> that is safe for
+ * transport
+ */
+ public static String encode(String url) {
+ try {
+ return encode(new URL(url)).toString();
+ } catch (MalformedURLException e) {
+ // ignore or log?
+ }
+
+ String file;
+ String ref = null;
+
+ int lastSlashIndex = url.lastIndexOf('/');
+ int lastHashIndex = url.lastIndexOf('#');
+ if ((lastHashIndex - lastSlashIndex > 1) && lastHashIndex < url.length() - 1) {
+ file = url.substring(0, lastHashIndex);
+ ref = url.substring(lastHashIndex + 1, url.length());
+ } else {
+ file = url;
+ }
+
+ return encode(file, ref);
+ }
+
+ /**
+ * Encodes the given file and reference parts of a <code>URL</code> into
+ * an <code>ASCII</code> readable <code>String</code> that is safe for
+ * transport. Returns the result.
+ *
+ * @return the result of encoding the given file and reference parts of
+ * a <code>URL</code> into an <code>ASCII</code> readable
+ * <code>String</code> that is safe for transport
+ */
+ public static String encode(String file, String ref) {
+ StringBuffer buf = new StringBuffer();
+ StringTokenizer tokenizer = new StringTokenizer(file, "/", true); //$NON-NLS-1$
+
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ if (token.equals("/")) { //$NON-NLS-1$
+ buf.append(token);
+ } else {
+ buf.append(encodeSegment(token));
+ }
+ }
+
+ if (ref != null) {
+ buf.append('#');
+ buf.append(encodeSegment(ref));
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Encodes the given <code>URL</code> into an <code>ASCII</code>
+ * readable <code>URL</code> that is safe for transport. Returns the
+ * result.
+ *
+ * @return the result of encoding the given <code>URL</code> into an
+ * <code>ASCII</code> readable <code>URL</code> that is safe for
+ * transport
+ */
+ public static URL encode(URL url) {
+ String file = url.getFile();
+ String ref = url.getRef();
+
+ try {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), encode(file, ref));
+ } catch (MalformedURLException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ private static String encodeSegment(String segment) {
+ StringBuffer result = new StringBuffer(segment.length());
+
+ for (int i = 0; i < segment.length(); ++i) {
+ char c = segment.charAt(i);
+ if (mustEncode(c)) {
+ byte[] bytes = null;
+ try {
+ bytes = new Character(c).toString().getBytes("UTF8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$
+ }
+ for (int j = 0; j < bytes.length; ++j) {
+ result.append('%');
+ result.append(Integer.toHexString((bytes[j] >> 4) & 0x0F));
+ result.append(Integer.toHexString(bytes[j] & 0x0F));
+ }
+ } else {
+ result.append(c);
+ }
+ }
+
+ return result.toString();
+ }
+
+ private static boolean mustEncode(char c) {
+ if (c >= 'a' && c <= 'z')
+ return false;
+ if (c >= 'A' && c <= 'Z')
+ return false;
+ if (c >= '0' && c <= '9')
+ return false;
+ if (c >= '\'' && c <= '.')
+ return false;
+ if (c == '!' || c == '$' || c == '_')
+ return false;
+ return true;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/internal/utils/URLEncoder.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/messages.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/messages.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/messages.properties 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,63 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+### Eclipse WebDAV Interface message catalog
+
+
+### Assert
+assert.internalError = Internal error.
+assert.nullArgument = Null argument; {0}.
+assert.failed = Assertion failed; {0}.
+assert.notSupported = Not supported.
+assert.unknownNodeType = Unknown node type.
+assert.notImplemented = Not implemented.
+assert.noHrefRef = Reference href does not exist.
+assert.decodeSegment = Unable to decode segment: {0}.
+
+### Ensure
+ensure.missingDepthElmt = Missing DAV:depth element.
+ensure.invalidDepth = Invalid depth: {0}.
+ensure.missingHrefElmt = Missing DAV:href element.
+ensure.missingLockscopeElmt = Missing DAV:lockscope element.
+ensure.missingSharedOrExclusiveElmt = Missing DAV:shared or DAV:exclusive element.
+ensure.conflictingSharedOrExclusiveElmt = Conflicting DAV:shared or DAV:exclusive elements.
+ensure.expectingAnElmt = Expecting DAV: {0} element.
+ensure.missingNamespaceForPrefix = Missing namespace name for prefix: {0}.
+ensure.mustHaveDAVQualifier = Name must have DAV qualifier.
+ensure.missingElmt = Missing element.
+ensure.missingLabel = Missing label name.
+ensure.missingResponseElmt = Missing DAV:response element.
+ensure.missingKeealiveElmt = Missing DAV:keepalive element.
+ensure.wrongForm = Element is in the wrong form for this method.
+ensure.expectingOmitOrKeepaliveElmt = Expecting DAV:omit or DAV:keepalive element.
+ensure.conflictingHrefElmt = Conflicting DAV:href element.
+ensure.conflictingOmitOrKeepaliveElmt = Conflicting DAV:omit or DAV:keepalive element.
+ensure.expectingPropElmt = Expecting DAV:prop element.
+ensure.expectingRemoveOrSetElmt = Expecting DAV:remove or DAV:set element.
+ensure.missingRemoveOrSetElmt = Missing DAV:remove or DAV:set element.
+ensure.missingPropElmt = Missing DAV:prop element.
+ensure.missingAllpropOrPropnameOrPropElmt = Missing DAV:allprop, DAV:propname, or DAV:prop element.
+ensure.conflictingAllpropOrPropnameOrPropElmt = Conflicting DAV:allprop, DAV:propname, or DAV:prop element.
+ensure.missingStatusElmt = Missing DAV:status element.
+ensure.missingPropstatElmt = Missing DAV:propstat element.
+ensure.missingStatusOrPropstatElmt = Missing DAV:status or DAV:propstat element.
+ensure.conflictingStatusOrPropstatElmt = Conflicting DAV:status or DAV:propstat element.
+ensure.missingLabelElmt = Missing DAV:label element.
+ensure.missingVersionElmt = Missing DAV:version element.
+ensure.missingTargetDesc = Missing target description..
+
+### QualifiedNameImpl
+qualifiedNameImpl.namespace = Namespace
+qualifiedNameImpl.localPart = Local part
+
+### Exception
+exception.namespacePrefixNotResolved = Namespace prefix {0} could not be resolved.
+exception.noLocalNameForElmt = Element doesn't have a local name.
+exception.malformedStatus = Malformed status: {0}.
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/messages.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/package.html
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/package.html (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/package.html 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides infrastructure objects for communicating with WebDAV/HTTP servers.
+<h2>
+Package Specification</h2>
+This package defines a set of infrastructure objects representing locations,
+servers and communications contexts needed for WebDAV and HTTP server
+interaction.
+</body>
+</html>
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/interface/org/eclipse/webdav/package.html
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ClientException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ClientException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ClientException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+/** Represents exceptions that can happen on the Client as the
+ * result of a client error.
+ * <p>
+ * Status codes:
+ * <ul>
+ * <li>400 Bad Request</li>
+ * <li>401 Unauthorized</li>
+ * <li>402 Payment Required</li>
+ * <li>403 Forbidden</li>
+ * <li>404 Not Found</li>
+ * <li>405 Mothod Not Allowed</li>
+ * <li>406 Not Acceptable</li>
+ * <li>407 Proxy Authentication Required</li>
+ * <li>408 Request Timeout</li>
+ * <li>409 Conflict</li>
+ * <li>410 Gone</li>
+ * <li>411 Length Required</li>
+ * <li>412 Precondition Failed</li>
+ * <li>413 Request Entity Too Large</li>
+ * <li>414 Request-URI Too Long</li>
+ * <li>415 Unsupported Media Type</li>
+ * <li>422 Unprocessable Entity</li>
+ * <li>423 Locked</li>
+ * <li>424 Method Failure</li>
+ * <li>425 Insufficient Space on Resource</li>
+ * </ul>
+ * </p>
+ */
+public class ClientException extends WebDAVException {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct a ClientException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public ClientException(int statusCode, String statusMessage) {
+ super(statusCode, statusMessage);
+ }
+
+ /**
+ * Construct a ClientException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public ClientException(int statusCode, String statusMessage, Object data) {
+ super(statusCode, statusMessage, data);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ClientException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Condition.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Condition.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Condition.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,247 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Vector;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * A Condition represents some state configuration of a particular resource that must be
+ * satisfied in order for the associated request to be valid. At least one of
+ * the ConditionTerms in a Condition must match with states of the resource, i.e.,
+ * they are OR'd together. Conditions are contained in a Precondition which is used in a
+ * WebDAV If header.
+ */
+public class Condition {
+ private String uri = null;
+ private Vector conditionTerms = new Vector();
+
+ /**
+ * Construct a Condition on the default resource.
+ */
+ public Condition() {
+ super();
+ }
+
+ /**
+ * Construct a Condition with the given URI.
+ *
+ * @param uri the URI of the resource associated with this condition
+ */
+ public Condition(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Add a ConditionTerm to a Condition.
+ *
+ * @param term the term to add
+ */
+ public void addConditionTerm(ConditionTerm term) throws WebDAVException {
+ conditionTerms.addElement(term);
+ }
+
+ /**
+ * Does this Condition contain the given ConditionTerm?
+ *
+ * @param term the term to check for
+ * @return true if the condition contains the given term, false otherwise
+ */
+ public boolean contains(ConditionTerm term) {
+ // iterate through the factors looking for a match
+ boolean match = false;
+ Enumeration terms = getConditionTerms();
+ while (!match && terms.hasMoreElements()) {
+ ConditionTerm t = (ConditionTerm) terms.nextElement();
+ match = term.matches(t);
+ }
+ return match;
+ }
+
+ /**
+ * Create a Condition by parsing the given If header as defined by
+ * section 9.4 in the WebDAV spec.
+ *
+ * @param tokenizer a StreamTokenizer on the contents of a WebDAV If header
+ * @return the parsed condition
+ */
+ public static Condition create(StreamTokenizer tokenizer) throws WebDAVException {
+ Condition condition = new Condition();
+ try {
+ int token = tokenizer.ttype;
+ if (token == '<') {
+ token = tokenizer.nextToken();
+ if (token == StreamTokenizer.TT_WORD) {
+ condition.setResourceURI(tokenizer.sval);
+ } else {
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingResource")); //$NON-NLS-1$
+ }
+ token = tokenizer.nextToken();
+ if (token == '>') {
+ token = tokenizer.nextToken();
+ } else {
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), ">")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ if (token == '(') {
+ while (token == '(') {
+ condition.addConditionTerm(ConditionTerm.create(tokenizer));
+ token = tokenizer.ttype;
+ }
+ } else {
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingStart", String.valueOf(token))); //$NON-NLS-1$
+ }
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ return condition;
+ }
+
+ /**
+ * Create a Condition by parsing the given If header as defined by
+ * section 9.4 in the WebDAV spec.
+ *
+ * @param ifHeader the contents of a WebDAV If header
+ * @return the parsed condition
+ * @exception WebDAVException thrown if there is a syntax error in the header
+ */
+ public static Condition create(String ifHeader) throws WebDAVException {
+ StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(ifHeader));
+ // URI characters
+ tokenizer.wordChars('!', '/');
+ tokenizer.wordChars(':', '@');
+ tokenizer.ordinaryChar('(');
+ tokenizer.ordinaryChar(')');
+ tokenizer.ordinaryChar('<');
+ tokenizer.ordinaryChar('>');
+ tokenizer.ordinaryChar('[');
+ tokenizer.ordinaryChar(']');
+ tokenizer.quoteChar('"');
+ Condition condition = null;
+ try {
+ int token = tokenizer.nextToken();
+ condition = Condition.create(tokenizer);
+ token = tokenizer.ttype;
+ if (token != StreamTokenizer.TT_EOF) {
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "EOF")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ return condition;
+ }
+
+ /**
+ * Get all the ConditionTerms for this Condition. At least one of the ConditionTerms in
+ * a Condition must match with states of the resource, i.e., they are OR'd
+ * together. Conditions are contained in a Precondition which is used in a
+ * WebDAV If header.
+ */
+ public Enumeration getConditionTerms() {
+ return conditionTerms.elements();
+ }
+
+ /**
+ * Get the URI of the associated Resource. The condition must match on this
+ * resource. This is useful for Preconditions that span multiple resources.
+ *
+ * @return the resource URI whose state is described by this Condition, may be null
+ * indicating the condition applies to the resource receiving the request
+ */
+ public String getResourceURI() {
+ return uri;
+ }
+
+ /**
+ * See if this Condition matches the given Condition. This is an
+ * OR operation.
+ *
+ * @param condition the condition to match against
+ * @return true if the conditions match, false otherwise.
+ */
+ public boolean matches(Condition condition) {
+ //// check the Resource if one was given
+ //boolean match = true;
+ //if (uri != null) {
+ ////try {
+ ////URL url1 = new URL(uri);
+ ////URL url2 = new URL(condition.getResourceURI());
+ ////match = match && url1.getProtocol().equals(url2.getProtocol());
+ ////match = match && url1.getHost().equals(url2.getHost());
+ ////int port1 = url1.getPort();
+ ////if (port1 == -1) { // use the default port
+ ////port1 = 80;
+ ////}
+ ////int port2 = url2.getPort();
+ ////if (port2 == -1) {
+ ////port2 = 80;
+ ////}
+ ////match = match && (port1 == port2);
+ ////match = match && url1.getFile().equals(url2.getFile());
+ ////} catch (Exception exc) {
+ ////match = false;
+ ////}
+ //// added to fix bug. should not compare full uris, only the path
+ //// match = uri.equals(condition.getResourceURI());
+ //match = (new URI(uri)).getPath().removeTrailingSeparator().equals(
+ //(new URI(condition.getResourceURI())).getPath().removeTrailingSeparator());
+ //}
+ //if (!match) {
+ //return false;
+ //}
+ //// is each term in the condition in the given condition
+ //match = false;
+ //Enumeration terms = getConditionTerms();
+ //while (!match && terms.hasMoreElements()) {
+ //ConditionTerm term = (ConditionTerm) terms.nextElement();
+ //match = condition.contains(term);
+ //}
+ //return match;
+ return false;
+ }
+
+ /**
+ * Set the URI of the associated Resource. The condition must match on this
+ * resource. This is useful for Preconditions that span multiple resources.
+ *
+ * @param value the resource URI whose state is described by this Condition.
+ * value can be null if the condition applies to the resource executing
+ * the method.
+ */
+ public void setResourceURI(String value) {
+ uri = value;
+ }
+
+ /**
+ * Return a String representation of this Condition as defined by section 9.4
+ * of the WebDAV Spec.
+ *
+ * @return a String representation of this condition
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (getResourceURI() != null) {
+ buffer.append('<');
+ buffer.append(getResourceURI());
+ buffer.append("> "); //$NON-NLS-1$
+ }
+ Enumeration terms = getConditionTerms();
+ while (terms.hasMoreElements()) {
+ ConditionTerm term = (ConditionTerm) terms.nextElement();
+ buffer.append(term.toString());
+ if (terms.hasMoreElements())
+ buffer.append(' ');
+ }
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Condition.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionFactor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionFactor.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionFactor.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * A ConditionFactor represents some state of a resource that must be
+ * satisfied in order for the associated request to be valid. The ConditionFactors in
+ * a ConditionTerm must all match with states of the resource, i.e., they are AND'ed
+ * together. Conditions are contained in a Precondition which is used in a
+ * WebDAV If header. ConditionFactors are either constructed by the client, or may
+ * have been given to the client in a previous method request. A ConditionFactor can
+ * be either a StateToken or an EntityTag as defined by section 9.4 of the WebDAV
+ * spec.
+ */
+public abstract class ConditionFactor {
+
+ private boolean not = false;
+
+ /**
+ * Create a ConditionFactor (either a StateToken or EntityTag) by parsing
+ * the tokenizer contining an If header value.
+ *
+ * @param tokenizer a StreamTokenizer containing the contents of a state token or entity tag
+ * from a WebDAV If header
+ * @return the parsed ConditionFactor
+ * @exception WebDAVException thrown if there is a syntax error in the If header
+ */
+ public static ConditionFactor create(StreamTokenizer tokenizer) throws WebDAVException {
+ boolean not = false;
+ ConditionFactor factor = null;
+ try {
+ int token = tokenizer.ttype;
+ if (token == StreamTokenizer.TT_WORD) {
+ if (tokenizer.sval.equalsIgnoreCase("Not")) { //$NON-NLS-1$
+ not = true;
+ } else {
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingNot")); //$NON-NLS-1$
+ }
+ token = tokenizer.nextToken();
+ }
+ switch (token) {
+ case '<' :
+ factor = StateToken.create(tokenizer);
+ break;
+ case '[' :
+ factor = EntityTag.create(tokenizer);
+ break;
+ default :
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingOpen", String.valueOf(token))); //$NON-NLS-1$
+ }
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ factor.setNot(not);
+ return factor;
+ }
+
+ /**
+ * Negate the comparison on this ConditionFactor?
+ *
+ * @return true if the condition factor was negated in the If header
+ */
+ public boolean not() {
+ return not;
+ }
+
+ /**
+ * Set how to compare to this ConditionFactor. Value is true implies match for
+ * a valid request, false implies the request is valid only if the ConditionFactor
+ * doesn't match.
+ *
+ * @param value true means negate the condition
+ */
+ public void setNot(boolean value) {
+ not = value;
+ }
+
+ /**
+ * Return a String representation of this ConditionFactor as defined by the If
+ * header in section 9.4 of the WebDAV spec.
+ *
+ * @return a string representation of a state token or entity tag
+ */
+ public abstract String toString();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionFactor.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionTerm.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionTerm.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionTerm.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.util.Enumeration;
+import java.util.Vector;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * A ConditionTerm represents some state configuration of a resource that must be
+ * satisfied in order for the associated request to be valid. The ConditionFactors in
+ * a ConditionTerm must all match with states of the resource, i.e., they are AND'ed
+ * together. ConditionTerms are contained in a Condition which is used in the Precondition
+ * of a WebDAV If header.
+ */
+public class ConditionTerm {
+
+ private Vector conditionFactors = new Vector();
+
+ /**
+ * Construct a Condition with no associated Resource URI.
+ */
+ public ConditionTerm() {
+ super();
+ }
+
+ /**
+ * Add a ConditionFactor to a ConditionTerm.
+ *
+ * @param factor the factor to add
+ * @exception WebDAVException thrown if the term already contains the factor
+ */
+ public void addConditionFactor(ConditionFactor factor) throws WebDAVException {
+ if (conditionFactors.contains(factor))
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseDuplicateEntry")); //$NON-NLS-1$
+ conditionFactors.addElement(factor);
+ }
+
+ /**
+ * Does this ConditionTerm contain the given ConditionFactor?
+ *
+ * @param factor the factor to check for
+ * @return true if the term contains the given factor
+ */
+ public boolean contains(ConditionFactor factor) {
+ return conditionFactors.contains(factor);
+ }
+
+ /**
+ * Create a ConditionTerm by parsing the given If header as defined by
+ * section 9.4 in the WebDAV spec.
+ *
+ * @param tokenizer a StreamTokenizer on the contents of a WebDAV If header
+ * @return the parsed ConditionTerm
+ * @exception WebDAVException thrown if there is a syntax error in the If header
+ */
+ public static ConditionTerm create(StreamTokenizer tokenizer) throws WebDAVException {
+ ConditionTerm term = new ConditionTerm();
+ try {
+ int token = tokenizer.ttype;
+ if (token == '(')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "(")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ while (token == StreamTokenizer.TT_WORD || token == '<' || token == '[') {
+ term.addConditionFactor(ConditionFactor.create(tokenizer));
+ token = tokenizer.ttype;
+ }
+ if (token == ')')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), ")")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ if (!term.getConditionFactors().hasMoreElements())
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingStateOrEntity")); //$NON-NLS-1$
+ return term;
+ }
+
+ /**
+ * Get all the ConditionFactors in this Condition. The ConditionFactors in
+ * a Condition must all match with states of the resource, i.e., they are AND'ed
+ * together. ConditionTerms are contained in a Condition which is used in the
+ * Precondition of a WebDAV If header.
+ *
+ * @return an Enumeration of ConditionFactors
+ */
+ public Enumeration getConditionFactors() {
+ return conditionFactors.elements();
+ }
+
+ /**
+ * See if this ConditionTerm matches the given ConditionTerm. This is an
+ * AND operation. All the factors in the ConditionTerm must match.
+ *
+ * @param conditionTerm the term to match
+ * @return true if all the factors in the term match those in this term
+ */
+ public boolean matches(ConditionTerm conditionTerm) {
+ int numberOfItemsToMatch = 0;
+ boolean match = true;
+ Enumeration factors = getConditionFactors();
+ while (match && factors.hasMoreElements()) {
+ ConditionFactor factor = (ConditionFactor) factors.nextElement();
+ if (factor.not()) {
+ match = !conditionTerm.contains(factor);
+ } else {
+ match = conditionTerm.contains(factor);
+ numberOfItemsToMatch++;
+ }
+ }
+ match = match && numberOfItemsToMatch == conditionTerm.numberOfFactors();
+ return match;
+ }
+
+ /**
+ * Get the number of ConditionFactors in this ConditionTerm.
+ *
+ * @return the number of factors in this term
+ */
+ public int numberOfFactors() {
+ return conditionFactors.size();
+ }
+
+ /**
+ * Return a String representation of this ConditionTerm as defined by section 9.4
+ * of the WebDAV Spec.
+ *
+ * @return a string representation of this term
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('(');
+ Enumeration factors = getConditionFactors();
+ while (factors.hasMoreElements()) {
+ ConditionFactor factor = (ConditionFactor) factors.nextElement();
+ buffer.append(factor.toString());
+ if (factors.hasMoreElements())
+ buffer.append(' ');
+ }
+ buffer.append(')');
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ConditionTerm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Context.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Context.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Context.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,1965 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.internal.kernel.utils.EnumerationConverter;
+import org.eclipse.webdav.internal.kernel.utils.MergedEnumeration;
+
+/**
+ * The <code>Context</code> class is essentially a collection of key-value
+ * pairings, with defaults. Implements the <code>Context</code> interface
+ * which provides convenience methods for most HTTP and WebDAV message
+ * header fields.
+ *
+ * To be done:
+ *
+ * 1) Types that take and return dates have not been changed. We need to write
+ * date formats to cope with the different strings that we may be sent, see
+ *the HTTP spec for details.
+ * 2) Identify the fields where multiple values are permissible, and change the
+ *params to be arrays of values.
+ *
+ */
+public class Context implements IContext {
+
+ protected Hashtable properties = new Hashtable(5);
+ protected IContext defaults = null;
+
+ protected final class ContextKey {
+
+ protected String key;
+
+ public ContextKey(String key) {
+ super();
+ this.key = key;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof ContextKey))
+ return false;
+ return ((ContextKey) obj).key.equalsIgnoreCase(key);
+ }
+
+ public int hashCode() {
+ return key.toLowerCase().hashCode();
+ }
+
+ public String toString() {
+ return key;
+ }
+ }
+
+ public final class ContextKeyToStringEnum extends EnumerationConverter {
+ ContextKeyToStringEnum(Enumeration sourceEnum) {
+ super(sourceEnum);
+ }
+
+ public Object nextElement() {
+ return ((ContextKey) sourceEnum.nextElement()).key;
+ }
+ }
+
+ // Field names used in HTTP message headers.
+
+ // from HTTP/1.1
+ public final String ACCEPT = "Accept"; //$NON-NLS-1$
+ public final String ACCEPT_CHARSET = "Accept-Charset"; //$NON-NLS-1$
+ public final String ACCEPT_ENCODING = "Accept-Encoding"; //$NON-NLS-1$
+ public final String ACCEPT_LANGUAGE = "Accept-Language"; //$NON-NLS-1$
+ public final String ACCEPT_RANGES = "Accept-Ranges"; //$NON-NLS-1$
+ public final String AGE = "Age"; //$NON-NLS-1$
+ public final String ALLOW = "Allow"; //$NON-NLS-1$
+ public final String AUTHORIZATION = "Authorization"; //$NON-NLS-1$
+ public final String CACHE_CONTROL = "Cache-Control"; //$NON-NLS-1$
+ public final String CONNECTION = "Connection"; //$NON-NLS-1$
+ public final String CONTENT_BASE = "Content-Base"; //$NON-NLS-1$
+ public final String CONTENT_ENCODING = "Content-Encoding"; //$NON-NLS-1$
+ public final String CONTENT_LANGUAGE = "Content-Language"; //$NON-NLS-1$
+ public final String CONTENT_LENGTH = "Content-Length"; //$NON-NLS-1$
+ public final String CONTENT_LOCATION = "Content-Location"; //$NON-NLS-1$
+ public final String CONTENT_MD5 = "Content-MD5"; //$NON-NLS-1$
+ public final String CONTENT_RANGE = "Content-Range"; //$NON-NLS-1$
+ public final String CONTENT_TYPE = "Content-Type"; //$NON-NLS-1$
+ public final String DATE = "Date"; //$NON-NLS-1$
+ public final String ETAG = "ETag"; //$NON-NLS-1$
+ public final String EXPIRES = "Expires"; //$NON-NLS-1$
+ public final String FROM = "From"; //$NON-NLS-1$
+ public final String HOST = "Host"; //$NON-NLS-1$
+ public final String IF_MODIFIED_SINCE = "If-Modified-Since"; //$NON-NLS-1$
+ public final String IF_MATCH = "If-Match"; //$NON-NLS-1$
+ public final String IF_NONE_MATCH = "If-None-Match"; //$NON-NLS-1$
+ public final String IF_RANGE = "If-Range"; //$NON-NLS-1$
+ public final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; //$NON-NLS-1$
+ public final String LAST_MODIFIED = "Last-Modified"; //$NON-NLS-1$
+ public final String LOCATION = "Location"; //$NON-NLS-1$
+ public final String MAX_FORWARDS = "Max-Forwards"; //$NON-NLS-1$
+ public final String PRAGMA = "Pragma"; //$NON-NLS-1$
+ public final String PROXY_AUTHENTICATE = "Proxy-Authenticate"; //$NON-NLS-1$
+ public final String PROXY_AUTHORIZATION = "Proxy-Authorization"; //$NON-NLS-1$
+ public final String PUBLIC = "Public"; //$NON-NLS-1$
+ public final String RANGE = "Range"; //$NON-NLS-1$
+ public final String REFERER = "Referer"; //$NON-NLS-1$
+ public final String RETRY_AFTER = "Retry-After"; //$NON-NLS-1$
+ public final String SERVER = "Server"; //$NON-NLS-1$
+ public final String TRANSFER_ENCODING = "Transfer-Encoding"; //$NON-NLS-1$
+ public final String UPGRADE = "Upgrade"; //$NON-NLS-1$
+ public final String USER_AGENT = "User-Agent"; //$NON-NLS-1$
+ public final String VARY = "Vary"; //$NON-NLS-1$
+ public final String VIA = "Via"; //$NON-NLS-1$
+ public final String WARNING = "Warning"; //$NON-NLS-1$
+ public final String WWW_AUTHENTICATE = "WWW-Authenticate"; //$NON-NLS-1$
+
+ // from WebDAV
+ public final String DAV = "DAV"; //$NON-NLS-1$
+ public final String DEPTH = "Depth"; //$NON-NLS-1$
+ public final String DESTINATION = "Destination"; //$NON-NLS-1$
+ public final String IF = "If"; //$NON-NLS-1$
+ public final String LOCK_TOKEN = "Lock-Token"; //$NON-NLS-1$
+ public final String OVERWRITE = "Overwrite"; //$NON-NLS-1$
+ public final String STATUS_URI = "Status-URI"; //$NON-NLS-1$
+ public final String TIMEOUT = "Timeout"; //$NON-NLS-1$
+
+ // from Advanced Collections
+ public final String ALL_BINDINGS = "All-Bindings"; //$NON-NLS-1$
+ public final String REF_TARGET = "Ref-Target"; //$NON-NLS-1$
+ public final String RES_TYPE = "Resource-Type"; //$NON-NLS-1$
+ public final String PASSTHROUGH = "Passthrough"; //$NON-NLS-1$
+ public final String ORDERED = "Ordered"; //$NON-NLS-1$
+ public final String POSITION = "Position"; //$NON-NLS-1$
+
+ // from Delta-V
+ public final String LABEL = "Label"; //$NON-NLS-1$
+
+ public Context() {
+ super();
+ }
+
+ /**
+ * Constructor for the class. Set the property defaults to be
+ * the given value.
+ *
+ * @param defaults the default property values for the context
+ */
+ public Context(IContext defaults) {
+ super();
+ this.defaults = defaults;
+ }
+
+ /**
+ * Copy all the default values into the receiver.
+ */
+ public void collapse() {
+ if (defaults != null) {
+ Enumeration keysEnum = defaults.keys();
+ while (keysEnum.hasMoreElements()) {
+ String key = (String) keysEnum.nextElement();
+ put(key, get(key));
+ }
+ defaults = null;
+ }
+ }
+
+ /**
+ * Return the value for the given key.
+ *
+ * @param key the key to look up
+ * @return the value for the key or null if none.
+ */
+ public String get(String key) {
+ String value = (String) properties.get(new ContextKey(key));
+ if (value == null && defaults != null)
+ return defaults.get(key);
+ return value;
+ }
+
+ /**
+ * Gets the media types that are acceptable for a response.
+ * Return the string value for the ACCEPT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT
+ * @see Context#getAccept()
+ */
+ public String getAccept() {
+ return get(ACCEPT);
+ }
+
+ /**
+ * Gets the character sets that are acceptable for a response.
+ * Return the string value for the ACCEPT_CHARSET key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT_CHARSET
+ * @see Context#getAcceptCharset()
+ */
+ public String getAcceptCharset() {
+ return get(ACCEPT_CHARSET);
+ }
+
+ /**
+ * Get what content-encoding values are acceptable for a response.
+ * Return the string value for the ACCEPT_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT_ENCODING
+ * @see Context#getAcceptEncoding()
+ */
+ public String getAcceptEncoding() {
+ return get(ACCEPT_ENCODING);
+ }
+
+ /**
+ * Get the natural languages that are acceptable for a response.
+ * Return the string value for the ACCEPT_LANGUAGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT_LANGUAGE
+ * @see Context#getAcceptLanguage()
+ */
+ public String getAcceptLanguage() {
+ return get(ACCEPT_LANGUAGE);
+ }
+
+ /**
+ * Get the range requests acceptable to a server.
+ * Return the string value for the ACCEPT_RANGES key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT_RANGES
+ * @see Context#getAcceptRanges()
+ */
+ public String getAcceptRanges() {
+ return get(ACCEPT_RANGES);
+ }
+
+ /**
+ * Get the sender's estimate of the time since the response was generated.
+ * Return the int value for the AGE key. Return -1 if the value is not set.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for AGE
+ * @see Context#getAge()
+ */
+ public int getAge() {
+ String ageString = get(AGE);
+ return (ageString == null) ? -1 : Integer.parseInt(ageString);
+ }
+
+ /**
+ * Return the string value for the ALL_BINDINGS key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ALL_BINDINGS
+ * @see Context#getAllBindings()
+ */
+ public String getAllBindings() {
+ return get(ALL_BINDINGS);
+ }
+
+ /**
+ * Gets the methods allowed on a resource
+ * Return the string value for the ALLOW key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ALLOW
+ * @see Context#getAllow()
+ */
+ public String getAllow() {
+ return get(ALLOW);
+ }
+
+ /**
+ * Get the user's credentials for the realm of the resource being requested.
+ * Return the string value for the AUTHORIZATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for AUTHORIZATION
+ * @see Context#getAuthorization()
+ */
+ public String getAuthorization() {
+ return get(AUTHORIZATION);
+ }
+
+ /**
+ * Get the cache control directives that must be obeyed.
+ * Return the string value for the CACHE_CONTROL key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CACHE_CONTROL
+ * @see Context#getCacheControl()
+ */
+ public String getCacheControl() {
+ return get(CACHE_CONTROL);
+ }
+
+ /**
+ * Get sender connection options.
+ * Return the string value for the CONNECTION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONNECTION
+ * @see Context#getConnection()
+ */
+ public String getConnection() {
+ return get(CONNECTION);
+ }
+
+ /**
+ * Return the String value for the CONTENT_BASE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_BASE
+ * @see Context#getContentBase()
+ */
+ public String getContentBase() {
+ return get(CONTENT_BASE);
+ }
+
+ /**
+ * Get what additional content encodings have been applied to the entity body.
+ * Return the string value for the CONTENT_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_ENCODING
+ * @see Context#getContentEncoding()
+ */
+ public String getContentEncoding() {
+ return get(CONTENT_ENCODING);
+ }
+
+ /**
+ * Gets the natural language of the intended audience for the entity body.
+ * Return the string value for the CONTENT_LANGUAGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_LANGUAGE
+ * @see Context#getContentLanguage()
+ */
+ public String getContentLanguage() {
+ return get(CONTENT_LANGUAGE);
+ }
+
+ /**
+ * Get the content length in bytes of the entity body.
+ * Return the value for the CONTENT_LENGTH key.
+ * Returns -1 if the Content-Length has not been set.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_LENGTH
+ * @see Context#getContentLength()
+ */
+ public long getContentLength() {
+ String lengthString = get(CONTENT_LENGTH);
+ return (lengthString == null) ? -1 : Long.parseLong(lengthString);
+ }
+
+ /**
+ * Return the String value for the CONTENT_LOCATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_LOCATION
+ * @see Context#getContentLocation()
+ */
+ public String getContentLocation() {
+ return get(CONTENT_LOCATION);
+ }
+
+ /**
+ * Return the string value for the CONTENT_MD5 key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_MD5
+ * @see Context#getContentMD5()
+ */
+ public String getContentMD5() {
+ return get(CONTENT_MD5);
+ }
+
+ /**
+ * Return the string value for the CONTENT_RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_RANGE
+ * @see Context#getContentRange()
+ */
+ public String getContentRange() {
+ return get(CONTENT_RANGE);
+ }
+
+ /**
+ * Get the MIME type for the response contents.
+ * Return the string value for the CONTENT_TYPE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for CONTENT_TYPE
+ * @see Context#getContentType()
+ */
+ public String getContentType() {
+ return get(CONTENT_TYPE);
+ }
+
+ /**
+ * The date the request was made.
+ * Return the string value for the DATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for DATE
+ * @see Context#getDate()
+ */
+ public String getDate() {
+ // TBD parse and return as a Java date
+ return get(DATE);
+ }
+
+ /**
+ * Get the DAV level supported by the server.
+ * Return the string value for the DAV key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for DAV
+ * @see Context#getDAV()
+ */
+ public String getDAV() {
+ return get(DAV);
+ }
+
+ /**
+ * Return the string value for the DEPTH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for DEPTH
+ * @see Context#getDepth()
+ */
+ public String getDepth() {
+ return get(DEPTH);
+ }
+
+ /**
+ * Get the destination URI for a copy or move operation.
+ * Return the URI value for the DESTINATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for DESTINATION
+ * @see Context#getDestination()
+ */
+ public String getDestination() {
+ return get(DESTINATION);
+ }
+
+ /**
+ * Get the entity tag for the associated entity.
+ * Return the string value for the ETAG key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ETAG
+ * @see Context#getETag()
+ */
+ public String getETag() {
+ return get(ETAG);
+ }
+
+ /**
+ * Get the date/time after which the response should be considered stale.
+ * Return the string value for the EXPIRES key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for EXPIRES
+ * @see Context#getExpires()
+ */
+ public String getExpires() {
+ // TDB : Parse and return as a date
+ return get(EXPIRES);
+ }
+
+ /**
+ * Return the string value for the FROM key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for FROM
+ * @see Context#getFrom()
+ */
+ public String getFrom() {
+ return get(FROM);
+ }
+
+ /**
+ * Get the Internet host and port of the resource being requested.
+ * Return the string value for the HOST key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for HOST
+ * @see Context#HOST
+ */
+ public String getHost() {
+ return get(HOST);
+ }
+
+ /**
+ * Return the string value for the IF key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF
+ * @see Context#getIfKey()
+ */
+ public String getIfKey() {
+ return get(IF);
+ }
+
+ /**
+ * Return the string value for the IF_MATCH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF_MATCH
+ * @see Context#getIfMatch()
+ */
+ public String getIfMatch() {
+ return get(IF_MATCH);
+ }
+
+ /**
+ * Return the string value for the IF_MODIFIED_SINCE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF_MODIFIED_SINCE
+ * @see Context#getIfModifiedSince()
+ */
+ public String getIfModifiedSince() {
+ return get(IF_MODIFIED_SINCE);
+ }
+
+ /**
+ * Return the string value for the IF_NONE_MATCH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF_NONE_MATCH
+ * @see Context#getIfNoneMatch()
+ */
+ public String getIfNoneMatch() {
+ return get(IF_NONE_MATCH);
+ }
+
+ /**
+ * Return the string value for the IF_RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF_RANGE
+ * @see Context#getIfRange()
+ */
+ public String getIfRange() {
+ return get(IF_RANGE);
+ }
+
+ /**
+ * Return the string value for the IF_UNMODIFIED_SINC key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for IF_UNMODIFIED_SINCE
+ * @see Context#getIfUnmodifiedSince()
+ */
+ public String getIfUnmodifiedSince() {
+ return get(IF_UNMODIFIED_SINCE);
+ }
+
+ /**
+ * Get the message label selector.
+ * Return the string value for the LABEL key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for LABEL
+ * @see Context#getLabel()
+ */
+ public String getLabel() {
+ return get(LABEL);
+ }
+
+ /**
+ * Get when the resource was last modified.
+ * Return the string value for the LAST_MODIFIED key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for LAST_MODIFIED
+ * @see Context#getLastModified()
+ */
+ public String getLastModified() {
+ // TDB: return as date
+ return get(LAST_MODIFIED);
+ }
+
+ /**
+ * Get the redirect location.
+ * Return the URI value for the LOCATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for LOCATION
+ * @see Context#getLocation()
+ */
+ public String getLocation() {
+ return get(LOCATION);
+ }
+
+ /**
+ * Gets the lock token for the resource, or null if it is not set.
+ * Return the lock token value for the LOCK_TOKEN key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for LOCK_TOKEN
+ * @see Context#getLockToken()
+ */
+ public String getLockToken() {
+ return get(LOCK_TOKEN);
+ }
+
+ /**
+ * Return the integer value for the MAX_FORWARDS key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for MAX_FORWARDS
+ * @see Context#getMaxForwards()
+ */
+ public int getMaxForwards() {
+ String s = get(MAX_FORWARDS);
+ return s == null ? -1 : Integer.parseInt(s);
+ }
+
+ /**
+ * Return the string value for the ORDERED key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ORDERED
+ * @see Context#getOrdered()
+ */
+ public String getOrdered() {
+ return get(ORDERED);
+ }
+
+ /**
+ * Get the flag that indicates if copy or move should overwrite
+ * an existing destination. Return the boolean value for the
+ * OVERWRITE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for OVERWRITE
+ * @see Context#OVERWRITE
+ */
+ public boolean getOverwrite() {
+ String overwriteString = get(OVERWRITE);
+ return overwriteString == null ? false : overwriteString.equalsIgnoreCase("T"); //$NON-NLS-1$
+ }
+
+ /**
+ * Return the boolean value for the PASSTHROUGH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PASSTHROUGH
+ * @see Context#getPassthrough()
+ */
+ public boolean getPassthrough() {
+ String s = get(PASSTHROUGH);
+ return s == null ? false : s.equalsIgnoreCase("T"); //$NON-NLS-1$
+ }
+
+ /**
+ * Return the string value for the POSITION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for POSITION
+ * @see Context#getPosition()
+ */
+ public String getPosition() {
+ return get(POSITION);
+ }
+
+ /**
+ * Return the string value for the PRAGMA key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PRAGMA
+ * @see Context#getPragma()
+ */
+ public String getPragma() {
+ return get(PRAGMA);
+ }
+
+ /**
+ * Get any precondition that must be true in order for method
+ * execution to be successful. A precondition corresponds to the
+ * WebDAV "If" header.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PRECONDITION
+ * @see Context#getPrecondition()
+ */
+ public String getPrecondition() {
+ return get(IF);
+ }
+
+ /**
+ * Return the string value for the PROXY_AUTHENTICATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PROXY_AUTHENTICATE
+ * @see Context#getProxyAuthenticate()
+ */
+ public String getProxyAuthenticate() {
+ return get(PROXY_AUTHENTICATE);
+ }
+
+ /**
+ * Return the string value for the PROXY_AUTHORIZATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PROXY_AUTHORIZATION
+ * @see Context#getProxyAuthorization()
+ */
+ public String getProxyAuthorization() {
+ return get(PROXY_AUTHORIZATION);
+ }
+
+ /**
+ * Return the string value for the PUBLIC_KEY key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for PUBLIC_KEY
+ * @see Context#getPublicKey()
+ */
+ public String getPublicKey() {
+ return get(PUBLIC);
+ }
+
+ /**
+ * Return the string value for the RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for RANGE
+ * @see Context#getRange()
+ */
+ public String getRange() {
+ return get(RANGE);
+ }
+
+ /**
+ * Get the URI of the resource from which the request was obtained.
+ * Return the String value for the REFERER key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for REFERER
+ * @see Context#getReferer()
+ */
+ public String getReferer() {
+ return get(REFERER);
+ }
+
+ /**
+ * Return the URI value for the REF_TARGET key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for REF_TARGET
+ * @see Context#getRefTarget()
+ */
+ public String getRefTarget() {
+ return get(REF_TARGET);
+ }
+
+ /**
+ * Return the string value for the RESOURCE_TYPE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for RESOURCE_TYPE
+ * @see Context#getResourceType()
+ */
+ public String getResourceType() {
+ return get(RES_TYPE);
+ }
+
+ /**
+ * Return the string value for the RETRY_AFTER key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for RETRY_AFTER
+ * @see Context#getRetryAfter()
+ */
+ public String getRetryAfter() {
+ return get(RETRY_AFTER);
+ }
+
+ /**
+ * Get information about the software used by the origin server
+ * to handle the request. Return the string value for the SERVER
+ * key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for SERVER
+ * @see Context#getServer()
+ */
+ public String getServer() {
+ return get(SERVER);
+ }
+
+ /**
+ * Get the String of the resource whose method is in process.
+ * Return the URI value for the STATUS_URI key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for STATUS_URI
+ * @see Context#getStatusURI()
+ */
+ public String getStatusURI() {
+ return get(STATUS_URI);
+ }
+
+ /**
+ * Get the lock timeout value. The value -1 means that the
+ * value was not set, the value -2 means that the value was "Infinity".
+ * Return the integer value for the TIMEOUT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for TIMEOUT
+ * @see Context#getTimeout()
+ */
+ public int getTimeout() {
+ String timeoutString = get(TIMEOUT);
+ if (timeoutString == null)
+ return -1;
+ if (timeoutString.equalsIgnoreCase(DEPTH_INFINITY))
+ return -2;
+ if (timeoutString.regionMatches(true, 1, "Second-", 1, 7)) //$NON-NLS-1$
+ return Integer.parseInt(timeoutString.substring(7));
+ // ignore all other cases, and use infinite timeout
+ return -2;
+ }
+
+ /**
+ * Return the string value for the TRANSFER_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for TRANSFER_ENCODING
+ * @see Context#getTransferEncoding()
+ */
+ public String getTransferEncoding() {
+ return get(TRANSFER_ENCODING);
+ }
+
+ /**
+ * Return the string value for the UPGRADE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for UPGRADE
+ * @see Context#getUpgrade()
+ */
+ public String getUpgrade() {
+ return get(UPGRADE);
+ }
+
+ /**
+ * Get information about the user agent originating the request.
+ * Return the string value for the USER_AGENT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for USER_AGENT
+ * @see Context#getUserAgent()
+ */
+ public String getUserAgent() {
+ return get(USER_AGENT);
+ }
+
+ /**
+ * Return the string value for the VARY key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for VARY
+ * @see Context#getVary()
+ */
+ public String getVary() {
+ return get(VARY);
+ }
+
+ /**
+ * Return the string value for the VIA key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for VIA
+ * @see Context#getVia()
+ */
+ public String getVia() {
+ return get(VIA);
+ }
+
+ /**
+ * Return the string value for the WARNING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for WARNING
+ * @see Context#getWarning()
+ */
+ public String getWarning() {
+ return get(WARNING);
+ }
+
+ /**
+ * Return the string value for the WWW_AUTHENTICATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for WWW_AUTHENTICATE
+ * @see Context#getWWWAuthenticate()
+ */
+ public String getWWWAuthenticate() {
+ return get(WWW_AUTHENTICATE);
+ }
+
+ /**
+ * Return an enumeration over the context's keys. (recursively computes the
+ * keys based on keys defaults as well)
+ *
+ * @return an enumeration over the context keys
+ */
+ public Enumeration keys() {
+
+ if (defaults == null)
+ return new ContextKeyToStringEnum(properties.keys());
+
+ Enumeration allKeys = new MergedEnumeration(new ContextKeyToStringEnum(properties.keys()), defaults.keys());
+
+ Hashtable keysSet = new Hashtable();
+ while (allKeys.hasMoreElements())
+ keysSet.put(allKeys.nextElement(), "ignored"); //$NON-NLS-1$
+
+ return keysSet.keys();
+ }
+
+ /**
+ * Put the given key-value pair into the context.
+ *
+ * @param key the key
+ * @param value its associated value
+ */
+ public void put(String key, String value) {
+ ContextKey ckey = new ContextKey(key);
+ if ((value == null) || (value.length() == 0))
+ properties.remove(ckey);
+ else
+ properties.put(ckey, value);
+ }
+
+ /**
+ * Remove the given key from the context
+ *
+ * @param key the key to remove
+ */
+ public void removeKey(String key) {
+ properties.remove(new ContextKey(key));
+ }
+
+ /**
+ * Set what media types are acceptable for a response.
+ * Set the string value for the ACCEPT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ACCEPT
+ * @see Context#setAccept(String)
+ */
+ public void setAccept(String value) {
+ put(ACCEPT, value);
+ }
+
+ /**
+ * Sets which character sets are acceptable for a response.
+ * Set the string value for the ACCEPT_CHARSET key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ACCEPT_CHARSET
+ * @see Context#setAcceptCharset(String)
+ */
+ public void setAcceptCharset(String value) {
+ put(ACCEPT_CHARSET, value);
+ }
+
+ /**
+ * Set the content-encoding values which are acceptable for a response.
+ * Set the string value for the ACCEPT_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ACCEPT_ENCODING
+ * @see Context#setAcceptEncoding(String)
+ */
+ public void setAcceptEncoding(String value) {
+ put(ACCEPT_ENCODING, value);
+ }
+
+ /**
+ * Get the natural languages that are acceptable for a response.
+ * Return the string value for the ACCEPT_LANGUAGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @return the value for ACCEPT_LANGUAGE
+ * @see Context#setAcceptLanguage()
+ */
+ public String setAcceptLanguage() {
+ return get(ACCEPT_LANGUAGE);
+ }
+
+ /**
+ * Set which natural languages are acceptable for a response.
+ * Set the string value for the ACCEPT_LANGUAGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ACCEPT_LANGUAGE
+ * @see Context#setAcceptLanguage(String)
+ */
+ public void setAcceptLanguage(String value) {
+ put(ACCEPT_LANGUAGE, value);
+ }
+
+ /**
+ * Set the range requests acceptable to a server.
+ * Set the string value for the ACCEPT_RANGES key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ACCEPT_RANGES
+ * @see Context#setAcceptRanges(String)
+ */
+ public void setAcceptRanges(String value) {
+ put(ACCEPT_RANGES, value);
+ }
+
+ /**
+ * Set the sender's estimate of the time since the response was generated.
+ * Set the int value for the AGE key. Set the value to -1 to remove the key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param seconds the value for AGE
+ * @see Context#setAge(int)
+ */
+ public void setAge(int seconds) {
+ put(AGE, (seconds == -1) ? "" : Integer.toString(seconds)); //$NON-NLS-1$
+ }
+
+ /**
+ * Set the string value for the ALL_BINDINGS key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for ALL_BINDINGS
+ * @see Context#setAllBindings(String)
+ */
+ public void setAllBindings(String s) {
+ put(ALL_BINDINGS, s);
+ }
+
+ /**
+ * Sets methods allowed on a resource
+ * Set the string value for the ALLOW key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ALLOW
+ * @see Context#setAllow(String)
+ */
+ public void setAllow(String value) {
+ put(ALLOW, value);
+ }
+
+ /**
+ * Set the user's credentials for the realm of the resource being requested.
+ * Set the string value for the AUTHORIZATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for AUTHORIZATION
+ * @see Context#setAuthorization(String)
+ */
+ public void setAuthorization(String value) {
+ put(AUTHORIZATION, value);
+ }
+
+ /**
+ * Set the cache control directives that must be obeyed.
+ * Set the string value for the CACHE_CONTROL key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CACHE_CONTROL
+ * @see Context#setCacheControl(String)
+ */
+ public void setCacheControl(String value) {
+ put(CACHE_CONTROL, value);
+ }
+
+ /**
+ * Set sender connection options.
+ * Set the string value for the CONNECTION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONNECTION
+ * @see Context#setConnection(String)
+ */
+ public void setConnection(String value) {
+ put(CONNECTION, value);
+ }
+
+ /**
+ * Set the String URL value for the CONTENT_BASE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param url the value for CONTENT_BASE
+ * @see Context#setContentBase(String)
+ */
+ public void setContentBase(String url) {
+ put(CONTENT_BASE, url);
+ }
+
+ /**
+ * Sets the additional content encodings that have been applied to the entity body.
+ * Set the string value for the CONTENT_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_ENCODING
+ * @see Context#setContentEncoding(String)
+ */
+ public void setContentEncoding(String value) {
+ put(CONTENT_ENCODING, value);
+ }
+
+ /**
+ * Sets the natural language of the intended audience for the entity body.
+ * Set the string value for the CONTENT_LANGUAGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_LANGUAGE
+ * @see Context#setContentLanguage(String)
+ */
+ public void setContentLanguage(String value) {
+ put(CONTENT_LANGUAGE, value);
+ }
+
+ /**
+ * Set the content length in bytes of the entity body.
+ * Set the value for the CONTENT_LENGTH key.
+ * Pass the value -1 to remove the key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_LENGTH
+ * @see Context#setContentLength(long)
+ */
+ public void setContentLength(long value) {
+ put(CONTENT_LENGTH, (value == -1) ? "" : Long.toString(value)); //$NON-NLS-1$
+ }
+
+ /**
+ * Set the String URI value for the CONTENT_LOCATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_LOCATION
+ * @see Context#setContentLocation(String)
+ */
+ public void setContentLocation(String value) {
+ put(CONTENT_LOCATION, value);
+ }
+
+ /**
+ * Set the string value for the CONTENT_MD5 key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_MD5
+ * @see Context#setContentMD5(String)
+ */
+ public void setContentMD5(String value) {
+ put(CONTENT_MD5, value);
+ }
+
+ /**
+ * Set the string value for the CONTENT_RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_RANGE
+ * @see Context#setContentRange(String)
+ */
+ public void setContentRange(String value) {
+ put(CONTENT_RANGE, value);
+ }
+
+ /**
+ * Set the MIME type for the response contents.
+ * Set the string value for the CONTENT_TYPE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for CONTENT_TYPE
+ * @see Context#setContentType(String)
+ */
+ public void setContentType(String value) {
+ put(CONTENT_TYPE, value);
+ }
+
+ /**
+ * Set the date the request was made.
+ * Set the string value for the DATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for DATE
+ * @see Context#setDate(String)
+ */
+ public void setDate(String value) {
+ put(DATE, value);
+ }
+
+ /**
+ * Set the DAV level supported by the server.
+ * Set the string value for the DAV key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for DAV
+ * @see Context#setDAV(String)
+ */
+ public void setDAV(String value) {
+ put(DAV, value);
+ }
+
+ /**
+ * Set the string value for the DEPTH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for DEPTH
+ * @see Context#setDepth(String)
+ */
+ public void setDepth(String s) {
+ put(DEPTH, s);
+ }
+
+ /**
+ * Set the destination URI for a copy or move operation.
+ * Set the URI value for the DESTINATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for DESTINATION
+ * @see Context#setDestination(String)
+ */
+ public void setDestination(String value) {
+ put(DESTINATION, value);
+ }
+
+ /**
+ * Set the entity tag for the associated entity.
+ * Set the string value for the ETAG key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ETAG
+ * @see Context#setETag(String)
+ */
+ public void setETag(String value) {
+ put(ETAG, value);
+ }
+
+ /**
+ * Set the date/time after which the response should be considered stale.
+ * Set the string value for the EXPIRES key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for EXPIRES
+ * @see Context#setExpires(String)
+ */
+ public void setExpires(String value) {
+ // TDB accept a date
+ put(EXPIRES, value);
+ }
+
+ /**
+ * Set the string value for the FROM key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for FROM
+ * @see Context#FROM
+ */
+ public void setFrom(String s) {
+ put(FROM, s);
+ }
+
+ /**
+ * Set the Internet host and port of the resource being requested.
+ * Set the string value for the HOST key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for HOST
+ * @see Context#setHost(String)
+ */
+ public void setHost(String value) {
+ put(HOST, value);
+ }
+
+ /**
+ * Set the string value for the IF key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF
+ * @see Context#setIfKey(String)
+ */
+ public void setIfKey(String s) {
+ put(IF, s);
+ }
+
+ /**
+ * Set the string value for the IF_MATCH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF_MATCH
+ * @see Context#setIfMatch(String)
+ */
+ public void setIfMatch(String s) {
+ put(IF_MATCH, s);
+ }
+
+ /**
+ * Set the string value for the IF_MODIFIED_SINCE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF_MODIFIED_SINCE
+ * @see Context#setIfModifiedSince(String)
+ */
+ public void setIfModifiedSince(String s) {
+ put(IF_MODIFIED_SINCE, s);
+ }
+
+ /**
+ * Set the string value for the IF_NONE_MATCH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF_NONE_MATCH
+ * @see Context#setIfNoneMatch(String)
+ */
+ public void setIfNoneMatch(String s) {
+ put(IF_NONE_MATCH, s);
+ }
+
+ /**
+ * Set the string value for the IF_RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF_RANGE
+ * @see Context#setIfRange(String)
+ */
+ public void setIfRange(String s) {
+ put(IF_RANGE, s);
+ }
+
+ /**
+ * Set the string value for the IF_UNMODIFIED_SINCE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for IF_UNMODIFIED_SINCE
+ * @see Context#setIfUnmodifiedSince(String)
+ */
+ public void setIfUnmodifiedSince(String s) {
+ put(IF_UNMODIFIED_SINCE, s);
+ }
+
+ /**
+ * Set the method's label selector.
+ * Set the string value for the LABEL key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for LABEL
+ * @see Context#setLabel(String)
+ */
+ public void setLabel(String value) {
+ put(LABEL, value);
+ }
+
+ /**
+ * Set when the resource was last modified.
+ * Set the string value for the LAST_MODIFIED key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for LAST_MODIFIED
+ * @see Context#setLastModified(String)
+ */
+ public void setLastModified(String value) {
+ // TDB set as a date
+ put(LAST_MODIFIED, value);
+ }
+
+ /**
+ * Sets the redirect location.
+ * Set the URI value for the LOCATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for LOCATION
+ * @see Context#LOCATION
+ */
+ public void setLocation(String value) {
+ put(LOCATION, value);
+ }
+
+ /**
+ * Set the lock token for the resource.
+ * Set the lock token value for the LOCK_TOKEN key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param token the value for LOCK_TOKEN
+ * @see Context#setLockToken(String)
+ */
+ public void setLockToken(String token) {
+ put(LOCK_TOKEN, token);
+ }
+
+ /**
+ * Set the integer value for the MAX_FORWARDS key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param i the value for MAX_FORWARDS
+ * @see Context#setMaxForwards(int)
+ */
+ public void setMaxForwards(int i) {
+ put(MAX_FORWARDS, Integer.toString(i));
+ }
+
+ /**
+ * Set the string value for the ORDERED key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for ORDERED
+ * @see Context#setOrdered(String)
+ */
+ public void setOrdered(String value) {
+ put(ORDERED, value);
+ }
+
+ /**
+ * Set if copy or move should overwrite an existing destination.
+ * Set the boolean value for the OVERWRITE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for OVERWRITE
+ * @see Context#setOverwrite(boolean)
+ */
+ public void setOverwrite(boolean value) {
+ put(OVERWRITE, value ? "T" : "F"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Set the boolean value for the PASSTHROUGH key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for PASSTHROUGH
+ * @see Context#setPassthrough(boolean)
+ */
+ public void setPassthrough(boolean value) {
+ put(PASSTHROUGH, value ? "T" : "F"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Set the string value for the POSITION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param s the value for POSITION
+ * @see Context#setPosition(String)
+ */
+ public void setPosition(String s) {
+ put(POSITION, s);
+ }
+
+ /**
+ * Set the string value for the PRAGMA key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for PRAGMA
+ * @see Context#setPragma(String)
+ */
+ public void setPragma(String value) {
+ put(PRAGMA, value);
+ }
+
+ /**
+ * Set any precondition that must be true in order for method
+ * execution to be successful. A precondition corresponds to the
+ * WebDAV "If" header.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for the precondition
+ * @see Context#setPrecondition(String)
+ */
+ public void setPrecondition(String value) {
+ put(IF, value);
+ }
+
+ /**
+ * Set the string value for the PROXY_AUTHENTICATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for PROXY_AUTHENTICATE
+ * @see Context#setProxyAuthenticate(String)
+ */
+ public void setProxyAuthenticate(String value) {
+ put(PROXY_AUTHENTICATE, value);
+ }
+
+ /**
+ * Set the string value for the PROXY_AUTHORIZATION key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for PROXY_AUTHORIZATION
+ * @see Context#setProxyAuthorization(String)
+ */
+ public void setProxyAuthorization(String value) {
+ put(PROXY_AUTHORIZATION, value);
+ }
+
+ /**
+ * Set the string value for the PUBLIC_KEY key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for PUBLIC_KEY
+ * @see Context#setPublicKey(String)
+ */
+ public void setPublicKey(String value) {
+ put(PUBLIC, value);
+ }
+
+ /**
+ * Set the string value for the RANGE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for RANGE
+ * @see Context#setRange(String)
+ */
+ public void setRange(String value) {
+ put(RANGE, value);
+ }
+
+ /**
+ * Set the URI of the resource from which the request was obtained.
+ * Set the String value for the REFERER key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for REFERER
+ * @see Context#setReferer(String)
+ */
+ public void setReferer(String value) {
+ put(REFERER, value);
+ }
+
+ /**
+ * Set the URI value for the REF_TARGET key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for REF_TARGET
+ * @see Context#setRefTarget(String)
+ */
+ public void setRefTarget(String value) {
+ put(REF_TARGET, value);
+ }
+
+ /**
+ * Set the string value for the RESOURCE_TYPE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for RESOURCE_TYPE
+ * @see Context#setResourceType(String)
+ */
+ public void setResourceType(String value) {
+ put(RES_TYPE, value);
+ }
+
+ /**
+ * Set the string value for the RETRY_AFTER key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for RETRY_AFTER
+ * @see Context#setRetryAfter(String)
+ */
+ public void setRetryAfter(String value) {
+ put(RETRY_AFTER, value);
+ }
+
+ /**
+ * Set information about the software used by the origin server
+ * to handle the request. Set the string value for the SERVER key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for SERVER
+ * @see Context#setServer(String)
+ */
+ public void setServer(String value) {
+ put(SERVER, value);
+ }
+
+ /**
+ * Set the URI of the resource whose method is in process.
+ * Set the String value for the STATUS_URI key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for STATUS_URI
+ * @see Context#setStatusURI(String)
+ */
+ public void setStatusURI(String value) {
+ put(STATUS_URI, value);
+ }
+
+ /**
+ * Set the lock timeout value in seconds. Pass -1 to clear the
+ * value, pass -2 to set "Infinity". Set the integer value for the
+ * TIMEOUT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for TIMEOUT
+ * @see Context#setTimeout(int)
+ */
+ public void setTimeout(int value) {
+ if (value == -1)
+ put(TIMEOUT, ""); //$NON-NLS-1$
+ else
+ put(TIMEOUT, (value == -2) ? DEPTH_INFINITY : "Second-" + Integer.toString(value)); //$NON-NLS-1$
+ }
+
+ /**
+ * Set the string value for the TRANSFER_ENCODING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for TRANSFER_ENCODING
+ * @see Context#setTransferEncoding(String)
+ */
+ public void setTransferEncoding(String value) {
+ put(TRANSFER_ENCODING, value);
+ }
+
+ /**
+ * Set the string value for the UPGRADE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for UPGRADE
+ * @see Context#setUpgrade(String)
+ */
+ public void setUpgrade(String value) {
+ put(UPGRADE, value);
+ }
+
+ /**
+ * Set information about the user agent originating the request.
+ * Set the string value for the USER_AGENT key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for USER_AGENT
+ * @see Context#setUserAgent(String)
+ */
+ public void setUserAgent(String value) {
+ put(USER_AGENT, value);
+ }
+
+ /**
+ * Set the string value for the VARY key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for VARY
+ * @see Context#setVary(String)
+ */
+ public void setVary(String value) {
+ put(VARY, value);
+ }
+
+ /**
+ * Set the string value for the VIA key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for VIA
+ * @see Context#setVia(String)
+ */
+ public void setVia(String value) {
+ put(VIA, value);
+ }
+
+ /**
+ * Set the string value for the WARNING key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for WARNING
+ * @see Context#setWarning(String)
+ */
+ public void setWarning(String value) {
+ put(WARNING, value);
+ }
+
+ /**
+ * Set the string value for the WWW_AUTHENTICATE key.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Context</code>.</p>
+ *
+ * @param value the value for WWW_AUTHENTICATE
+ * @see Context#setWWWAuthenticate(String)
+ */
+ public void setWWWAuthenticate(String value) {
+ put(WWW_AUTHENTICATE, value);
+ }
+
+ /**
+ * Return a string representation of the context.
+ *
+ * @return the context, as a String
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Enumeration keysEnum = keys();
+ while (keysEnum.hasMoreElements()) {
+ String key = (String) keysEnum.nextElement();
+ buffer.append(key);
+ buffer.append(": "); //$NON-NLS-1$
+ buffer.append(get(key));
+ buffer.append('\n');
+ }
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Context.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ContextFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ContextFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ContextFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.IContextFactory;
+
+public class ContextFactory implements IContextFactory {
+
+ protected IContext defaults = new Context();
+
+ public ContextFactory() {
+ super();
+ }
+
+ public IContext newContext() {
+ return new Context(defaults);
+ }
+
+ public IContext newContext(IContext baseContext) {
+ return new Context(baseContext);
+ }
+
+ /**
+ * Set the default values on the factory. All contexts created by this
+ * factory will have these defaults.
+ *
+ * @param defaultValues the default values
+ */
+ public void setDefaults(IContext defaultValues) {
+ defaults = defaultValues;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ContextFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAV4JRuntimeException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAV4JRuntimeException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAV4JRuntimeException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public class DAV4JRuntimeException extends RuntimeException {
+
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ // The wrapped exception, if one exists
+ private Throwable fWrappedException = null;
+
+ // The status code for the exception
+ private int fErrorCode = 0;
+
+ /**
+ * Create and answer a new runtime exception with the specified error code
+ * and descriptive message.
+ *
+ * @param code the error code for the exception
+ * @param message a string describing the exception
+ */
+ public DAV4JRuntimeException(int code, String message) {
+ super(message);
+ setErrorCode(code);
+ }
+
+ /**
+ * Create and answer a new runtime exception with the given
+ * descriptive message.
+ *
+ * @param message a string describing the exception
+ */
+ public DAV4JRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Create and answer a runtime exception which wraps the given
+ * exception.
+ */
+ public DAV4JRuntimeException(Throwable exception) {
+ super();
+ if (exception instanceof DAV4JRuntimeException)
+ setWrappedException(((DAV4JRuntimeException) exception).getWrappedException());
+ else
+ setWrappedException(exception);
+ }
+
+ /**
+ * Makes the same association between exception argument and error code as
+ * <code>DAV4JRuntimeException(Exception)</code>
+ *
+ * @param exception the exception to wrap
+ * @param message a string describing the exception
+ */
+ public DAV4JRuntimeException(Throwable exception, String message) {
+ super(message + "\n " + Policy.bind("label.exceptionMessage") + exception.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ setWrappedException(exception);
+ }
+
+ /**
+ * Answer the error code which is set on the receiver. If the receiver
+ * wraps a DAV4JException, then get the error code from the wrapped
+ * exception.
+ */
+ public int getErrorCode() {
+ if (getWrappedException() != null && getWrappedException() instanceof DAV4JRuntimeException)
+ return ((DAV4JRuntimeException) getWrappedException()).getErrorCode();
+ return fErrorCode;
+ }
+
+ /**
+ * Answer the receiver's field which holds onto the exception
+ * which the receiver wraps.
+ *
+ * @return the wrapped exception
+ */
+ public Throwable getWrappedException() {
+ return fWrappedException;
+ }
+
+ /**
+ * If the receiver wraps an exception, then ask the exception to
+ * print out a stack trace to the system output.
+ */
+ public void printStackTrace() {
+ Throwable wrappedException = getWrappedException();
+ if (wrappedException != null)
+ wrappedException.printStackTrace();
+ else
+ super.printStackTrace();
+ }
+
+ /**
+ * Set the receiver's field which holds onto the error code.
+ *
+ * @param errorCode the error code for the exception
+ */
+ protected void setErrorCode(int errorCode) {
+ fErrorCode = errorCode;
+ }
+
+ /**
+ * Set the receiver's field which holds onto the wrapped exception.
+ *
+ * @param exception the exception to be wrapped
+ */
+ protected void setWrappedException(Throwable exception) {
+ fWrappedException = exception;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAV4JRuntimeException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public class DAVException extends Exception {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * DAV4JException default constructor.
+ */
+ public DAVException() {
+ super();
+ }
+
+ public DAVException(String s) {
+ super(s);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVRuntimeException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVRuntimeException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVRuntimeException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public class DAVRuntimeException extends RuntimeException {
+
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ // The wrapped exception, if one exists
+ private Throwable fWrappedException = null;
+
+ // The status code for the exception
+ private int fErrorCode = 0;
+
+ /**
+ * Create and answer a new runtime exception with the specified error code
+ * and descriptive message.
+ *
+ * @param code the error code for the exception
+ * @param message a string describing the exception
+ */
+ public DAVRuntimeException(int code, String message) {
+ super(message);
+ setErrorCode(code);
+ }
+
+ /**
+ * Create and answer a new runtime exception with the given
+ * descriptive message.
+ *
+ * @param message a string describing the exception
+ */
+ public DAVRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Create and answer a runtime exception which wraps the given
+ * exception.
+ */
+ public DAVRuntimeException(Throwable exception) {
+ super();
+ if (exception instanceof DAVRuntimeException)
+ setWrappedException(((DAVRuntimeException) exception).getWrappedException());
+ else
+ setWrappedException(exception);
+ }
+
+ /**
+ * Makes the same association between exception argument and error code as
+ * <code>DAVRuntimeException(Exception)</code>
+ *
+ * @param exception the exception to wrap
+ * @param message a string describing the exception
+ */
+ public DAVRuntimeException(Throwable exception, String message) {
+ super(message + "\n " + Policy.bind("label.exceptionMessage") + exception.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ setWrappedException(exception);
+ }
+
+ /**
+ * Answer the error code which is set on the receiver. If the receiver
+ * wraps a DAV4JException, then get the error code from the wrapped
+ * exception.
+ */
+ public int getErrorCode() {
+ if (getWrappedException() != null && getWrappedException() instanceof DAVRuntimeException)
+ return ((DAVRuntimeException) getWrappedException()).getErrorCode();
+ return fErrorCode;
+ }
+
+ /**
+ * Answer the receiver's field which holds onto the exception
+ * which the receiver wraps.
+ *
+ * @return the wrapped exception
+ */
+ public Throwable getWrappedException() {
+ return fWrappedException;
+ }
+
+ /**
+ * If the receiver wraps an exception, then ask the exception to
+ * print out a stack trace to the system output.
+ */
+ public void printStackTrace() {
+ Throwable wrappedException = getWrappedException();
+ if (wrappedException != null)
+ wrappedException.printStackTrace();
+ else
+ super.printStackTrace();
+ }
+
+ /**
+ * Set the receiver's field which holds onto the error code.
+ *
+ * @param errorCode the error code for the exception
+ */
+ protected void setErrorCode(int errorCode) {
+ fErrorCode = errorCode;
+ }
+
+ /**
+ * Set the receiver's field which holds onto the wrapped exception.
+ *
+ * @param exception the exception to be wrapped
+ */
+ protected void setWrappedException(Throwable exception) {
+ fWrappedException = exception;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DAVRuntimeException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import javax.xml.parsers.*;
+import org.w3c.dom.Document;
+
+public class DocumentFactory implements IDocumentFactory {
+
+ DocumentBuilder builder = null;
+
+ public Document newDocument() {
+ if (builder == null) {
+ try {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (FactoryConfigurationError e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return builder.newDocument();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentMarshaler.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentMarshaler.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentMarshaler.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.*;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class DocumentMarshaler implements IDocumentMarshaler {
+
+ public Document parse(Reader reader) throws IOException {
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ return parser.parse(new InputSource(reader));
+ } catch (ParserConfigurationException e) {
+ throw new IOException(e.getMessage());
+ } catch (SAXException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public void print(Document document, Writer writer, String encoding) throws IOException {
+ Transformer transformer = null;
+ try {
+ transformer = TransformerFactory.newInstance().newTransformer();
+ } catch (TransformerConfigurationException e) {
+ throw new IOException(e.getMessageAndLocation());
+ } catch (TransformerFactoryConfigurationError e) {
+ throw new IOException(e.getMessage());
+ }
+ DOMSource source = new DOMSource(document);
+ StreamResult result = new StreamResult(writer);
+ try {
+ transformer.transform(source, result);
+ } catch (TransformerException e) {
+ throw new IOException(e.getMessageAndLocation());
+ }
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/DocumentMarshaler.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ElementHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ElementHelper.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ElementHelper.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.util.Enumeration;
+import org.eclipse.webdav.dom.QualifiedName;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.w3c.dom.*;
+
+public class ElementHelper implements WebDAVConstants {
+
+ // This W3C Document is the factory for Nodes
+ // produced by this class.
+ protected Document nodeFactory;
+
+ protected final static String DAV_PREFIX = "D"; //$NON-NLS-1$
+ protected final static String NS_SEPARATOR = ":"; //$NON-NLS-1$
+ protected final static String DAV_NS_ATTRIB = "xmlns" + NS_SEPARATOR + DAV_PREFIX; //$NON-NLS-1$
+
+ public ElementHelper() {
+ super();
+ IDocumentFactory factory = new DocumentFactory();
+ this.nodeFactory = factory.newDocument();
+ }
+
+ public String extractText(Element element) {
+ NodeList childNodes = element.getChildNodes();
+ Assert.isTrue(childNodes.getLength() == 1, Policy.bind("error.requireElementWithSingleChild")); //$NON-NLS-1$
+ Node child = childNodes.item(0);
+ Assert.isTrue(child instanceof Text, Policy.bind("error.extractFromElementWithoutText")); //$NON-NLS-1$
+ return ((Text) child).getData();
+ }
+
+ public Element newDAVElement(QualifiedName name) {
+ Assert.isTrue(name.getQualifier().equals(DAV_URI), Policy.bind("error.davElementsNeedQualifier")); //$NON-NLS-1$
+ Element element = nodeFactory.createElement(DAV_PREFIX + NS_SEPARATOR + name.getLocalName());
+ element.setAttribute(DAV_NS_ATTRIB, DAV_URI);
+ return element;
+ }
+
+ /**
+ * Answer a DOM <code>Element</code> that represents a set of <code>String</code>.
+ * <p>
+ * The set is represented by a single <code>Element</code> whose name is
+ * given as the <code>setName</code> argument. Each member of the set is
+ * a child <code>Element</code> named <code>memberName</code> that has
+ * text taken from the <code>memberEnum</code> an <code>Enumeration</code>
+ * of <code>String</code>.
+ */
+ public Element newDAVElementSet(QualifiedName setName, QualifiedName memberName, Enumeration memberEnum) {
+ Element setElement = newDAVElement(setName);
+ while (memberEnum.hasMoreElements()) {
+ String member = (String) memberEnum.nextElement();
+ Element memberElement = newDAVTextElement(memberName, member);
+ setElement.appendChild(memberElement);
+ }
+ return setElement;
+ }
+
+ public Element newDAVProperty(QualifiedName name, String value) {
+ Element element = newDAVElement(name);
+ element.appendChild(nodeFactory.createTextNode(value));
+ return element;
+ }
+
+ public Element newDAVProperty(QualifiedName name, Element value) {
+ Element element = newDAVElement(name);
+ element.appendChild(value);
+ return element;
+ }
+
+ public Element newDAVTextElement(QualifiedName name, String value) {
+ Element element = newDAVElement(name);
+ element.appendChild(nodeFactory.createTextNode(value));
+ return element;
+ }
+
+ public Element newTextElement(String name, String value) {
+ Element element = nodeFactory.createElement(name);
+ element.appendChild(nodeFactory.createTextNode(value));
+ return element;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ElementHelper.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/EntityTag.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/EntityTag.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/EntityTag.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * An EntityTag is a ConditionFactor describing some state of a resource represented
+ * as an opaque string. See section 3.11 of the HTTP/1.1 spec.
+ */
+public class EntityTag extends ConditionFactor {
+
+ private static int bcnt = 0;
+ private static String basetime = Long.toHexString(new java.util.Date().getTime());
+
+ private String eTag = null;
+ // represents some state of a resource expressed as a ETag
+ private boolean weak = false;
+
+ /**
+ * Construct a EntityTag. Should never be called.
+ */
+ private EntityTag() {
+ super();
+ }
+
+ /**
+ * Construct a EntityTag with the given opaque string tag.
+ *
+ * @param tag the opaque string defining the entity tag
+ */
+ public EntityTag(String tag) {
+ this.eTag = tag;
+ }
+
+ /**
+ * Create an EntityTag by parsing the given If header as defined by
+ * section 3.11 of the HTTP/1.1 spec.
+ *
+ * @param tokenizer a StreamTokenizer on the contents of a WebDAV If header
+ * @return the parsed ConditionFactor (EntityTag)
+ * @exception WebDAVException thrown if there is a syntax error in the If header
+ */
+ public static ConditionFactor create(StreamTokenizer tokenizer) throws WebDAVException {
+ EntityTag entityTag = new EntityTag();
+ try {
+ int token = tokenizer.ttype;
+ if (token == '[')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "[")); //$NON-NLS-1$ //$NON-NLS-2$
+ if (token == '"') { //$NON-NLS-1$
+ entityTag.setETag(tokenizer.sval);
+ token = tokenizer.nextToken();
+ } else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingQuotedString", String.valueOf(token))); //$NON-NLS-1$
+ if (token == ']')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "]")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ return entityTag;
+ }
+
+ /**
+ * Compare with another EntityTag.
+ *
+ * @param etag the entity tag to compare
+ * @return true if the tags are equal, false otherwise
+ */
+ public boolean equals(Object etag) {
+ return etag != null && etag instanceof EntityTag && getETag().equals(((EntityTag) etag).getETag());
+ }
+
+ /**
+ * Construct a unique EntityTag. The tag is constructed by concatening the
+ * current time with the current thread's hash code.
+ *
+ * @return a unique entity tag that servers may use for any purpose
+ */
+ public static EntityTag generateEntityTag() {
+ String xx = basetime + ":" + Integer.toHexString(Thread.currentThread().hashCode()); //$NON-NLS-1$
+ bcnt++;
+ xx += ":" + bcnt; //$NON-NLS-1$
+ return new EntityTag(xx);
+ }
+
+ /**
+ * Get the ETag of this EntityTag. The ETag represents some state of the
+ * resource in the containing Condition.
+ *
+ * @return the etag
+ */
+ public String getETag() {
+ return eTag;
+ }
+
+ /**
+ * Is this a weak EntityTag?
+ *
+ * @return true if this is a weak entity tag
+ */
+ public boolean isWeak() {
+ return weak;
+ }
+
+ /**
+ * Set the ETag of this EntityTag. The ETag represents some state of the
+ * resource in the containing Condition, for example, the lock token.
+ *
+ * @value the etag to set
+ */
+ public void setETag(String value) {
+ eTag = value;
+ }
+
+ /**
+ * Set the strength of this EntityTag.
+ * value true indicates this is a weak entity tag
+ */
+ public void setWeak(boolean value) {
+ weak = value;
+ }
+
+ /**
+ * Return a String representation of this EntityTag as defined by the If
+ * header in section 9.4 of the WebDAV spec.
+ *
+ * @return a string representation of this entity tag
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (not())
+ buffer.append("Not "); //$NON-NLS-1$
+ if (isWeak())
+ buffer.append("W/"); //$NON-NLS-1$
+ buffer.append("[\""); //$NON-NLS-1$
+ buffer.append(getETag());
+ buffer.append("\"]"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/EntityTag.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.w3c.dom.Document;
+
+public interface IDocumentFactory {
+
+ public Document newDocument();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentMarshaler.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentMarshaler.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentMarshaler.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.*;
+import org.w3c.dom.Document;
+
+public interface IDocumentMarshaler {
+
+ public Document parse(Reader reader) throws IOException;
+
+ // Write out the give document to the writer.
+ // The writer's encoding scheme is given.
+ public void print(Document document, Writer writer, String encoding) throws IOException;
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/IDocumentMarshaler.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/InvalidPropertyNameException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/InvalidPropertyNameException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/InvalidPropertyNameException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+/**
+ * When thrown, this class signals that the property name
+ * string provided was not legal based on the definition
+ * provided in the documentation of the PropertyName(String)
+ * constructor.
+ */
+public class InvalidPropertyNameException extends Exception {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an InvalidPropertyNameException object.
+ */
+ public InvalidPropertyNameException() {
+ super("InvalidPropertyName"); //$NON-NLS-1$
+ }
+
+ /**
+ * InvalidPropertyNameException constructor comment.
+ * @param statusMessage a message describing the exception of status code
+ */
+ public InvalidPropertyNameException(String statusMessage) {
+ super(statusMessage);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/InvalidPropertyNameException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Locator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Locator.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Locator.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.ILocator;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * A <code>LocatorImpl</code> uniquely identifies a DAV
+ * a resource.
+ * <p>
+ * This class implements the <code>Locator</code>
+ * interface.</p>
+ *
+ * @see Locator
+ */
+public class Locator implements ILocator {
+
+ protected String resourceURL;
+ protected String label;
+ protected boolean isStable;
+
+ public Locator(String resourceURL, String label) {
+ super();
+ Assert.isLegal(resourceURL != null);
+ this.resourceURL = resourceURL;
+ this.label = label;
+ this.isStable = false;
+ }
+
+ /**
+ * Return a boolean value indicating whether or not this locator
+ * and the given object are equal.
+ *
+ * @param obj the object to compare against
+ * @return equality indicator
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof ILocator))
+ return false;
+ ILocator locator = (ILocator) obj;
+ if (!resourceURL.equals(locator.getResourceURL()))
+ return false;
+ if (label == null)
+ return locator.getLabel() == null;
+ return label.equals(locator.getLabel());
+ }
+
+ public int hashCode() {
+ return resourceURL.hashCode();
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getResourceURL() {
+ return resourceURL;
+ }
+
+ public boolean isStable() {
+ return isStable;
+ }
+
+ public void markStable() {
+ // Stable URLs cannot not have a label.
+ Assert.isTrue(label == null);
+ isStable = true;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("[Locator "); //$NON-NLS-1$
+ buffer.append(resourceURL);
+ if (label != null) {
+ buffer.append("\n label: "); //$NON-NLS-1$
+ buffer.append(label);
+ }
+ if (isStable)
+ buffer.append("\n stable"); //$NON-NLS-1$
+ buffer.append("]"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Locator.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LocatorFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LocatorFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LocatorFactory.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.ILocator;
+import org.eclipse.webdav.ILocatorFactory;
+
+public class LocatorFactory implements ILocatorFactory {
+
+ public LocatorFactory() {
+ super();
+ }
+
+ public ILocator newLocator(String resourceURL) {
+ return new Locator(resourceURL, null);
+ }
+
+ /**
+ * @deprecated -- not really deprecated, just a warning
+ * the second argument used to be the workspace URL but
+ * is now a version label!
+ * @deprecated
+ */
+ public ILocator newLocator(String resourceURL, String label) {
+ return new Locator(resourceURL, label);
+ }
+
+ public ILocator newStableLocator(String resourceURL) {
+ Locator locator = new Locator(resourceURL, null);
+ locator.markStable();
+ return locator;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LocatorFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LockToken.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LockToken.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LockToken.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public class LockToken {
+
+ private String fToken = null;
+
+ public LockToken(String token) {
+ fToken = token;
+ }
+
+ public String getToken() {
+ return fToken;
+ }
+
+ public void setToken(String token) {
+ fToken = token;
+ }
+
+ public String toString() {
+ return fToken;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/LockToken.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Message.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Message.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Message.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.IContext;
+
+/**
+ * The <code>Message</code> class represents a basic message
+ * that has a context and a body.
+ */
+public class Message {
+
+ protected IContext context = new ContextFactory().newContext();
+
+ // The message body. Can be either an Element, an InputStream
+ protected Object body;
+
+ /**
+ * Default constructor for the class.
+ */
+ public Message() {
+ super();
+ }
+
+ /**
+ * Return the message body.
+ */
+ public Object getBody() {
+ return body;
+ }
+
+ /**
+ * Return the message context.
+ *
+ * @return the message context.
+ * @see Context
+ */
+ public IContext getContext() {
+ return context;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Message.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Policy.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Policy.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Policy.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.text.MessageFormat;
+import java.util.*;
+
+public class Policy {
+ private static final String bundleName = "org.eclipse.webdav.internal.kernel.messages";//$NON-NLS-1$
+ private static ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+
+ /**
+ * Lookup the message with the given ID in this catalog
+ */
+ public static String bind(String id) {
+ return bind(id, (String[]) null);
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string.
+ */
+ public static String bind(String id, String binding) {
+ return bind(id, new String[] {binding});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given strings.
+ */
+ public static String bind(String id, String binding1, String binding2) {
+ return bind(id, new String[] {binding1, binding2});
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string values.
+ */
+ public static String bind(String id, String[] bindings) {
+ if (id == null)
+ return "No message available";//$NON-NLS-1$
+ String message = null;
+ try {
+ message = bundle.getString(id);
+ } catch (MissingResourceException e) {
+ // If we got an exception looking for the message, fail gracefully by just returning
+ // the id we were looking for. In most cases this is semi-informative so is not too bad.
+ return "Missing message: " + id + " in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (bindings == null)
+ return message;
+ return MessageFormat.format(message, bindings);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Policy.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Precondition.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Precondition.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Precondition.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Vector;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * A Precondition represents some condition or collection of conditions
+ * representing states of a resource. If the state of the resource does not
+ * match any of the specified states in any of the conditions, then the
+ * method must fail. Conditions in a Precondition are OR'd together while
+ * ConditionFactors in a ConditionTerm are AND'ed.
+ */
+public class Precondition {
+
+ private Vector conditions = new Vector();
+
+ /**
+ * Construct an empty Precondition. The client must add Conditions.
+ */
+ public Precondition() {
+ super();
+ }
+
+ /**
+ * Construct a Precondition by parsing the given If header as defined by
+ * section 8.4 in the WebDAV spec.
+ *
+ * @param ifHeader the contents of a WebDAV If header
+ */
+ public Precondition(String ifHeader) throws WebDAVException {
+ StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(ifHeader));
+ // URI characters
+ tokenizer.wordChars('!', '/');
+ tokenizer.wordChars(':', '@');
+ tokenizer.ordinaryChar('(');
+ tokenizer.ordinaryChar(')');
+ tokenizer.ordinaryChar('<');
+ tokenizer.ordinaryChar('>');
+ tokenizer.ordinaryChar('[');
+ tokenizer.ordinaryChar(']');
+ tokenizer.quoteChar('"');
+ int token = 0;
+ try {
+ token = tokenizer.nextToken();
+ switch (token) {
+ case '<' :
+ while (token == '<') {
+ addCondition(Condition.create(tokenizer));
+ token = tokenizer.ttype;
+ }
+ break;
+ case '(' :
+ while (token == '(') {
+ addCondition(Condition.create(tokenizer));
+ token = tokenizer.ttype;
+ }
+ break;
+ }
+ if (token != StreamTokenizer.TT_EOF)
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "EOF")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (!getConditions().hasMoreElements())
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseEmptyList", ifHeader)); //$NON-NLS-1$
+
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ }
+
+ /**
+ * Add a Condition to this Precondition. Conditions are OR'd together to
+ * check for a matching resource.
+ *
+ * @param condition the Condition to add
+ * @exception WebDAVException thrown if the precondition already contains this condition
+ */
+ public void addCondition(Condition condition) throws WebDAVException {
+ // a Resource URI can only be specified once in a Precondition
+ Enumeration conditions = getConditions();
+ if (condition.getResourceURI() != null) {
+ while (conditions.hasMoreElements()) {
+ Condition existingCondition = (Condition) conditions.nextElement();
+ if (existingCondition.getResourceURI() != null && existingCondition.getResourceURI().equals(condition.getResourceURI()))
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMultipleSpecification", condition.getResourceURI())); //$NON-NLS-1$
+ }
+ }
+ this.conditions.addElement(condition);
+ }
+
+ /**
+ * Add a condition created from the given URI and state token. This is a
+ * convenience method used primarily to create preconditions for lock tokens
+ * that must be provided in the resource context for methods that update
+ * the resource.
+ *
+ * @param resourceURI the URI of the resource the state token applies to. Null
+ * implicitly specifies the resource processing the request
+ * @param stateToken the state token to match
+ */
+ public void addStateTokenCondition(String resourceURI, String stateToken) throws WebDAVException {
+ Condition condition = new Condition(resourceURI);
+ ConditionTerm term = new ConditionTerm();
+ term.addConditionFactor(new StateToken(stateToken));
+ condition.addConditionTerm(term);
+ addCondition(condition);
+ }
+
+ /**
+ * Construct a Precondition by parsing the given If header as defined by
+ * section 9.4 in the WebDAV spec.
+ *
+ * @param ifHeader the contents of a WebDAV If header
+ * @return the parser If header
+ * @exception WebDAVException thrown if there is a syntax error in the If header
+ */
+ public static Precondition create(String ifHeader) throws WebDAVException {
+ return new Precondition(ifHeader);
+ }
+
+ /**
+ * Get the Conditions contained in this Precondition. At least one must match
+ * in order for a valid match to occur.
+ *
+ * @return an Enumeration of Conditions
+ */
+ public Enumeration getConditions() {
+ return conditions.elements();
+ }
+
+ /**
+ * See if this Precondition contains a matching Condition.
+ *
+ * @param condition the condition to match
+ * @return true if this precondition contains atleast one condition matching the given condition
+ */
+ public boolean matches(Condition condition) {
+ boolean match = false;
+ Enumeration conditions = getConditions();
+ while (!match && conditions.hasMoreElements()) {
+ Condition existingCondition = (Condition) conditions.nextElement();
+ match = existingCondition.matches(condition);
+ }
+ return match;
+ }
+
+ /**
+ * Return a String representation of this Precondition as defined by section 9.4
+ * of the WebDAV Spec. The string is the value of an If header.
+ *
+ * @return a string representation of this precondition
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Enumeration conditions = getConditions();
+ while (conditions.hasMoreElements()) {
+ Condition condition = (Condition) conditions.nextElement();
+ buffer.append(condition.toString());
+ if (conditions.hasMoreElements())
+ buffer.append(' ');
+ }
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Precondition.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/QualifiedNameImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/QualifiedNameImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/QualifiedNameImpl.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.dom.QualifiedName;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+
+/**
+ * Qualified names are two-part names: qualifier and local name.
+ * The qualifier must be in URI form (see RFC2396).
+ * Note however that the qualifier may be <code>null</code> if
+ * the default name space is being used. The empty space is
+ * not a valid qualifier.
+ */
+public class QualifiedNameImpl implements QualifiedName {
+
+ /** Qualifier part (potentially <code>null</code>). */
+ protected String qualifier = null;
+
+ /** Local name part. */
+ protected String localName = null;
+
+ /**
+ * Creates and returns a new qualified name with the given qualifier
+ * and local name. The local name must not be the empty string.
+ * The qualifier may be <code>null</code>.
+ */
+ public QualifiedNameImpl(String qualifier, String localName) {
+ Assert.isLegal(localName != null && localName.length() != 0);
+ this.qualifier = qualifier;
+ this.localName = localName;
+ }
+
+ /**
+ * Returns <code>true</code> if this qualified name is equivalent to the given object.
+ * <p>
+ * Qualified names are equal if and only if they have the same
+ * qualified parts and local parts.
+ * Qualified names are not equal to objects other than qualified names.
+ *
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (!(obj instanceof QualifiedName))
+ return false;
+ // There may or may not be a qualifier.
+ QualifiedName qName = (QualifiedName) obj;
+ if (qualifier == null && qName.getQualifier() != null)
+ return false;
+ if (qualifier != null && !qualifier.equals(qName.getQualifier()))
+ return false;
+ return localName.equals(qName.getLocalName());
+ }
+
+ /**
+ * Returns the local part of this name.
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * Returns the qualifier part for this qualifed name, or <code>null</code>
+ * if none.
+ */
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ /**
+ * Returns the hash code for this qualified name.
+ */
+ public int hashCode() {
+ return (qualifier == null ? 0 : qualifier.hashCode()) + localName.hashCode();
+ }
+
+ /**
+ * Converts this qualified name into a string, suitable for
+ * display (unsuitable for parsing back to a qualified name!).
+ */
+ public String toString() {
+ return "Namespace: \"" + //$NON-NLS-1$
+ (getQualifier() == null ? "null" : getQualifier()) + //$NON-NLS-1$
+ "\", Local part: \"" + //$NON-NLS-1$ //$NON-NLS-2$
+ getLocalName() + "\""; //$NON-NLS-1$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/QualifiedNameImpl.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/RedirectionException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/RedirectionException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/RedirectionException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+/** Represents exceptions that require further action by the user agent
+ * in order to fulfill the request.
+ * <p>
+ * Status codes:
+ * <ul>
+ * <li>300 Multiple Choices</li>
+ * <li>301 Moved Permanently</li>
+ * <li>302 Moved Temporarily</li>
+ * <li>303 See Other</li>
+ * <li>304 Not Modified</li>
+ * <li>305 Use Proxy</li>
+ * </ul>
+ * </p>
+ */
+public class RedirectionException extends WebDAVException {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct a RedirectionException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public RedirectionException(int statusCode, String statusMessage) {
+ super(statusCode, statusMessage);
+ }
+
+ /**
+ * Construct a RedirectionException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public RedirectionException(int statusCode, String statusMessage, Object data) {
+ super(statusCode, statusMessage, data);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/RedirectionException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Response.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Response.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Response.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.*;
+import org.eclipse.webdav.IContext;
+import org.eclipse.webdav.IResponse;
+import org.eclipse.webdav.internal.kernel.utils.Assert;
+import org.w3c.dom.Document;
+
+/**
+ * The <code>Response</code> class subclasses <code>Message</code> to
+ * add a status field.
+ */
+public class Response extends Message implements IResponse {
+
+ protected Status status;
+
+ public Response(Status status, IContext context, InputStream body) {
+ super();
+ this.status = status;
+ this.context = context;
+ this.body = body;
+ }
+
+ public Response(Status status, IContext context, Document body) {
+ super();
+ this.status = status;
+ this.context = context;
+ this.body = body;
+ }
+
+ public void close() throws IOException {
+ if (!hasDocumentBody())
+ getInputStream().close();
+ }
+
+ public Document getDocumentBody() throws IOException {
+ Assert.isTrue(hasDocumentBody(), Policy.bind("error.receiverMissingBody")); //$NON-NLS-1$
+ return (Document) body;
+ }
+
+ public InputStream getInputStream() {
+ Assert.isTrue(!hasDocumentBody(), Policy.bind("error.receiverHasBody")); //$NON-NLS-1$
+ return (InputStream) body;
+ }
+
+ /**
+ * Return the status code for this response.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Response</code>.</p>
+ *
+ * @return the status code
+ * @see Response#getStatusCode()
+ */
+ public int getStatusCode() {
+ return status.getCode();
+ }
+
+ /**
+ * Return the status message for this response.
+ *
+ * <p>Implements the corresponding API in the interface
+ * <code>Response</code>.</p>
+ *
+ * @return the status message
+ * @see Response#getStatusMessage()
+ */
+ public String getStatusMessage() {
+ return status.getMessage();
+ }
+
+ public boolean hasDocumentBody() {
+ return (body instanceof Document);
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(status.toHTTPString());
+ buffer.append('\n');
+ buffer.append(context.toString());
+ buffer.append('\n');
+ try {
+ if (hasDocumentBody()) {
+ IDocumentMarshaler marshaler = new DocumentMarshaler();
+ Writer writer = new StringWriter();
+ marshaler.print(getDocumentBody(), writer, "UTF-8"); //$NON-NLS-1$
+ buffer.append(writer.toString());
+ } else
+ buffer.append("<<" //$NON-NLS-1$
+ + Policy.bind("label.bytes", String.valueOf(getInputStream().available())) //$NON-NLS-1$
+ + ">>"); //$NON-NLS-1$
+ } catch (IOException e) {
+ buffer.append("<<" + Policy.bind("exception.dumping", e.getMessage()) + ">>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Response.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ServerException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ServerException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ServerException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+/** Represents exceptions that can happen on the server as the
+ * result of a server error.
+ * <p>
+ * Status codes:
+ * <ul>
+ * <li>500 Internal Server Error</li>
+ * <li>501 Not Implemented</li>
+ * <li>502 Bad Gateway</li>
+ * <li>503 Service Unavailable</li>
+ * <li>504 Gateway Timeout</li>
+ * <li>505 HTTP Version Not Supported</li>
+ * </ul>
+ * </p>
+ */
+public class ServerException extends WebDAVException {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct a ServerException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public ServerException(int statusCode, String statusMessage) {
+ super(statusCode, statusMessage);
+ }
+
+ /**
+ * Construct a ServerException with a status code and simple message.
+ *
+ * @param statusCode the WebDAV status code corresponding to the exception
+ * @param statusMessage a message describing the status code in the context of the exception
+ */
+ public ServerException(int statusCode, String statusMessage, Object data) {
+ super(statusCode, statusMessage, data);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/ServerException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/StateToken.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/StateToken.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/StateToken.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import org.eclipse.webdav.IResponse;
+
+/**
+ * A StateToken is a ConditionFactor describing some state of a resource represented
+ * as a URI. A typical example would be the WebDAV lock token.
+ */
+public class StateToken extends ConditionFactor {
+
+ private String uri = null;
+
+ // represents some state of a resource expressed as a URI
+
+ /**
+ * Construct a StateToken. Should never be called.
+ */
+ private StateToken() {
+ super();
+ }
+
+ /**
+ * Construct a StateToken with the given URI.
+ *
+ * @param uri the URI of the state token
+ */
+ public StateToken(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Create a StateToken by parsing the given If header as defined by
+ * section 9.4 in the WebDAV spec.
+ *
+ * @param tokenizer a StreamTokenizer on the contents of a WebDAV If header
+ * @return the parsed ConditionFactor (StateToken)
+ */
+ public static ConditionFactor create(StreamTokenizer tokenizer) throws WebDAVException {
+ StateToken stateToken = new StateToken();
+ try {
+ int token = tokenizer.ttype;
+ if (token == '<')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), "<")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (token == StreamTokenizer.TT_WORD) {
+ stateToken.setURI(tokenizer.sval);
+ token = tokenizer.nextToken();
+ } else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissingURI", String.valueOf(token))); //$NON-NLS-1$
+
+ if (token == '>')
+ token = tokenizer.nextToken();
+ else
+ throw new WebDAVException(IResponse.SC_BAD_REQUEST, Policy.bind("error.parseMissing", String.valueOf(token), ">")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (IOException exc) {
+ // ignore or log?
+ }
+ return stateToken;
+ }
+
+ /**
+ * Compare with another StateToken.
+ *
+ * @param factor the state token to compare with
+ * @return true if this state token has the same URI as the factor
+ */
+ public boolean equals(Object factor) {
+ return factor != null && factor instanceof StateToken && getURI().equals(((StateToken) factor).getURI());
+ }
+
+ /**
+ * Get the URI of this StateToken. The URI represents some state of the
+ * resource in the containing Condition, for example, the lock token.
+ *
+ * @return the URI for this state token
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * Set the URI of this StateToken. The URI represents some state of the
+ * resource in the containing Condition, for example, the lock token.
+ *
+ * @param value the URI for this state token
+ */
+ public void setURI(String value) {
+ uri = value;
+ }
+
+ /**
+ * Return a String representation of this StateToken as defined by the If
+ * header in section 9.4 of the WebDAV spec.
+ *
+ * @return a string representation of this state token
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (not())
+ buffer.append("Not "); //$NON-NLS-1$
+ buffer.append('<');
+ buffer.append(getURI());
+ buffer.append('>');
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/StateToken.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Status.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Status.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Status.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.IResponse;
+import org.w3c.dom.Document;
+
+public class Status implements Cloneable {
+
+ // Instance fields all set during instance creation.
+
+ protected int code;
+ protected String message;
+ protected Document extendedStatus;
+
+ /* Static fields -- Predefined status messages. */
+
+ // 100-series
+ public final static Status CONTINUE = new Status(IResponse.SC_CONTINUE, "Continue"); //$NON-NLS-1$
+ public final static Status SWITCHING_PROTOCOLS = new Status(IResponse.SC_SWITCHING_PROTOCOLS, "Switching Protocols"); //$NON-NLS-1$
+ public final static Status PROCESSING = new Status(IResponse.SC_PROCESSING, "Processing"); //$NON-NLS-1$
+
+ // 200-series
+ public final static Status OK = new Status(IResponse.SC_OK, "OK"); //$NON-NLS-1$
+ public final static Status CREATED = new Status(IResponse.SC_CREATED, "Created"); //$NON-NLS-1$
+ public final static Status ACCEPTED = new Status(IResponse.SC_ACCEPTED, "Accepted"); //$NON-NLS-1$
+ public final static Status NON_AUTHORITATIVE_INFORMATION = new Status(IResponse.SC_NON_AUTHORITATIVE_INFORMATION, "Non Authoritative Information"); //$NON-NLS-1$
+ public final static Status NO_CONTENT = new Status(IResponse.SC_NO_CONTENT, "No Content"); //$NON-NLS-1$
+ public final static Status RESET_CONTENT = new Status(IResponse.SC_RESET_CONTENT, "Reset Content"); //$NON-NLS-1$
+ public final static Status PARTIAL_CONTENT = new Status(IResponse.SC_PARTIAL_CONTENT, "Partial Content"); //$NON-NLS-1$
+ public final static Status MULTI_STATUS = new Status(IResponse.SC_MULTI_STATUS, "Multi-Status"); //$NON-NLS-1$
+
+ // 300-series
+ public final static Status MULTIPLE_CHOICES = new Status(IResponse.SC_MULTIPLE_CHOICES, "Multiple Choices"); //$NON-NLS-1$
+ public final static Status MOVED_PERMANENTLY = new Status(IResponse.SC_MOVED_PERMANENTLY, "Moved Permanently"); //$NON-NLS-1$
+ public final static Status MOVED_TEMPORARILY = new Status(IResponse.SC_MOVED_TEMPORARILY, "Moved Temporarily"); //$NON-NLS-1$
+ public final static Status SEE_OTHER = new Status(IResponse.SC_SEE_OTHER, "See Other"); //$NON-NLS-1$
+ public final static Status NOT_MODIFIED = new Status(IResponse.SC_NOT_MODIFIED, "Not Modified"); //$NON-NLS-1$
+ public final static Status USE_PROXY = new Status(IResponse.SC_USE_PROXY, "Use Proxy"); //$NON-NLS-1$
+
+ // 400-series
+ public final static Status BAD_REQUEST = new Status(IResponse.SC_BAD_REQUEST, "Bad Request"); //$NON-NLS-1$
+ public final static Status UNAUTHORIZED = new Status(IResponse.SC_UNAUTHORIZED, "Unauthorized"); //$NON-NLS-1$
+ public final static Status PAYMENT_REQUIRED = new Status(IResponse.SC_PAYMENT_REQUIRED, "Payment Required"); //$NON-NLS-1$
+ public final static Status FORBIDDEN = new Status(IResponse.SC_FORBIDDEN, "Forbidden"); //$NON-NLS-1$
+ public final static Status NOT_FOUND = new Status(IResponse.SC_NOT_FOUND, "Not Found"); //$NON-NLS-1$
+ public final static Status METHOD_NOT_ALLOWED = new Status(IResponse.SC_METHOD_NOT_ALLOWED, "Method Not Allowed"); //$NON-NLS-1$
+ public final static Status NOT_ACCEPTABLE = new Status(IResponse.SC_NOT_ACCEPTABLE, "Not Acceptable"); //$NON-NLS-1$
+ public final static Status PROXY_AUTHENTICATION_REQUIRED = new Status(IResponse.SC_PROXY_AUTHENTICATION_REQUIRED, "Proxy Authentication Required"); //$NON-NLS-1$
+ public final static Status REQUEST_TIMEOUT = new Status(IResponse.SC_REQUEST_TIMEOUT, "Request Timeout"); //$NON-NLS-1$
+ public final static Status CONFLICT = new Status(IResponse.SC_CONFLICT, "Conflict"); //$NON-NLS-1$
+ public final static Status GONE = new Status(IResponse.SC_GONE, "Gone"); //$NON-NLS-1$
+ public final static Status LENGTH_REQUIRED = new Status(IResponse.SC_LENGTH_REQUIRED, "Length Required"); //$NON-NLS-1$
+ public final static Status PRECONDITION_FAILED = new Status(IResponse.SC_PRECONDITION_FAILED, "Precondition Failed"); //$NON-NLS-1$
+ public final static Status REQUEST_TOO_LONG = new Status(IResponse.SC_REQUEST_TOO_LONG, "Request Too Long"); //$NON-NLS-1$
+ public final static Status REQUEST_URI_TOO_LONG = new Status(IResponse.SC_REQUEST_URI_TOO_LONG, "Request URI Too Long"); //$NON-NLS-1$
+ public final static Status UNSUPPORTED_MEDIA_TYPE = new Status(IResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"); //$NON-NLS-1$
+ public final static Status UNPROCESSABLE_ENTITY = new Status(IResponse.SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity"); //$NON-NLS-1$
+ public final static Status LOCKED = new Status(IResponse.SC_LOCKED, "Locked"); //$NON-NLS-1$
+ public final static Status FAILED_DEPENDENCY = new Status(IResponse.SC_FAILED_DEPENDENCY, "Failed Dependency"); //$NON-NLS-1$
+ public final static Status INSUFFICIENT_SPACE_ON_RESOURCE = new Status(IResponse.SC_INSUFFICIENT_SPACE_ON_RESOURCE, "Insufficient Space on Resource"); //$NON-NLS-1$
+
+ // 500-series
+ public final static Status INTERNAL_SERVER_ERROR = new Status(IResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error"); //$NON-NLS-1$
+ public final static Status NOT_IMPLEMENTED = new Status(IResponse.SC_NOT_IMPLEMENTED, "Not Implemented"); //$NON-NLS-1$
+ public final static Status BAD_GATEWAY = new Status(IResponse.SC_BAD_GATEWAY, "Bad Gateway"); //$NON-NLS-1$
+ public final static Status SERVICE_UNAVAILABLE = new Status(IResponse.SC_SERVICE_UNAVAILABLE, "Service Unavailable"); //$NON-NLS-1$
+ public final static Status GATEWAY_TIMEOUT = new Status(IResponse.SC_GATEWAY_TIMEOUT, "Gateway Timeout"); //$NON-NLS-1$
+ public final static Status HTTP_VERSION_NOT_SUPPORTED = new Status(IResponse.SC_HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported"); //$NON-NLS-1$
+ public final static Status LOOP_DETECTED = new Status(IResponse.SC_LOOP_DETECTED, "Loop Detected"); //$NON-NLS-1$
+ public final static Status CROSS_SERVER_BINDING_FORBIDDEN = new Status(IResponse.SC_CROSS_SERVER_BINDING_FORBIDDEN, "Cross-Server Binding Forbidden"); //$NON-NLS-1$
+
+ public Status(int code, String message) {
+ super();
+ this.code = code;
+ this.message = message;
+ this.extendedStatus = null;
+ }
+
+ public Status(Status basicStatus, Document extendedStatus) {
+ super();
+ this.code = basicStatus.code;
+ this.message = basicStatus.message;
+ this.extendedStatus = extendedStatus;
+ }
+
+ /**
+ * Answers whether the receiver and the argument are considered
+ * equal. Note that in this implementation of equal, the only
+ * field that is considered is the status code. In particular,
+ * the status message and the extended status information are
+ * not considered revlevant to equality.
+ *
+ * @param obj other object with which to test equality.
+ * @return boolean indicating equality.
+ * @see Status#sameAs(Object)
+ */
+ public boolean equals(Object obj) {
+ return (obj != null) && (obj instanceof Status) && (this.code == ((Status) obj).getCode());
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * Get the extended status information for the receiver
+ * as an XML document. This method will return <code>null
+ * </code> if there is no extended information.
+ *
+ * @return the extended infomration as a <code>Document</code>,
+ *or <code>null</code> if there is no such information.
+ */
+ public Document getExtendedStatus() {
+ return extendedStatus;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * @see #hashCode()
+ */
+ public int hashCode() {
+ return code;
+ }
+
+ /**
+ * Answers whether the receiver and the argument are considered
+ * identical. To be identical, the receiver and the argument
+ * must have the same status code, message, and extended status
+ * information.
+ *
+ * @param obj other object with which to test.
+ * @return boolean indicating whether they are the same or not.
+ * @see Status#equals(Object)
+ */
+ public boolean sameAs(Object obj) {
+ if (obj == null || !(obj instanceof Status))
+ return false;
+ Status other = (Status) obj;
+ if (other.code != code || !other.message.equals(message))
+ return false;
+ return other.extendedStatus.equals(extendedStatus);
+ }
+
+ public String toHTTPString() {
+ return "HTTP/1.1 " + code + " " + message; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public String toString() {
+ return getClass().getName() + "(" + toHTTPString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/Status.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/SystemException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/SystemException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/SystemException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public class SystemException extends DAVException {
+
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+ protected Exception wrappedException;
+
+ /**
+ * SystemException default constructor.
+ */
+ public SystemException() {
+ super();
+ }
+
+ public SystemException(Exception e) {
+ super(e.getMessage());
+ wrappedException = e;
+ }
+
+ public SystemException(String s) {
+ super(s);
+ }
+
+ public Exception getWrappedException() {
+ return wrappedException;
+ }
+
+ public void setWrappedException(Exception e) {
+ wrappedException = e;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/SystemException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVConstants.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVConstants.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVConstants.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+public interface WebDAVConstants {
+
+ // Namespace URI for all WebDAV elements.
+ String DAV_URI = "DAV:"; //$NON-NLS-1$
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVConstants.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+/**
+ * This is the superclass of all WebDAV protocol exceptions
+ * It contains a status code that provides information, and a
+ * descriptive message.
+ */
+public class WebDAVException extends DAVException {
+
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+ private int statusCode = 0;
+ protected Object data = null;
+
+ /**
+ * Construct a WebDAVException
+ *
+ * @param statusCode the HTTP/1.1 or WebDAV status code
+ * @param statusMessage a message describing the exception of status code
+ */
+ public WebDAVException(int statusCode, String statusMessage) {
+ super(statusMessage);
+ this.statusCode = statusCode;
+ }
+
+ /**
+ * Construct a WebDAVException
+ *
+ * @param statusCode the HTTP/1.1 or WebDAV status code
+ * @param statusMessage a message describing the exception of status code
+ */
+ public WebDAVException(int statusCode, String statusMessage, Object data) {
+ super(statusMessage);
+ this.statusCode = statusCode;
+ this.data = data;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ /**
+ * Get the status code that provides additional information about the
+ * exception. These status codes are defined by the HTTP/1.1 and WebDAV
+ * specifications.
+ *
+ * @return the HTTP/1.1 or WebDAV status code
+ */
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * Render this WebDAVException as a string including its status code.
+ *
+ * @return the string includes the status code and message
+ */
+ public String toString() {
+ return "WebDAVException(" + statusCode + ": " + getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPreconditionFailures.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPreconditionFailures.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPreconditionFailures.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.dom.QualifiedName;
+
+public interface WebDAVPreconditionFailures extends WebDAVConstants {
+
+ // The following precondition failures are considered 403 Forbidden.
+ // The server understood the request, but is refusing to fulfill it.
+ // Authorization will not help and the request SHOULD NOT be repeated.
+ QualifiedName DAV_ACTIVITY_LOCATION_OK = new QualifiedNameImpl(DAV_URI, "activity-location-ok"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_SELECTOR_MUST_BE_EMPTY = new QualifiedNameImpl(DAV_URI, "baseline-selector-must-be-empty"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_COPY_HISTORY = new QualifiedNameImpl(DAV_URI, "cannot-copy-history"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_CHECKED_IN_PARENT = new QualifiedNameImpl(DAV_URI, "cannot-modify-checked-in-parent"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_DESTINATION_CHECKED_IN_PARENT = new QualifiedNameImpl(DAV_URI, "cannot-modify-destination-checked-in-parent"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_PROTECTED_PROPERTY = new QualifiedNameImpl(DAV_URI, "cannot-modify-protected-property"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_UNSUPPORTED_PROPERTY = new QualifiedNameImpl(DAV_URI, "cannot-modify-unsupported-property"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_VERSION = new QualifiedNameImpl(DAV_URI, "cannot-modify-version"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_RENAME_RESOURCE = new QualifiedNameImpl(DAV_URI, "cannot-rename-resource"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_RENAME_VARIANT = new QualifiedNameImpl(DAV_URI, "cannot-rename-variant"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKIN_FORK_FORBIDDEN = new QualifiedNameImpl(DAV_URI, "checkin-fork-forbidden"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_NOT_ALLOWED = new QualifiedNameImpl(DAV_URI, "checkout-not-allowed"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_FORBIDDEN = new QualifiedNameImpl(DAV_URI, "checkout-of-checked-out-version-is-forbidden"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_FORBIDDEN = new QualifiedNameImpl(DAV_URI, "checkout-of-version-with-descendant-is-forbidden"); //$NON-NLS-1$
+ QualifiedName DAV_DELETE_VARIANT_REFERENCE = new QualifiedNameImpl(DAV_URI, "delete-variant-reference"); //$NON-NLS-1$
+ QualifiedName DAV_LINEAR_ACTIVITY = new QualifiedNameImpl(DAV_URI, "linear-activity"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_ACTIVITY = new QualifiedNameImpl(DAV_URI, "must-be-activity"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_BASELINE = new QualifiedNameImpl(DAV_URI, "must-be-baseline"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_CHECKED_IN = new QualifiedNameImpl(DAV_URI, "must-be-checked-in"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_CHECKED_IN_VERSION_CONTROLLED_RESOURCE = new QualifiedNameImpl(DAV_URI, "must-be-checked-in-version-controlled-resource"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_HAVE_NO_VERSION_CONTROLLED_MEMBERS = new QualifiedNameImpl(DAV_URI, "must-have-no-version-controlled-members"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_SELECT_VARIANT = new QualifiedNameImpl(DAV_URI, "must-select-variant"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_SELECT_VERSION = new QualifiedNameImpl(DAV_URI, "must-select-version"); //$NON-NLS-1$
+ QualifiedName DAV_PREDECESSOR_IN_CHECKED_OUT_VERSION_HISTORY = new QualifiedNameImpl(DAV_URI, "predecessor-in-checked-out-version-history"); //$NON-NLS-1$
+ QualifiedName DAV_WORKSPACE_REQUIRED = new QualifiedNameImpl(DAV_URI, "workspace-required"); //$NON-NLS-1$
+
+ // The following precondition failures are considered 409 Conflict
+ // The request could not be completed due to a conflict with the current
+ // state of the resource. This code is only allowed in situations where
+ // it is expected that the user might be able to resolve the conflict
+ // and resubmit the request.
+ QualifiedName DAV_ATOMIC_ACTIVITY_CHECKIN = new QualifiedNameImpl(DAV_URI, "atomic-activity-check-in"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_CONTROLLED_MEMBERS_MUST_BE_CHECKED_IN = new QualifiedNameImpl(DAV_URI, "baseline-controlled-members-must-be-checked-in"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_ADD_TO_EXISTING_HISTORY = new QualifiedNameImpl(DAV_URI, "cannot-add-to-existing-history"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MERGE_CHECKED_OUT_RESOURCE = new QualifiedNameImpl(DAV_URI, "canot-merge-checked-out-resource"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_DESTINATION_PARENT_VERSION = new QualifiedNameImpl(DAV_URI, "cannot-modify-destination-parent-version"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_PARENT_VERSION = new QualifiedNameImpl(DAV_URI, "cannot-modify-parent-version"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_VERSION_CONTROLLED_CONTENT = new QualifiedNameImpl(DAV_URI, "cannot-modify-version-controlled-content"); //$NON-NLS-1$
+ QualifiedName DAV_CANNOT_MODIFY_VERSION_CONTROLLED_PROPERTY = new QualifiedNameImpl(DAV_URI, "cannot-modify-version-controlled-property"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKIN_FORK_DISCOURAGED = new QualifiedNameImpl(DAV_URI, "checkin-fork-discouraged"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_DISCOURAGED = new QualifiedNameImpl(DAV_URI, "checkout-of-checked-out-version-is-discouraged"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_DISCOURAGED = new QualifiedNameImpl(DAV_URI, "checkout-of-version-with-descendant-is-discouraged"); //$NON-NLS-1$
+ QualifiedName DAV_LABEL_MUST_EXIST = new QualifiedNameImpl(DAV_URI, "label-must-exist"); //$NON-NLS-1$
+ QualifiedName DAV_MERGE_MUST_BE_COMPLETE = new QualifiedNameImpl(DAV_URI, "merge-must-be-complete"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_NEW_LABEL = new QualifiedNameImpl(DAV_URI, "must-be-new-label"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_VERSION = new QualifiedNameImpl(DAV_URI, "must-be-version"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "must-be-checked-out"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_BE_CHECKED_OUT_VERSION_CONTROLLED_RESOURCE = new QualifiedNameImpl(DAV_URI, "must-be-checked-out-version-controlled-resource"); //$NON-NLS-1$
+ QualifiedName DAV_MUST_NOT_BE_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "must-not-be-checked-out"); //$NON-NLS-1$
+ QualifiedName DAV_NO_CHECKED_OUT_BASELINE_CONTROLLED_COLLECTION_MEMBERS = new QualifiedNameImpl(DAV_URI, "no-checked-out-baseline-controlled-collection-members"); //$NON-NLS-1$
+ QualifiedName DAV_ONE_BASELINE_CONTROLLED_COLLECTION_PER_HISTORY_PER_WORKSPACE = new QualifiedNameImpl(DAV_URI, "one-baseline-controlled-collection-per-history-per-workspace"); //$NON-NLS-1$
+ QualifiedName DAV_ONE_VERSION_CONTROLLED_RESOURCE_PER_HISTORY_PER_WORKSPACE = new QualifiedNameImpl(DAV_URI, "one-version-controlled-resource-per-history-per-workspace"); //$NON-NLS-1$
+ QualifiedName DAV_ONE_CHECKOUT_PER_ACTIVITY_PER_HISTORY = new QualifiedNameImpl(DAV_URI, "one-checkout-per-activity-per-history"); //$NON-NLS-1$
+ QualifiedName DAV_RESOURCE_MUST_BE_NULL = new QualifiedNameImpl(DAV_URI, "resource-must-be-null"); //$NON-NLS-1$
+
+ // Postconditions
+ /* QualifiedName DAV_ACTIVITY_COLLECTION_SET_OK = new QualifiedNameImpl(DAV_URI, "activity-collection-set-ok");
+ QualifiedName DAV_ADD_LABEL = new QualifiedNameImpl(DAV_URI, "add-label");
+ QualifiedName DAV_ALREADY_UNDER_VERSION_CONTROL = new QualifiedNameImpl(DAV_URI, "already-under-version-control");
+ QualifiedName DAV_ANCESTOR_VERSION = new QualifiedNameImpl(DAV_URI, "ancestor-version");
+ QualifiedName DAV_AUTO_BASELINE = new QualifiedNameImpl(DAV_URI, "auto-baseline");
+ QualifiedName DAV_AUTO_CHECKOUT = new QualifiedNameImpl(DAV_URI, "auto-checkout");
+ QualifiedName DAV_AUTO_CHECKOUT_CHECKIN = new QualifiedNameImpl(DAV_URI, "auto-checkout-checkin");
+ QualifiedName DAV_BASELINE_CONTROLLED_COLLECTION_SET_OK = new QualifiedNameImpl(DAV_URI, "baseline-controlled-collection-set-ok");
+ QualifiedName DAV_BASELINE_VERSION_OK = new QualifiedNameImpl(DAV_URI, "baseline-version-ok");
+ QualifiedName DAV_BASELINES_FROM_SAME_HISTORY = new QualifiedNameImpl(DAV_URI, "baselines-from-same-history");
+ QualifiedName DAV_CANNOT_DELETE_REFERENCED_VERSION = new QualifiedNameImpl(DAV_URI, "cannot-delete-referenced-version");
+ QualifiedName DAV_CANNOT_DELETE_ROOT_VERSION = new QualifiedNameImpl(DAV_URI, "cannot-delete-root-version");
+ QualifiedName DAV_CHECKED_IN = new QualifiedNameImpl(DAV_URI, "checked-in");
+ QualifiedName DAV_CHECK_IN_ACTIVITY = new QualifiedNameImpl(DAV_URI, "check-in-activity");
+ QualifiedName DAV_CHECKED_OUT_FOR_MERGE = new QualifiedNameImpl(DAV_URI, "checked-out-for-merge");
+ QualifiedName DAV_CREATE_BASELINE_SELECTOR = new QualifiedNameImpl(DAV_URI, "create-baseline-selector");
+ QualifiedName DAV_CREATE_BASELINE_VERSION_SET = new QualifiedNameImpl(DAV_URI, "create-baseline-version-set");
+ QualifiedName DAV_CREATE_NEW_VARIANT = new QualifiedNameImpl(DAV_URI, "create-new-variant");
+ QualifiedName DAV_CREATE_VERSION = new QualifiedNameImpl(DAV_URI, "create-version");
+ QualifiedName DAV_DELETE_ACTIVITY_REFERENCE = new QualifiedNameImpl(DAV_URI, "delete-activity-reference");
+ QualifiedName DAV_DELETE_VARIANT_PREDECESSOR = new QualifiedNameImpl(DAV_URI, "delete-variant-predecessor");
+ QualifiedName DAV_DELETE_VERSION_SET = new QualifiedNameImpl(DAV_URI, "delete-version-set");
+ QualifiedName DAV_DELETE_VERSION_REFERENCE = new QualifiedNameImpl(DAV_URI, "delete-version-reference");
+ QualifiedName DAV_DELETE_WORKING_RESOURCE = new QualifiedNameImpl(DAV_URI, "delete-working-resource");
+ QualifiedName DAV_DESCENDANT_VERSION = new QualifiedNameImpl(DAV_URI, "descendant-version");
+ QualifiedName DAV_DEPTH_UPDATE = new QualifiedNameImpl(DAV_URI, "depth-update");
+ QualifiedName DAV_INITIALIZE_ACTIVITY_SET = new QualifiedNameImpl(DAV_URI, "initialize-activity-set");
+ QualifiedName DAV_INITIALIZE_COLLECTION_VERSION_BINDINGS = new QualifiedNameImpl(DAV_URI, "initialize-collection-version-bindings");
+ QualifiedName DAV_INITIALIZE_PRECURSOR = new QualifiedNameImpl(DAV_URI, "initialize-precursor");
+ QualifiedName DAV_INITIALIZE_PREDECESSOR_SET = new QualifiedNameImpl(DAV_URI, "initialize-predecessor-set");
+ QualifiedName DAV_INITIALIZE_UNRESERVED = new QualifiedNameImpl(DAV_URI, "initialize-unreserved");
+ QualifiedName DAV_INITIALIZE_VERSION_CONTENT_AND_PROPERTIES = new QualifiedNameImpl(DAV_URI, "initialize-version-content-and-properties");
+ QualifiedName DAV_INITIALIZE_WORKSPACE_PROPERTIES = new QualifiedNameImpl(DAV_URI, "initialize-workspace-properties");
+ QualifiedName DAV_IS_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "is-checked-out");
+ QualifiedName DAV_KEEP_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "keep-checked-out");
+ QualifiedName DAV_LATEST_ACTIVITY_VERSION_OK = new QualifiedNameImpl(DAV_URI, "latest-activity-version-ok");
+ QualifiedName DAV_MERGE_BASELINE = new QualifiedNameImpl(DAV_URI, "merge-baseline");
+ QualifiedName DAV_NO_VERSION_DELETE = new QualifiedNameImpl(DAV_URI, "no-version-delete");
+ QualifiedName DAV_NEW_VERSION_HISTORY = new QualifiedNameImpl(DAV_URI, "new-version-history");
+ QualifiedName DAV_NEW_VERSION_CONTROLLED_RESOURCE = new QualifiedNameImpl(DAV_URI, "new-version-controlled-resource");
+ QualifiedName DAV_PRESERVE_HISTORY = new QualifiedNameImpl(DAV_URI, "preserve-history");
+ QualifiedName DAV_PUT_UNDER_VERSION_CONTROL = new QualifiedNameImpl(DAV_URI, "put-under-version-control");
+ QualifiedName DAV_REMOVE_LABEL = new QualifiedNameImpl(DAV_URI, "remove-label");
+ QualifiedName DAV_SELECT_EXISTING_BASELINE = new QualifiedNameImpl(DAV_URI, "select-existing-baseline");
+ QualifiedName DAV_SET_BASELINE_CONTROLLED_COLLECTION_MEMBERS = new QualifiedNameImpl(DAV_URI, "set-baseline-controlled-collection-members");
+ QualifiedName DAV_UPDATE_ACTIVITY_REFERENCE = new QualifiedNameImpl(DAV_URI, "update-activity-reference");
+ QualifiedName DAV_UPDATE_ACTIVITY_VERSION_SET = new QualifiedNameImpl(DAV_URI, "update-activity-version-set");
+ QualifiedName DAV_UPDATE_CHECKED_IN_PROPERTY = new QualifiedNameImpl(DAV_URI, "update-checked-in-property");
+ QualifiedName DAV_UPDATE_CHECKED_OUT_REFERENCE = new QualifiedNameImpl(DAV_URI, "update-checked-out-reference");
+ QualifiedName DAV_UPDATE_CONTENT_AND_DEAD_PROPERTIES = new QualifiedNameImpl(DAV_URI, "update-content-and-dead-properties");
+ QualifiedName DAV_UPDATE_DEFAULT_VARIANT = new QualifiedNameImpl(DAV_URI, "update-default-variant");
+ QualifiedName DAV_UPDATE_MERGE_SET = new QualifiedNameImpl(DAV_URI, "update-merge-set");
+ QualifiedName DAV_UPDATE_PREDECESSOR_SET = new QualifiedNameImpl(DAV_URI, "update-predecessor-set");
+ QualifiedName DAV_UPDATE_VARIANT_CONTROLLED_RESOURCE = new QualifiedNameImpl(DAV_URI, "update-variant-controlled-resource");
+ QualifiedName DAV_UPDATE_VERSION_CONTROLLED_COLLECTION_MEMBERS = new QualifiedNameImpl(DAV_URI, "update-version-controlled-collection-members");
+ QualifiedName DAV_UPDATE_WORKSPACE_REFERENCE = new QualifiedNameImpl(DAV_URI, "update-workspace-reference");
+ QualifiedName DAV_VARIANT_CONTROL = new QualifiedNameImpl(DAV_URI, "variant-control");
+ QualifiedName DAV_VERSION_CONTROL_WORKING_COLLECTION_MEMBERS = new QualifiedNameImpl(DAV_URI, "version-control-working-collection-members");
+ QualifiedName DAV_VERSION_CONTROLLED_RESOURCE_URL_OK = new QualifiedNameImpl(DAV_URI, "version-controlled-resource-url-ok");
+ QualifiedName DAV_VERSION_HISTORY_COLLECTION_SET_OK = new QualifiedNameImpl(DAV_URI, "version-history-collection-set-ok");
+ QualifiedName DAV_VERSION_HISTORY_IS_TREE = new QualifiedNameImpl(DAV_URI, "version-history-is-tree");
+ QualifiedName DAV_VERSION_TREE_OK = new QualifiedNameImpl(DAV_URI, "version-tree-ok");
+ QualifiedName DAV_WORKSPACE_LOCATION_OK = new QualifiedNameImpl(DAV_URI, "workspace-location-ok");
+ QualifiedName DAV_WORKSPACE_MEMBER_MOVED = new QualifiedNameImpl(DAV_URI, "workspace-member-moved");
+ QualifiedName DAV_WORKSPACE_MOVED = new QualifiedNameImpl(DAV_URI, "workspace-moved");
+ */
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPreconditionFailures.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyNames.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyNames.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyNames.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.dom.QualifiedName;
+
+public interface WebDAVPropertyNames extends WebDAVConstants {
+
+ // From WebDAV (RFC2518).
+ QualifiedName DAV_CREATION_DATE = new QualifiedNameImpl(DAV_URI, "creationdate"); //$NON-NLS-1$
+ QualifiedName DAV_DISPLAY_NAME = new QualifiedNameImpl(DAV_URI, "displayname"); //$NON-NLS-1$
+ QualifiedName DAV_GET_CONTENT_LANGUAGE = new QualifiedNameImpl(DAV_URI, "getcontentlanguage"); //$NON-NLS-1$
+ QualifiedName DAV_GET_CONTENT_LENGTH = new QualifiedNameImpl(DAV_URI, "getcontentlength"); //$NON-NLS-1$
+ QualifiedName DAV_GET_CONTENT_TYPE = new QualifiedNameImpl(DAV_URI, "getcontenttype"); //$NON-NLS-1$
+ QualifiedName DAV_GET_E_TAG = new QualifiedNameImpl(DAV_URI, "getetag"); //$NON-NLS-1$
+ QualifiedName DAV_GET_LAST_MODIFIED = new QualifiedNameImpl(DAV_URI, "getlastmodified"); //$NON-NLS-1$
+ QualifiedName DAV_HREF = new QualifiedNameImpl(DAV_URI, "href"); //$NON-NLS-1$
+ QualifiedName DAV_LOCK_DISCOVERY = new QualifiedNameImpl(DAV_URI, "lockdiscovery"); //$NON-NLS-1$
+ QualifiedName DAV_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "resourcetype"); //$NON-NLS-1$
+ QualifiedName DAV_SOURCE = new QualifiedNameImpl(DAV_URI, "source"); //$NON-NLS-1$
+ QualifiedName DAV_SUPPORTED_LOCK = new QualifiedNameImpl(DAV_URI, "supportedlock"); //$NON-NLS-1$
+
+ // From Delta-V.
+
+ // Properties defined in core versioning.
+ QualifiedName DAV_ACTIVITY_CHECKOUT_SET = new QualifiedNameImpl(DAV_URI, "activity-checkout-set"); //$NON-NLS-1$
+ QualifiedName DAV_ACTIVITY_VERSION_SET = new QualifiedNameImpl(DAV_URI, "activity-version-set"); //$NON-NLS-1$
+ QualifiedName DAV_AUTO_CHECKIN = new QualifiedNameImpl(DAV_URI, "auto-checkin"); //$NON-NLS-1$
+ QualifiedName DAV_AUTO_CHECKOUT = new QualifiedNameImpl(DAV_URI, "auto-checkout"); //$NON-NLS-1$
+ QualifiedName DAV_AUTO_MERGE_SET = new QualifiedNameImpl(DAV_URI, "auto-merge-set"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_CONTROLLED_COLLECTION = new QualifiedNameImpl(DAV_URI, "baseline-controlled-collection"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_COLLECTION = new QualifiedNameImpl(DAV_URI, "baseline-collection"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_CONTROLLED_COLLECTION_SET = new QualifiedNameImpl(DAV_URI, "baseline-controlled-collection-set"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_SELECTOR = new QualifiedNameImpl(DAV_URI, "baseline-selector"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKED_IN = new QualifiedNameImpl(DAV_URI, "checked-in"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "checked-out"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKIN_DATE = new QualifiedNameImpl(DAV_URI, "checkin-date"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKIN_FORK = new QualifiedNameImpl(DAV_URI, "checkin-fork"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_FORK = new QualifiedNameImpl(DAV_URI, "checkout-fork"); //$NON-NLS-1$
+ QualifiedName DAV_CHECKOUT_SET = new QualifiedNameImpl(DAV_URI, "checkout-date"); //$NON-NLS-1$
+ QualifiedName DAV_COMMENT = new QualifiedNameImpl(DAV_URI, "comment"); //$NON-NLS-1$
+ QualifiedName DAV_CREATOR_DISPLAYNAME = new QualifiedNameImpl(DAV_URI, "creator-displayname"); //$NON-NLS-1$
+ QualifiedName DAV_CURRENT_ACTIVITY_SET = new QualifiedNameImpl(DAV_URI, "current-activity-set"); //$NON-NLS-1$
+ QualifiedName DAV_CURRENT_WORKSPACE_SET = new QualifiedNameImpl(DAV_URI, "current-workspace-set"); //$NON-NLS-1$
+ QualifiedName DAV_LATEST_VERSION = new QualifiedNameImpl(DAV_URI, "latest-version"); //$NON-NLS-1$
+ QualifiedName DAV_LABEL_NAME_SET = new QualifiedNameImpl(DAV_URI, "label-name-set"); //$NON-NLS-1$
+ QualifiedName DAV_MERGE_SET = new QualifiedNameImpl(DAV_URI, "merge-set"); //$NON-NLS-1$
+ QualifiedName DAV_MUTABLE = new QualifiedNameImpl(DAV_URI, "mutable"); //$NON-NLS-1$
+ QualifiedName DAV_PRECURSOR_SET = new QualifiedNameImpl(DAV_URI, "precursor-set"); //$NON-NLS-1$
+ QualifiedName DAV_PREDECESSOR_SET = new QualifiedNameImpl(DAV_URI, "predecessor-set"); //$NON-NLS-1$
+ QualifiedName DAV_ROOT_VERSION = new QualifiedNameImpl(DAV_URI, "root-version"); //$NON-NLS-1$
+ QualifiedName DAV_SUBACTIVITY_SET = new QualifiedNameImpl(DAV_URI, "subactivity-set"); //$NON-NLS-1$
+ QualifiedName DAV_SUBBASELINE_SET = new QualifiedNameImpl(DAV_URI, "subbaseline-set"); //$NON-NLS-1$
+ QualifiedName DAV_SUCCESSOR_SET = new QualifiedNameImpl(DAV_URI, "successor-set"); //$NON-NLS-1$
+ QualifiedName DAV_SUPPORTED_LIVE_PROPERTY_SET = new QualifiedNameImpl(DAV_URI, "supported-live-property-set"); //$NON-NLS-1$
+ QualifiedName DAV_SUPPORTED_METHOD_SET = new QualifiedNameImpl(DAV_URI, "supported-method-set"); //$NON-NLS-1$
+ QualifiedName DAV_SUPPORTED_REPORT_SET = new QualifiedNameImpl(DAV_URI, "supported-report-set"); //$NON-NLS-1$
+ QualifiedName DAV_UNRESERVED = new QualifiedNameImpl(DAV_URI, "unreserved"); //$NON-NLS-1$
+ QualifiedName DAV_VERSION_CONTROLLED_CONFIGURATION = new QualifiedNameImpl(DAV_URI, "version-controlled-configuration"); //$NON-NLS-1$
+ QualifiedName DAV_VERSION_HISTORY = new QualifiedNameImpl(DAV_URI, "version-history"); //$NON-NLS-1$
+ QualifiedName DAV_VERSION_NAME = new QualifiedNameImpl(DAV_URI, "version-name"); //$NON-NLS-1$
+ QualifiedName DAV_VERSION_SET = new QualifiedNameImpl(DAV_URI, "version-set"); //$NON-NLS-1$
+ QualifiedName DAV_WORKSPACE = new QualifiedNameImpl(DAV_URI, "workspace"); //$NON-NLS-1$
+ QualifiedName DAV_WORKSPACE_CHECKOUT_SET = new QualifiedNameImpl(DAV_URI, "workspace-checkout-set"); //$NON-NLS-1$
+ QualifiedName DAV_WORKSPACE_COLLECTION_SET = new QualifiedNameImpl(DAV_URI, "workspace-collection-set"); //$NON-NLS-1$
+
+ // From Bindings spec.
+ QualifiedName DAV_RESOURCE_ID = new QualifiedNameImpl(DAV_URI, "resourceid"); //$NON-NLS-1$
+
+ // Added by this server implementation.
+ QualifiedName DAV_WORKING_RESOURCE = new QualifiedNameImpl(DAV_URI, "working-resource"); //$NON-NLS-1$
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyNames.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyValues.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyValues.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyValues.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel;
+
+import org.eclipse.webdav.dom.QualifiedName;
+
+public interface WebDAVPropertyValues extends WebDAVConstants {
+
+ // Resource types.
+ QualifiedName DAV_ACTIVITY_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "activity-resourcetype"); //$NON-NLS-1$
+ QualifiedName DAV_BASELINE_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "baseline-resourcetype"); //$NON-NLS-1$
+ QualifiedName DAV_COLLECTION_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "collection"); //$NON-NLS-1$
+ QualifiedName DAV_VERSION_HISTORY_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "version-history-resourcetype"); //$NON-NLS-1$
+ QualifiedName DAV_WORKSPACE_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "workspace-resourcetype"); //$NON-NLS-1$
+ QualifiedName DAV_HISTORY_RESOURCE_TYPE = new QualifiedNameImpl(DAV_URI, "history-resourcetype"); //$NON-NLS-1$
+
+ // Check-in policies.
+ QualifiedName DAV_KEEP_CHECKED_OUT = new QualifiedNameImpl(DAV_URI, "keep-checked-out"); //$NON-NLS-1$
+ QualifiedName DAV_NEW_VERSION = new QualifiedNameImpl(DAV_URI, "new-version"); //$NON-NLS-1$
+ QualifiedName DAV_OVERWRITE = new QualifiedNameImpl(DAV_URI, "overwrite"); //$NON-NLS-1$
+
+ // Auto-version policies.
+ QualifiedName DAV_LOCKED_UPDATE = new QualifiedNameImpl(DAV_URI, "locked-update"); //$NON-NLS-1$
+ QualifiedName DAV_UNLOCKED_UPDATE = new QualifiedNameImpl(DAV_URI, "unlocked-update"); //$NON-NLS-1$
+
+ // Fork control policy.
+ QualifiedName DAV_OK = new QualifiedNameImpl(DAV_URI, "ok"); //$NON-NLS-1$
+ QualifiedName DAV_DISCOURAGED = new QualifiedNameImpl(DAV_URI, "discouraged"); //$NON-NLS-1$
+ QualifiedName DAV_FORBIDDEN = new QualifiedNameImpl(DAV_URI, "forbidden"); //$NON-NLS-1$
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/WebDAVPropertyValues.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/messages.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/messages.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/messages.properties 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,37 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+### WebDAV Kernel messages
+
+label.exceptionMessage = Wrapped exception's message:
+label.bytes = Bytes body: {0} bytes
+
+assert.fail = assertion failed; {0}
+assert.null = null argument; {0}
+
+exception.dumping = Dumping exception: {0}.
+
+error.extractFromElementWithoutText = Attempt to extract text node from Element without text.
+error.parseDuplicateEntry = Error parsing If header: duplicate entry in list
+error.parseEmptyList = Syntax error in If header: list is empty: {0}
+error.parseMissing = Error parsing If header: saw: {0} expected: {1}
+error.parseMissingNot = Error parsing If header: expected Not
+error.parseMissingOpen = Error parsing If header: saw: {0} expected: < or [
+error.parseMissingQuotedString = Error parsing If header: saw: {0} expected a quoted string
+error.parseMissingResource = Error parsing If header: missing resource URI
+error.parseMissingStart = Error parsing If header: saw: {0} expected: ( or <
+error.parseMissingStateOrEntity = Error parsing If header: missing State-Token or entity-tag
+error.parseMissingURI = Error parsing If header: saw: {0} expected a URI
+error.parseMultipleSpecification = Cannot be specified more than once in an If header: {0}
+error.receiverHasBody = Receiver has a Document body.
+error.receiverMissingBody = Receiver does not have a Document body.
+error.requireElementWithSingleChild = Can only extract text node from an Element with a single text child.
+error.davElementsNeedQualifier = DAV elements must have DAV: namespace qualifier.
+
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/messages.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/Assert.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/Assert.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/Assert.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import org.eclipse.webdav.internal.kernel.Policy;
+
+/**
+ * <code>Assert</code> is useful for for embedding runtime sanity checks
+ * in code.
+ * The predicate methods all test a condition and throw some
+ * type of unchecked exception if the condition does not hold.
+ * <p>
+ * Assertion failure exceptions, like most runtime exceptions, are
+ * thrown when something is misbehaving. Assertion failures are invariably
+ * unspecified behavior; consequently, clients should never rely on
+ * these being thrown (and certainly should not being catching them
+ * specifically).
+ *
+ */
+public class Assert {
+ /** Block instantiation. */
+ private Assert() {
+ super();
+ }
+
+ /** Asserts that an argument is legal. If the given boolean is
+ * not <code>true</code>, an <code>IllegalArgumentException</code>
+ * is thrown.
+ *
+ * @exception IllegalArgumentException Thrown if the legality test failed
+ */
+ static public boolean isLegal(boolean expression) {
+ return isLegal(expression, ""); //$NON-NLS-1$
+ }
+
+ /** Asserts that an argument is legal. If the given boolean is
+ * not <code>true</code>, an <code>IllegalArgumentException</code>
+ * is thrown.
+ * The given message is included in that exception, to aid debugging.
+ *
+ * @exception IllegalArgumentException Thrown if the legality test failed
+ */
+ static public boolean isLegal(boolean expression, String message) {
+ if (!expression)
+ throw new IllegalArgumentException(message);
+ return expression;
+ }
+
+ /** Asserts that the given object is not <code>null</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ */
+ static public void isNotNull(Object o) {
+ isNotNull(o, ""); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given object is not <code>null</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ */
+ static public void isNotNull(Object o, String message) {
+ if (o == null)
+ throw new AssertionFailedException(Policy.bind("assert.null", message)); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given boolean is <code>true</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ */
+ static public boolean isTrue(boolean expression) {
+ return isTrue(expression, ""); //$NON-NLS-1$
+ }
+
+ /** Asserts that the given boolean is <code>true</code>. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ */
+ static public boolean isTrue(boolean expression, String message) {
+ if (!expression)
+ throw new AssertionFailedException(Policy.bind("assert.fail", message)); //$NON-NLS-1$
+ return expression;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/Assert.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/AssertionFailedException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/AssertionFailedException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/AssertionFailedException.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+/**
+ * <code>AssertionFailedException</code> is a runtime exception thrown
+ * by some of the methods in <code>Assert</code>.
+ * <p>
+ * This class is not declared public to prevent some misuses; programs that catch
+ * or otherwise depend on assertion failures are susceptible to unexpected
+ * breakage when assertions in the code are added or removed.
+ */
+/* package */class AssertionFailedException extends RuntimeException {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Constructs a new exception.
+ */
+ public AssertionFailedException() {
+ super();
+ }
+
+ /** Constructs a new exception with the given message.
+ */
+ public AssertionFailedException(String detail) {
+ super(detail);
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/AssertionFailedException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/DateTime.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/DateTime.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/DateTime.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * A generic date and time object. It uses UTC as the timezone and US as the locale.
+ */
+
+public class DateTime {
+ protected SimpleDateFormat dateFormat;
+ protected long dateTime;
+
+ protected static final String RFC_1123_PATTERN = "EEE, dd MMM yyyy HH:mm:ss 'GMT'"; //$NON-NLS-1$
+ protected static final String RFC_850_PATTERN = "E, dd-MMM-yyyy HH:mm:ss 'GMT'"; //$NON-NLS-1$
+ protected static final String ASCTIME_PATTERN = "EEE MMM dd HH:mm:ss yyyy"; //$NON-NLS-1$
+ protected static final String ISO_8601_UTC_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
+ protected static final String ISO_8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ssz"; //$NON-NLS-1$
+ protected static final String ISO_8601_UTC_MILLIS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
+ protected static final String ISO_8601_MILLIS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSz"; //$NON-NLS-1$
+
+ public DateTime() {
+ this(0);
+ }
+
+ /**
+ * Starts this object from a java long format (milliseconds).
+ */
+ public DateTime(long date) {
+ setDateTime(date);
+ dateFormat = new SimpleDateFormat();
+ dateFormat.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US)); //$NON-NLS-1$
+ }
+
+ public boolean after(DateTime other) {
+ return getDateTime() > other.getDateTime();
+ }
+
+ public boolean before(DateTime other) {
+ return getDateTime() < other.getDateTime();
+ }
+
+ public boolean equals(DateTime other) {
+ return getDateTime() == other.getDateTime();
+ }
+
+ /**
+ * Milliseconds since 1 January 1970 0:00 UTC.
+ */
+ public long getDateTime() {
+ return dateTime;
+ }
+
+ public int getMilliseconds() {
+ return (int) (getDateTime() % 1000);
+ }
+
+ /**
+ * Sets the date and time from a java long format (milliseconds).
+ */
+ public void setDateTime(long dateTime) {
+ this.dateTime = dateTime;
+ }
+
+ /**
+ * Do nothing if date format is not supported
+ */
+ public void setDateTime(String date) {
+ String[] patterns = {RFC_1123_PATTERN, ISO_8601_UTC_PATTERN, ISO_8601_UTC_MILLIS_PATTERN, ISO_8601_PATTERN, ISO_8601_MILLIS_PATTERN, RFC_850_PATTERN, ASCTIME_PATTERN};
+ for (int i = 0; i < patterns.length; i++) {
+ if (setDateTime(date, patterns[i]))
+ break;
+ }
+ }
+
+ /**
+ * Do nothing if date format is not supported.
+ */
+ protected boolean setDateTime(String date, String pattern) {
+ boolean dateChanged = true;
+ dateFormat.applyPattern(pattern);
+ try {
+ setDateTime(dateFormat.parse(date));
+ } catch (ParseException e) {
+ dateChanged = false;
+ }
+ return dateChanged;
+ }
+
+ public void setDateTime(Date date) {
+ dateTime = date.getTime();
+ }
+
+ public Date toDate() {
+ return new Date(dateTime);
+ }
+
+ public String toISO8601() {
+ if (getMilliseconds() == 0)
+ return toString(ISO_8601_UTC_PATTERN);
+ return toString(ISO_8601_UTC_MILLIS_PATTERN);
+ }
+
+ public String toRFC1123() {
+ return toString(RFC_1123_PATTERN);
+ }
+
+ /**
+ * Returns on a RFC 1123 format.
+ */
+ public String toString() {
+ return toRFC1123();
+ }
+
+ protected String toString(String pattern) {
+ dateFormat.applyPattern(pattern);
+ return dateFormat.format(toDate());
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/DateTime.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EmptyEnumeration.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EmptyEnumeration.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EmptyEnumeration.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.NoSuchElementException;
+
+public class EmptyEnumeration extends EnumerationFilter {
+ public EmptyEnumeration() {
+ super();
+ }
+
+ /**
+ * @see #hasMoreElements()
+ */
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ /**
+ * @see #nextElement()
+ */
+ public Object nextElement() {
+ throw new NoSuchElementException();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EmptyEnumeration.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationConverter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationConverter.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationConverter.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.Enumeration;
+
+public abstract class EnumerationConverter extends EnumerationFilter {
+
+ protected Enumeration sourceEnum;
+
+ public EnumerationConverter(Enumeration sourceEnum) {
+ super();
+ this.sourceEnum = sourceEnum;
+ }
+
+ /**
+ * @see #hasMoreElements()
+ */
+ public boolean hasMoreElements() {
+ return sourceEnum.hasMoreElements();
+ }
+
+ /**
+ * @see #nextElement()
+ * Subclasses should override ths method to convert the
+ * source enum objects to the new types.
+ */
+ public abstract Object nextElement();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationConverter.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationFilter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationFilter.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationFilter.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.Enumeration;
+
+public abstract class EnumerationFilter implements Enumeration {
+ public EnumerationFilter() {
+ super();
+ }
+
+ /**
+ * @see #hasMoreElements()
+ */
+ public abstract boolean hasMoreElements();
+
+ /**
+ * @see #nextElement()
+ */
+ public abstract Object nextElement();
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/EnumerationFilter.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/ExcludingEnumeration.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/ExcludingEnumeration.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/ExcludingEnumeration.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class ExcludingEnumeration extends EnumerationFilter {
+
+ protected Enumeration e;
+ protected Vector excludeList;
+ protected Object next;
+
+ public ExcludingEnumeration(Enumeration e, Vector excludeList) {
+ super();
+ this.e = e;
+ this.excludeList = excludeList;
+ getNextCandidate();
+ }
+
+ private void getNextCandidate() {
+ while (e.hasMoreElements()) {
+ Object candidate = e.nextElement();
+ if (excludeList.indexOf(candidate) != -1) {
+ next = candidate;
+ return;
+ }
+ }
+ next = null;
+ }
+
+ /**
+ * @see #hasMoreElements()
+ */
+ public boolean hasMoreElements() {
+ return (next != null);
+ }
+
+ /**
+ * @see #nextElement()
+ */
+ public Object nextElement() {
+ Object answer = next;
+ getNextCandidate();
+ return answer;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/ExcludingEnumeration.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/MergedEnumeration.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/MergedEnumeration.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/MergedEnumeration.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.Enumeration;
+
+public class MergedEnumeration extends EnumerationFilter {
+
+ protected Enumeration first;
+ protected Enumeration second;
+
+ /**
+ * MergedEnumeration constructor comment.
+ */
+ public MergedEnumeration(Enumeration first, Enumeration second) {
+ super();
+ this.first = first;
+ this.second = second;
+ }
+
+ public boolean hasMoreElements() {
+ return (first.hasMoreElements() || second.hasMoreElements());
+ }
+
+ public Object nextElement() {
+ if (first.hasMoreElements())
+ return first.nextElement();
+ return second.nextElement();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/MergedEnumeration.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/NestedHashtable.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/NestedHashtable.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/NestedHashtable.java 2008-06-24 13:32:27 UTC (rev 20729)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.webdav.internal.kernel.utils;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+public class NestedHashtable {
+
+ protected Hashtable localValues = new Hashtable(5);
+ protected NestedHashtable defaults = null;
+
+ public NestedHashtable() {
+ super();
+ }
+
+ /**
+ * Constructor for the class. Set the defaults to be
+ * the given value.
+ *
+ * @param defaults the default values for the receiver
+ */
+ public NestedHashtable(NestedHashtable defaults) {
+ super();
+ this.defaults = defaults;
+ }
+
+ /**
+ * Copy all the default values into the receiver.
+ */
+ public void collapse() {
+ if (defaults != null) {
+ Enumeration keysEnum = defaults.keys();
+ while (keysEnum.hasMoreElements()) {
+ Object key = keysEnum.nextElement();
+ localValues.put(key, defaults.get(key));
+ }
+ defaults = null;
+ }
+ }
+
+ /**
+ * Return the value for the given key.
+ *
+ * @param key the key to look up
+ * @return the value for the key or null if none.
+ */
+ public Object get(Object key) {
+ Object value = localValues.get(key);
+ if (value == null && defaults != null)
+ return defaults.get(key);
+ return value;
+ }
+
+ /**
+ * Return an enumeration over the context's keys. (recursively computes the
+ * keys based on keys defaults as well)
+ *
+ * @return an enumeration over the context keys
+ */
+ public Enumeration keys() {
+ if (defaults == null)
+ return localValues.keys();
+ return new MergedEnumeration(localValues.keys(), defaults.keys());
+ }
+
+ /**
+ * Put the given key-value pair into the context.
+ *
+ * @param key the key
+ * @param value its associated value
+ */
+ public void put(Object key, Object value) {
+ localValues.put(key, value);
+ }
+
+ /**
+ * Remove the given key from the context
+ *
+ * @param key the key to remove
+ */
+ public Object remove(Object key) {
+ return localValues.remove(key);
+ }
+
+ /**
+ * Return a string representation of the context.
+ *
+ * @return the context, as a String
+ * @see #toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Enumeration keysEnum = keys();
+ while (keysEnum.hasMoreElements()) {
+ Object key = keysEnum.nextElement();
+ buffer.append(key.toString());
+ buffer.append(": "); //$NON-NLS-1$
+ buffer.append(get(key).toString());
+ buffer.append('\n');
+ }
+ return buffer.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-eclipse/org.eclipse.webdav/src/kernel/org/eclipse/webdav/internal/kernel/utils/NestedHashtable.java
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-svn-commits
mailing list