source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.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.5 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.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 GS2MGPPRetrieve
34 extends AbstractGS2DocumentRetrieve
35{
36 // Parameters used
37 private static final String LEVEL_PARAM = "level";
38
39 // Elements used in the config file that are specific to this class
40 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
41
42 private MGPPWrapper mgpp_src = null;
43
44 private String default_level = null;
45 private String mgpp_textdir = null;
46
47 public GS2MGPPRetrieve() {
48 this.mgpp_src = new MGPPWrapper();
49 }
50
51 /** configure this service */
52 public boolean configure(Element info, Element extra_info)
53 {
54 // Do specific configuration
55 System.out.println("Configuring GS2MGPPRetrieve...");
56
57 // Get the default level out of <defaultLevel> (buildConfig.xml)
58 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
59 if (def != null) {
60 this.default_level = def.getAttribute(GSXML.NAME_ATT);
61 }
62 if (this.default_level == null || this.default_level.equals("")) {
63 System.err.println("Error: default level not specified!");
64 return false;
65 }
66 // System.out.println("Default level: " + default_level_);
67
68 // The location of the MGPP text files
69 mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
70 File.separatorChar + GSFile.collectionTextPath(this.cluster_name);
71
72 // Do generic configuration
73 return super.configure(info, extra_info);
74
75 }
76
77 /** returns the content of a node
78 * should return a nodeContent element:
79 * <nodeContent>text content or other elements</nodeContent>
80 */
81 protected Element getNodeContent(String doc_id) {
82 String lang = "en"; // **********
83 long doc_num = this.gdbm_src.OID2Docnum(doc_id);
84 if (doc_num == -1) {
85 System.err.println("OID "+doc_id +" couldn't be converted to mgpp num");
86 return null;
87 }
88 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
89
90 String doc_content = "";
91 try {
92 doc_content = this.mgpp_src.getDocument(this.mgpp_textdir,
93 this.default_level,
94 doc_num);
95 if (doc_content != null) {
96 doc_content = resolveTextMacros(doc_content, doc_id, lang);
97 }
98 } catch (Exception e) {
99 System.out.println("exception happended with mgpp_src.getDocument()" + e);
100 doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n";
101
102 }
103 Text t = this.doc.createTextNode(doc_content);
104 content_node.appendChild(t);
105 return content_node;
106
107 }
108
109
110}
Note: See TracBrowser for help on using the repository browser.