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