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

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

configure takes two args - the xml for teh service plus some optional stuff - eg teh collection configuration file - its up to teh service now to extract what it needs. the query services need the index specific display elements and a general format element, the classifier services need classifier specific display and format stuff.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.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: 3938 $
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, Element extra_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, extra_info);
77 }
78
79
80 /** Retrieve the content of a document */
81 protected Element processDocumentContentRetrieve(Element request)
82 {
83 // Create a new (empty) result message
84 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
85 String from = GSPath.appendLink(cluster_name_, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
86 result.setAttribute(GSXML.FROM_ATT, from);
87 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
88
89 // Get the parameters of the request - not used at the moment
90 //Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
91
92 // Get the request doc_list
93 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
94 if (query_doc_list == null) {
95 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
96 return result;
97 }
98
99 Element doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
100 result.appendChild(doc_list);
101
102 // The location of the MGPP text files
103 String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_);
104 String textdir = GSFile.collectionTextPath(cluster_name_);
105
106 // Get the documents
107 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
108 GSXML.DOC_NODE_ID_ATT);
109 for (int i = 0; i < doc_ids.length; i++) {
110 String doc_id = doc_ids[i];
111
112 if (OID.needsTranslating(doc_id)) {
113 doc_id = gdbm_src_.translateOID(doc_id);
114 }
115
116 long doc_num = gdbm_src_.oid2Docnum(doc_id);
117 String doc_content = mgpp_src_.getDocument(basedir, textdir, default_level_, doc_num);
118
119 // For now, stick it in a text node - eventually should be parsed as xml??
120
121 Element doc = doc_.createElement(GSXML.DOC_NODE_ELEM);
122 doc.setAttribute(GSXML.DOC_NODE_ID_ATT, doc_id);
123 GSXML.addDocText(doc_, doc, doc_content);
124 doc_list.appendChild(doc);
125
126 }
127
128 return result;
129 }
130}
131
Note: See TracBrowser for help on using the repository browser.