source: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java@ 9815

Last change on this file since 9815 was 9815, checked in by kjdon, 19 years ago

some methods from documentretrieve classes now throw GSExceptions. am trying to make it so that no Exceptions get to the user interface. returning a lot more error elements too, in the hope that they may be useful for other people

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