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

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

merged from branch ant-install-branch: merge 1

  • 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 // Do specific configuration
58 System.out.println("Configuring GS2MGRetrieve...");
59 // System.out.println("info:\n" + converter_.getString(info));
60 // System.out.println("extra_info:\n" + converter_.getString(extra_info));
61
62 // Get the default index out of <defaultIndex> (buildConfig.xml)
63 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
64 if (def != null) {
65 this.default_index = def.getAttribute(GSXML.NAME_ATT);
66 }
67 if (this.default_index == null || this.default_index.equals("")) {
68 System.err.println("Error: default index not specified!");
69 return false;
70 }
71 // System.out.println("Default index: " + this.default_index);
72
73 // The location of the MG index and text files
74 mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG
75 mg_textdir = GSFile.collectionTextPath(this.cluster_name);
76 // index is only needed to start up MG, not used so just use the default index
77 String indexpath = GSFile.collectionIndexPath(this.cluster_name, this.default_index);
78 this.mg_src.setIndex(indexpath);
79
80 // Do generic configuration
81 return super.configure(info, extra_info);
82 }
83
84 /** returns the content of a node
85 * should return a nodeContent element:
86 * <nodeContent>text content or other elements</nodeContent>
87 */
88 protected Element getNodeContent(String doc_id) throws GSException {
89 String lang = "en"; // **********
90 long doc_num = this.gdbm_src.OID2Docnum(doc_id);
91 if (doc_num == -1) {
92 System.err.println("OID "+doc_id +" couldn't be converted to mg num");
93 return null;
94 }
95 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
96
97 String doc_content = this.mg_src.getDocument(this.mg_basedir,
98 this.mg_textdir, doc_num);
99
100 if (doc_content!=null) {
101 // remove any ctrl-c or ctrl-b
102 doc_content = doc_content.replaceAll("\u0002|\u0003", "");
103 // replace _httpimg_ with the correct address
104 doc_content = resolveTextMacros(doc_content, doc_id, lang);
105 //GSXML.addDocText(this.doc, doc, doc_content);
106 } else {
107 System.err.println("the doc content was null, not getting that section\n");
108 doc_content = "couldn't retrieve content for this section\n";
109 }
110 Text t = this.doc.createTextNode(doc_content);
111 content_node.appendChild(t);
112 return content_node;
113
114 }
115
116
117}
Note: See TracBrowser for help on using the repository browser.