1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.Vector ; 29 import org.apache.webdav.lib.PropertyName; 30 import org.apache.webdav.lib.util.XMLPrinter; 31 32 38 public class PropertyBodyHelper { 39 40 protected PropertyName[] propertyNames; 41 42 49 protected void setPropertyNames(Collection propertyNames) { 50 Vector list = new Vector (); 51 Iterator propertyIterator = propertyNames.iterator(); 52 while (propertyIterator.hasNext()) { 53 Object item = propertyIterator.next(); 54 55 if (item instanceof PropertyName) { 56 list.add(item); 57 58 } else if (item instanceof String ) { 59 String propertyName = (String ) item; 60 int length = propertyName.length(); 61 boolean found = false; 62 int i = 1; 63 while (!found && (i <= length)) { 64 char chr = propertyName.charAt(length - i); 65 if (!Character.isUnicodeIdentifierPart(chr) 66 && chr != '-' 67 && chr != '_' 68 && chr != '.') { 69 found = true; 70 } else { 71 i++; 72 } 73 } 74 if ((i == 1) || (i >= length)) { 75 list.add(new PropertyName("DAV:", propertyName)); 76 } else { 77 String namespace = propertyName.substring(0, length + 1 - i); 78 String localName = propertyName.substring(length + 1 - i); 79 list.add(new PropertyName(namespace, localName)); 80 } 81 } else { 82 } 85 } 86 this.propertyNames = 87 (PropertyName[]) list.toArray(new PropertyName[list.size()]); 88 } 89 90 100 protected void wirtePropElement(XMLPrinter printer) { 101 if (propertyNames != null) { 102 printer.writeElement("D", "prop", XMLPrinter.OPENING); 103 for (int i = 0; i < propertyNames.length; i++) { 104 String namespace = propertyNames[i].getNamespaceURI(); 105 String localname = propertyNames[i].getLocalName(); 106 if ("DAV:".equals(namespace)) { 107 printer.writeElement("D", localname, XMLPrinter.NO_CONTENT); 108 } else { 109 printer.writeElement("ZZ", namespace, localname, XMLPrinter.NO_CONTENT); 110 } 111 } 112 printer.writeElement("D", "prop", XMLPrinter.CLOSING); 113 } 114 } 115 } 116 | Popular Tags |