source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java@ 10651

Last change on this file since 10651 was 10651, checked in by kjdon, 19 years ago

made all index/gdbm db paths use indexstem instead of cluster_name

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/*
2 * GS2MGRetrieve.java
3 * Copyright (C) 2005 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// Greenstone classes
22import org.greenstone.mg.*;
23import org.greenstone.gsdl3.core.GSException;
24import org.greenstone.gsdl3.util.GSFile;
25import org.greenstone.gsdl3.util.GSXML;
26
27// XML classes
28import org.w3c.dom.Element;
29import org.w3c.dom.Text;
30
31// General Java classes
32import java.io.File;
33
34public class GS2MGRetrieve
35 extends AbstractGS2DocumentRetrieve
36{
37 // Elements used in the config file that are specific to this class
38 private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
39
40 private MGWrapper mg_src = null;
41 private String mg_basedir = null;
42 private String mg_textdir = null;
43 private String default_index = null;
44
45 public GS2MGRetrieve() {
46 this.mg_src = new MGWrapper();
47 }
48
49 public void cleanUp() {
50 super.cleanUp();
51 this.mg_src.unloadIndexData();
52 }
53
54 /** configure this service */
55 public boolean configure(Element info, Element extra_info)
56 {
57 if (!super.configure(info, extra_info)){
58 return false;
59 }
60
61 // Do specific configuration
62 System.out.println("Configuring GS2MGRetrieve...");
63 // System.out.println("info:\n" + converter_.getString(info));
64 // System.out.println("extra_info:\n" + converter_.getString(extra_info));
65
66 // Get the default index out of <defaultIndex> (buildConfig.xml)
67 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
68 if (def != null) {
69 this.default_index = def.getAttribute(GSXML.NAME_ATT);
70 }
71 if (this.default_index == null || this.default_index.equals("")) {
72 System.err.println("Error: default index not specified!");
73 return false;
74 }
75 // System.out.println("Default index: " + this.default_index);
76
77 // The location of the MG index and text files
78 mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG
79 mg_textdir = GSFile.collectionTextPath(this.index_stem);
80 // index is only needed to start up MG, not used so just use the default index
81 String indexpath = GSFile.collectionIndexPath(this.index_stem, this.default_index);
82 this.mg_src.setIndex(indexpath);
83
84 return true;
85 }
86
87 /** returns the content of a node
88 * should return a nodeContent element:
89 * <nodeContent>text content or other elements</nodeContent>
90 */
91 protected Element getNodeContent(String doc_id) throws GSException {
92 String lang = "en"; // **********
93 long doc_num = this.gdbm_src.OID2Docnum(doc_id);
94 if (doc_num == -1) {
95 System.err.println("OID "+doc_id +" couldn't be converted to mg num");
96 return null;
97 }
98 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
99
100 String doc_content = this.mg_src.getDocument(this.mg_basedir,
101 this.mg_textdir, doc_num);
102
103 if (doc_content!=null) {
104 // remove any ctrl-c or ctrl-b
105 doc_content = doc_content.replaceAll("\u0002|\u0003", "");
106 // replace _httpimg_ with the correct address
107 doc_content = resolveTextMacros(doc_content, doc_id, lang);
108 //GSXML.addDocText(this.doc, doc, doc_content);
109 } else {
110 System.err.println("the doc content was null, not getting that section\n");
111 doc_content = "couldn't retrieve content for this section\n";
112 }
113 Text t = this.doc.createTextNode(doc_content);
114 content_node.appendChild(t);
115 return content_node;
116
117 }
118
119
120}
Note: See TracBrowser for help on using the repository browser.