package org.greenstone.mat; import java.io.*; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import org.w3c.dom.Node; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.greenstone.gsdl3.core.MessageRouter; import org.greenstone.util.GlobalProperties; import org.greenstone.gsdl3.util.GSFile; import org.greenstone.gsdl3.util.GSXML; import org.greenstone.gsdl3.util.XMLConverter; import org.greenstone.gsdl3.util.GDBMWrapper; import org.greenstone.gsdl3.util.GSPath; public class DescribeMessenger { protected String site_name = "localsite"; protected MessageRouter mr = null; protected Node CollectionList = null; protected Document doc=null; protected XMLConverter converter=null; protected final static String mrSubsetOptions = //messageRouter "collectionList serviceClusterList serviceList siteList"; protected final static String csSubsetOptions = //collections and serviceClusters "metadataList serviceList displayItemList"; protected final static String serviceSubsetOptions = //services "paramList displayItemList"; final int MESSAGEROUTER = 1, COLLECTION = 2, SERVICECLUSTER = 3, SERVICE = 4; private String collection_Name = null; private String OAI_URL = null; protected GDBMWrapper gdbm_src = null; protected String site_name1 = ""; protected String coll_name1 = ""; protected Element coll_config_xml = null; protected HashMap element_map = new HashMap(); protected MetadataStats ms; protected String site_home = null; public DescribeMessenger() { String gsdl3_home = GlobalProperties.getGSDL3Home(); if (gsdl3_home == null || gsdl3_home.equals("")) { System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server."); return; } site_home = GSFile.siteHome(gsdl3_home, this.site_name); File site_file = new File(site_home); if (!site_file.isDirectory()) { System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server."); return; } this.converter = new XMLConverter(); this.doc = this.converter.newDOM(); mr = new MessageRouter(); mr.setSiteName(this.site_name); mr.setLibraryName(this.site_name); mr.configure(); this.gdbm_src = new GDBMWrapper(); } public DescribeMessenger(String collectionName, String URL) { collection_Name = collectionName; OAI_URL = URL; String gsdl3_home = GlobalProperties.getGSDL3Home(); System.out.println(gsdl3_home); System.out.println(GSPath.removeLastLink(gsdl3_home)); if (gsdl3_home == null || gsdl3_home.equals("")) { System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server."); return; } site_home = GSFile.siteHome(gsdl3_home, this.site_name); File site_file = new File(site_home); if (!site_file.isDirectory()) { System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server."); return; } this.converter = new XMLConverter(); this.doc = this.converter.newDOM(); this.mr = new MessageRouter(); this.mr.setSiteName(this.site_name); this.gdbm_src = new GDBMWrapper(); } public void setCollectionName(String arg){ collection_Name = arg; } public String describe(){ return describe("", "", "", mrSubsetOptions); } public String getCollectionName(){ return collection_Name; } protected String describe(String to, String lang, String subsetOption, String validSubsetOptions) { try{ Node message = doc.createElement(GSXML.MESSAGE_ELEM); Node request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, ""); if(subsetOption != "") { if(validSubsetOptions.indexOf(subsetOption) == -1){ return "Invalid List to be described. Choose one of:\n" + validSubsetOptions; } Node param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, subsetOption)); request.appendChild(param_list); } message.appendChild(request); CollectionList = mr.process(message); return ">>"+GSXML.MESSAGE_ELEM+"<<"; }catch(Exception ex){ ex.printStackTrace(); return "failure"; } } public Node getCollectionList(){ return CollectionList; } public void describeMatadata(String collectionName,String OAIURL){ ms = new MetadataStats(this.site_home,collectionName,OAIURL,"test"); if(ms.getStatus()){ //printWebPage(ms); } else{ System.out.print("

The metadataStats fails

"); } } public void printWebPage(MetadataStats ms){ DataMaker dm = new DataMaker(ms); PrintHTML phtml = new PrintHTML(ms); HashMap hp = ms.getMetadataSetMap(); Collection c = hp.values(); Iterator i = c.iterator(); while(i.hasNext()){ MetadataSet mds = (MetadataSet)i.next(); ArrayList elementList = mds.getIndexsList(); String[] mdsElement = new String[elementList.size()]; for(int x = 0; x