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

Last change on this file since 13575 was 13575, checked in by kjdon, 17 years ago

getNodeContent() now takes lang as a param

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