source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java@ 21768

Last change on this file since 21768 was 21768, checked in by ak19, 14 years ago

Removing the Doc and Sec opening and closing tags, since they interfere with the validity of the html pages output (also cases of unevenly matched tags noticed).

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/*
2 * GS2MGPPRetrieve.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.mgpp.*;
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 GS2MGPPRetrieve
37 extends AbstractGS2DocumentRetrieve {
38 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGPPRetrieve.class.getName());
39
40 // Parameters used
41 private static final String LEVEL_PARAM = "level";
42
43 // Elements used in the config file that are specific to this class
44 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
45
46 private static MGPPRetrieveWrapper mgpp_src = null;
47
48 private String default_level = null;
49 private String mgpp_textdir = null;
50
51 public GS2MGPPRetrieve() {
52 if(mgpp_src == null) {
53 mgpp_src = new MGPPRetrieveWrapper();
54 }
55 }
56
57 public void cleanUp() {
58 super.cleanUp();
59 }
60
61 /** configure this service */
62 public boolean configure(Element info, Element extra_info) {
63 if (!super.configure(info, extra_info)){
64 return false;
65 }
66
67 // Do specific configuration
68 logger.info("Configuring GS2MGPPRetrieve...");
69
70 // Get the default level out of <defaultLevel> (buildConfig.xml)
71 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
72 if (def != null) {
73 this.default_level = def.getAttribute(GSXML.SHORTNAME_ATT);
74 }
75 if (this.default_level == null || this.default_level.equals("")) {
76 logger.error("default level not specified!");
77 return false;
78 }
79
80 // The location of the MGPP text files
81 mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
82 File.separatorChar + GSFile.collectionTextPath(this.index_stem);
83
84 // Do generic configuration
85 return true;
86
87 }
88
89 /** returns the content of a node
90 * should return a nodeContent element:
91 * <nodeContent>text content or other elements</nodeContent>
92 */
93 protected Element getNodeContent(String doc_id, String lang) throws GSException {
94 long doc_num = this.coll_db.OID2DocnumLong(doc_id);
95 if (doc_num == -1) {
96 logger.error("OID "+doc_id +" couldn't be converted to mgpp num");
97 return null;
98 }
99 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
100 synchronized (mgpp_src) {
101 String doc_content = "";
102 try {
103
104 doc_content = mgpp_src.getDocument(this.mgpp_textdir,
105 this.default_level,
106 doc_num);
107
108 if (doc_content != null) {
109 doc_content = resolveTextMacros(doc_content, doc_id, lang);
110 }
111
112 // remove the <Doc></Doc> and <Sec></Sec> tags
113 //doc_content = doc_content.replace("<Doc>", "").replace("</Doc>", "").replace("<Sec>", "").replace("</Sec>", "");
114 doc_content = doc_content.replaceAll("</?(Doc|Sec)>", "");
115 } catch (Exception e) {
116 logger.info("exception happended with mgpp_src.getDocument()" + e);
117 doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n";
118
119 }
120 Text t = this.doc.createTextNode(doc_content);
121 content_node.appendChild(t);
122 return content_node;
123 }//end of synchronized
124 }
125
126
127}
Note: See TracBrowser for help on using the repository browser.