[3649] | 1 | /*
|
---|
| 2 | * GS2MGRetrieve.java
|
---|
[8959] | 3 | * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
|
---|
[3649] | 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 | */
|
---|
| 19 | package org.greenstone.gsdl3.service;
|
---|
| 20 |
|
---|
[3799] | 21 | // Greenstone classes
|
---|
[3754] | 22 | import org.greenstone.mg.*;
|
---|
[9874] | 23 | import org.greenstone.gsdl3.core.GSException;
|
---|
[8959] | 24 | import org.greenstone.gsdl3.util.GSFile;
|
---|
| 25 | import org.greenstone.gsdl3.util.GSXML;
|
---|
[3649] | 26 |
|
---|
[3799] | 27 | // XML classes
|
---|
| 28 | import org.w3c.dom.Element;
|
---|
[8959] | 29 | import org.w3c.dom.Text;
|
---|
[3754] | 30 |
|
---|
[3799] | 31 | // General Java classes
|
---|
[3754] | 32 | import java.io.File;
|
---|
| 33 |
|
---|
[13124] | 34 | import org.apache.log4j.*;
|
---|
| 35 |
|
---|
[3649] | 36 | public class GS2MGRetrieve
|
---|
[8959] | 37 | extends AbstractGS2DocumentRetrieve
|
---|
| 38 | {
|
---|
[13270] | 39 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGRetrieve.class.getName());
|
---|
[13124] | 40 |
|
---|
[3799] | 41 | // Elements used in the config file that are specific to this class
|
---|
[3754] | 42 | private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
|
---|
[13567] | 43 | private static final String INDEX_LIST_ELEM = "indexList";
|
---|
| 44 | private static final String INDEX_ELEM = "index";
|
---|
[3754] | 45 |
|
---|
[5098] | 46 | private MGWrapper mg_src = null;
|
---|
[8959] | 47 | private String mg_basedir = null;
|
---|
| 48 | private String mg_textdir = null;
|
---|
[5098] | 49 | private String default_index = null;
|
---|
[13567] | 50 | private boolean has_default_index = false;
|
---|
[8959] | 51 |
|
---|
| 52 | public GS2MGRetrieve() {
|
---|
[5098] | 53 | this.mg_src = new MGWrapper();
|
---|
[3649] | 54 | }
|
---|
| 55 |
|
---|
[9874] | 56 | public void cleanUp() {
|
---|
| 57 | super.cleanUp();
|
---|
| 58 | this.mg_src.unloadIndexData();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[3649] | 61 | /** configure this service */
|
---|
[3938] | 62 | public boolean configure(Element info, Element extra_info)
|
---|
[3754] | 63 | {
|
---|
[10093] | 64 | if (!super.configure(info, extra_info)){
|
---|
| 65 | return false;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[3799] | 68 | // Do specific configuration
|
---|
[13124] | 69 | logger.info("Configuring GS2MGRetrieve...");
|
---|
| 70 |
|
---|
[3799] | 71 | // Get the default index out of <defaultIndex> (buildConfig.xml)
|
---|
[3754] | 72 | Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
|
---|
| 73 | if (def != null) {
|
---|
[5098] | 74 | this.default_index = def.getAttribute(GSXML.NAME_ATT);
|
---|
[3754] | 75 | }
|
---|
[5098] | 76 | if (this.default_index == null || this.default_index.equals("")) {
|
---|
[13567] | 77 | logger.error("default index is not specified, the content of a document will not be retrieved");
|
---|
| 78 | has_default_index = false;
|
---|
| 79 | return true;
|
---|
| 80 | //}
|
---|
[3754] | 81 | }
|
---|
[13124] | 82 | logger.debug("Default index: " + this.default_index);
|
---|
[13567] | 83 |
|
---|
[8959] | 84 | // The location of the MG index and text files
|
---|
| 85 | mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG
|
---|
[10651] | 86 | mg_textdir = GSFile.collectionTextPath(this.index_stem);
|
---|
[8959] | 87 | // index is only needed to start up MG, not used so just use the default index
|
---|
[10651] | 88 | String indexpath = GSFile.collectionIndexPath(this.index_stem, this.default_index);
|
---|
[8959] | 89 | this.mg_src.setIndex(indexpath);
|
---|
[13567] | 90 | has_default_index = true;
|
---|
[10093] | 91 | return true;
|
---|
[3799] | 92 | }
|
---|
[8959] | 93 |
|
---|
| 94 | /** returns the content of a node
|
---|
| 95 | * should return a nodeContent element:
|
---|
| 96 | * <nodeContent>text content or other elements</nodeContent>
|
---|
| 97 | */
|
---|
[9874] | 98 | protected Element getNodeContent(String doc_id) throws GSException {
|
---|
[8959] | 99 | String lang = "en"; // **********
|
---|
| 100 | long doc_num = this.gdbm_src.OID2Docnum(doc_id);
|
---|
| 101 | if (doc_num == -1) {
|
---|
[13124] | 102 | logger.error("OID "+doc_id +" couldn't be converted to mg num");
|
---|
[8959] | 103 | return null;
|
---|
[8674] | 104 | }
|
---|
[8959] | 105 | Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
|
---|
[3862] | 106 |
|
---|
[13567] | 107 |
|
---|
| 108 | String doc_content = null;
|
---|
| 109 |
|
---|
| 110 | if (has_default_index ){
|
---|
| 111 | doc_content = this.mg_src.getDocument(this.mg_basedir,
|
---|
| 112 | this.mg_textdir, doc_num);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[8959] | 115 | if (doc_content!=null) {
|
---|
| 116 | // remove any ctrl-c or ctrl-b
|
---|
| 117 | doc_content = doc_content.replaceAll("\u0002|\u0003", "");
|
---|
| 118 | // replace _httpimg_ with the correct address
|
---|
| 119 | doc_content = resolveTextMacros(doc_content, doc_id, lang);
|
---|
| 120 | //GSXML.addDocText(this.doc, doc, doc_content);
|
---|
| 121 | } else {
|
---|
[13124] | 122 | logger.error("the doc content was null, not getting that section\n");
|
---|
[13567] | 123 | doc_content = "couldn't retrieve content for this section, please check the log file for more detail\n";
|
---|
[3754] | 124 | }
|
---|
[8959] | 125 | Text t = this.doc.createTextNode(doc_content);
|
---|
| 126 | content_node.appendChild(t);
|
---|
| 127 | return content_node;
|
---|
[3649] | 128 |
|
---|
| 129 | }
|
---|
[8959] | 130 |
|
---|
| 131 |
|
---|
[3990] | 132 | }
|
---|