source: gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java@ 20447

Last change on this file since 20447 was 20447, checked in by kjdon, 15 years ago

split CollectionConfiguration into three files: CollectionConfiguration handles all the DOM internal stuff, while CollectCfgReadWrite and CollectionConfigXMLReadWrite handle reading from and writing to collect.cfg and collectionConfig.xml files, respectively. This class was jsut getting far too big and I could never find anything in it...

File size: 93.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Methods to read collectionConfig.xml files into internal XML form, and write
9 * them back out again.
10 *
11 * Copyright (C) 1999 New Zealand Digital Library Project
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *########################################################################
27 */
28package org.greenstone.gatherer.cdm;
29
30import java.io.File;
31import java.util.ArrayList;
32import java.util.HashMap;
33import java.util.StringTokenizer;
34
35import org.greenstone.gatherer.DebugStream;
36import org.greenstone.gatherer.metadata.MetadataElement;
37import org.greenstone.gatherer.metadata.MetadataTools;
38import org.greenstone.gatherer.util.XMLTools;
39import org.greenstone.gatherer.util.StaticStrings;
40import org.greenstone.gatherer.util.Utility;
41
42import org.w3c.dom.*;
43
44public class CollectionConfigXMLReadWrite {
45
46 static final private String PLUGOUT_ELEMENT = "plugout";//used by building flax collections
47
48 /** ********************************************************************************************************
49 The code from this point below are used for greenstone 3 collection configuration, i.e., read ColletionConfig.xml
50 * into the internal DOM tree, and convert the internal DOM tree back to CollectionConfig.xml.
51 *
52 Methods named 'doXXXX' are for convert collectionConfig.xml into the internal configuration xml structure;
53 Methods named 'convertXXXX' are for convert the internal configuration xml structure back to collectionConfig.xml.
54 ************************************************************************************************************ */
55
56 /**Arguments: metadataListNode->the 'displayItemList' element in collectionConfig.xml
57 name_value->the value of the 'name' attribute of 'index' element;
58 att_value->the value of the 'name' attribute of 'displayItem' element
59 return: an ArrayList of the contructed 'CollectionMetadata' elements
60 */
61 static private ArrayList doDisplayItemList (Document to, Node displayListNode, String att_value, String name_value) {
62 Element toElement = to.getDocumentElement ();
63 ArrayList display_item_list = new ArrayList ();
64 ArrayList item_list = XMLTools.getNamedElementList ((Element)displayListNode,
65 StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, att_value);
66 if (item_list == null) {
67 return null;
68 }
69
70 for (int i=0; i<item_list.size (); i++) {
71 Element item = (Element)item_list.get (i);
72 String text = XMLTools.getNodeText (item);
73
74 //If there is nothing to display, don't bother creating the element
75 if (text == "") {
76 continue;
77 }
78 //get the value in 'lang=value'
79 String lang = item.getAttribute (StaticStrings.LANG_STR);
80
81 Element e = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
82 e.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
83 e.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_value);
84 e.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
85 XMLTools.setNodeText (e, text);
86 display_item_list.add (e);
87 }
88 return display_item_list;
89 }
90
91 static private ArrayList doMetadataList (Document to, Node metadataListNode, String ele_name, String att_value) {
92 Element toElement = to.getDocumentElement ();
93 ArrayList metadata_list = new ArrayList ();
94
95 ArrayList item_list = XMLTools.getNamedElementList ((Element)metadataListNode,
96 StaticStrings.METADATA_STR, StaticStrings.NAME_ATTRIBUTE, att_value);
97 if (item_list == null) {
98 return null;
99 }
100
101 for (int i=0; i<item_list.size (); i++) {
102 Element item = (Element)item_list.get (i);
103 String text = XMLTools.getNodeText (item);
104
105 //If there is nothing to display, don't bother creating the element
106 if (text == "") {
107 continue;
108 }
109 //get the value in 'lang=value'
110 String lang = item.getAttribute (StaticStrings.LANG_STR);
111
112 Element element = to.createElement (ele_name);
113 element.setAttribute (StaticStrings.NAME_ATTRIBUTE, att_value);
114 element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
115 element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
116 element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
117 XMLTools.setNodeText (element, text);
118
119 metadata_list.add (element);
120 }
121 return metadata_list;
122 }
123 // 'to' is the internal structure
124 static private void doMGIndexes (Document to, Node searchNode) {
125 Element toElement = to.getDocumentElement ();
126 Element indexes_element = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
127 indexes_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
128 indexes_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
129
130 NodeList index_children = ((Element)searchNode).getElementsByTagName (StaticStrings.INDEX_LOW_STR);//index
131 int num_nodes = index_children.getLength ();
132
133 for (int i=0; i<num_nodes; i++) {
134 Element e = (Element)index_children.item (i);
135 String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
136 String index_str_display = index_str;//used for creating collectionmetadata for this index
137 Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
138
139 // For mg, it's the 'Old G2.38 and earlier' that use level:source tuplets, but we double check it anyway
140 boolean old_index = true;
141 if(index_str.indexOf (StaticStrings.COLON_CHARACTER) == -1) {
142 // It doesn't contain ':' character
143 System.err.println ("Something is wrong! the index should be level:source tuplets.");
144 old_index = false;
145 }
146 else {
147 // Handling 'index' element
148 index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE,
149 index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER)));
150 index_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
151
152 //Each index may have a list of comma-separated strings.
153 //split them into 'content' elements in the internal structure
154 StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
155 //index_str = "";
156 while(content_tokenizer.hasMoreTokens ()) {
157 // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
158
159
160 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
161 String content_str = content_tokenizer.nextToken ();
162 // Since the contents of indexes have to be certain keywords, or metadata elements,
163 //if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
164 if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
165 if(content_str.equals (StaticStrings.TEXT_STR) ||
166 (!old_index && content_str.equals (StaticStrings.ALLFIELDS_STR))) {
167 // in this case, do nothing
168 }
169 else {
170 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
171 }
172 }
173
174 content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
175 index_element.appendChild (content_element);
176 content_element = null;
177 } // while ends
178
179 indexes_element.appendChild (index_element);
180
181 // Handling 'displayItem' elements and Constructing 'collectionmetadata' elements
182 // Use the fully qualified index names
183 ArrayList collectionmetadata_list = doDisplayItemList (to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
184 appendArrayList (toElement, collectionmetadata_list);
185 } //else ends
186 } //for loop ends
187 appendProperly (toElement, indexes_element);
188
189 //***//
190 // create another set of <indexes> which will be used when user switches to MGPP/LUCENE
191 // i.e. we build a default index set for a start
192
193 String []index_strs =
194 {StaticStrings.TEXT_STR,
195 StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.TITLE_ELEMENT,
196 StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.SOURCE_ELEMENT};
197
198 Element mgpp_indexes = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
199 mgpp_indexes.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
200 mgpp_indexes.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
201 for (int i=0; i<index_strs.length; i++) {
202 Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
203 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
204 content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
205 index_element.appendChild (content_element);
206 mgpp_indexes.appendChild (index_element);
207
208 // Contructing 'collectionmetadata' elements for 'mgpp' indexes
209 Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
210 collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
211 collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
212 collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
213 if (index_strs[i].indexOf (StaticStrings.NS_SEP) != -1) {
214 index_strs[i] = index_strs[i].substring (index_strs[i].indexOf (StaticStrings.NS_SEP) + 1);
215 }
216 XMLTools.setNodeText (collectionmetadata, index_strs[i]);
217
218 appendProperly (toElement, collectionmetadata);
219
220 }
221 appendProperly (toElement, mgpp_indexes);
222 }
223
224 //This is actually doing indexes for both mgpp and lucene
225 static private void doMGPPIndexes (Document to, Node searchNode) {
226 Element toElement = to.getDocumentElement ();
227 Element indexes_element = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
228 indexes_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
229 indexes_element.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR);
230
231 NodeList index_children = ((Element)searchNode).getElementsByTagName (StaticStrings.INDEX_LOW_STR);//index
232 int num_nodes = index_children.getLength ();
233
234 for (int i=0; i<num_nodes; i++) {
235
236 Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
237 Element e = (Element)index_children.item (i);
238 String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
239 String index_str_display = index_str;//for creating collectionmetadata for this index
240
241 // Handling 'index' element
242 // Double check to make sure it's not colon separated style index.
243 boolean old_index = false;
244 if(index_str.indexOf (StaticStrings.COLON_CHARACTER) != -1) {
245 System.err.println ("Something is wrong! the index should NOT be level:source tuplets style.");
246 old_index = true;
247 }
248 //Each index may have a list of comma-separated strings.
249 //split them into 'content' elements in the internal structure
250 StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
251 //index_str = "";
252 while(content_tokenizer.hasMoreTokens ()) {
253 // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
254
255 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
256 String content_str = content_tokenizer.nextToken ();
257 // 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.
258 if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
259 if(content_str.equals (StaticStrings.TEXT_STR)) {
260 // in this case, do nothing
261 }
262 else {
263 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
264 }
265 }
266 content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
267 index_element.appendChild (content_element);
268 content_element = null;
269 } //while ends
270
271 indexes_element.appendChild (index_element);
272
273
274 index_element = null;
275
276 // Handling 'displayItem' element of this 'index' element
277 // 'e' is the parent element 'index' of 'displayItem' element
278 ArrayList collectionmetadata_list = doDisplayItemList (to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
279 appendArrayList (toElement, collectionmetadata_list);
280
281
282 } // for loop ends
283 toElement.appendChild (indexes_element);
284
285 // create another set of <indexes> which will be used when user switches to MG
286 // i.e. we build a default index set for a start
287 Element mg_indexes = to.createElement (StaticStrings.INDEXES_ELEMENT);//<Indexes>
288 mg_indexes.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
289 mg_indexes.setAttribute (StaticStrings.MGPP_ATTRIBUTE, StaticStrings.FALSE_STR);
290
291 //put the namespace '.ex' as prefix to the indexes
292 String []index_strs =
293 {StaticStrings.TEXT_STR,
294 StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.TITLE_ELEMENT,
295 StaticStrings.EXTRACTED_NAMESPACE + StaticStrings.SOURCE_ELEMENT};
296 for (int i=0; i<index_strs.length; i++) {
297 Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);//<Index>
298 index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE, StaticStrings.DOCUMENT_STR);
299 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
300 content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_strs[i]);
301 index_element.appendChild (content_element);
302
303 mg_indexes.appendChild (index_element);
304
305 // Contructing 'collectionmetadata' elements for 'mg' indexes
306 Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
307 collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
308 String temp = StaticStrings.DOCUMENT_STR.concat (StaticStrings.COLON_CHARACTER).concat (index_strs[i]);
309 collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, temp);
310 collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
311 if (index_strs[i].indexOf (StaticStrings.NS_SEP) != -1) {
312 index_strs[i] = index_strs[i].substring (index_strs[i].indexOf (StaticStrings.NS_SEP) + 1);
313 }
314 XMLTools.setNodeText (collectionmetadata, index_strs[i]);
315
316 appendProperly (toElement, collectionmetadata);
317
318 }
319 toElement.appendChild (mg_indexes);
320
321 }
322
323 static private void doDisplayFormat (Document to, Element from) {
324 //display element in the xml file
325 Element de = (Element)XMLTools.getChildByTagName (from, StaticStrings.DISPLAY_STR);
326 if (de == null) {
327 return;
328 }
329 //format element in the display element
330 Element fe = (Element)XMLTools.getChildByTagName (de, StaticStrings.FORMAT_STR);
331
332 to.getDocumentElement ().appendChild (doFormat(to, fe, StaticStrings.DISPLAY_STR));
333 }
334
335 //construct 'DefaultIndex' element in the internal structure from collectionConfig.xml
336 static private void doDefaultIndex (Document to, Node searchNode) {
337 Element toElement = to.getDocumentElement ();
338 Element default_index_element = to.createElement (StaticStrings.INDEX_DEFAULT_ELEMENT);
339 default_index_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
340
341 Element e = (Element)XMLTools.getChildByTagName (searchNode, StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE);//defaultIndex
342 if (e == null) {
343 return;
344 }
345 String index_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
346
347 boolean old_index = false;
348 if(index_str.indexOf (StaticStrings.COLON_CHARACTER) != -1) {
349 //The index is 'level:source tuplets' which is for mg. Take out 'level'
350 old_index = true;
351 default_index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE,
352 index_str.substring (0, index_str.indexOf (StaticStrings.COLON_CHARACTER)));
353 index_str = index_str.substring (index_str.indexOf (StaticStrings.COLON_CHARACTER) + 1);
354 } else {
355 default_index_element.setAttribute (StaticStrings.LEVEL_ATTRIBUTE, "");
356 }
357
358 //Each index may have a list of comma-separated strings.
359 //split them into 'content' elements in the internal structure
360 StringTokenizer content_tokenizer = new StringTokenizer (index_str, StaticStrings.COMMA_CHARACTER);
361 while(content_tokenizer.hasMoreTokens ()) {
362 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
363 String content_str = content_tokenizer.nextToken ();
364 // 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.
365 if(content_str.indexOf (StaticStrings.NS_SEP) == -1) {
366 if(content_str.equals (StaticStrings.TEXT_STR) ||
367 (!old_index && content_str.equals (StaticStrings.ALLFIELDS_STR))) {
368 // in this case, do nothing
369 }
370 else {
371 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
372 }
373 }
374
375 content_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, content_str);
376 default_index_element.appendChild (content_element);
377 content_element = null;
378 }
379 appendProperly (toElement, default_index_element);
380 }
381 // For mg, this method is still called, but make it 'assigned=false'
382 static private void doDefaultLevel (Document to, Node searchNode) {
383 Element toElement = to.getDocumentElement ();
384 Element default_index_option = to.createElement (StaticStrings.INDEXOPTION_DEFAULT_ELEMENT);
385 default_index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVEL_DEFAULT_STR);
386
387 Element e = (Element)XMLTools.getChildByTagName (searchNode, StaticStrings.LEVEL_DEFAULT_ELEMENT);
388 if (e != null) {
389 default_index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
390 String level = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
391 default_index_option.setAttribute (StaticStrings.VALUE_ATTRIBUTE, level);
392 } else {
393 //In the case of mg, there's no level! build a default one using 'assigned=false value=document'
394 default_index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
395 default_index_option.setAttribute (StaticStrings.VALUE_ATTRIBUTE, StaticStrings.DOCUMENT_STR);
396 }
397 appendProperly (toElement, default_index_option);
398 }
399
400 // Transform plugins (pluginListNode) of collectionConfig.xml into the internal structure (i.e. Document to)
401 static private void doPlugin (Document to, Node pluginListNode) {
402 Element toElement = to.getDocumentElement ();
403 NodeList plugin_children = ((Element)pluginListNode).getElementsByTagName (StaticStrings.PLUGIN_STR);
404 int plugin_nodes = plugin_children.getLength ();
405
406 if (plugin_nodes < 1) {
407 return;
408 }
409
410 for (int i=0; i<plugin_nodes; i++) {
411 Element e = (Element)plugin_children.item (i);
412 String str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
413 str = Utility.ensureNewPluginName(str);
414 Element plugin_element = to.createElement (StaticStrings.PLUGIN_ELEMENT);
415 plugin_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, str);
416
417
418 NodeList option_children = e.getElementsByTagName (StaticStrings.OPTION_STR);
419
420 for (int j=0; j<option_children.getLength (); j++) {
421 Element el = (Element)option_children.item (j);
422 String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
423 if (name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
424 name_str = name_str.substring (1);
425 }
426 String value_str = el.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
427 Element option_element = null;
428
429 if (name_str.equals ("") && !value_str.equals ("")) {
430 continue;
431 }
432
433
434 option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
435 option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
436 if(name_str.equals (StaticStrings.RECPLUG_STR) && value_str.equals (StaticStrings.USE_METADATA_FILES_ARGUMENT)) {
437 continue; // ignore this option
438 }
439
440 if(value_str != null) {
441 // Remove any speech marks appended in strings containing whitespace
442 if(value_str.startsWith (StaticStrings.SPEECH_CHARACTER) && value_str.endsWith (StaticStrings.SPEECH_CHARACTER)) {
443 value_str = value_str.substring (1, value_str.length () - 1);
444 }
445 if(name_str.equals (StaticStrings.METADATA_STR)) {
446 // 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.
447 String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
448 value_str = "";
449 for (int k=0; k<=values.length-1; k++) {
450 if (values[k].indexOf (StaticStrings.NS_SEP) == -1) {
451 values[k] = StaticStrings.EXTRACTED_NAMESPACE + values[k];
452 }
453
454 if (k < values.length-1) {
455 value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
456
457 } else {
458 value_str = value_str + values[k];
459 }
460 }
461 }
462 }
463 if (!name_str.equals ("")) {
464 option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
465 }
466 if (!value_str.equals ("")) {
467 XMLTools.setNodeText (option_element, value_str);
468 }
469 plugin_element.appendChild (option_element);
470
471 }
472
473 appendProperly (toElement, plugin_element);
474 }
475
476 }
477
478 //Handle classifiers
479 static private void doClassifier (Document to, Node browseNode) {
480 Element toElement = to.getDocumentElement ();
481 NodeList classifier_children = ((Element)browseNode).getElementsByTagName (StaticStrings.CLASSIFIER_STR);
482 int num_nodes = classifier_children.getLength ();
483
484 if (num_nodes < 1) {
485 return;
486 }
487
488 for (int i=0; i<num_nodes; i++) {
489 Element e = (Element)classifier_children.item (i);
490 String str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
491 Element classify_element = to.createElement (StaticStrings.CLASSIFY_ELEMENT);
492 classify_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, str);
493
494 String options_str = "";
495 NodeList option_children = e.getElementsByTagName (StaticStrings.OPTION_STR);
496 for (int j=0; j<option_children.getLength (); j++) {
497 Element el = (Element)option_children.item (j);
498 String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
499 options_str = options_str + ((name_str.equals(""))? "" : (" " + name_str));
500 if (name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
501 name_str = name_str.substring (1);
502 }
503 String value_str = el.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
504 options_str = options_str + ((name_str.equals(""))? "" : (" " + value_str));
505 Element option_element = null;
506
507 if (name_str.equals ("") && !value_str.equals ("")) {
508 continue; //invalid condition
509 }
510
511 option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
512 option_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
513
514 if (!name_str.equals ("")) {
515 option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
516 }
517
518 if (!value_str.equals ("") && name_str.equals (StaticStrings.METADATA_STR)) {
519 // 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.
520 String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
521 value_str = "";
522 for (int k=0; k<=values.length-1; k++) {
523 if (values[k].indexOf (StaticStrings.NS_SEP) == -1) {
524 values[k] = StaticStrings.EXTRACTED_NAMESPACE + values[k];
525 }
526 else {
527 MetadataElement metadata_element = MetadataTools.getMetadataElementWithName (values[k]);
528 if (metadata_element != null) {
529 values[k] = metadata_element.getDisplayName ();
530 }
531 }
532 if (k < values.length-1) {
533 value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
534 } else {
535 value_str = value_str + values[k];
536 }
537 }
538 }
539
540 if (value_str != null && !value_str.equals ("")) {
541 XMLTools.setNodeText (option_element, value_str);
542 }
543 classify_element.appendChild (option_element);
544 }
545 //format element for this classifier
546 Element format = (Element)XMLTools.getChildByTagName (e, StaticStrings.FORMAT_STR);
547 if(format != null) {
548 classify_element.appendChild (doFormat(to, format, null));
549 }
550 appendProperly (toElement, classify_element);
551 }
552
553 // default format statement for all classifiers
554 Element default_classifier_format = (Element)XMLTools.getChildByTagName (browseNode, StaticStrings.FORMAT_STR);
555
556 to.getDocumentElement ().appendChild (doFormat(to, default_classifier_format, StaticStrings.BROWSE_STR));
557 }
558 static private Element doFormat(Document to, Element format, String name_str) {
559 Element format_element = to.createElement (StaticStrings.FORMAT_STR);
560 if (name_str != null) {
561 format_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
562 }
563 if (format != null) {
564 String gsf_text = XMLTools.xmlNodeToStringWithoutIndenting(format);
565
566 if (gsf_text.startsWith("<") && (gsf_text.indexOf("<") != gsf_text.lastIndexOf("<"))) {
567 gsf_text = gsf_text.substring(gsf_text.indexOf("<gsf"),
568 gsf_text.indexOf(StaticStrings.FORMAT_END_TAG));
569 }
570
571 XMLTools.setNodeText(format_element, gsf_text);
572 }
573 return format_element;
574 }
575 // Handling 'subcollection' elements in 'search' element of 'collectionConfig.xml'
576 static private void doSubcollection (Document to, Node searchNode) {
577 Element toElement = to.getDocumentElement ();
578 NodeList sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.SUBCOLLECTION_STR);
579 int sub_nodes = sub_children.getLength ();
580
581 // There is no subcollection
582 if (sub_nodes < 1) {
583 return;
584 }
585
586 for (int i=0; i<sub_nodes; i++) {
587 Element sub_child = (Element)sub_children.item (i);
588 String name_str = sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
589 String filter_str = sub_child.getAttribute (StaticStrings.FILTER_ATTRIBUTE);
590
591 // filter_str is in the form '<! (if set)><metadata>/<metadata value>/<flag (if any)>'
592
593 int pos = filter_str.indexOf (StaticStrings.SEPARATOR_CHARACTER);
594 String meta_str = "";
595 String meta_value_str = "";
596 String clude_str = "";
597 String flag_str = "";
598 if (pos == -1) {
599
600 meta_str = meta_value_str = filter_str;
601 clude_str = StaticStrings.INCLUDE_STR;
602 } else {
603 clude_str = StaticStrings.INCLUDE_STR;
604 if (filter_str.startsWith (StaticStrings.EXCLAMATION_CHARACTER)) {
605 clude_str = StaticStrings.EXCLUDE_STR;
606 // Peel off "!"
607 filter_str = filter_str.substring (StaticStrings.EXCLAMATION_CHARACTER.length ());
608 }
609
610 String[] strs = filter_str.split (StaticStrings.SEPARATOR_CHARACTER);
611 if (strs[0] != null && strs[0] != "") {
612 meta_str = strs[0];
613 }
614 if(!meta_str.equals (StaticStrings.FILENAME_STR) && meta_str.indexOf (StaticStrings.NS_SEP) == -1) {
615 meta_str = StaticStrings.EXTRACTED_NAMESPACE + meta_str;
616 }
617
618 if (strs[1] != null && strs[1] != "") {
619 meta_value_str = strs[1];
620 }
621 if (strs.length > 2) {
622 //This means there has been set a flag
623 if (strs[2] != null && strs[2] != "") {
624 flag_str = strs[2];
625 }
626 }
627 }
628 Element subcollection_element = to.createElement (StaticStrings.SUBCOLLECTION_ELEMENT);
629 subcollection_element.setAttribute (StaticStrings.NAME_STR, name_str);
630 subcollection_element.setAttribute (StaticStrings.CONTENT_ATTRIBUTE, meta_str);
631 subcollection_element.setAttribute (StaticStrings.TYPE_ATTRIBUTE, clude_str);
632 if (flag_str != "") {
633 subcollection_element.setAttribute (StaticStrings.OPTIONS_ATTRIBUTE, flag_str);
634 }
635 XMLTools.setNodeText (subcollection_element, meta_value_str);
636
637 toElement.appendChild (subcollection_element);
638 }
639 }
640 //Handle levels (document, section). In the internal structure, the element is called 'IndexOption'
641 static private void doLevel (Document to, Node searchNode) {
642 Element toElement = to.getDocumentElement ();
643 NodeList level_children = ((Element)searchNode).getElementsByTagName (StaticStrings.LEVEL_ATTRIBUTE);
644 int level_nodes = level_children.getLength ();
645
646 // it's mg, there's no level. So we construct a default 'indexOption' in the internal structure
647 if (level_nodes < 1) {
648 Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
649 index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
650 index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVELS_STR);
651
652 Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
653 option_element.setAttribute (StaticStrings.NAME_STR, StaticStrings.DOCUMENT_STR);
654 index_option.appendChild (option_element);
655
656 appendProperly (toElement, index_option);
657
658 return;
659 }
660
661 Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
662 index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
663 index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.LEVELS_STR);
664
665 for (int i=0; i<level_nodes; i++) {
666 Element level_element = (Element)level_children.item (i);
667 String level_str = level_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
668 Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
669 option_element.setAttribute (StaticStrings.NAME_STR, level_str);
670 index_option.appendChild (option_element);
671
672
673 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'level' element
674 ArrayList displayItem_list = XMLTools.getNamedElementList (level_element,
675 StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
676 if (displayItem_list == null) {
677 return ;
678 }
679 for (int j=0; j<displayItem_list.size (); j++) {
680 Element item = (Element)displayItem_list.get (j);
681 String text = XMLTools.getNodeText (item);
682 String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
683
684 //If there is nothing to display, don't bother creating the element
685 if (text == "") {
686 continue;
687 }
688 Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
689 collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
690 collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, level_str);
691 collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
692 XMLTools.setNodeText (collectionmetadata, text);
693
694 appendProperly (toElement, collectionmetadata);
695 }
696 }
697 appendProperly (toElement, index_option);
698 }
699 //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.
700 static private void doIndexSubcollection (Document to, Node searchNode) {
701 Element toElement = to.getDocumentElement ();
702 NodeList index_sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.SUBCOLLECTION_INDEX_ELEMENT);
703 int num_nodes = index_sub_children.getLength ();
704
705 // there is no subcollection index
706 if (num_nodes < 1) {
707 return;
708 }
709
710 Element subcollection_indexes = to.createElement (StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT);
711
712 for (int i=0; i<num_nodes; i++) {
713 Element index_element = to.createElement (StaticStrings.INDEX_ELEMENT);
714 Element index_sub_child = (Element)index_sub_children.item (i);
715 String name_str = index_sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
716
717 // name_str is in the form of comma separated strings, each of which is a subcollection filter name
718 String[] filters = name_str.split (StaticStrings.COMMA_CHARACTER);
719 for (int j=0; j<filters.length; j++) {
720
721 Element content_element = to.createElement (StaticStrings.CONTENT_ELEMENT);
722 content_element.setAttribute (StaticStrings.NAME_STR, filters[j]);
723 index_element.appendChild (content_element);
724 }
725 subcollection_indexes.appendChild (index_element);
726
727 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexSubcollection' element
728 ArrayList displayItem_list = XMLTools.getNamedElementList (index_sub_child,
729 StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
730 if (displayItem_list == null) {
731 // there is no display item for this element
732 continue;
733 }
734 for (int j=0; j<displayItem_list.size (); j++) {
735 Element item = (Element)displayItem_list.get (j);
736 String text = XMLTools.getNodeText (item);
737 String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
738
739 //If there is nothing to display, don't bother creating the element
740 if (text == "") {
741 continue;
742 }
743 Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
744 collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
745 collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
746 collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
747 XMLTools.setNodeText (collectionmetadata, text);
748
749 appendProperly (toElement, collectionmetadata);
750 }
751 }
752 appendProperly (toElement, subcollection_indexes);
753 }
754 //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.
755 static private void doIndexLanguage (Document to, Node searchNode) {
756 Element toElement = to.getDocumentElement ();
757 NodeList index_sub_children = ((Element)searchNode).getElementsByTagName (StaticStrings.LANGUAGE_INDEX_ELEMENT);
758 int num_nodes = index_sub_children.getLength ();
759
760 // there is no subcollection index
761 if (num_nodes < 1) {
762 return;
763 }
764
765 Element language_indexes = to.createElement (StaticStrings.LANGUAGES_ELEMENT);
766
767 for (int i=0; i<num_nodes; i++) {
768 Element language_element = to.createElement (StaticStrings.LANGUAGE_ELEMENT);
769 Element index_sub_child = (Element)index_sub_children.item (i);
770 String name_str = index_sub_child.getAttribute (StaticStrings.NAME_ATTRIBUTE);
771 language_element.setAttribute (StaticStrings.NAME_STR, name_str);
772 language_indexes.appendChild (language_element);
773
774 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexLanguage' element
775 ArrayList displayItem_list = XMLTools.getNamedElementList (index_sub_child,
776 StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR);
777 if (displayItem_list == null) {
778 // there is no display item for this element
779 continue;
780 }
781 for (int j=0; j<displayItem_list.size (); j++) {
782 Element item = (Element)displayItem_list.get (j);
783 String text = XMLTools.getNodeText (item);
784 String lang = item.getAttribute (StaticStrings.LANG_ATTRIBUTE);
785
786 //If there is nothing to display, don't bother creating the element
787 if (text == "") {
788 continue;
789 }
790 Element collectionmetadata = to.createElement (StaticStrings.COLLECTIONMETADATA_ELEMENT);
791 collectionmetadata.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
792 collectionmetadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
793 collectionmetadata.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, lang);
794 XMLTools.setNodeText (collectionmetadata, text);
795
796 appendProperly (toElement, collectionmetadata);
797 }
798 }
799 toElement.appendChild (language_indexes);
800 }
801 // Handling both searchType and search format statement
802 static private void doSearchFormat (Document to, Node searchNode) {
803 //There are two elements called <format> in <search>: one is for searchType; another is for format statement
804 NodeList format_children = ((Element)searchNode).getElementsByTagName (StaticStrings.FORMAT_STR);
805 int format_nodes = format_children.getLength ();
806 if (format_nodes < 1) {
807 return;
808 }
809 Element format = null;
810 Element search_type = null;
811 for(int i=0; i<format_nodes; i++) {
812 Node e = format_children.item (i);
813 if (e.hasAttributes () == false) {
814 //The format element for format statement has no any attribute
815 format = (Element)e;
816 }
817 else if (((Element)e).getAttribute (StaticStrings.NAME_ATTRIBUTE).equals(StaticStrings.SEARCHTYPE_ELEMENT)) {
818 search_type = (Element)e;
819 }
820 }
821 //format statement for search
822 if (format != null) {
823 (to.getDocumentElement ()).appendChild (doFormat(to, format, StaticStrings.SEARCH_STR));
824 }
825 // searchType in search
826 if(search_type != null) {
827 String searchtype_str = XMLTools.getNodeText(search_type);
828
829 Element search_type_element = to.createElement (StaticStrings.FORMAT_STR);
830 search_type_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);
831 XMLTools.setNodeText(search_type_element, searchtype_str);
832
833
834 appendProperly (to.getDocumentElement (), search_type_element);
835 }
836 }
837 // Handling defaultIndexLanguage and languageMetadata in collectionConfig.xml ('elementNameFrom'); in the internal structure, they are called 'DefaultLanguage' and 'LanguageMetadata' ('elementNameTo') respectively.
838 // Converting from collectionConfig.xml to the internal xml structure.
839 static private void doLanguageMetadata (Document to, Node searchNode) {
840 Element toElement = to.getDocumentElement ();
841 String elementNameFrom = StaticStrings.LANGUAGE_METADATA_ELEMENT_STR;
842 String elementNameTo = StaticStrings.LANGUAGE_METADATA_ELEMENT;
843 Node from_element = XMLTools.getChildByTagName (searchNode, elementNameFrom);
844 if (from_element == null) {
845 return; // such an element not found
846 }
847
848 Element to_element = to.createElement (elementNameTo);
849
850 String name_str = ((Element)from_element).getAttribute (StaticStrings.NAME_ATTRIBUTE);
851 if (name_str.indexOf (StaticStrings.NS_SEP) == -1) {
852 name_str = StaticStrings.EXTRACTED_NAMESPACE + name_str;
853 }
854 to_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
855 to_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
856
857 toElement.appendChild (to_element);
858 }
859 static private void doReplaceListRef (Document to, Element from) {
860 Element toElement = to.getDocumentElement ();
861
862 Node replace_element = XMLTools.getChildByTagName (from, StaticStrings.REPLACELISTREF_STR);
863 if (replace_element == null) {
864 return; // such an element not found
865 }
866
867 Element to_element = XMLTools.duplicateElement (to, (Element)replace_element, true);
868 toElement.appendChild (to_element);
869 }
870 static private void convertReplaceListRef (Document from, Document to) {
871 Element toElement = to.getDocumentElement ();
872
873 Node replace_element = XMLTools.getChildByTagName (from.getDocumentElement (), StaticStrings.REPLACELISTREF_STR);
874 if (replace_element == null) {
875 return; // such an element not found
876 }
877
878 Element to_element = XMLTools.duplicateElement (to, (Element)replace_element, true);
879 toElement.appendChild (to_element);
880 }
881 static private void doOAIElement (Document to, Element from) {
882 Element toElement = to.getDocumentElement ();
883
884 Node oai_element = XMLTools.getChildByTagName (from, StaticStrings.OAI_ELEMENT);
885 if (oai_element == null) {
886 return; // such an element not found
887 }
888
889 Element to_element = XMLTools.duplicateElement (to, (Element)oai_element, true);
890 toElement.appendChild (to_element);
891 }
892 static private void convertOAIElement (Document from, Document to) {
893 Element toElement = to.getDocumentElement ();
894
895 Node oai_element = XMLTools.getChildByTagName (from.getDocumentElement (), StaticStrings.OAI_ELEMENT);
896 if (oai_element == null) {
897 return; // such an element not found
898 }
899
900 Element to_element = XMLTools.duplicateElement (to, (Element)oai_element, true);
901 toElement.appendChild (to_element);
902 }
903 static private void doDefaultIndexLanguage (Document to, Node searchNode) {
904 Element toElement = to.getDocumentElement ();
905 String elementNameFrom = StaticStrings.LANGUAGE_DEFAULT_INDEX_ELEMENT;
906 String elementNameTo = StaticStrings.LANGUAGE_DEFAULT_ELEMENT;
907 Node from_element = XMLTools.getChildByTagName (searchNode, elementNameFrom);
908 if (from_element == null) {
909 return; // such an element not found
910 }
911
912 Element to_element = to.createElement (elementNameTo);
913
914 String name_str = ((Element)from_element).getAttribute (StaticStrings.NAME_ATTRIBUTE);
915 to_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
916 to_element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
917
918 toElement.appendChild (to_element);
919 }
920
921 //Handle 'indexOption' (i.e. casefold, stem etc). In the internal structure, the element is called 'IndexOption'
922 static private void doIndexOption (Document to, Node searchNode) {
923 Element toElement = to.getDocumentElement ();
924 Node index_option_node = XMLTools.getChildByTagName (searchNode, StaticStrings.INDEXOPTION_STR);
925 if (index_option_node == null) {
926 return;
927 }
928 NodeList option_children = ((Element)index_option_node).getElementsByTagName (StaticStrings.OPTION_STR);
929 int option_nodes = option_children.getLength ();
930
931 // for lucene, there is no 'indexOption'. We build a default 'indexOption' and 'assigned=false' in case the user switches to mg or mgpp
932 if (option_nodes < 1) {
933 Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
934 index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
935 index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.INDEXOPTIONS_STR);
936 String[] option_str =
937 { StaticStrings.CASEFOLD_OPTION_STR, StaticStrings.STEM_OPTION_STR };
938 for (int i=0; i<option_str.length; i++) {
939 Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
940 option_element.setAttribute (StaticStrings.NAME_STR, option_str[i]);
941 index_option.appendChild (option_element);
942 }
943 appendProperly (toElement, index_option);
944 return;
945 }
946
947 Element index_option = to.createElement (StaticStrings.INDEXOPTIONS_ELEMENT);
948 index_option.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
949 index_option.setAttribute (StaticStrings.NAME_STR, StaticStrings.INDEXOPTIONS_STR);
950
951 for (int i=0; i<option_nodes; i++) {
952 String option_str = ((Element)option_children.item (i)).getAttribute (StaticStrings.NAME_ATTRIBUTE);
953 Element option_element = to.createElement (StaticStrings.OPTION_ELEMENT);
954 option_element.setAttribute (StaticStrings.NAME_STR, option_str);
955 index_option.appendChild (option_element);
956 }
957 appendProperly (toElement, index_option);
958 }
959
960 static private Element doBuildType (Document to, String att_value) {
961
962 //construct 'BuildType' element
963 Element element = to.createElement (StaticStrings.BUILDTYPE_ELEMENT);
964 element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.BUILDTYPE_STR);
965 element.setAttribute (StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR);
966 element.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
967 element.setAttribute (StaticStrings.SPECIAL_ATTRIBUTE, StaticStrings.TRUE_STR);
968
969 XMLTools.setNodeText (element, att_value);
970
971 return element;
972 }
973
974 // Convert 'description', 'smallicon' etc.
975 static private void convertDisplayItemList (Document from, Document to) {
976 Element displayItemList = to.createElement (StaticStrings.DISPLAYITEMLIST_STR);
977 Element destination = to.getDocumentElement ();
978
979 String []att_values =
980 {StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR,
981 StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR,
982 StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR,
983 StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR};
984
985 String []map_attrs =
986 {StaticStrings.DESCRIPTION_STR,
987 StaticStrings.SMALLICON_STR,
988 StaticStrings.ICON_STR,
989 StaticStrings.NAME_STR};
990
991 for (int i=0; i<att_values.length; i++) {
992
993 //dOc
994 ArrayList e_list = XMLTools.getNamedElementList (from.getDocumentElement (),
995 StaticStrings.COLLECTIONMETADATA_ELEMENT,
996 StaticStrings.NAME_ATTRIBUTE, att_values[i]);
997 // if such elements don't exist, don't bother
998 if (e_list == null) {
999 continue;
1000 }
1001 for (int j=0; j<e_list.size (); j++) {
1002 Element e = (Element)e_list.get (j);
1003 if (e.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1004 continue;
1005 }
1006 String text = XMLTools.getNodeText (e);
1007 String lang = e.getAttribute (StaticStrings.LANGUAGE_ATTRIBUTE);
1008
1009 Element displayItem = constructElement (StaticStrings.DISPLAYITEM_STR, map_attrs[i],
1010 StaticStrings.LANG_STR, lang, text, to);
1011 displayItemList.appendChild (displayItem);
1012 }
1013
1014 }
1015 destination.appendChild (displayItemList);
1016 }
1017 // This method creates a DisplayItem element of the type of 'to' by using the ingredients from the element 'e'
1018 static private Element constructDisplayItem (Element e, Document to) {
1019 String lang_string = e.getAttribute (StaticStrings.LANGUAGE_ATTRIBUTE);
1020 String text = XMLTools.getNodeText (e);
1021 Element displayItem = to.createElement (StaticStrings.DISPLAYITEM_STR);
1022 displayItem.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_ATTRIBUTE);
1023 displayItem.setAttribute (StaticStrings.LANG_STR, lang_string);
1024 XMLTools.setNodeText (displayItem, text);
1025 return displayItem;
1026 }
1027 static private void convertMetadataList (Document from, Document to) {
1028 Element metadataList = to.createElement (StaticStrings.METADATALIST_STR);
1029 Element destination = to.getDocumentElement ();
1030
1031 String []ele_names =
1032 {StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT,
1033 StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT,
1034 StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT};
1035 String []att_names =
1036 {StaticStrings.COLLECTIONMETADATA_CREATOR_STR,
1037 StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR,
1038 StaticStrings.COLLECTIONMETADATA_PUBLIC_STR};
1039 for (int i=0; i<ele_names.length; i++) {
1040 Element e = XMLTools.getNamedElement (from.getDocumentElement (),
1041 ele_names[i], StaticStrings.NAME_ATTRIBUTE, att_names[i]);
1042 if (e == null) {
1043 continue;
1044 }
1045 String text = XMLTools.getNodeText (e);
1046 Element metadata = to.createElement (StaticStrings.METADATA_STR);
1047 metadata.setAttribute (StaticStrings.NAME_ATTRIBUTE, att_names[i]);
1048 metadata.setAttribute (StaticStrings.LANG_STR, StaticStrings.ENGLISH_LANGUAGE_STR);
1049 XMLTools.setNodeText (metadata, text);
1050 metadataList.appendChild (metadata);
1051 }
1052
1053 destination.appendChild (metadataList);
1054 }
1055 // This method creates an element with the name 'element_name' of the type of 'to' by using the other three strings
1056 static private Element constructElement (String element_name, String name_value, String lang_att, String lang_value, String text, Document to) {
1057 Element e = to.createElement (element_name);
1058 e.setAttribute (StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
1059 e.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_value);
1060 e.setAttribute (lang_att, lang_value);
1061 XMLTools.setNodeText (e, text);
1062
1063 return e;
1064 }
1065 // Convert classify in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to)
1066 static private void convertClassifier (Document from, Document to) {
1067 Element browse_element = to.createElement (StaticStrings.BROWSE_STR);
1068 NodeList children = from.getDocumentElement ().getElementsByTagName (StaticStrings.CLASSIFY_ELEMENT);
1069
1070 int num_children = (children == null)? 0 : children.getLength ();
1071
1072 if (num_children == 0) {
1073 return ;
1074 }
1075
1076 for (int i=0; i<num_children; i++) {
1077
1078 Element child = (Element)children.item (i);
1079 if (child.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1080 continue;
1081 }
1082 String str = child.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
1083 Element classifier_element = to.createElement (StaticStrings.CLASSIFIER_STR);
1084 classifier_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, str);
1085
1086 NodeList option_children = child.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
1087 for (int j=0; j<option_children.getLength (); j++) {
1088 Element el = (Element)option_children.item (j);
1089 if (el.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1090 continue;
1091 }
1092 String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1093 String value_str = XMLTools.getNodeText (el);
1094
1095
1096 if (name_str == null && value_str == null) {
1097 continue;
1098 }
1099 Element option_element = to.createElement (StaticStrings.OPTION_STR);
1100 if (name_str != null && name_str.equals (StaticStrings.METADATA_STR)) {
1101
1102 // 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.
1103 String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
1104 value_str = "";
1105 for (int k=0; k<=values.length-1; k++) {
1106 if(values[k].startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1107 values[k] = values[k].substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1108 }
1109 else {
1110 MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (values[k]);
1111 if (metadata_element != null) {
1112 values[k] = metadata_element.getFullName ();
1113 }
1114 }
1115 if (k < values.length-1) {
1116 value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
1117 } else {
1118 value_str = value_str + values[k];
1119 }
1120 }
1121 }
1122
1123 if (!name_str.equals ("")) {
1124 if (!name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
1125 name_str = StaticStrings.MINUS_CHARACTER + name_str;
1126 }
1127 option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
1128 }
1129
1130 if (!value_str.equals ("")) {
1131 option_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, value_str);
1132 }
1133
1134 classifier_element.appendChild (option_element);
1135 }
1136
1137 //format element for this classifier
1138 Element e = (Element)XMLTools.getChildByTagName (child, StaticStrings.FORMAT_STR);
1139
1140 if (e != null) {
1141 classifier_element.appendChild (convertFormat(to, e));
1142 }
1143 browse_element.appendChild (classifier_element);
1144 }
1145
1146 //convert default classifier format
1147 Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
1148 StaticStrings.NAME_ATTRIBUTE, StaticStrings.BROWSE_STR);
1149 browse_element.appendChild (convertFormat(to, e));
1150
1151 to.getDocumentElement ().appendChild (browse_element);
1152 }
1153 static private Element convertFormat(Document to, Element e) {
1154 String format_str = XMLTools.getNodeText(e);
1155 Element format = to.createElement (StaticStrings.FORMAT_STR);
1156 //XMLTools.copyAllChildren (format, e);
1157 XMLTools.setNodeText(format, format_str);
1158 return format;
1159 }
1160 //convert format statement for search
1161 static private void convertSearchFormat (Document from, Document to) {
1162 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1163 Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
1164 StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCH_STR);
1165
1166 search.appendChild (convertFormat(to, e));
1167
1168 }
1169 //convert format statement for display of the documents
1170 static private void convertDisplayFormat (Document from, Document to) {
1171 Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
1172 StaticStrings.NAME_ATTRIBUTE, StaticStrings.DISPLAY_STR);
1173 if (e == null) {
1174 return;
1175 }
1176 Element display = to.createElement (StaticStrings.DISPLAY_STR);
1177 display.appendChild (convertFormat(to, e));
1178 to.getDocumentElement ().appendChild (display);
1179 }
1180 // Convert plugins in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to)
1181 static private void convertPlugin (Document from, Document to) {
1182 Element import_element = to.createElement (StaticStrings.IMPORT_STR);
1183 Element plugin_list_element = to.createElement (StaticStrings.PLUGINLIST_STR);
1184
1185 NodeList children = from.getDocumentElement ().getElementsByTagName (StaticStrings.PLUGIN_ELEMENT);
1186 int num_children = (children == null)? 0 : children.getLength ();
1187 if (num_children == 0) {
1188 return ;
1189 }
1190
1191 for (int i=0; i<num_children; i++) {
1192
1193 Element child = (Element)children.item (i);
1194 if (child.getAttribute (StaticStrings.SEPARATOR_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
1195 continue;
1196 }
1197 if (child.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1198 continue;
1199 }
1200
1201 String str = child.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
1202 Element plugin_element = to.createElement (StaticStrings.PLUGIN_STR);
1203 plugin_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, str);
1204
1205 NodeList option_children = child.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
1206 for (int j=0; j<option_children.getLength (); j++) {
1207 Element el = (Element)option_children.item (j);
1208 if(!el.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
1209 continue;
1210 }
1211 String name_str = el.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1212 String value_str = XMLTools.getNodeText (el);
1213
1214
1215 if (name_str == null && value_str == null) {
1216 continue;
1217 }
1218 Element option_element = to.createElement (StaticStrings.OPTION_STR);
1219 if (name_str != null && name_str.equals (StaticStrings.METADATA_STR)) {
1220
1221 // 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.
1222 String[] values = value_str.split (StaticStrings.COMMA_CHARACTER);
1223 value_str = "";
1224 for (int k=0; k<=values.length-1; k++) {
1225 if(values[k].startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1226 values[k] = values[k].substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1227 }
1228
1229 if (k < values.length-1) {
1230 value_str = value_str + values[k] + StaticStrings.COMMA_CHARACTER;
1231 } else {
1232 value_str = value_str + values[k];
1233 }
1234 }
1235 }
1236
1237 if (!name_str.equals ("")) {
1238 if (!name_str.startsWith (StaticStrings.MINUS_CHARACTER)) {
1239 name_str = StaticStrings.MINUS_CHARACTER + name_str;
1240 }
1241 option_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
1242 }
1243
1244 if (!value_str.equals ("")) {
1245 option_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, value_str);
1246 }
1247
1248 plugin_element.appendChild (option_element);
1249 }//for loop ends
1250
1251 plugin_list_element.appendChild (plugin_element);
1252 }//for loop ends
1253
1254 import_element.appendChild (plugin_list_element);
1255
1256 //do the plugout element (used by building flax collections)
1257 Node plugout = XMLTools.getChildByTagNameIndexed (from.getDocumentElement (), PLUGOUT_ELEMENT, 0);
1258 if (plugout != null) {
1259 Element to_element = XMLTools.duplicateElement (to, (Element)plugout, true);
1260 import_element.appendChild (to_element);
1261 }
1262
1263 to.getDocumentElement ().appendChild (import_element);
1264 }
1265
1266 //Handle 'searchType' of collectionConfig.xml. In the internal structure, its also called 'searchType', eg. plain, form
1267 static private void convertSearchType (Document from, Document to) {
1268 Element e = XMLTools.getNamedElement (from.getDocumentElement (), StaticStrings.FORMAT_STR,
1269 StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);//searchType
1270
1271 if (e == null) {
1272 return;
1273 }
1274 Element search_type_element = to.createElement (StaticStrings.FORMAT_STR);
1275
1276 // String searchtype_str = e.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
1277 // search_type_element.setAttribute (StaticStrings.VALUE_ATTRIBUTE, searchtype_str);
1278 String searchtype_str = XMLTools.getNodeText(e);
1279 XMLTools.setNodeText(search_type_element, searchtype_str);
1280
1281 search_type_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT);
1282 //Get the 'search' element from 'to'
1283 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1284 search.appendChild (search_type_element);
1285 }
1286
1287 static private void convertBuildType (Document from, Document to) {
1288 Element e = XMLTools.getNamedElement (from.getDocumentElement (),
1289 StaticStrings.BUILDTYPE_ELEMENT,
1290 StaticStrings.NAME_ATTRIBUTE, StaticStrings.BUILDTYPE_STR);
1291 if (e == null) {
1292 return;
1293 }
1294 String indexer = XMLTools.getNodeText (e);
1295 Element search = to.createElement (StaticStrings.SEARCH_STR);
1296 search.setAttribute (StaticStrings.TYPE_ATTRIBUTE, indexer);
1297 to.getDocumentElement ().appendChild (search);
1298 }
1299 static private void convertDefaultIndex (Document from, Document to, Element search) {
1300 Element source = from.getDocumentElement ();
1301
1302 Element default_index_element = (Element)XMLTools.getChildByTagName (source, StaticStrings.INDEX_DEFAULT_ELEMENT);
1303 if (default_index_element == null) {
1304 return;
1305 }
1306
1307 String indexer = search.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
1308 String level_str = default_index_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE);
1309 // Debugging purposes
1310 if (level_str.equals ("") && indexer.equals (StaticStrings.MG_STR) ) {
1311 System.out.println ("Bug: DefaultIndex should have its level attribute not empty.");
1312 }
1313
1314 NodeList content_elements = default_index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
1315 int content_elements_length = content_elements.getLength ();
1316
1317 // Don't output anything if no indexes are set
1318 if(content_elements_length == 0) {
1319 return ;//
1320 }
1321
1322 String index_str = "";
1323
1324 if (indexer.equals (StaticStrings.MG_STR)) {
1325 //combine level with indexes
1326 index_str = level_str + StaticStrings.COLON_CHARACTER;
1327 }
1328 else { //for mgpp/lucene, just take index
1329 //do nothing
1330 }
1331
1332 for(int k = 0; k < content_elements_length; k++) {
1333 Element content_element = (Element) content_elements.item (k);
1334 if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1335 continue;
1336 }
1337 String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1338
1339 if(name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1340 name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1341 }
1342
1343 index_str = index_str + name_str;
1344
1345 // Make it comma separated string
1346 if(k < content_elements_length - 1) {
1347 index_str = index_str + StaticStrings.COMMA_CHARACTER;
1348 }
1349 content_element = null;
1350 }//for loop ends
1351
1352
1353 Element default_index = to.createElement (StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE);
1354 default_index.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_str);
1355 search.appendChild (default_index);
1356
1357 }
1358 static private void convertSubcollection (Document from, Document to) {
1359 Element source = from.getDocumentElement ();
1360 //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
1361 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1362
1363 // Get the Subcollection element from the internal structure
1364 NodeList subcollection_elements = source.getElementsByTagName (StaticStrings.SUBCOLLECTION_ELEMENT);
1365 if (subcollection_elements == null) {
1366 return;
1367 }
1368 int subcollection_elements_length = subcollection_elements.getLength ();
1369
1370 if (subcollection_elements_length == 0) { // no
1371 return ;
1372 }
1373
1374 for(int j = 0; j < subcollection_elements_length; j++) {
1375
1376 Element e = (Element) subcollection_elements.item (j);
1377 if (e.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1378 continue;
1379 }
1380 String content = e.getAttribute (StaticStrings.CONTENT_ATTRIBUTE);
1381 String name = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1382 String options = e.getAttribute (StaticStrings.OPTIONS_ATTRIBUTE);
1383 String type = e.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
1384 String text = XMLTools.getNodeText (e);
1385
1386 String filter = "";
1387 if (type.equals (StaticStrings.EXCLUDE_STR)) {
1388 filter = StaticStrings.EXCLAMATION_CHARACTER;
1389 }
1390
1391 if(content.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1392 content = content.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1393 }
1394 filter = filter + content + StaticStrings.SEPARATOR_CHARACTER + text;
1395 if (options != null && options != "") {
1396 filter = filter + StaticStrings.SEPARATOR_CHARACTER + options;
1397 }
1398 Element subcollection = to.createElement (StaticStrings.SUBCOLLECTION_STR);
1399 subcollection.setAttribute (StaticStrings.FILTER_ATTRIBUTE, filter);
1400 subcollection.setAttribute (StaticStrings.NAME_ATTRIBUTE, name);
1401
1402 search.appendChild (subcollection);
1403 }
1404 }
1405 static private void convertSubcollectionIndexes (Document from, Document to) {
1406 Element source = from.getDocumentElement ();
1407 //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
1408 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1409
1410 // Get the SubcollectionIndexes element from the internal structure
1411 Element subcollection_indexes = (Element)XMLTools.getChildByTagName (source, StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT);
1412 if (subcollection_indexes == null) {
1413 return;
1414 }
1415 NodeList index_elements = subcollection_indexes.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
1416 int index_elements_length = index_elements.getLength ();
1417
1418 if (index_elements_length == 0) { // no indexes
1419 return ;
1420 }
1421
1422 for(int j = 0; j < index_elements_length; j++) {
1423 Element index_element = (Element) index_elements.item (j);
1424 if (index_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1425 continue;
1426 }
1427
1428 Element index = to.createElement (StaticStrings.SUBCOLLECTION_INDEX_ELEMENT);
1429
1430 String index_value = "";
1431
1432 NodeList content_elements = index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
1433 int content_elements_length = content_elements.getLength ();
1434
1435 for(int k = 0; k < content_elements_length; k++) {
1436 Element content_element = (Element) content_elements.item (k);
1437 if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1438 continue;
1439 }
1440 String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1441 index_value += name_str;
1442 // Make it comma separated string
1443 if(k < content_elements_length - 1) {
1444 index_value += StaticStrings.COMMA_CHARACTER;
1445 }
1446 content_element = null;
1447 }//for loop ends
1448
1449 index.setAttribute (StaticStrings.NAME_ATTRIBUTE, index_value);
1450
1451 // Now constructing 'displayItem' element for this 'indexSubcollection' element
1452 // from the collectionmetadata element
1453 ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
1454 StaticStrings.COLLECTIONMETADATA_ELEMENT,
1455 StaticStrings.NAME_ATTRIBUTE, index_value);
1456
1457 if (collectionmetadata_list != null) {
1458
1459 for(int k = 0; k < collectionmetadata_list.size (); k++) {
1460 Element collectionmetadata = (Element)collectionmetadata_list.get (k);
1461 if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1462 continue;
1463 }
1464 Element displayItem = constructDisplayItem (collectionmetadata, to);
1465 index.appendChild (displayItem);
1466 }
1467 }
1468
1469 search.appendChild (index);
1470
1471 } //for loop ends
1472 }
1473
1474 static private void convertLanguages (Document from, Document to) {
1475 Element source = from.getDocumentElement ();
1476 //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
1477 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1478
1479 // Get the Languages element from the internal structure
1480 Element languages = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGES_ELEMENT);
1481 if (languages == null) {
1482 return;
1483 }
1484 NodeList language_elements = languages.getElementsByTagName (StaticStrings.LANGUAGE_ELEMENT);
1485 int language_elements_length = language_elements.getLength ();
1486
1487 if (language_elements_length == 0) {
1488 return ;
1489 }
1490
1491 for(int j = 0; j < language_elements_length; j++) {
1492 Element element = (Element) language_elements.item (j);
1493 if (element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1494 continue;
1495 }
1496
1497 // Create indexLanguage element
1498 Element index_language = to.createElement (StaticStrings.LANGUAGE_INDEX_ELEMENT);
1499
1500 String name_str = element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1501 index_language.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
1502
1503 // Now constructing 'displayItem' element for this 'indexLanguage' element
1504 // from the collectionmetadata element
1505 ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
1506 StaticStrings.COLLECTIONMETADATA_ELEMENT,
1507 StaticStrings.NAME_ATTRIBUTE, name_str);
1508
1509 if (collectionmetadata_list != null) {
1510
1511 for(int k = 0; k < collectionmetadata_list.size (); k++) {
1512 Element collectionmetadata = (Element)collectionmetadata_list.get (k);
1513 if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1514 continue;
1515 }
1516 Element displayItem = constructDisplayItem (collectionmetadata, to);
1517 index_language.appendChild (displayItem);
1518 }
1519 }
1520
1521 search.appendChild (index_language);
1522
1523 } //for loop ends
1524
1525 // Convert DefaultLanguage
1526 // Get the DefaultLanguage element from the internal structure
1527 Element default_language = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGE_DEFAULT_ELEMENT);
1528 if(default_language != null) {
1529 String lang_name = default_language.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1530 Element default_index_language = to.createElement (StaticStrings.LANGUAGE_DEFAULT_INDEX_ELEMENT);
1531 default_index_language.setAttribute (StaticStrings.NAME_ATTRIBUTE, lang_name);
1532 search.appendChild (default_index_language);
1533 }
1534 // Convert LanguageMetadata
1535 // Get the LanguageMetadata element from the internal structure
1536 Element language_metadata = (Element)XMLTools.getChildByTagName (source, StaticStrings.LANGUAGE_METADATA_ELEMENT);
1537 if(language_metadata != null) {
1538 String meta_name = language_metadata.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1539 Element language_meta = to.createElement (StaticStrings.LANGUAGE_METADATA_ELEMENT_STR);
1540 if(meta_name.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1541 meta_name = meta_name.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1542 }
1543 language_meta.setAttribute (StaticStrings.NAME_ATTRIBUTE, meta_name);
1544 search.appendChild (language_meta);
1545 }
1546 }
1547
1548 //convert indexes and their displayItems, which go in 'search' element in collectionConfig.xml
1549 //parameter 'to' is the document to be saved as collectionConfig.xml
1550 //parameter 'from' is the internal xml structure
1551 static private void convertIndex (Document from, Document to) {
1552 Element source = from.getDocumentElement ();
1553 //Get the 'search' element from 'to' which has already been created in 'convertBuildType'
1554 Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR);
1555
1556 //THere are two sets of indexes elements, find the one which is assigned 'true'
1557 Element indexes = XMLTools.getNamedElement (source,
1558 StaticStrings.INDEXES_ELEMENT,
1559 StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
1560 if (indexes == null) {
1561 return;
1562 }
1563 NodeList index_elements = indexes.getElementsByTagName (StaticStrings.INDEX_ELEMENT);
1564 int index_elements_length = index_elements.getLength ();
1565
1566 if (index_elements_length == 0) { // no indexes
1567 return ;
1568 }
1569
1570 //find out it's mg or mgpp/lucene
1571 String mg = search.getAttribute (StaticStrings.TYPE_ATTRIBUTE);
1572 boolean mg_indexer = false;
1573 if (mg.equals (StaticStrings.MG_STR)) {
1574 mg_indexer = true;//it's mg, then the level is set as attribute of
1575 }
1576 if (mg_indexer == false) {
1577 // It's mgpp. Construct 'level' and 'defaultLevel' elements separately.
1578 convertLevels (from, to, search);
1579 }
1580
1581 for(int j = 0; j < index_elements_length; j++) {
1582 Element index_element = (Element) index_elements.item (j);
1583 if (index_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1584 continue;
1585 }
1586
1587 Element index_ele = to.createElement (StaticStrings.INDEX_LOW_STR);//index
1588
1589 // Used for creating displayItem for this element 'index_ele' further below
1590 // full_index_names contain 'ex.'
1591 String full_index_name = "";
1592 String level_str = "";
1593
1594 StringBuffer index_value = new StringBuffer ();
1595 if (mg_indexer == true) {
1596 // For mg indexer, there is a 'level' attribute in the index element of the internal structure
1597 // But mgpp/lucene don't
1598 level_str = index_element.getAttribute (StaticStrings.LEVEL_ATTRIBUTE);
1599 if(level_str.length () > 0) {
1600 index_value.append (level_str).append (StaticStrings.COLON_CHARACTER);
1601 //index_value = index_value.StaticStrings.COLON_CHARACTER;
1602 }
1603 }
1604
1605 NodeList content_elements = index_element.getElementsByTagName (StaticStrings.CONTENT_ELEMENT);
1606 int content_elements_length = content_elements.getLength ();
1607
1608 for(int k = 0; k < content_elements_length; k++) {
1609 Element content_element = (Element) content_elements.item (k);
1610 if (content_element.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1611 continue;
1612 }
1613 String name_str = content_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1614
1615 full_index_name = full_index_name + name_str;
1616 if (k < content_elements_length - 1) {
1617 full_index_name = full_index_name + StaticStrings.COMMA_CHARACTER;
1618 }
1619
1620 if(name_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
1621 name_str = name_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
1622 }
1623
1624 index_value.append (name_str);
1625 name_str = null;
1626 // Make it comma separated string
1627 if(k < content_elements_length - 1) {
1628 index_value.append (StaticStrings.COMMA_CHARACTER);
1629 }
1630 content_element = null;
1631 }//for loop ends
1632
1633 String temp_str = index_value.toString ();
1634 index_ele.setAttribute (StaticStrings.NAME_ATTRIBUTE, temp_str);
1635
1636 // Now constructing 'displayItem' element for this 'index_ele' element
1637 // The index names in the collectionmetadata elements in the internal structure are not the names that
1638 // are used in the content elements (i.e. ex.Source or dc.Subject and keywords), but the names that are
1639 // in the configuration files (i.e. Source or dc.Subject)
1640 ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
1641 StaticStrings.COLLECTIONMETADATA_ELEMENT,
1642 StaticStrings.NAME_ATTRIBUTE, temp_str);
1643
1644 if (collectionmetadata_list == null) {
1645 //try the full name, i.e. with 'ex.'
1646 if (mg_indexer == true) {
1647 // but first append level info if we are mg
1648 full_index_name = level_str+StaticStrings.COLON_CHARACTER+full_index_name;
1649 }
1650 collectionmetadata_list = XMLTools.getNamedElementList (source,
1651 StaticStrings.COLLECTIONMETADATA_ELEMENT,
1652 StaticStrings.NAME_ATTRIBUTE, full_index_name);
1653 }
1654
1655 if (collectionmetadata_list != null) {
1656
1657 for(int k = 0; k < collectionmetadata_list.size (); k++) {
1658 Element collectionmetadata = (Element)collectionmetadata_list.get (k);
1659 if (collectionmetadata.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1660 continue;
1661 }
1662 Element displayItem = constructDisplayItem (collectionmetadata, to);
1663
1664 index_ele.appendChild (displayItem);
1665 }
1666 }
1667
1668 search.appendChild (index_ele);
1669
1670 } //for loop ends
1671
1672 //Convert default index
1673 convertDefaultIndex (from, to, search);
1674 convertIndexOptions(from, to, search);
1675 }
1676 // Convert levels for mgpp/lucene. This method is called by converIndex() when mgpp indexer is detected.
1677 static private void convertLevels (Document from, Document to, Element search) {
1678 Element source = from.getDocumentElement ();
1679 Element index_option = XMLTools.getNamedElement (source,
1680 StaticStrings.INDEXOPTIONS_ELEMENT,
1681 StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVELS_STR);
1682 if (index_option == null) {
1683 return;
1684 }
1685 //Debugging purposes
1686 if (index_option.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1687 DebugStream.println ("For mgpp, there should be an IndexOption element for levels which is assigned 'true': possible bug.");
1688 }
1689
1690 NodeList option_elements = index_option.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
1691 int num_elements = option_elements.getLength ();
1692
1693 // Don't output anything if no indexes are set
1694 if(num_elements == 0) {
1695 return ;//
1696 }
1697
1698 for(int k = 0; k < num_elements; k++) {
1699 Element e = (Element) option_elements.item (k);
1700 String name_str = e.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1701 Element level_element = to.createElement (StaticStrings.LEVEL_ELEMENT);
1702 level_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, name_str);
1703
1704 //Now construct displayItem for this level element from collectionmetadata
1705 ArrayList collectionmetadata_list = XMLTools.getNamedElementList (source,
1706 StaticStrings.COLLECTIONMETADATA_ELEMENT,
1707 StaticStrings.NAME_ATTRIBUTE, name_str);
1708
1709 if (collectionmetadata_list != null) {
1710
1711 for(int j = 0; j < collectionmetadata_list.size (); j++) {
1712 Element collectionmetadata = (Element)collectionmetadata_list.get (j);
1713
1714 Element displayItem = constructDisplayItem (collectionmetadata, to);
1715 level_element.appendChild (displayItem);
1716 }
1717 }
1718 search.appendChild (level_element);
1719 }
1720
1721 //Convert default level
1722 Element default_index_option = XMLTools.getNamedElement (source,
1723 StaticStrings.INDEXOPTION_DEFAULT_ELEMENT,
1724 StaticStrings.NAME_ATTRIBUTE, StaticStrings.LEVEL_DEFAULT_STR);
1725 if (default_index_option == null) {
1726 return;
1727 }
1728 Element default_level = to.createElement (StaticStrings.LEVEL_DEFAULT_ELEMENT);
1729 String default_level_str = default_index_option.getAttribute (StaticStrings.VALUE_ATTRIBUTE);
1730 default_level.setAttribute (StaticStrings.NAME_ATTRIBUTE, default_level_str);
1731 search.appendChild (default_level);
1732
1733 }
1734 // Convert indexoptions for mg/mgpp/lucene. This method is called by convertIndex().
1735 static private void convertIndexOptions (Document from, Document to, Element search) {
1736 Element source = from.getDocumentElement ();
1737 Element index_option = XMLTools.getNamedElement (source,
1738 StaticStrings.INDEXOPTIONS_ELEMENT,
1739 StaticStrings.NAME_ATTRIBUTE, StaticStrings.INDEXOPTIONS_STR);
1740 if (index_option == null) {
1741 return;
1742 }
1743 //Debugging purposes
1744 if (index_option.getAttribute (StaticStrings.ASSIGNED_ATTRIBUTE).equals (StaticStrings.FALSE_STR)) {
1745 DebugStream.println ("There should be an IndexOption element which is assigned 'true': possible bug.");
1746 }
1747 Element indexOptionEl = to.createElement(StaticStrings.INDEXOPTION_STR);
1748 NodeList option_elements = index_option.getElementsByTagName (StaticStrings.OPTION_ELEMENT);
1749 int num_elements = option_elements.getLength ();
1750 // Don't output anything if no index
1751 if(num_elements == 0) {
1752 return ;//
1753 }
1754 search.appendChild (indexOptionEl);
1755
1756 for(int k = 0; k < num_elements; k++) {
1757 Element e = (Element) option_elements.item (k);
1758 String name_att = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
1759 Element optionEl = to.createElement(StaticStrings.OPTION_STR);
1760 optionEl.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_att);
1761 indexOptionEl.appendChild(optionEl);
1762 }
1763
1764 }
1765 // Append the element son to the element mother in the appropriate position.
1766 static public void appendProperly (Element mother, Element son) {
1767 if (son == null)
1768 return;
1769
1770 Node reference_node = findInsertionPoint (mother, son);
1771 if(reference_node != null) {
1772 mother.insertBefore (son, reference_node);
1773 }
1774 else {
1775 mother.appendChild (son);
1776 }
1777 }
1778 /** 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.
1779 * @param target_element the command Element to be inserted
1780 * @return the Element which the given command should be inserted before, or null to append to end of list
1781 */
1782 static public Node findInsertionPoint (Element document_element, Element target_element) {
1783 ///ystem.err.println("Find insertion point: " + target_element.getNodeName());
1784 String target_element_name = target_element.getNodeName ();
1785
1786 // Try to find commands with the same tag.
1787 NodeList matching_elements = document_element.getElementsByTagName (target_element_name);
1788 // If we found matching elements, then we have our most likely insertion location, so check within for groupings
1789 if(matching_elements.getLength () != 0) {
1790 ///ystem.err.println("Found matching elements.");
1791 // Only CollectionMeta are grouped.
1792 if(target_element_name.equals (StaticStrings.COLLECTIONMETADATA_ELEMENT)) {
1793 ///ystem.err.println("Dealing with collection metadata");
1794 // 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.
1795 // So if the command to be added is special add it immediately after any other special command
1796 if(target_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
1797 int index = 0;
1798 Element matched_element = (Element) matching_elements.item (index);
1799 Element sibling_element = (Element) matched_element.getNextSibling ();
1800 while(sibling_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
1801 index++;
1802 matched_element = (Element) matching_elements.item (index);
1803 sibling_element = (Element) matched_element.getNextSibling ();
1804 }
1805 if(sibling_element.getNodeName ().equals (CollectionConfiguration.NEWLINE_ELEMENT)) {
1806 Element newline_element = document_element.getOwnerDocument().createElement (CollectionConfiguration.NEWLINE_ELEMENT);
1807 document_element.insertBefore (newline_element, sibling_element);
1808 }
1809 return sibling_element;
1810 }
1811 // Otherwise try to find a matching 'name' and add after the last one in that group.
1812 else {
1813 int index = 0;
1814 target_element_name = target_element.getAttribute (StaticStrings.NAME_ATTRIBUTE);
1815 boolean found = false;
1816 // Skip all of the special metadata
1817 Element matched_element = (Element) matching_elements.item (index);
1818 while(matched_element.getAttribute (StaticStrings.SPECIAL_ATTRIBUTE).equals (StaticStrings.TRUE_STR)) {
1819 index++;
1820 matched_element = (Element) matching_elements.item (index);
1821 }
1822 // Begin search
1823 while(!found && matched_element != null) {
1824 if(matched_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
1825 found = true;
1826 }
1827 else {
1828 index++;
1829 matched_element = (Element) matching_elements.item (index);
1830 }
1831 }
1832 // If we found a match, we need to continue checking until we find the last name match.
1833 if(found) {
1834 index++;
1835 Element previous_sibling = matched_element;
1836 Element sibling_element = (Element) matching_elements.item (index);
1837 while(sibling_element != null && sibling_element.getAttribute (StaticStrings.NAME_ATTRIBUTE).equals (target_element_name)) {
1838 previous_sibling = sibling_element;
1839 index++;
1840 sibling_element = (Element) matching_elements.item (index);
1841 }
1842 // 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!
1843 return previous_sibling.getNextSibling ();
1844 }
1845 // If not found we just add after last metadata element
1846 else {
1847 Element last_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
1848 return last_element.getNextSibling ();
1849 }
1850 }
1851
1852 }
1853 else {
1854 ///ystem.err.println("Not dealing with collection meta.");
1855 Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
1856 // 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)
1857 Node sibling_element = matched_element.getNextSibling ();
1858 if(sibling_element != null && sibling_element.getNodeName ().equals (CollectionConfiguration.NEWLINE_ELEMENT)) {
1859 Element newline_element = document_element.getOwnerDocument().createElement (CollectionConfiguration.NEWLINE_ELEMENT);
1860 document_element.insertBefore (newline_element, sibling_element);
1861 }
1862 return sibling_element; // Note that this may be null
1863 }
1864 }
1865 ///ystem.err.println("No matching elements found.");
1866 // Locate where this command is in the ordering
1867 int command_index = -1;
1868 for(int i = 0; command_index == -1 && i < CollectionConfiguration.COMMAND_ORDER.length; i++) {
1869 if(CollectionConfiguration.COMMAND_ORDER[i].equals (target_element_name)) {
1870 command_index = i;
1871 }
1872 }
1873 ///ystem.err.println("Command index is: " + command_index);
1874 // Now move forward, checking for existing elements in each of the preceeding command orders.
1875 int preceeding_index = command_index - 1;
1876 ///ystem.err.println("Searching before the target command.");
1877 while(preceeding_index >= 0) {
1878 matching_elements = document_element.getElementsByTagName (CollectionConfiguration.COMMAND_ORDER[preceeding_index]);
1879 // If we've found a match
1880 if(matching_elements.getLength () > 0) {
1881 // We add after the last element
1882 Element matched_element = (Element) matching_elements.item (matching_elements.getLength () - 1);
1883 // 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)
1884 Node sibling_element = matched_element.getNextSibling ();
1885 if(sibling_element != null && sibling_element.getNodeName ().equals (CollectionConfiguration.NEWLINE_ELEMENT)) {
1886 Element newline_element = document_element.getOwnerDocument().createElement (CollectionConfiguration.NEWLINE_ELEMENT);
1887 document_element.insertBefore (newline_element, sibling_element);
1888 }
1889 return sibling_element; // Note that this may be null
1890 }
1891 preceeding_index--;
1892 }
1893 // If all that fails, we now move backwards through the commands
1894 int susceeding_index = command_index + 1;
1895 ///ystem.err.println("Searching after the target command.");
1896 while(susceeding_index < CollectionConfiguration.COMMAND_ORDER.length) {
1897 matching_elements = document_element.getElementsByTagName (CollectionConfiguration.COMMAND_ORDER[susceeding_index]);
1898 // If we've found a match
1899 if(matching_elements.getLength () > 0) {
1900 // We add before the first element
1901 Element matched_element = (Element) matching_elements.item (0);
1902 // 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)
1903 Node sibling_element = matched_element.getPreviousSibling ();
1904 if(sibling_element != null && sibling_element.getNodeName ().equals (CollectionConfiguration.NEWLINE_ELEMENT)) {
1905 Element newline_element = document_element.getOwnerDocument().createElement (CollectionConfiguration.NEWLINE_ELEMENT);
1906 document_element.insertBefore (newline_element, sibling_element);
1907 }
1908 return sibling_element; // Note that this may be null
1909 }
1910 susceeding_index++;
1911 }
1912 // Well. Apparently there are no other commands in this collection configuration. So append away...
1913 return null;
1914 }
1915 // From collectionConfig.xml to internal structure:add 'ex.' namespace (if none).
1916 // From internal structure to collectionConfig.xml:always peel off 'ex.' namespace (if any), except for format statement
1917 //This method parses 'xml_file_doc' into 'dOc'
1918 static public void parse(File xml_file, Document dOc) {
1919
1920 Document xml_file_doc = XMLTools.parseXMLFile (xml_file);
1921 Element fromElement = xml_file_doc.getDocumentElement ();
1922 Element toElement = dOc.getDocumentElement ();
1923
1924 // It's deliberately set that 'creator', 'maintainer', and 'public' are only in English (as they are just names).
1925 // So the following ArrayList have only one element.
1926 Node metadataListNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.METADATALIST_STR, 0);
1927 if (metadataListNode != null) {
1928 ArrayList creator = doMetadataList (dOc, metadataListNode, StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT,
1929 StaticStrings.COLLECTIONMETADATA_CREATOR_STR);
1930 ArrayList maintainer = doMetadataList (dOc, metadataListNode,
1931 StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT,
1932 StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR);
1933 ArrayList is_public = doMetadataList (dOc, metadataListNode, StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT,
1934 StaticStrings.COLLECTIONMETADATA_PUBLIC_STR);
1935
1936 appendArrayList (toElement, creator);
1937 appendArrayList (toElement, maintainer);
1938 appendArrayList (toElement, is_public);
1939 }
1940
1941 Node searchNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.SEARCH_STR, 0);
1942 String buildtype_value = ((Element)searchNode).getAttribute (StaticStrings.TYPE_ATTRIBUTE);//might be mg|mgpp|lucene
1943 Element buildtype = doBuildType (dOc, buildtype_value);
1944 appendProperly (toElement, buildtype);
1945
1946
1947 Node importNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.IMPORT_STR, 0);
1948 if (importNode == null) {
1949 System.out.println ("There is no content in the 'import' block.");
1950 }
1951 if (importNode != null) {
1952 //do plugin list nodes
1953 Node pluginListNode = XMLTools.getChildByTagNameIndexed ((Element)importNode, StaticStrings.PLUGINLIST_STR, 0);
1954 if (pluginListNode == null) {
1955 System.out.println ("There is no pluginlist set.");
1956 }
1957 if (pluginListNode != null) {
1958
1959 doPlugin (dOc, pluginListNode);
1960 }
1961
1962 //do the plugout element (used by building flax collections)
1963 Node plugout = XMLTools.getChildByTagNameIndexed ((Element)importNode, PLUGOUT_ELEMENT, 0);
1964 if (plugout != null) {
1965 Element to_element = XMLTools.duplicateElement (dOc, (Element)plugout, true);
1966 toElement.appendChild (to_element);
1967 }
1968 }
1969
1970 Node browseNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.BROWSE_STR, 0);
1971 if (browseNode != null) {
1972 if (browseNode == null) {
1973 System.out.println ("There is no classifier.");
1974 }
1975 doClassifier (dOc, browseNode);
1976 }
1977
1978 Node displayItemListNode = XMLTools.getChildByTagNameIndexed (fromElement, StaticStrings.DISPLAYITEMLIST_STR, 0);
1979 if (displayItemListNode != null) {
1980 ArrayList description = doDisplayItemList (dOc, displayItemListNode, StaticStrings.DESCRIPTION_STR,
1981 StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
1982 ArrayList smallicon = doDisplayItemList (dOc, displayItemListNode, StaticStrings.SMALLICON_STR,
1983 StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
1984 ArrayList icon = doDisplayItemList (dOc, displayItemListNode, StaticStrings.ICON_STR,
1985 StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR);
1986 ArrayList name = doDisplayItemList (dOc, displayItemListNode, StaticStrings.NAME_STR,
1987 StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
1988
1989 appendArrayList (toElement, description);
1990 appendArrayList (toElement, smallicon);
1991 appendArrayList (toElement, icon);
1992 appendArrayList (toElement, name);
1993 }
1994
1995 if (buildtype_value.equalsIgnoreCase ("mg")) {
1996 doMGIndexes (dOc, searchNode);
1997 }
1998 else {
1999 doMGPPIndexes (dOc, searchNode);
2000 }
2001
2002 doDefaultIndex (dOc, searchNode);
2003 //doSearchType (dOc, searchNode);
2004 doDefaultLevel (dOc, searchNode);
2005 doLevel (dOc, searchNode);
2006 doIndexOption (dOc, searchNode);
2007 doSubcollection (dOc, searchNode);
2008 doIndexSubcollection (dOc, searchNode);
2009 doIndexLanguage (dOc, searchNode);
2010 doDefaultIndexLanguage (dOc, searchNode);
2011 doLanguageMetadata (dOc, searchNode);
2012 doSearchFormat (dOc, searchNode);
2013 doDisplayFormat (dOc, fromElement);
2014 doReplaceListRef (dOc, fromElement);
2015 doOAIElement (dOc, fromElement);
2016
2017 }
2018
2019
2020 static public String generateStringVersion(Document doc) {
2021 return XMLTools.xmlNodeToString(doc);
2022 }
2023
2024 static public void save (File collect_config_xml_file, Document doc) {
2025
2026 Document collection_config_xml_document = convertInternalToCollectionConfig (doc);
2027 String[] nonEscapingTagNames = {StaticStrings.FORMAT_STR};
2028 XMLTools.writeXMLFile (collect_config_xml_file, collection_config_xml_document, nonEscapingTagNames);
2029
2030 }
2031
2032 //Convert the internal XML DOM tree (dOc) into that of collectionConfig.xml (skeleton)
2033 static private Document convertInternalToCollectionConfig (Document dOc) {
2034 //first parse an empty skeleton of xml config file
2035 //The aim is to convert the internal structure into this skeleton
2036 Document skeleton = XMLTools.parseXMLFile ("xml/CollectionConfig.xml", true);
2037 //Element internal = dOc.getDocumentElement();
2038 convertMetadataList (dOc, skeleton);
2039 convertDisplayItemList (dOc, skeleton);
2040 convertBuildType (dOc, skeleton);
2041 convertIndex (dOc, skeleton);
2042 convertPlugin (dOc, skeleton);//also do the plugout element
2043 convertClassifier (dOc, skeleton);
2044 convertSubcollectionIndexes (dOc, skeleton);
2045 convertLanguages (dOc, skeleton);
2046 convertSubcollection (dOc, skeleton);
2047 convertSearchType (dOc, skeleton);
2048 convertSearchFormat (dOc, skeleton);
2049 convertDisplayFormat (dOc, skeleton);
2050 convertReplaceListRef (dOc, skeleton);
2051 convertOAIElement(dOc, skeleton);
2052
2053 return skeleton;
2054 }
2055
2056 // Append the elements, which are of Element type, in 'list' to Element 'to'
2057 static private void appendArrayList (Element to, ArrayList list) {
2058 if (list == null) return;
2059
2060 for (int i=0; i<list.size (); i++) {
2061 appendProperly (to, (Element)list.get (i));
2062 }
2063 }
2064
2065
2066
2067}
Note: See TracBrowser for help on using the repository browser.