source: trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java@ 5903

Last change on this file since 5903 was 5899, checked in by jmt12, 21 years ago

Added a new constructor for 'dummy' collection metadata - ie that metadata which is used as a placeholder in managers such as the TranslationView but haven't actually been added to the collection configuration model

  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29/**************************************************************************************
30 * Written:
31 * Revised: 28/06/03 - DOM support
32 **************************************************************************************/
33import org.greenstone.gatherer.Configuration;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.cdm.CollectionConfiguration;
36import org.greenstone.gatherer.cdm.CollectionDesignManager;
37import org.greenstone.gatherer.cdm.DOMProxyListEntry;
38import org.greenstone.gatherer.cdm.Index;
39import org.greenstone.gatherer.msm.MSMUtils;
40import org.greenstone.gatherer.util.Codec;
41import org.greenstone.gatherer.util.StaticStrings;
42import org.greenstone.gatherer.util.Utility;
43import org.w3c.dom.*;
44/** This class encapsulates a single collection level metadata assignment, which constitutes a name, language and value.
45 * @author John Thompson, Greenstone Digital Library, University of Waikato
46 * @version 2.4
47 */
48public class CollectionMeta
49 implements DOMProxyListEntry {
50
51 static final public boolean TEXT = true;
52 static final public boolean GREENSTONE = false;
53
54 private boolean dummy = false;
55 private Element element;
56 private String text;
57
58 /** Constructor.
59 * @param element the Element from which we will determine metadata details
60 */
61 public CollectionMeta(Element element) {
62 this.element = element;
63 }
64
65 /** Constructor to create a new piece of metadata given its name. */
66 public CollectionMeta(String name) {
67 element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT);
68 element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
69 element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.interface_language);
70 }
71
72 /** Constructor to create a new piece of metadata given its name. */
73 public CollectionMeta(String name, String language) {
74 element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT);
75 element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
76 element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language);
77 }
78
79 /** Constructor to create a new piece of metadata given its name. */
80 public CollectionMeta(String name, String language, boolean dummy) {
81 this(name, language);
82 this.dummy = dummy;
83 }
84
85 /** Method to compare two collection metadata objects to calculate their respective ordering.
86 * @param object the other metadata to compare to, as an Object
87 * @return an int which is less than 0 if this object proceeds the given object, 0 if they are equal and greater than 0 otherwise.
88 * @see org.greenstone.gatherer.cdm.Language
89 */
90 public int compareTo(Object object) {
91 return toString().compareTo(object.toString());
92 }
93
94 /** Factory constructor. */
95 public DOMProxyListEntry create(Element element) {
96 return new CollectionMeta(element);
97 }
98
99 /** Method to compare two collection metadata objects for equality.
100 * @param object The other metadata to compare to, as an <strong>Object</strong>.
101 * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise.
102 */
103 public boolean equals(Object object) {
104 return (compareTo(object) == 0);
105 }
106
107 public Element getElement() {
108 return element;
109 }
110
111 /** Method to retrieve the value of language.
112 * @return The value of language as a <strong>String</strong>.
113 */
114 public String getLanguage() {
115 // Retrieve the language string
116 return element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
117 }
118
119 /** Method to retrieve the value of name.
120 * @return
121 */
122 public String getName() {
123 return element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
124 }
125 /** Method to retrieve the value of value (well great choice of name there).
126 * @return The value of value as a <strong>String</strong>.
127 */
128 public String getValue(boolean text_value) {
129 String raw_value = MSMUtils.getValue(element);
130 // Decode the raw value depending on whether the user asked for the TEXT or GREENSTONE version
131 if(text_value == TEXT) {
132 return Codec.transform(raw_value, Codec.DOM_TO_TEXT);
133 }
134 else {
135 return Codec.transform(raw_value, Codec.DOM_TO_GREENSTONE);
136 }
137 }
138
139 public boolean isAssigned() {
140 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
141 }
142
143 public boolean isDummy() {
144 return dummy;
145 }
146
147 /** Determine if this metadata is one of the four special pieces of metadata.
148 * @return true if this metadata is special, false otherwise.
149 */
150 public boolean isSpecial() {
151 return (element != null && element.getAttribute(StaticStrings.SPECIAL_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
152 }
153
154 public void setAssigned(boolean assigned) {
155 if(element != null) {
156 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
157 }
158 }
159
160 public void setElement(Element element) {
161 this.element = element;
162 text = null;
163 }
164
165 /** Change the value of value.
166 * @param value the new value as a String.
167 */
168 public void setValue(String raw_value) {
169 // Only raw html text can be given to setValue so we need to encode it
170 MSMUtils.setValue(element, Codec.transform(raw_value, Codec.TEXT_TO_DOM));
171 text = null; // Reset text
172 }
173
174 /** Method to print out this class as it would appear within the collection configuration file.
175 * @return A <strong>String</strong> containing the text value of this class.
176 */
177 public String toString() {
178 if(text == null) {
179 text = CollectionConfiguration.toString(element, true);
180 }
181 return text;
182 }
183}
Note: See TracBrowser for help on using the repository browser.