1 19 package org.openharmonise.webdav.client.methods; 20 21 import javax.xml.parsers.*; 22 23 import org.openharmonise.commons.xml.*; 24 import org.openharmonise.commons.xml.namespace.*; 25 import org.openharmonise.webdav.client.*; 26 import org.w3c.dom.*; 27 28 29 36 public class Lock extends AbstractWebDAVMethod { 37 38 41 public static String METHOD_NAME = "LOCK"; 42 43 46 public static final String LOCK_EXCLUSIVE = "exclusive"; 47 48 51 public static final String LOCK_SHARED = "shared"; 52 53 56 private String m_sLockType = "exclusive"; 57 58 61 private String m_sOwner = null; 62 63 68 public Lock(String sURL) { 69 super(METHOD_NAME, sURL); 70 } 71 72 77 public void setLockType(String sLockType) { 78 if( sLockType.equals(LOCK_EXCLUSIVE) || sLockType.equals(LOCK_SHARED)) { 79 this.m_sLockType = sLockType; 80 } 81 } 82 83 88 public void setOwner(String sOwner) { 89 this.m_sOwner = sOwner; 90 } 91 92 public byte[] getData() { 93 94 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 95 factory.setNamespaceAware(true); 96 Document xmlDoc = null; 97 try { 98 xmlDoc = factory.newDocumentBuilder().newDocument(); 99 } catch (ParserConfigurationException e) { 100 e.printStackTrace(); 101 } 102 103 Element elLockInfo = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"lockinfo"); 104 xmlDoc.appendChild(elLockInfo); 105 106 Element elLockScope = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"lockscope"); 107 elLockInfo.appendChild(elLockScope); 108 Element elLockScopeVal = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,this.m_sLockType); 109 elLockScope.appendChild(elLockScopeVal); 110 111 Element elLockType = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"locktype"); 112 elLockInfo.appendChild(elLockType); 113 Element elLockTypeVal = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"write"); 114 elLockType.appendChild(elLockTypeVal); 115 116 XMLPrettyPrint printer = new XMLPrettyPrint(); 117 printer.setNamespaceAware(true); 118 119 String sXML = null; 120 try { 121 sXML = printer.printNode(xmlDoc.getDocumentElement()); 122 } catch (NamespaceClashException e1) { 123 e1.printStackTrace(); 124 } 125 126 return sXML.getBytes(); 127 } 128 129 } 130 | Popular Tags |