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 | * Copyright (C) 2022 New Zealand Digital Library Project
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *########################################################################
|
---|
24 | */
|
---|
25 | package org.greenstone.gatherer.cdm;
|
---|
26 |
|
---|
27 | import org.greenstone.gatherer.Gatherer;
|
---|
28 | import org.greenstone.gatherer.Configuration;
|
---|
29 | import org.greenstone.gatherer.util.Codec;
|
---|
30 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
31 | import org.greenstone.gatherer.util.XMLTools;
|
---|
32 | import org.w3c.dom.*;
|
---|
33 |
|
---|
34 |
|
---|
35 | /** This class encapsulates a single search metadata assignment, which constitutes a name, language and value and type
|
---|
36 | */
|
---|
37 | public class SearchMeta
|
---|
38 | extends CollectionMeta {
|
---|
39 |
|
---|
40 | public static final String TYPE_INDEX = "index";
|
---|
41 | public static final String TYPE_LEVEL = "level";
|
---|
42 | public static final String TYPE_PARTITION = "partition";
|
---|
43 | public static final String TYPE_LANGUAGE = "language";
|
---|
44 | public static final String TYPE_SORT = "sort";
|
---|
45 | public static final String TYPE_FACET = "facet";
|
---|
46 |
|
---|
47 | // public SearchMeta() {
|
---|
48 | //}
|
---|
49 | /** Constructor.
|
---|
50 | * @param element the Element from which we will determine metadata details
|
---|
51 | */
|
---|
52 | public SearchMeta(Element element) {
|
---|
53 | System.err.println("new search meta, elem = ");
|
---|
54 | System.err.println(XMLTools.xmlNodeToString(element));
|
---|
55 | this.element = element;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public SearchMeta(String name) {
|
---|
59 | System.err.println("error calling new search meta with only a name");
|
---|
60 | }
|
---|
61 | /** Constructor to create a new piece of metadata given its name. */
|
---|
62 | public SearchMeta(String name, String type) {
|
---|
63 | this(name, type, Configuration.getLanguage());
|
---|
64 | // element = CollectionConfiguration.createElement(StaticStrings.SEARCHMETADATA_ELEMENT);
|
---|
65 | // element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
66 | // element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Configuration.getLanguage());
|
---|
67 | // element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
68 | // element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** Constructor to create a new piece of metadata given its name. */
|
---|
72 | public SearchMeta(String name, String type, String language) {
|
---|
73 | element = CollectionConfiguration.createElement(StaticStrings.SEARCHMETADATA_ELEMENT);
|
---|
74 | element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
75 | element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language);
|
---|
76 | element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
77 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /** Constructor to create a new piece of metadata given its name. */
|
---|
81 | public SearchMeta(String name, String type, String language, boolean dummy) {
|
---|
82 | this(name, type, language);
|
---|
83 | this.dummy = dummy;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /** Method to compare two collection metadata objects to calculate their respective ordering.
|
---|
87 | * @param object the other metadata to compare to, as an Object
|
---|
88 | * @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.
|
---|
89 | * @see org.greenstone.gatherer.cdm.Language
|
---|
90 | */
|
---|
91 | // todo this soesn't look at type
|
---|
92 | public int compareTo(Object object) {
|
---|
93 | return toString().compareTo(object.toString());
|
---|
94 | }
|
---|
95 |
|
---|
96 | /** Factory constructor. */
|
---|
97 | public DOMProxyListEntry create(Element element) {
|
---|
98 | return new SearchMeta(element);
|
---|
99 | }
|
---|
100 |
|
---|
101 | /** Method to compare two collection metadata objects for equality.
|
---|
102 | * @param object The other metadata to compare to, as an <strong>Object</strong>.
|
---|
103 | * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise.
|
---|
104 | */
|
---|
105 | public boolean equals(Object object) {
|
---|
106 | // System.err.println("running search meta equals");
|
---|
107 | // if (object instanceof SearchMeta) {
|
---|
108 | // if (compareTo(object) == 0 && getType().equals(((SearchMeta)object).getType())) {
|
---|
109 | // return true;
|
---|
110 | // }
|
---|
111 | // }
|
---|
112 | // return false;
|
---|
113 | return (compareTo(object) == 0);
|
---|
114 | }
|
---|
115 |
|
---|
116 | // public Element getElement() {
|
---|
117 | // return element;
|
---|
118 | // }
|
---|
119 |
|
---|
120 | // /** Method to retrieve the value of language.
|
---|
121 | // * @return the value of language as a <strong>String</strong>.
|
---|
122 | // */
|
---|
123 | // public String getLanguage() {
|
---|
124 | // // Retrieve the language string
|
---|
125 | // return element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
|
---|
126 | // }
|
---|
127 |
|
---|
128 | // /** Method to retrieve the value of name.
|
---|
129 | // * @return the name attribute of the collection meta as a String
|
---|
130 | // */
|
---|
131 | // public String getName() {
|
---|
132 | // return element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
133 | // }
|
---|
134 | // /** Method to retrieve the value of value (well great choice of name there).
|
---|
135 | // * @return The value of value as a <strong>String</strong>.
|
---|
136 | // */
|
---|
137 | // public String getValue(boolean text_value) {
|
---|
138 | // String raw_value = XMLTools.getValue(element);
|
---|
139 | // // Decode the raw value depending on whether the user asked for the TEXT or GREENSTONE version
|
---|
140 | // if(text_value == TEXT) {
|
---|
141 | // return Codec.transform(raw_value, Codec.DOM_TO_TEXT);
|
---|
142 | // }
|
---|
143 | // else {
|
---|
144 | // return Codec.transform(raw_value, Codec.DOM_TO_GREENSTONE);
|
---|
145 | // }
|
---|
146 | // }
|
---|
147 |
|
---|
148 | // public boolean isAssigned() {
|
---|
149 | // return (element != null && !element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR));
|
---|
150 | // }
|
---|
151 |
|
---|
152 | // public boolean isDummy() {
|
---|
153 | // return dummy;
|
---|
154 | // }
|
---|
155 |
|
---|
156 | // /** Determine if this metadata is one of the four special pieces of metadata.
|
---|
157 | // * @return true if this metadata is special, false otherwise.
|
---|
158 | // */
|
---|
159 | // public boolean isSpecial() {
|
---|
160 | // return (element != null && element.getAttribute(StaticStrings.SPECIAL_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
161 | // }
|
---|
162 |
|
---|
163 | // public void setAssigned(boolean assigned) {
|
---|
164 | // if(element != null) {
|
---|
165 | // element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
166 | // }
|
---|
167 | // }
|
---|
168 |
|
---|
169 | // public void setElement(Element element) {
|
---|
170 | // this.element = element;
|
---|
171 | // text = null;
|
---|
172 | // }
|
---|
173 |
|
---|
174 | // /** Change the value of value.
|
---|
175 | // * @param raw_value the new value as a String.
|
---|
176 | // */
|
---|
177 | // public void setValue(String raw_value) {
|
---|
178 | // setValue(raw_value, false);
|
---|
179 | // }
|
---|
180 |
|
---|
181 | // public void setValue(String raw_value, boolean preserveTags) {
|
---|
182 | // // we need to check if the value has changed
|
---|
183 | // String current_value = XMLTools.getValue(element);
|
---|
184 |
|
---|
185 | // String new_value = preserveTags ?
|
---|
186 | // Codec.transform(raw_value, Codec.TEXT_TO_DOM_PRESERVE_TAGS)
|
---|
187 | // : Codec.transform(raw_value, Codec.TEXT_TO_DOM);
|
---|
188 | // if (!current_value.equals(new_value)) {
|
---|
189 | // // Only raw html text can be given to setValue so we need to encode it
|
---|
190 | // XMLTools.setValue(element, new_value);
|
---|
191 | // text = null; // Reset text
|
---|
192 | // // And determine if this makes the metadata assigned
|
---|
193 | // setAssigned(raw_value != null && raw_value.length() > 0);
|
---|
194 | // }
|
---|
195 | // }
|
---|
196 |
|
---|
197 | public void setType(String type) {
|
---|
198 | if(element != null) {
|
---|
199 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
200 | }
|
---|
201 | }
|
---|
202 | public String getType() {
|
---|
203 | if (element != null) {
|
---|
204 | return element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
205 | }
|
---|
206 | return null;
|
---|
207 | }
|
---|
208 | public boolean hasType() {
|
---|
209 | return element.hasAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
210 | }
|
---|
211 | /** Method to print out this class as it would appear within the collection configuration file.
|
---|
212 | * @return A <strong>String</strong> containing the text value of this class.
|
---|
213 | */
|
---|
214 | /** what is this used for???? */
|
---|
215 | public String toString() {
|
---|
216 | if(text == null) {
|
---|
217 | text = "searchmeta ["+getType()+"] [l="+getLanguage()+"] \""+getName()+"\"";
|
---|
218 | }
|
---|
219 | // text = CollectCfgReadWrite.toString(element); // this puts a dot in now. don't want that. but it also adds the language
|
---|
220 | // if (text.equals("")){
|
---|
221 | // text = getName();
|
---|
222 | // }
|
---|
223 | // }
|
---|
224 | return text;
|
---|
225 | }
|
---|
226 | }
|
---|