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 | */
|
---|
27 | package org.greenstone.gatherer.cdm;
|
---|
28 | /**************************************************************************************
|
---|
29 | * Written:
|
---|
30 | * Revised: 28/06/03 - DOM support
|
---|
31 | **************************************************************************************/
|
---|
32 | import org.greenstone.gatherer.Configuration;
|
---|
33 | import org.greenstone.gatherer.Gatherer;
|
---|
34 | import org.greenstone.gatherer.cdm.CollectionConfiguration;
|
---|
35 | import org.greenstone.gatherer.cdm.CollectionDesignManager;
|
---|
36 | import org.greenstone.gatherer.cdm.DOMProxyListEntry;
|
---|
37 | import org.greenstone.gatherer.cdm.Index;
|
---|
38 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
39 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
40 | import org.greenstone.gatherer.util.Utility;
|
---|
41 | import org.w3c.dom.*;
|
---|
42 | /** This class encapsulates a single collection level metadata assignment, which constitutes a name, language and value.
|
---|
43 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
44 | * @version 2.4
|
---|
45 | */
|
---|
46 | public class CollectionMeta
|
---|
47 | implements DOMProxyListEntry {
|
---|
48 | private Element element;
|
---|
49 | private String text;
|
---|
50 |
|
---|
51 | /** Constructor.
|
---|
52 | * @param element the Element from which we will determine metadata details
|
---|
53 | */
|
---|
54 | public CollectionMeta(Element element) {
|
---|
55 | this.element = element;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /** Constructor to create a new piece of metadata given its name. */
|
---|
59 | public CollectionMeta(String name) {
|
---|
60 | element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
61 | element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
62 | element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.interface_language);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /** Constructor to create a new piece of metadata given its name. */
|
---|
66 | public CollectionMeta(String name, String language) {
|
---|
67 | element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
68 | element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
69 | element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** Method to compare two collection metadata objects to calculate their respective ordering.
|
---|
73 | * @param object the other metadata to compare to, as an Object
|
---|
74 | * @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.
|
---|
75 | * @see org.greenstone.gatherer.cdm.Language
|
---|
76 | */
|
---|
77 | public int compareTo(Object object) {
|
---|
78 | return toString().compareTo(object.toString());
|
---|
79 | }
|
---|
80 |
|
---|
81 | /** Factory constructor. */
|
---|
82 | public DOMProxyListEntry create(Element element) {
|
---|
83 | return new CollectionMeta(element);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /** Method to compare two collection metadata objects for equality.
|
---|
87 | * @param object The other metadata to compare to, as an <strong>Object</strong>.
|
---|
88 | * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise.
|
---|
89 | */
|
---|
90 | public boolean equals(Object object) {
|
---|
91 | return (compareTo(object) == 0);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public Element getElement() {
|
---|
95 | return element;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /** Method to retrieve the value of language.
|
---|
99 | * @return The value of language as a <strong>String</strong>.
|
---|
100 | */
|
---|
101 | public String getLanguage() {
|
---|
102 | // Retrieve the language string
|
---|
103 | return element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /** Method to retrieve the value of name.
|
---|
107 | * @return
|
---|
108 | */
|
---|
109 | public String getName() {
|
---|
110 | return element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
111 | }
|
---|
112 | /** Method to retrieve the value of value (well great choice of name there).
|
---|
113 | * @return The value of value as a <strong>String</strong>.
|
---|
114 | */
|
---|
115 | public String getValue() {
|
---|
116 | // We have to replace the string made of '\' 'n' with the '\n' character! Also watch for other greenstone magic
|
---|
117 | return Utility.decodeGreenstone(MSMUtils.getValue(element));
|
---|
118 | }
|
---|
119 |
|
---|
120 | public boolean isAssigned() {
|
---|
121 | return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** Determine if this metadata is one of the four special pieces of metadata.
|
---|
125 | * @return true if this metadata is special, false otherwise.
|
---|
126 | */
|
---|
127 | public boolean isSpecial() {
|
---|
128 | return (element != null && element.getAttribute(StaticStrings.SPECIAL_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
129 | }
|
---|
130 |
|
---|
131 | public void setAssigned(boolean assigned) {
|
---|
132 | if(element != null) {
|
---|
133 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | public void setElement(Element element) {
|
---|
138 | this.element = element;
|
---|
139 | text = null;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /** Change the value of value.
|
---|
143 | * @param value the new value as a String.
|
---|
144 | */
|
---|
145 | public void setValue(String value) {
|
---|
146 | MSMUtils.setValue(element, Utility.encodeGreenstone(value));
|
---|
147 | text = null; // Reset text
|
---|
148 | }
|
---|
149 |
|
---|
150 | /** Method to print out this class as it would appear within the collection configuration file.
|
---|
151 | * @return A <strong>String</strong> containing the text value of this class.
|
---|
152 | */
|
---|
153 | public String toString() {
|
---|
154 | if(text == null) {
|
---|
155 | text = CollectionConfiguration.toString(element, true);
|
---|
156 | }
|
---|
157 | return text;
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|