Changeset 36972
- Timestamp:
- 2022-12-06T14:08:15+13:00 (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CollectionGroups.java
r36639 r36972 4 4 5 5 import org.apache.log4j.Logger; 6 import org.greenstone.gsdl3.util.DisplayItemUtil; 6 7 import org.greenstone.gsdl3.util.GSFile; 7 8 import org.greenstone.gsdl3.util.GSXML; … … 22 23 23 24 import java.util.HashSet; 25 import java.util.HashMap; 24 26 import java.util.Iterator; 25 27 … … 28 30 private Element hierarchy = null; 29 31 private Element groupDesc = null; 32 private HashMap<String, Element> group_descriptions_map = null; // new one for display items 30 33 31 34 public static final String GROUP_CONTENT_SERVICE = "GroupCurrentContent"; 35 // not used?? 32 36 public static final String UNIQUE_COLLECTIONS_SERVICE = "UniqueCollections"; 37 // not used?? 33 38 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"; 35 41 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.CollectionGroups.class.getName()); 36 42 … … 48 54 } 49 55 56 group_descriptions_map = new HashMap<String, Element>(); 50 57 logger.info("Configuring CollectionGroups..."); 51 58 this.config_info = info; … … 69 76 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); 70 77 71 78 String lang = request.getAttribute(GSXML.LANG_ATT); 72 79 // Get param list from request 73 80 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); … … 82 89 } 83 90 } 84 //Remove leading, ending / and duplic lated /91 //Remove leading, ending / and duplicated / 85 92 groupPath = groupPath.replaceAll("(/+)", "/"); 86 93 groupPath = groupPath.replaceAll("(^/+)|(/+$)", ""); … … 132 139 Element currentGroup = (Element) currentContent.item(i); 133 140 String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT); 134 Element groupDescription = getGroupDescription( currentGroupName);141 Element groupDescription = getGroupDescription(doc, currentGroupName, lang); 135 142 136 143 groupDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i)); … … 154 161 155 162 } else { 156 Element groupDescription = getPathInfo(groupPath);163 Element groupDescription = getPathInfo(groupPath, lang); 157 164 if (groupContent != null){ 158 165 result.appendChild(doc.importNode(groupDescription, true)); … … 235 242 Document doc = XMLConverter.newDOM(); 236 243 UserContext userContext = new UserContext(request); 244 String lang = request.getAttribute(GSXML.LANG_ATT); 237 245 // Prepare basic response 238 246 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); … … 249 257 //Get ungrouped collection list 250 258 sanitizeCurrentContent(currentContent, searchableCollectionList); 251 addGroupInfo(currentContent, currentPath );259 addGroupInfo(currentContent, currentPath, lang); 252 260 addUngroupedCollections(currentContent, searchableCollectionList); 253 261 addAllOption(currentContent); … … 271 279 } 272 280 273 private void addGroupInfo(Element currentContent, String groupPath) {281 private void addGroupInfo(Element currentContent, String groupPath, String lang) { 274 282 NodeList groups = GSXML.getChildrenByTagName(currentContent,GSXML.GROUP_ELEM); 283 Document doc = currentContent.getOwnerDocument(); 275 284 for (int i=0;i<groups.getLength();i++){ 276 285 Element group = (Element) groups.item(i); … … 278 287 String newPath = groupPath + "/" + name; 279 288 group.setAttribute(GSXML.PATH_ATT, newPath); 280 Element groupDescription = getGroupDescription( name);289 Element groupDescription = getGroupDescription(doc, name, lang); 281 290 Element titleEl = (Element) GSXML.getChildByTagName(groupDescription, GSXML.TITLE_ELEM); 282 291 String title; … … 287 296 } 288 297 group.setAttribute(GSXML.TITLE_ELEM, title ); 289 addGroupInfo(group, newPath );298 addGroupInfo(group, newPath, lang); 290 299 } 291 300 … … 401 410 } 402 411 403 412 private void verifyGroupDescription(Document doc) { 404 413 if (groupDesc == null) { 405 414 // we set up one for ourselves … … 419 428 groupTitle.setTextContent(name); 420 429 defaultDescription.appendChild(groupTitle); 430 431 Element titleDisplayItem = DisplayItemUtil.createDisplayItem(doc, GSXML.DISPLAY_TEXT_NAME, DEFAULT_LANG, name); 432 defaultDescription.appendChild(titleDisplayItem); 421 433 groupDesc.appendChild(defaultDescription); 422 434 } 435 Element this_di_list = doc.createElement("dummy"); 436 DisplayItemUtil.storeDisplayItems(this_di_list, foundDescription); 437 group_descriptions_map.put(name, this_di_list); 423 438 } 424 439 425 440 } 426 441 427 private Element getGroupDescription (String name) {442 private Element getGroupDescriptionOld(String name) { 428 443 Element description = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name); 429 444 if (description == null) { … … 432 447 return description; 433 448 } 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 } 434 475 435 476 private Element getUngroupedCollections(Element mr_collection_list) { … … 472 513 473 514 } 474 private Element getPathInfo(String path) {515 private Element getPathInfo(String path, String lang) { 475 516 476 517 Document doc = XMLConverter.newDOM(); … … 493 534 } 494 535 currentPath += pathSteps[i]; 495 Element pathStepDescription = getGroupDescription(pathSteps[i]);536 Element pathStepDescription = getGroupDescription(doc, pathSteps[i], lang); 496 537 if (pathStepDescription != null){ 497 538 pathStepDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
Note:
See TracChangeset
for help on using the changeset viewer.