Changeset 22346

Show
Ignore:
Timestamp:
05.07.2010 14:23:43 (9 years ago)
Author:
kjdon
Message:

search types now separate elements in config file, not format elements. but in internal dom we pretend they are format statements to keep the interface the same as before.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java

    r20447 r22346  
    799799    toElement.appendChild (language_indexes); 
    800800  } 
    801   // Handling both searchType and search format statement 
     801 
     802  // Handling search types 
     803  static private void doSearchType (Document to, Node searchNode) { 
     804    NodeList type_children = ((Element)searchNode).getElementsByTagName (StaticStrings.SEARCHTYPE_ELEMENT); 
     805    int num_types = type_children.getLength(); 
     806    String searchtype_str = ""; 
     807    if (num_types < 1) { 
     808      // not defined yet, add in default 
     809      searchtype_str = "plain,simpleform,advancedform"; 
     810    } 
     811    else { 
     812      for(int i=0; i<num_types; i++) { 
     813    Node e = type_children.item (i); 
     814    String t = ((Element)e).getAttribute (StaticStrings.NAME_ATTRIBUTE); 
     815    if (i>0) { 
     816      searchtype_str += ","; 
     817    } 
     818    searchtype_str += t; 
     819      } 
     820    } 
     821     
     822    // pretend its a format statement 
     823    Element search_type_element = to.createElement (StaticStrings.FORMAT_STR); 
     824    search_type_element.setAttribute (StaticStrings.NAME_ATTRIBUTE, StaticStrings.SEARCHTYPE_ELEMENT); 
     825    XMLTools.setNodeText(search_type_element, searchtype_str); 
     826    appendProperly (to.getDocumentElement (), search_type_element); 
     827     
     828  } 
     829 
     830  // Handling search format statement 
    802831  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 
     832    // THere is currently just one format element for search. HOwever, need to check for old config files which used to have <format name="searchTypes"> 
    804833    NodeList format_children = ((Element)searchNode).getElementsByTagName (StaticStrings.FORMAT_STR); 
    805834    int format_nodes = format_children.getLength (); 
     
    808837    } 
    809838    Element format = null; 
    810     Element search_type = null; 
    811839    for(int i=0; i<format_nodes; i++) { 
    812840      Node e = format_children.item (i); 
    813841      if (e.hasAttributes () == false) { 
    814     //The format element for format statement has no any attribute 
     842    //The format element for format statement has no attribute 
    815843    format = (Element)e; 
    816       } 
    817       else if (((Element)e).getAttribute (StaticStrings.NAME_ATTRIBUTE).equals(StaticStrings.SEARCHTYPE_ELEMENT)) { 
    818     search_type = (Element)e; 
    819844      } 
    820845    } 
     
    822847    if (format != null) {             
    823848      (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); 
    835849    } 
    836850  } 
     
    12721286      return; 
    12731287    } 
    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); 
     1288    String searchtype_str = XMLTools.getNodeText(e);  
    12821289    //Get the 'search' element from 'to' 
    12831290    Element search = (Element)XMLTools.getChildByTagName (to.getDocumentElement (), StaticStrings.SEARCH_STR); 
    1284     search.appendChild (search_type_element); 
     1291 
     1292    String[] types = searchtype_str.split(","); 
     1293    for (int i=0; i<types.length; i++) { 
     1294      Element search_type_element = to.createElement (StaticStrings.SEARCHTYPE_ELEMENT); 
     1295      search_type_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, types[i]); 
     1296      search.appendChild (search_type_element); 
     1297    } 
    12851298  } 
    12861299     
     
    20012014         
    20022015    doDefaultIndex (dOc, searchNode); 
    2003     //doSearchType (dOc, searchNode); 
    20042016    doDefaultLevel (dOc, searchNode); 
    20052017    doLevel (dOc, searchNode); 
     
    20102022    doDefaultIndexLanguage (dOc, searchNode); 
    20112023    doLanguageMetadata (dOc, searchNode); 
     2024    doSearchType (dOc, searchNode); 
    20122025    doSearchFormat (dOc, searchNode); 
    20132026    doDisplayFormat (dOc, fromElement);