source: other-projects/trunk/greenstone3-extension/mat/DLMetadataQuality/src/org/greenstone3/ms/DescribeMessager.java@ 17184

Last change on this file since 17184 was 17184, checked in by cc108, 16 years ago

Metadata Quality For Digital Libraries

File size: 11.1 KB
Line 
1package org.greenstone3.ms;
2
3import java.io.File;
4import java.util.ArrayList;
5import java.util.Arrays;
6import java.util.Collection;
7import java.util.HashMap;
8import java.util.Iterator;
9
10
11import java.io.*;
12
13import org.w3c.dom.Node;
14import org.w3c.dom.Document;
15import org.w3c.dom.Element;
16
17import org.greenstone.gsdl3.core.MessageRouter;
18import org.greenstone.gsdl3.util.GlobalProperties;
19import org.greenstone.gsdl3.util.GSFile;
20import org.greenstone.gsdl3.util.GSXML;
21import org.greenstone.gsdl3.util.XMLConverter;
22import org.greenstone.gsdl3.util.GDBMWrapper;
23
24public class DescribeMessager {
25
26 protected String site_name = "localsite";
27
28
29 /** message router object to pass requests messages to and which
30 * will process them.*/
31 protected MessageRouter mr = null;
32 private Node CollectionList = null;
33 /** container Document to create XML Nodes */
34 protected Document doc=null;
35 /** a converter class to parse XML and create Docs */
36 protected XMLConverter converter=null;
37
38 protected final static String mrSubsetOptions = //messageRouter
39 "collectionList serviceClusterList serviceList siteList";
40 protected final static String csSubsetOptions = //collections and serviceClusters
41 "metadataList serviceList displayItemList";
42 protected final static String serviceSubsetOptions = //services
43 "paramList displayItemList";
44 final int MESSAGEROUTER = 1, COLLECTION = 2,
45 SERVICECLUSTER = 3, SERVICE = 4;
46
47 private String collection_Name = null;
48 private String OAI_URL = null;
49 protected GDBMWrapper gdbm_src = null;
50 protected String site_name1 = "";
51 protected String coll_name1 = "";
52 protected Element coll_config_xml = null;
53 protected HashMap element_map = new HashMap();
54 protected MetadataStats ms;
55 String site_home = null;
56
57 public DescribeMessager() {
58
59 String gsdl3_home = GlobalProperties.getGSDL3Home();
60 if (gsdl3_home == null || gsdl3_home.equals("")) {
61 System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server.");
62 return;
63 }
64
65
66 site_home = GSFile.siteHome(gsdl3_home, this.site_name);
67
68 File site_file = new File(site_home);
69 if (!site_file.isDirectory()) {
70 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
71 return;
72 }
73 this.converter = new XMLConverter();
74 this.doc = this.converter.newDOM();
75 System.err.println("3");
76 mr = new MessageRouter();
77
78 mr.setSiteName(this.site_name);
79 mr.setLibraryName(this.site_name);
80
81 mr.configure();
82 /*
83 try{
84
85 mr.
86 }catch(Exception ex){ex.printStackTrace();}
87 */
88 System.err.println("6");
89
90 this.gdbm_src = new GDBMWrapper();
91 System.err.println("7");
92
93
94 }
95
96 public DescribeMessager(String collectionName, String URL) {
97
98 collection_Name = collectionName;
99 OAI_URL = URL;
100
101 String gsdl3_home = GlobalProperties.getGSDL3Home();
102 if (gsdl3_home == null || gsdl3_home.equals("")) {
103 System.err.println("Couldn't access GSDL3Home from GlobalProperties.getGSDL3HOME, can't initialize the SOAP Server.");
104 return;
105 }
106
107 site_home = GSFile.siteHome(gsdl3_home, this.site_name);
108
109 File site_file = new File(site_home);
110 if (!site_file.isDirectory()) {
111 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
112 return;
113 }
114 this.converter = new XMLConverter();
115 this.doc = this.converter.newDOM();
116
117 mr = new MessageRouter();
118 mr.setSiteName(this.site_name);
119 //mr.configure();
120 this.gdbm_src = new GDBMWrapper();
121 //describe();
122 }
123 /*
124 public void setURL(String arg){
125 OAI_URL = arg;
126 }
127 */
128
129 public void setCollectionName(String arg){
130 collection_Name = arg;
131 }
132
133 public String describe()
134 {
135 return describe("", "", "", mrSubsetOptions);
136 }
137
138 /*
139 public String getURL(){
140 return OAI_URL;
141 }
142 */
143
144 public String getCollectionName(){
145 return collection_Name;
146 }
147
148 /*
149 //Describe Messages sent to Services (or Collection/Services)
150 public String describeCollService(String toColl, String toService,
151 String lang, String subsetOption) {
152
153 return describe(toColl + "/" + toService,
154 lang, subsetOption, serviceSubsetOptions);
155 }
156 */
157 //If public, this method would give full access: a describe message that
158 //lets the user specify all the details of who the receiver is, and what
159 //details are requested.
160 protected String describe(String to, String lang,
161 String subsetOption, String validSubsetOptions)
162 {
163
164 //Create message element: <message></message>
165 try{
166 //DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
167 //Get the DocumentBuilder
168 //DocumentBuilder parser = factory.newDocumentBuilder();
169 //Create blank DOM Document
170 //Document doct = parser.newDocument();
171
172 Node message = doc.createElement(GSXML.MESSAGE_ELEM);
173
174 //<message><request lang="en" to="" type="describe" uid="" /></message>
175
176 Node request = GSXML.createBasicRequest(
177 this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, "");
178
179 //Check if only a subset of this Module Interface's data is asked
180 //to be described
181
182 if(subsetOption != "") {
183 //Now deal with the value for subset param:
184 //only deal with valid params for subset of to-ModuleInterface
185 if(validSubsetOptions.indexOf(subsetOption) == -1)
186 return "Invalid List to be described. Choose one of:\n"
187 + validSubsetOptions;
188
189 //else, append <paramList />
190 Node param_list = this.doc.createElement(
191 GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
192 param_list.appendChild(GSXML.createParameter(
193 this.doc, GSXML.SUBSET_PARAM, subsetOption));
194 request.appendChild(param_list);
195
196 }
197 message.appendChild(request);
198 //System.out.println(this.converter.getPrettyString(message));
199 /*
200 Element request = GSXML.createBasicRequest(
201 this.doc, GSXML.REQUEST_TYPE_PROCESS,"nwgfril"+"/DocumentMetadataRetrieve","en", "");
202
203Element param_list = this.doc.createElement(
204 GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
205
206param_list.appendChild(GSXML.createParameter(
207 this.doc, "metadata", "all"));
208
209Element documentNode_list = this.doc.createElement(
210 GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
211
212Element documentNode = this.doc.createElement(GSXML.DOC_NODE_ELEM);
213documentNode.setAttribute("nodeID","HASH01981d6a4a1502253e1a2283");
214documentNode_list.appendChild(documentNode);
215
216request.appendChild(param_list);
217request.appendChild(documentNode_list);
218message.appendChild(request);
219System.out.println(this.converter.getPrettyString(message));
220*/
221 // message.appendChild(request);
222 //System.out.println("\nRequest message");
223 //System.out.println(this.converter.getPrettyString(message));
224 //System.out.println(this.converter.getPrettyString(message));
225 //////////////////////////////////////////////////////////////////////////////////////////////
226 ////////////////////////////////////////////////////////////////////////////////////////////////
227 CollectionList = mr.process(message);
228 //System.out.println(this.converter.getPrettyString(CollectionList));
229 //Element response = mr.process(message);
230 //System.out.println(this.converter.getPrettyString(response));
231 //System.out.println("list"+CollectionList);
232 return ">>"+GSXML.MESSAGE_ELEM+"<<";
233 //return request.;
234 }catch(Exception ex){return "failure";}
235 //return this.converter.getPrettyString(message.toString());
236 //return this.converter.getPrettyString(CollectionList);
237
238 }
239
240 public Node getCollectionList(){
241 return CollectionList;
242 }
243
244
245 public void describeMatadata(String collectionName,String OAIURL){
246
247 ms = new MetadataStats(this.site_home,collectionName,OAIURL,"test");
248
249 if(ms.getStatus()){
250 //return;
251 printWebPage(ms);
252 }
253 // Servlet-------------------------------------------------
254 else{
255 System.out.print("<p> The metadataStats fails</p>");
256 }
257 //System.out.println("\nTotal Number of Documents: "+ms.getDocNum());
258 //System.out.println("\n system ends");
259 //System.out.println(ms.metadataNameList.size());
260
261 }
262
263 public void printWebPage(MetadataStats ms){
264 //long startTime=System.currentTimeMillis();
265 DataMaker dm = new DataMaker(ms);
266 String[] elements = new String [ms.metadataNameList.size()];
267
268 for(int i = 0; i<elements.length; i++){
269 elements[i] = (String)ms.metadataNameList.get(i);
270 }
271
272 Arrays.sort(elements);
273 String[] metaDataElementName = (String[])elements.clone();
274 String[] ids = dm.getDocumentIDs("archivedir");
275
276 ArrayList alist = new ArrayList();
277 for(int a = 0; a<elements.length; a++){
278 alist.add(dm.getMetadataRows(elements[a]));
279 }
280 //System.out.println(alist.size()+ " " +ids.length+" "+metaDataElementName.length);
281 PrintHTML phtml = new PrintHTML(ms);
282
283 //?????????????????????????????????????????????????????????????????????????/
284 HashMap hp = ms.getMetadataSetMap();
285 Collection c = hp.values();
286 Iterator i = c.iterator();
287
288 while(i.hasNext()){
289 MetadataSet mds = (MetadataSet)i.next();
290 //if(!mds.getName().equals("extracted")){
291 ArrayList elementList = mds.getIndexsList();
292 String[] mdsElement = new String[elementList.size()];
293 for(int x = 0; x<mdsElement.length; x++){
294 mdsElement[x]=(String)elementList.get(x);
295 }
296 Arrays.sort(mdsElement);
297
298 String[] metaDataElement = (String[])mdsElement.clone();
299 String[] idList = dm.getDocumentIDs("archivedir");
300
301 ArrayList datalist = new ArrayList();
302 for(int a = 0; a<mdsElement.length; a++){
303 datalist.add(dm.getMetadataRows(mdsElement[a]));
304 }
305 phtml.generateAllPossibleGraph(datalist,idList,metaDataElement,mds.getName());
306 //}
307 }
308
309 //??????????????????????????????????????????????????????????????????????????
310 //long startTime=System.currentTimeMillis();
311 //phtml.generateAllPossibleGraph(alist,ids,metaDataElementName,"both");
312 //////////////////////////////////
313 //Now generate chart for individaul mds
314 //????????????????????????????????????????????????????????//
315
316 //long endTime=System.currentTimeMillis();
317 //System.out.println("Total time taken for generating overall Statistics Page "+(endTime-startTime)+ " millisec");
318
319 phtml.generateOverallStatisticsPage(hp);
320
321 Collection cx = ms.getMetadataSetMap().values();
322 Iterator ix = cx.iterator();
323
324 while(ix.hasNext()){
325 MetadataSet temp = (MetadataSet)ix.next();
326 phtml.WriteMetadataSetDetailHTML(temp);
327 phtml.generateMetadataElementDetailPage(temp);
328 }
329 }
330
331
332 public MetadataStats getElementClass()
333 {
334 return ms;
335 }
336
337 public static void main(String[] args) {
338 //DescribeMessager dm = new DescribeMessager();
339 //System.out.println("test");
340 //dm.describe("","","","");
341 //dm.describeMatadata("sampleco","http://researchcommons.waikato.ac.nz/cgi/oai2.cgi");
342 }
343}
344
Note: See TracBrowser for help on using the repository browser.