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

Last change on this file since 14000 was 14000, checked in by qq6, 17 years ago

add parameters:defaultIndexSubcollection, defaultIndexLanguage

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