/* * GS2MGPPRetrieve.java * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.greenstone.gsdl3.service; // Greenstone classes import org.greenstone.mgpp.*; import org.greenstone.gsdl3.util.*; // XML classes import org.w3c.dom.Element; // General Java classes import java.io.File; /** * A ServiceRack class for retrieval in greenstone 2 MGPP collections * * @author Katherine Don * @version $Revision: 8674 $ * @see ServiceRack */ public class GS2MGPPRetrieve extends GS2Retrieve { // Parameters used private static final String LEVEL_PARAM = "level"; // Elements used in the config file that are specific to this class private static final String DEFAULT_LEVEL_ELEM = "defaultLevel"; private MGPPWrapper mgpp_src = null; private String default_level = null; /** constructor */ public GS2MGPPRetrieve() { this.mgpp_src = new MGPPWrapper(); } /** configure this service */ public boolean configure(Element info, Element extra_info) { // Do specific configuration System.out.println("Configuring GS2MGPPRetrieve..."); // Get the default level out of (buildConfig.xml) Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM); if (def != null) { this.default_level = def.getAttribute(GSXML.NAME_ATT); } if (this.default_level == null || this.default_level.equals("")) { System.err.println("Error: default level not specified!"); return false; } // System.out.println("Default level: " + default_level_); // Do generic configuration return super.configure(info, extra_info); } /** Retrieve the content of a document */ protected Element processDocumentContentRetrieve(Element request) { // Create a new (empty) result message Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); result.setAttribute(GSXML.FROM_ATT,DOCUMENT_CONTENT_RETRIEVE_SERVICE ); result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); // Get the parameters of the request Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM); boolean extlink = false; if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) { extlink = true; } // Get the request doc_list Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); if (query_doc_list == null) { System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n"); return result; } String lang = request.getAttribute(GSXML.LANG_ATT); Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); result.appendChild(doc_list); // The location of the MGPP text files String textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar + GSFile.collectionTextPath(this.cluster_name); // Get the documents String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list, GSXML.NODE_ID_ATT); for (int i = 0; i < doc_ids.length; i++) { String doc_id = doc_ids[i]; if (extlink) { doc_id = this.gdbm_src.extlink2OID(doc_id); } else if (OID.needsTranslating(doc_id)) { doc_id = this.gdbm_src.translateOID(doc_id); } long doc_num = this.gdbm_src.OID2Docnum(doc_id); String doc_content = this.mgpp_src.getDocument(textdir, this.default_level, doc_num); doc_content = resolveTextMacros(doc_content, doc_id, lang); // For now, stick it in a text node - eventually should be parsed as xml?? Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM); doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); GSXML.addDocText(this.doc, doc, doc_content); doc_list.appendChild(doc); } return result; } }