source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java@ 3851

Last change on this file since 3851 was 3851, checked in by kjdon, 21 years ago

a wide variety of changes, next I will go through and make sure the code is tidy, nad tidy up teh xml a bit, but I wanted to check in all this first.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/*
2 * GS2MGPPRetrieve.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 */
19package org.greenstone.gsdl3.service;
20
21
22// Greenstone classes
23import org.greenstone.mgpp.*;
24import org.greenstone.gsdl3.util.*;
25
26// XML classes
27import org.w3c.dom.Element;
28
29
30/**
31 * A ServiceRack class for retrieval in greenstone 2 MGPP collections
32 *
33 * @author <a href="mailto:[email protected]">Katherine Don</a>
34 * @version $Revision: 3851 $
35 * @see ServiceRack
36 */
37public class GS2MGPPRetrieve
38 extends GS2Retrieve {
39
40 // Parameters used
41 private static final String LEVEL_PARAM = "level";
42
43 // Elements used in the config file that are specific to this class
44 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
45
46 private MGPPWrapper mgpp_src_ = null;
47
48 private String default_level_ = null;
49
50
51 /** constructor */
52 public GS2MGPPRetrieve()
53 {
54 mgpp_src_ = new MGPPWrapper();
55 }
56
57
58 /** configure this service */
59 public boolean configure(Element info)
60 {
61 // Do specific configuration
62 System.out.println("Configuring GS2MGPPRetrieve...");
63
64 // Get the default level out of <defaultLevel> (buildConfig.xml)
65 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
66 if (def != null) {
67 default_level_ = def.getAttribute(GSXML.NAME_ATT);
68 }
69 if (default_level_ == null || default_level_.equals("")) {
70 System.err.println("Error: default level not specified!");
71 return false;
72 }
73 // System.out.println("Default level: " + default_level_);
74
75 // Do generic configuration
76 return super.configure(info);
77 }
78
79
80 /** Retrieve the structure of a document - this function needed as its called specifically on the class name*/
81 protected Element processDocumentStructureRetrieve(Element request)
82 {
83 return super.processDocumentStructureRetrieve(request);
84 }
85
86
87 /** Retrieve metadata associated with a document - this function needed as its called specifically on the class name*/
88 protected Element processDocumentMetadataRetrieve(Element request)
89 {
90 return super.processDocumentMetadataRetrieve(request);
91 }
92
93
94 /** Retrieve the content of a document */
95 protected Element processDocumentContentRetrieve(Element request)
96 {
97 // Create a new (empty) result message
98 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
99 String from = GSPath.appendLink(cluster_name_, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
100 result.setAttribute(GSXML.FROM_ATT, from);
101 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
102 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM);
103 result.appendChild(result_content);
104
105 // Get the parameters of the request
106 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
107 if (param_list == null) {
108 System.err.println("GS2MGPPRetrieve, DocumentContentRetrieve Error: missing paramList.\n");
109 return result; // Return the empty result
110 }
111
112 String level = default_level_;
113
114 // Process the request parameters
115 // are there any???
116 Element param = (Element) param_list.getFirstChild();
117 while (param != null) {
118 if (!param.getNodeName().equals(GSXML.PARAM_ELEM)) {
119 System.err.println("Warning: Non-param in paramList (ignored).");
120 }
121 else {
122 // this looks for a level param but I think we dont use it
123 if (param.getAttribute(GSXML.NAME_ATT) == LEVEL_PARAM) {
124 level = GSXML.getValue(param);
125 System.out.println("Level: " + level);
126 }
127 }
128
129 param = (Element) param.getNextSibling();
130 }
131
132 // Get the request content
133 Element content = (Element) GSXML.getChildByTagName(request, GSXML.CONTENT_ELEM);
134 if (content == null) {
135 System.err.println("Error: DocumentContentRetrieve request had no content.\n");
136 return result;
137 }
138
139 Element doc_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
140 result_content.appendChild(doc_list);
141
142 // The location of the MGPP text files
143 String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_);
144 String textdir = GSFile.collectionTextPath(cluster_name_);
145
146 // Get the documents
147 String[] doc_ids = GSXML.getDocumentNameList(content);
148 for (int i = 0; i < doc_ids.length; i++) {
149 String doc_id = doc_ids[i];
150 long doc_num = gdbm_src_.oid2Docnum(doc_id);
151 String doc_content = mgpp_src_.getDocument(basedir, textdir, level, doc_num);
152
153 // For now, stick it in a text node - eventually should be parsed as xml??
154 Element doc = GSXML.createDocumentElement(doc_, doc_id);
155 GSXML.addDocText(doc_, doc, doc_content);
156 doc_list.appendChild(doc);
157 }
158
159 return result;
160 }
161}
Note: See TracBrowser for help on using the repository browser.