LOCK Sample Code

                 

 
Special Edition Using Microsoft SharePoint Portal Server
By Robert  Ferguson

Table of Contents
Chapter  16.   Using WebDAV Protocol to Create Web Parts


As mentioned earlier, the WebDAV LOCK method provides a mechanism for avoiding lost updates . Right now, only basic exclusive lock is supported, which means that updates to resources will be serialized. When a person issues a lock on a resource, he will be able to access and update the locked resource. With the LOCK method specified in the request header, we need to provide more information about the lock in the body of the request in XML form. Sample code provided in Listing 16.10 shows complete VBScript code for issuing a lock, and Listing 16.11 shows the response returned from the server.

Listing 16.10 The Sample Code for LOCK Method of WebDAV Protocol
 Dim strServer Dim strWorkspace Dim strFolder Dim strURL Dim strUser Dim strPassword Dim DAVRequest Dim strXMLRequest strServer = "dianatr" strWorkspace = "spsbook" strUser = "dianatr0\spsuser" strPassword = "spspw" strURL = "http://" + strServer + "/" + strWorkspace + "/Portal Content/tips/SPSLOCK.doc" strURL = Replace(strURL, " ", "%20") strXMLRequest = "" + _ "<?xml version='1.0' ?>" + _  "<a:lockinfo xmlns:a='DAV:'>" + _      "<a:lockscope><a:exclusive /></a:lockscope>" + _      "<a:locktype><a:write /></a:locktype>" + _      "<a:owner>" + _          "<a:href>http://dianatr</a:href>" + _      "</a:owner>" + _  "</a:lockinfo>" set DAVRequest = CreateObject("MSXML2.xmlhttp") DAVRequest.open "LOCK", strURL, False, strUser, strPassword DAVRequest.setRequestHeader "Content-Type", "text/xml" DAVRequest.send strXMLRequest Set xmlBody = CreateObject("MSXML2.domdocument") xmlBody.async = False xmlBody.load DAVRequest.responseXML xmlBody.save "lock.xml" 

As you see in Listing 16.10, we have identified the lock type as write, and we have defined the owner property. When the source is locked, the DAV: lockdiscovery property of the resource will be updated to a string, with its value being a concatenation of the owner value with a system-generated lock token value. There are still problems with the locking standards on WebDAV, so IETF has decided to make it an optional feature, and WebDAV-compliant products might choose not to support the LOCK method at all. Some of these problems are

  • How long we want to lock a resource for.

  • What mechanism is in place for avoiding monopolization of a resource.

Right now, to refresh a lock or unlock a resource we should know the Lock-token value, such as 91939B1E-1C14-47D3-91F8-511C4BBBAB08:2228155915641552899, which is not very user friendly.

TIP

A lock token is a universally unique identifier that the system will generate whenever it issues a LOCK successfully. This token will be returned as part of the response body, as shown in Listing 16.11.


Listing 16.11 The Response Returned from the Web Server for the LOCK Method
 <?xml version="1.0" ?> <a:prop xmlns:a="DAV:"> <a:lockdiscovery> <a:activelock> <a:locktype> <a:write /> </a:locktype> <a:lockscope> <a:exclusive /> </a:lockscope> <a:owner xmlns:a="DAV:"> <a:href>http://dianatr</a:href> </a:owner> <a:locktoken> <a:href>opaquelocktoken: 91939B1E-1C14-47D3-91F8-511C4BBBAB08:2228155915641552899</a:href> </a:locktoken> <a:depth>infinity</a:depth> <a:timeout>Second-180</a:timeout> </a:activelock> </a:lockdiscovery> </a:prop> 

As you see in Listing 16.11, we can identify the time period when a resource needs to be locked. To manage this, we can assign a timeout value as part of the request header; otherwise the system will assign 180 seconds as the default value.

NOTE

As a prefix to the token value, you also see opaquelocktoken, which uses the Universal Unique Identifier (UUID) mechanism, to guarantee uniqueness of the token all the time.


Refresh the Lock

We can use if with the lock token value to refresh the lock.

 DAVRequest.setRequestHeader "if", "<http://dianatr/spsbook/Portal%20COntent/tips/SPSLOCK. graphics/ccc.gif doc>(<opaquelocktoken: 91939B1E-1C14-47D3-91F8-511C4BBBAB08:2372271103717408771>)" 

Unlock a Resource

To unlock a resource, we just need to know the Lock-Token value that the server generates when it issues a lock.

 DAVRequest.setRequestHeader "Lock-Token", "<opaquelocktoken: graphics/ccc.gif 91939B1E-1C14-47D3-91F8-511C4BBBAB08:2444328697755336707>" 

                 
Top


Special Edition Using Microsoft SharePoint Portal Server
Special Edition Using Microsoft SharePoint Portal Server
ISBN: 0789725703
EAN: 2147483647
Year: 2002
Pages: 286

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net