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

Last change on this file since 13576 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
RevLine 
[3649]1/*
2 * GS2MGRetrieve.java
[8959]3 * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
[3649]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
[3799]21// Greenstone classes
[3754]22import org.greenstone.mg.*;
[9874]23import org.greenstone.gsdl3.core.GSException;
[8959]24import org.greenstone.gsdl3.util.GSFile;
25import org.greenstone.gsdl3.util.GSXML;
[3649]26
[3799]27// XML classes
28import org.w3c.dom.Element;
[8959]29import org.w3c.dom.Text;
[3754]30
[3799]31// General Java classes
[3754]32import java.io.File;
33
[13124]34import org.apache.log4j.*;
35
[3649]36public class GS2MGRetrieve
[8959]37 extends AbstractGS2DocumentRetrieve
38{
[13270]39 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGRetrieve.class.getName());
[13124]40
[3799]41 // Elements used in the config file that are specific to this class
[3754]42 private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
[13567]43 private static final String INDEX_LIST_ELEM = "indexList";
44 private static final String INDEX_ELEM = "index";
[3754]45
[5098]46 private MGWrapper mg_src = null;
[8959]47 private String mg_basedir = null;
48 private String mg_textdir = null;
[5098]49 private String default_index = null;
[13567]50 private boolean has_default_index = false;
[8959]51
52 public GS2MGRetrieve() {
[5098]53 this.mg_src = new MGWrapper();
[3649]54 }
55
[9874]56 public void cleanUp() {
57 super.cleanUp();
58 this.mg_src.unloadIndexData();
59 }
60
[3649]61 /** configure this service */
[3938]62 public boolean configure(Element info, Element extra_info)
[3754]63 {
[10093]64 if (!super.configure(info, extra_info)){
65 return false;
66 }
67
[3799]68 // Do specific configuration
[13124]69 logger.info("Configuring GS2MGRetrieve...");
70
[3799]71 // Get the default index out of <defaultIndex> (buildConfig.xml)
[3754]72 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
73 if (def != null) {
[5098]74 this.default_index = def.getAttribute(GSXML.NAME_ATT);
[3754]75 }
[5098]76 if (this.default_index == null || this.default_index.equals("")) {
[13567]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 //}
[3754]81 }
[13124]82 logger.debug("Default index: " + this.default_index);
[13567]83
[8959]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
[10651]86 mg_textdir = GSFile.collectionTextPath(this.index_stem);
[8959]87 // index is only needed to start up MG, not used so just use the default index
[10651]88 String indexpath = GSFile.collectionIndexPath(this.index_stem, this.default_index);
[8959]89 this.mg_src.setIndex(indexpath);
[13567]90 has_default_index = true;
[10093]91 return true;
[3799]92 }
[8959]93
94 /** returns the content of a node
95 * should return a nodeContent element:
96 * <nodeContent>text content or other elements</nodeContent>
97 */
[13575]98 protected Element getNodeContent(String doc_id, String lang) throws GSException {
[8959]99 long doc_num = this.gdbm_src.OID2Docnum(doc_id);
100 if (doc_num == -1) {
[13124]101 logger.error("OID "+doc_id +" couldn't be converted to mg num");
[8959]102 return null;
[8674]103 }
[8959]104 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
[3862]105
[13567]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
[8959]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 {
[13124]121 logger.error("the doc content was null, not getting that section\n");
[13567]122 doc_content = "couldn't retrieve content for this section, please check the log file for more detail\n";
[3754]123 }
[8959]124 Text t = this.doc.createTextNode(doc_content);
125 content_node.appendChild(t);
126 return content_node;
[3649]127
128 }
[8959]129
130
[3990]131}
Note: See TracBrowser for help on using the repository browser.