source: trunk/gli/src/org/greenstone/gatherer/msm/Metadata.java@ 8022

Last change on this file since 8022 was 7290, checked in by kjdon, 20 years ago

modified the getAbsolutePath method - it was not returning the whole path for hierarchical metadata

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.msm;
38
39import java.io.*;
40import org.greenstone.gatherer.Gatherer;
41import org.greenstone.gatherer.collection.Collection;
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.msm.ElementWrapper;
44import org.greenstone.gatherer.msm.MetadataSetManager;
45import org.greenstone.gatherer.valuetree.GValueModel;
46import org.greenstone.gatherer.valuetree.GValueNode;
47import org.greenstone.gatherer.util.StaticStrings;
48import org.w3c.dom.Element;
49/** Stores a mapping between a particular metadata element, and a certain value node.
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.3
52 */
53public class Metadata
54 implements Comparable {
55 /** Is this an accumulating piece of metadata? */
56 private boolean accumulate = false;
57 /** Indicates what level of metadata this is, relative to the file it was retrieved for. */
58 private boolean file_level = true;
59 /** The file for which this metadata was retrieved. This allows us to determine the source of folder level metadata. */
60 private File file;
61 /** The value node this metadata maps to. */
62 private GValueNode value = null;
63 /** Used to count the number of references to this piece of metadata within the metadata table. */
64 private int count = 1;
65 /** The metadata element this metadata maps to. */
66 private ElementWrapper element = null;
67 /** Constructs a new Metadata object with no current value.
68 * @param element The <strong>ElementWrapper</strong> associated with this metadata.
69 */
70 public Metadata(ElementWrapper element) {
71 super();
72 this.element = element;
73 this.value = null;
74 }
75 /** Default constructor simply creates a new Metadata object based on the given parameters.
76 * @param element The <strong>ElementWrapper</strong> associated with this metadata.
77 * @param value The assigned value for the given element, as a <strong>GValueNode</strong>.
78 */
79 public Metadata(ElementWrapper element, GValueNode value) {
80 super();
81 this.element = element;
82 this.value = value;
83 }
84 /** Constructs a new Metadata object, given the value. The metadata element is extracted from the value tree information.
85 * @param value The assigned value for the given element, as a <strong>GValueNode</strong>.
86 * @see org.greenstone.gatherer.Gatherer
87 * @see org.greenstone.gatherer.collection.CollectionManager
88 * @see org.greenstone.gatherer.msm.MetadataSetManager
89 */
90 public Metadata(GValueNode value) {
91 super();
92 this.element = Gatherer.c_man.getCollection().msm.getElement(value.getMetadataElementName());
93 this.value = value;
94 }
95 /** Determine if this metadata overwrites or accumulates. */
96 public boolean accumulates() {
97 return accumulate;
98 }
99 /** Compares two Metadata objects for ordering purposes.
100 * @param object The other metadata as an <strong>Object</strong>.
101 * @return An <i>int</i> value as specified in java.lang.String#compareTo
102 * @see java.lang.String#compareTo
103 */
104 public int compareTo(Object object) {
105 return toString().compareTo(object.toString());
106 }
107 /** Decrease the reference count by 1. */
108 public void dec() {
109 count--;
110 }
111 /** Tests to metadata objects for equality.
112 * @param object The other metadata as an <strong>Object</strong>.
113 * @return <i>true</i> if the metadata are equal, <i>false</i> otherwise.
114 */
115 public boolean equals(Object object) {
116 if(compareTo(object) == 0) {
117 return true;
118 }
119 return false;
120 }
121 /** Determine the absolute path value of this metadata, taking into account whether this value is hierarchical. */
122 public String getAbsoluteValue() {
123 String abs_result = "";
124 if(value != null) {
125 //abs_result = value.toString(GValueNode.GREENSTONE);
126 abs_result = value.getFullPath(false);
127 }
128 return abs_result;
129 }
130
131 /** Retrieve the reference count.
132 * @return The count as an <i>int</i>.
133 */
134 public int getCount() {
135 return count;
136 }
137 /** Retrieve the element associated with this metadata.
138 * @return An <strong>ElementWrapper</strong>.
139 */
140 public ElementWrapper getElement() {
141 return element;
142 }
143
144 /** Retrieve the source file if any. */
145 public File getFile() {
146 return file;
147 }
148
149 /** Get the textual value of this metadata.
150 * @return A <strong>String</strong> representing the value of this Metadata. Note that if the value node is null, then the String returned is "".
151 */
152 public String getValue() {
153 String result = "";
154 if(value != null) {
155 result = value.toString();
156 }
157 return result;
158 }
159 /** Retrieve the value node associated with this metadata.
160 * @return A <strong>GValueNode</strong>.
161 */
162 public GValueNode getValueNode() {
163 return value;
164 }
165 /** Increase the reference count by 1. */
166 public void inc() {
167 count++;
168 }
169
170 /** Determine if this metadata is file level or folder level. */
171 public boolean isFileLevel() {
172 return file_level;
173 }
174
175 /** Inform this metadata whether it will accumulate with any other metadata of the same type. */
176 public void setAccumulate(boolean accumulate) {
177 this.accumulate = accumulate;
178 }
179 /** Sets the reference count.
180 * @param value The new value of count as an <i>int</i>.
181 */
182 public void setCount(int value) {
183 count = value;
184 }
185 /** Set the level of this metadata (whether it is associated with this file explicitly or found in some folder above this file). */
186 public void setFileLevel(boolean file_level) {
187 this.file_level = file_level;
188 }
189
190 /** Set the current source file for this metadata to the given collection. This value should not be counted are remaining valid at any time other than immediately after a getMetadata call as it is relative the the file that metadata call was for. */
191 public void setFile(File file) {
192 this.file = file;
193 }
194
195 /** Translates this object into a string representation.
196 * @return A <strong>String</strong>.
197 */
198 public String toString() {
199 return element.toString() + "=" + getValue();
200 }
201
202 /** Retrieve the value node associated with a certain value string. */
203 static final public GValueNode getDefaultValueNode(ElementWrapper element, String value) {
204 // Retrieve the GValueNode
205 GValueModel model = Gatherer.c_man.getCollection().msm.getValueTree(element);
206 GValueNode value_node;
207 if(model != null) {
208 value_node = model.getValue(value);
209 }
210 else {
211 value_node = new GValueNode(element.getName(), value);
212 }
213 model = null;
214 return value_node;
215 }
216}
Note: See TracBrowser for help on using the repository browser.