source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPRetrieve.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.7 KB
Line 
1/*
2 * GS3MGPPRetrieve.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;
25import org.greenstone.gsdl3.util.GS3OID;
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 GS3MGPPRetrieve
35 extends AbstractGS3DocumentRetrieve
36{
37 // Elements used in the config file that are specific to this class
38 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
39
40 private MGPPWrapper mgpp_src = null;
41
42 private String default_level = null;
43 private String mgpp_textdir = null;
44
45 public GS3MGPPRetrieve() {
46 this.mgpp_src = new MGPPWrapper();
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 GS3MGPPRetrieve...");
54
55 // Get the default level out of <defaultLevel> (buildConfig.xml)
56 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
57 if (def != null) {
58 this.default_level = def.getAttribute(GSXML.NAME_ATT);
59 }
60 if (this.default_level == null || this.default_level.equals("")) {
61 System.err.println("Error: default level not specified!");
62 return false;
63 }
64 // System.out.println("Default level: " + default_level_);
65
66 // The location of the MGPP text files
67 mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
68 File.separatorChar + GSFile.collectionTextPath(this.cluster_name);
69
70 // Do generic configuration
71 return super.configure(info, extra_info);
72
73 }
74
75 /** returns the content of a node
76 * should return a nodeContent element:
77 * <nodeContent>text content or other elements</nodeContent>
78 */
79 protected Element getNodeContent(String doc_id) {
80 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
81 // if we have a whole doc id, and the document is hierarchical,
82 // we want to change the id to be the top id of the section
83 // hierarchy
84 doc_id = GS3OID.createOID(doc_id, "1");
85 }
86
87 String doc_num = this.database.OID2MGNum(doc_id);
88 // doc nums have the index prefixed
89 doc_num = doc_num.substring(doc_num.indexOf(".")+1);
90 int doc_int = Integer.parseInt(doc_num);
91
92 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
93
94 String doc_content = "";
95 try {
96 doc_content = this.mgpp_src.getDocument(this.mgpp_textdir,
97 this.default_level,
98 doc_int);
99 doc_content = resolveRelativeLinks(doc_content, doc_id);
100 } catch (Exception e) {
101 System.out.println("exception happended with mgpp_src.getDocument()" + e);
102 doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_int+"\n";
103 }
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.