Ignore:
Timestamp:
2022-12-06T14:08:15+13:00 (17 months ago)
Author:
kjdon
Message:

now we use displayItems in preference to title, description, shortDescription elements. This allows language specific variants.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CollectionGroups.java

    r36639 r36972  
    44
    55import org.apache.log4j.Logger;
     6import org.greenstone.gsdl3.util.DisplayItemUtil;
    67import org.greenstone.gsdl3.util.GSFile;
    78import org.greenstone.gsdl3.util.GSXML;
     
    2223
    2324import java.util.HashSet;
     25import java.util.HashMap;
    2426import java.util.Iterator;
    2527
     
    2830    private Element hierarchy = null;
    2931    private Element groupDesc = null;
     32  private HashMap<String, Element> group_descriptions_map = null; // new one for display items
    3033
    3134    public static final String GROUP_CONTENT_SERVICE = "GroupCurrentContent";
     35  // not used??
    3236    public static final String UNIQUE_COLLECTIONS_SERVICE = "UniqueCollections";
     37  // not used??
    3338    public static final String COLLECTIONS_HIERARCHY_SERVICE = "CollectionsHierarchy";
    34 
     39// hack, should be getting this from library servlet
     40  private static final String DEFAULT_LANG = "en";
    3541    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.CollectionGroups.class.getName());
    3642
     
    4854        }
    4955
     56                group_descriptions_map = new HashMap<String, Element>();
    5057        logger.info("Configuring CollectionGroups...");
    5158        this.config_info = info;
     
    6976        Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
    7077       
    71        
     78        String lang = request.getAttribute(GSXML.LANG_ATT);
    7279        // Get param list from request
    7380        Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     
    8289            }
    8390        }
    84         //Remove leading, ending / and dupliclated /
     91        //Remove leading, ending / and duplicated /
    8592        groupPath = groupPath.replaceAll("(/+)", "/");
    8693        groupPath = groupPath.replaceAll("(^/+)|(/+$)", "");
     
    132139                    Element currentGroup = (Element) currentContent.item(i);
    133140                    String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT);
    134                     Element groupDescription = getGroupDescription(currentGroupName);
     141                    Element groupDescription = getGroupDescription(doc, currentGroupName, lang);
    135142                   
    136143                    groupDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
     
    154161               
    155162            } else {
    156                 Element groupDescription = getPathInfo(groupPath);
     163                          Element groupDescription = getPathInfo(groupPath, lang);
    157164                if (groupContent != null){
    158165                    result.appendChild(doc.importNode(groupDescription, true));
     
    235242        Document doc = XMLConverter.newDOM();
    236243        UserContext userContext = new UserContext(request);
     244                String lang = request.getAttribute(GSXML.LANG_ATT);
    237245        // Prepare basic response
    238246        Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
     
    249257        //Get ungrouped collection list
    250258        sanitizeCurrentContent(currentContent, searchableCollectionList);
    251         addGroupInfo(currentContent, currentPath);
     259        addGroupInfo(currentContent, currentPath, lang);
    252260        addUngroupedCollections(currentContent, searchableCollectionList);
    253261        addAllOption(currentContent);
     
    271279    }
    272280
    273     private void addGroupInfo(Element currentContent, String groupPath) {
     281  private void addGroupInfo(Element currentContent, String groupPath, String lang) {
    274282        NodeList groups = GSXML.getChildrenByTagName(currentContent,GSXML.GROUP_ELEM);
     283                Document doc = currentContent.getOwnerDocument();
    275284        for (int i=0;i<groups.getLength();i++){
    276285            Element group = (Element) groups.item(i);
     
    278287            String newPath = groupPath + "/" + name;
    279288            group.setAttribute(GSXML.PATH_ATT, newPath);
    280             Element groupDescription = getGroupDescription(name);
     289            Element groupDescription = getGroupDescription(doc, name, lang);
    281290            Element titleEl = (Element) GSXML.getChildByTagName(groupDescription, GSXML.TITLE_ELEM);
    282291            String title;
     
    287296            }
    288297            group.setAttribute(GSXML.TITLE_ELEM, title  );
    289             addGroupInfo(group, newPath);
     298            addGroupInfo(group, newPath, lang);
    290299        }
    291300       
     
    401410    }
    402411
    403     private void verifyGroupDescription(Document doc) {
     412  private void verifyGroupDescription(Document doc) {
    404413      if (groupDesc == null) {
    405414        // we set up one for ourselves
     
    419428                groupTitle.setTextContent(name);
    420429                defaultDescription.appendChild(groupTitle);
     430                               
     431                                Element titleDisplayItem = DisplayItemUtil.createDisplayItem(doc, GSXML.DISPLAY_TEXT_NAME, DEFAULT_LANG, name);
     432                                defaultDescription.appendChild(titleDisplayItem);
    421433                groupDesc.appendChild(defaultDescription);
    422434            }
     435                        Element this_di_list = doc.createElement("dummy");
     436                        DisplayItemUtil.storeDisplayItems(this_di_list, foundDescription);
     437                        group_descriptions_map.put(name, this_di_list);
    423438        }
    424439       
    425440    }
    426441
    427     private Element getGroupDescription(String name) {
     442    private Element getGroupDescriptionOld(String name) {
    428443        Element description = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
    429444        if (description == null) {
     
    432447        return description;
    433448    }
     449  private Element getGroupDescription(Document doc, String name, String lang) {
     450    // get all the display items for group
     451    Element all_di = group_descriptions_map.get(name);
     452    Element new_di_list = doc.createElement(GSXML.GROUP_ELEM);
     453    new_di_list.setAttribute(GSXML.NAME_ATT, name);
     454    DisplayItemUtil.addLanguageSpecificDisplayItems(new_di_list, all_di, lang, DEFAULT_LANG, this.class_loader);
     455
     456    // now merge in the old style metadata - to be backwards compatible
     457    Element old_style_desc = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
     458    if (old_style_desc != null) {
     459      Element meta = (Element)GSXML.getChildByTagName(old_style_desc, "title");
     460      if (meta != null) {
     461        new_di_list.appendChild(doc.importNode(meta, true));
     462      }
     463      meta = (Element)GSXML.getChildByTagName(old_style_desc, "description");
     464      if (meta != null) {
     465        new_di_list.appendChild(doc.importNode(meta, true));
     466      }
     467      meta = (Element)GSXML.getChildByTagName(old_style_desc, "shortDescription");
     468      if (meta != null) {
     469        new_di_list.appendChild(doc.importNode(meta, true));
     470      }   
     471    }
     472    return new_di_list;
     473   
     474  }
    434475
    435476    private Element getUngroupedCollections(Element mr_collection_list) {
     
    472513
    473514    }
    474     private Element getPathInfo(String path) {
     515  private Element getPathInfo(String path, String lang) {
    475516
    476517        Document doc = XMLConverter.newDOM();
     
    493534              }
    494535              currentPath += pathSteps[i];
    495                 Element pathStepDescription = getGroupDescription(pathSteps[i]);
     536                          Element pathStepDescription = getGroupDescription(doc, pathSteps[i], lang);
    496537                if (pathStepDescription != null){
    497538                    pathStepDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
Note: See TracChangeset for help on using the changeset viewer.