source: other-projects/trunk/greenstone3-extension/mat/src/org/greenstone/gsdl3_extension/mat/DescribeMessenger.java@ 18000

Last change on this file since 18000 was 18000, checked in by cc108, 15 years ago

new source code

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