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

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

restructured the retrieval classes. split apart browsing and doc retrieval into two classes, inplemented an abstract base class for each which new services can inherit

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