source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GsdlCollageBrowse.java@ 38881

Last change on this file since 38881 was 38881, checked in by anupama, 2 months ago

It was hard to solve why GsdlCollageApplet didn't work as well when run as an application. There were two issues. 1. The order of creating the applet/application matters (it needs a size). This mattered for bypassing createImage returning null in DisplayImages.java at the start. 2. Once the application finally appeared, no longer bogged down by a null pointer exception since before it finished initialising, the display_thread and download_thread were null. It was very basic. The main() method added to run the applet as an application was never calling the start() method. Only init() got called. An applet init(), then start() are automatically called by the browser/appletviewer, and I presume when the user quits the applet's browser window, that an actual applet stop() and destroy() are called. However, as the Phind applet only had init() and no start() or stop(), I had blindly imitated its main() and custom application constructor, which only ever called init(). So once I called start(), the download_thread and display_thread were both instantiated and the applet started working when run as an application at last! I also now call stop() on WindowClosing to do the cleanup. So this is proof of concept. Applet mode of GsdlCollageApplet run through the appletviewer would display the applet window and present an infinite Downloading... message, but be unable to download images due to security exceptions. The application run through the commandline is able to now download the images. So no security exception, oddly enough. Is the difference because appletviewer has sandbox/security restrictions? Webswing running GsdlCollageApplet is still stuck with the original null pointer exception: the window does not display early enough for the size to be set and displayimages to start. Maybe there's an OnShow event handler where I can instantiate the displayImages thread. But fingers crossed, I may be able to get Webswing to run the GsdlCollageApplet as an application. That will be the next step. Further problems remain: GS2 never gave the applet the URL to the Image browsing classifier CL2.3, but to the actual Collage classifier (CL3.1). I have to give it the CL2.3 classifier, because GS2's image directory is straighforwardly located. So more thinking is required on that, among other outstanding issues.

File size: 6.9 KB
Line 
1/*
2 * GsdlCollage Services java file
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21import org.greenstone.gsdl3.util.*;
22
23import org.greenstone.mgpp.*;
24import org.w3c.dom.Document;
25import org.w3c.dom.Node;
26import org.w3c.dom.Element;
27import org.w3c.dom.Text;
28
29import java.util.Vector;
30import java.util.HashMap;
31import java.io.File;
32import java.io.Serializable;
33
34import org.apache.log4j.*;
35
36/**
37 * GsdlCollageServices - the gsdl collage browsing service
38 *
39 */
40public class GsdlCollageBrowse
41 extends ServiceRack {
42
43 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GsdlCollageBrowse.class.getName());
44
45 // the services on offer
46 private static final String GSDL_COLLAGE_SERVICE = "GsdlCollageApplet";
47
48 private String basepath = null;
49
50 private Element applet_description = null;
51
52 public GsdlCollageBrowse() {
53 super();
54 }
55
56 public void cleanUp() {
57 super.cleanUp();
58
59 }
60
61 /** configure the service module
62 *
63 * @param info a DOM Element containing any config info for the service
64 * @return true if configured
65 */
66 public boolean configure(Element info, Element extra_info) {
67
68 if (!super.configure(info, extra_info)){
69 return false;
70 }
71
72 logger.info("configuring GsdlCollageBrowse");
73
74 // set up short_service_info_ - for now just has name and type
75 Element e = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
76 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_APPLET);
77 e.setAttribute(GSXML.NAME_ATT, GSDL_COLLAGE_SERVICE);
78 this.short_service_info.appendChild(e);
79
80 // set up the static applet description
81
82 applet_description = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
83 applet_description.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_APPLET);
84 applet_description.setAttribute(GSXML.NAME_ATT, GSDL_COLLAGE_SERVICE);
85
86 // add in the applet info for the gsdl collage applet
87 // need to make this dynamic - library names etc
88 // change the applet params - have a single param with the library name
89 // this is left blank at this end, and must be filled in by applet action - if the library name is not needed, this param is left out
90
91 String app_info = "<"+GSXML.APPLET_ELEM+" CODEBASE='applet' CODE='org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet.class' ARCHIVE='GsdlCollageApplet.jar' WIDTH='600' HEIGHT='300'>"; // w=645,h=780
92 app_info +="<param name='library' value='library'/>"; // TODO
93 app_info +="<param name='collection' value='";
94 app_info += this.cluster_name + "'/>";
95 //app_info += "<param name='gwcgi' value='http://localhost:8383/greenstone3/library' /><param name='classifier' value='CL3.1' /><param name='hrefMustHave' value='CL3' /><param name='imageMustNotHave' value='hl=%x=%gt=%gc=%.pr' /><param name='imageType' value='.jpg%%.png' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
96 app_info += "<param name='gsdlversion' value='3' />";
97 app_info += "<param name='baseurl' value='http://localhost:8383/greenstone3/' />";
98 app_info += "<param name='sitename' value='localsite' />\n";
99 //app_info += "<param name='documentroot' value='library/collection/" + this.cluster_name + "/'/>";
100 app_info += "<param name='documentroot' value='greenstone3'/>\n";
101 app_info += "<param name='verbosity' value='3' />\n";
102 app_info += "<param name='imageType' value='.jpg%%.png' />\n";
103 //app_info += "<param name='hrefMustHave' value='smallbea' />\n";
104 //app_info += "<param name='imageMustNotHave' value='hl=%x=%gt=%gc=%.pr' />\n";
105 app_info += "<param name='imageMustNotHave' value='interfaces/' />\n";
106 app_info += "<param name='gwcgi' value='http://localhost:8383/greenstone3/library/collection/smallbea/' /><param name='classifier' value='CL2.3' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
107
108 Document dom = this.converter.getDOM(app_info);
109 if (dom==null) {
110 logger.error("Couldn't parse applet info");
111 return false;
112 }
113 Element app_elem = dom.getDocumentElement();
114 applet_description.appendChild(this.desc_doc.importNode(app_elem, true));
115
116 return true;
117 }
118
119 protected Element getServiceDescription(Document doc, String service, String lang, String subset) {
120 if (!service.equals(GSDL_COLLAGE_SERVICE)) {
121 return null;
122 }
123 Element describe = (Element)doc.importNode(applet_description,true);
124
125 Element el1 = GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME, getTextString(GSDL_COLLAGE_SERVICE+".name", lang));
126 describe.appendChild(el1);
127
128 Element el2 = GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(GSDL_COLLAGE_SERVICE+".description", lang));
129 describe.appendChild(el2);
130
131 return describe;
132 }
133
134 protected Element processGsdlCollageApplet(Element request) {
135 Document result_doc = XMLConverter.newDOM();
136
137 // the result element
138 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
139 result.setAttribute(GSXML.FROM_ATT, GSDL_COLLAGE_SERVICE);
140 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
141
142 // applet result info must be in appletInfo element
143 Element applet_data = result_doc.createElement(GSXML.APPLET_DATA_ELEM);
144 result.appendChild(applet_data);
145 Element gsdlCollage_data = result_doc.createElement("gsdlCollageData");
146 applet_data.appendChild(gsdlCollage_data);
147
148 gsdlCollage_data.appendChild(result_doc.createTextNode("TODO: GsdlCollage applet doesn't actually do any processing"));
149
150 return result;
151
152
153 }// processGsdlCollageApplet
154
155 protected Element gsdlCollageError(Document collage_doc, String message) {
156 Element e = collage_doc.createElement("gsdlCollageError");
157 Text t = collage_doc.createTextNode(message);
158 e.appendChild(t);
159 return e;
160 }
161
162}
163
Note: See TracBrowser for help on using the repository browser.