1 | package org.greenstone.gsdl3_extension.mat;
|
---|
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.Node;
|
---|
12 | import org.w3c.dom.Document;
|
---|
13 | import org.w3c.dom.Element;
|
---|
14 |
|
---|
15 | import org.greenstone.gsdl3.core.MessageRouter;
|
---|
16 | import org.greenstone.gsdl3.util.GlobalProperties;
|
---|
17 | import org.greenstone.gsdl3.util.GSFile;
|
---|
18 | import org.greenstone.gsdl3.util.GSXML;
|
---|
19 | import org.greenstone.gsdl3.util.XMLConverter;
|
---|
20 | import org.greenstone.gsdl3.util.GDBMWrapper;
|
---|
21 | import org.greenstone.gsdl3.util.GSPath;
|
---|
22 |
|
---|
23 |
|
---|
24 | public class DescribeMessenger {
|
---|
25 |
|
---|
26 | protected String site_name = "localsite";
|
---|
27 | protected MessageRouter mr = null;
|
---|
28 | protected Node CollectionList = null;
|
---|
29 | protected Document doc=null;
|
---|
30 | protected XMLConverter converter=null;
|
---|
31 |
|
---|
32 | protected final static String mrSubsetOptions = //messageRouter
|
---|
33 | "collectionList serviceClusterList serviceList siteList";
|
---|
34 |
|
---|
35 | protected final static String csSubsetOptions = //collections and serviceClusters
|
---|
36 | "metadataList serviceList displayItemList";
|
---|
37 |
|
---|
38 | protected final static String serviceSubsetOptions = //services
|
---|
39 | "paramList displayItemList";
|
---|
40 |
|
---|
41 | final int MESSAGEROUTER = 1, COLLECTION = 2, SERVICECLUSTER = 3, SERVICE = 4;
|
---|
42 |
|
---|
43 | private String collection_Name = null;
|
---|
44 | private String OAI_URL = null;
|
---|
45 | protected GDBMWrapper gdbm_src = null;
|
---|
46 | protected String site_name1 = "";
|
---|
47 | protected String coll_name1 = "";
|
---|
48 | protected Element coll_config_xml = null;
|
---|
49 | protected HashMap element_map = new HashMap();
|
---|
50 | protected MetadataStats ms;
|
---|
51 | protected String site_home = null;
|
---|
52 |
|
---|
53 | public DescribeMessenger() {
|
---|
54 |
|
---|
55 | String gsdl3_home = GlobalProperties.getGSDL3Home();
|
---|
56 |
|
---|
57 | if (gsdl3_home == null || gsdl3_home.equals("")) {
|
---|
58 | System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server.");
|
---|
59 | return;
|
---|
60 | }
|
---|
61 |
|
---|
62 | site_home = GSFile.siteHome(gsdl3_home, this.site_name);
|
---|
63 | File site_file = new File(site_home);
|
---|
64 |
|
---|
65 | if (!site_file.isDirectory()) {
|
---|
66 | System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
|
---|
67 | return;
|
---|
68 | }
|
---|
69 | this.converter = new XMLConverter();
|
---|
70 | this.doc = this.converter.newDOM();
|
---|
71 |
|
---|
72 | mr = new MessageRouter();
|
---|
73 |
|
---|
74 | mr.setSiteName(this.site_name);
|
---|
75 | mr.setLibraryName(this.site_name);
|
---|
76 | mr.configure();
|
---|
77 | this.gdbm_src = new GDBMWrapper();
|
---|
78 | }
|
---|
79 |
|
---|
80 | public DescribeMessenger(String collectionName, String URL) {
|
---|
81 |
|
---|
82 | collection_Name = collectionName;
|
---|
83 | OAI_URL = URL;
|
---|
84 |
|
---|
85 | String gsdl3_home = GlobalProperties.getGSDL3Home();
|
---|
86 | System.out.println(gsdl3_home);
|
---|
87 | System.out.println(GSPath.removeLastLink(gsdl3_home));
|
---|
88 | if (gsdl3_home == null || gsdl3_home.equals("")) {
|
---|
89 | System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server.");
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 | site_home = GSFile.siteHome(gsdl3_home, this.site_name);
|
---|
94 |
|
---|
95 | File site_file = new File(site_home);
|
---|
96 |
|
---|
97 | if (!site_file.isDirectory()) {
|
---|
98 | System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | this.converter = new XMLConverter();
|
---|
103 | this.doc = this.converter.newDOM();
|
---|
104 | this.mr = new MessageRouter();
|
---|
105 | this.mr.setSiteName(this.site_name);
|
---|
106 | this.gdbm_src = new GDBMWrapper();
|
---|
107 | }
|
---|
108 |
|
---|
109 | public void setCollectionName(String arg){
|
---|
110 | collection_Name = arg;
|
---|
111 | }
|
---|
112 |
|
---|
113 | public String describe(){
|
---|
114 | return describe("", "", "", mrSubsetOptions);
|
---|
115 | }
|
---|
116 |
|
---|
117 | public String getCollectionName(){
|
---|
118 | return collection_Name;
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected String describe(String to, String lang, String subsetOption, String validSubsetOptions)
|
---|
122 | {
|
---|
123 | try{
|
---|
124 | Node message = doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
125 | Node request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, "");
|
---|
126 |
|
---|
127 | if(subsetOption != "") {
|
---|
128 | if(validSubsetOptions.indexOf(subsetOption) == -1){
|
---|
129 | return "Invalid List to be described. Choose one of:\n" + validSubsetOptions;
|
---|
130 | }
|
---|
131 |
|
---|
132 | Node param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
133 | param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, subsetOption));
|
---|
134 | request.appendChild(param_list);
|
---|
135 | }
|
---|
136 |
|
---|
137 | message.appendChild(request);
|
---|
138 | CollectionList = mr.process(message);
|
---|
139 | return ">>"+GSXML.MESSAGE_ELEM+"<<";
|
---|
140 | }catch(Exception ex){
|
---|
141 | ex.printStackTrace();
|
---|
142 | return "failure";
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | public Node getCollectionList(){
|
---|
147 | return CollectionList;
|
---|
148 | }
|
---|
149 |
|
---|
150 | public void describeMatadata(String collectionName,String OAIURL){
|
---|
151 |
|
---|
152 |
|
---|
153 | ms = new MetadataStats(this.site_home,collectionName,OAIURL,"test");
|
---|
154 |
|
---|
155 | if(ms.getStatus()){
|
---|
156 | //printWebPage(ms);
|
---|
157 | }
|
---|
158 | else{
|
---|
159 | System.out.print("<p> The metadataStats fails</p>");
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | public void printWebPage(MetadataStats ms){
|
---|
164 |
|
---|
165 | DataMaker dm = new DataMaker(ms);
|
---|
166 | PrintHTML phtml = new PrintHTML(ms);
|
---|
167 |
|
---|
168 | HashMap hp = ms.getMetadataSetMap();
|
---|
169 | Collection c = hp.values();
|
---|
170 | Iterator i = c.iterator();
|
---|
171 |
|
---|
172 | while(i.hasNext()){
|
---|
173 | MetadataSet mds = (MetadataSet)i.next();
|
---|
174 | ArrayList elementList = mds.getIndexsList();
|
---|
175 | String[] mdsElement = new String[elementList.size()];
|
---|
176 |
|
---|
177 | for(int x = 0; x<mdsElement.length; x++){
|
---|
178 | mdsElement[x]=(String)elementList.get(x);
|
---|
179 | }
|
---|
180 |
|
---|
181 | Arrays.sort(mdsElement);
|
---|
182 |
|
---|
183 | String[] metaDataElement = (String[])mdsElement.clone();
|
---|
184 | String[] idList = dm.getDocumentIDs("archivedir");
|
---|
185 |
|
---|
186 | ArrayList datalist = new ArrayList();
|
---|
187 |
|
---|
188 | for(int a = 0; a<mdsElement.length; a++){
|
---|
189 | datalist.add(dm.getMetadataRows(mdsElement[a]));
|
---|
190 | }
|
---|
191 | phtml.generateAllPossibleGraph(datalist,idList,metaDataElement,mds.getName());
|
---|
192 | }
|
---|
193 |
|
---|
194 | phtml.generateOverallStatisticsPage(hp);
|
---|
195 |
|
---|
196 | Collection cx = ms.getMetadataSetMap().values();
|
---|
197 | Iterator ix = cx.iterator();
|
---|
198 |
|
---|
199 | while(ix.hasNext()){
|
---|
200 | MetadataSet temp = (MetadataSet)ix.next();
|
---|
201 | phtml.WriteMetadataSetDetailHTML(temp);
|
---|
202 | phtml.generateMetadataElementDetailPage(temp);
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | public MetadataStats getElementClass(){
|
---|
207 | return ms;
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|