1 23 package org.apache.webdav.lib.properties; 24 25 import java.util.ArrayList ; 26 import org.apache.webdav.lib.BaseProperty; 27 import org.apache.webdav.lib.Lock; 28 import org.apache.webdav.lib.ResponseEntity; 29 import org.apache.webdav.lib.util.DOMUtils; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.NodeList ; 32 33 36 public class SupportedLockProperty extends BaseProperty { 37 38 39 41 42 45 public static final String TAG_NAME = "supportedlock"; 46 47 48 50 51 54 public SupportedLockProperty(ResponseEntity response, Element element) { 55 super(response, element); 56 } 57 58 59 61 62 63 68 public Lock[] getLockEntries() { 69 NodeList children = element.getChildNodes(); 70 if (children == null || children.getLength() == 0) 71 return null; 72 ArrayList locks = new ArrayList (); 73 for (int i = 0; i < children.getLength(); i++) { 74 try { 75 Element child = (Element ) children.item(i); 76 String namespace = DOMUtils.getElementNamespaceURI(child); 77 if (namespace != null && namespace.equals("DAV:")) { 78 String localName = DOMUtils.getElementLocalName(child); 79 if ("lockentry".equals(localName)) { 80 locks.add(parseLock(child)); 81 } 82 } 83 } catch (ClassCastException e) { 84 } 85 } 86 return (Lock[]) locks.toArray(new Lock[locks.size()]); 87 } 88 89 90 92 93 96 protected Lock parseLock(Element element) { 97 98 int ls = -1; 99 Element child = DOMUtils.getFirstElement(element, "DAV:", "lockscope"); 100 if (child != null) { 101 Element lockScope = 102 DOMUtils.getFirstElement(child, "DAV:", "exclusive"); 103 if (lockScope != null) { 104 ls = Lock.SCOPE_EXCLUSIVE; 105 } 106 lockScope = DOMUtils.getFirstElement(child, "DAV:", "shared"); 107 if (lockScope != null) { 108 ls = Lock.SCOPE_SHARED; 109 } 110 } 111 112 int lt = -1; 113 child = DOMUtils.getFirstElement(element, "DAV:", "locktype"); 114 if (child != null) { 115 Element lockType = 116 DOMUtils.getFirstElement(child, "DAV:", "write"); 117 if (lockType != null) { 118 lt = Lock.TYPE_WRITE; 119 } 120 } 121 122 return new Lock(ls, lt); 123 } 124 125 public String getPropertyAsString() { 126 Lock[] locks = getLockEntries(); 127 128 if ((locks==null) || (locks.length==0)) 129 return ""; 130 131 StringBuffer tmp = new StringBuffer (locks[0].toString()); 132 for (int i=1; i<locks.length ; i++) { 133 tmp.append(", "); 134 tmp.append(locks[i].toString()); 135 } 136 137 return tmp.toString(); 138 } 139 } 140 141 142 | Popular Tags |