source: greenstone3/trunk/resources/java/MyNewServicesTemplate.java@ 20126

Last change on this file since 20126 was 20126, checked in by kjdon, 15 years ago

made it part of service package

File size: 5.4 KB
Line 
1/*
2 * MyNewServicesTemplate.java - a dummy class showing how to create new
3 * services for Greenstone3
4 *
5 * This class has two dummy services: TextQuery and MyDifferentService
6 */
7
8// This file needs to be put in org/greenstone/gsdl3/service
9package org.greenstone.gsdl3.service;
10
11// Greenstone classes
12import org.greenstone.gsdl3.util.*;
13
14// XML classes
15import org.w3c.dom.Document;
16import org.w3c.dom.Element;
17import org.w3c.dom.NodeList;
18
19import org.apache.log4j.*;
20
21// change the class name (and the filename) to something more appropriate
22public class MyNewServicesTemplate
23 extends ServiceRack {
24
25 // add in a logger for error messages
26 static Logger logger = Logger.getLogger("MyNewServicesTemplate");
27
28 // the new service names
29 protected static final String QUERY_SERVICE = "TextQuery";
30 protected static final String DIFFERENT_SERVICE = "MyDifferentService";
31
32 // initialize any custom variables
33 public MyNewServicesTemplate() {
34
35 }
36
37 // clean up anything that we need to
38 public void cleanUp() {
39 super.cleanUp();
40 }
41
42 // Configure the class based in info in buildConfig.xml and collectionConfig.xml
43 // info is the <serviceRack name="MyNewServicesTemplate"/> element from
44 // buildConfig.xml, and extra_info is the whole collectionConfig.xml file
45 // in case its needed
46 public boolean configure(Element info, Element extra_info) {
47
48 if (!super.configure(info, extra_info)) {
49 return false;
50 }
51
52 logger.info("Configuring MyNewServicesTemplate...");
53
54 // set up short_service_info - this currently is a list of services,
55 // with their names and service types
56 // we have two services, a new textquery, and a new one of a new type
57 Element tq_service = this.doc.createElement(GSXML.SERVICE_ELEM);
58 tq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
59 tq_service.setAttribute(GSXML.NAME_ATT, QUERY_SERVICE);
60 this.short_service_info.appendChild(tq_service);
61
62 Element diff_service = this.doc.createElement(GSXML.SERVICE_ELEM);
63 diff_service.setAttribute(GSXML.TYPE_ATT, "xxx");
64 diff_service.setAttribute(GSXML.NAME_ATT, DIFFERENT_SERVICE);
65 this.short_service_info.appendChild(diff_service);
66
67
68 // Extract any relevant information from info and extra_info
69 // This can be used to set up variables.
70
71 // If there is any formatting information, add it in to format_info_map
72
73 // Do this for all services as appropriate
74 Element format = null; // find it from info/extra_info
75 if (format != null) {
76 this.format_info_map.put(QUERY_SERVICE, this.doc.importNode(format, true));
77 }
78
79 return true;
80
81 }
82
83 // get the desription of a service. Could include parameter lists, displayText
84 protected Element getServiceDescription(String service, String lang, String subset) {
85
86 // check that we have been asked for the right service
87 if (!service.equals(QUERY_SERVICE) && !service.equals(DIFFERENT_SERVICE)) {
88 return null;
89 }
90
91 if (service.equals(QUERY_SERVICE)) {
92 Element tq_service = this.doc.createElement(GSXML.SERVICE_ELEM);
93 tq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
94 tq_service.setAttribute(GSXML.NAME_ATT, QUERY_SERVICE);
95 if (subset==null || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
96 // add in any <displayText> elements
97 // name, for example - get from properties file
98 tq_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(QUERY_SERVICE+".name", lang) ));
99 }
100
101 if (subset==null || subset.equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) {
102 // add in a param list if this service has parameters
103 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
104 tq_service.appendChild(param_list);
105 // create any params and append to param_list
106 }
107 return tq_service;
108 }
109
110 if (service.equals(DIFFERENT_SERVICE)) {
111 Element diff_service = this.doc.createElement(GSXML.SERVICE_ELEM);
112 diff_service.setAttribute(GSXML.TYPE_ATT, "xxx");
113 diff_service.setAttribute(GSXML.NAME_ATT, DIFFERENT_SERVICE);
114 if (subset==null || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
115 // add in any <displayText> elements
116 // name, for example - get from properties file
117 diff_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(DIFFERENT_SERVICE+".name", lang) ));
118 }
119
120 if (subset==null || subset.equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) {
121 // add in a param list if this service has parameters
122 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
123 diff_service.appendChild(param_list);
124 // create any params and append to param_list
125 }
126
127 return diff_service;
128 }
129
130 // not a valid service for this class
131 return null;
132
133
134
135 }
136
137 /** This is the method that actually handles the TextQuery Service */
138 protected Element processTextQuery(Element request) {
139
140 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
141 result.setAttribute(GSXML.FROM_ATT, QUERY_SERVICE);
142 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
143
144 // fill in the rest
145 return result;
146 }
147
148 /** This is the method that actually handles the MyDifferentService service */
149 protected Element processMyDifferentService(Element request) {
150
151 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
152 result.setAttribute(GSXML.FROM_ATT, DIFFERENT_SERVICE);
153 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
154
155 // fill in the rest
156 return result;
157 }
158}
159
160
161
Note: See TracBrowser for help on using the repository browser.