package org.greenstone3.ms; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class SearchLink { //final String path = "/research/cc108/greenstone3/web/mat/"; final String path = "/home/cc108/MRWks1/describeMessenger/"; String collection =""; String metadataElement =""; //String core_element=""; PrintWriter out; boolean status = true; public SearchLink(PrintWriter arg){ out = arg; } public SearchLink(){ } public boolean getStatus(){ return status; } public static void main(String[] args){ SearchLink sl = new SearchLink(); //sl.CreateIndentifierLinkPage("dc.Creator", "Lowe, David J.", "dc.Identifier","poilkjm"); //sl.CreateIndentifierLinkPage("dc.Publisher2", "ResearchSpace@Auckland", "dc.Identifier1","vmeqlek"); } public ArrayList CreateIndentifierLinkPage(String metadataElement, String text, String identifier, String col, HashMap valueMap, HashMap linkMap){ collection = col; //System.out.println("valueMap: "+valueMap.size()+ " linkMap: "+ linkMap.size()); this.metadataElement = metadataElement; //Element ex = openfile(metadataElement,col); try{ if(valueMap.size()==0){ status = false; return new ArrayList(); } else{ ArrayList alist = retrieveHASHID(valueMap,text); if(alist.size()==0){ status = false; return new ArrayList(); } //ex = openfile(identifier,col); if(linkMap.size()==0){ //out.write("

"+ identifier +" does not exist

"); status = false; return new ArrayList(); //System.out.println(identifier + "does not exist2"); //return createResult(new ArrayList()); } else{ ArrayList alist2 = retrieveHASHID(linkMap,alist,metadataElement); //System.out.println("break3"); return alist2; } } }catch(Exception ex){ex.printStackTrace(); return new ArrayList();} //return ""; } private Element openfile(String core_element, String collection){ try{ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); //Element rootNode = doc. //System.out.println(path+collection+"/metadataStats/"+core_element+".xml"); doc = docBuilder.parse (new File(path+"/"+collection+"/metadataStats/"+core_element+".xml")); Element rootNode = doc.getDocumentElement(); return rootNode; }catch (Exception e) { //e.printStackTrace(); //out.write("

"+core_element +" does not exist

"); System.out.println(core_element + " does not exist1"); return null; } } private ArrayList retrieveHASHID (HashMap hp, String text){ //ArrayList alist = new ArrayList(); if(hp.containsKey(text)){ InternalLink il = (InternalLink) hp.get(text); return il.retrieveList(); } else{ return new ArrayList(); } } private ArrayList retrieveHASHID (HashMap hp, ArrayList arg,String metadataElement){ //System.out.println(metadataElement); ArrayList alist = new ArrayList(); for(int i = 0; i\r\n"); out.write("\r\n"); out.write("\r\nResult\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write(""); out.write(""); out.write("
No."); out.write(" URL"); //System.out.println(alist.size()); for(int i = 0; i < alist.size(); i++){ out.write("
"+(i+1)); out.write(""+(String)alist.get(i)+"\n"); } out.write("
\r\n"); out.close(); fstream.close(); //System.out.println("/home/cc108/MRWks1/Quality"+"/"+collection+"/"+metadataElement+"_result.html"); }catch(Exception ex){ //ex.printStackTrace(); out.write("

links cannot be generated

"); } return url; } */ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// public HashMap createValueMap(String core_element, String collection){ //System.out.println("Create value map1 "+core_element); HashMap hp = new HashMap(); Element ex = openfile(core_element,collection); NodeList valueList = ex.getElementsByTagName("ActualValue"); for(int s=0; s