source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ArchiveRetrieve.java@ 24211

Last change on this file since 24211 was 24211, checked in by sjm84, 13 years ago

Initial commit of the new ArchiveRetrieve service

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1/*
2* AbstractDocumentRetrieve.java
3* a base class for retrieval services
4
5* Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
6*
7* This program is free software; you can redistribute it and/or modify
8* it under the terms of the GNU General Public License as published by
9* the Free Software Foundation; either version 2 of the License, or
10* (at your option) any later version.
11*
12* This program is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15* GNU General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License
18* along with this program; if not, write to the Free Software
19* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21package org.greenstone.gsdl3.service;
22
23import org.greenstone.gsdl3.util.GSPath;
24import org.greenstone.gsdl3.util.GSXML;
25import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
26
27import org.w3c.dom.Element;
28
29import org.apache.log4j.*;
30
31import java.io.File;
32import java.util.HashMap;
33
34/** Abstract class for Document Retrieval Services
35*
36* @author <a href="mailto:[email protected]">Katherine Don</a>
37*/
38
39public class ArchiveRetrieve extends ServiceRack {
40
41 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.ArchiveRetrieve.class.getName());
42
43 protected static final String ARCHIVE_FILE_PATH_RETRIEVE_SERVICE = "ArchiveFilePathRetrieve";
44
45 protected SimpleCollectionDatabase coll_db = null;
46
47 /** constructor */
48 public ArchiveRetrieve()
49 {
50 }
51
52 /** configure this service */
53 public boolean configure(Element info, Element extra_info)
54 {
55 if (!super.configure(info, extra_info)){
56 return false;
57 }
58
59 logger.info("Configuring ArchiveRetrieve...");
60 this.config_info = info;
61
62 Element archiveFilePathRetrieveService = this.doc.createElement(GSXML.SERVICE_ELEM);
63 archiveFilePathRetrieveService.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
64 archiveFilePathRetrieveService.setAttribute(GSXML.NAME_ATT, ARCHIVE_FILE_PATH_RETRIEVE_SERVICE);
65 this.short_service_info.appendChild(archiveFilePathRetrieveService);
66
67 return true;
68 }
69
70 protected Element getServiceDescription(String service_id, String lang, String subset)
71 {
72 Element service_elem = this.doc.createElement(GSXML.SERVICE_ELEM);
73 service_elem.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
74 service_elem.setAttribute(GSXML.NAME_ATT, ARCHIVE_FILE_PATH_RETRIEVE_SERVICE);
75 return service_elem;
76 }
77
78 protected Element processArchiveFilePathRetrieve(Element request)
79 {
80 // Create a new (empty) result message
81 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
82 result.setAttribute(GSXML.FROM_ATT, ARCHIVE_FILE_PATH_RETRIEVE_SERVICE);
83 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
84
85 String lang = request.getAttribute(GSXML.LANG_ATT);
86 String uid = request.getAttribute(GSXML.USER_ID_ATT);
87
88 // Get the parameters of the request
89 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
90 if (param_list == null) {
91 GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: missing "+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX);
92 return result;
93 }
94 HashMap params = GSXML.extractParams(param_list, false);
95
96 String docID = (String) params.get("docID");
97 String collection = (String) params.get("c");
98
99 String assocFilePath = getAssocFilePathFromDocID(docID, collection, lang, uid);
100
101 String docFilePath = this.site_home + File.separatorChar +
102 "collect" + File.separatorChar +
103 collection + File.separatorChar +
104 "archives" + File.separatorChar +
105 assocFilePath + File.separatorChar +
106 "doc.xml";
107
108 Element metaElem = this.doc.createElement(GSXML.METADATA_ELEM);
109 metaElem.setAttribute("name", "docFilePath");
110 metaElem.setAttribute("value", docFilePath);
111
112 logger.error("DOCFILEPATH = " + docFilePath);
113
114 result.appendChild(metaElem);
115
116 return result;
117 }
118
119 protected Element processArchiveAssociatedImportFilesRetrieve(Element request)
120 {
121 // find out what kind of database we have
122 //Element database_type_elem = (Element) GSXML.getChildByTagName(this.config_info, GSXML.DATABASE_TYPE_ELEM);
123 //String database_type = "jdbm";
124 /*if (database_type_elem != null) {
125 database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
126 }
127 if (database_type == null || database_type.equals("")) {
128 database_type = "gdbm"; // the default
129 }
130
131 String db_ext = null;
132 if (database_type.equalsIgnoreCase("jdbm")) {
133 db_ext = ".jdb";
134 } else {
135 db_ext = ".gdb"; // assume gdbm
136 }
137
138
139 coll_db = new SimpleCollectionDatabase(database_type);
140 if (!coll_db.databaseOK()) {
141 logger.error("Couldn't create the collection database of type "+database_type);
142 return null;
143 }
144 */
145
146 /*coll_db.openDatabase(
147 this.site_home + File.separatorChar +
148 "collect" + File.separatorChar +
149 collection + File.separatorChar +
150 "archives" + File.separatorChar +
151 "archiveinf-doc" + db_ext,
152 SimpleCollectionDatabase.READ);
153
154 logger.error("STUFF " + coll_db.getInfo(docID));
155
156 coll_db.getInfo(docID);*/
157 return null;
158 }
159
160 public String getAssocFilePathFromDocID(String docID, String collection, String lang, String uid)
161 {
162 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
163 Element mr_query_request = GSXML.createBasicRequest (this.doc, GSXML.REQUEST_TYPE_PAGE, collection + "/DocumentMetadataRetrieve", lang, uid);
164 mr_query_message.appendChild(mr_query_request);
165
166 Element paramList = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
167
168 Element assocParam = this.doc.createElement(GSXML.PARAM_ELEM);
169 assocParam.setAttribute("name", "metadata");
170 assocParam.setAttribute("value", "assocfilepath");
171 paramList.appendChild(assocParam);
172
173 mr_query_request.appendChild(paramList);
174
175 Element docList = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
176 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
177 doc.setAttribute(GSXML.NODE_ID_ATT, docID);
178 docList.appendChild(doc);
179 mr_query_request.appendChild(docList);
180
181 Element response = (Element) this.router.process(mr_query_message);
182
183 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
184 path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
185 path = GSPath.appendLink(path, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
186 Element metadataListElem = (Element) GSXML.getNodeByPath(response, path);
187 Element metadataElem = (Element) metadataListElem.getFirstChild();
188
189 return metadataElem.getFirstChild().getNodeValue();
190 }
191}
Note: See TracBrowser for help on using the repository browser.