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 | import java.awt.*;
|
---|
30 | import java.awt.event.*;
|
---|
31 | import java.io.*;
|
---|
32 | import java.util.*;
|
---|
33 | import javax.swing.*;
|
---|
34 | import org.greenstone.gatherer.Configuration;
|
---|
35 | import org.greenstone.gatherer.DebugStream;
|
---|
36 | import org.greenstone.gatherer.Gatherer;
|
---|
37 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
38 | import org.greenstone.gatherer.greenstone.LocalLibraryServer;
|
---|
39 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
40 | import org.greenstone.gatherer.metadata.MetadataElement;
|
---|
41 | import org.greenstone.gatherer.metadata.MetadataSetManager;
|
---|
42 | import org.greenstone.gatherer.metadata.MetadataTools;
|
---|
43 | import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
|
---|
44 | import org.greenstone.gatherer.util.DOMTree;
|
---|
45 | import org.greenstone.gatherer.util.Codec;
|
---|
46 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
47 | import org.greenstone.gatherer.util.XMLTools;
|
---|
48 | import org.greenstone.gatherer.util.Utility;
|
---|
49 | import org.w3c.dom.*;
|
---|
50 |
|
---|
51 | /** This class provides access to an xml-type view of the collect.cfg file. This is useful as it allows the manipulation and free form editing of a collect.cfg file while still allowing the various CDM data managers to base themselves directly on this model (whereas they used to be independant ListModels which clobbered the ordering of unparsed commands).
|
---|
52 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
53 | * @version 2.3d
|
---|
54 | */
|
---|
55 | public class CollectionConfiguration {
|
---|
56 | static final private String ENCODING = "UTF-8";
|
---|
57 | static final private String NEWLINE_ELEMENT = "NewLine";
|
---|
58 | static final private String PLUGOUT_ELEMENT = "plugout";//used by building flax collections
|
---|
59 |
|
---|
60 | static private Document document;
|
---|
61 | static private StringBuffer saved_collect_cfg_string_buffer = null;
|
---|
62 |
|
---|
63 |
|
---|
64 | static public Element createElement (String element_name) {
|
---|
65 | return document.createElement (element_name);
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | /** Find the best insertion position for the given DOM Element. This should try to match command tag, and if found should then try to group by name or type (eg CollectionMeta), or append to end is no such grouping exists (eg Plugins). Failing a command match it will check against the command order for the best insertion location.
|
---|
70 | * @param target_element the command Element to be inserted
|
---|
71 | * @return the Element which the given command should be inserted before, or null to append to end of list
|
---|
72 | */
|
---|
73 | static public Node findInsertionPoint (Element target_element) {
|
---|
74 | ///ystem.err.println("Find insertion point: " + target_element.getNodeName());
|
---|
75 | String target_element_name = target_element.getNodeName ();
|
---|
76 | Element document_element = document.getDocumentElement ();
|
---|
77 | // Try to find commands with the same tag.
|
---|
78 | NodeList matching_elements = document_element.getElementsByTagName (target_element_name);
|
---|
79 | // If we found matching elements, then we have our most likely insertion location, so check within for groupings
|
---|
80 | if(matching_elements.getLength () != 0) {
|
---|
81 | ///ystem.err.println("Found matching elements.");
|
---|
82 | // Only CollectionMeta are grouped.
|
---|
83 | if(target_element_name.equals (StaticStrings.COLLECTIONMETADATA_ELEMENT)) {
|
---|
84 | ///ystem.err.println("Dealing with collection metadata");
|
---|
85 | // Special case: CollectionMeta can be added at either the start or end of a collection configuration file. However the start position is reserved for special metadata, so if no non-special metadata can be found we must append to the end.
|
---|
86 | // So if the command to be added is special add it immediately after any other special command
|
---|
87 | if(target_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
88 | int index = 0;
|
---|
89 | Element matched_element = (Element) matching_elements.item (index);
|
---|
90 | Element sibling_element = (Element) matched_element.getNextSibling ();
|
---|
91 | while(sibling_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
92 | index++;
|
---|
93 | matched_element = (Element) matching_elements.item (index);
|
---|
94 | sibling_element = (Element) matched_element.getNextSibling ();
|
---|
95 | }
|
---|
96 | if(sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
97 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
98 | document_element.insertBefore (newline_element, sibling_element);
|
---|
99 | }
|
---|
100 | return sibling_element;
|
---|
101 | }
|
---|
102 | // Otherwise try to find a matching 'name' and add after the last one in that group.
|
---|
103 | else {
|
---|
104 | int index = 0;
|
---|
105 | target_element_name = target_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
106 | boolean found = false;
|
---|
107 | // Skip all of the special metadata
|
---|
108 | Element matched_element = (Element) matching_elements.item (index);
|
---|
109 | while(matched_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
110 | index++;
|
---|
111 | matched_element = (Element) matching_elements.item (index);
|
---|
112 | }
|
---|
113 | // Begin search
|
---|
114 | while(!found && matched_element != null) {
|
---|
115 | if(matched_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
|
---|
116 | found = true;
|
---|
117 | }
|
---|
118 | else {
|
---|
119 | index++;
|
---|
120 | matched_element = (Element) matching_elements.item (index);
|
---|
121 | }
|
---|
122 | }
|
---|
123 | // If we found a match, we need to continue checking until we find the last name match.
|
---|
124 | if(found) {
|
---|
125 | index++;
|
---|
126 | Element previous_sibling = matched_element;
|
---|
127 | Element sibling_element = (Element) matching_elements.item (index);
|
---|
128 | while(sibling_element != null && sibling_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
|
---|
129 | previous_sibling = sibling_element;
|
---|
130 | index++;
|
---|
131 | sibling_element = (Element) matching_elements.item (index);
|
---|
132 | }
|
---|
133 | // Previous sibling now holds the command immediately before where we want to add, so find its next sibling and add to that. In this one case we can ignore new lines!
|
---|
134 | return previous_sibling.getNextSibling ();
|
---|
135 | }
|
---|
136 | // If not found we just add after last metadata element
|
---|
137 | else {
|
---|
138 | Element last_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
139 | return last_element.getNextSibling ();
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|
144 | else {
|
---|
145 | ///ystem.err.println("Not dealing with collection meta.");
|
---|
146 | Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
147 | // One final quick test. If the matched element is immediately followed by a NewLine command, then we insert another NewLine after the matched command, then return the NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
148 | Node sibling_element = matched_element.getNextSibling ();
|
---|
149 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
150 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
151 | document_element.insertBefore (newline_element, sibling_element);
|
---|
152 | }
|
---|
153 | return sibling_element; // Note that this may be null
|
---|
154 | }
|
---|
155 | }
|
---|
156 | ///ystem.err.println("No matching elements found.");
|
---|
157 | // Locate where this command is in the ordering
|
---|
158 | int command_index = -1;
|
---|
159 | for(int i = 0; command_index == -1 && i < COMMAND_ORDER.length; i++) {
|
---|
160 | if(COMMAND_ORDER[i].equals (target_element_name)) {
|
---|
161 | command_index = i;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | ///ystem.err.println("Command index is: " + command_index);
|
---|
165 | // Now move forward, checking for existing elements in each of the preceeding command orders.
|
---|
166 | int preceeding_index = command_index - 1;
|
---|
167 | ///ystem.err.println("Searching before the target command.");
|
---|
168 | while(preceeding_index >= 0) {
|
---|
169 | matching_elements = document_element.getElementsByTagName (COMMAND_ORDER[preceeding_index]);
|
---|
170 | // If we've found a match
|
---|
171 | if(matching_elements.getLength () > 0) {
|
---|
172 | // We add after the last element
|
---|
173 | Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
174 | // One final quick test. If the matched element is immediately followed by a NewLine command, then we insert another NewLine after the matched command, then return the NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
175 | Node sibling_element = matched_element.getNextSibling ();
|
---|
176 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
177 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
178 | document_element.insertBefore (newline_element, sibling_element);
|
---|
179 | }
|
---|
180 | return sibling_element; // Note that this may be null
|
---|
181 | }
|
---|
182 | preceeding_index--;
|
---|
183 | }
|
---|
184 | // If all that fails, we now move backwards through the commands
|
---|
185 | int susceeding_index = command_index + 1;
|
---|
186 | ///ystem.err.println("Searching after the target command.");
|
---|
187 | while(susceeding_index < COMMAND_ORDER.length) {
|
---|
188 | matching_elements = document_element.getElementsByTagName (COMMAND_ORDER[susceeding_index]);
|
---|
189 | // If we've found a match
|
---|
190 | if(matching_elements.getLength () > 0) {
|
---|
191 | // We add before the first element
|
---|
192 | Element matched_element = (Element) matching_elements.item (0);
|
---|
193 | // One final quick test. If the matched element is immediately preceeded by a NewLine command, then we insert another NewLine before the matched command, then return this new NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
194 | Node sibling_element = matched_element.getPreviousSibling ();
|
---|
195 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
196 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
197 | document_element.insertBefore (newline_element, sibling_element);
|
---|
198 | }
|
---|
199 | return sibling_element; // Note that this may be null
|
---|
200 | }
|
---|
201 | susceeding_index++;
|
---|
202 | }
|
---|
203 | // Well. Apparently there are no other commands in this collection configuration. So append away...
|
---|
204 | return null;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | static public NodeList getElementsByTagName (String element_name) {
|
---|
209 | return document.getDocumentElement ().getElementsByTagName (element_name);
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | static public String toString (Element command_element, boolean show_extracted_namespace) {
|
---|
214 | String command_element_name = command_element.getNodeName ();
|
---|
215 | if(command_element_name.equals (StaticStrings.CLASSIFY_ELEMENT)) {
|
---|
216 | return classifyToString (command_element, show_extracted_namespace);
|
---|
217 | }
|
---|
218 | else if(command_element_name.equals (StaticStrings.FORMAT_ELEMENT)) {
|
---|
219 | return formatToString (command_element, show_extracted_namespace);
|
---|
220 | }
|
---|
221 | else if(command_element_name.equals (StaticStrings.INDEXES_ELEMENT)) {
|
---|
222 | return indexesToString (command_element, show_extracted_namespace);
|
---|
223 | }
|
---|
224 | else if(command_element_name.equals (StaticStrings.INDEX_DEFAULT_ELEMENT)) {
|
---|
225 | return indexDefaultToString (command_element, show_extracted_namespace);
|
---|
226 | }
|
---|
227 | else if(command_element_name.equals (StaticStrings.LANGUAGES_ELEMENT)) {
|
---|
228 | return languagesToString (command_element);
|
---|
229 | }
|
---|
230 | else if(command_element_name.equals (StaticStrings.LANGUAGE_DEFAULT_ELEMENT)) {
|
---|
231 | return languageDefaultToString (command_element);
|
---|
232 | }
|
---|
233 | else if (command_element_name.equals (StaticStrings.LANGUAGE_METADATA_ELEMENT)) {
|
---|
234 | return languageMetadataToString (command_element, show_extracted_namespace);
|
---|
235 | }
|
---|
236 | else if(command_element_name.equals (StaticStrings.INDEXOPTIONS_ELEMENT)) {
|
---|
237 | return indexOptionsToString (command_element);
|
---|
238 | }
|
---|
239 | else if(command_element_name.equals (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT)) {
|
---|
240 | return indexOptionDefaultToString (command_element);
|
---|
241 | }
|
---|
242 | else if(command_element_name.equals (StaticStrings.COLLECTIONMETADATA_ELEMENT)) {
|
---|
243 | return metadataToString (command_element, show_extracted_namespace);
|
---|
244 | }
|
---|
245 | else if(command_element_name.equals (StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT)) {
|
---|
246 | return metadataToString (command_element, show_extracted_namespace);
|
---|
247 | }
|
---|
248 | else if(command_element_name.equals (StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT)) {
|
---|
249 | return metadataToString (command_element, show_extracted_namespace);
|
---|
250 | }
|
---|
251 | else if(command_element_name.equals (StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT)) {
|
---|
252 | return metadataToString (command_element, show_extracted_namespace);
|
---|
253 | }
|
---|
254 | else if (command_element_name.equals (StaticStrings.BUILDTYPE_ELEMENT)) {
|
---|
255 | return metadataToString (command_element, show_extracted_namespace);
|
---|
256 | }
|
---|
257 | else if(command_element_name.equals (StaticStrings.PLUGIN_ELEMENT)) {
|
---|
258 | return pluginToString (command_element, show_extracted_namespace);
|
---|
259 | }
|
---|
260 | else if(command_element_name.equals (StaticStrings.SUBCOLLECTION_ELEMENT)) {
|
---|
261 | return subcollectionToString (command_element, show_extracted_namespace);
|
---|
262 | }
|
---|
263 | else if(command_element_name.equals (StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT)) {
|
---|
264 | return subcollectionDefaultIndexToString (command_element);
|
---|
265 | }
|
---|
266 | else if(command_element_name.equals (StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT)) {
|
---|
267 | return subcollectionIndexesToString (command_element);
|
---|
268 | }
|
---|
269 | else if(command_element_name.equals (StaticStrings.SUPERCOLLECTION_ELEMENT)) {
|
---|
270 | return supercollectionToString (command_element);
|
---|
271 | }
|
---|
272 | else if(command_element_name.equals (StaticStrings.UNKNOWN_ELEMENT)) {
|
---|
273 | return unknownToString (command_element);
|
---|
274 | }
|
---|
275 | return "";
|
---|
276 | }
|
---|
277 |
|
---|
278 | /** Parses arguments from a tokenizer and returns a HashMap of mappings. The tricky bit here is that not all entries in the HashMap are name->value pairs, as some arguments are boolean and are turned on by their presence. Arguments are denoted by a '-' prefix.
|
---|
279 | * @param tokenizer a CommandTokenizer based on the unconsumed portion of a command string
|
---|
280 | * @return a HashMap containing the arguments parsed
|
---|
281 | */
|
---|
282 | static public HashMap parseArguments (CommandTokenizer tokenizer) {
|
---|
283 | HashMap arguments = new HashMap ();
|
---|
284 | String name = null;
|
---|
285 | String value = null;
|
---|
286 | while(tokenizer.hasMoreTokens () || name != null) {
|
---|
287 | // First we retrieve a name if we need one.
|
---|
288 | if(name == null) {
|
---|
289 | name = tokenizer.nextToken ();
|
---|
290 | }
|
---|
291 | // Now we attempt to retrieve a value
|
---|
292 | if(tokenizer.hasMoreTokens ()) {
|
---|
293 | value = tokenizer.nextToken ();
|
---|
294 | // Test if the value is actually a name, and if so add the name by itself, then put value into name so that it is parsed correctly during the next loop.
|
---|
295 | // The value is not a name if it contains a space character: it's a quoted value
|
---|
296 | if (value.startsWith(StaticStrings.MINUS_CHARACTER) && value.indexOf(StaticStrings.SPACE_CHARACTER) == -1) {
|
---|
297 | arguments.put (name, null);
|
---|
298 | name = value;
|
---|
299 | }
|
---|
300 | // Otherwise we have a typical name->value pair ready to go
|
---|
301 | else {
|
---|
302 | arguments.put (name, value);
|
---|
303 | name = null;
|
---|
304 | }
|
---|
305 | }
|
---|
306 | // Otherwise its a binary flag
|
---|
307 | else {
|
---|
308 | arguments.put (name, null);
|
---|
309 | name = null;
|
---|
310 | }
|
---|
311 | }
|
---|
312 | return arguments;
|
---|
313 | }
|
---|
314 |
|
---|
315 | /** Gives the preferred ordering of commands */
|
---|
316 | static final private String[] COMMAND_ORDER =
|
---|
317 | {StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT, StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT, StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT, StaticStrings.BUILDTYPE_ELEMENT, StaticStrings.PLUGIN_ELEMENT, StaticStrings.INDEXES_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT, StaticStrings.INDEXOPTIONS_ELEMENT, StaticStrings.INDEXOPTION_DEFAULT_ELEMENT, StaticStrings.LANGUAGES_ELEMENT, StaticStrings.LANGUAGE_DEFAULT_ELEMENT, StaticStrings.LANGUAGE_METADATA_ELEMENT, StaticStrings.SUBCOLLECTION_ELEMENT, StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT, StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT, StaticStrings.SUPERCOLLECTION_ELEMENT, StaticStrings.CLASSIFY_ELEMENT, StaticStrings.FORMAT_ELEMENT, StaticStrings.COLLECTIONMETADATA_ELEMENT};
|
---|
318 |
|
---|
319 | /** ************************** Public Data Members ***************************/
|
---|
320 |
|
---|
321 | /** ************************** Private Data Members ***************************/
|
---|
322 |
|
---|
323 | private File collect_cfg_file;
|
---|
324 |
|
---|
325 | /** ************************** Public Methods ***************************/
|
---|
326 |
|
---|
327 |
|
---|
328 | /** This debug facility shows the currently loaded collect.cfg or CollectConfig.xml file as a DOM tree. */
|
---|
329 | public void display () {
|
---|
330 | JDialog dialog = new JDialog (Gatherer.g_man, "Collection Configuration", false);
|
---|
331 | dialog.setSize (400,400);
|
---|
332 | JPanel content_pane = (JPanel) dialog.getContentPane ();
|
---|
333 | final DOMTree tree = new DOMTree (document);
|
---|
334 | JButton refresh_button = new GLIButton ("Refresh Tree");
|
---|
335 | refresh_button.addActionListener (new ActionListener () {
|
---|
336 | public void actionPerformed (ActionEvent event) {
|
---|
337 | tree.setDocument (document);
|
---|
338 | }
|
---|
339 | });
|
---|
340 | content_pane.setBorder (BorderFactory.createEmptyBorder (5,5,5,5));
|
---|
341 | content_pane.setLayout (new BorderLayout ());
|
---|
342 | content_pane.add (new JScrollPane (tree), BorderLayout.CENTER);
|
---|
343 | content_pane.add (refresh_button, BorderLayout.SOUTH);
|
---|
344 | dialog.setVisible (true);
|
---|
345 | }
|
---|
346 |
|
---|
347 |
|
---|
348 | public Element getCreator () {
|
---|
349 | Element element = getOrCreateElementByTagName (StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT, null, null);
|
---|
350 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.COLLECTIONMETADATA_CREATOR_STR);
|
---|
351 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
352 | return element;
|
---|
353 | }
|
---|
354 |
|
---|
355 | public Element getDocumentElement () {
|
---|
356 | return document.getDocumentElement ();
|
---|
357 | }
|
---|
358 |
|
---|
359 | public File getFile () {
|
---|
360 | return collect_cfg_file;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /** Retrieve or create the languages Element. */
|
---|
364 | public Element getLanguages () {
|
---|
365 | return getOrCreateElementByTagName (StaticStrings.LANGUAGES_ELEMENT, null, null);
|
---|
366 | }
|
---|
367 |
|
---|
368 | public Element getLanguageMetadata () {
|
---|
369 | return getOrCreateElementByTagName (StaticStrings.LANGUAGE_METADATA_ELEMENT, null, null);
|
---|
370 | }
|
---|
371 |
|
---|
372 | public Element getLevels () {
|
---|
373 | return getOrCreateElementByTagName (StaticStrings.INDEXOPTIONS_ELEMENT, StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVELS_STR);
|
---|
374 | }
|
---|
375 |
|
---|
376 | public Element getLevelDefault () {
|
---|
377 | return getOrCreateElementByTagName (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT, StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVEL_DEFAULT_STR);
|
---|
378 | }
|
---|
379 |
|
---|
380 | public Element getStemOptions () {
|
---|
381 | return getOrCreateElementByTagName (StaticStrings.INDEXOPTIONS_ELEMENT, StaticStrings.NAME_ATTRIBUTE, StaticStrings.STEMOPTIONS_STR);
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | public Element getMaintainer () {
|
---|
386 | Element element = getOrCreateElementByTagName (StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT, null, null);
|
---|
387 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR);
|
---|
388 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
389 | return element;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /** Retrieve or create the indexes Element. Note that this method behaves differently from the other getBlah methods, in that it also has to keep in mind that indexes come in two flavours, MG and MGPP. */
|
---|
393 | public Element getMGIndexes () {
|
---|
394 | return getOrCreateElementByTagName (StaticStrings.INDEXES_ELEMENT, StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
395 | }
|
---|
396 |
|
---|
397 | public Element getMGPPIndexes () {
|
---|
398 | return getOrCreateElementByTagName (StaticStrings.INDEXES_ELEMENT, StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
399 | }
|
---|
400 |
|
---|
401 | public Element getPublic () {
|
---|
402 | Element element = getOrCreateElementByTagName (StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT, null, null);
|
---|
403 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.COLLECTIONMETADATA_PUBLIC_STR);
|
---|
404 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
405 | return element;
|
---|
406 | }
|
---|
407 |
|
---|
408 | public Element getBuildType () {
|
---|
409 | Element element = getOrCreateElementByTagName (StaticStrings.BUILDTYPE_ELEMENT, null, null);
|
---|
410 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.BUILDTYPE_STR);
|
---|
411 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
412 | return element;
|
---|
413 |
|
---|
414 | }
|
---|
415 |
|
---|
416 | /** Retrieve or create the subindexes Element. */
|
---|
417 | public Element getSubIndexes () {
|
---|
418 | return getOrCreateElementByTagName (StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT, null, null);
|
---|
419 | }
|
---|
420 |
|
---|
421 | /** Retrieve or create the supercollections Element. */
|
---|
422 | public Element getSuperCollection () {
|
---|
423 | return getOrCreateElementByTagName (StaticStrings.SUPERCOLLECTION_ELEMENT, null, null);
|
---|
424 | }
|
---|
425 |
|
---|
426 | public boolean ready () {
|
---|
427 | return document != null;
|
---|
428 | }
|
---|
429 |
|
---|
430 |
|
---|
431 |
|
---|
432 |
|
---|
433 | /** ************************** Private Methods ***************************/
|
---|
434 |
|
---|
435 | static private String classifyToString (Element command_element, boolean show_extracted_namespace) {
|
---|
436 | StringBuffer text = new StringBuffer (StaticStrings.CLASSIFY_STR);
|
---|
437 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
438 | text.append (command_element.getAttribute (StaticStrings.TYPE_ATTRIBUTE));
|
---|
439 | NodeList option_elements = command_element.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
440 | int option_elements_length = option_elements.getLength ();
|
---|
441 | for(int j = 0; j < option_elements_length; j++) {
|
---|
442 | Element option_element = (Element) option_elements.item (j);
|
---|
443 | if(option_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
444 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
445 | text.append (StaticStrings.MINUS_CHARACTER);
|
---|
446 | text.append (option_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
447 | String value_str = XMLTools.getValue (option_element);
|
---|
448 |
|
---|
449 | // Convert metadata element names to internal names, and remove extracted metadata namespaces
|
---|
450 | if (value_str.length () > 0) {
|
---|
451 | StringTokenizer string_tokenizer = new StringTokenizer (value_str, ",");
|
---|
452 | StringBuffer value_buffer = new StringBuffer ();
|
---|
453 | while (string_tokenizer.hasMoreElements ()) {
|
---|
454 | String raw_token = (String) string_tokenizer.nextElement ();
|
---|
455 | String token = raw_token.trim ();
|
---|
456 | MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (token);
|
---|
457 | if (metadata_element != null) {
|
---|
458 | token = metadata_element.getFullName ();
|
---|
459 | }
|
---|
460 |
|
---|
461 | if (token.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
462 | token = token.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
463 | }
|
---|
464 | value_buffer.append (token);
|
---|
465 | if (string_tokenizer.hasMoreElements ()) {
|
---|
466 | value_buffer.append (",");
|
---|
467 | }
|
---|
468 | }
|
---|
469 | value_str = value_buffer.toString ();
|
---|
470 | }
|
---|
471 |
|
---|
472 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
473 | if (value_str.indexOf (StaticStrings.SPACE_CHARACTER) == -1) {
|
---|
474 | text.append (value_str);
|
---|
475 | }
|
---|
476 | else {
|
---|
477 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
478 | text.append (value_str);
|
---|
479 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
480 | }
|
---|
481 | value_str = null;
|
---|
482 | }
|
---|
483 | option_element = null;
|
---|
484 | }
|
---|
485 | option_elements = null;
|
---|
486 | return text.toString ();
|
---|
487 | }
|
---|
488 |
|
---|
489 | static private String formatToString (Element command_element, boolean show_extracted_namespace) {
|
---|
490 | StringBuffer text = new StringBuffer (StaticStrings.FORMAT_STR);
|
---|
491 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
492 | text.append (command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
493 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
494 | String value_str = command_element.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
|
---|
495 | if(value_str.length () != 0) {
|
---|
496 | text.append (value_str);
|
---|
497 | }
|
---|
498 | else {
|
---|
499 | // Remember to encode format string to Greenstone specification
|
---|
500 | value_str = Codec.transform (XMLTools.getValue (command_element), Codec.DOM_TO_GREENSTONE);
|
---|
501 | // Remove any references to a namespace for extracted metadata
|
---|
502 | if (!show_extracted_namespace) {
|
---|
503 | String match_string = "\\[" + MetadataSetManager.EXTRACTED_METADATA_NAMESPACE + "\\.";
|
---|
504 | value_str = value_str.replaceAll (match_string, "[");
|
---|
505 | }
|
---|
506 |
|
---|
507 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
508 | text.append (value_str);
|
---|
509 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
510 | }
|
---|
511 | value_str = null;
|
---|
512 | return text.toString ();
|
---|
513 | }
|
---|
514 |
|
---|
515 | /** Retrieve or create the indexes Element. */
|
---|
516 | static private Element getOrCreateElementByTagName (String name, String conditional_attribute, String required_value) {
|
---|
517 | Element document_element = document.getDocumentElement ();
|
---|
518 | NodeList elements = document_element.getElementsByTagName (name);
|
---|
519 | int elements_length = elements.getLength ();
|
---|
520 | if(elements_length > 0) {
|
---|
521 | if(conditional_attribute == null) {
|
---|
522 | document_element = null;
|
---|
523 | return (Element) elements.item (0);
|
---|
524 | }
|
---|
525 | else {
|
---|
526 | for(int i = 0; i < elements_length; i++) {
|
---|
527 | Element element = (Element) elements.item (i);
|
---|
528 | if(element.getAttribute (conditional_attribute).equals (required_value)) {
|
---|
529 | document_element = null;
|
---|
530 | return element;
|
---|
531 | }
|
---|
532 | element = null;
|
---|
533 | }
|
---|
534 | }
|
---|
535 | }
|
---|
536 | // Create the element
|
---|
537 | Element element = document.createElement (name);
|
---|
538 | // If there was a property set it
|
---|
539 | if(conditional_attribute != null) {
|
---|
540 | element.setAttribute (conditional_attribute, required_value);
|
---|
541 | }
|
---|
542 | Node target_node = findInsertionPoint (element);
|
---|
543 | if(target_node != null) {
|
---|
544 | document_element.insertBefore (element, target_node);
|
---|
545 | }
|
---|
546 | else {
|
---|
547 | document_element.appendChild (element);
|
---|
548 | }
|
---|
549 | document_element = null;
|
---|
550 | return element;
|
---|
551 | }
|
---|
552 |
|
---|
553 | static private String indexesToString (Element command_element, boolean show_extracted_namespace) {
|
---|
554 | boolean comment_only = false;
|
---|
555 | StringBuffer text = new StringBuffer ("");
|
---|
556 | if(command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
557 | text.append ("#");
|
---|
558 | comment_only = true;
|
---|
559 | }
|
---|
560 | text.append (StaticStrings.INDEX_STR);
|
---|
561 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
562 | if(!comment_only) {
|
---|
563 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
564 | }
|
---|
565 | NodeList index_elements = command_element.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
|
---|
566 | if (index_elements.getLength () == 0) { // no indexes
|
---|
567 | return "";
|
---|
568 | }
|
---|
569 | // For each index, write its level, a colon, then concatenate its child content elements into a single comma separated list
|
---|
570 | int index_elements_length = index_elements.getLength ();
|
---|
571 | for(int j = 0; j < index_elements_length; j++) {
|
---|
572 | Element index_element = (Element) index_elements.item (j);
|
---|
573 | String level_str = index_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE);
|
---|
574 | if(level_str.length () > 0) {
|
---|
575 | text.append (level_str);
|
---|
576 | text.append (StaticStrings.COLON_CHARACTER);
|
---|
577 | }
|
---|
578 | NodeList content_elements = index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
579 | int content_elements_length = content_elements.getLength ();
|
---|
580 | // Don't output anything if no indexes are set
|
---|
581 | if(content_elements_length == 0) {
|
---|
582 | return null;
|
---|
583 | }
|
---|
584 | for(int k = 0; k < content_elements_length; k++) {
|
---|
585 | Element content_element = (Element) content_elements.item (k);
|
---|
586 | String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
587 | if(!show_extracted_namespace && name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
588 | name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
589 | }
|
---|
590 | text.append (name_str);
|
---|
591 | name_str = null;
|
---|
592 | if(k < content_elements_length - 1) {
|
---|
593 | text.append (StaticStrings.COMMA_CHARACTER);
|
---|
594 | }
|
---|
595 | content_element = null;
|
---|
596 | }
|
---|
597 | if(j < index_elements_length - 1) {
|
---|
598 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
599 | }
|
---|
600 | content_elements = null;
|
---|
601 | index_element = null;
|
---|
602 | }
|
---|
603 | index_elements = null;
|
---|
604 | return text.toString ();
|
---|
605 | }
|
---|
606 |
|
---|
607 | static private String indexDefaultToString (Element command_element, boolean show_extracted_namespace) {
|
---|
608 | StringBuffer text = new StringBuffer ("");
|
---|
609 | if(command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
610 | text.append ("#");
|
---|
611 | }
|
---|
612 | text.append (StaticStrings.INDEX_DEFAULT_STR);
|
---|
613 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
614 | if (!command_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE).equals ("")) {
|
---|
615 | text.append (command_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE));
|
---|
616 | text.append (StaticStrings.COLON_CHARACTER);
|
---|
617 | }
|
---|
618 | NodeList content_elements = command_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
619 | int content_elements_length = content_elements.getLength ();
|
---|
620 | for(int j = 0; j < content_elements_length; j++) {
|
---|
621 | Element content_element = (Element) content_elements.item (j);
|
---|
622 | String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
623 | if(!show_extracted_namespace && name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
624 | name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
625 | }
|
---|
626 | text.append (name_str);
|
---|
627 | name_str = null;
|
---|
628 | if(j < content_elements_length - 1) {
|
---|
629 | text.append (StaticStrings.COMMA_CHARACTER);
|
---|
630 | }
|
---|
631 | content_element = null;
|
---|
632 | }
|
---|
633 | content_elements = null;
|
---|
634 | return text.toString ();
|
---|
635 | }
|
---|
636 |
|
---|
637 | static private String languagesToString (Element command_element) {
|
---|
638 | StringBuffer text = new StringBuffer (StaticStrings.LANGUAGES_STR);
|
---|
639 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
640 | // Retrieve all the languages and write them out in a space separated list
|
---|
641 | NodeList language_elements = command_element.getElementsByTagName (StaticStrings.LANGUAGE_ELEMENT);
|
---|
642 | int language_elements_length = language_elements.getLength ();
|
---|
643 | if(language_elements_length == 0) {
|
---|
644 | return null;
|
---|
645 | }
|
---|
646 | for(int j = 0; j < language_elements_length; j++) {
|
---|
647 | Element language_element = (Element) language_elements.item (j);
|
---|
648 | text.append (language_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
649 | if(j < language_elements_length - 1) {
|
---|
650 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
651 | }
|
---|
652 | }
|
---|
653 | return text.toString ();
|
---|
654 | }
|
---|
655 |
|
---|
656 | static private String languageDefaultToString (Element command_element) {
|
---|
657 | StringBuffer text = new StringBuffer (StaticStrings.LANGUAGE_DEFAULT_STR);
|
---|
658 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
659 | text.append (command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
660 | return text.toString ();
|
---|
661 | }
|
---|
662 |
|
---|
663 | static private String languageMetadataToString (Element command_element, boolean show_extracted_namespace) {
|
---|
664 | if (!command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
665 | return "";
|
---|
666 | }
|
---|
667 | StringBuffer text = new StringBuffer (StaticStrings.LANGUAGE_METADATA_STR);
|
---|
668 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
669 | String name_str = command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
670 | if(!show_extracted_namespace && name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
671 | name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
672 | }
|
---|
673 | text.append (name_str);
|
---|
674 | return text.toString ();
|
---|
675 | }
|
---|
676 |
|
---|
677 | static private String indexOptionsToString (Element command_element) {
|
---|
678 | StringBuffer text = new StringBuffer ("");
|
---|
679 | if(command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
680 | text.append ("#");
|
---|
681 | }
|
---|
682 | text.append (command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
683 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
684 | NodeList content_elements = command_element.getElementsByTagName (StaticStrings.INDEXOPTION_ELEMENT);
|
---|
685 | int content_elements_length = content_elements.getLength ();
|
---|
686 | // Don't output anything if no options are set.
|
---|
687 | if(content_elements_length == 0) {
|
---|
688 | return null;
|
---|
689 | }
|
---|
690 | for(int i = 0; i < content_elements_length; i++) {
|
---|
691 | Element content_element = (Element) content_elements.item (i);
|
---|
692 | text.append (content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
693 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
694 | }
|
---|
695 | return text.substring (0, text.length () - 1);
|
---|
696 | }
|
---|
697 |
|
---|
698 | static private String indexOptionDefaultToString (Element command_element) {
|
---|
699 | // Don't bother if there is no value
|
---|
700 | if (command_element.getAttribute (StaticStrings.VALUE_ATTRIBUTE).equals ("")) {
|
---|
701 | return "";
|
---|
702 | }
|
---|
703 | StringBuffer text = new StringBuffer ("");
|
---|
704 | if(command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
705 | text.append ("#");
|
---|
706 | }
|
---|
707 | text.append (command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
708 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
709 | text.append (command_element.getAttribute (StaticStrings.VALUE_ATTRIBUTE));
|
---|
710 | return text.toString ();
|
---|
711 | }
|
---|
712 |
|
---|
713 | static private String metadataToString (Element command_element, boolean text_value) {
|
---|
714 | // lets first check the value - if its empty, don't bother sticking it in the config file
|
---|
715 | String value_str = XMLTools.getValue (command_element);
|
---|
716 | if (value_str.equals ("")) {
|
---|
717 | return "";
|
---|
718 | }
|
---|
719 | boolean special = false;
|
---|
720 |
|
---|
721 | StringBuffer text = new StringBuffer ("");
|
---|
722 | String name_str = command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
723 | // If the name is one of the special four, we don't write the collectionmeta first. Note maintainer and buildtype are singled out for 'prittying' reasons.
|
---|
724 | if(name_str.equals (StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR)|| name_str.equals (StaticStrings.BUILDTYPE_STR) ) {
|
---|
725 | text.append (name_str);
|
---|
726 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
727 | special = true;
|
---|
728 | }
|
---|
729 | else if (name_str.equals (StaticStrings.COLLECTIONMETADATA_CREATOR_STR) || name_str.equals (StaticStrings.COLLECTIONMETADATA_PUBLIC_STR) ) {
|
---|
730 | text.append (name_str);
|
---|
731 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
732 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
733 | special = true;
|
---|
734 | }
|
---|
735 | else {
|
---|
736 | text.append (StaticStrings.COLLECTIONMETADATA_STR);
|
---|
737 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
738 | text.append (name_str);
|
---|
739 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
740 | String language_str = command_element.getAttribute (StaticStrings.LANGUAGE_ATTRIBUTE);
|
---|
741 | text.append (StaticStrings.LBRACKET_CHARACTER);
|
---|
742 | text.append (StaticStrings.LANGUAGE_ARGUMENT);
|
---|
743 | text.append (language_str);
|
---|
744 | text.append (StaticStrings.RBRACKET_CHARACTER);
|
---|
745 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
746 | }
|
---|
747 | name_str = null;
|
---|
748 |
|
---|
749 | // The value string we retrieved will be encoded for xml, so we now decode it - to text if text_value set. This parameter was originally show_extracted_namespace, but sincethis is only true for 'toString()' commands from within the CDM, its good enough to determine if this toString() will be used to display on screen, or write to collect.cfg
|
---|
750 | if(text_value == CollectionMeta.TEXT) {
|
---|
751 | value_str = Codec.transform (value_str, Codec.DOM_TO_TEXT);
|
---|
752 | }
|
---|
753 | else {
|
---|
754 | value_str = Codec.transform (value_str, Codec.DOM_TO_GREENSTONE);
|
---|
755 | }
|
---|
756 |
|
---|
757 | // We don't wrap the email addresses in quotes, nor the other special metadata
|
---|
758 | if(special) {
|
---|
759 | text.append (value_str);
|
---|
760 | }
|
---|
761 | else {
|
---|
762 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
763 | text.append (value_str);
|
---|
764 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
765 | }
|
---|
766 | value_str = null;
|
---|
767 | return text.toString ();
|
---|
768 | }
|
---|
769 |
|
---|
770 | /** Parse a collect.cfg into a DOM model representation.
|
---|
771 | * note we are ignoring 2.39 compatibility now. */
|
---|
772 | private void parse (File collect_cfg_file) {
|
---|
773 | // hack for pre 2.71 compatibility - we need to add in a
|
---|
774 | // build type if there is not one there
|
---|
775 | boolean search_types_parsed = false;
|
---|
776 | boolean build_types_parsed = false;
|
---|
777 | try {
|
---|
778 | saved_collect_cfg_string_buffer = new StringBuffer ();
|
---|
779 |
|
---|
780 | Element collect_cfg_element = document.getDocumentElement ();
|
---|
781 | // Read in the file one command at a time.
|
---|
782 | InputStream istream = new FileInputStream (collect_cfg_file);
|
---|
783 | Reader in_reader = new InputStreamReader (istream, ENCODING);
|
---|
784 | BufferedReader in = new BufferedReader (in_reader);
|
---|
785 | String command_str = null;
|
---|
786 | while((command_str = in.readLine ()) != null) {
|
---|
787 | saved_collect_cfg_string_buffer.append (command_str + "\n");
|
---|
788 |
|
---|
789 | boolean append_element = true;
|
---|
790 | Element command_element = null;
|
---|
791 | // A command may be broken over several lines.
|
---|
792 | command_str = command_str.trim ();
|
---|
793 | boolean eof = false;
|
---|
794 | while(!eof && command_str.endsWith (StaticStrings.NEWLINE_CHARACTER)) {
|
---|
795 | String next_line = in.readLine ();
|
---|
796 | if(next_line != null) {
|
---|
797 | next_line = next_line.trim ();
|
---|
798 | if(next_line.length () > 0) {
|
---|
799 | // Remove the new line character
|
---|
800 | command_str = command_str.substring (0, command_str.lastIndexOf (StaticStrings.NEWLINE_CHARACTER));
|
---|
801 | // And append the next line, which due to the test above must be non-zero length
|
---|
802 | command_str = command_str + next_line;
|
---|
803 | }
|
---|
804 | next_line = null;
|
---|
805 | }
|
---|
806 | // If we've reached the end of the file theres nothing more we can do
|
---|
807 | else {
|
---|
808 | eof = true;
|
---|
809 | }
|
---|
810 | }
|
---|
811 | // If there is still a new line character, then we remove it and hope for the best
|
---|
812 | if(command_str.endsWith (StaticStrings.NEWLINE_CHARACTER)) {
|
---|
813 | command_str = command_str.substring (0, command_str.lastIndexOf (StaticStrings.NEWLINE_CHARACTER));
|
---|
814 | }
|
---|
815 | // Now we've either got a command to parse...
|
---|
816 | if(command_str.length () != 0) {
|
---|
817 | // Start trying to figure out what it is
|
---|
818 | //StringTokenizer tokenizer = new StringTokenizer(command_str);
|
---|
819 | // Instead of a standard string tokenizer I'm going to use the new version of CommandTokenizer, which is not only smart enough to correctly notice speech marks and correctly parse them out, but now also takes the input stream so it can rebuild tokens that stretch over several lines.
|
---|
820 | CommandTokenizer tokenizer = new CommandTokenizer (command_str, in);
|
---|
821 | String command_type = tokenizer.nextToken ().toLowerCase ();
|
---|
822 | // Why can't you switch on strings eh? We pass it to the various subparsers who each have a bash at parsing the command. If none can parse the command, an unknown element is created
|
---|
823 | if(command_element == null && command_type.equals (StaticStrings.CLASSIFY_STR)) {
|
---|
824 | command_element = parseClassify (command_str);
|
---|
825 | }
|
---|
826 | if(command_element == null && command_type.equals (StaticStrings.FORMAT_STR)) {
|
---|
827 | command_element = parseFormat (tokenizer); // Revised to handle multiple lines
|
---|
828 | }
|
---|
829 | if(command_element == null && (command_type.equals (StaticStrings.INDEX_STR) || command_type.equals (StaticStrings.COMMENTED_INDEXES_STR))) {
|
---|
830 | command_element = parseIndex (command_str);
|
---|
831 | }
|
---|
832 | if(command_element == null && (command_type.equals (StaticStrings.INDEX_DEFAULT_STR) || command_type.equals (StaticStrings.COMMENTED_INDEX_DEFAULT_STR))) {
|
---|
833 |
|
---|
834 | command_element = parseIndexDefault (command_str);
|
---|
835 | }
|
---|
836 | if(command_element == null && command_type.equals (StaticStrings.LANGUAGES_STR)) {
|
---|
837 | command_element = parseLanguage (command_str);
|
---|
838 | }
|
---|
839 | if(command_element == null && command_type.equals (StaticStrings.LANGUAGE_DEFAULT_STR)) {
|
---|
840 | command_element = parseLanguageDefault (command_str);
|
---|
841 | }
|
---|
842 | if (command_element == null && command_type.equals (StaticStrings.LANGUAGE_METADATA_STR)) {
|
---|
843 | command_element = parseLanguageMetadata (command_str);
|
---|
844 | }
|
---|
845 | if(command_element == null && command_type.equals (StaticStrings.LEVELS_STR)) {
|
---|
846 | command_element = parseIndexOptions (command_str, StaticStrings.LEVELS_STR, true);
|
---|
847 | }
|
---|
848 | if (command_element == null && command_type.equals (StaticStrings.COMMENTED_LEVELS_STR)) {
|
---|
849 | command_element = parseIndexOptions (command_str, StaticStrings.LEVELS_STR, false);
|
---|
850 | }
|
---|
851 | if(command_element == null && command_type.equals (StaticStrings.LEVEL_DEFAULT_STR)) {
|
---|
852 | command_element = parseIndexOptionDefault (command_str, StaticStrings.LEVEL_DEFAULT_STR, true);
|
---|
853 | }
|
---|
854 | if(command_element == null && command_type.equals (StaticStrings.COMMENTED_LEVEL_DEFAULT_STR)) {
|
---|
855 | command_element = parseIndexOptionDefault (command_str, StaticStrings.LEVEL_DEFAULT_STR, false);
|
---|
856 | }
|
---|
857 | if (command_element == null && command_type.equals (StaticStrings.STEMOPTIONS_STR)) {
|
---|
858 | command_element = parseIndexOptions (command_str, StaticStrings.STEMOPTIONS_STR, true);
|
---|
859 | }
|
---|
860 | if (command_element == null && command_type.equals (StaticStrings.COMMENTED_STEMOPTIONS_STR)) {
|
---|
861 | command_element = parseIndexOptions (command_str, StaticStrings.STEMOPTIONS_STR, false);
|
---|
862 | }
|
---|
863 | if(command_element == null && command_type.equals (StaticStrings.COLLECTIONMETADATA_STR)) {
|
---|
864 | command_element = parseMetadata (tokenizer); // Revised to handle multiple lines
|
---|
865 | }
|
---|
866 | if(command_element == null && (command_type.equals (StaticStrings.COLLECTIONMETADATA_PUBLIC_STR) || command_type.equals (StaticStrings.COLLECTIONMETADATA_CREATOR_STR) || command_type.equals (StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR) || command_type.equals (StaticStrings.BUILDTYPE_STR))) {
|
---|
867 | command_element = parseMetadataSpecial (command_str);
|
---|
868 | // pre 2.71 hack
|
---|
869 | if (command_type.equals (StaticStrings.BUILDTYPE_STR)) {
|
---|
870 | build_types_parsed = true;
|
---|
871 | }
|
---|
872 | }
|
---|
873 | if(command_element == null && command_type.equals (StaticStrings.PLUGIN_STR)) {
|
---|
874 | command_element = parsePlugin (command_str);
|
---|
875 | }
|
---|
876 | // leave here for backwards compatibility
|
---|
877 | if(command_element == null && command_type.equals (StaticStrings.SEARCHTYPE_STR)) {
|
---|
878 | command_element = parseSearchType (command_str);
|
---|
879 | // pre 2.71 hack
|
---|
880 | search_types_parsed = true;
|
---|
881 |
|
---|
882 | }
|
---|
883 | if(command_element == null && command_type.equals (StaticStrings.SUBCOLLECTION_STR)) {
|
---|
884 | command_element = parseSubCollection (command_str);
|
---|
885 | }
|
---|
886 | if(command_element == null && command_type.equals (StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_STR)) {
|
---|
887 | command_element = parseSubCollectionDefaultIndex (command_str);
|
---|
888 | }
|
---|
889 | if(command_element == null && command_type.equals (StaticStrings.SUBCOLLECTION_INDEX_STR)) {
|
---|
890 | command_element = parseSubCollectionIndex (command_str);
|
---|
891 | }
|
---|
892 | if(command_element == null && (command_type.equals (StaticStrings.SUPERCOLLECTION_STR) || command_type.equals (StaticStrings.CCS_STR))) {
|
---|
893 | command_element = parseSuperCollection (command_str);
|
---|
894 | }
|
---|
895 | // Doesn't match any known type
|
---|
896 | command_type = null;
|
---|
897 | if(command_element == null) {
|
---|
898 | // No-one knows what to do with this command, so we create an Unknown command element
|
---|
899 | command_element = document.createElement (StaticStrings.UNKNOWN_ELEMENT);
|
---|
900 | XMLTools.setValue (command_element, command_str);
|
---|
901 | }
|
---|
902 | }
|
---|
903 | // Or an empty line to remember for later
|
---|
904 | else {
|
---|
905 | command_element = document.createElement (NEWLINE_ELEMENT);
|
---|
906 | }
|
---|
907 | // Now command element shouldn't be null so we append it to the collection config DOM, but only if we haven't been told not to add it
|
---|
908 | //if(append_element) {
|
---|
909 | collect_cfg_element.appendChild (command_element);
|
---|
910 | //}
|
---|
911 | }
|
---|
912 | if (!build_types_parsed) {
|
---|
913 | String buildtype_type = BuildTypeManager.BUILD_TYPE_MG;
|
---|
914 | if (search_types_parsed) {
|
---|
915 | buildtype_type = BuildTypeManager.BUILD_TYPE_MGPP;
|
---|
916 | }
|
---|
917 | Element command_element = parseMetadataSpecial (StaticStrings.BUILDTYPE_STR+" "+buildtype_type);
|
---|
918 | Node target_node = findInsertionPoint (command_element);
|
---|
919 | if(target_node != null) {
|
---|
920 | collect_cfg_element.insertBefore (command_element, target_node);
|
---|
921 | }
|
---|
922 | else {
|
---|
923 | collect_cfg_element.appendChild (command_element);
|
---|
924 | }
|
---|
925 |
|
---|
926 | }
|
---|
927 | }
|
---|
928 | catch(Exception exception) {
|
---|
929 | DebugStream.println ("Error in CollectionConfiguration.parse(java.io.File): " + exception);
|
---|
930 | DebugStream.printStackTrace (exception);
|
---|
931 | }
|
---|
932 | }
|
---|
933 |
|
---|
934 |
|
---|
935 | private Element parseClassify (String command_str) {
|
---|
936 | Element command_element = null;
|
---|
937 | try {
|
---|
938 | CommandTokenizer tokenizer = new CommandTokenizer (command_str);
|
---|
939 | // Check the token count. The token count from a command tokenizer isn't guarenteed to be correct, but it does give the maximum number of available tokens according to the underlying StringTokenizer (some of which may actually be append together by the CommandTokenizer as being a single argument).
|
---|
940 | if(tokenizer.countTokens () >= 2) { // Must support "classify Phind" (no args)
|
---|
941 | command_element = document.createElement (StaticStrings.CLASSIFY_ELEMENT);
|
---|
942 | // First token is classify
|
---|
943 | tokenizer.nextToken ();
|
---|
944 | // The next token is the classifier type
|
---|
945 | command_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, tokenizer.nextToken ());
|
---|
946 | // Now we parse out the remaining arguments into a hashmapping from name to value
|
---|
947 | HashMap arguments = parseArguments (tokenizer);
|
---|
948 | // Assign the arguments as Option elements, but watch out for the metadata argument as we treat that differently
|
---|
949 | Iterator names = arguments.keySet ().iterator ();
|
---|
950 | while(names.hasNext ()) {
|
---|
951 | String name = (String) names.next ();
|
---|
952 | String value = (String) arguments.get (name); // Can be null
|
---|
953 | // The metadata argument gets added as the content attribute
|
---|
954 | if (name.equals (StaticStrings.METADATA_ARGUMENT) && value != null) {
|
---|
955 | // Add the extracted namespace onto un-namespaced metadata names
|
---|
956 | StringTokenizer string_tokenizer = new StringTokenizer (value, ",");
|
---|
957 | value = "";
|
---|
958 | while (string_tokenizer.hasMoreElements ()) {
|
---|
959 | String token = (String) string_tokenizer.nextElement ();
|
---|
960 |
|
---|
961 | if (token.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
962 | token = StaticStrings.EXTRACTED_NAMESPACE + token;
|
---|
963 | }
|
---|
964 | else {
|
---|
965 | MetadataElement metadata_element = MetadataTools.getMetadataElementWithName (token);
|
---|
966 | if (metadata_element != null) {
|
---|
967 | token = metadata_element.getDisplayName ();
|
---|
968 | }
|
---|
969 | }
|
---|
970 |
|
---|
971 | if (!value.equals ("")) {
|
---|
972 | value = value + ",";
|
---|
973 | }
|
---|
974 | value = value + token;
|
---|
975 | }
|
---|
976 | }
|
---|
977 | // Everything else is an Option Element
|
---|
978 | Element option_element = document.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
979 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name.substring (1));
|
---|
980 | if(value != null) {
|
---|
981 | // Remove any speech marks appended in strings containing whitespace
|
---|
982 | if(value.startsWith (StaticStrings.SPEECH_CHARACTER) && value.endsWith (StaticStrings.SPEECH_CHARACTER)) {
|
---|
983 | value = value.substring (1, value.length () - 1);
|
---|
984 | }
|
---|
985 | XMLTools.setValue (option_element, value);
|
---|
986 | }
|
---|
987 | option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
988 | command_element.appendChild (option_element);
|
---|
989 | option_element = null;
|
---|
990 | name = null;
|
---|
991 | value = null;
|
---|
992 | }
|
---|
993 | names = null;
|
---|
994 | arguments = null;
|
---|
995 | }
|
---|
996 | tokenizer = null;
|
---|
997 | }
|
---|
998 | catch(Exception error) {
|
---|
999 | }
|
---|
1000 | return command_element;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | private Element parseFormat (CommandTokenizer tokenizer) {
|
---|
1004 | Element command_element = null;
|
---|
1005 | try {
|
---|
1006 | command_element = document.createElement (StaticStrings.FORMAT_ELEMENT);
|
---|
1007 | String name_str = tokenizer.nextToken ();
|
---|
1008 | String value_str = tokenizer.nextToken ();
|
---|
1009 | if(name_str != null && value_str != null) {
|
---|
1010 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
1011 | // If the value is true or false we add it as an attribute
|
---|
1012 | if(value_str.equalsIgnoreCase (StaticStrings.TRUE_STR) || value_str.equalsIgnoreCase (StaticStrings.FALSE_STR)) {
|
---|
1013 | command_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, value_str.toLowerCase ());
|
---|
1014 | }
|
---|
1015 | // Otherwise it gets added as a text node
|
---|
1016 | else {
|
---|
1017 | // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
|
---|
1018 | value_str = Codec.transform (value_str, Codec.GREENSTONE_TO_DOM);
|
---|
1019 | XMLTools.setValue (command_element, value_str);
|
---|
1020 | }
|
---|
1021 | }
|
---|
1022 | else {
|
---|
1023 | command_element = null;
|
---|
1024 | }
|
---|
1025 | name_str = null;
|
---|
1026 | value_str = null;
|
---|
1027 | }
|
---|
1028 | catch (Exception exception) {
|
---|
1029 | DebugStream.printStackTrace (exception);
|
---|
1030 | command_element = null;
|
---|
1031 | }
|
---|
1032 | return command_element;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | private Element parseIndex (String command_str) {
|
---|
1036 | Element command_element = null;
|
---|
1037 | try {
|
---|
1038 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1039 | String command = tokenizer.nextToken ();
|
---|
1040 | command_element = document.createElement (StaticStrings.INDEXES_ELEMENT);
|
---|
1041 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, (command.equals (StaticStrings.INDEX_STR) ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
1042 | command = null;
|
---|
1043 | if(!tokenizer.hasMoreTokens ()) {
|
---|
1044 |
|
---|
1045 | // there are no indexes
|
---|
1046 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1047 | command_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR); // for now
|
---|
1048 | tokenizer = null;
|
---|
1049 | return command_element;
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | while(tokenizer.hasMoreTokens ()) {
|
---|
1053 | Element index_element = document.createElement (StaticStrings.INDEX_ELEMENT);
|
---|
1054 | String index_str = tokenizer.nextToken ();
|
---|
1055 | // There are two types of index we have to consider. Old G2.38 and earlier use level:source tuplets while G2.39+ have just a single, non-comma separated list where order is important.
|
---|
1056 | boolean old_index;
|
---|
1057 | if(index_str.indexOf (StaticStrings.COLON_CHARACTER) != -1) {
|
---|
1058 | old_index = true;
|
---|
1059 | index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE, index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER)));
|
---|
1060 | index_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
|
---|
1061 | command_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1062 | }
|
---|
1063 | else {
|
---|
1064 | command_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1065 | old_index = false;
|
---|
1066 | }
|
---|
1067 | StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
|
---|
1068 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1069 | Element content_element = document.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1070 | String content_str = content_tokenizer.nextToken ();
|
---|
1071 | // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
1072 | if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1073 | if(content_str.equals (StaticStrings.TEXT_STR) || (!old_index && content_str.equals (StaticStrings.ALLFIELDS_STR))) {
|
---|
1074 | // Our special strings are OK.
|
---|
1075 | }
|
---|
1076 | else {
|
---|
1077 | content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
|
---|
1078 | }
|
---|
1079 | }
|
---|
1080 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
|
---|
1081 | index_element.appendChild (content_element);
|
---|
1082 | content_element = null;
|
---|
1083 | }
|
---|
1084 | content_tokenizer = null;
|
---|
1085 | index_str = null;
|
---|
1086 | command_element.appendChild (index_element);
|
---|
1087 | index_element = null;
|
---|
1088 | }
|
---|
1089 | tokenizer = null;
|
---|
1090 | }
|
---|
1091 | catch (Exception exception) {
|
---|
1092 | exception.printStackTrace ();
|
---|
1093 | }
|
---|
1094 | return command_element;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | private Element parseIndexDefault (String command_str) {
|
---|
1098 | Element command_element = null;
|
---|
1099 | try {
|
---|
1100 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1101 | if(tokenizer.countTokens () >= 2) {
|
---|
1102 | command_element = document.createElement (StaticStrings.INDEX_DEFAULT_ELEMENT);
|
---|
1103 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, ((tokenizer.nextToken ()).equals (StaticStrings.INDEX_DEFAULT_STR) ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
1104 | String index_str = tokenizer.nextToken ();
|
---|
1105 | String level="";
|
---|
1106 | if (index_str.indexOf (StaticStrings.COLON_CHARACTER) !=-1) {
|
---|
1107 | level = index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER));
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | command_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE,level);
|
---|
1111 |
|
---|
1112 | String content_str = index_str;
|
---|
1113 |
|
---|
1114 | if (index_str.indexOf (StaticStrings.COLON_CHARACTER) !=-1) {
|
---|
1115 | content_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | StringTokenizer content_tokenizer = new StringTokenizer (content_str, StaticStrings.COMMA_CHARACTER);
|
---|
1119 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1120 | Element content_element = document.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1121 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_tokenizer.nextToken ());
|
---|
1122 | command_element.appendChild (content_element);
|
---|
1123 | content_element = null;
|
---|
1124 | }
|
---|
1125 | content_tokenizer = null;
|
---|
1126 | content_str = null;
|
---|
1127 | content_str = null;
|
---|
1128 | index_str = null;
|
---|
1129 | }
|
---|
1130 | tokenizer = null;
|
---|
1131 | }
|
---|
1132 | catch (Exception exception) {
|
---|
1133 | }
|
---|
1134 | return command_element;
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | private Element parseLanguage (String command_str) {
|
---|
1138 | Element command_element = null;
|
---|
1139 | try {
|
---|
1140 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1141 | tokenizer.nextToken ();
|
---|
1142 | if(tokenizer.hasMoreTokens ()) {
|
---|
1143 | command_element = document.createElement (StaticStrings.LANGUAGES_ELEMENT);
|
---|
1144 | while(tokenizer.hasMoreTokens ()) {
|
---|
1145 | Element language_element = document.createElement (StaticStrings.LANGUAGE_ELEMENT);
|
---|
1146 | language_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, tokenizer.nextToken ());
|
---|
1147 | command_element.appendChild (language_element);
|
---|
1148 | language_element = null;
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 | tokenizer = null;
|
---|
1152 | }
|
---|
1153 | catch (Exception exception) {
|
---|
1154 | }
|
---|
1155 | return command_element;
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | private Element parseLanguageDefault (String command_str) {
|
---|
1159 | Element command_element = null;
|
---|
1160 | try {
|
---|
1161 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1162 | if(tokenizer.countTokens () >= 2) {
|
---|
1163 | command_element = document.createElement (StaticStrings.LANGUAGE_DEFAULT_ELEMENT);
|
---|
1164 | tokenizer.nextToken ();
|
---|
1165 | String default_language_str = tokenizer.nextToken ();
|
---|
1166 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, default_language_str);
|
---|
1167 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1168 | default_language_str = null;
|
---|
1169 | }
|
---|
1170 | tokenizer = null;
|
---|
1171 | }
|
---|
1172 | catch (Exception exception) {
|
---|
1173 | }
|
---|
1174 | return command_element;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | private Element parseLanguageMetadata (String command_str) {
|
---|
1178 | Element command_element = null;
|
---|
1179 | try {
|
---|
1180 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1181 | if(tokenizer.countTokens () >= 2) {
|
---|
1182 | command_element = document.createElement (StaticStrings.LANGUAGE_METADATA_ELEMENT);
|
---|
1183 | tokenizer.nextToken ();
|
---|
1184 | String language_metadata_str = tokenizer.nextToken ();
|
---|
1185 | if (language_metadata_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1186 | language_metadata_str = StaticStrings.EXTRACTED_NAMESPACE + language_metadata_str;
|
---|
1187 | }
|
---|
1188 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, language_metadata_str);
|
---|
1189 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1190 | language_metadata_str = null;
|
---|
1191 | }
|
---|
1192 | tokenizer = null;
|
---|
1193 |
|
---|
1194 | }
|
---|
1195 | catch (Exception exception) {
|
---|
1196 | }
|
---|
1197 | return command_element;
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | private Element parseIndexOptions (String command_str, String type, boolean assigned) {
|
---|
1201 | Element command_element = null;
|
---|
1202 | try {
|
---|
1203 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1204 | // First token is command type
|
---|
1205 | String command = tokenizer.nextToken ();
|
---|
1206 | if(tokenizer.hasMoreTokens ()) {
|
---|
1207 | command_element = document.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
|
---|
1208 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE,type);
|
---|
1209 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
1210 | while(tokenizer.hasMoreTokens ()) {
|
---|
1211 | Element option_element = document.createElement (StaticStrings.INDEXOPTION_ELEMENT);
|
---|
1212 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, tokenizer.nextToken ());
|
---|
1213 | command_element.appendChild (option_element);
|
---|
1214 | option_element = null;
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 | command = null;
|
---|
1218 | }
|
---|
1219 | catch(Exception exception) {
|
---|
1220 | }
|
---|
1221 | return command_element;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | private Element parseIndexOptionDefault (String command_str, String type, boolean assigned) {
|
---|
1225 | Element command_element = null;
|
---|
1226 | try {
|
---|
1227 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1228 | // First token is command type
|
---|
1229 | String command = tokenizer.nextToken ();
|
---|
1230 | if(tokenizer.hasMoreTokens ()) {
|
---|
1231 | command_element = document.createElement (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT);
|
---|
1232 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR)); // is it commented out or not?
|
---|
1233 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, type);
|
---|
1234 | command_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, tokenizer.nextToken ());
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | tokenizer = null;
|
---|
1238 | }
|
---|
1239 | catch (Exception exception) {
|
---|
1240 | }
|
---|
1241 | return command_element;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | private Element parseMetadata (CommandTokenizer tokenizer) {
|
---|
1245 | Element command_element = null;
|
---|
1246 | try {
|
---|
1247 | command_element = document.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
1248 | String name_str = tokenizer.nextToken ();
|
---|
1249 | String value_str = tokenizer.nextToken ();
|
---|
1250 | if(name_str != null && value_str != null) {
|
---|
1251 | String language_str = Configuration.getLanguage ();
|
---|
1252 | // Check if the value string is actually a language string
|
---|
1253 | if(value_str.startsWith (StaticStrings.LBRACKET_CHARACTER) && value_str.endsWith (StaticStrings.RBRACKET_CHARACTER)) {
|
---|
1254 | language_str = value_str.substring (value_str.indexOf (StaticStrings.LANGUAGE_ARGUMENT) + 2, value_str.length () - 1);
|
---|
1255 | value_str = tokenizer.nextToken ();
|
---|
1256 | }
|
---|
1257 | if(value_str != null) {
|
---|
1258 | // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
|
---|
1259 | value_str = Codec.transform (value_str, Codec.GREENSTONE_TO_DOM);
|
---|
1260 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
1261 | command_element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, language_str);
|
---|
1262 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1263 | XMLTools.setValue (command_element, value_str);
|
---|
1264 | }
|
---|
1265 | else {
|
---|
1266 | command_element = null;
|
---|
1267 | }
|
---|
1268 | language_str = null;
|
---|
1269 | }
|
---|
1270 | else {
|
---|
1271 | command_element = null;
|
---|
1272 | }
|
---|
1273 | name_str = null;
|
---|
1274 | value_str = null;
|
---|
1275 | }
|
---|
1276 | catch (Exception exception) {
|
---|
1277 | DebugStream.printStackTrace (exception);
|
---|
1278 | command_element = null;
|
---|
1279 | }
|
---|
1280 | return command_element;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | private Element parseMetadataSpecial (String command_str) {
|
---|
1284 | Element command_element = null;
|
---|
1285 | try {
|
---|
1286 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1287 | if(tokenizer.countTokens () >= 2) {
|
---|
1288 | String name_str = tokenizer.nextToken ();
|
---|
1289 | String value_str = tokenizer.nextToken ();
|
---|
1290 | if (name_str.equals (StaticStrings.COLLECTIONMETADATA_CREATOR_STR)) {
|
---|
1291 | command_element = document.createElement (StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT);
|
---|
1292 | }
|
---|
1293 | else if(name_str.equals (StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR)) {
|
---|
1294 | command_element = document.createElement (StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT);
|
---|
1295 | }
|
---|
1296 | else if(name_str.equals (StaticStrings.COLLECTIONMETADATA_PUBLIC_STR)) {
|
---|
1297 | command_element = document.createElement (StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT);
|
---|
1298 | }
|
---|
1299 | else if (name_str.equals (StaticStrings.BUILDTYPE_STR)) {
|
---|
1300 | command_element = document.createElement (StaticStrings.BUILDTYPE_ELEMENT);
|
---|
1301 | }
|
---|
1302 | if(command_element != null) {
|
---|
1303 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
1304 | command_element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
|
---|
1305 | command_element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1306 | command_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1307 | if(value_str.startsWith (StaticStrings.SPEECH_CHARACTER) && value_str.endsWith (StaticStrings.SPEECH_CHARACTER)) {
|
---|
1308 | value_str = value_str.substring (1, value_str.length () - 1);
|
---|
1309 | }
|
---|
1310 | XMLTools.setValue (command_element, value_str);
|
---|
1311 | }
|
---|
1312 | value_str = null;
|
---|
1313 | name_str = null;
|
---|
1314 | }
|
---|
1315 | tokenizer = null;
|
---|
1316 | }
|
---|
1317 | catch (Exception exception) {
|
---|
1318 | }
|
---|
1319 | return command_element;
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | private Element parsePlugin (String command_str) {
|
---|
1323 | Element command_element = null;
|
---|
1324 | try {
|
---|
1325 | CommandTokenizer tokenizer = new CommandTokenizer (command_str);
|
---|
1326 | // Check the token count. The token count from a command tokenizer isn't guarenteed to be correct, but it does give the maximum number of available tokens according to the underlying StringTokenizer (some of which may actually be append together by the CommandTokenizer as being a single argument).
|
---|
1327 | if(tokenizer.countTokens () >= 2) {
|
---|
1328 | command_element = document.createElement (StaticStrings.PLUGIN_ELEMENT);
|
---|
1329 | // First token is plugin
|
---|
1330 | tokenizer.nextToken ();
|
---|
1331 | // The next token is the type
|
---|
1332 | String type = tokenizer.nextToken ();
|
---|
1333 | type = ensureNewPluginName(type);
|
---|
1334 | command_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
1335 | // Now we parse out the remaining arguments into a hashmapping from name to value
|
---|
1336 | HashMap arguments = parseArguments (tokenizer);
|
---|
1337 | // Assign the arguments as Option elements, but watch out for the metadata argument as we treat that differently
|
---|
1338 | // also watch out for the deprecated -use_metadata_files option to RecPlug and remove it
|
---|
1339 | Iterator names = arguments.keySet ().iterator ();
|
---|
1340 | while(names.hasNext ()) {
|
---|
1341 | String name = (String) names.next ();
|
---|
1342 | String value = (String) arguments.get (name); // Can be null
|
---|
1343 |
|
---|
1344 | if(type.equals (StaticStrings.RECPLUG_STR) && name.substring (1).equals (StaticStrings.USE_METADATA_FILES_ARGUMENT)) {
|
---|
1345 | continue; // ignore this option
|
---|
1346 | }
|
---|
1347 | Element option_element = document.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
1348 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name.substring (1));
|
---|
1349 | option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1350 | if(value != null) {
|
---|
1351 | // Remove any speech marks appended in strings containing whitespace
|
---|
1352 | if(value.startsWith (StaticStrings.SPEECH_CHARACTER) && value.endsWith (StaticStrings.SPEECH_CHARACTER)) {
|
---|
1353 | value = value.substring (1, value.length () - 1);
|
---|
1354 | }
|
---|
1355 | if(name.equals (StaticStrings.METADATA_ARGUMENT)) {
|
---|
1356 | // The metadata argument must be the fully qualified name of a metadata element, so if it doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
1357 | if(value.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1358 | value = StaticStrings.EXTRACTED_NAMESPACE + value;
|
---|
1359 | }
|
---|
1360 | }
|
---|
1361 | XMLTools.setValue (option_element, value);
|
---|
1362 | }
|
---|
1363 | command_element.appendChild (option_element);
|
---|
1364 | option_element = null;
|
---|
1365 | name = null;
|
---|
1366 | value = null;
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | type = null;
|
---|
1370 | names = null;
|
---|
1371 | arguments = null;
|
---|
1372 | }
|
---|
1373 | tokenizer = null;
|
---|
1374 | }
|
---|
1375 | catch(Exception exception) {
|
---|
1376 | // This catch clause had been left empty. If this is deliberate then
|
---|
1377 | // we should have a comment here explaining why there is no need to
|
---|
1378 | // print anything out. Am assuming this is mistake for now, and
|
---|
1379 | // have added in a call to printStackTrace()
|
---|
1380 | System.err.println("Malformed plugin statement");
|
---|
1381 | exception.printStackTrace();
|
---|
1382 | }
|
---|
1383 | return command_element;
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | /* search types are now handled as formats - leave this here to convert in case we have an old config file */
|
---|
1387 | private Element parseSearchType (String command_str) {
|
---|
1388 | Element command_element = null;
|
---|
1389 | try {
|
---|
1390 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1391 | // First token is command type (searchtype)
|
---|
1392 | tokenizer.nextToken ();
|
---|
1393 | if(tokenizer.hasMoreTokens ()) {
|
---|
1394 | command_element = document.createElement (StaticStrings.FORMAT_ELEMENT);
|
---|
1395 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, "SearchTypes");
|
---|
1396 | String value = tokenizer.nextToken ();
|
---|
1397 | while(tokenizer.hasMoreTokens ()) {
|
---|
1398 | value += ","+tokenizer.nextToken ();
|
---|
1399 | }
|
---|
1400 | value = Codec.transform (value, Codec.GREENSTONE_TO_DOM);
|
---|
1401 | XMLTools.setValue (command_element, value);
|
---|
1402 | }
|
---|
1403 | }
|
---|
1404 | catch(Exception exception) {
|
---|
1405 | }
|
---|
1406 | return command_element;
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | private Element parseSubCollection (String command_str) {
|
---|
1410 | Element command_element = null;
|
---|
1411 | try {
|
---|
1412 | CommandTokenizer tokenizer = new CommandTokenizer (command_str);
|
---|
1413 | if(tokenizer.countTokens () >= 3) {
|
---|
1414 | command_element = document.createElement (StaticStrings.SUBCOLLECTION_ELEMENT);
|
---|
1415 | // First token is command type
|
---|
1416 | tokenizer.nextToken ();
|
---|
1417 | // Then subcollection identifier
|
---|
1418 | command_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, tokenizer.nextToken ());
|
---|
1419 | // Then finally the pattern used to build the subcollection partition
|
---|
1420 | String full_pattern_str = tokenizer.nextToken ();
|
---|
1421 | // Set inclusion/exclusion flag and remove any exclamation mark
|
---|
1422 | boolean exclusion = full_pattern_str.startsWith (StaticStrings.EXCLAMATION_CHARACTER);
|
---|
1423 | if (exclusion) {
|
---|
1424 | full_pattern_str = full_pattern_str.substring (1, full_pattern_str.length ());
|
---|
1425 | command_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, StaticStrings.EXCLUDE_STR);
|
---|
1426 | }
|
---|
1427 | else {
|
---|
1428 | command_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, StaticStrings.INCLUDE_STR);
|
---|
1429 | }
|
---|
1430 | StringTokenizer pattern_tokenizer = new StringTokenizer (full_pattern_str, StaticStrings.SEPARATOR_CHARACTER);
|
---|
1431 | if(pattern_tokenizer.countTokens () >= 2) {
|
---|
1432 | String content_str = pattern_tokenizer.nextToken ();
|
---|
1433 | // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
1434 | if(!content_str.equals (StaticStrings.FILENAME_STR) && content_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1435 | content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
|
---|
1436 | }
|
---|
1437 | command_element.setAttribute (StaticStrings.CONTENT_ATTRIBUTE, content_str);
|
---|
1438 | XMLTools.setValue (command_element, pattern_tokenizer.nextToken ());
|
---|
1439 | if(pattern_tokenizer.hasMoreTokens ()) {
|
---|
1440 | command_element.setAttribute (StaticStrings.OPTIONS_ATTRIBUTE, pattern_tokenizer.nextToken ());
|
---|
1441 | }
|
---|
1442 | }
|
---|
1443 | pattern_tokenizer = null;
|
---|
1444 | }
|
---|
1445 | }
|
---|
1446 | catch(Exception exception) {
|
---|
1447 | exception.printStackTrace ();
|
---|
1448 | }
|
---|
1449 | return command_element;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | private Element parseSubCollectionDefaultIndex (String command_str) {
|
---|
1453 | Element command_element = null;
|
---|
1454 | try {
|
---|
1455 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1456 | if(tokenizer.countTokens () == 2) {
|
---|
1457 | command_element = document.createElement (StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT);
|
---|
1458 | tokenizer.nextToken ();
|
---|
1459 | //command_element.setAttribute(CONTENT_ATTRIBUTE, tokenizer.nextToken());
|
---|
1460 | String content_str = tokenizer.nextToken ();
|
---|
1461 | StringTokenizer content_tokenizer = new StringTokenizer (content_str, StaticStrings.COMMA_CHARACTER);
|
---|
1462 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1463 | Element content_element = document.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1464 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_tokenizer.nextToken ());
|
---|
1465 | command_element.appendChild (content_element);
|
---|
1466 | content_element = null;
|
---|
1467 | }
|
---|
1468 | content_tokenizer = null;
|
---|
1469 | content_str = null;
|
---|
1470 | }
|
---|
1471 | tokenizer = null;
|
---|
1472 | }
|
---|
1473 | catch(Exception exception) {
|
---|
1474 | }
|
---|
1475 | return command_element;
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | private Element parseSubCollectionIndex (String command_str) {
|
---|
1479 | Element command_element = null;
|
---|
1480 | try {
|
---|
1481 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1482 | tokenizer.nextToken ();
|
---|
1483 | if(tokenizer.hasMoreTokens ()) {
|
---|
1484 | command_element = document.createElement (StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT);
|
---|
1485 | }
|
---|
1486 | while(tokenizer.hasMoreTokens ()) {
|
---|
1487 | Element subcollectionindex_element = document.createElement (StaticStrings.INDEX_ELEMENT);
|
---|
1488 | //command_element.setAttribute(CONTENT_ATTRIBUTE, tokenizer.nextToken());
|
---|
1489 | String content_str = tokenizer.nextToken ();
|
---|
1490 | StringTokenizer content_tokenizer = new StringTokenizer (content_str, StaticStrings.COMMA_CHARACTER);
|
---|
1491 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1492 | Element content_element = document.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1493 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_tokenizer.nextToken ());
|
---|
1494 | subcollectionindex_element.appendChild (content_element);
|
---|
1495 | content_element = null;
|
---|
1496 | }
|
---|
1497 | content_tokenizer = null;
|
---|
1498 | content_str = null;
|
---|
1499 | command_element.appendChild (subcollectionindex_element);
|
---|
1500 | subcollectionindex_element = null;
|
---|
1501 | }
|
---|
1502 | tokenizer = null;
|
---|
1503 | }
|
---|
1504 | catch (Exception exception) {
|
---|
1505 | }
|
---|
1506 | return command_element;
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | private Element parseSuperCollection (String command_str) {
|
---|
1510 | Element command_element = null;
|
---|
1511 | try {
|
---|
1512 | StringTokenizer tokenizer = new StringTokenizer (command_str);
|
---|
1513 | if(tokenizer.countTokens () >= 3) {
|
---|
1514 | command_element = document.createElement (StaticStrings.SUPERCOLLECTION_ELEMENT);
|
---|
1515 | tokenizer.nextToken ();
|
---|
1516 | while(tokenizer.hasMoreTokens ()) {
|
---|
1517 | Element collection_element = document.createElement (StaticStrings.COLLECTION_ELEMENT);
|
---|
1518 | collection_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, tokenizer.nextToken ());
|
---|
1519 | command_element.appendChild (collection_element);
|
---|
1520 | collection_element = null;
|
---|
1521 | }
|
---|
1522 | }
|
---|
1523 | tokenizer = null;
|
---|
1524 | }
|
---|
1525 | catch(Exception exception) {
|
---|
1526 | }
|
---|
1527 | return command_element;
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | static private String pluginToString (Element command_element, boolean show_extracted_namespace) {
|
---|
1531 | StringBuffer text = new StringBuffer ();
|
---|
1532 | if(!command_element.getAttribute (StaticStrings.SEPARATOR_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
1533 | text.append (StaticStrings.PLUGIN_STR);
|
---|
1534 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1535 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1536 | text.append (command_element.getAttribute (StaticStrings.TYPE_ATTRIBUTE));
|
---|
1537 | // Retrieve, and output, the arguments
|
---|
1538 | NodeList option_elements = command_element.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
1539 | int option_elements_length = option_elements.getLength ();
|
---|
1540 | if(option_elements_length > 0) {
|
---|
1541 | for(int j = 0; j < option_elements_length; j++) {
|
---|
1542 | Element option_element = (Element) option_elements.item (j);
|
---|
1543 | if(option_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
1544 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1545 | text.append (StaticStrings.MINUS_CHARACTER);
|
---|
1546 | text.append (option_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1547 | String value_str = XMLTools.getValue (option_element);
|
---|
1548 | if(!show_extracted_namespace && value_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
1549 | value_str = value_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
1550 | }
|
---|
1551 | if(value_str.length () > 0) {
|
---|
1552 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1553 | if(value_str.indexOf (StaticStrings.SPACE_CHARACTER) == -1) {
|
---|
1554 | text.append (value_str);
|
---|
1555 | }
|
---|
1556 | else {
|
---|
1557 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
1558 | text.append (value_str);
|
---|
1559 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
1560 | }
|
---|
1561 | }
|
---|
1562 | value_str = null;
|
---|
1563 | }
|
---|
1564 | option_element = null;
|
---|
1565 | }
|
---|
1566 | }
|
---|
1567 | option_elements = null;
|
---|
1568 | }
|
---|
1569 | return text.toString ();
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | static private String searchtypeToString (Element command_element) {
|
---|
1573 | if(command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
1574 | StringBuffer text = new StringBuffer (StaticStrings.SEARCHTYPE_STR);
|
---|
1575 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1576 | NodeList search_elements = command_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
1577 | int search_elements_length = search_elements.getLength ();
|
---|
1578 | for(int i = 0; i < search_elements_length; i++) {
|
---|
1579 | Element search_element = (Element) search_elements.item (i);
|
---|
1580 | text.append (search_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1581 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1582 | }
|
---|
1583 | return text.substring (0, text.length () - 1);
|
---|
1584 | }
|
---|
1585 | else {
|
---|
1586 | return null;
|
---|
1587 | }
|
---|
1588 | }
|
---|
1589 |
|
---|
1590 | static private String subcollectionToString (Element command_element, boolean show_extracted_namespace) {
|
---|
1591 | StringBuffer text = new StringBuffer (StaticStrings.SUBCOLLECTION_STR);
|
---|
1592 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1593 | text.append (command_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1594 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1595 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1596 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
1597 | if(command_element.getAttribute (StaticStrings.TYPE_ATTRIBUTE).equals (StaticStrings.EXCLUDE_STR)) {
|
---|
1598 | text.append (StaticStrings.EXCLAMATION_CHARACTER);
|
---|
1599 | }
|
---|
1600 | String content_str = command_element.getAttribute (StaticStrings.CONTENT_ATTRIBUTE);
|
---|
1601 | if(!show_extracted_namespace && content_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
1602 | content_str = content_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
1603 | }
|
---|
1604 | text.append (content_str);
|
---|
1605 | content_str = null;
|
---|
1606 | text.append (StaticStrings.SEPARATOR_CHARACTER);
|
---|
1607 | text.append (XMLTools.getValue (command_element));
|
---|
1608 | text.append (StaticStrings.SEPARATOR_CHARACTER);
|
---|
1609 | String options_str = command_element.getAttribute (StaticStrings.OPTIONS_ATTRIBUTE);
|
---|
1610 | if(options_str.length () > 0) {
|
---|
1611 | text.append (options_str);
|
---|
1612 | }
|
---|
1613 | options_str = null;
|
---|
1614 | text.append (StaticStrings.SPEECH_CHARACTER);
|
---|
1615 | return text.toString ();
|
---|
1616 | }
|
---|
1617 |
|
---|
1618 | static private String subcollectionDefaultIndexToString (Element command_element) {
|
---|
1619 | StringBuffer text = new StringBuffer (StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_STR);
|
---|
1620 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1621 | NodeList content_elements = command_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
1622 | int content_elements_length = content_elements.getLength ();
|
---|
1623 | for(int j = 0; j < content_elements_length; j++) {
|
---|
1624 | Element content_element = (Element) content_elements.item (j);
|
---|
1625 | text.append (content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1626 | if(j < content_elements_length - 1) {
|
---|
1627 | text.append (StaticStrings.COMMA_CHARACTER);
|
---|
1628 | }
|
---|
1629 | }
|
---|
1630 | return text.toString ();
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | static private String subcollectionIndexesToString (Element command_element) {
|
---|
1634 | StringBuffer text = new StringBuffer (StaticStrings.SUBCOLLECTION_INDEX_STR);
|
---|
1635 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1636 | // Retrieve all of the subcollection index partitions
|
---|
1637 | NodeList subcollectionindex_elements = command_element.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
|
---|
1638 | int subcollectionindex_elements_length = subcollectionindex_elements.getLength ();
|
---|
1639 | if(subcollectionindex_elements_length == 0) {
|
---|
1640 | return null;
|
---|
1641 | }
|
---|
1642 | for(int j = 0; j < subcollectionindex_elements_length; j++) {
|
---|
1643 | Element subcollectionindex_element = (Element) subcollectionindex_elements.item (j);
|
---|
1644 | NodeList content_elements = subcollectionindex_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
1645 | int content_elements_length = content_elements.getLength ();
|
---|
1646 | for(int k = 0; k < content_elements_length; k++) {
|
---|
1647 | Element content_element = (Element) content_elements.item (k);
|
---|
1648 | text.append (content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1649 | if(k < content_elements_length - 1) {
|
---|
1650 | text.append (StaticStrings.COMMA_CHARACTER);
|
---|
1651 | }
|
---|
1652 | }
|
---|
1653 | if(j < subcollectionindex_elements_length - 1) {
|
---|
1654 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1655 | }
|
---|
1656 | }
|
---|
1657 | return text.toString ();
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 | static private String supercollectionToString (Element command_element) {
|
---|
1661 | NodeList content_elements = command_element.getElementsByTagName (StaticStrings.COLLECTION_ELEMENT);
|
---|
1662 | int content_elements_length = content_elements.getLength ();
|
---|
1663 | if(content_elements_length > 1) {
|
---|
1664 | StringBuffer text = new StringBuffer (StaticStrings.SUPERCOLLECTION_STR);
|
---|
1665 | text.append (StaticStrings.TAB_CHARACTER);
|
---|
1666 | for(int j = 0; j < content_elements_length; j++) {
|
---|
1667 | Element content_element = (Element) content_elements.item (j);
|
---|
1668 | text.append (content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
|
---|
1669 | if(j < content_elements_length - 1) {
|
---|
1670 | text.append (StaticStrings.SPACE_CHARACTER);
|
---|
1671 | }
|
---|
1672 | }
|
---|
1673 | return text.toString ();
|
---|
1674 | }
|
---|
1675 | return null;
|
---|
1676 | }
|
---|
1677 |
|
---|
1678 | static private String unknownToString (Element command_element) {
|
---|
1679 | return XMLTools.getValue (command_element);
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 | /** Write the text to the buffer. This is used so we don't have to worry about storing intermediate String values just so we can calaulate length and offset.
|
---|
1683 | * @param writer the BufferedWriter to which the str will be written
|
---|
1684 | * @param str the String to be written
|
---|
1685 | */
|
---|
1686 | private void write (BufferedWriter writer, String str)
|
---|
1687 | throws IOException {
|
---|
1688 | writer.write (str, 0, str.length ());
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | /** ********************************************************************************************************
|
---|
1692 | The code from this point below are used for greenstone 3 collection configuration, i.e., read ColletionConfig.xml
|
---|
1693 | * into the internal DOM tree, and convert the internal DOM tree back to CollectionConfig.xml.
|
---|
1694 | *
|
---|
1695 | Methods named 'doXXXX' are for convert collectionConfig.xml into the internal configuration xml structure;
|
---|
1696 | Methods named 'convertXXXX' are for convert the internal configuration xml structure back to collectionConfig.xml.
|
---|
1697 | ************************************************************************************************************ */
|
---|
1698 |
|
---|
1699 | /**Arguments: metadataListNode->the 'displayItemList' element in collectionConfig.xml
|
---|
1700 | name_value->the value of the 'name' attribute of 'index' element;
|
---|
1701 | att_value->the value of the 'name' attribute of 'displayItem' element
|
---|
1702 | return: an ArrayList of the contructed 'CollectionMetadata' elements
|
---|
1703 | */
|
---|
1704 | private ArrayList doDisplayItemList (Document to, Node displayListNode, String att_value, String name_value) {
|
---|
1705 | Element toElement = to.getDocumentElement ();
|
---|
1706 | ArrayList display_item_list = new ArrayList ();
|
---|
1707 | ArrayList item_list = XMLTools.getNamedElementList ((Element)displayListNode,
|
---|
1708 | StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, att_value);
|
---|
1709 | if (item_list == null) {
|
---|
1710 | return null;
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | for (int i=0; i<item_list.size (); i++) {
|
---|
1714 | Element item = (Element)item_list.get (i);
|
---|
1715 | String text = XMLTools.getNodeText (item);
|
---|
1716 |
|
---|
1717 | //If there is nothing to display, don't bother creating the element
|
---|
1718 | if (text == "") {
|
---|
1719 | continue;
|
---|
1720 | }
|
---|
1721 | //get the value in 'lang=value'
|
---|
1722 | String lang = item.getAttribute (StaticStrings.LANG_STR);
|
---|
1723 |
|
---|
1724 | Element e = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
1725 | e.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1726 | e.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_value);
|
---|
1727 | e.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
|
---|
1728 | XMLTools.setNodeText (e, text);
|
---|
1729 | display_item_list.add (e);
|
---|
1730 | }
|
---|
1731 | return display_item_list;
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | private ArrayList doMetadataList (Document to, Node metadataListNode, String ele_name, String att_value) {
|
---|
1735 | Element toElement = to.getDocumentElement ();
|
---|
1736 | ArrayList metadata_list = new ArrayList ();
|
---|
1737 |
|
---|
1738 | ArrayList item_list = XMLTools.getNamedElementList ((Element)metadataListNode,
|
---|
1739 | StaticStrings.METADATA_STR, StaticStrings.NAME_ATTRIBUTE, att_value);
|
---|
1740 | if (item_list == null) {
|
---|
1741 | return null;
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | for (int i=0; i<item_list.size (); i++) {
|
---|
1745 | Element item = (Element)item_list.get (i);
|
---|
1746 | String text = XMLTools.getNodeText (item);
|
---|
1747 |
|
---|
1748 | //If there is nothing to display, don't bother creating the element
|
---|
1749 | if (text == "") {
|
---|
1750 | continue;
|
---|
1751 | }
|
---|
1752 | //get the value in 'lang=value'
|
---|
1753 | String lang = item.getAttribute (StaticStrings.LANG_STR);
|
---|
1754 |
|
---|
1755 | Element element = to.createElement (ele_name);
|
---|
1756 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, att_value);
|
---|
1757 | element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
|
---|
1758 | element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1759 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1760 | XMLTools.setNodeText (element, text);
|
---|
1761 |
|
---|
1762 | metadata_list.add (element);
|
---|
1763 | }
|
---|
1764 | return metadata_list;
|
---|
1765 | }
|
---|
1766 | // 'to' is the internal structure
|
---|
1767 | private void doMGIndexes (Document to, Node searchNode) {
|
---|
1768 | Element toElement = to.getDocumentElement ();
|
---|
1769 | Element indexes_element = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
|
---|
1770 | indexes_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1771 | indexes_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1772 |
|
---|
1773 | NodeList index_children = ((Element)searchNode).getElementsByTagName (StaticStrings.INDEX_LOW_STR);//index
|
---|
1774 | int num_nodes = index_children.getLength ();
|
---|
1775 |
|
---|
1776 | for (int i=0; i<num_nodes; i++) {
|
---|
1777 | Element e = (Element)index_children.item (i);
|
---|
1778 | String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
1779 | String index_str_display = index_str;//used for creating collectionmetadata for this index
|
---|
1780 | Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
|
---|
1781 |
|
---|
1782 | // For mg, it's the 'Old G2.38 and earlier' that use level:source tuplets, but we double check it anyway
|
---|
1783 | boolean old_index = true;
|
---|
1784 | if(index_str.indexOf (StaticStrings.COLON_CHARACTER) == -1) {
|
---|
1785 | // It doesn't contain ':' character
|
---|
1786 | System.err.println ("Something is wrong! the index should be level:source tuplets.");
|
---|
1787 | old_index = false;
|
---|
1788 | }
|
---|
1789 | else {
|
---|
1790 | // Handling 'index' element
|
---|
1791 | index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE,
|
---|
1792 | index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER)));
|
---|
1793 | index_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
|
---|
1794 |
|
---|
1795 | //Each index may have a list of comma-separated strings.
|
---|
1796 | //split them into 'content' elements in the internal structure
|
---|
1797 | StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
|
---|
1798 | //index_str = "";
|
---|
1799 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1800 | // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
|
---|
1801 |
|
---|
1802 |
|
---|
1803 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1804 | String content_str = content_tokenizer.nextToken ();
|
---|
1805 | // Since the contents of indexes have to be certain keywords, or metadata elements,
|
---|
1806 | //if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
1807 | if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1808 | if(content_str.equals (StaticStrings.TEXT_STR) ||
|
---|
1809 | (!old_index && content_str.equals (StaticStrings.ALLFIELDS_STR))) {
|
---|
1810 | // in this case, do nothing
|
---|
1811 | }
|
---|
1812 | else {
|
---|
1813 | content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
|
---|
1814 | }
|
---|
1815 | }
|
---|
1816 |
|
---|
1817 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
|
---|
1818 | index_element.appendChild (content_element);
|
---|
1819 | content_element = null;
|
---|
1820 | } // while ends
|
---|
1821 |
|
---|
1822 | indexes_element.appendChild (index_element);
|
---|
1823 |
|
---|
1824 | // Handling 'displayItem' elements and Constructing 'collectionmetadata' elements
|
---|
1825 | // Use the fully qualified index names
|
---|
1826 | ArrayList collectionmetadata_list = doDisplayItemList (to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
|
---|
1827 | appendArrayList (toElement, collectionmetadata_list);
|
---|
1828 | } //else ends
|
---|
1829 | } //for loop ends
|
---|
1830 | appendProperly (toElement, indexes_element);
|
---|
1831 |
|
---|
1832 | //***//
|
---|
1833 | // create another set of <indexes> which will be used when user switches to MGPP/LUCENE
|
---|
1834 | // i.e. we build a default index set for a start
|
---|
1835 |
|
---|
1836 | String []index_strs =
|
---|
1837 | {StaticStrings.TEXT_STR,
|
---|
1838 | StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.TITLE_ELEMENT,
|
---|
1839 | StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.SOURCE_ELEMENT};
|
---|
1840 |
|
---|
1841 | Element mgpp_indexes = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
|
---|
1842 | mgpp_indexes.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1843 | mgpp_indexes.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1844 | for (int i=0; i<index_strs.length; i++) {
|
---|
1845 | Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
|
---|
1846 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1847 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
|
---|
1848 | index_element.appendChild (content_element);
|
---|
1849 | mgpp_indexes.appendChild (index_element);
|
---|
1850 |
|
---|
1851 | // Contructing 'collectionmetadata' elements for 'mgpp' indexes
|
---|
1852 | Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
1853 | collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1854 | collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
|
---|
1855 | collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
|
---|
1856 | if (index_strs[i].indexOf (StaticStrings.NS_SEP) != -1) {
|
---|
1857 | index_strs[i] = index_strs[i].substring (index_strs[i].indexOf (StaticStrings.NS_SEP) + 1);
|
---|
1858 | }
|
---|
1859 | XMLTools.setNodeText (collectionmetadata, index_strs[i]);
|
---|
1860 |
|
---|
1861 | appendProperly (toElement, collectionmetadata);
|
---|
1862 |
|
---|
1863 | }
|
---|
1864 | appendProperly (toElement, mgpp_indexes);
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | //This is actually doing indexes for both mgpp and lucene
|
---|
1868 | private void doMGPPIndexes (Document to, Node searchNode) {
|
---|
1869 | Element toElement = to.getDocumentElement ();
|
---|
1870 | Element indexes_element = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
|
---|
1871 | indexes_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1872 | indexes_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1873 |
|
---|
1874 | NodeList index_children = ((Element)searchNode).getElementsByTagName (StaticStrings.INDEX_LOW_STR);//index
|
---|
1875 | int num_nodes = index_children.getLength ();
|
---|
1876 |
|
---|
1877 | for (int i=0; i<num_nodes; i++) {
|
---|
1878 |
|
---|
1879 | Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
|
---|
1880 | Element e = (Element)index_children.item (i);
|
---|
1881 | String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
1882 | String index_str_display = index_str;//for creating collectionmetadata for this index
|
---|
1883 |
|
---|
1884 | // Handling 'index' element
|
---|
1885 | // Double check to make sure it's not colon separated style index.
|
---|
1886 | boolean old_index = false;
|
---|
1887 | if(index_str.indexOf (StaticStrings.COLON_CHARACTER) != -1) {
|
---|
1888 | System.err.println ("Something is wrong! the index should NOT be level:source tuplets style.");
|
---|
1889 | old_index = true;
|
---|
1890 | }
|
---|
1891 | //Each index may have a list of comma-separated strings.
|
---|
1892 | //split them into 'content' elements in the internal structure
|
---|
1893 | StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
|
---|
1894 | //index_str = "";
|
---|
1895 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
1896 | // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
|
---|
1897 |
|
---|
1898 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1899 | String content_str = content_tokenizer.nextToken ();
|
---|
1900 | // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
1901 | if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
1902 | if(content_str.equals (StaticStrings.TEXT_STR)) {
|
---|
1903 | // in this case, do nothing
|
---|
1904 | }
|
---|
1905 | else {
|
---|
1906 | content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
|
---|
1907 | }
|
---|
1908 | }
|
---|
1909 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
|
---|
1910 | index_element.appendChild (content_element);
|
---|
1911 | content_element = null;
|
---|
1912 | } //while ends
|
---|
1913 |
|
---|
1914 | indexes_element.appendChild (index_element);
|
---|
1915 |
|
---|
1916 |
|
---|
1917 | index_element = null;
|
---|
1918 |
|
---|
1919 | // Handling 'displayItem' element of this 'index' element
|
---|
1920 | // 'e' is the parent element 'index' of 'displayItem' element
|
---|
1921 | ArrayList collectionmetadata_list = doDisplayItemList (to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
|
---|
1922 | appendArrayList (toElement, collectionmetadata_list);
|
---|
1923 |
|
---|
1924 |
|
---|
1925 | } // for loop ends
|
---|
1926 | toElement.appendChild (indexes_element);
|
---|
1927 |
|
---|
1928 | // create another set of <indexes> which will be used when user switches to MG
|
---|
1929 | // i.e. we build a default index set for a start
|
---|
1930 | Element mg_indexes = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
|
---|
1931 | mg_indexes.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1932 | mg_indexes.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
1933 |
|
---|
1934 | //put the namespace '.ex' as prefix to the indexes
|
---|
1935 | String []index_strs =
|
---|
1936 | {StaticStrings.TEXT_STR,
|
---|
1937 | StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.TITLE_ELEMENT,
|
---|
1938 | StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.SOURCE_ELEMENT};
|
---|
1939 | for (int i=0; i<index_strs.length; i++) {
|
---|
1940 | Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
|
---|
1941 | index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE, StaticStrings.DOCUMENT_STR);
|
---|
1942 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
1943 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
|
---|
1944 | index_element.appendChild (content_element);
|
---|
1945 |
|
---|
1946 | mg_indexes.appendChild (index_element);
|
---|
1947 |
|
---|
1948 | // Contructing 'collectionmetadata' elements for 'mg' indexes
|
---|
1949 | Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
1950 | collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1951 | String temp = StaticStrings.DOCUMENT_STR.concat (StaticStrings.COLON_CHARACTER).concat (index_strs[i]);
|
---|
1952 | collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, temp);
|
---|
1953 | collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
|
---|
1954 | if (index_strs[i].indexOf (StaticStrings.NS_SEP) != -1) {
|
---|
1955 | index_strs[i] = index_strs[i].substring (index_strs[i].indexOf (StaticStrings.NS_SEP) + 1);
|
---|
1956 | }
|
---|
1957 | XMLTools.setNodeText (collectionmetadata, index_strs[i]);
|
---|
1958 |
|
---|
1959 | appendProperly (toElement, collectionmetadata);
|
---|
1960 |
|
---|
1961 | }
|
---|
1962 | toElement.appendChild (mg_indexes);
|
---|
1963 |
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | private void doDisplayFormat (Document to, Element from) {
|
---|
1967 | //display element in the xml file
|
---|
1968 | Element de = (Element)XMLTools.getChildByTagName (from, StaticStrings.DISPLAY_STR);
|
---|
1969 | if (de == null) {
|
---|
1970 | return;
|
---|
1971 | }
|
---|
1972 | //format element in the display element
|
---|
1973 | Element fe = (Element)XMLTools.getChildByTagName (de, StaticStrings.FORMAT_STR);
|
---|
1974 |
|
---|
1975 | to.getDocumentElement ().appendChild (doFormat(to, fe, StaticStrings.DISPLAY_STR));
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | //construct 'DefaultIndex' element in the internal structure from collectionConfig.xml
|
---|
1979 | private void doDefaultIndex (Document to, Node searchNode) {
|
---|
1980 | Element toElement = to.getDocumentElement ();
|
---|
1981 | Element default_index_element = to.createElement (StaticStrings.INDEX_DEFAULT_ELEMENT);
|
---|
1982 | default_index_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
1983 |
|
---|
1984 | Element e = (Element)XMLTools.getChildByTagName (searchNode, StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE);//defaultIndex
|
---|
1985 | if (e == null) {
|
---|
1986 | return;
|
---|
1987 | }
|
---|
1988 | String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
1989 |
|
---|
1990 | boolean old_index = false;
|
---|
1991 | if(index_str.indexOf (StaticStrings.COLON_CHARACTER) != -1) {
|
---|
1992 | //The index is 'level:source tuplets' which is for mg. Take out 'level'
|
---|
1993 | old_index = true;
|
---|
1994 | default_index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE,
|
---|
1995 | index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER)));
|
---|
1996 | index_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
|
---|
1997 | } else {
|
---|
1998 | default_index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE, "");
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | //Each index may have a list of comma-separated strings.
|
---|
2002 | //split them into 'content' elements in the internal structure
|
---|
2003 | StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
|
---|
2004 | while(content_tokenizer.hasMoreTokens ()) {
|
---|
2005 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
2006 | String content_str = content_tokenizer.nextToken ();
|
---|
2007 | // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
2008 | if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
2009 | if(content_str.equals (StaticStrings.TEXT_STR) ||
|
---|
2010 | (!old_index && content_str.equals (StaticStrings.ALLFIELDS_STR))) {
|
---|
2011 | // in this case, do nothing
|
---|
2012 | }
|
---|
2013 | else {
|
---|
2014 | content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
|
---|
2015 | }
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
|
---|
2019 | default_index_element.appendChild (content_element);
|
---|
2020 | content_element = null;
|
---|
2021 | }
|
---|
2022 | appendProperly (toElement, default_index_element);
|
---|
2023 | }
|
---|
2024 | // For mg, this method is still called, but make it 'assigned=false'
|
---|
2025 | private void doDefaultLevel (Document to, Node searchNode) {
|
---|
2026 | Element toElement = to.getDocumentElement ();
|
---|
2027 | Element default_index_option = to.createElement (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT);
|
---|
2028 | default_index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVEL_DEFAULT_STR);
|
---|
2029 |
|
---|
2030 | Element e = (Element)XMLTools.getChildByTagName (searchNode, StaticStrings.LEVEL_DEFAULT_ELEMENT);
|
---|
2031 | if (e != null) {
|
---|
2032 | default_index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2033 | String level = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2034 | default_index_option.setAttribute (StaticStrings.VALUE_ATTRIBUTE, level);
|
---|
2035 | } else {
|
---|
2036 | //In the case of mg, there's no level! build a default one using 'assigned=false value=document'
|
---|
2037 | default_index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
2038 | default_index_option.setAttribute (StaticStrings.VALUE_ATTRIBUTE, StaticStrings.DOCUMENT_STR);
|
---|
2039 | }
|
---|
2040 | appendProperly (toElement, default_index_option);
|
---|
2041 | }
|
---|
2042 |
|
---|
2043 | // Transform plugins (pluginListNode) of collectionConfig.xml into the internal structure (i.e. Document to)
|
---|
2044 | private void doPlugin (Document to, Node pluginListNode) {
|
---|
2045 | Element toElement = to.getDocumentElement ();
|
---|
2046 | NodeList plugin_children = ((Element)pluginListNode).getElementsByTagName (StaticStrings.PLUGIN_STR);
|
---|
2047 | int plugin_nodes = plugin_children.getLength ();
|
---|
2048 |
|
---|
2049 | if (plugin_nodes < 1) {
|
---|
2050 | return;
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | for (int i=0; i<plugin_nodes; i++) {
|
---|
2054 | Element e = (Element)plugin_children.item (i);
|
---|
2055 | String str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2056 | str = ensureNewPluginName(str);
|
---|
2057 | Element plugin_element = to.createElement (StaticStrings.PLUGIN_ELEMENT);
|
---|
2058 | plugin_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, str);
|
---|
2059 |
|
---|
2060 |
|
---|
2061 | NodeList option_children = e.getElementsByTagName (StaticStrings.OPTION_STR);
|
---|
2062 |
|
---|
2063 | for (int j=0; j<option_children.getLength (); j++) {
|
---|
2064 | Element el = (Element)option_children.item (j);
|
---|
2065 | String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2066 | if (name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
|
---|
2067 | name_str = name_str.substring (1);
|
---|
2068 | }
|
---|
2069 | String value_str = el.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
|
---|
2070 | Element option_element = null;
|
---|
2071 |
|
---|
2072 | if (name_str.equals ("") && !value_str.equals ("")) {
|
---|
2073 | continue;
|
---|
2074 | }
|
---|
2075 |
|
---|
2076 |
|
---|
2077 | option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2078 | option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2079 | if(name_str.equals (StaticStrings.RECPLUG_STR) && value_str.equals (StaticStrings.USE_METADATA_FILES_ARGUMENT)) {
|
---|
2080 | continue; // ignore this option
|
---|
2081 | }
|
---|
2082 |
|
---|
2083 | if(value_str != null) {
|
---|
2084 | // Remove any speech marks appended in strings containing whitespace
|
---|
2085 | if(value_str.startsWith (StaticStrings.SPEECH_CHARACTER) && value_str.endsWith (StaticStrings.SPEECH_CHARACTER)) {
|
---|
2086 | value_str = value_str.substring (1, value_str.length () - 1);
|
---|
2087 | }
|
---|
2088 | if(name_str.equals (StaticStrings.METADATA_STR)) {
|
---|
2089 | // The metadata argument must be the fully qualified name of a metadata element, so if it doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
2090 | String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
|
---|
2091 | value_str = "";
|
---|
2092 | for (int k=0; k<=values.length-1; k++) {
|
---|
2093 | if (values[k].indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
2094 | values[k] = StaticStrings.EXTRACTED_NAMESPACE + values[k];
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | if (k < values.length-1) {
|
---|
2098 | value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
|
---|
2099 |
|
---|
2100 | } else {
|
---|
2101 | value_str = value_str + values[k];
|
---|
2102 | }
|
---|
2103 | }
|
---|
2104 | }
|
---|
2105 | }
|
---|
2106 | if (!name_str.equals ("")) {
|
---|
2107 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2108 | }
|
---|
2109 | if (!value_str.equals ("")) {
|
---|
2110 | XMLTools.setNodeText (option_element, value_str);
|
---|
2111 | }
|
---|
2112 | plugin_element.appendChild (option_element);
|
---|
2113 |
|
---|
2114 | }
|
---|
2115 |
|
---|
2116 | appendProperly (toElement, plugin_element);
|
---|
2117 | }
|
---|
2118 |
|
---|
2119 | }
|
---|
2120 |
|
---|
2121 | //Handle classifiers
|
---|
2122 | private void doClassifier (Document to, Node browseNode) {
|
---|
2123 | Element toElement = to.getDocumentElement ();
|
---|
2124 | NodeList classifier_children = ((Element)browseNode).getElementsByTagName (StaticStrings.CLASSIFIER_STR);
|
---|
2125 | int num_nodes = classifier_children.getLength ();
|
---|
2126 |
|
---|
2127 | if (num_nodes < 1) {
|
---|
2128 | return;
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | for (int i=0; i<num_nodes; i++) {
|
---|
2132 | Element e = (Element)classifier_children.item (i);
|
---|
2133 | String str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2134 | Element classify_element = to.createElement (StaticStrings.CLASSIFY_ELEMENT);
|
---|
2135 | classify_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, str);
|
---|
2136 |
|
---|
2137 | String options_str = "";
|
---|
2138 | NodeList option_children = e.getElementsByTagName (StaticStrings.OPTION_STR);
|
---|
2139 | for (int j=0; j<option_children.getLength (); j++) {
|
---|
2140 | Element el = (Element)option_children.item (j);
|
---|
2141 | String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2142 | options_str = options_str + ((name_str.equals(""))? "" : (" " + name_str));
|
---|
2143 | if (name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
|
---|
2144 | name_str = name_str.substring (1);
|
---|
2145 | }
|
---|
2146 | String value_str = el.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
|
---|
2147 | options_str = options_str + ((name_str.equals(""))? "" : (" " + value_str));
|
---|
2148 | Element option_element = null;
|
---|
2149 |
|
---|
2150 | if (name_str.equals ("") && !value_str.equals ("")) {
|
---|
2151 | continue; //invalid condition
|
---|
2152 | }
|
---|
2153 |
|
---|
2154 | option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2155 | option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2156 |
|
---|
2157 | if (!name_str.equals ("")) {
|
---|
2158 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | if (!value_str.equals ("") && name_str.equals (StaticStrings.METADATA_STR)) {
|
---|
2162 | // The metadata argument must be the fully qualified name of a metadata element, so if it doesn't yet have a namespace, append the extracted metadata namespace.
|
---|
2163 | String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
|
---|
2164 | value_str = "";
|
---|
2165 | for (int k=0; k<=values.length-1; k++) {
|
---|
2166 | if (values[k].indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
2167 | values[k] = StaticStrings.EXTRACTED_NAMESPACE + values[k];
|
---|
2168 | }
|
---|
2169 | else {
|
---|
2170 | MetadataElement metadata_element = MetadataTools.getMetadataElementWithName (values[k]);
|
---|
2171 | if (metadata_element != null) {
|
---|
2172 | values[k] = metadata_element.getDisplayName ();
|
---|
2173 | }
|
---|
2174 | }
|
---|
2175 | if (k < values.length-1) {
|
---|
2176 | value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
|
---|
2177 | } else {
|
---|
2178 | value_str = value_str + values[k];
|
---|
2179 | }
|
---|
2180 | }
|
---|
2181 | }
|
---|
2182 |
|
---|
2183 | if (value_str != null && !value_str.equals ("")) {
|
---|
2184 | XMLTools.setNodeText (option_element, value_str);
|
---|
2185 | }
|
---|
2186 | classify_element.appendChild (option_element);
|
---|
2187 | }
|
---|
2188 | //format element for this classifier
|
---|
2189 | Element format = (Element)XMLTools.getChildByTagName (e, StaticStrings.FORMAT_STR);
|
---|
2190 | if(format != null) {
|
---|
2191 | classify_element.appendChild (doFormat(to, format, null));
|
---|
2192 | }
|
---|
2193 | appendProperly (toElement, classify_element);
|
---|
2194 | }
|
---|
2195 |
|
---|
2196 | // default format statement for all classifiers
|
---|
2197 | Element default_classifier_format = (Element)XMLTools.getChildByTagName (browseNode, StaticStrings.FORMAT_STR);
|
---|
2198 |
|
---|
2199 | to.getDocumentElement ().appendChild (doFormat(to, default_classifier_format, StaticStrings.BROWSE_STR));
|
---|
2200 | }
|
---|
2201 | private Element doFormat(Document to, Element format, String name_str) {
|
---|
2202 | Element format_element = to.createElement (StaticStrings.FORMAT_STR);
|
---|
2203 | if (name_str != null) {
|
---|
2204 | format_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2205 | }
|
---|
2206 | if (format != null) {
|
---|
2207 | String gsf_text = XMLTools.xmlNodeToStringWithoutIndenting(format);
|
---|
2208 |
|
---|
2209 | if (gsf_text.startsWith("<") && (gsf_text.indexOf("<") != gsf_text.lastIndexOf("<"))) {
|
---|
2210 | gsf_text = gsf_text.substring(gsf_text.indexOf("<gsf"),
|
---|
2211 | gsf_text.indexOf(StaticStrings.FORMAT_END_TAG));
|
---|
2212 | }
|
---|
2213 |
|
---|
2214 | XMLTools.setNodeText(format_element, gsf_text);
|
---|
2215 | }
|
---|
2216 | return format_element;
|
---|
2217 | }
|
---|
2218 | // Handling 'subcollection' elements in 'search' element of 'collectionConfig.xml'
|
---|
2219 | private void doSubcollection (Document to, Node searchNode) {
|
---|
2220 | Element toElement = to.getDocumentElement ();
|
---|
2221 | NodeList sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.SUBCOLLECTION_STR);
|
---|
2222 | int sub_nodes = sub_children.getLength ();
|
---|
2223 |
|
---|
2224 | // There is no subcollection
|
---|
2225 | if (sub_nodes < 1) {
|
---|
2226 | return;
|
---|
2227 | }
|
---|
2228 |
|
---|
2229 | for (int i=0; i<sub_nodes; i++) {
|
---|
2230 | Element sub_child = (Element)sub_children.item (i);
|
---|
2231 | String name_str = sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2232 | String filter_str = sub_child.getAttribute (StaticStrings.FILTER_ATTRIBUTE);
|
---|
2233 |
|
---|
2234 | // filter_str is in the form '<! (if set)><metadata>/<metadata value>/<flag (if any)>'
|
---|
2235 |
|
---|
2236 | int pos = filter_str.indexOf (StaticStrings.SEPARATOR_CHARACTER);
|
---|
2237 | String meta_str = "";
|
---|
2238 | String meta_value_str = "";
|
---|
2239 | String clude_str = "";
|
---|
2240 | String flag_str = "";
|
---|
2241 | if (pos == -1) {
|
---|
2242 |
|
---|
2243 | meta_str = meta_value_str = filter_str;
|
---|
2244 | clude_str = StaticStrings.INCLUDE_STR;
|
---|
2245 | } else {
|
---|
2246 | clude_str = StaticStrings.INCLUDE_STR;
|
---|
2247 | if (filter_str.startsWith (StaticStrings.EXCLAMATION_CHARACTER)) {
|
---|
2248 | clude_str = StaticStrings.EXCLUDE_STR;
|
---|
2249 | // Peel off "!"
|
---|
2250 | filter_str = filter_str.substring (StaticStrings.EXCLAMATION_CHARACTER.length ());
|
---|
2251 | }
|
---|
2252 |
|
---|
2253 | String[] strs = filter_str.split (StaticStrings.SEPARATOR_CHARACTER);
|
---|
2254 | if (strs[0] != null && strs[0] != "") {
|
---|
2255 | meta_str = strs[0];
|
---|
2256 | }
|
---|
2257 | if(!meta_str.equals (StaticStrings.FILENAME_STR) && meta_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
2258 | meta_str = StaticStrings.EXTRACTED_NAMESPACE + meta_str;
|
---|
2259 | }
|
---|
2260 |
|
---|
2261 | if (strs[1] != null && strs[1] != "") {
|
---|
2262 | meta_value_str = strs[1];
|
---|
2263 | }
|
---|
2264 | if (strs.length > 2) {
|
---|
2265 | //This means there has been set a flag
|
---|
2266 | if (strs[2] != null && strs[2] != "") {
|
---|
2267 | flag_str = strs[2];
|
---|
2268 | }
|
---|
2269 | }
|
---|
2270 | }
|
---|
2271 | Element subcollection_element = to.createElement (StaticStrings.SUBCOLLECTION_ELEMENT);
|
---|
2272 | subcollection_element.setAttribute (StaticStrings.NAME_STR, name_str);
|
---|
2273 | subcollection_element.setAttribute (StaticStrings.CONTENT_ATTRIBUTE, meta_str);
|
---|
2274 | subcollection_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, clude_str);
|
---|
2275 | if (flag_str != "") {
|
---|
2276 | subcollection_element.setAttribute (StaticStrings.OPTIONS_ATTRIBUTE, flag_str);
|
---|
2277 | }
|
---|
2278 | XMLTools.setNodeText (subcollection_element, meta_value_str);
|
---|
2279 |
|
---|
2280 | toElement.appendChild (subcollection_element);
|
---|
2281 | }
|
---|
2282 | }
|
---|
2283 | //Handle levels (document, section). In the internal structure, the element is called 'IndexOption'
|
---|
2284 | private void doLevel (Document to, Node searchNode) {
|
---|
2285 | Element toElement = to.getDocumentElement ();
|
---|
2286 | NodeList level_children = ((Element)searchNode).getElementsByTagName (StaticStrings.LEVEL_ATTRIBUTE);
|
---|
2287 | int level_nodes = level_children.getLength ();
|
---|
2288 |
|
---|
2289 | // it's mg, there's no level. So we construct a default 'indexOption' in the internal structure
|
---|
2290 | if (level_nodes < 1) {
|
---|
2291 | Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
|
---|
2292 | index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
2293 | index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVELS_STR);
|
---|
2294 |
|
---|
2295 | Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2296 | option_element.setAttribute (StaticStrings.NAME_STR, StaticStrings.DOCUMENT_STR);
|
---|
2297 | index_option.appendChild (option_element);
|
---|
2298 |
|
---|
2299 | appendProperly (toElement, index_option);
|
---|
2300 |
|
---|
2301 | return;
|
---|
2302 | }
|
---|
2303 |
|
---|
2304 | Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
|
---|
2305 | index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2306 | index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVELS_STR);
|
---|
2307 |
|
---|
2308 | for (int i=0; i<level_nodes; i++) {
|
---|
2309 | Element level_element = (Element)level_children.item (i);
|
---|
2310 | String level_str = level_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2311 | Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2312 | option_element.setAttribute (StaticStrings.NAME_STR, level_str);
|
---|
2313 | index_option.appendChild (option_element);
|
---|
2314 |
|
---|
2315 |
|
---|
2316 | // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'level' element
|
---|
2317 | ArrayList displayItem_list = XMLTools.getNamedElementList (level_element,
|
---|
2318 | StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
|
---|
2319 | if (displayItem_list == null) {
|
---|
2320 | return ;
|
---|
2321 | }
|
---|
2322 | for (int j=0; j<displayItem_list.size (); j++) {
|
---|
2323 | Element item = (Element)displayItem_list.get (j);
|
---|
2324 | String text = XMLTools.getNodeText (item);
|
---|
2325 | String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
|
---|
2326 |
|
---|
2327 | //If there is nothing to display, don't bother creating the element
|
---|
2328 | if (text == "") {
|
---|
2329 | continue;
|
---|
2330 | }
|
---|
2331 | Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
2332 | collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2333 | collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, level_str);
|
---|
2334 | collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
|
---|
2335 | XMLTools.setNodeText (collectionmetadata, text);
|
---|
2336 |
|
---|
2337 | appendProperly (toElement, collectionmetadata);
|
---|
2338 | }
|
---|
2339 | }
|
---|
2340 | appendProperly (toElement, index_option);
|
---|
2341 | }
|
---|
2342 | //Handle 'indexSubcollection' element of collectionConfig.xml, which is called 'SubcollectionIndexes' in the internal structure. These contain the subcollection indexes (i.e. the filter or filter combinations), and displayed words for the filter names.
|
---|
2343 | private void doIndexSubcollection (Document to, Node searchNode) {
|
---|
2344 | Element toElement = to.getDocumentElement ();
|
---|
2345 | NodeList index_sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.SUBCOLLECTION_INDEX_ELEMENT);
|
---|
2346 | int num_nodes = index_sub_children.getLength ();
|
---|
2347 |
|
---|
2348 | // there is no subcollection index
|
---|
2349 | if (num_nodes < 1) {
|
---|
2350 | return;
|
---|
2351 | }
|
---|
2352 |
|
---|
2353 | Element subcollection_indexes = to.createElement (StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT);
|
---|
2354 |
|
---|
2355 | for (int i=0; i<num_nodes; i++) {
|
---|
2356 | Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);
|
---|
2357 | Element index_sub_child = (Element)index_sub_children.item (i);
|
---|
2358 | String name_str = index_sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2359 |
|
---|
2360 | // name_str is in the form of comma separated strings, each of which is a subcollection filter name
|
---|
2361 | String[] filters = name_str.split (StaticStrings.COMMA_CHARACTER);
|
---|
2362 | for (int j=0; j<filters.length; j++) {
|
---|
2363 |
|
---|
2364 | Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
|
---|
2365 | content_element.setAttribute (StaticStrings.NAME_STR, filters[j]);
|
---|
2366 | index_element.appendChild (content_element);
|
---|
2367 | }
|
---|
2368 | subcollection_indexes.appendChild (index_element);
|
---|
2369 |
|
---|
2370 | // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexSubcollection' element
|
---|
2371 | ArrayList displayItem_list = XMLTools.getNamedElementList (index_sub_child,
|
---|
2372 | StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
|
---|
2373 | if (displayItem_list == null) {
|
---|
2374 | // there is no display item for this element
|
---|
2375 | continue;
|
---|
2376 | }
|
---|
2377 | for (int j=0; j<displayItem_list.size (); j++) {
|
---|
2378 | Element item = (Element)displayItem_list.get (j);
|
---|
2379 | String text = XMLTools.getNodeText (item);
|
---|
2380 | String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
|
---|
2381 |
|
---|
2382 | //If there is nothing to display, don't bother creating the element
|
---|
2383 | if (text == "") {
|
---|
2384 | continue;
|
---|
2385 | }
|
---|
2386 | Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
2387 | collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2388 | collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2389 | collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
|
---|
2390 | XMLTools.setNodeText (collectionmetadata, text);
|
---|
2391 |
|
---|
2392 | appendProperly (toElement, collectionmetadata);
|
---|
2393 | }
|
---|
2394 | }
|
---|
2395 | appendProperly (toElement, subcollection_indexes);
|
---|
2396 | }
|
---|
2397 | //Handle 'indexLanguage' element of collectionConfig.xml, which is called 'Languages' in the internal structure. These contain the language indexes, and displayed words for those language index names.
|
---|
2398 | private void doIndexLanguage (Document to, Node searchNode) {
|
---|
2399 | Element toElement = to.getDocumentElement ();
|
---|
2400 | NodeList index_sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.LANGUAGE_INDEX_ELEMENT);
|
---|
2401 | int num_nodes = index_sub_children.getLength ();
|
---|
2402 |
|
---|
2403 | // there is no subcollection index
|
---|
2404 | if (num_nodes < 1) {
|
---|
2405 | return;
|
---|
2406 | }
|
---|
2407 |
|
---|
2408 | Element language_indexes = to.createElement (StaticStrings.LANGUAGES_ELEMENT);
|
---|
2409 |
|
---|
2410 | for (int i=0; i<num_nodes; i++) {
|
---|
2411 | Element language_element = to.createElement (StaticStrings.LANGUAGE_ELEMENT);
|
---|
2412 | Element index_sub_child = (Element)index_sub_children.item (i);
|
---|
2413 | String name_str = index_sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2414 | language_element.setAttribute (StaticStrings.NAME_STR, name_str);
|
---|
2415 | language_indexes.appendChild (language_element);
|
---|
2416 |
|
---|
2417 | // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexLanguage' element
|
---|
2418 | ArrayList displayItem_list = XMLTools.getNamedElementList (index_sub_child,
|
---|
2419 | StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
|
---|
2420 | if (displayItem_list == null) {
|
---|
2421 | // there is no display item for this element
|
---|
2422 | continue;
|
---|
2423 | }
|
---|
2424 | for (int j=0; j<displayItem_list.size (); j++) {
|
---|
2425 | Element item = (Element)displayItem_list.get (j);
|
---|
2426 | String text = XMLTools.getNodeText (item);
|
---|
2427 | String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
|
---|
2428 |
|
---|
2429 | //If there is nothing to display, don't bother creating the element
|
---|
2430 | if (text == "") {
|
---|
2431 | continue;
|
---|
2432 | }
|
---|
2433 | Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
|
---|
2434 | collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2435 | collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2436 | collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
|
---|
2437 | XMLTools.setNodeText (collectionmetadata, text);
|
---|
2438 |
|
---|
2439 | appendProperly (toElement, collectionmetadata);
|
---|
2440 | }
|
---|
2441 | }
|
---|
2442 | toElement.appendChild (language_indexes);
|
---|
2443 | }
|
---|
2444 | // Handling both searchType and search format statement
|
---|
2445 | private void doSearchFormat (Document to, Node searchNode) {
|
---|
2446 | //There are two elements called <format> in <search>: one is for searchType; another is for format statement
|
---|
2447 | NodeList format_children = ((Element)searchNode).getElementsByTagName (StaticStrings.FORMAT_STR);
|
---|
2448 | int format_nodes = format_children.getLength ();
|
---|
2449 | if (format_nodes < 1) {
|
---|
2450 | return;
|
---|
2451 | }
|
---|
2452 | Element format = null;
|
---|
2453 | Element search_type = null;
|
---|
2454 | for(int i=0; i<format_nodes; i++) {
|
---|
2455 | Node e = format_children.item (i);
|
---|
2456 | if (e.hasAttributes () == false) {
|
---|
2457 | //The format element for format statement has no any attribute
|
---|
2458 | format = (Element)e;
|
---|
2459 | }
|
---|
2460 | else if (((Element)e).getAttribute (StaticStrings.NAME_ATTRIBUTE).equals(StaticStrings.SEARCHTYPE_ELEMENT)) {
|
---|
2461 | search_type = (Element)e;
|
---|
2462 | }
|
---|
2463 | }
|
---|
2464 | //format statement for search
|
---|
2465 | if (format != null) {
|
---|
2466 | (to.getDocumentElement ()).appendChild (doFormat(to, format, StaticStrings.SEARCH_STR));
|
---|
2467 | }
|
---|
2468 | // searchType in search
|
---|
2469 | if(search_type != null) {
|
---|
2470 | String searchtype_str = XMLTools.getNodeText(search_type);
|
---|
2471 |
|
---|
2472 | Element search_type_element = to.createElement (StaticStrings.FORMAT_STR);
|
---|
2473 | search_type_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);
|
---|
2474 | XMLTools.setNodeText(search_type_element, searchtype_str);
|
---|
2475 |
|
---|
2476 |
|
---|
2477 | appendProperly (to.getDocumentElement (), search_type_element);
|
---|
2478 | }
|
---|
2479 | }
|
---|
2480 | // Handling defaultIndexLanguage and languageMetadata in collectionConfig.xml ('elementNameFrom'); in the internal structure, they are called 'DefaultLanguage' and 'LanguageMetadata' ('elementNameTo') respectively.
|
---|
2481 | // Converting from collectionConfig.xml to the internal xml structure.
|
---|
2482 | private void doLanguageMetadata (Document to, Node searchNode) {
|
---|
2483 | Element toElement = to.getDocumentElement ();
|
---|
2484 | String elementNameFrom = StaticStrings.LANGUAGE_METADATA_ELEMENT_STR;
|
---|
2485 | String elementNameTo = StaticStrings.LANGUAGE_METADATA_ELEMENT;
|
---|
2486 | Node from_element = XMLTools.getChildByTagName (searchNode, elementNameFrom);
|
---|
2487 | if (from_element == null) {
|
---|
2488 | return; // such an element not found
|
---|
2489 | }
|
---|
2490 |
|
---|
2491 | Element to_element = to.createElement (elementNameTo);
|
---|
2492 |
|
---|
2493 | String name_str = ((Element)from_element).getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2494 | if (name_str.indexOf (StaticStrings.NS_SEP) == -1) {
|
---|
2495 | name_str = StaticStrings.EXTRACTED_NAMESPACE + name_str;
|
---|
2496 | }
|
---|
2497 | to_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2498 | to_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2499 |
|
---|
2500 | toElement.appendChild (to_element);
|
---|
2501 | }
|
---|
2502 | private void doReplaceListRef (Document to, Element from) {
|
---|
2503 | Element toElement = to.getDocumentElement ();
|
---|
2504 |
|
---|
2505 | Node replace_element = XMLTools.getChildByTagName (from, StaticStrings.REPLACELISTREF_STR);
|
---|
2506 | if (replace_element == null) {
|
---|
2507 | return; // such an element not found
|
---|
2508 | }
|
---|
2509 |
|
---|
2510 | Element to_element = XMLTools.duplicateElement (to, (Element)replace_element, true);
|
---|
2511 | toElement.appendChild (to_element);
|
---|
2512 | }
|
---|
2513 | private void convertReplaceListRef (Document from, Document to) {
|
---|
2514 | Element toElement = to.getDocumentElement ();
|
---|
2515 |
|
---|
2516 | Node replace_element = XMLTools.getChildByTagName (from.getDocumentElement (), StaticStrings.REPLACELISTREF_STR);
|
---|
2517 | if (replace_element == null) {
|
---|
2518 | return; // such an element not found
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | Element to_element = XMLTools.duplicateElement (to, (Element)replace_element, true);
|
---|
2522 | toElement.appendChild (to_element);
|
---|
2523 | }
|
---|
2524 | private void doOAIElement (Document to, Element from) {
|
---|
2525 | Element toElement = to.getDocumentElement ();
|
---|
2526 |
|
---|
2527 | Node oai_element = XMLTools.getChildByTagName (from, StaticStrings.OAI_ELEMENT);
|
---|
2528 | if (oai_element == null) {
|
---|
2529 | return; // such an element not found
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 | Element to_element = XMLTools.duplicateElement (to, (Element)oai_element, true);
|
---|
2533 | toElement.appendChild (to_element);
|
---|
2534 | }
|
---|
2535 | private void convertOAIElement (Document from, Document to) {
|
---|
2536 | Element toElement = to.getDocumentElement ();
|
---|
2537 |
|
---|
2538 | Node oai_element = XMLTools.getChildByTagName (from.getDocumentElement (), StaticStrings.OAI_ELEMENT);
|
---|
2539 | if (oai_element == null) {
|
---|
2540 | return; // such an element not found
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | Element to_element = XMLTools.duplicateElement (to, (Element)oai_element, true);
|
---|
2544 | toElement.appendChild (to_element);
|
---|
2545 | }
|
---|
2546 | private void doDefaultIndexLanguage (Document to, Node searchNode) {
|
---|
2547 | Element toElement = to.getDocumentElement ();
|
---|
2548 | String elementNameFrom = StaticStrings.LANGUAGE_DEFAULT_INDEX_ELEMENT;
|
---|
2549 | String elementNameTo = StaticStrings.LANGUAGE_DEFAULT_ELEMENT;
|
---|
2550 | Node from_element = XMLTools.getChildByTagName (searchNode, elementNameFrom);
|
---|
2551 | if (from_element == null) {
|
---|
2552 | return; // such an element not found
|
---|
2553 | }
|
---|
2554 |
|
---|
2555 | Element to_element = to.createElement (elementNameTo);
|
---|
2556 |
|
---|
2557 | String name_str = ((Element)from_element).getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2558 | to_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2559 | to_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2560 |
|
---|
2561 | toElement.appendChild (to_element);
|
---|
2562 | }
|
---|
2563 |
|
---|
2564 | //Handle 'indexOption' (i.e. casefold, stem etc). In the internal structure, the element is called 'IndexOption'
|
---|
2565 | private void doIndexOption (Document to, Node searchNode) {
|
---|
2566 | Element toElement = to.getDocumentElement ();
|
---|
2567 | Node index_option_node = XMLTools.getChildByTagName (searchNode, StaticStrings.INDEXOPTION_STR);
|
---|
2568 | if (index_option_node == null) {
|
---|
2569 | return;
|
---|
2570 | }
|
---|
2571 | NodeList option_children = ((Element)index_option_node).getElementsByTagName (StaticStrings.OPTION_STR);
|
---|
2572 | int option_nodes = option_children.getLength ();
|
---|
2573 |
|
---|
2574 | // for lucene, there is no 'indexOption'. We build a default 'indexOption' and 'assigned=false' in case the user switches to mg or mgpp
|
---|
2575 | if (option_nodes < 1) {
|
---|
2576 | Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
|
---|
2577 | index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
2578 | index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.INDEXOPTIONS_STR);
|
---|
2579 | String[] option_str =
|
---|
2580 | { StaticStrings.CASEFOLD_OPTION_STR, StaticStrings.STEM_OPTION_STR };
|
---|
2581 | for (int i=0; i<option_str.length; i++) {
|
---|
2582 | Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2583 | option_element.setAttribute (StaticStrings.NAME_STR, option_str[i]);
|
---|
2584 | index_option.appendChild (option_element);
|
---|
2585 | }
|
---|
2586 | appendProperly (toElement, index_option);
|
---|
2587 | return;
|
---|
2588 | }
|
---|
2589 |
|
---|
2590 | Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
|
---|
2591 | index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2592 | index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.INDEXOPTIONS_STR);
|
---|
2593 |
|
---|
2594 | for (int i=0; i<option_nodes; i++) {
|
---|
2595 | String option_str = ((Element)option_children.item (i)).getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2596 | Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
|
---|
2597 | option_element.setAttribute (StaticStrings.NAME_STR, option_str);
|
---|
2598 | index_option.appendChild (option_element);
|
---|
2599 | }
|
---|
2600 | appendProperly (toElement, index_option);
|
---|
2601 | }
|
---|
2602 |
|
---|
2603 | private Element doBuildType (Document to, String att_value) {
|
---|
2604 |
|
---|
2605 | //construct 'BuildType' element
|
---|
2606 | Element element = to.createElement (StaticStrings.BUILDTYPE_ELEMENT);
|
---|
2607 | element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.BUILDTYPE_STR);
|
---|
2608 | element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
|
---|
2609 | element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2610 | element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2611 |
|
---|
2612 | XMLTools.setNodeText (element, att_value);
|
---|
2613 |
|
---|
2614 | return element;
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 | // Convert 'description', 'smallicon' etc.
|
---|
2618 | private void convertDisplayItemList (Document from, Document to) {
|
---|
2619 | Element displayItemList = to.createElement (StaticStrings.DISPLAYITEMLIST_STR);
|
---|
2620 | Element destination = to.getDocumentElement ();
|
---|
2621 |
|
---|
2622 | String []att_values =
|
---|
2623 | {StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR,
|
---|
2624 | StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR,
|
---|
2625 | StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR,
|
---|
2626 | StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR};
|
---|
2627 |
|
---|
2628 | String []map_attrs =
|
---|
2629 | {StaticStrings.DESCRIPTION_STR,
|
---|
2630 | StaticStrings.SMALLICON_STR,
|
---|
2631 | StaticStrings.ICON_STR,
|
---|
2632 | StaticStrings.NAME_STR};
|
---|
2633 |
|
---|
2634 | for (int i=0; i<att_values.length; i++) {
|
---|
2635 |
|
---|
2636 | //dOc
|
---|
2637 | ArrayList e_list = XMLTools.getNamedElementList (from.getDocumentElement (),
|
---|
2638 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
2639 | StaticStrings.NAME_ATTRIBUTE, att_values[i]);
|
---|
2640 | // if such elements don't exist, don't bother
|
---|
2641 | if (e_list == null) {
|
---|
2642 | continue;
|
---|
2643 | }
|
---|
2644 | for (int j=0; j<e_list.size (); j++) {
|
---|
2645 | Element e = (Element)e_list.get (j);
|
---|
2646 | if (e.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
2647 | continue;
|
---|
2648 | }
|
---|
2649 | String text = XMLTools.getNodeText (e);
|
---|
2650 | String lang = e.getAttribute (StaticStrings.LANGUAGE_ATTRIBUTE);
|
---|
2651 |
|
---|
2652 | Element displayItem = constructElement (StaticStrings.DISPLAYITEM_STR, map_attrs[i],
|
---|
2653 | StaticStrings.LANG_STR, lang, text, to);
|
---|
2654 | displayItemList.appendChild (displayItem);
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 | }
|
---|
2658 | destination.appendChild (displayItemList);
|
---|
2659 | }
|
---|
2660 | // This method creates a DisplayItem element of the type of 'to' by using the ingredients from the element 'e'
|
---|
2661 | private Element constructDisplayItem (Element e, Document to) {
|
---|
2662 | String lang_string = e.getAttribute (StaticStrings.LANGUAGE_ATTRIBUTE);
|
---|
2663 | String text = XMLTools.getNodeText (e);
|
---|
2664 | Element displayItem = to.createElement (StaticStrings.DISPLAYITEM_STR);
|
---|
2665 | displayItem.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_ATTRIBUTE);
|
---|
2666 | displayItem.setAttribute (StaticStrings.LANG_STR, lang_string);
|
---|
2667 | XMLTools.setNodeText (displayItem, text);
|
---|
2668 | return displayItem;
|
---|
2669 | }
|
---|
2670 | private void convertMetadataList (Document from, Document to) {
|
---|
2671 | Element metadataList = to.createElement (StaticStrings.METADATALIST_STR);
|
---|
2672 | Element destination = to.getDocumentElement ();
|
---|
2673 |
|
---|
2674 | String []ele_names =
|
---|
2675 | {StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT,
|
---|
2676 | StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT,
|
---|
2677 | StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT};
|
---|
2678 | String []att_names =
|
---|
2679 | {StaticStrings.COLLECTIONMETADATA_CREATOR_STR,
|
---|
2680 | StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR,
|
---|
2681 | StaticStrings.COLLECTIONMETADATA_PUBLIC_STR};
|
---|
2682 | for (int i=0; i<ele_names.length; i++) {
|
---|
2683 | Element e = XMLTools.getNamedElement (from.getDocumentElement (),
|
---|
2684 | ele_names[i], StaticStrings.NAME_ATTRIBUTE, att_names[i]);
|
---|
2685 | if (e == null) {
|
---|
2686 | continue;
|
---|
2687 | }
|
---|
2688 | String text = XMLTools.getNodeText (e);
|
---|
2689 | Element metadata = to.createElement (StaticStrings.METADATA_STR);
|
---|
2690 | metadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, att_names[i]);
|
---|
2691 | metadata.setAttribute (StaticStrings.LANG_STR, StaticStrings.ENGLISH_LANGUAGE_STR);
|
---|
2692 | XMLTools.setNodeText (metadata, text);
|
---|
2693 | metadataList.appendChild (metadata);
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 | destination.appendChild (metadataList);
|
---|
2697 | }
|
---|
2698 | // This method creates an element with the name 'element_name' of the type of 'to' by using the other three strings
|
---|
2699 | private Element constructElement (String element_name, String name_value, String lang_att, String lang_value, String text, Document to) {
|
---|
2700 | Element e = to.createElement (element_name);
|
---|
2701 | e.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
2702 | e.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_value);
|
---|
2703 | e.setAttribute (lang_att, lang_value);
|
---|
2704 | XMLTools.setNodeText (e, text);
|
---|
2705 |
|
---|
2706 | return e;
|
---|
2707 | }
|
---|
2708 | // Convert classify in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to)
|
---|
2709 | private void convertClassifier (Document from, Document to) {
|
---|
2710 | Element browse_element = to.createElement (StaticStrings.BROWSE_STR);
|
---|
2711 | NodeList children = from.getDocumentElement ().getElementsByTagName (StaticStrings.CLASSIFY_ELEMENT);
|
---|
2712 |
|
---|
2713 | int num_children = (children == null)? 0 : children.getLength ();
|
---|
2714 |
|
---|
2715 | if (num_children == 0) {
|
---|
2716 | return ;
|
---|
2717 | }
|
---|
2718 |
|
---|
2719 | for (int i=0; i<num_children; i++) {
|
---|
2720 |
|
---|
2721 | Element child = (Element)children.item (i);
|
---|
2722 | if (child.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
2723 | continue;
|
---|
2724 | }
|
---|
2725 | String str = child.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
|
---|
2726 | Element classifier_element = to.createElement (StaticStrings.CLASSIFIER_STR);
|
---|
2727 | classifier_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, str);
|
---|
2728 |
|
---|
2729 | NodeList option_children = child.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
2730 | for (int j=0; j<option_children.getLength (); j++) {
|
---|
2731 | Element el = (Element)option_children.item (j);
|
---|
2732 | if (el.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
2733 | continue;
|
---|
2734 | }
|
---|
2735 | String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2736 | String value_str = XMLTools.getNodeText (el);
|
---|
2737 |
|
---|
2738 |
|
---|
2739 | if (name_str == null && value_str == null) {
|
---|
2740 | continue;
|
---|
2741 | }
|
---|
2742 | Element option_element = to.createElement (StaticStrings.OPTION_STR);
|
---|
2743 | if (name_str != null && name_str.equals (StaticStrings.METADATA_STR)) {
|
---|
2744 |
|
---|
2745 | // The metadata argument is the fully qualified name of a metadata element, so if it contains a namespace, remove the extracted metadata namespace as the build process doesn't know about it.
|
---|
2746 | String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
|
---|
2747 | value_str = "";
|
---|
2748 | for (int k=0; k<=values.length-1; k++) {
|
---|
2749 | if(values[k].startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
2750 | values[k] = values[k].substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
2751 | }
|
---|
2752 | else {
|
---|
2753 | MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (values[k]);
|
---|
2754 | if (metadata_element != null) {
|
---|
2755 | values[k] = metadata_element.getFullName ();
|
---|
2756 | }
|
---|
2757 | }
|
---|
2758 | if (k < values.length-1) {
|
---|
2759 | value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
|
---|
2760 | } else {
|
---|
2761 | value_str = value_str + values[k];
|
---|
2762 | }
|
---|
2763 | }
|
---|
2764 | }
|
---|
2765 |
|
---|
2766 | if (!name_str.equals ("")) {
|
---|
2767 | if (!name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
|
---|
2768 | name_str = StaticStrings.MINUS_CHARACTER + name_str;
|
---|
2769 | }
|
---|
2770 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2771 | }
|
---|
2772 |
|
---|
2773 | if (!value_str.equals ("")) {
|
---|
2774 | option_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, value_str);
|
---|
2775 | }
|
---|
2776 |
|
---|
2777 | classifier_element.appendChild (option_element);
|
---|
2778 | }
|
---|
2779 |
|
---|
2780 | //format element for this classifier
|
---|
2781 | Element e = (Element)XMLTools.getChildByTagName (child, StaticStrings.FORMAT_STR);
|
---|
2782 |
|
---|
2783 | if (e != null) {
|
---|
2784 | classifier_element.appendChild (convertFormat(to, e));
|
---|
2785 | }
|
---|
2786 | browse_element.appendChild (classifier_element);
|
---|
2787 | }
|
---|
2788 |
|
---|
2789 | //convert default classifier format
|
---|
2790 | Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
|
---|
2791 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.BROWSE_STR);
|
---|
2792 | browse_element.appendChild (convertFormat(to, e));
|
---|
2793 |
|
---|
2794 | to.getDocumentElement ().appendChild (browse_element);
|
---|
2795 | }
|
---|
2796 | private Element convertFormat(Document to, Element e) {
|
---|
2797 | String format_str = XMLTools.getNodeText(e);
|
---|
2798 | Element format = to.createElement (StaticStrings.FORMAT_STR);
|
---|
2799 | //XMLTools.copyAllChildren (format, e);
|
---|
2800 | XMLTools.setNodeText(format, format_str);
|
---|
2801 | return format;
|
---|
2802 | }
|
---|
2803 | //convert format statement for search
|
---|
2804 | private void convertSearchFormat (Document from, Document to) {
|
---|
2805 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
2806 | Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
|
---|
2807 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCH_STR);
|
---|
2808 |
|
---|
2809 | search.appendChild (convertFormat(to, e));
|
---|
2810 |
|
---|
2811 | }
|
---|
2812 | //convert format statement for display of the documents
|
---|
2813 | private void convertDisplayFormat (Document from, Document to) {
|
---|
2814 | Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
|
---|
2815 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.DISPLAY_STR);
|
---|
2816 | if (e == null) {
|
---|
2817 | return;
|
---|
2818 | }
|
---|
2819 | Element display = to.createElement (StaticStrings.DISPLAY_STR);
|
---|
2820 | display.appendChild (convertFormat(to, e));
|
---|
2821 | to.getDocumentElement ().appendChild (display);
|
---|
2822 | }
|
---|
2823 | // Convert plugins in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to)
|
---|
2824 | private void convertPlugin (Document from, Document to) {
|
---|
2825 | Element import_element = to.createElement (StaticStrings.IMPORT_STR);
|
---|
2826 | Element plugin_list_element = to.createElement (StaticStrings.PLUGINLIST_STR);
|
---|
2827 |
|
---|
2828 | NodeList children = from.getDocumentElement ().getElementsByTagName (StaticStrings.PLUGIN_ELEMENT);
|
---|
2829 | int num_children = (children == null)? 0 : children.getLength ();
|
---|
2830 | if (num_children == 0) {
|
---|
2831 | return ;
|
---|
2832 | }
|
---|
2833 |
|
---|
2834 | for (int i=0; i<num_children; i++) {
|
---|
2835 |
|
---|
2836 | Element child = (Element)children.item (i);
|
---|
2837 | if (child.getAttribute (StaticStrings.SEPARATOR_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
2838 | continue;
|
---|
2839 | }
|
---|
2840 | if (child.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
2841 | continue;
|
---|
2842 | }
|
---|
2843 |
|
---|
2844 | String str = child.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
|
---|
2845 | Element plugin_element = to.createElement (StaticStrings.PLUGIN_STR);
|
---|
2846 | plugin_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, str);
|
---|
2847 |
|
---|
2848 | NodeList option_children = child.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
2849 | for (int j=0; j<option_children.getLength (); j++) {
|
---|
2850 | Element el = (Element)option_children.item (j);
|
---|
2851 | if(!el.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
2852 | continue;
|
---|
2853 | }
|
---|
2854 | String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2855 | String value_str = XMLTools.getNodeText (el);
|
---|
2856 |
|
---|
2857 |
|
---|
2858 | if (name_str == null && value_str == null) {
|
---|
2859 | continue;
|
---|
2860 | }
|
---|
2861 | Element option_element = to.createElement (StaticStrings.OPTION_STR);
|
---|
2862 | if (name_str != null && name_str.equals (StaticStrings.METADATA_STR)) {
|
---|
2863 |
|
---|
2864 | // The metadata argument is the fully qualified name of a metadata element, so if it contains a namespace, remove the extracted metadata namespace as the build process doesn't know about it.
|
---|
2865 | String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
|
---|
2866 | value_str = "";
|
---|
2867 | for (int k=0; k<=values.length-1; k++) {
|
---|
2868 | if(values[k].startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
2869 | values[k] = values[k].substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
2870 | }
|
---|
2871 |
|
---|
2872 | if (k < values.length-1) {
|
---|
2873 | value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
|
---|
2874 | } else {
|
---|
2875 | value_str = value_str + values[k];
|
---|
2876 | }
|
---|
2877 | }
|
---|
2878 | }
|
---|
2879 |
|
---|
2880 | if (!name_str.equals ("")) {
|
---|
2881 | if (!name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
|
---|
2882 | name_str = StaticStrings.MINUS_CHARACTER + name_str;
|
---|
2883 | }
|
---|
2884 | option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
2885 | }
|
---|
2886 |
|
---|
2887 | if (!value_str.equals ("")) {
|
---|
2888 | option_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, value_str);
|
---|
2889 | }
|
---|
2890 |
|
---|
2891 | plugin_element.appendChild (option_element);
|
---|
2892 | }//for loop ends
|
---|
2893 |
|
---|
2894 | plugin_list_element.appendChild (plugin_element);
|
---|
2895 | }//for loop ends
|
---|
2896 |
|
---|
2897 | import_element.appendChild (plugin_list_element);
|
---|
2898 |
|
---|
2899 | //do the plugout element (used by building flax collections)
|
---|
2900 | Node plugout = XMLTools.getChildByTagNameIndexed (from.getDocumentElement (), PLUGOUT_ELEMENT, 0);
|
---|
2901 | if (plugout != null) {
|
---|
2902 | Element to_element = XMLTools.duplicateElement (to, (Element)plugout, true);
|
---|
2903 | import_element.appendChild (to_element);
|
---|
2904 | }
|
---|
2905 |
|
---|
2906 | to.getDocumentElement ().appendChild (import_element);
|
---|
2907 | }
|
---|
2908 |
|
---|
2909 | //Handle 'searchType' of collectionConfig.xml. In the internal structure, its also called 'searchType', eg. plain, form
|
---|
2910 | private void convertSearchType (Document from, Document to) {
|
---|
2911 | Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
|
---|
2912 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);//searchType
|
---|
2913 |
|
---|
2914 | if (e == null) {
|
---|
2915 | return;
|
---|
2916 | }
|
---|
2917 | Element search_type_element = to.createElement (StaticStrings.FORMAT_STR);
|
---|
2918 |
|
---|
2919 | // String searchtype_str = e.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
|
---|
2920 | // search_type_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, searchtype_str);
|
---|
2921 | String searchtype_str = XMLTools.getNodeText(e);
|
---|
2922 | XMLTools.setNodeText(search_type_element, searchtype_str);
|
---|
2923 |
|
---|
2924 | search_type_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);
|
---|
2925 | //Get the 'search' element from 'to'
|
---|
2926 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
2927 | search.appendChild (search_type_element);
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 | private void convertBuildType (Document from, Document to) {
|
---|
2931 | Element e = XMLTools.getNamedElement (from.getDocumentElement (),
|
---|
2932 | StaticStrings.BUILDTYPE_ELEMENT,
|
---|
2933 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.BUILDTYPE_STR);
|
---|
2934 | if (e == null) {
|
---|
2935 | return;
|
---|
2936 | }
|
---|
2937 | String indexer = XMLTools.getNodeText (e);
|
---|
2938 | Element search = to.createElement (StaticStrings.SEARCH_STR);
|
---|
2939 | search.setAttribute (StaticStrings.TYPE_ATTRIBUTE, indexer);
|
---|
2940 | to.getDocumentElement ().appendChild (search);
|
---|
2941 | }
|
---|
2942 | private void convertDefaultIndex (Document from, Document to, Element search) {
|
---|
2943 | Element source = from.getDocumentElement ();
|
---|
2944 |
|
---|
2945 | Element default_index_element = (Element)XMLTools.getChildByTagName (source, StaticStrings.INDEX_DEFAULT_ELEMENT);
|
---|
2946 | if (default_index_element == null) {
|
---|
2947 | return;
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | String indexer = search.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
|
---|
2951 | String level_str = default_index_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE);
|
---|
2952 | // Debugging purposes
|
---|
2953 | if (level_str.equals ("") && indexer.equals (StaticStrings.MG_STR) ) {
|
---|
2954 | System.out.println ("Bug: DefaultIndex should have its level attribute not empty.");
|
---|
2955 | }
|
---|
2956 |
|
---|
2957 | NodeList content_elements = default_index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
2958 | int content_elements_length = content_elements.getLength ();
|
---|
2959 |
|
---|
2960 | // Don't output anything if no indexes are set
|
---|
2961 | if(content_elements_length == 0) {
|
---|
2962 | return ;//
|
---|
2963 | }
|
---|
2964 |
|
---|
2965 | String index_str = "";
|
---|
2966 |
|
---|
2967 | if (indexer.equals (StaticStrings.MG_STR)) {
|
---|
2968 | //combine level with indexes
|
---|
2969 | index_str = level_str + StaticStrings.COLON_CHARACTER;
|
---|
2970 | }
|
---|
2971 | else { //for mgpp/lucene, just take index
|
---|
2972 | //do nothing
|
---|
2973 | }
|
---|
2974 |
|
---|
2975 | for(int k = 0; k < content_elements_length; k++) {
|
---|
2976 | Element content_element = (Element) content_elements.item (k);
|
---|
2977 | if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
2978 | continue;
|
---|
2979 | }
|
---|
2980 | String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
2981 |
|
---|
2982 | if(name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
2983 | name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
2984 | }
|
---|
2985 |
|
---|
2986 | index_str = index_str + name_str;
|
---|
2987 |
|
---|
2988 | // Make it comma separated string
|
---|
2989 | if(k < content_elements_length - 1) {
|
---|
2990 | index_str = index_str + StaticStrings.COMMA_CHARACTER;
|
---|
2991 | }
|
---|
2992 | content_element = null;
|
---|
2993 | }//for loop ends
|
---|
2994 |
|
---|
2995 |
|
---|
2996 | Element default_index = to.createElement (StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE);
|
---|
2997 | default_index.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_str);
|
---|
2998 | search.appendChild (default_index);
|
---|
2999 |
|
---|
3000 | }
|
---|
3001 | private void convertSubcollection (Document from, Document to) {
|
---|
3002 | Element source = from.getDocumentElement ();
|
---|
3003 | //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
|
---|
3004 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
3005 |
|
---|
3006 | // Get the Subcollection element from the internal structure
|
---|
3007 | NodeList subcollection_elements = source.getElementsByTagName (StaticStrings.SUBCOLLECTION_ELEMENT);
|
---|
3008 | if (subcollection_elements == null) {
|
---|
3009 | return;
|
---|
3010 | }
|
---|
3011 | int subcollection_elements_length = subcollection_elements.getLength ();
|
---|
3012 |
|
---|
3013 | if (subcollection_elements_length == 0) { // no
|
---|
3014 | return ;
|
---|
3015 | }
|
---|
3016 |
|
---|
3017 | for(int j = 0; j < subcollection_elements_length; j++) {
|
---|
3018 |
|
---|
3019 | Element e = (Element) subcollection_elements.item (j);
|
---|
3020 | if (e.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3021 | continue;
|
---|
3022 | }
|
---|
3023 | String content = e.getAttribute (StaticStrings.CONTENT_ATTRIBUTE);
|
---|
3024 | String name = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3025 | String options = e.getAttribute (StaticStrings.OPTIONS_ATTRIBUTE);
|
---|
3026 | String type = e.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
|
---|
3027 | String text = XMLTools.getNodeText (e);
|
---|
3028 |
|
---|
3029 | String filter = "";
|
---|
3030 | if (type.equals (StaticStrings.EXCLUDE_STR)) {
|
---|
3031 | filter = StaticStrings.EXCLAMATION_CHARACTER;
|
---|
3032 | }
|
---|
3033 |
|
---|
3034 | if(content.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
3035 | content = content.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
3036 | }
|
---|
3037 | filter = filter + content + StaticStrings.SEPARATOR_CHARACTER + text;
|
---|
3038 | if (options != null && options != "") {
|
---|
3039 | filter = filter + StaticStrings.SEPARATOR_CHARACTER + options;
|
---|
3040 | }
|
---|
3041 | Element subcollection = to.createElement (StaticStrings.SUBCOLLECTION_STR);
|
---|
3042 | subcollection.setAttribute (StaticStrings.FILTER_ATTRIBUTE, filter);
|
---|
3043 | subcollection.setAttribute (StaticStrings.NAME_ATTRIBUTE, name);
|
---|
3044 |
|
---|
3045 | search.appendChild (subcollection);
|
---|
3046 | }
|
---|
3047 | }
|
---|
3048 | private void convertSubcollectionIndexes (Document from, Document to) {
|
---|
3049 | Element source = from.getDocumentElement ();
|
---|
3050 | //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
|
---|
3051 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
3052 |
|
---|
3053 | // Get the SubcollectionIndexes element from the internal structure
|
---|
3054 | Element subcollection_indexes = (Element)XMLTools.getChildByTagName (source, StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT);
|
---|
3055 | if (subcollection_indexes == null) {
|
---|
3056 | return;
|
---|
3057 | }
|
---|
3058 | NodeList index_elements = subcollection_indexes.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
|
---|
3059 | int index_elements_length = index_elements.getLength ();
|
---|
3060 |
|
---|
3061 | if (index_elements_length == 0) { // no indexes
|
---|
3062 | return ;
|
---|
3063 | }
|
---|
3064 |
|
---|
3065 | for(int j = 0; j < index_elements_length; j++) {
|
---|
3066 | Element index_element = (Element) index_elements.item (j);
|
---|
3067 | if (index_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3068 | continue;
|
---|
3069 | }
|
---|
3070 |
|
---|
3071 | Element index = to.createElement (StaticStrings.SUBCOLLECTION_INDEX_ELEMENT);
|
---|
3072 |
|
---|
3073 | String index_value = "";
|
---|
3074 |
|
---|
3075 | NodeList content_elements = index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
3076 | int content_elements_length = content_elements.getLength ();
|
---|
3077 |
|
---|
3078 | for(int k = 0; k < content_elements_length; k++) {
|
---|
3079 | Element content_element = (Element) content_elements.item (k);
|
---|
3080 | if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3081 | continue;
|
---|
3082 | }
|
---|
3083 | String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3084 | index_value += name_str;
|
---|
3085 | // Make it comma separated string
|
---|
3086 | if(k < content_elements_length - 1) {
|
---|
3087 | index_value += StaticStrings.COMMA_CHARACTER;
|
---|
3088 | }
|
---|
3089 | content_element = null;
|
---|
3090 | }//for loop ends
|
---|
3091 |
|
---|
3092 | index.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_value);
|
---|
3093 |
|
---|
3094 | // Now constructing 'displayItem' element for this 'indexSubcollection' element
|
---|
3095 | // from the collectionmetadata element
|
---|
3096 | ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
|
---|
3097 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
3098 | StaticStrings.NAME_ATTRIBUTE, index_value);
|
---|
3099 |
|
---|
3100 | if (collectionmetadata_list != null) {
|
---|
3101 |
|
---|
3102 | for(int k = 0; k < collectionmetadata_list.size (); k++) {
|
---|
3103 | Element collectionmetadata = (Element)collectionmetadata_list.get (k);
|
---|
3104 | if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3105 | continue;
|
---|
3106 | }
|
---|
3107 | Element displayItem = constructDisplayItem (collectionmetadata, to);
|
---|
3108 | index.appendChild (displayItem);
|
---|
3109 | }
|
---|
3110 | }
|
---|
3111 |
|
---|
3112 | search.appendChild (index);
|
---|
3113 |
|
---|
3114 | } //for loop ends
|
---|
3115 | }
|
---|
3116 |
|
---|
3117 | private void convertLanguages (Document from, Document to) {
|
---|
3118 | Element source = from.getDocumentElement ();
|
---|
3119 | //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
|
---|
3120 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
3121 |
|
---|
3122 | // Get the Languages element from the internal structure
|
---|
3123 | Element languages = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGES_ELEMENT);
|
---|
3124 | if (languages == null) {
|
---|
3125 | return;
|
---|
3126 | }
|
---|
3127 | NodeList language_elements = languages.getElementsByTagName (StaticStrings.LANGUAGE_ELEMENT);
|
---|
3128 | int language_elements_length = language_elements.getLength ();
|
---|
3129 |
|
---|
3130 | if (language_elements_length == 0) {
|
---|
3131 | return ;
|
---|
3132 | }
|
---|
3133 |
|
---|
3134 | for(int j = 0; j < language_elements_length; j++) {
|
---|
3135 | Element element = (Element) language_elements.item (j);
|
---|
3136 | if (element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3137 | continue;
|
---|
3138 | }
|
---|
3139 |
|
---|
3140 | // Create indexLanguage element
|
---|
3141 | Element index_language = to.createElement (StaticStrings.LANGUAGE_INDEX_ELEMENT);
|
---|
3142 |
|
---|
3143 | String name_str = element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3144 | index_language.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
3145 |
|
---|
3146 | // Now constructing 'displayItem' element for this 'indexLanguage' element
|
---|
3147 | // from the collectionmetadata element
|
---|
3148 | ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
|
---|
3149 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
3150 | StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
3151 |
|
---|
3152 | if (collectionmetadata_list != null) {
|
---|
3153 |
|
---|
3154 | for(int k = 0; k < collectionmetadata_list.size (); k++) {
|
---|
3155 | Element collectionmetadata = (Element)collectionmetadata_list.get (k);
|
---|
3156 | if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3157 | continue;
|
---|
3158 | }
|
---|
3159 | Element displayItem = constructDisplayItem (collectionmetadata, to);
|
---|
3160 | index_language.appendChild (displayItem);
|
---|
3161 | }
|
---|
3162 | }
|
---|
3163 |
|
---|
3164 | search.appendChild (index_language);
|
---|
3165 |
|
---|
3166 | } //for loop ends
|
---|
3167 |
|
---|
3168 | // Convert DefaultLanguage
|
---|
3169 | // Get the DefaultLanguage element from the internal structure
|
---|
3170 | Element default_language = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGE_DEFAULT_ELEMENT);
|
---|
3171 | if(default_language != null) {
|
---|
3172 | String lang_name = default_language.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3173 | Element default_index_language = to.createElement (StaticStrings.LANGUAGE_DEFAULT_INDEX_ELEMENT);
|
---|
3174 | default_index_language.setAttribute (StaticStrings.NAME_ATTRIBUTE, lang_name);
|
---|
3175 | search.appendChild (default_index_language);
|
---|
3176 | }
|
---|
3177 | // Convert LanguageMetadata
|
---|
3178 | // Get the LanguageMetadata element from the internal structure
|
---|
3179 | Element language_metadata = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGE_METADATA_ELEMENT);
|
---|
3180 | if(language_metadata != null) {
|
---|
3181 | String meta_name = language_metadata.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3182 | Element language_meta = to.createElement (StaticStrings.LANGUAGE_METADATA_ELEMENT_STR);
|
---|
3183 | if(meta_name.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
3184 | meta_name = meta_name.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
3185 | }
|
---|
3186 | language_meta.setAttribute (StaticStrings.NAME_ATTRIBUTE, meta_name);
|
---|
3187 | search.appendChild (language_meta);
|
---|
3188 | }
|
---|
3189 | }
|
---|
3190 |
|
---|
3191 | //convert indexes and their displayItems, which go in 'search' element in collectionConfig.xml
|
---|
3192 | //parameter 'to' is the document to be saved as collectionConfig.xml
|
---|
3193 | //parameter 'from' is the internal xml structure
|
---|
3194 | private void convertIndex (Document from, Document to) {
|
---|
3195 | Element source = from.getDocumentElement ();
|
---|
3196 | //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
|
---|
3197 | Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
|
---|
3198 |
|
---|
3199 | //THere are two sets of indexes elements, find the one which is assigned 'true'
|
---|
3200 | Element indexes = XMLTools.getNamedElement (source,
|
---|
3201 | StaticStrings.INDEXES_ELEMENT,
|
---|
3202 | StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
3203 | if (indexes == null) {
|
---|
3204 | return;
|
---|
3205 | }
|
---|
3206 | NodeList index_elements = indexes.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
|
---|
3207 | int index_elements_length = index_elements.getLength ();
|
---|
3208 |
|
---|
3209 | if (index_elements_length == 0) { // no indexes
|
---|
3210 | return ;
|
---|
3211 | }
|
---|
3212 |
|
---|
3213 | //find out it's mg or mgpp/lucene
|
---|
3214 | String mg = search.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
|
---|
3215 | boolean mg_indexer = false;
|
---|
3216 | if (mg.equals (StaticStrings.MG_STR)) {
|
---|
3217 | mg_indexer = true;//it's mg, then the level is set as attribute of
|
---|
3218 | }
|
---|
3219 | if (mg_indexer == false) {
|
---|
3220 | // It's mgpp. Construct 'level' and 'defaultLevel' elements separately.
|
---|
3221 | convertLevels (from, to, search);
|
---|
3222 | }
|
---|
3223 |
|
---|
3224 | for(int j = 0; j < index_elements_length; j++) {
|
---|
3225 | Element index_element = (Element) index_elements.item (j);
|
---|
3226 | if (index_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3227 | continue;
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | Element index_ele = to.createElement (StaticStrings.INDEX_LOW_STR);//index
|
---|
3231 |
|
---|
3232 | // Used for creating displayItem for this element 'index_ele' further below
|
---|
3233 | // full_index_names contain 'ex.'
|
---|
3234 | String full_index_name = "";
|
---|
3235 | String level_str = "";
|
---|
3236 |
|
---|
3237 | StringBuffer index_value = new StringBuffer ();
|
---|
3238 | if (mg_indexer == true) {
|
---|
3239 | // For mg indexer, there is a 'level' attribute in the index element of the internal structure
|
---|
3240 | // But mgpp/lucene don't
|
---|
3241 | level_str = index_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE);
|
---|
3242 | if(level_str.length () > 0) {
|
---|
3243 | index_value.append (level_str).append (StaticStrings.COLON_CHARACTER);
|
---|
3244 | //index_value = index_value.StaticStrings.COLON_CHARACTER;
|
---|
3245 | }
|
---|
3246 | }
|
---|
3247 |
|
---|
3248 | NodeList content_elements = index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
|
---|
3249 | int content_elements_length = content_elements.getLength ();
|
---|
3250 |
|
---|
3251 | for(int k = 0; k < content_elements_length; k++) {
|
---|
3252 | Element content_element = (Element) content_elements.item (k);
|
---|
3253 | if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3254 | continue;
|
---|
3255 | }
|
---|
3256 | String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3257 |
|
---|
3258 | full_index_name = full_index_name + name_str;
|
---|
3259 | if (k < content_elements_length - 1) {
|
---|
3260 | full_index_name = full_index_name + StaticStrings.COMMA_CHARACTER;
|
---|
3261 | }
|
---|
3262 |
|
---|
3263 | if(name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
3264 | name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
|
---|
3265 | }
|
---|
3266 |
|
---|
3267 | index_value.append (name_str);
|
---|
3268 | name_str = null;
|
---|
3269 | // Make it comma separated string
|
---|
3270 | if(k < content_elements_length - 1) {
|
---|
3271 | index_value.append (StaticStrings.COMMA_CHARACTER);
|
---|
3272 | }
|
---|
3273 | content_element = null;
|
---|
3274 | }//for loop ends
|
---|
3275 |
|
---|
3276 | String temp_str = index_value.toString ();
|
---|
3277 | index_ele.setAttribute (StaticStrings.NAME_ATTRIBUTE, temp_str);
|
---|
3278 |
|
---|
3279 | // Now constructing 'displayItem' element for this 'index_ele' element
|
---|
3280 | // The index names in the collectionmetadata elements in the internal structure are not the names that
|
---|
3281 | // are used in the content elements (i.e. ex.Source or dc.Subject and keywords), but the names that are
|
---|
3282 | // in the configuration files (i.e. Source or dc.Subject)
|
---|
3283 | ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
|
---|
3284 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
3285 | StaticStrings.NAME_ATTRIBUTE, temp_str);
|
---|
3286 |
|
---|
3287 | if (collectionmetadata_list == null) {
|
---|
3288 | //try the full name, i.e. with 'ex.'
|
---|
3289 | if (mg_indexer == true) {
|
---|
3290 | // but first append level info if we are mg
|
---|
3291 | full_index_name = level_str+StaticStrings.COLON_CHARACTER+full_index_name;
|
---|
3292 | }
|
---|
3293 | collectionmetadata_list = XMLTools.getNamedElementList (source,
|
---|
3294 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
3295 | StaticStrings.NAME_ATTRIBUTE, full_index_name);
|
---|
3296 | }
|
---|
3297 |
|
---|
3298 | if (collectionmetadata_list != null) {
|
---|
3299 |
|
---|
3300 | for(int k = 0; k < collectionmetadata_list.size (); k++) {
|
---|
3301 | Element collectionmetadata = (Element)collectionmetadata_list.get (k);
|
---|
3302 | if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3303 | continue;
|
---|
3304 | }
|
---|
3305 | Element displayItem = constructDisplayItem (collectionmetadata, to);
|
---|
3306 |
|
---|
3307 | index_ele.appendChild (displayItem);
|
---|
3308 | }
|
---|
3309 | }
|
---|
3310 |
|
---|
3311 | search.appendChild (index_ele);
|
---|
3312 |
|
---|
3313 | } //for loop ends
|
---|
3314 |
|
---|
3315 | //Convert default index
|
---|
3316 | convertDefaultIndex (from, to, search);
|
---|
3317 | convertIndexOptions(from, to, search);
|
---|
3318 | }
|
---|
3319 | // Convert levels for mgpp/lucene. This method is called by converIndex() when mgpp indexer is detected.
|
---|
3320 | private void convertLevels (Document from, Document to, Element search) {
|
---|
3321 | Element source = from.getDocumentElement ();
|
---|
3322 | Element index_option = XMLTools.getNamedElement (source,
|
---|
3323 | StaticStrings.INDEXOPTIONS_ELEMENT,
|
---|
3324 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVELS_STR);
|
---|
3325 | if (index_option == null) {
|
---|
3326 | return;
|
---|
3327 | }
|
---|
3328 | //Debugging purposes
|
---|
3329 | if (index_option.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3330 | DebugStream.println ("For mgpp, there should be an IndexOption element for levels which is assigned 'true': possible bug.");
|
---|
3331 | }
|
---|
3332 |
|
---|
3333 | NodeList option_elements = index_option.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
3334 | int num_elements = option_elements.getLength ();
|
---|
3335 |
|
---|
3336 | // Don't output anything if no indexes are set
|
---|
3337 | if(num_elements == 0) {
|
---|
3338 | return ;//
|
---|
3339 | }
|
---|
3340 |
|
---|
3341 | for(int k = 0; k < num_elements; k++) {
|
---|
3342 | Element e = (Element) option_elements.item (k);
|
---|
3343 | String name_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3344 | Element level_element = to.createElement (StaticStrings.LEVEL_ELEMENT);
|
---|
3345 | level_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
3346 |
|
---|
3347 | //Now construct displayItem for this level element from collectionmetadata
|
---|
3348 | ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
|
---|
3349 | StaticStrings.COLLECTIONMETADATA_ELEMENT,
|
---|
3350 | StaticStrings.NAME_ATTRIBUTE, name_str);
|
---|
3351 |
|
---|
3352 | if (collectionmetadata_list != null) {
|
---|
3353 |
|
---|
3354 | for(int j = 0; j < collectionmetadata_list.size (); j++) {
|
---|
3355 | Element collectionmetadata = (Element)collectionmetadata_list.get (j);
|
---|
3356 |
|
---|
3357 | Element displayItem = constructDisplayItem (collectionmetadata, to);
|
---|
3358 | level_element.appendChild (displayItem);
|
---|
3359 | }
|
---|
3360 | }
|
---|
3361 | search.appendChild (level_element);
|
---|
3362 | }
|
---|
3363 |
|
---|
3364 | //Convert default level
|
---|
3365 | Element default_index_option = XMLTools.getNamedElement (source,
|
---|
3366 | StaticStrings.INDEXOPTION_DEFAULT_ELEMENT,
|
---|
3367 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVEL_DEFAULT_STR);
|
---|
3368 | if (default_index_option == null) {
|
---|
3369 | return;
|
---|
3370 | }
|
---|
3371 | Element default_level = to.createElement (StaticStrings.LEVEL_DEFAULT_ELEMENT);
|
---|
3372 | String default_level_str = default_index_option.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
|
---|
3373 | default_level.setAttribute (StaticStrings.NAME_ATTRIBUTE, default_level_str);
|
---|
3374 | search.appendChild (default_level);
|
---|
3375 |
|
---|
3376 | }
|
---|
3377 | // Convert indexoptions for mg/mgpp/lucene. This method is called by convertIndex().
|
---|
3378 | private void convertIndexOptions (Document from, Document to, Element search) {
|
---|
3379 | Element source = from.getDocumentElement ();
|
---|
3380 | Element index_option = XMLTools.getNamedElement (source,
|
---|
3381 | StaticStrings.INDEXOPTIONS_ELEMENT,
|
---|
3382 | StaticStrings.NAME_ATTRIBUTE, StaticStrings.INDEXOPTIONS_STR);
|
---|
3383 | if (index_option == null) {
|
---|
3384 | return;
|
---|
3385 | }
|
---|
3386 | //Debugging purposes
|
---|
3387 | if (index_option.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
|
---|
3388 | DebugStream.println ("There should be an IndexOption element which is assigned 'true': possible bug.");
|
---|
3389 | }
|
---|
3390 | Element indexOptionEl = to.createElement(StaticStrings.INDEXOPTION_STR);
|
---|
3391 | NodeList option_elements = index_option.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
|
---|
3392 | int num_elements = option_elements.getLength ();
|
---|
3393 | // Don't output anything if no index
|
---|
3394 | if(num_elements == 0) {
|
---|
3395 | return ;//
|
---|
3396 | }
|
---|
3397 | search.appendChild (indexOptionEl);
|
---|
3398 |
|
---|
3399 | for(int k = 0; k < num_elements; k++) {
|
---|
3400 | Element e = (Element) option_elements.item (k);
|
---|
3401 | String name_att = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
3402 | Element optionEl = to.createElement(StaticStrings.OPTION_STR);
|
---|
3403 | optionEl.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_att);
|
---|
3404 | indexOptionEl.appendChild(optionEl);
|
---|
3405 | }
|
---|
3406 |
|
---|
3407 | }
|
---|
3408 | // Append the element son to the element mother in the appropriate position.
|
---|
3409 | static public void appendProperly (Element mother, Element son) {
|
---|
3410 | if (son == null)
|
---|
3411 | return;
|
---|
3412 |
|
---|
3413 | Node reference_node = findInsertionPoint (mother, son);
|
---|
3414 | if(reference_node != null) {
|
---|
3415 | mother.insertBefore (son, reference_node);
|
---|
3416 | }
|
---|
3417 | else {
|
---|
3418 | mother.appendChild (son);
|
---|
3419 | }
|
---|
3420 | }
|
---|
3421 | /** Find the best insertion position for the given DOM Element 'target_element' in the DOM Element 'document_element'. This should try to match command tag, and if found should then try to group by name or type (eg CollectionMeta), or append to end is no such grouping exists (eg Plugins). Failing a command match it will check against the command order for the best insertion location.
|
---|
3422 | * @param target_element the command Element to be inserted
|
---|
3423 | * @return the Element which the given command should be inserted before, or null to append to end of list
|
---|
3424 | */
|
---|
3425 | static public Node findInsertionPoint (Element document_element, Element target_element) {
|
---|
3426 | ///ystem.err.println("Find insertion point: " + target_element.getNodeName());
|
---|
3427 | String target_element_name = target_element.getNodeName ();
|
---|
3428 |
|
---|
3429 | // Try to find commands with the same tag.
|
---|
3430 | NodeList matching_elements = document_element.getElementsByTagName (target_element_name);
|
---|
3431 | // If we found matching elements, then we have our most likely insertion location, so check within for groupings
|
---|
3432 | if(matching_elements.getLength () != 0) {
|
---|
3433 | ///ystem.err.println("Found matching elements.");
|
---|
3434 | // Only CollectionMeta are grouped.
|
---|
3435 | if(target_element_name.equals (StaticStrings.COLLECTIONMETADATA_ELEMENT)) {
|
---|
3436 | ///ystem.err.println("Dealing with collection metadata");
|
---|
3437 | // Special case: CollectionMeta can be added at either the start or end of a collection configuration file. However the start position is reserved for special metadata, so if no non-special metadata can be found we must append to the end.
|
---|
3438 | // So if the command to be added is special add it immediately after any other special command
|
---|
3439 | if(target_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
3440 | int index = 0;
|
---|
3441 | Element matched_element = (Element) matching_elements.item (index);
|
---|
3442 | Element sibling_element = (Element) matched_element.getNextSibling ();
|
---|
3443 | while(sibling_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
3444 | index++;
|
---|
3445 | matched_element = (Element) matching_elements.item (index);
|
---|
3446 | sibling_element = (Element) matched_element.getNextSibling ();
|
---|
3447 | }
|
---|
3448 | if(sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
3449 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
3450 | document_element.insertBefore (newline_element, sibling_element);
|
---|
3451 | }
|
---|
3452 | return sibling_element;
|
---|
3453 | }
|
---|
3454 | // Otherwise try to find a matching 'name' and add after the last one in that group.
|
---|
3455 | else {
|
---|
3456 | int index = 0;
|
---|
3457 | target_element_name = target_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
|
---|
3458 | boolean found = false;
|
---|
3459 | // Skip all of the special metadata
|
---|
3460 | Element matched_element = (Element) matching_elements.item (index);
|
---|
3461 | while(matched_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
|
---|
3462 | index++;
|
---|
3463 | matched_element = (Element) matching_elements.item (index);
|
---|
3464 | }
|
---|
3465 | // Begin search
|
---|
3466 | while(!found && matched_element != null) {
|
---|
3467 | if(matched_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
|
---|
3468 | found = true;
|
---|
3469 | }
|
---|
3470 | else {
|
---|
3471 | index++;
|
---|
3472 | matched_element = (Element) matching_elements.item (index);
|
---|
3473 | }
|
---|
3474 | }
|
---|
3475 | // If we found a match, we need to continue checking until we find the last name match.
|
---|
3476 | if(found) {
|
---|
3477 | index++;
|
---|
3478 | Element previous_sibling = matched_element;
|
---|
3479 | Element sibling_element = (Element) matching_elements.item (index);
|
---|
3480 | while(sibling_element != null && sibling_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
|
---|
3481 | previous_sibling = sibling_element;
|
---|
3482 | index++;
|
---|
3483 | sibling_element = (Element) matching_elements.item (index);
|
---|
3484 | }
|
---|
3485 | // Previous sibling now holds the command immediately before where we want to add, so find its next sibling and add to that. In this one case we can ignore new lines!
|
---|
3486 | return previous_sibling.getNextSibling ();
|
---|
3487 | }
|
---|
3488 | // If not found we just add after last metadata element
|
---|
3489 | else {
|
---|
3490 | Element last_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
3491 | return last_element.getNextSibling ();
|
---|
3492 | }
|
---|
3493 | }
|
---|
3494 |
|
---|
3495 | }
|
---|
3496 | else {
|
---|
3497 | ///ystem.err.println("Not dealing with collection meta.");
|
---|
3498 | Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
3499 | // One final quick test. If the matched element is immediately followed by a NewLine command, then we insert another NewLine after the matched command, then return the NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
3500 | Node sibling_element = matched_element.getNextSibling ();
|
---|
3501 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
3502 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
3503 | document_element.insertBefore (newline_element, sibling_element);
|
---|
3504 | }
|
---|
3505 | return sibling_element; // Note that this may be null
|
---|
3506 | }
|
---|
3507 | }
|
---|
3508 | ///ystem.err.println("No matching elements found.");
|
---|
3509 | // Locate where this command is in the ordering
|
---|
3510 | int command_index = -1;
|
---|
3511 | for(int i = 0; command_index == -1 && i < COMMAND_ORDER.length; i++) {
|
---|
3512 | if(COMMAND_ORDER[i].equals (target_element_name)) {
|
---|
3513 | command_index = i;
|
---|
3514 | }
|
---|
3515 | }
|
---|
3516 | ///ystem.err.println("Command index is: " + command_index);
|
---|
3517 | // Now move forward, checking for existing elements in each of the preceeding command orders.
|
---|
3518 | int preceeding_index = command_index - 1;
|
---|
3519 | ///ystem.err.println("Searching before the target command.");
|
---|
3520 | while(preceeding_index >= 0) {
|
---|
3521 | matching_elements = document_element.getElementsByTagName (COMMAND_ORDER[preceeding_index]);
|
---|
3522 | // If we've found a match
|
---|
3523 | if(matching_elements.getLength () > 0) {
|
---|
3524 | // We add after the last element
|
---|
3525 | Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
|
---|
3526 | // One final quick test. If the matched element is immediately followed by a NewLine command, then we insert another NewLine after the matched command, then return the NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
3527 | Node sibling_element = matched_element.getNextSibling ();
|
---|
3528 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
3529 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
3530 | document_element.insertBefore (newline_element, sibling_element);
|
---|
3531 | }
|
---|
3532 | return sibling_element; // Note that this may be null
|
---|
3533 | }
|
---|
3534 | preceeding_index--;
|
---|
3535 | }
|
---|
3536 | // If all that fails, we now move backwards through the commands
|
---|
3537 | int susceeding_index = command_index + 1;
|
---|
3538 | ///ystem.err.println("Searching after the target command.");
|
---|
3539 | while(susceeding_index < COMMAND_ORDER.length) {
|
---|
3540 | matching_elements = document_element.getElementsByTagName (COMMAND_ORDER[susceeding_index]);
|
---|
3541 | // If we've found a match
|
---|
3542 | if(matching_elements.getLength () > 0) {
|
---|
3543 | // We add before the first element
|
---|
3544 | Element matched_element = (Element) matching_elements.item (0);
|
---|
3545 | // One final quick test. If the matched element is immediately preceeded by a NewLine command, then we insert another NewLine before the matched command, then return this new NewLine instead (thus the about to be inserted command will be placed between the two NewLines)
|
---|
3546 | Node sibling_element = matched_element.getPreviousSibling ();
|
---|
3547 | if(sibling_element != null && sibling_element.getNodeName ().equals (NEWLINE_ELEMENT)) {
|
---|
3548 | Element newline_element = document.createElement (NEWLINE_ELEMENT);
|
---|
3549 | document_element.insertBefore (newline_element, sibling_element);
|
---|
3550 | }
|
---|
3551 | return sibling_element; // Note that this may be null
|
---|
3552 | }
|
---|
3553 | susceeding_index++;
|
---|
3554 | }
|
---|
3555 | // Well. Apparently there are no other commands in this collection configuration. So append away...
|
---|
3556 | return null;
|
---|
3557 | }
|
---|
3558 | // From collectionConfig.xml to internal structure:add 'ex.' namespace (if none).
|
---|
3559 | // From internal structure to collectionConfig.xml:always peel off 'ex.' namespace (if any), except for format statement
|
---|
3560 | //This method parses 'xml_file_doc' into 'dOc'
|
---|
3561 | public void parseCollectionConfigXML (File xml_file, Document dOc) {
|
---|
3562 |
|
---|
3563 | Document xml_file_doc = XMLTools.parseXMLFile (xml_file);
|
---|
3564 | Element fromElement = xml_file_doc.getDocumentElement ();
|
---|
3565 | Element toElement = dOc.getDocumentElement ();
|
---|
3566 |
|
---|
3567 | // It's deliberately set that 'creator', 'maintainer', and 'public' are only in English (as they are just names).
|
---|
3568 | // So the following ArrayList have only one element.
|
---|
3569 | Node metadataListNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.METADATALIST_STR, 0);
|
---|
3570 | if (metadataListNode != null) {
|
---|
3571 | ArrayList creator = doMetadataList (dOc, metadataListNode, StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT,
|
---|
3572 | StaticStrings.COLLECTIONMETADATA_CREATOR_STR);
|
---|
3573 | ArrayList maintainer = doMetadataList (dOc, metadataListNode,
|
---|
3574 | StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT,
|
---|
3575 | StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR);
|
---|
3576 | ArrayList is_public = doMetadataList (dOc, metadataListNode, StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT,
|
---|
3577 | StaticStrings.COLLECTIONMETADATA_PUBLIC_STR);
|
---|
3578 |
|
---|
3579 | appendArrayList (toElement, creator);
|
---|
3580 | appendArrayList (toElement, maintainer);
|
---|
3581 | appendArrayList (toElement, is_public);
|
---|
3582 | }
|
---|
3583 |
|
---|
3584 | Node searchNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.SEARCH_STR, 0);
|
---|
3585 | String buildtype_value = ((Element)searchNode).getAttribute (StaticStrings.TYPE_ATTRIBUTE);//might be mg|mgpp|lucene
|
---|
3586 | Element buildtype = doBuildType (dOc, buildtype_value);
|
---|
3587 | appendProperly (toElement, buildtype);
|
---|
3588 |
|
---|
3589 |
|
---|
3590 | Node importNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.IMPORT_STR, 0);
|
---|
3591 | if (importNode == null) {
|
---|
3592 | System.out.println ("There is no content in the 'import' block.");
|
---|
3593 | }
|
---|
3594 | if (importNode != null) {
|
---|
3595 | //do plugin list nodes
|
---|
3596 | Node pluginListNode = XMLTools.getChildByTagNameIndexed ((Element)importNode, StaticStrings.PLUGINLIST_STR, 0);
|
---|
3597 | if (pluginListNode == null) {
|
---|
3598 | System.out.println ("There is no pluginlist set.");
|
---|
3599 | }
|
---|
3600 | if (pluginListNode != null) {
|
---|
3601 |
|
---|
3602 | doPlugin (dOc, pluginListNode);
|
---|
3603 | }
|
---|
3604 |
|
---|
3605 | //do the plugout element (used by building flax collections)
|
---|
3606 | Node plugout = XMLTools.getChildByTagNameIndexed ((Element)importNode, PLUGOUT_ELEMENT, 0);
|
---|
3607 | if (plugout != null) {
|
---|
3608 | Element to_element = XMLTools.duplicateElement (dOc, (Element)plugout, true);
|
---|
3609 | toElement.appendChild (to_element);
|
---|
3610 | }
|
---|
3611 | }
|
---|
3612 |
|
---|
3613 | Node browseNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.BROWSE_STR, 0);
|
---|
3614 | if (browseNode != null) {
|
---|
3615 | if (browseNode == null) {
|
---|
3616 | System.out.println ("There is no classifier.");
|
---|
3617 | }
|
---|
3618 | doClassifier (dOc, browseNode);
|
---|
3619 | }
|
---|
3620 |
|
---|
3621 | Node displayItemListNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.DISPLAYITEMLIST_STR, 0);
|
---|
3622 | if (displayItemListNode != null) {
|
---|
3623 | ArrayList description = doDisplayItemList (dOc, displayItemListNode, StaticStrings.DESCRIPTION_STR,
|
---|
3624 | StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
|
---|
3625 | ArrayList smallicon = doDisplayItemList (dOc, displayItemListNode, StaticStrings.SMALLICON_STR,
|
---|
3626 | StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
|
---|
3627 | ArrayList icon = doDisplayItemList (dOc, displayItemListNode, StaticStrings.ICON_STR,
|
---|
3628 | StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR);
|
---|
3629 | ArrayList name = doDisplayItemList (dOc, displayItemListNode, StaticStrings.NAME_STR,
|
---|
3630 | StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
|
---|
3631 |
|
---|
3632 | appendArrayList (toElement, description);
|
---|
3633 | appendArrayList (toElement, smallicon);
|
---|
3634 | appendArrayList (toElement, icon);
|
---|
3635 | appendArrayList (toElement, name);
|
---|
3636 | }
|
---|
3637 |
|
---|
3638 | if (buildtype_value.equalsIgnoreCase ("mg")) {
|
---|
3639 | doMGIndexes (dOc, searchNode);
|
---|
3640 | }
|
---|
3641 | else {
|
---|
3642 | doMGPPIndexes (dOc, searchNode);
|
---|
3643 | }
|
---|
3644 |
|
---|
3645 | doDefaultIndex (dOc, searchNode);
|
---|
3646 | //doSearchType (dOc, searchNode);
|
---|
3647 | doDefaultLevel (dOc, searchNode);
|
---|
3648 | doLevel (dOc, searchNode);
|
---|
3649 | doIndexOption (dOc, searchNode);
|
---|
3650 | doSubcollection (dOc, searchNode);
|
---|
3651 | doIndexSubcollection (dOc, searchNode);
|
---|
3652 | doIndexLanguage (dOc, searchNode);
|
---|
3653 | doDefaultIndexLanguage (dOc, searchNode);
|
---|
3654 | doLanguageMetadata (dOc, searchNode);
|
---|
3655 | doSearchFormat (dOc, searchNode);
|
---|
3656 | doDisplayFormat (dOc, fromElement);
|
---|
3657 | doReplaceListRef (dOc, fromElement);
|
---|
3658 | doOAIElement (dOc, fromElement);
|
---|
3659 |
|
---|
3660 | }
|
---|
3661 |
|
---|
3662 |
|
---|
3663 | public void saveCollectionConfigXML (File collect_cfg_file, Document doc) {
|
---|
3664 | //In this method, the file collect_cfg_file must be 'collectionConfig.xml'
|
---|
3665 |
|
---|
3666 |
|
---|
3667 | //Compare the internal structure (doc) with the saved structure from collectionConfig.xml and see if it has changed
|
---|
3668 | StringBuffer collect_cfg_string_buffer = new StringBuffer (XMLTools.xmlNodeToString (doc));
|
---|
3669 | String collect_cfg_string = collect_cfg_string_buffer.toString ();
|
---|
3670 | if (saved_collect_cfg_string_buffer != null) {
|
---|
3671 | String saved_collect_cfg_string = saved_collect_cfg_string_buffer.toString ();
|
---|
3672 | if (collect_cfg_string.equals (saved_collect_cfg_string)) {
|
---|
3673 | DebugStream.println ("'collectionConfig.xml' file hasn't changed so no save necessary...");
|
---|
3674 | return;
|
---|
3675 | }
|
---|
3676 | }
|
---|
3677 |
|
---|
3678 | DebugStream.println ("'collectionConfig.xml' file has changed, saving now...");
|
---|
3679 |
|
---|
3680 | // If we're using the Local Library we must release the collection before writing to the collect.cfg file
|
---|
3681 | String collection_name = Gatherer.c_man.getCollection ().getName ();
|
---|
3682 | boolean collection_released = false;
|
---|
3683 | if (Gatherer.c_man.built () && LocalLibraryServer.isRunning () == true) {
|
---|
3684 | // Release the collection
|
---|
3685 | LocalLibraryServer.releaseCollection (collection_name);
|
---|
3686 | collection_released = true;
|
---|
3687 | }
|
---|
3688 |
|
---|
3689 | // Make a backup of the collectionConfig.xml file so that the user can manully change back
|
---|
3690 | if (collect_cfg_file.exists ()) {
|
---|
3691 |
|
---|
3692 | File original_file = new File (collect_cfg_file.getParentFile (), Utility.COLLECTION_CONFIG_XML);
|
---|
3693 | File backup_file = new File (collect_cfg_file.getParentFile (), Utility.COLLECTION_CONFIG_BAK);
|
---|
3694 | if (backup_file.exists ()) {
|
---|
3695 | backup_file.delete ();
|
---|
3696 | }
|
---|
3697 | if (!original_file.renameTo (backup_file)) {
|
---|
3698 | System.err.println ("Warning: can't rename collectionConfig.xml to collectionConfig.bak.");
|
---|
3699 | }
|
---|
3700 | }
|
---|
3701 |
|
---|
3702 | Document collection_config_xml_document = convertInternalToCollectionConfig (doc);
|
---|
3703 | String[] nonEscapingTagNames = {StaticStrings.FORMAT_STR};
|
---|
3704 | XMLTools.writeXMLFile (collect_cfg_file, collection_config_xml_document, nonEscapingTagNames);
|
---|
3705 | saved_collect_cfg_string_buffer = collect_cfg_string_buffer;
|
---|
3706 |
|
---|
3707 | // If we're using a remote Greenstone server, upload the new 'collectionConfig.xml' file
|
---|
3708 | if (Gatherer.isGsdlRemote) {
|
---|
3709 | Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file);
|
---|
3710 | }
|
---|
3711 |
|
---|
3712 | // Now re-add the collection to the Local Library server
|
---|
3713 | if (collection_released) {
|
---|
3714 | LocalLibraryServer.addCollection (collection_name);
|
---|
3715 | }
|
---|
3716 |
|
---|
3717 | }
|
---|
3718 | public void saveIfNecessary () {
|
---|
3719 | if (Gatherer.GS3 == true) {
|
---|
3720 | saveCollectionConfigXML (collect_cfg_file, document);
|
---|
3721 | return;
|
---|
3722 | }
|
---|
3723 | // Convert the collection configuration XML tree to the collect.cfg version
|
---|
3724 | StringBuffer collect_cfg_string_buffer = new StringBuffer ();
|
---|
3725 | NodeList command_elements = document.getDocumentElement ().getChildNodes ();
|
---|
3726 | boolean just_wrote_blank_line = false; // Prevent two or more blank lines in a row
|
---|
3727 | for (int i = 0; i < command_elements.getLength (); i++) {
|
---|
3728 | Node command_node = command_elements.item (i);
|
---|
3729 | if (!(command_node instanceof Element)) {
|
---|
3730 | // We're only interested in Elements
|
---|
3731 | continue;
|
---|
3732 | }
|
---|
3733 | Element command_element = (Element) command_node;
|
---|
3734 |
|
---|
3735 | // Handle NewLine elements (blank lines)
|
---|
3736 | if (command_element.getNodeName ().equals (NEWLINE_ELEMENT) && !just_wrote_blank_line) {
|
---|
3737 | collect_cfg_string_buffer.append ("\n");
|
---|
3738 | just_wrote_blank_line = true;
|
---|
3739 | }
|
---|
3740 |
|
---|
3741 | // Anything else we write to file, but only if it has been assigned, except for index and level commands
|
---|
3742 | // (which just get commented out if unassigned -- a side effect of MG & MGPP compatibility)
|
---|
3743 | else if (!command_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR) || command_element.getNodeName ().equals (StaticStrings.INDEXES_ELEMENT) || command_element.getNodeName ().equals (StaticStrings.INDEX_DEFAULT_ELEMENT) || command_element.getNodeName ().equals (StaticStrings.INDEXOPTIONS_ELEMENT) || command_element.getNodeName ().equals (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT)) {
|
---|
3744 | String command;
|
---|
3745 | if (command_element.getNodeName ().equals (StaticStrings.FORMAT_ELEMENT)) {
|
---|
3746 | // Format statements we write out with ex. still present
|
---|
3747 | command = toString (command_element, true);
|
---|
3748 | }
|
---|
3749 | else {
|
---|
3750 | command = toString (command_element, false);
|
---|
3751 | }
|
---|
3752 |
|
---|
3753 | if (command != null && command.length ()> 0 ) {
|
---|
3754 | collect_cfg_string_buffer.append (command + "\n");
|
---|
3755 | just_wrote_blank_line = false;
|
---|
3756 | }
|
---|
3757 | }
|
---|
3758 | }
|
---|
3759 |
|
---|
3760 | String collect_cfg_string = collect_cfg_string_buffer.toString ();
|
---|
3761 | String saved_collect_cfg_string = saved_collect_cfg_string_buffer.toString ();
|
---|
3762 | if (collect_cfg_string.equals (saved_collect_cfg_string)) {
|
---|
3763 | DebugStream.println ("Collect.cfg file hasn't changed so no save necessary...");
|
---|
3764 | return;
|
---|
3765 | }
|
---|
3766 |
|
---|
3767 | DebugStream.println ("Collect.cfg file has changed, saving now...");
|
---|
3768 |
|
---|
3769 | // If we're using the Local Library we must release the collection before writing to the collect.cfg file
|
---|
3770 | String collection_name = CollectionManager.getLoadedCollectionName ();
|
---|
3771 | boolean collection_released = false;
|
---|
3772 | if (Gatherer.c_man.built () && LocalLibraryServer.isRunning () == true) {
|
---|
3773 | // Release the collection
|
---|
3774 | LocalLibraryServer.releaseCollection (collection_name);
|
---|
3775 | collection_released = true;
|
---|
3776 | }
|
---|
3777 |
|
---|
3778 | // Make a backup of the collect.cfg file
|
---|
3779 | if (collect_cfg_file.exists ()) {
|
---|
3780 | File original_file = new File (collect_cfg_file.getParentFile (), StaticStrings.COLLECT_CFG);
|
---|
3781 | File backup_file = new File (collect_cfg_file.getParentFile (), Utility.COLLECT_BAK);
|
---|
3782 | if (backup_file.exists ()) {
|
---|
3783 | backup_file.delete ();
|
---|
3784 | }
|
---|
3785 | if (!original_file.renameTo (backup_file)) {
|
---|
3786 | System.err.println ("Warning: can't rename collect.cfg to collect.bak.");
|
---|
3787 | }
|
---|
3788 | }
|
---|
3789 |
|
---|
3790 | try {
|
---|
3791 | OutputStream ostream = new FileOutputStream (collect_cfg_file);
|
---|
3792 | Writer file_writer = new OutputStreamWriter (ostream, ENCODING);
|
---|
3793 | BufferedWriter buffered_writer = new BufferedWriter (file_writer);
|
---|
3794 | buffered_writer.write (collect_cfg_string);
|
---|
3795 | buffered_writer.close ();
|
---|
3796 |
|
---|
3797 | saved_collect_cfg_string_buffer = collect_cfg_string_buffer;
|
---|
3798 |
|
---|
3799 | // If we're using a remote Greenstone server, upload the new collect.cfg file
|
---|
3800 | if (Gatherer.isGsdlRemote) {
|
---|
3801 | Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file);
|
---|
3802 | }
|
---|
3803 | }
|
---|
3804 | catch (Exception exception) {
|
---|
3805 | DebugStream.println ("Error in CollectionConfiguration.save(): " + exception);
|
---|
3806 | DebugStream.printStackTrace (exception);
|
---|
3807 | }
|
---|
3808 |
|
---|
3809 | // Now re-add the collection to the Local Library server
|
---|
3810 | if (collection_released) {
|
---|
3811 | LocalLibraryServer.addCollection (collection_name);
|
---|
3812 | }
|
---|
3813 | }
|
---|
3814 | // This method is initilised in CollectionDesignManager.java constructor
|
---|
3815 | public CollectionConfiguration (File collect_cfg_file) {
|
---|
3816 | this.collect_cfg_file = collect_cfg_file;
|
---|
3817 |
|
---|
3818 | // parse the XML template
|
---|
3819 | document = XMLTools.parseXMLFile ("xml/CollectionConfig.xml", true);
|
---|
3820 | String filename = collect_cfg_file.getName ().toLowerCase ();
|
---|
3821 |
|
---|
3822 | if (filename.endsWith (".cfg")) {
|
---|
3823 | parse (collect_cfg_file);
|
---|
3824 | }
|
---|
3825 | if (filename.endsWith (".xml")) {
|
---|
3826 | parseCollectionConfigXML (collect_cfg_file, document);
|
---|
3827 | }
|
---|
3828 |
|
---|
3829 | //XMLTools.printXMLNode(document.getDocumentElement());
|
---|
3830 | }
|
---|
3831 |
|
---|
3832 | // Append the elements, which are of Element type, in 'list' to Element 'to'
|
---|
3833 | private void appendArrayList (Element to, ArrayList list) {
|
---|
3834 | if (list == null) return;
|
---|
3835 |
|
---|
3836 | for (int i=0; i<list.size (); i++) {
|
---|
3837 | appendProperly (to, (Element)list.get (i));
|
---|
3838 | }
|
---|
3839 | }
|
---|
3840 | //Convert the internal XML DOM tree (dOc) into that of collectionConfig.xml (skeleton)
|
---|
3841 | public Document convertInternalToCollectionConfig (Document dOc) {
|
---|
3842 | //first parse an empty skeleton of xml config file
|
---|
3843 | //The aim is to convert the internal structure into this skeleton
|
---|
3844 | Document skeleton = XMLTools.parseXMLFile ("xml/CollectionConfig.xml", true);
|
---|
3845 | //Element internal = dOc.getDocumentElement();
|
---|
3846 | convertMetadataList (dOc, skeleton);
|
---|
3847 | convertDisplayItemList (dOc, skeleton);
|
---|
3848 | convertBuildType (dOc, skeleton);
|
---|
3849 | convertIndex (dOc, skeleton);
|
---|
3850 | convertPlugin (dOc, skeleton);//also do the plugout element
|
---|
3851 | convertClassifier (dOc, skeleton);
|
---|
3852 | convertSubcollectionIndexes (dOc, skeleton);
|
---|
3853 | convertLanguages (dOc, skeleton);
|
---|
3854 | convertSubcollection (dOc, skeleton);
|
---|
3855 | convertSearchType (dOc, skeleton);
|
---|
3856 | convertSearchFormat (dOc, skeleton);
|
---|
3857 | convertDisplayFormat (dOc, skeleton);
|
---|
3858 | convertReplaceListRef (dOc, skeleton);
|
---|
3859 | convertOAIElement(dOc, skeleton);
|
---|
3860 |
|
---|
3861 | return skeleton;
|
---|
3862 | }
|
---|
3863 |
|
---|
3864 | static private HashMap plugin_map = null;
|
---|
3865 |
|
---|
3866 | private void setUpPluginNameMap() {
|
---|
3867 | plugin_map = new HashMap();
|
---|
3868 | plugin_map.put("RecPlug", "DirectoryPlugin");
|
---|
3869 | plugin_map.put("ArcPlug","ArchivesInfPlugin");
|
---|
3870 | plugin_map.put("TEXTPlug","TextPlugin");
|
---|
3871 | plugin_map.put("EMAILPlug","EmailPlugin");
|
---|
3872 | plugin_map.put("SRCPlug","SourceCodePlugin");
|
---|
3873 | plugin_map.put("NULPlug","NulPlugin");
|
---|
3874 | plugin_map.put("W3ImgPlug","W3ImagePlugin");
|
---|
3875 | plugin_map.put("PagedImgPlug","PagedImagePlugin");
|
---|
3876 | plugin_map.put("METSPlug", "GreenstoneMETSPlugin");
|
---|
3877 | }
|
---|
3878 |
|
---|
3879 | private String ensureNewPluginName(String plugin) {
|
---|
3880 | if (plugin.endsWith("Plugin")) return plugin;
|
---|
3881 | if (plugin_map == null) {
|
---|
3882 | setUpPluginNameMap();
|
---|
3883 | }
|
---|
3884 | String new_name = (String)plugin_map.get(plugin);
|
---|
3885 | if (new_name != null) return new_name;
|
---|
3886 | new_name = plugin.replaceAll("Plug", "Plugin");
|
---|
3887 | return new_name;
|
---|
3888 | }
|
---|
3889 |
|
---|
3890 |
|
---|
3891 | ///*********************************************************************************************************///
|
---|
3892 | }
|
---|
3893 |
|
---|