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