/* * 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: 3990 $ * @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() { 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) { default_level_ = def.getAttribute(GSXML.NAME_ATT); } if (default_level_ == null || 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 = 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 - not used at the moment //Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); // 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; } Element doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); result.appendChild(doc_list); // The location of the MGPP text files // String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_); // String textdir = GSFile.collectionTextPath(cluster_name_); String basedir = ""; String textdir = GSFile.collectionBaseDir(site_home_, cluster_name_) + File.separatorChar + GSFile.collectionTextPath(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 (OID.needsTranslating(doc_id)) { doc_id = gdbm_src_.translateOID(doc_id); } long doc_num = gdbm_src_.oid2Docnum(doc_id); String doc_content = mgpp_src_.getDocument(basedir, textdir, default_level_, doc_num); doc_content = resolveImages(doc_content, doc_id); // For now, stick it in a text node - eventually should be parsed as xml?? Element doc = doc_.createElement(GSXML.DOC_NODE_ELEM); doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); GSXML.addDocText(doc_, doc, doc_content); doc_list.appendChild(doc); } return result; } }