[3649] | 1 | /*
|
---|
| 2 | * GS2MGPPRetrieve.java
|
---|
| 3 | * Copyright (C) 2002 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 | */
|
---|
| 19 | package org.greenstone.gsdl3.service;
|
---|
| 20 |
|
---|
[3799] | 21 |
|
---|
| 22 | // Greenstone classes
|
---|
[3649] | 23 | import org.greenstone.mgpp.*;
|
---|
| 24 | import org.greenstone.gsdl3.util.*;
|
---|
| 25 |
|
---|
[3799] | 26 | // XML classes
|
---|
[3649] | 27 | import org.w3c.dom.Element;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * A ServiceRack class for retrieval in greenstone 2 MGPP collections
|
---|
| 32 | *
|
---|
| 33 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
| 34 | * @version $Revision: 3799 $
|
---|
| 35 | * @see ServiceRack
|
---|
| 36 | */
|
---|
| 37 | public class GS2MGPPRetrieve
|
---|
[3799] | 38 | extends GS2Retrieve {
|
---|
[3649] | 39 |
|
---|
[3799] | 40 | // Parameters used
|
---|
[3649] | 41 | private static final String LEVEL_PARAM = "level";
|
---|
| 42 |
|
---|
[3799] | 43 | // Elements used in the config file that are specific to this class
|
---|
[3649] | 44 | private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
|
---|
[3799] | 45 |
|
---|
| 46 | private MGPPWrapper mgpp_src_ = null;
|
---|
[3649] | 47 |
|
---|
[3799] | 48 | private String default_level_ = null;
|
---|
[3649] | 49 |
|
---|
| 50 |
|
---|
[3799] | 51 | /** constructor */
|
---|
| 52 | public GS2MGPPRetrieve()
|
---|
| 53 | {
|
---|
| 54 | System.out.println("Constructing GS2MGPPRetrieve...");
|
---|
[3649] | 55 | mgpp_src_ = new MGPPWrapper();
|
---|
[3799] | 56 | }
|
---|
[3649] | 57 |
|
---|
[3799] | 58 |
|
---|
[3649] | 59 | /** configure this service */
|
---|
[3799] | 60 | public boolean configure(Element info)
|
---|
| 61 | {
|
---|
| 62 | // Do specific configuration
|
---|
| 63 | System.out.println("Configuring GS2MGPPRetrieve...");
|
---|
[3649] | 64 |
|
---|
[3799] | 65 | // Get the default level out of <defaultLevel> (buildConfig.xml)
|
---|
| 66 | Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
|
---|
| 67 | if (def != null) {
|
---|
[3649] | 68 | default_level_ = def.getAttribute(GSXML.NAME_ATT);
|
---|
| 69 | }
|
---|
[3799] | 70 | if (default_level_ == null || default_level_.equals("")) {
|
---|
[3649] | 71 | System.err.println("Error: default level not specified!");
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
[3799] | 74 | System.out.println("Default level: " + default_level_);
|
---|
[3649] | 75 |
|
---|
[3799] | 76 | // Do generic configuration
|
---|
| 77 | return super.configure(info);
|
---|
| 78 | }
|
---|
[3649] | 79 |
|
---|
| 80 |
|
---|
[3799] | 81 | /** Retrieve the structure of a document */
|
---|
| 82 | protected Element processDocumentStructureRetrieve(Element request)
|
---|
| 83 | {
|
---|
| 84 | return super.processDocumentStructureRetrieve(request);
|
---|
| 85 | }
|
---|
[3649] | 86 |
|
---|
| 87 |
|
---|
[3799] | 88 | /** Retrieve metadata associated with a document */
|
---|
| 89 | protected Element processDocumentMetadataRetrieve(Element request)
|
---|
| 90 | {
|
---|
| 91 | return super.processDocumentMetadataRetrieve(request);
|
---|
[3649] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
[3799] | 95 | /** Retrieve the content of a document */
|
---|
| 96 | protected Element processDocumentContentRetrieve(Element request)
|
---|
| 97 | {
|
---|
| 98 | // Create a new (empty) result message
|
---|
[3649] | 99 | Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
|
---|
[3799] | 100 | String from = GSPath.appendLink(cluster_name_, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
|
---|
[3649] | 101 | result.setAttribute(GSXML.FROM_ATT, from);
|
---|
[3799] | 102 | result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
|
---|
| 103 | Element result_content = doc_.createElement(GSXML.CONTENT_ELEM);
|
---|
| 104 | result.appendChild(result_content);
|
---|
[3649] | 105 |
|
---|
[3799] | 106 | // Get the parameters of the request
|
---|
| 107 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
| 108 | if (param_list == null) {
|
---|
| 109 | System.err.println("GS2Retrieve, DocumentContentRetrieve Error: missing paramList.\n");
|
---|
| 110 | return result; // Return the empty result
|
---|
[3649] | 111 | }
|
---|
| 112 |
|
---|
[3799] | 113 | String level = default_level_;
|
---|
| 114 |
|
---|
| 115 | // Process the request parameters
|
---|
| 116 | Element param = (Element) param_list.getFirstChild();
|
---|
| 117 | while (param != null) {
|
---|
| 118 | if (!param.getNodeName().equals(GSXML.PARAM_ELEM)) {
|
---|
| 119 | System.err.println("Warning: Non-param in paramList (ignored).");
|
---|
| 120 | }
|
---|
| 121 | else {
|
---|
| 122 | //
|
---|
| 123 | if (param.getAttribute(GSXML.NAME_ATT) == LEVEL_PARAM) {
|
---|
| 124 | level = GSXML.getValue(param);
|
---|
| 125 | System.out.println("Level: " + level);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | param = (Element) param.getNextSibling();
|
---|
[3649] | 130 | }
|
---|
| 131 |
|
---|
[3799] | 132 | // Get the request content
|
---|
| 133 | Element content = (Element) GSXML.getChildByTagName(request, GSXML.CONTENT_ELEM);
|
---|
| 134 | if (content == null) {
|
---|
| 135 | System.err.println("Error: DocumentContentRetrieve request had no content.\n");
|
---|
[3649] | 136 | return result;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[3799] | 139 | Element doc_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
|
---|
| 140 | result_content.appendChild(doc_list);
|
---|
[3649] | 141 |
|
---|
[3799] | 142 | // The location of the MGPP text files
|
---|
| 143 | String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_);
|
---|
| 144 | String textdir = GSFile.collectionTextPath(cluster_name_);
|
---|
| 145 | System.out.println("Base directory: " + basedir);
|
---|
| 146 | System.out.println("Text directory: " + textdir);
|
---|
[3649] | 147 |
|
---|
[3799] | 148 | // Get the documents
|
---|
| 149 | String[] doc_ids = GSXML.getDocumentNameList(content);
|
---|
| 150 | for (int i = 0; i < doc_ids.length; i++) {
|
---|
| 151 | String doc_id = doc_ids[i];
|
---|
| 152 | System.out.println("Retrieving content of " + doc_id + "...");
|
---|
[3649] | 153 |
|
---|
[3799] | 154 | long doc_num = gdbm_src_.oid2Docnum(doc_id);
|
---|
| 155 | String doc_content = mgpp_src_.getDocument(basedir, textdir, level, doc_num);
|
---|
| 156 |
|
---|
| 157 | // For now, stick it in a text node - eventually should be parsed as xml??
|
---|
| 158 | Element doc = GSXML.createDocumentElement(doc_, doc_id);
|
---|
| 159 | GSXML.addDocText(doc_, doc, doc_content);
|
---|
| 160 | doc_list.appendChild(doc);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | return result;
|
---|
| 164 | }
|
---|
[3649] | 165 | }
|
---|