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 collection relationship type properties.
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class CollectionRange 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(3);
045:
046: /**
047: *
048: */
049: public CollectionRange() {
050: super ();
051: }
052:
053: /* (non-Javadoc)
054: * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
055: */
056: public ValidationResult validate(ValueInstance value) {
057: boolean bIsValid = false;
058:
059: String sValue = ((ResourceValue) value).getValue();
060:
061: Iterator iter = m_aHREFs.iterator();
062:
063: while (iter.hasNext() && bIsValid == false) {
064: String sPath = (String) iter.next();
065: if (sValue.startsWith(sPath)) {
066: bIsValid = true;
067: }
068: }
069:
070: return new ValidationResult(bIsValid, "");
071: }
072:
073: /* (non-Javadoc)
074: * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
075: */
076: public void instantiate(Element elRange) {
077: NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href");
078: for (int i = 0; i < nl.getLength(); i++) {
079: Element elHREF = (Element) nl.item(i);
080: if (elHREF.getChildNodes().getLength() == 1) {
081: Node node = elHREF.getFirstChild();
082: if (node.getNodeType() == Node.TEXT_NODE) {
083: this .m_aHREFs.add(((Text) node).getNodeValue());
084: }
085: }
086: }
087: }
088:
089: /**
090: * Returns a list of collections which contain valid values.
091: *
092: * @return List of full paths
093: */
094: public List getHREFs() {
095: return (List) this .m_aHREFs.clone();
096: }
097:
098: /**
099: * Sets the list of collections which contain valid values.
100: *
101: * @param aHREFs List of full paths
102: */
103: public void setHREFs(List aHREFs) {
104: this .m_aHREFs = new ArrayList(aHREFs);
105: }
106:
107: public String toString() {
108: StringBuffer sBuff = new StringBuffer();
109:
110: sBuff.append("CollectionRange:\n");
111: Iterator itor = this .m_aHREFs.iterator();
112: while (itor.hasNext()) {
113: sBuff.append("HREF: ").append(((String) itor.next()))
114: .append("\n");
115: }
116:
117: return sBuff.toString();
118: }
119:
120: }
|