[18093] | 1 | package org.greenstone.gsdl3_extension.mat.servlet;
|
---|
| 2 |
|
---|
| 3 | import java.io.*;
|
---|
| 4 | import java.io.File;
|
---|
| 5 | import java.util.ArrayList;
|
---|
| 6 | import java.util.Arrays;
|
---|
| 7 | import java.util.Collection;
|
---|
| 8 | import java.util.HashMap;
|
---|
| 9 | import java.util.Iterator;
|
---|
| 10 |
|
---|
| 11 | import org.w3c.dom.Element;
|
---|
| 12 | import org.greenstone.gsdl3.core.MessageRouter;
|
---|
| 13 | import org.greenstone.gsdl3.util.GlobalProperties;
|
---|
| 14 | import org.greenstone.gsdl3.util.GSFile;
|
---|
| 15 | import org.greenstone.gsdl3.util.GDBMWrapper;
|
---|
| 16 |
|
---|
| 17 | public class DescribeMessager {
|
---|
| 18 |
|
---|
| 19 | private final String site_name = "localsite";
|
---|
| 20 | private MessageRouter mr = null;
|
---|
| 21 | private String collection_Name = null;
|
---|
| 22 | private MetadataStats ms;
|
---|
| 23 | private String site_home = null;
|
---|
| 24 | private String gsdl3_home = null;
|
---|
| 25 |
|
---|
| 26 | public DescribeMessager(String collectionName, String URL) {
|
---|
| 27 |
|
---|
| 28 | collection_Name = collectionName;
|
---|
| 29 | gsdl3_home = GlobalProperties.getGSDL3Home();
|
---|
| 30 |
|
---|
| 31 | if (gsdl3_home == null || gsdl3_home.equals("")) {
|
---|
| 32 | System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server.");
|
---|
| 33 | return;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | site_home = GSFile.siteHome(gsdl3_home, this.site_name);
|
---|
| 37 |
|
---|
| 38 | File site_file = new File(site_home);
|
---|
| 39 |
|
---|
| 40 | if (!site_file.isDirectory()) {
|
---|
| 41 | System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | mr = new MessageRouter();
|
---|
| 46 | mr.setSiteName(this.site_name);
|
---|
| 47 | mr.configure();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public void setCollectionName(String arg){
|
---|
| 51 | collection_Name = arg;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public String getCollectionName(){
|
---|
| 55 | return collection_Name;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public boolean describeMatadata(PrintWriter out, String collectionName,String OAIURL, String oaiPrefix){
|
---|
| 59 |
|
---|
| 60 | ms = new MetadataStats(this.site_home,collectionName,OAIURL,out, oaiPrefix);
|
---|
| 61 |
|
---|
| 62 | if(ms.getStatus()){
|
---|
| 63 | printWebPage(ms,out);
|
---|
| 64 | return true;
|
---|
| 65 | }
|
---|
| 66 | else{
|
---|
| 67 | out.print("<p> This collection could not be analysed.</p>");
|
---|
| 68 | return false;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public void printWebPage(MetadataStats ms,PrintWriter out){
|
---|
| 73 |
|
---|
| 74 | DataMaker dm = new DataMaker(ms);
|
---|
| 75 | String[] elements = new String [ms.metadataNameList.size()];
|
---|
| 76 |
|
---|
| 77 | for(int i = 0; i<elements.length; i++){
|
---|
| 78 | elements[i] = (String)ms.metadataNameList.get(i);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | Arrays.sort(elements);
|
---|
| 82 |
|
---|
| 83 | /*
|
---|
| 84 | String[] metaDataElementName = (String[])elements.clone();
|
---|
| 85 | String[] ids = dm.getDocumentIDs("archivedir");
|
---|
| 86 | ArrayList alist = new ArrayList();
|
---|
| 87 |
|
---|
| 88 | for(int a = 0; a<elements.length; a++){
|
---|
| 89 | alist.add(dm.getMetadataRows(elements[a]));
|
---|
| 90 | }
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | PrintHTML phtml = new PrintHTML(ms,out);
|
---|
| 94 | HashMap hp = ms.getMetadataSetMap();
|
---|
| 95 | Collection c = hp.values();
|
---|
| 96 | Iterator i = c.iterator();
|
---|
| 97 |
|
---|
| 98 | while(i.hasNext()){
|
---|
| 99 | MetadataSet mds = (MetadataSet)i.next();
|
---|
| 100 | ArrayList elementList = mds.getIndexsList();
|
---|
| 101 | String[] mdsElement = new String[elementList.size()];
|
---|
| 102 |
|
---|
| 103 | for(int x = 0; x<mdsElement.length; x++){
|
---|
| 104 | mdsElement[x]=(String)elementList.get(x);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | Arrays.sort(mdsElement);
|
---|
| 108 |
|
---|
| 109 | String[] metaDataElement = (String[])mdsElement.clone();
|
---|
| 110 | String[] idList = dm.getDocumentIDs("archivedir");
|
---|
| 111 | ArrayList datalist = new ArrayList();
|
---|
| 112 |
|
---|
| 113 | for(int a = 0; a<mdsElement.length; a++){
|
---|
| 114 | datalist.add(dm.getMetadataRows(mdsElement[a]));
|
---|
| 115 | }
|
---|
| 116 | phtml.generateAllPossibleGraph(datalist,idList,metaDataElement,mds.getName());
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | phtml.generateOverallStatisticsPage(hp);
|
---|
| 120 |
|
---|
| 121 | Collection cx = ms.getMetadataSetMap().values();
|
---|
| 122 | Iterator ix = cx.iterator();
|
---|
| 123 |
|
---|
| 124 | while(ix.hasNext()){
|
---|
| 125 | MetadataSet temp = (MetadataSet)ix.next();
|
---|
| 126 | phtml.WriteMetadataSetDetailHTML(temp);
|
---|
| 127 | phtml.generateMetadataElementDetailPage(temp,out);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | public MetadataStats getElementClass(){
|
---|
| 132 | return ms;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | public static void main(String[] args) {
|
---|
| 137 | DescribeMessager dm = new DescribeMessager("testCOLLECTION","cs.waikato.ac.nz");
|
---|
| 138 | }
|
---|
| 139 | */
|
---|
| 140 | }
|
---|
| 141 |
|
---|