001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.metadata.range;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.openharmonise.vfs.metadata.*;
026: import org.openharmonise.vfs.metadata.value.*;
027: import org.w3c.dom.Element;
028: import org.w3c.dom.Node;
029: import org.w3c.dom.NodeList;
030: import org.w3c.dom.Text;
031:
032: /**
033: * This is the range for resource relationship type properties.
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class ResourceRange extends AbstractRange implements Range {
040:
041: /**
042: * List of full paths to collections which contain valid values.
043: */
044: private ArrayList m_aHREFs = new ArrayList();
045:
046: /**
047: * List of content types which are valid for this range.
048: */
049: private ArrayList m_aContentTypes = new ArrayList();
050:
051: /**
052: *
053: */
054: public ResourceRange() {
055: super ();
056: }
057:
058: /* (non-Javadoc)
059: * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
060: */
061: public ValidationResult validate(ValueInstance value) {
062: boolean bIsValid = false;
063:
064: String sValue = ((ResourceValue) value).getValue();
065:
066: Iterator iter = m_aHREFs.iterator();
067:
068: while (iter.hasNext() && bIsValid == false) {
069: String sPath = (String) iter.next();
070: if (sValue.startsWith(sPath)) {
071: bIsValid = true;
072: }
073: }
074:
075: return new ValidationResult(bIsValid, "");
076: }
077:
078: /**
079: * Returns a list of collections which contain valid values.
080: *
081: * @return List of full paths
082: */
083: public List getHREFs() {
084: return (List) this .m_aHREFs.clone();
085: }
086:
087: /**
088: * Sets the list of collections which contain valid values.
089: *
090: * @param aHREFs List of full paths
091: */
092: public void setHREFs(List aHREFs) {
093: this .m_aHREFs = new ArrayList(aHREFs);
094: }
095:
096: /**
097: * Returns a list of content types which are valid for this range.
098: *
099: * @return List of content types
100: */
101: public List getContentTypes() {
102: return (List) this .m_aContentTypes.clone();
103: }
104:
105: /**
106: * Sets the list of content types which are valid for this range.
107: *
108: * @param aContentTypes List of content types
109: */
110: public void setContentTypes(List aContentTypes) {
111: this .m_aContentTypes = new ArrayList(aContentTypes);
112: }
113:
114: /* (non-Javadoc)
115: * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
116: */
117: public void instantiate(Element elRange) {
118: NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href");
119: for (int i = 0; i < nl.getLength(); i++) {
120: Element elHREF = (Element) nl.item(i);
121: if (elHREF.getChildNodes().getLength() == 1) {
122: Node node = elHREF.getFirstChild();
123: if (node.getNodeType() == Node.TEXT_NODE) {
124: this .m_aHREFs.add(((Text) node).getNodeValue());
125: }
126: }
127: }
128:
129: nl = elRange.getElementsByTagNameNS("DAV:", "contenttype");
130: for (int i = 0; i < nl.getLength(); i++) {
131: Element elContentType = (Element) nl.item(i);
132: if (elContentType.getChildNodes().getLength() == 1) {
133: Node node = elContentType.getFirstChild();
134: if (node.getNodeType() == Node.TEXT_NODE) {
135: this .m_aContentTypes.add(((Text) node)
136: .getNodeValue());
137: }
138: }
139: }
140: }
141:
142: public String toString() {
143: StringBuffer sBuff = new StringBuffer();
144:
145: sBuff.append("ResourceRange:\n");
146: Iterator itor = this .m_aHREFs.iterator();
147: while (itor.hasNext()) {
148: sBuff.append("HREF: ").append(((String) itor.next()))
149: .append("\n");
150: }
151:
152: itor = this .m_aContentTypes.iterator();
153: while (itor.hasNext()) {
154: sBuff.append("Contenttype: ")
155: .append(((String) itor.next())).append("\n");
156: }
157:
158: return sBuff.toString();
159: }
160:
161: }
|