Ignore:
Timestamp:
2012-06-07T21:34:38+12:00 (12 years ago)
Author:
ak19
Message:

Better way of removing duplicate collectionMetadata/displayItem elements from the collectionConfig.xml. Needed to do more to prevent duplicate elements than in the previous commit since the image-e/backdrop collections tested last time did not have search indexes while the reports collection does and these are the elements that got duplicated this time.

File:
1 edited

Legend:

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

    r25744 r25779  
    3131import java.util.ArrayList;
    3232import java.util.HashMap;
     33import java.util.HashSet;
    3334import java.util.Iterator;
    3435import java.util.LinkedHashSet;
     
    23402341        }
    23412342
    2342         if (displayItemListNode != null)
    2343         {
    2344 
    2345             NodeList nl = ((Element)displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR);
    2346 
    2347             // make a list of all unique attribute names that are specifically not
    2348             // description, smallicon, icon and name, since these are already processed above
    2349             Set setOfUniqueDisplayItemNames = new LinkedHashSet();
    2350             for(int i = 0; i < nl.getLength(); i++) {
    2351             Element displayItem = (Element)nl.item(i);
    2352             String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    2353 
    2354             if(name.equals("")) continue; // no name attribute
    2355 
    2356             if(name.equals(StaticStrings.DESCRIPTION_STR)) continue;
    2357             if(name.equals(StaticStrings.SMALLICON_STR)) continue;
    2358             if(name.equals(StaticStrings.ICON_STR)) continue;
    2359             if(name.equals(StaticStrings.NAME_STR)) continue;
    2360             // don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title
    2361             if(name.indexOf(":") != -1) continue;
    2362 
    2363             // otherwise
    2364             setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names
    2365             }
    2366            
    2367             Iterator i = setOfUniqueDisplayItemNames.iterator();
    2368             while (i.hasNext()) {
    2369             String displayItemName = (String)i.next();
    2370 
    2371             ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName);       
    2372             appendArrayList(toElement, custom_displayItem);
    2373             }
    2374         }
    2375 
    23762343        if (buildtype_value.equalsIgnoreCase("mg"))
    23772344        {
     
    23812348        {
    23822349            doMGPPIndexes(dOc, searchNode);
    2383         }
     2350        }       
    23842351
    23852352        doDefaultIndex(dOc, searchNode);
     
    23972364        doReplaceListRef(dOc, fromElement);
    23982365        doServiceRackList(dOc, fromElement);
     2366
     2367        // the official displayItems in the displayItemList element have already been handled above
     2368        // and created as collectionmetadata elements in the dOc object
     2369        // Now we add in all the *other* (remaining) displayItems as collectionmeta elements
     2370        NodeList collectionMetadataList = dOc.getDocumentElement().getElementsByTagName(StaticStrings.COLLECTIONMETADATA_ELEMENT);
     2371        Set setOfUniqueColMetaNames = new HashSet();
     2372        for(int i = 0; i < collectionMetadataList.getLength(); i++) {
     2373            Element colMeta = (Element)collectionMetadataList.item(i);
     2374            String name = colMeta.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     2375            setOfUniqueColMetaNames.add(name);
     2376        }
     2377
     2378        if (displayItemListNode != null)
     2379        {
     2380            NodeList nl = ((Element)displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR);
     2381
     2382            // make a list of all unique attribute names that are specifically not
     2383            // description, smallicon, icon and name, since these are already processed above
     2384            Set setOfUniqueDisplayItemNames = new LinkedHashSet();
     2385            for(int i = 0; i < nl.getLength(); i++) {
     2386            Element displayItem = (Element)nl.item(i);
     2387            String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     2388
     2389            if(name.equals("")) continue; // no name attribute
     2390            if(setOfUniqueColMetaNames.contains(name)) continue;
     2391
     2392            if(name.equals(StaticStrings.DESCRIPTION_STR)) continue;
     2393            if(name.equals(StaticStrings.SMALLICON_STR)) continue;
     2394            if(name.equals(StaticStrings.ICON_STR)) continue;
     2395            if(name.equals(StaticStrings.NAME_STR)) continue;
     2396            // don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title
     2397            if(name.indexOf(":") != -1) continue;
     2398
     2399            // otherwise
     2400            setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names
     2401            }
     2402           
     2403            Iterator i = setOfUniqueDisplayItemNames.iterator();
     2404            while (i.hasNext()) {
     2405            String displayItemName = (String)i.next();
     2406
     2407            ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName);       
     2408            appendArrayList(toElement, custom_displayItem);
     2409            }
     2410        }
    23992411
    24002412    }
Note: See TracChangeset for help on using the changeset viewer.