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

Last change on this file since 8674 was 8674, checked in by kjdon, 20 years ago

several changes all at once. GDBMWrapper methods docnum2Oid and oid2Docnum renamed, the content and metadata retrieve methods now look for an extra parameter: ext. this is for doing greenstone 2 relative external links. where you get a url, and you look this up in the database to turn it into a greensotne hash id.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 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// General Java classes
30import java.io.File;
31
32
33/**
34 * A ServiceRack class for retrieval in greenstone 2 MGPP collections
35 *
36 * @author <a href="mailto:[email protected]">Katherine Don</a>
37 * @version $Revision: 8674 $
38 * @see ServiceRack
39 */
40public class GS2MGPPRetrieve
41 extends GS2Retrieve {
42
43 // Parameters used
44 private static final String LEVEL_PARAM = "level";
45
46 // Elements used in the config file that are specific to this class
47 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
48
49 private MGPPWrapper mgpp_src = null;
50
51 private String default_level = null;
52
53
54 /** constructor */
55 public GS2MGPPRetrieve()
56 {
57 this.mgpp_src = new MGPPWrapper();
58 }
59
60
61 /** configure this service */
62 public boolean configure(Element info, Element extra_info)
63 {
64 // Do specific configuration
65 System.out.println("Configuring GS2MGPPRetrieve...");
66
67 // Get the default level out of <defaultLevel> (buildConfig.xml)
68 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
69 if (def != null) {
70 this.default_level = def.getAttribute(GSXML.NAME_ATT);
71 }
72 if (this.default_level == null || this.default_level.equals("")) {
73 System.err.println("Error: default level not specified!");
74 return false;
75 }
76 // System.out.println("Default level: " + default_level_);
77
78 // Do generic configuration
79 return super.configure(info, extra_info);
80 }
81
82
83 /** Retrieve the content of a document */
84 protected Element processDocumentContentRetrieve(Element request)
85 {
86 // Create a new (empty) result message
87 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
88 result.setAttribute(GSXML.FROM_ATT,DOCUMENT_CONTENT_RETRIEVE_SERVICE );
89 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
90
91 // Get the parameters of the request
92 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
93 Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM);
94 boolean extlink = false;
95 if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) {
96 extlink = true;
97 }
98
99 // Get the request doc_list
100 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
101 if (query_doc_list == null) {
102 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
103 return result;
104 }
105 String lang = request.getAttribute(GSXML.LANG_ATT);
106 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
107 result.appendChild(doc_list);
108
109 // The location of the MGPP text files
110 String textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
111 File.separatorChar + GSFile.collectionTextPath(this.cluster_name);
112
113 // Get the documents
114 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
115 GSXML.NODE_ID_ATT);
116 for (int i = 0; i < doc_ids.length; i++) {
117 String doc_id = doc_ids[i];
118 if (extlink) {
119 doc_id = this.gdbm_src.extlink2OID(doc_id);
120 }
121 else if (OID.needsTranslating(doc_id)) {
122 doc_id = this.gdbm_src.translateOID(doc_id);
123 }
124
125 long doc_num = this.gdbm_src.OID2Docnum(doc_id);
126 String doc_content = this.mgpp_src.getDocument(textdir, this.default_level, doc_num);
127 doc_content = resolveTextMacros(doc_content, doc_id, lang);
128
129 // For now, stick it in a text node - eventually should be parsed as xml??
130
131 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
132 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
133 GSXML.addDocText(this.doc, doc, doc_content);
134 doc_list.appendChild(doc);
135
136 }
137
138 return result;
139 }
140}
141
Note: See TracBrowser for help on using the repository browser.