package org.honours.greenstone; import java.io.File; import org.apache.log4j.Logger; import org.greenstone.gsdl3.util.GSXML; import org.greenstone.gsdl3.util.XMLConverter; import org.honours.Main; import org.w3c.dom.*; /** * This class is used to obtain elements from * a collection's corresponding collectionConfig.xml * file. * @author - Korii */ public class CollectionConfigReader { static Logger logger = Logger.getLogger(org.honours.greenstone.CollectionConfigReader.class.getName()); private XMLConverter _xmlConverter; private Document _document; private String _collectionConfigFile; public CollectionConfigReader(String collectionName){ _xmlConverter = new XMLConverter(); _collectionConfigFile = Main.GSDL_COLLECT_PATH + collectionName + File.separator + "etc" + File.separator + "collectionConfig.xml"; _document = _xmlConverter.getDOM(new File(_collectionConfigFile)); } /** * Method available to retrieve a collection's description. * @return */ public String retrieveDescription(){ return obtainElementTextFromDisplayItemList("description"); } /** * Method available to retrieve a collection's full name. * @return */ public String retrieveFullCollectionName(){ return obtainElementTextFromDisplayItemList("name"); } /** * Retrieves text from an element in the displayItemList * section of the collectionConfig.xml file. * @return - the collection's description text */ public String obtainElementTextFromDisplayItemList(String name){ NodeList nl = _document.getDocumentElement().getElementsByTagName("displayItemList"); Element displayItemList = (Element)nl.item(0); nl = displayItemList.getChildNodes(); int i = 0; while(i <= nl.getLength()){ Node node = nl.item(i); if(node != null){ if(node.getNodeType() == Node.ELEMENT_NODE){ Element e = (Element)node; if(e.getTagName().equals("displayItem") && e.getAttribute("name").equals(name)){ return GSXML.getNodeText(e); } } } i++; } return null; } }