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 vocabulary type properties.
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class ValueRange extends AbstractRange implements Range {
040:
041: /**
042: * List of full paths to virtual files for values that are valid for this range.
043: */
044: private ArrayList m_aValueGroups = new ArrayList();
045:
046: /**
047: *
048: */
049: public ValueRange() {
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 = ((ValueValue) value).getValue();
060:
061: Iterator iter = m_aValueGroups.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: public List getValueGroups() {
074: ArrayList aVals = new ArrayList();
075: Iterator itor = this .m_aValueGroups.iterator();
076: while (itor.hasNext()) {
077: String sHREF = (String) itor.next();
078: ValueGroup val = ValueCache.getInstance().getValueGroup(
079: sHREF);
080: aVals.add(val);
081: }
082:
083: return aVals;
084: }
085:
086: public List getHREFs() {
087: return this .m_aValueGroups;
088: }
089:
090: public void setHREFs(List aHREFs) {
091: this .m_aValueGroups = new ArrayList(aHREFs);
092: }
093:
094: public void setValueGroups(List aValueGroups) {
095: this .m_aValueGroups = new ArrayList(aValueGroups);
096: }
097:
098: /* (non-Javadoc)
099: * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
100: */
101: public void instantiate(Element elRange) {
102: NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href");
103: for (int i = 0; i < nl.getLength(); i++) {
104: Element elHREF = (Element) nl.item(i);
105: if (elHREF.getParentNode().getLocalName().equalsIgnoreCase(
106: "property")) {
107: if (elHREF.getChildNodes().getLength() == 1) {
108: Node node = elHREF.getFirstChild();
109: if (node.getNodeType() == Node.TEXT_NODE) {
110: //this.m_aHREFs.add( ((Text)node).getNodeValue() );
111: }
112: }
113: }
114: }
115:
116: nl = elRange
117: .getElementsByTagNameNS(
118: "http://www.simulacramedia.com/harmoniseclient/propdefs",
119: "valuegroups");
120: for (int i = 0; i < nl.getLength(); i++) {
121: Element elValue = (Element) nl.item(i);
122: NodeList nl2 = elValue.getElementsByTagNameNS("DAV:",
123: "href");
124: for (int j = 0; j < nl2.getLength(); j++) {
125: Element elHREF = (Element) nl2.item(j);
126: if (elHREF.getChildNodes().getLength() == 1) {
127: Node node = elHREF.getFirstChild();
128: if (node.getNodeType() == Node.TEXT_NODE) {
129: String sHREF = ((Text) node).getNodeValue();
130: this .m_aValueGroups.add(sHREF);
131: }
132: }
133: }
134: }
135: }
136:
137: public String toString() {
138: StringBuffer sBuff = new StringBuffer();
139:
140: sBuff.append("ValueRange:\n");
141:
142: sBuff.append("Values:\n");
143: Iterator itor = this .m_aValueGroups.iterator();
144: while (itor.hasNext()) {
145: ValueGroup val = ValueCache.getInstance().getValueGroup(
146: (String) itor.next());
147: sBuff.append(val).append("\n");
148: }
149:
150: return sBuff.toString();
151: }
152:
153: }
|