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

Last change on this file since 29318 was 28966, checked in by kjdon, 10 years ago

Lots of changes. Mainly to do with removing this.doc from everywhere. Document is not thread safe. Now we tend to create a new Document everytime we are starting a new page/message etc. in service this.desc_doc is available as teh document to create service info stuff. But it should only be used for this and not for other messages. newDOM is now static for XMLConverter. method param changes for some GSXML methods.

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