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 org.w3c.dom.Element;
022: import org.w3c.dom.Node;
023: import org.w3c.dom.NodeList;
024: import org.w3c.dom.Text;
025:
026: /**
027: * Represents a value in a vocabulary.
028: *
029: * @author Matthew Large
030: * @version $Revision: 1.1 $
031: *
032: */
033: public class Value {
034:
035: /**
036: * Name.
037: */
038: private String m_sName = null;
039:
040: /**
041: * Full path to the virtual file for the value.
042: */
043: private String m_sHREF = null;
044:
045: /**
046: * Display name.
047: */
048: private String m_sDisplayName = null;
049:
050: public Value() {
051: super ();
052: }
053:
054: /**
055: * Construcs a new value
056: *
057: * @param sName Name
058: * @param sPath Full path
059: */
060: public Value(String sName, String sPath) {
061: super ();
062: this .m_sName = sName;
063: this .m_sHREF = sPath;
064: this .m_sDisplayName = sName;
065: }
066:
067: /**
068: * Sets the name of this value.
069: *
070: * @param sName Name
071: */
072: public void setName(String sName) {
073: this .m_sName = sName;
074: }
075:
076: /**
077: * Sets the display name for this value
078: *
079: * @param sDisplayName Display name
080: */
081: public void setDisplayName(String sDisplayName) {
082: this .m_sDisplayName = sDisplayName;
083: }
084:
085: /**
086: * Returns the display name for this value.
087: *
088: * @return Display name
089: */
090: public String getDisplayName() {
091: return this .m_sDisplayName;
092: }
093:
094: /**
095: * Returns the name for this value.
096: *
097: * @return Name
098: */
099: public String getName() {
100: return this .m_sName;
101: }
102:
103: /**
104: * Returns the full path to the virtual file for this value.
105: *
106: * @return Full path
107: */
108: public String getHREF() {
109: return this .m_sHREF;
110: }
111:
112: public void instantiate(Element elValue) {
113: this .m_sName = elValue
114: .getAttributeNS(
115: "http://www.simulacramedia.com/harmoniseclient/propdefs",
116: "name");
117: NodeList nl = elValue.getChildNodes();
118: for (int i = 0; i < nl.getLength(); i++) {
119: Node node = nl.item(i);
120: if (node.getNodeType() == Node.ELEMENT_NODE) {
121: Element element = (Element) node;
122: if (element.getLocalName().equalsIgnoreCase(
123: "displayname")) {
124: Node node2 = element.getFirstChild();
125: if (node2.getNodeType() == Node.TEXT_NODE) {
126: this .m_sDisplayName = ((Text) node2)
127: .getNodeValue();
128: }
129: } else if (element.getLocalName().equalsIgnoreCase(
130: "href")) {
131: Node node2 = element.getFirstChild();
132: if (node2.getNodeType() == Node.TEXT_NODE) {
133: this .m_sHREF = ((Text) node2).getNodeValue();
134: }
135: }
136: }
137: }
138: }
139:
140: public String toString() {
141: StringBuffer sBuff = new StringBuffer();
142:
143: sBuff.append("Value: [").append(this .m_sName).append("]\n")
144: .append("DisplayName: ").append(this .m_sDisplayName)
145: .append("\n").append("Path: ").append(this .m_sHREF)
146: .append("\n");
147:
148: return sBuff.toString();
149: }
150:
151: }
|