[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
|
---|
[14431] | 37 | extends AbstractGS2DocumentRetrieve {
|
---|
| 38 | static Logger logger = Logger.getLogger (org.greenstone.gsdl3.service.GS2MGRetrieve.class.getName ());
|
---|
| 39 |
|
---|
[3799] | 40 | // Elements used in the config file that are specific to this class
|
---|
[3754] | 41 | private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
|
---|
[13567] | 42 | private static final String INDEX_LIST_ELEM = "indexList";
|
---|
| 43 | private static final String INDEX_ELEM = "index";
|
---|
[14000] | 44 | private static final String DEFAULT_INDEX_SUBCOLLECTION_ELEM = "defaultIndexSubcollection";
|
---|
| 45 | private static final String DEFAULT_INDEX_LANGUAGE_ELEM = "defaultIndexLanguage";
|
---|
[14431] | 46 |
|
---|
| 47 | private MGRetrieveWrapper mg_src = null;
|
---|
| 48 | // private MGWrapper mg_src = null;
|
---|
| 49 |
|
---|
[8959] | 50 | private String mg_basedir = null;
|
---|
| 51 | private String mg_textdir = null;
|
---|
[5098] | 52 | private String default_index = null;
|
---|
[13567] | 53 | private boolean has_default_index = false;
|
---|
[14431] | 54 |
|
---|
| 55 | public GS2MGRetrieve () {
|
---|
| 56 | this.mg_src = new MGRetrieveWrapper ();
|
---|
[3649] | 57 | }
|
---|
[14431] | 58 |
|
---|
| 59 | public void cleanUp () {
|
---|
| 60 | super.cleanUp ();
|
---|
| 61 | this.mg_src.unloadIndexData ();
|
---|
[9874] | 62 | }
|
---|
[14431] | 63 |
|
---|
[3649] | 64 | /** configure this service */
|
---|
[14431] | 65 | public boolean configure (Element info, Element extra_info) {
|
---|
| 66 | if (!super.configure (info, extra_info)){
|
---|
| 67 | return false;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | // Do specific configuration
|
---|
| 71 | logger.info ("Configuring GS2MGRetrieve...");
|
---|
| 72 |
|
---|
| 73 | // Get the default index out of <defaultIndex> (buildConfig.xml)
|
---|
| 74 | Element def = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_ELEM);
|
---|
| 75 | if (def != null) {
|
---|
| 76 | this.default_index = def.getAttribute (GSXML.SHORTNAME_ATT);
|
---|
| 77 | }
|
---|
| 78 | Element defSub = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_SUBCOLLECTION_ELEM);
|
---|
| 79 | if (defSub != null) {
|
---|
| 80 | this.default_index += defSub.getAttribute (GSXML.SHORTNAME_ATT);
|
---|
| 81 | logger.info ("default indexSubcollection is "+defSub.getAttribute (GSXML.SHORTNAME_ATT));
|
---|
| 82 | } //concate defaultIndex + defaultIndexSubcollection
|
---|
| 83 |
|
---|
| 84 | //get the default indexLanguage out of <defaultIndexLanguage> (buildConfig.xml)
|
---|
| 85 | Element defLang = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_LANGUAGE_ELEM);
|
---|
| 86 | if (defLang != null) {
|
---|
| 87 | this.default_index += defLang.getAttribute (GSXML.SHORTNAME_ATT);
|
---|
| 88 | logger.info ("default indexLanguage is "+defLang.getAttribute (GSXML.SHORTNAME_ATT));
|
---|
| 89 | } //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | if (this.default_index == null || this.default_index.equals ("")) {
|
---|
| 93 | logger.error ("default index is not specified, the content of a document will not be retrieved");
|
---|
| 94 | has_default_index = false;
|
---|
| 95 | return true;
|
---|
| 96 | //}
|
---|
| 97 | }
|
---|
| 98 | logger.debug ("Default index: " + this.default_index);
|
---|
| 99 |
|
---|
| 100 | // The location of the MG index and text files
|
---|
| 101 | mg_basedir = GSFile.collectionBaseDir (this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG
|
---|
| 102 | mg_textdir = GSFile.collectionTextPath (this.index_stem);
|
---|
| 103 | // index is only needed to start up MG, not used so just use the default index
|
---|
| 104 | String indexpath = GSFile.collectionIndexPath (this.index_stem, this.default_index);
|
---|
| 105 | this.mg_src.setIndex (indexpath);
|
---|
| 106 | has_default_index = true;
|
---|
| 107 | return true;
|
---|
[3799] | 108 | }
|
---|
[8959] | 109 |
|
---|
| 110 | /** returns the content of a node
|
---|
| 111 | * should return a nodeContent element:
|
---|
| 112 | * <nodeContent>text content or other elements</nodeContent>
|
---|
| 113 | */
|
---|
[14431] | 114 | protected Element getNodeContent (String doc_id, String lang) throws GSException {
|
---|
| 115 | long doc_num = this.gdbm_src.OID2Docnum (doc_id);
|
---|
| 116 | if (doc_num == -1) {
|
---|
| 117 | logger.error ("OID "+doc_id +" couldn't be converted to mg num");
|
---|
| 118 | return null;
|
---|
| 119 | }
|
---|
| 120 | Element content_node = this.doc.createElement (GSXML.NODE_CONTENT_ELEM);
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | String doc_content = null;
|
---|
| 124 |
|
---|
| 125 | //means that this.mg_src is up and running
|
---|
| 126 | if (has_default_index ){
|
---|
| 127 | doc_content = this.mg_src.getDocument (this.mg_basedir,
|
---|
| 128 | this.mg_textdir, doc_num);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if (doc_content!=null) {
|
---|
| 132 | // remove any ctrl-c or ctrl-b
|
---|
| 133 | doc_content = doc_content.replaceAll ("\u0002|\u0003", "");
|
---|
| 134 | // replace _httpimg_ with the correct address
|
---|
| 135 | doc_content = resolveTextMacros (doc_content, doc_id, lang);
|
---|
| 136 | //GSXML.addDocText(this.doc, doc, doc_content);
|
---|
| 137 | } else {
|
---|
| 138 | logger.error ("the doc content was null, not getting that section\n");
|
---|
| 139 | doc_content = "couldn't retrieve content for this section, please check the log file for more detail\n";
|
---|
| 140 | }
|
---|
| 141 | Text t = this.doc.createTextNode (doc_content);
|
---|
| 142 | content_node.appendChild (t);
|
---|
| 143 | return content_node;
|
---|
| 144 |
|
---|
[3649] | 145 | }
|
---|
[14431] | 146 |
|
---|
| 147 |
|
---|
[3990] | 148 | }
|
---|