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

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

new xml format - removed content from request and response, document has been renamed documentNode

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 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: 3862 $
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 - not used at the moment
106 //Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
107
108 // Get the request doc_list
109 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
110 if (query_doc_list == null) {
111 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
112 return result;
113 }
114
115 Element doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
116 result.appendChild(doc_list);
117
118 // The location of the MGPP text files
119 String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_);
120 String textdir = GSFile.collectionTextPath(cluster_name_);
121
122 // Get the documents
123 //String[] doc_ids = GSXML.getDocumentNameList(content);
124 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
125 GSXML.DOC_NODE_ID_ATT);
126 for (int i = 0; i < doc_ids.length; i++) {
127 String doc_id = doc_ids[i];
128 long doc_num = gdbm_src_.oid2Docnum(doc_id);
129 String doc_content = mgpp_src_.getDocument(basedir, textdir, default_level_, doc_num);
130
131 // For now, stick it in a text node - eventually should be parsed as xml??
132
133 Element doc = doc_.createElement(GSXML.DOC_NODE_ELEM);
134 doc.setAttribute(GSXML.DOC_NODE_ID_ATT, doc_id);
135 GSXML.addDocText(doc_, doc, doc_content);
136 doc_list.appendChild(doc);
137
138 }
139
140 return result;
141 }
142}
Note: See TracBrowser for help on using the repository browser.