001: // DAVProperties.java
002: // $Id: DAVProperties.java,v 1.10 2000/10/12 16:19:20 bmahe Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.www.webdav.xml;
006:
007: import java.util.Date;
008: import java.util.Vector;
009:
010: import org.w3c.dom.Document;
011: import org.w3c.dom.Element;
012: import org.w3c.dom.Node;
013:
014: import org.w3c.util.DateParser;
015: import org.w3c.util.InvalidDateException;
016:
017: /**
018: * @version $Revision: 1.10 $
019: * @author Benoît Mahé (bmahe@w3.org)
020: */
021: public class DAVProperties extends DAVNode {
022:
023: public void addProperty(String name, String value) {
024: addDAVNode(name, value);
025: }
026:
027: public void addProperty(String name) {
028: addDAVNode(name, null);
029: }
030:
031: public Element[] getProperties() {
032: return getChildrenElements();
033: }
034:
035: public String[] getPropertyNames() {
036: return getDAVNodeNames();
037: }
038:
039: public String getProperty(String propname) {
040: return getTextChildValue(propname);
041: }
042:
043: public Date getCreationDate() {
044: String creationdate = getTextChildValue(CREATIONDATE_NODE);
045: if (creationdate != null) {
046: try {
047: return DateParser.parse(creationdate);
048: } catch (InvalidDateException ex) {
049: return null;
050: }
051: }
052: return null;
053: }
054:
055: public String getDisplayName() {
056: return getTextChildValue(DISPLAYNAME_NODE);
057: }
058:
059: public String getContentLanguage() {
060: return getTextChildValue(GETCONTENTLANGUAGE_NODE);
061: }
062:
063: public String getContentType() {
064: return getTextChildValue(GETCONTENTTYPE_NODE);
065: }
066:
067: public int getContentLength() {
068: String cl = getTextChildValue(GETCONTENTLENGTH_NODE);
069: if (cl != null) {
070: try {
071: return Integer.parseInt(cl);
072: } catch (Exception ex) {
073: return -1;
074: }
075: } else {
076: return -1;
077: }
078: }
079:
080: public String getETag() {
081: return getTextChildValue(GETETAG_NODE);
082: }
083:
084: public Date getLastModified() {
085: String lastmodified = getTextChildValue(GETLASTMODIFIED_NODE);
086: if (lastmodified != null) {
087: try {
088: return DateParser.parse(lastmodified);
089: } catch (InvalidDateException ex) {
090: return null;
091: }
092: }
093: return null;
094: }
095:
096: public String getLockDiscovery() {
097: return getTextChildValue(LOCKDISCOVERY_NODE);
098: }
099:
100: public String getResourceType() {
101: return getTextChildValue(RESOURCETYPE_NODE);
102: }
103:
104: public DAVLink[] getSources() {
105: Vector vnodes = getDAVElementsByTagName(SOURCE_NODE);
106: int len = vnodes.size();
107: DAVLink links[] = new DAVLink[len];
108: for (int i = 0; i < len; i++) {
109: links[i] = new DAVLink((Element) vnodes.elementAt(i));
110: }
111: return links;
112: }
113:
114: public DAVLockEntry[] getSupportedLocks() {
115: Vector vnodes = getDAVElementsByTagName(SUPPORTEDLOCK_NODE);
116: int len = vnodes.size();
117: DAVLockEntry locks[] = new DAVLockEntry[len];
118: for (int i = 0; i < len; i++) {
119: locks[i] = new DAVLockEntry((Element) vnodes.elementAt(i));
120: }
121: return locks;
122: }
123:
124: public void setResourceType(String type) {
125: Document doc = element.getOwnerDocument();
126: Node rtn = DAVNode.getDAVNode(element, RESOURCETYPE_NODE);
127: Element rtype = DAVFactory.createDAVElement(doc,
128: RESOURCETYPE_NODE);
129: if (type != null) {
130: DAVNode.addDAVNode(rtype, type, null);
131: }
132: if (rtn != null) {
133: element.replaceChild(rtype, rtn);
134: } else {
135: element.appendChild(rtype);
136: }
137: }
138:
139: DAVProperties(Element element) {
140: super(element);
141: }
142:
143: }
|