You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2003/04/02 14:59:08 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods PropertyBodyHelper.java

juergen     2003/04/02 04:59:08

  Added:       src/webdav/client/src/org/apache/webdav/lib/methods
                        PropertyBodyHelper.java
  Log:
  implemented WebDAVResource.aclReportMethod. thanks to Martin Dulisch [mdulisch@s-und-n.de] for the donation.
  
  Revision  Changes    Path
  1.1                  jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PropertyBodyHelper.java
  
  Index: PropertyBodyHelper.java
  ===================================================================
  package org.apache.webdav.lib.methods;
  
  import org.apache.util.XMLPrinter;
  import org.apache.webdav.lib.PropertyName;
  
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Vector;
  
  /**
   * This class manages an array of PropertyNames.
   * It is used to generate a <prop> tag section
   * in the body of a WebDAV method. 
   * 
   * @author Martin Dulisch, 07.02.2003
   */
  public class PropertyBodyHelper {
  
  	protected PropertyName[] propertyNames;
  
  	/**
  	 * Property names setter.
  	 * The enumeration may contain strings with or without a namespace prefix
  	 * but the preferred way is to provide PropertyName objects.
  	 *
  	 * @param propertyNames List of the property names
  	 */
  	protected void setPropertyNames(Collection propertyNames) {
  		Vector list = new Vector();
  		Iterator propertyIterator = propertyNames.iterator();
  		while (propertyIterator.hasNext()) {
  			Object item = propertyIterator.next();
  
  			if (item instanceof PropertyName) {
  				list.add(item);
  
  			} else if (item instanceof String) {
  				String propertyName = (String) item;
  				int length = propertyName.length();
  				boolean found = false;
  				int i = 1;
  				while (!found && (i <= length)) {
  					char chr = propertyName.charAt(length - i);
  					if (!Character.isUnicodeIdentifierPart(chr)
  						&& chr != '-'
  						&& chr != '_'
  						&& chr != '.') {
  						found = true;
  					} else {
  						i++;
  					}
  				}
  				if ((i == 1) || (i >= length)) {
  					list.add(new PropertyName("DAV:", propertyName));
  				} else {
  					String namespace = propertyName.substring(0, length + 1 - i);
  					String localName = propertyName.substring(length + 1 - i);
  					list.add(new PropertyName(namespace, localName));
  				}
  			} else {
  				// unknown type
  				// ignore
  			}
  		}
  		this.propertyNames =
  			(PropertyName[]) list.toArray(new PropertyName[list.size()]);
  	}
  
  	/**
  	 * Writes the <D:prop> element to a XMLPrinter.
  	 * The element contains all properties from the
  	 * propertyNames array. Result is:
  	 * <D:prop>
  	 *   <D:displayname/>
  	 *   <D:creationdate/>
  	 *   ...
  	 * </D:prop>
  	 */
  	protected void wirtePropElement(XMLPrinter printer) {
  		if (propertyNames != null) {
  			printer.writeElement("D", "prop", XMLPrinter.OPENING);
  			for (int i = 0; i < propertyNames.length; i++) {
  				String namespace = propertyNames[i].getNamespaceURI();
  				String localname = propertyNames[i].getLocalName();
  				if ("DAV:".equals(namespace)) {
  					printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
  				} else {
  					printer.writeElement("ZZ", namespace, localname, XMLPrinter.NO_CONTENT);
  				}
  			}
  			printer.writeElement("D", "prop", XMLPrinter.CLOSING);
  		}
  	}
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org