Changeset 29221 for main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
- Timestamp:
- 2014-08-20T19:57:04+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r29177 r29221 376 376 } 377 377 378 //This processes <sort> and <facet> subelements of <search> for a solr collection 379 // Note that GLI at present does not allow the user to set or modify the solr-specific elements 380 // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such 381 // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there. 382 static private void doSolrFacetsAndSorts(Document to, Node searchNode) 383 { 384 Element toElement = to.getDocumentElement(); 385 Element solr_element = to.createElement(StaticStrings.SOLR_ELEMENT);//<Solr> 386 solr_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 387 solr_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 388 389 390 NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR);//<sort> 391 int num_nodes = sort_children.getLength(); 392 393 for (int i = 0; i < num_nodes; i++) 394 { 395 396 Element sort_element = to.createElement(StaticStrings.SORT_ELEMENT);//<Sort> 397 Element e = (Element) sort_children.item(i); 398 String sort_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 399 String sort_str_display = sort_str;//for creating collectionmetadata for this sort element 400 401 // Handling 'sort' element 402 sort_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, sort_str); 403 404 Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort> 405 406 if(displayItem != null) { 407 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE); 408 409 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 410 411 String value_str = XMLTools.getNodeText(displayItem); 412 413 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>! 414 displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 415 416 if (lang_str != null && !lang_str.equals("")) 417 { 418 displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str); 419 } 420 if (name_str != null && !name_str.equals("")) 421 { 422 displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 423 } 424 if (value_str != null && !value_str.equals("")) 425 { 426 //XMLTools.setNodeText(displayItem_element, value_str); 427 displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str); 428 } 429 sort_element.appendChild(displayItem_element); 430 431 } 432 433 solr_element.appendChild(sort_element); 434 435 sort_element = null; 436 437 // Handling 'displayItem' element of this 'sort' element 438 // 'e' is the parent 'sort' element of 'displayItem' element 439 ///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, sort_str_display); 440 ///appendArrayList(toElement, collectionmetadata_list); 441 442 } // for loop on sort elements ends 443 444 445 NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR);//facet 446 num_nodes = facet_children.getLength(); 447 448 for (int i = 0; i < num_nodes; i++) 449 { 450 451 Element facet_element = to.createElement(StaticStrings.FACET_ELEMENT);//<Facet> 452 Element e = (Element) facet_children.item(i); 453 String facet_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 454 String facet_str_display = facet_str;//for creating collectionmetadata for this facet 455 456 // Handling 'facet' element 457 facet_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, facet_str); 458 459 Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort> 460 461 if(displayItem != null) { 462 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE); 463 464 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 465 466 String value_str = XMLTools.getNodeText(displayItem); 467 468 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>! 469 displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 470 471 if (lang_str != null && !lang_str.equals("")) 472 { 473 displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str); 474 } 475 if (name_str != null && !name_str.equals("")) 476 { 477 displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 478 } 479 if (value_str != null && !value_str.equals("")) 480 { 481 //XMLTools.setNodeText(displayItem_element, value_str); 482 displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str); 483 } 484 facet_element.appendChild(displayItem_element); 485 486 } 487 solr_element.appendChild(facet_element); 488 489 facet_element = null; 490 491 // Handling 'displayItem' element of this 'facet' element 492 // 'e' is the parent 'facet' element of 'displayItem' element 493 ///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, facet_str_display); 494 ///appendArrayList(toElement, collectionmetadata_list); 495 496 } // for loop on facet elements ends 497 498 // finished processing sort and facet elements 499 toElement.appendChild(solr_element); 500 501 } 502 378 503 static private void doGlobalFormat(Document to, Element from) 379 504 { … … 2077 2202 convertDefaultIndex(from, to, search); 2078 2203 convertIndexOptions(from, to, search); 2204 } 2205 2206 //convert <facet> and <sort> elements and their displayItem subelements, 2207 //which go in 'search' element in collectionConfig.xml 2208 //parameter 'to' is the document to be saved as collectionConfig.xml 2209 //parameter 'from' is the internal xml structure 2210 // Note that GLI at present does not allow the user to set or modify the solr-specific elements 2211 // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such 2212 // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there. 2213 static private void convertSolrFacetsAndSorts(Document from, Document to) 2214 { 2215 Element source = from.getDocumentElement(); 2216 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2217 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2218 2219 //There are two sets of <Solr> elements, find the one which is assigned 'true' 2220 Element solr = XMLTools.getNamedElement(source, StaticStrings.SOLR_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2221 if (solr == null) 2222 { 2223 return; 2224 } 2225 NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_ELEMENT); //<Sort> 2226 int sort_elements_length = sort_elements.getLength(); 2227 NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_ELEMENT); //<Facet> 2228 int facet_elements_length = facet_elements.getLength(); 2229 2230 for (int j = 0; j < sort_elements_length; j++) 2231 { 2232 Element sort_element = (Element) sort_elements.item(j); 2233 if (sort_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2234 { 2235 continue; 2236 } 2237 2238 Element sort_ele = to.createElement(StaticStrings.SORT_LOW_STR);//<sort> 2239 String name_attr = sort_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2240 2241 /*if (name_attr.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_attr.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1) 2242 { 2243 name_attr = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length()); 2244 } 2245 */ 2246 sort_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr); 2247 2248 // Now constructing 'displayItem' element for this 'sort_ele' element 2249 Element displayItem = (Element) XMLTools.getChildByTagName(sort_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Sort> 2250 2251 if(displayItem != null) { 2252 if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) { 2253 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem> 2254 2255 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE); 2256 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2257 String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 2258 2259 if (lang_str != null && !lang_str.equals("")) 2260 { 2261 displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str); 2262 } 2263 if (name_str != null && !name_str.equals("")) 2264 { 2265 displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2266 } 2267 if (value_str != null && !value_str.equals("")) 2268 { 2269 XMLTools.setNodeText(displayItem_element, value_str); 2270 } 2271 sort_ele.appendChild(displayItem_element); 2272 } 2273 } 2274 2275 search.appendChild(sort_ele); 2276 2277 } //for loop on sort_elements ends 2278 2279 for (int j = 0; j < facet_elements_length; j++) 2280 { 2281 Element facet_element = (Element) facet_elements.item(j); 2282 if (facet_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2283 { 2284 continue; 2285 } 2286 2287 Element facet_ele = to.createElement(StaticStrings.FACET_LOW_STR);//<facet> 2288 String name_attr = facet_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2289 2290 facet_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr); 2291 2292 // Now constructing 'displayItem' element for this 'facet_ele' element 2293 Element displayItem = (Element) XMLTools.getChildByTagName(facet_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Facet> 2294 2295 if(displayItem != null) { 2296 if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) { 2297 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem> 2298 2299 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE); 2300 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2301 String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 2302 2303 if (lang_str != null && !lang_str.equals("")) 2304 { 2305 displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str); 2306 } 2307 if (name_str != null && !name_str.equals("")) 2308 { 2309 displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2310 } 2311 if (value_str != null && !value_str.equals("")) 2312 { 2313 XMLTools.setNodeText(displayItem_element, value_str); 2314 } 2315 facet_ele.appendChild(displayItem_element); 2316 } 2317 } 2318 2319 search.appendChild(facet_ele); 2320 2321 } //for loop on facet_elements ends 2322 2079 2323 } 2080 2324 … … 2504 2748 } 2505 2749 2750 if(buildtype_value.equalsIgnoreCase("solr")) { 2751 doSolrFacetsAndSorts(dOc, searchNode); // <facet><displayItem /></facet> and <sort><displayItem /></sort> 2752 } 2753 2506 2754 doDefaultIndex(dOc, searchNode); 2507 2755 doDefaultLevel(dOc, searchNode); … … 2604 2852 convertDatabaseType(dOc, skeleton); 2605 2853 convertIndex(dOc, skeleton); 2854 convertSolrFacetsAndSorts(dOc, skeleton); 2606 2855 convertPlugin(dOc, skeleton);//also do the plugout element 2607 2856 convertClassifier(dOc, skeleton);
Note:
See TracChangeset
for help on using the changeset viewer.