1 | /*
|
---|
2 | * MGPPService.java
|
---|
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 | */
|
---|
19 | package org.greenstone.gsdl3.service;
|
---|
20 |
|
---|
21 | import org.w3c.dom.Document;
|
---|
22 | import org.w3c.dom.Node;
|
---|
23 | import org.w3c.dom.Text;
|
---|
24 | import org.w3c.dom.Element;
|
---|
25 | import org.w3c.dom.NodeList;
|
---|
26 | /**
|
---|
27 | * A Service class for MGPP
|
---|
28 | *
|
---|
29 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
30 | * @version $Revision: 3452 $
|
---|
31 | */
|
---|
32 |
|
---|
33 |
|
---|
34 | public class MGPPService
|
---|
35 | extends ServiceModule {
|
---|
36 |
|
---|
37 | /** passes the request Element to the appropriate service function*/
|
---|
38 | protected Element processService(String name, Element request) {
|
---|
39 |
|
---|
40 | // dont need to check that the service name is supported for this particular object, because that has been checked by ServiceModule
|
---|
41 | if (name.equals("TextQuery")) {
|
---|
42 | return processTextQuery(request);
|
---|
43 | } else if(name.equals("FieldQuery")) {
|
---|
44 | return processFieldQuery(request);
|
---|
45 | } else if (name.equals("DocRetrieve")) {
|
---|
46 | return processDocRetrieve(request);
|
---|
47 | } else if (name.equals("MetadataRetrieve")) {
|
---|
48 | return processMetadataRetrieve(request);
|
---|
49 | }
|
---|
50 |
|
---|
51 | System.err.println("MGPPService:should never get here. service type wrong:"+name);
|
---|
52 | return null;
|
---|
53 |
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | /** configure this service */
|
---|
59 | public boolean configure(Element info) {
|
---|
60 |
|
---|
61 | System.out.println("configuring MGPPService");
|
---|
62 |
|
---|
63 | Element e = null;
|
---|
64 | // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
|
---|
65 | // set up short_service_info_ - for now just has name and type
|
---|
66 | e = doc_.createElement("service");
|
---|
67 | e.setAttribute("type", "query");
|
---|
68 | e.setAttribute("name", "TextQuery");
|
---|
69 | short_service_info_.appendChild(e);
|
---|
70 |
|
---|
71 | e = doc_.createElement("service");
|
---|
72 | e.setAttribute("type", "query");
|
---|
73 | e.setAttribute("name", "FieldQuery");
|
---|
74 | short_service_info_.appendChild(e);
|
---|
75 |
|
---|
76 | e = doc_.createElement("service");
|
---|
77 | e.setAttribute("type", "query");
|
---|
78 | e.setAttribute("name", "DocRetrieve");
|
---|
79 | short_service_info_.appendChild(e);
|
---|
80 |
|
---|
81 | e = doc_.createElement("service");
|
---|
82 | e.setAttribute("type", "query");
|
---|
83 | e.setAttribute("name", "MetadataRetrieve");
|
---|
84 | short_service_info_.appendChild(e);
|
---|
85 |
|
---|
86 | // set up service_info_map_ - for now, just has the same elements as above
|
---|
87 | // should have full details about each service incl params lists etc.
|
---|
88 | e = doc_.createElement("service");
|
---|
89 | e.setAttribute("type", "query");
|
---|
90 | e.setAttribute("name", "TextQuery");
|
---|
91 | service_info_map_.put("TextQuery", e);
|
---|
92 |
|
---|
93 | e = doc_.createElement("service");
|
---|
94 | e.setAttribute("type", "query");
|
---|
95 | e.setAttribute("name", "FieldQuery");
|
---|
96 | service_info_map_.put("FieldQuery", e);
|
---|
97 |
|
---|
98 | e = doc_.createElement("service");
|
---|
99 | e.setAttribute("type", "query");
|
---|
100 | e.setAttribute("name", "DocRetrieve");
|
---|
101 | service_info_map_.put("DocRetrieve", e);
|
---|
102 |
|
---|
103 | e = doc_.createElement("service");
|
---|
104 | e.setAttribute("type", "query");
|
---|
105 | e.setAttribute("name", "MetadataRetrieve");
|
---|
106 | service_info_map_.put("MetadataRetrieve", e);
|
---|
107 | return true;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /** process a text query */
|
---|
111 | protected Element processTextQuery(Element request) {
|
---|
112 | Element result = doc_.createElement("response");
|
---|
113 | result.setAttribute("name", "TextQuery");
|
---|
114 |
|
---|
115 | // dummy result
|
---|
116 | Text t = null;
|
---|
117 | t = doc_.createTextNode("Textquery result... ");
|
---|
118 | result.appendChild(t);
|
---|
119 | return result;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /** process a fielded query */
|
---|
123 | protected Element processFieldQuery(Element request) {
|
---|
124 | Element result = doc_.createElement("response");
|
---|
125 | result.setAttribute("name", "FieldQuery");
|
---|
126 |
|
---|
127 | // dummy result
|
---|
128 | Text t = null;
|
---|
129 | t = doc_.createTextNode("Fieldquery result... ");
|
---|
130 | result.appendChild(t);
|
---|
131 | return result;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** retrieve a document */
|
---|
135 | protected Element processDocRetrieve(Element request) {
|
---|
136 | Element result = doc_.createElement("response");
|
---|
137 | result.setAttribute("name", "DocRetrieve");
|
---|
138 |
|
---|
139 | // dummy result
|
---|
140 | Text t = null;
|
---|
141 | t = doc_.createTextNode("DocRetrieve result... ");
|
---|
142 | result.appendChild(t);
|
---|
143 | return result;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /** retrieve metadata */
|
---|
147 | protected Element processMetadataRetrieve(Element request) {
|
---|
148 | Element result = doc_.createElement("response");
|
---|
149 | result.setAttribute("name", "MetadataRetrieve");
|
---|
150 |
|
---|
151 | // dummy result
|
---|
152 | Text t = null;
|
---|
153 | t = doc_.createTextNode("MetadataRetrieve result... ");
|
---|
154 | result.appendChild(t);
|
---|
155 | return result;
|
---|
156 | }
|
---|
157 |
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|