source: other-projects/GlamED/trunk/src/org/honours/greenstone/CollectionConfigReader.java

Last change on this file was 26700, checked in by davidb, 11 years ago

Introduced for reading xml elements in a collection's matching collectionConfig.xml file, in particular the description and full name of the collection.

File size: 2.1 KB
Line 
1package org.honours.greenstone;
2
3import java.io.File;
4
5import org.apache.log4j.Logger;
6
7import org.greenstone.gsdl3.util.GSXML;
8import org.greenstone.gsdl3.util.XMLConverter;
9import org.honours.Main;
10import org.w3c.dom.*;
11
12/**
13 * This class is used to obtain elements from
14 * a collection's corresponding collectionConfig.xml
15 * file.
16 * @author - Korii
17 */
18public class CollectionConfigReader {
19
20 static Logger logger = Logger.getLogger(org.honours.greenstone.CollectionConfigReader.class.getName());
21
22 private XMLConverter _xmlConverter;
23 private Document _document;
24
25 private String _collectionConfigFile;
26
27 public CollectionConfigReader(String collectionName){
28
29 _xmlConverter = new XMLConverter();
30 _collectionConfigFile = Main.GSDL_COLLECT_PATH + collectionName + File.separator + "etc" +
31 File.separator + "collectionConfig.xml";
32 _document = _xmlConverter.getDOM(new File(_collectionConfigFile));
33 }
34
35 /**
36 * Method available to retrieve a collection's description.
37 * @return
38 */
39 public String retrieveDescription(){
40
41 return obtainElementTextFromDisplayItemList("description");
42 }
43
44 /**
45 * Method available to retrieve a collection's full name.
46 * @return
47 */
48 public String retrieveFullCollectionName(){
49 return obtainElementTextFromDisplayItemList("name");
50 }
51
52 /**
53 * Retrieves text from an element in the displayItemList
54 * section of the collectionConfig.xml file.
55 * @return - the collection's description text
56 */
57 public String obtainElementTextFromDisplayItemList(String name){
58
59 NodeList nl = _document.getDocumentElement().getElementsByTagName("displayItemList");
60 Element displayItemList = (Element)nl.item(0);
61
62 nl = displayItemList.getChildNodes();
63 int i = 0;
64
65 while(i <= nl.getLength()){
66
67 Node node = nl.item(i);
68 if(node != null){
69
70 if(node.getNodeType() == Node.ELEMENT_NODE){
71
72 Element e = (Element)node;
73
74 if(e.getTagName().equals("displayItem") &&
75 e.getAttribute("name").equals(name)){
76 return GSXML.getNodeText(e);
77 }
78 }
79 }
80
81 i++;
82 }
83
84 return null;
85 }
86
87}
Note: See TracBrowser for help on using the repository browser.