Changeset 26571 for main/trunk/gli
- Timestamp:
- 2012-12-11T14:30:48+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r26355 r26571 53 53 static final private String PLUGOUT_ELEMENT = "plugout";//used by building flax collections 54 54 55 // a list of all known top level elements 56 static final private String known_element_names_array[] = {StaticStrings.METADATALIST_STR, StaticStrings.DISPLAYITEMLIST_STR, StaticStrings.FORMAT_STR, StaticStrings.SEARCH_STR, StaticStrings.INFODB_STR, StaticStrings.BROWSE_STR, StaticStrings.IMPORT_STR, StaticStrings.DISPLAY_STR, StaticStrings.REPLACELISTREF_STR, StaticStrings.REPLACELIST_STR, StaticStrings.SERVICE_RACK_LIST_ELEMENT}; 57 static final private Set known_element_names = new HashSet(Arrays.asList(known_element_names_array)); 55 // a list of all known top level elements 56 static final private String known_element_names_array[] = { StaticStrings.METADATALIST_STR, StaticStrings.DISPLAYITEMLIST_STR, StaticStrings.FORMAT_STR, StaticStrings.SEARCH_STR, StaticStrings.INFODB_STR, StaticStrings.BROWSE_STR, StaticStrings.IMPORT_STR, StaticStrings.DISPLAY_STR, StaticStrings.REPLACELISTREF_STR, StaticStrings.REPLACELIST_STR, StaticStrings.SERVICE_RACK_LIST_ELEMENT }; 57 static final private Set known_element_names = new HashSet(Arrays.asList(known_element_names_array)); 58 58 59 /** 59 60 * ************************************************************************* 60 * ******************************* The code in this file is used 61 * forgreenstone 3 collection configuration, i.e., read ColletionConfig.xml61 * ******************************* The code in this file is used for 62 * greenstone 3 collection configuration, i.e., read ColletionConfig.xml 62 63 * into the internal DOM tree, and convert the internal DOM tree back to 63 64 * CollectionConfig.xml. … … 175 176 // Handling 'index' element 176 177 index_element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, index_str.substring(0, index_str.indexOf(StaticStrings.COLON_CHARACTER))); 177 178 178 179 index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1); 179 180 } 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 181 //Each index may have a list of comma-separated strings. 182 //split them into 'content' elements in the internal structure 183 StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER); 184 //index_str = ""; 185 while (content_tokenizer.hasMoreTokens()) 186 { 187 // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject. 188 189 Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT); 190 String content_str = content_tokenizer.nextToken(); 191 // Since the contents of indexes have to be certain keywords, or metadata elements, 192 //if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace. 193 if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR))) 194 { 195 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str; 196 197 } 198 199 content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str); 200 index_element.appendChild(content_element); 201 content_element = null; 202 } // while ends 203 204 indexes_element.appendChild(index_element); 205 206 // Handling 'displayItem' elements and Constructing 'collectionmetadata' elements 207 // Use the fully qualified index names 208 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display); 209 appendArrayList(toElement, collectionmetadata_list); 209 210 } //for loop ends 210 211 appendProperly(toElement, indexes_element); … … 269 270 System.err.println("Something is wrong! the index should NOT be level:source tuplets style."); 270 271 index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1); 271 272 272 273 } 273 274 //Each index may have a list of comma-separated strings. … … 281 282 String content_str = content_tokenizer.nextToken(); 282 283 // 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. 283 if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR)))284 { 285 284 if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR))) 285 { 286 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str; 286 287 } 287 288 content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str); … … 338 339 339 340 } 340 static private void doGlobalFormat(Document to, Element from) 341 { 342 // look for a top level format element 343 Element fe = (Element) XMLTools.getChildByTagName(from, StaticStrings.FORMAT_STR); 344 to.getDocumentElement().appendChild(doFormat(to, fe, StaticStrings.GLOBAL_STR)); 345 } 341 342 static private void doGlobalFormat(Document to, Element from) 343 { 344 // look for a top level format element 345 Element fe = (Element) XMLTools.getChildByTagName(from, StaticStrings.FORMAT_STR); 346 to.getDocumentElement().appendChild(doFormat(to, fe, StaticStrings.GLOBAL_STR)); 347 } 348 346 349 static private void doDisplayFormat(Document to, Element from) 347 350 { … … 640 643 { // not an empty format statement 641 644 String gsf_text = XMLTools.xmlNodeToString(format); 642 645 643 646 //We don't want the <format> elements in the string 644 647 int startFormatIndex = gsf_text.indexOf(StaticStrings.FORMAT_START_TAG) + StaticStrings.FORMAT_START_TAG.length(); … … 1003 1006 XMLTools.duplicateElementList(to, toElement, replace_elements, true); 1004 1007 } 1008 1005 1009 // int num_elems = replace_elements.getLength(); 1006 1010 // if (num_elems < 1) … … 1022 1026 XMLTools.duplicateElementList(to, toElement, replace_elements, true); 1023 1027 } 1024 // int num_elems = replace_elements.getLength(); 1025 // if (num_elems < 1) 1026 // { 1027 // return; 1028 // } 1029 // for (int i = 0; i < num_elems; i++) 1030 // { 1031 // Element to_element = XMLTools.duplicateElement(to, (Element) replace_elements.item(i), true); 1032 // toElement.appendChild(to_element); 1033 // } 1034 // } 1035 1036 /* replacelist currently not editable in GLI, just copy it in and back out again */ 1028 1029 // int num_elems = replace_elements.getLength(); 1030 // if (num_elems < 1) 1031 // { 1032 // return; 1033 // } 1034 // for (int i = 0; i < num_elems; i++) 1035 // { 1036 // Element to_element = XMLTools.duplicateElement(to, (Element) replace_elements.item(i), true); 1037 // toElement.appendChild(to_element); 1038 // } 1039 // } 1040 1041 /* 1042 * replacelist currently not editable in GLI, just copy it in and back out 1043 * again 1044 */ 1037 1045 static private void doReplaceList(Document to, Element from) 1038 1046 { … … 1062 1070 toElement.appendChild(to_element); 1063 1071 } 1064 1072 1065 1073 /** 1066 1074 * serviceRackList is currently not editable in GLI - just copy it in from … … 1198 1206 // as displayItems in the collectionConfig.xml than they do in memory 1199 1207 Map attributeMap = new HashMap(4); 1200 attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR, StaticStrings.DESCRIPTION_STR);1201 attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR, StaticStrings.NAME_STR);1202 attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR, StaticStrings.SMALLICON_STR);1203 attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR, StaticStrings.ICON_STR);1208 attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR, StaticStrings.DESCRIPTION_STR); 1209 attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR, StaticStrings.NAME_STR); 1210 attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR, StaticStrings.SMALLICON_STR); 1211 attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR, StaticStrings.ICON_STR); 1204 1212 1205 1213 NodeList e_list = from.getDocumentElement().getElementsByTagName(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1206 1214 // if such elements don't exist, don't bother 1207 if (e_list != null) { 1208 1209 for (int j = 0; j < e_list.getLength(); j++) { 1210 Element e = (Element) e_list.item(j); 1211 if (e.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) { 1212 continue; 1213 } 1214 String text = XMLTools.getNodeText(e); 1215 String lang = e.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE); 1216 String name_value = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 1217 1218 String name_mapping = (String)attributeMap.get(name_value); 1219 if(name_mapping != null) { 1220 name_value = name_mapping; 1221 } 1222 1223 Element displayItem = constructElement(StaticStrings.DISPLAYITEM_STR, name_value, StaticStrings.LANG_STR, lang, text, to); 1224 displayItemList.appendChild(displayItem); 1225 } 1226 1215 if (e_list != null) 1216 { 1217 1218 for (int j = 0; j < e_list.getLength(); j++) 1219 { 1220 Element e = (Element) e_list.item(j); 1221 if (e.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 1222 { 1223 continue; 1224 } 1225 String text = XMLTools.getNodeText(e); 1226 String lang = e.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE); 1227 String name_value = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 1228 1229 String name_mapping = (String) attributeMap.get(name_value); 1230 if (name_mapping != null) 1231 { 1232 name_value = name_mapping; 1233 } 1234 1235 Element displayItem = constructElement(StaticStrings.DISPLAYITEM_STR, name_value, StaticStrings.LANG_STR, lang, text, to); 1236 displayItemList.appendChild(displayItem); 1237 } 1238 1227 1239 } 1228 1240 destination.appendChild(displayItemList); … … 1416 1428 } 1417 1429 1418 1430 // convert global format statement 1419 1431 static private void convertGlobalFormat(Document from, Document to) 1420 1432 { 1421 1422 1423 to.getDocumentElement().appendChild(convertFormat(to, e));1424 1425 } 1426 1433 Element e = XMLTools.getNamedElement(from.getDocumentElement(), StaticStrings.FORMAT_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.GLOBAL_STR); 1434 1435 to.getDocumentElement().appendChild(convertFormat(to, e)); 1436 1437 } 1438 1427 1439 // Convert plugins in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to) 1428 1440 static private void convertPlugin(Document from, Document to) … … 2102 2114 } 2103 2115 2104 // handle top level elements which GLI knows nothing about 2105 // we store them internally in a Unknown element for easy access when 2106 // we write them out. 2107 static private void doUnknownElements(Document to, Element from) { 2108 Element toElement = to.getDocumentElement(); 2109 Element unknownElement = to.createElement(StaticStrings.UNKNOWN_ELEMENT); 2110 toElement.appendChild(unknownElement); 2111 2112 Node child = from.getFirstChild(); 2113 while (child != null) 2114 { 2115 System.err.println("child name=" +child.getNodeName()); 2116 if (child.getNodeType() == Node.ELEMENT_NODE && ! known_element_names.contains(child.getNodeName())) { 2117 unknownElement.appendChild(XMLTools.duplicateElement(to, (Element) child, true)); 2118 } 2119 child = child.getNextSibling(); 2120 } 2121 2122 } 2123 2124 // just copy all children of Unknown element into output doc. 2125 static private void convertUnknownElements(Document from, Document to) { 2126 2127 Element toElement = to.getDocumentElement(); 2128 Node unknown_element = XMLTools.getChildByTagName(from.getDocumentElement(), StaticStrings.UNKNOWN_ELEMENT); 2129 2130 Node child = unknown_element.getFirstChild(); 2131 while (child != null) 2132 { 2133 Element to_element = XMLTools.duplicateElement(to, (Element) child, true); 2134 toElement.appendChild(to_element); 2135 2136 child = child.getNextSibling(); 2137 } 2138 2139 } 2116 // handle top level elements which GLI knows nothing about 2117 // we store them internally in a Unknown element for easy access when 2118 // we write them out. 2119 static private void doUnknownElements(Document to, Element from) 2120 { 2121 Element toElement = to.getDocumentElement(); 2122 Element unknownElement = to.createElement(StaticStrings.UNKNOWN_ELEMENT); 2123 toElement.appendChild(unknownElement); 2124 2125 Node child = from.getFirstChild(); 2126 while (child != null) 2127 { 2128 System.err.println("child name=" + child.getNodeName()); 2129 if (child.getNodeType() == Node.ELEMENT_NODE && !known_element_names.contains(child.getNodeName())) 2130 { 2131 unknownElement.appendChild(XMLTools.duplicateElement(to, (Element) child, true)); 2132 } 2133 child = child.getNextSibling(); 2134 } 2135 2136 } 2137 2138 // just copy all children of Unknown element into output doc. 2139 static private void convertUnknownElements(Document from, Document to) 2140 { 2141 2142 Element toElement = to.getDocumentElement(); 2143 Node unknown_element = XMLTools.getChildByTagName(from.getDocumentElement(), StaticStrings.UNKNOWN_ELEMENT); 2144 2145 Node child = unknown_element.getFirstChild(); 2146 while (child != null) 2147 { 2148 Element to_element = XMLTools.duplicateElement(to, (Element) child, true); 2149 toElement.appendChild(to_element); 2150 2151 child = child.getNextSibling(); 2152 } 2153 2154 } 2140 2155 2141 2156 // Append the element son to the element mother in the appropriate position. … … 2425 2440 { 2426 2441 doMGPPIndexes(dOc, searchNode); 2427 } 2442 } 2428 2443 2429 2444 doDefaultIndex(dOc, searchNode); … … 2443 2458 doReplaceList(dOc, fromElement); 2444 2459 doServiceRackList(dOc, fromElement); 2445 doUnknownElements(dOc, fromElement); 2460 doUnknownElements(dOc, fromElement); 2446 2461 // the official displayItems in the displayItemList element have already been handled above 2447 2462 // and created as collectionmetadata elements in the dOc object … … 2449 2464 NodeList collectionMetadataList = dOc.getDocumentElement().getElementsByTagName(StaticStrings.COLLECTIONMETADATA_ELEMENT); 2450 2465 Set setOfUniqueColMetaNames = new HashSet(); 2451 for(int i = 0; i < collectionMetadataList.getLength(); i++) { 2452 Element colMeta = (Element)collectionMetadataList.item(i); 2453 String name = colMeta.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2454 setOfUniqueColMetaNames.add(name); 2466 for (int i = 0; i < collectionMetadataList.getLength(); i++) 2467 { 2468 Element colMeta = (Element) collectionMetadataList.item(i); 2469 String name = colMeta.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2470 setOfUniqueColMetaNames.add(name); 2455 2471 } 2456 2472 2457 2473 if (displayItemListNode != null) 2458 2474 { 2459 NodeList nl = ((Element)displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR); 2460 2461 // make a list of all unique attribute names that are specifically not 2462 // description, smallicon, icon and name, since these are already processed above 2463 Set setOfUniqueDisplayItemNames = new LinkedHashSet(); 2464 for(int i = 0; i < nl.getLength(); i++) { 2465 Element displayItem = (Element)nl.item(i); 2466 String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2467 2468 if(name.equals("")) continue; // no name attribute 2469 if(setOfUniqueColMetaNames.contains(name)) continue; 2470 2471 if(name.equals(StaticStrings.DESCRIPTION_STR)) continue; 2472 if(name.equals(StaticStrings.SMALLICON_STR)) continue; 2473 if(name.equals(StaticStrings.ICON_STR)) continue; 2474 if(name.equals(StaticStrings.NAME_STR)) continue; 2475 // don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title 2476 if(name.indexOf(":") != -1) continue; 2477 2478 // otherwise 2479 setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names 2480 } 2481 2482 Iterator i = setOfUniqueDisplayItemNames.iterator(); 2483 while (i.hasNext()) { 2484 String displayItemName = (String)i.next(); 2485 2486 ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName); 2487 appendArrayList(toElement, custom_displayItem); 2488 } 2475 NodeList nl = ((Element) displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR); 2476 2477 // make a list of all unique attribute names that are specifically not 2478 // description, smallicon, icon and name, since these are already processed above 2479 Set setOfUniqueDisplayItemNames = new LinkedHashSet(); 2480 for (int i = 0; i < nl.getLength(); i++) 2481 { 2482 Element displayItem = (Element) nl.item(i); 2483 String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2484 2485 if (name.equals("")) 2486 continue; // no name attribute 2487 if (setOfUniqueColMetaNames.contains(name)) 2488 continue; 2489 2490 if (name.equals(StaticStrings.DESCRIPTION_STR)) 2491 continue; 2492 if (name.equals(StaticStrings.SMALLICON_STR)) 2493 continue; 2494 if (name.equals(StaticStrings.ICON_STR)) 2495 continue; 2496 if (name.equals(StaticStrings.NAME_STR)) 2497 continue; 2498 // don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title 2499 if (name.indexOf(":") != -1) 2500 continue; 2501 2502 // otherwise 2503 setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names 2504 } 2505 2506 Iterator i = setOfUniqueDisplayItemNames.iterator(); 2507 while (i.hasNext()) 2508 { 2509 String displayItemName = (String) i.next(); 2510 2511 ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName); 2512 appendArrayList(toElement, custom_displayItem); 2513 } 2489 2514 } 2490 2515 … … 2508 2533 //first parse an empty skeleton of xml config file 2509 2534 //The aim is to convert the internal structure into this skeleton 2510 2535 // This skeleton just has the CollectionConfig element and nothing else 2511 2536 Document skeleton = XMLTools.parseXMLFile("xml/CollectionConfig.xml", true); 2512 2537 //Element internal = dOc.getDocumentElement();
Note:
See TracChangeset
for help on using the changeset viewer.