[24509] | 1 | /*
|
---|
| 2 | * DocumentBasket.java
|
---|
| 3 | * Copyright (C) 2006 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 |
|
---|
| 20 | package org.greenstone.gsdl3.service;
|
---|
| 21 |
|
---|
| 22 | import java.sql.Statement;
|
---|
| 23 | import java.util.Hashtable;
|
---|
| 24 | import java.util.HashMap;
|
---|
| 25 | import java.util.ArrayList;
|
---|
| 26 | import java.util.HashSet;
|
---|
| 27 | import java.util.Iterator;
|
---|
| 28 |
|
---|
| 29 | import org.w3c.dom.Element;
|
---|
| 30 | import org.w3c.dom.NodeList;
|
---|
| 31 |
|
---|
| 32 | import org.greenstone.util.GlobalProperties;
|
---|
| 33 | import org.greenstone.gsdl3.util.GSXML;
|
---|
| 34 | import org.greenstone.gsdl3.util.GSPath;
|
---|
| 35 |
|
---|
| 36 | import java.net.InetAddress;
|
---|
| 37 | import java.util.Properties;
|
---|
| 38 | import java.util.Date;
|
---|
| 39 |
|
---|
| 40 | import javax.mail.*;
|
---|
| 41 | import javax.mail.internet.*;
|
---|
| 42 |
|
---|
| 43 | import java.awt.event.ActionEvent;
|
---|
| 44 | import java.awt.event.ActionListener;
|
---|
| 45 | import javax.swing.Timer;
|
---|
| 46 |
|
---|
| 47 | import java.io.FileOutputStream;
|
---|
| 48 | import java.io.*;
|
---|
| 49 | import java.io.IOException;
|
---|
| 50 |
|
---|
| 51 | import org.apache.log4j.*;
|
---|
| 52 |
|
---|
[24976] | 53 | public class DocumentBasket extends ServiceRack
|
---|
| 54 | {
|
---|
[24509] | 55 |
|
---|
[24976] | 56 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.DocumentBasket.class.getName());
|
---|
[24509] | 57 |
|
---|
[24976] | 58 | // the services on offer
|
---|
| 59 | // these strings must match what is found in the properties file
|
---|
| 60 | protected static final String ADD_ITEM_SERVICE = "AddDocument";
|
---|
| 61 | protected static final String DISPLAY_ITEMS_SERVICE = "DisplayDocumentList";
|
---|
| 62 | protected static final String ITEM_NUM_SERVICE = "GetDocuments";
|
---|
| 63 | protected static final String DELETE_ITEMS_SERVICE = "DeleteDocuments";
|
---|
| 64 | protected static final String DELETE_ITEM_SERVICE = "DeleteDocument";
|
---|
[24509] | 65 | //added
|
---|
| 66 | protected static final String MERGE_ITEM_SERVICE = "MergeDocument";
|
---|
| 67 | protected static final String ITEM_PARAM = "item";
|
---|
[24976] | 68 | protected static final String delimiter = "|";
|
---|
| 69 | protected static final int delay = 1800000;
|
---|
[24509] | 70 |
|
---|
[24976] | 71 | protected static final String BASKET_BOOK = "documentBasketBook";
|
---|
[24509] | 72 |
|
---|
[24976] | 73 | protected Hashtable userMap = null;
|
---|
| 74 | protected Hashtable timerMap = null;
|
---|
| 75 | protected String username = "";
|
---|
| 76 | protected String password = "";
|
---|
[24509] | 77 |
|
---|
[24976] | 78 | /** constructor */
|
---|
| 79 | public DocumentBasket()
|
---|
[24509] | 80 | {
|
---|
[24976] | 81 | userMap = new Hashtable();
|
---|
| 82 | timerMap = new Hashtable();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private Hashtable updateDocMap(Element request)
|
---|
| 86 | {
|
---|
[24509] | 87 | String id = request.getAttribute("uid");
|
---|
| 88 |
|
---|
[24976] | 89 | if (userMap.containsKey(id))
|
---|
| 90 | {
|
---|
| 91 | if (timerMap.containsKey(id))
|
---|
| 92 | {
|
---|
| 93 | UserTimer timer = (UserTimer) timerMap.get(id);
|
---|
[24509] | 94 | timer.restart();
|
---|
[24976] | 95 | }
|
---|
[24509] | 96 | return (Hashtable) userMap.get(id);
|
---|
| 97 | }
|
---|
| 98 | else
|
---|
| 99 | {
|
---|
[24976] | 100 | UserTimer timer = new UserTimer(delay, id);
|
---|
| 101 | timerMap.put(id, timer);
|
---|
[24509] | 102 | timer.start();
|
---|
[24976] | 103 | Hashtable newDocs = new Hashtable();
|
---|
| 104 | userMap.put(id, newDocs);
|
---|
[24509] | 105 | return newDocs;
|
---|
[24976] | 106 | }
|
---|
[24509] | 107 | }
|
---|
| 108 |
|
---|
[24976] | 109 | /** configure this service */
|
---|
| 110 | public boolean configure(Element info, Element extra_info)
|
---|
| 111 | {
|
---|
[24509] | 112 | logger.info("Configuring DocumentBasket...");
|
---|
| 113 | this.config_info = info;
|
---|
| 114 |
|
---|
| 115 | // set up short_service_info_ - for now just has name and type
|
---|
| 116 | Element add_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 117 | add_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 118 | add_service.setAttribute(GSXML.NAME_ATT, ADD_ITEM_SERVICE);
|
---|
| 119 | this.short_service_info.appendChild(add_service);
|
---|
| 120 |
|
---|
| 121 | // set up short_service_info_ - for now just has name and type
|
---|
| 122 | Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 123 | disp_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 124 | disp_service.setAttribute(GSXML.NAME_ATT, DISPLAY_ITEMS_SERVICE);
|
---|
| 125 | this.short_service_info.appendChild(disp_service);
|
---|
| 126 |
|
---|
| 127 | // set up short_service_info_ - for now just has name and type
|
---|
| 128 | Element num_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 129 | num_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 130 | num_service.setAttribute(GSXML.NAME_ATT, ITEM_NUM_SERVICE);
|
---|
| 131 | this.short_service_info.appendChild(num_service);
|
---|
| 132 |
|
---|
[24976] | 133 | // set up short_service_info_ - for now just has name and type
|
---|
[24509] | 134 | Element delete_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 135 | delete_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 136 | delete_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEMS_SERVICE);
|
---|
| 137 | this.short_service_info.appendChild(delete_service);
|
---|
| 138 |
|
---|
[24976] | 139 | // set up short_service_info_ - for now just has name and type
|
---|
[24509] | 140 | Element deleteone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 141 | deleteone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 142 | deleteone_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEM_SERVICE);
|
---|
| 143 | this.short_service_info.appendChild(deleteone_service);
|
---|
[24976] | 144 |
|
---|
[24509] | 145 | // set up short_service_info_ - for now just has name and type
|
---|
| 146 | Element merge_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 147 | merge_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 148 | merge_service.setAttribute(GSXML.NAME_ATT, MERGE_ITEM_SERVICE);
|
---|
| 149 | this.short_service_info.appendChild(merge_service);
|
---|
| 150 |
|
---|
[24976] | 151 | return true;
|
---|
| 152 | }
|
---|
[24509] | 153 |
|
---|
[24976] | 154 | /** returns a specific service description */
|
---|
| 155 | protected Element getServiceDescription(String service_id, String lang, String subset)
|
---|
[24509] | 156 | {
|
---|
[24976] | 157 | if (service_id.equals(ADD_ITEM_SERVICE))
|
---|
| 158 | {
|
---|
[24509] | 159 | Element add_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 160 | add_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 161 | add_service.setAttribute(GSXML.NAME_ATT, ADD_ITEM_SERVICE);
|
---|
| 162 | return add_service;
|
---|
| 163 | }
|
---|
[24976] | 164 | if (service_id.equals(DISPLAY_ITEMS_SERVICE))
|
---|
| 165 | {
|
---|
| 166 |
|
---|
[24509] | 167 | Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 168 | disp_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 169 | disp_service.setAttribute(GSXML.NAME_ATT, DISPLAY_ITEMS_SERVICE);
|
---|
| 170 | return disp_service;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[24976] | 173 | if (service_id.equals(ITEM_NUM_SERVICE))
|
---|
| 174 | {
|
---|
| 175 |
|
---|
[24509] | 176 | Element num_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 177 | num_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 178 | num_service.setAttribute(GSXML.NAME_ATT, ITEM_NUM_SERVICE);
|
---|
| 179 | return num_service;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[24976] | 182 | if (service_id.equals(DELETE_ITEMS_SERVICE))
|
---|
| 183 | {
|
---|
| 184 |
|
---|
[24509] | 185 | Element del_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 186 | del_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 187 | del_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEMS_SERVICE);
|
---|
| 188 | return del_service;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[24976] | 191 | if (service_id.equals(DELETE_ITEM_SERVICE))
|
---|
| 192 | {
|
---|
| 193 |
|
---|
[24509] | 194 | Element delone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 195 | delone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 196 | delone_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEM_SERVICE);
|
---|
| 197 | return delone_service;
|
---|
| 198 | }
|
---|
[24976] | 199 | if (service_id.equals(MERGE_ITEM_SERVICE))
|
---|
| 200 | {
|
---|
[24509] | 201 | Element merge_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 202 | merge_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
|
---|
| 203 | merge_service.setAttribute(GSXML.NAME_ATT, MERGE_ITEM_SERVICE);
|
---|
| 204 | return merge_service;
|
---|
| 205 | }
|
---|
| 206 | return null;
|
---|
[24976] | 207 | }
|
---|
[24509] | 208 |
|
---|
[24976] | 209 | protected Element processAddDocument(Element request)
|
---|
| 210 | {
|
---|
[24509] | 211 | //System.err.println("REQUEST = " + GSXML.xmlNodeToString(request));
|
---|
[24976] | 212 | Hashtable docsMap = updateDocMap(request);
|
---|
[24509] | 213 | //System.err.println("DOCSMAP = " + docsMap);
|
---|
| 214 | // Create a new (empty) result message
|
---|
| 215 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[24976] | 216 |
|
---|
[24509] | 217 | // Get the parameters of the request
|
---|
[24976] | 218 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 219 | if (param_list == null)
|
---|
| 220 | {
|
---|
[24509] | 221 | logger.error("DocumentBasket Error: AddDocument request had no paramList.");
|
---|
[24976] | 222 | return result; // Return the empty result
|
---|
[24509] | 223 | }
|
---|
[24976] | 224 |
|
---|
[24509] | 225 | HashMap params = GSXML.extractParams(param_list, false);
|
---|
| 226 | //System.err.println("PARAMS = " + params);
|
---|
[24976] | 227 | String item = (String) params.get("item");
|
---|
| 228 |
|
---|
[24509] | 229 | int startIndex = item.startsWith(BASKET_BOOK) ? BASKET_BOOK.length() : 0;
|
---|
[24976] | 230 |
|
---|
[24509] | 231 | String collection = "";
|
---|
| 232 | int pos = item.indexOf(":");
|
---|
[24976] | 233 | if (pos != -1)
|
---|
| 234 | {
|
---|
| 235 | collection = item.substring(startIndex, pos);
|
---|
| 236 | item = item.substring(pos + 1);
|
---|
[24509] | 237 | }
|
---|
| 238 | //logger.error("COLLECTION = " + collection + " *** ITEM = " + item);
|
---|
[24976] | 239 | if (docsMap.containsKey(collection))
|
---|
| 240 | {
|
---|
[24509] | 241 | Hashtable items = (Hashtable) docsMap.get(collection);
|
---|
[24976] | 242 | if (!items.containsKey(item))
|
---|
| 243 | {
|
---|
| 244 | Item newItem = generateItem(collection, item);
|
---|
[24509] | 245 | items.put(item, newItem);
|
---|
| 246 | result.appendChild(newItem.wrapIntoElement());
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
[24976] | 249 | else
|
---|
| 250 | {
|
---|
[24509] | 251 | Hashtable items = new Hashtable();
|
---|
[24976] | 252 | Item newItem = generateItem(collection, item);
|
---|
[24509] | 253 | items.put(item, newItem);
|
---|
[24976] | 254 | docsMap.put(collection, items);
|
---|
[24509] | 255 | result.appendChild(newItem.wrapIntoElement());
|
---|
| 256 | }
|
---|
[24976] | 257 |
|
---|
[24509] | 258 | return result;
|
---|
[24976] | 259 | }
|
---|
| 260 |
|
---|
[24509] | 261 | protected Element processMergeDocument(Element request)
|
---|
| 262 | {
|
---|
| 263 | // Get the parameters of the request
|
---|
[24976] | 264 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 265 | if (param_list == null)
|
---|
| 266 | {
|
---|
[24509] | 267 | logger.error("DocumentBasket Error: MergeDocument request had no paramList.");
|
---|
[24976] | 268 | return null; // Return the empty result
|
---|
[24509] | 269 | }
|
---|
[24976] | 270 |
|
---|
[24509] | 271 | HashMap params = GSXML.extractParams(param_list, false);
|
---|
[24976] | 272 |
|
---|
| 273 | String docString = (String) params.get("docs");
|
---|
[24509] | 274 | String[] docs = docString.split("-");
|
---|
[24976] | 275 |
|
---|
| 276 | for (String d : docs)
|
---|
[24509] | 277 | {
|
---|
| 278 | logger.error("DOC = " + d);
|
---|
| 279 | }
|
---|
[24976] | 280 |
|
---|
| 281 | /*
|
---|
| 282 | * try{ System.out.println("Concatenate Two PDF"); PdfReader reader1 =
|
---|
| 283 | * new PdfReader("3A01-01_Part_1-001.pdf"); PdfReader reader2 = new
|
---|
| 284 | * PdfReader("3A01-01_Part_1-017.pdf"); PdfCopyFields copy = new
|
---|
| 285 | * PdfCopyFields(new FileOutputStream("concatenatedPDF.pdf"));
|
---|
| 286 | * copy.addDocument(reader1); copy.addDocument(reader2); copy.close(); }
|
---|
| 287 | * catch(Exception ex) { ex.printStackTrace(); }
|
---|
| 288 | */
|
---|
| 289 | // added -->
|
---|
| 290 |
|
---|
| 291 | try
|
---|
[24509] | 292 | {
|
---|
[24976] | 293 | {
|
---|
| 294 | PrintWriter pw = new PrintWriter(new FileOutputStream("G:/output1.xml"));
|
---|
| 295 | File file = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASH0189.dir/");
|
---|
| 296 | File[] files = file.listFiles();
|
---|
[24509] | 297 |
|
---|
[24976] | 298 | for (int i = 0; i < files.length; i++)
|
---|
| 299 | {
|
---|
[24509] | 300 |
|
---|
[24976] | 301 | //System.out.println(files[i].getName());
|
---|
| 302 | String fileName = files[i].getName();
|
---|
[24509] | 303 |
|
---|
[24976] | 304 | if (fileName.equals("doc.xml"))
|
---|
| 305 | {
|
---|
[24509] | 306 |
|
---|
[24976] | 307 | System.out.println("Processing " + files[i].getPath() + "... ");
|
---|
| 308 | BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
|
---|
| 309 | String line = br.readLine();
|
---|
| 310 | while (line != null)
|
---|
| 311 | {
|
---|
| 312 | pw.println(line);
|
---|
| 313 | line = br.readLine();
|
---|
| 314 | }
|
---|
| 315 | br.close();
|
---|
[24509] | 316 |
|
---|
[24976] | 317 | }
|
---|
| 318 |
|
---|
[24509] | 319 | }
|
---|
| 320 |
|
---|
[24976] | 321 | File file1 = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASHfdc0.dir/");
|
---|
| 322 | File[] files1 = file1.listFiles();
|
---|
[24509] | 323 |
|
---|
[24976] | 324 | for (int i = 0; i < files1.length; i++)
|
---|
| 325 | {
|
---|
[24509] | 326 |
|
---|
[24976] | 327 | //System.out.println(files[i].getName());
|
---|
| 328 | String fileName = files1[i].getName();
|
---|
[24509] | 329 |
|
---|
[24976] | 330 | if (fileName.equals("doc.xml"))
|
---|
| 331 | {
|
---|
[24509] | 332 |
|
---|
[24976] | 333 | System.out.println("Processing " + files1[i].getPath() + "... ");
|
---|
| 334 | BufferedReader br = new BufferedReader(new FileReader(files1[i].getPath()));
|
---|
| 335 | String line = br.readLine();
|
---|
| 336 | while (line != null)
|
---|
| 337 | {
|
---|
| 338 | pw.println(line);
|
---|
| 339 | line = br.readLine();
|
---|
| 340 | }
|
---|
| 341 | br.close();
|
---|
[24509] | 342 |
|
---|
[24976] | 343 | }
|
---|
[24509] | 344 |
|
---|
[24976] | 345 | }
|
---|
[24509] | 346 |
|
---|
[24976] | 347 | pw.close();
|
---|
[24509] | 348 |
|
---|
[24976] | 349 | System.out.println("All doc.xml files have been concatenated into output1.xml");
|
---|
| 350 | }
|
---|
[24509] | 351 | }
|
---|
[24976] | 352 | catch (Exception ex)
|
---|
| 353 | {
|
---|
| 354 | ex.printStackTrace();
|
---|
| 355 | }
|
---|
| 356 | return null;
|
---|
[24509] | 357 | }
|
---|
| 358 |
|
---|
[24976] | 359 | //end
|
---|
| 360 | private Item generateItem(String collection, String id)
|
---|
| 361 | {
|
---|
[24509] | 362 | Item item = new Item(collection, id);
|
---|
| 363 | String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
|
---|
| 364 | ArrayList tmp = new ArrayList();
|
---|
[24976] | 365 | tmp.add(id);
|
---|
| 366 | Element response = getDocumentMetadata(to, "en", "dumy", tmp.iterator());
|
---|
| 367 | Element doc_node = (Element) response.getElementsByTagName(GSXML.DOC_NODE_ELEM).item(0);
|
---|
[24509] | 368 |
|
---|
| 369 | String node_id = doc_node.getAttribute(GSXML.NODE_ID_ATT);
|
---|
[24976] | 370 | Element metadata_list = (Element) doc_node.getElementsByTagName(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER).item(0);
|
---|
[24509] | 371 |
|
---|
| 372 | //assign title metadata if any
|
---|
[24976] | 373 | Element metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "Title");
|
---|
| 374 | if (metadata != null)
|
---|
| 375 | {
|
---|
[24509] | 376 | item.title = GSXML.getNodeText(metadata).trim();
|
---|
[24976] | 377 | }
|
---|
[24509] | 378 | //assign date metadata if any
|
---|
[24976] | 379 | metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "Date");
|
---|
| 380 | if (metadata != null)
|
---|
| 381 | {
|
---|
[24509] | 382 | item.date = GSXML.getNodeText(metadata).trim();
|
---|
[24976] | 383 | }
|
---|
| 384 |
|
---|
[24509] | 385 | //assign root title metadata if any
|
---|
[24976] | 386 | metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "root_Title");
|
---|
| 387 | if (metadata != null)
|
---|
| 388 | {
|
---|
| 389 | String rootTitle = GSXML.getNodeText(metadata).trim();
|
---|
| 390 | if (!rootTitle.equals(item.title))
|
---|
| 391 | {
|
---|
| 392 | item.rootTitle = rootTitle;
|
---|
[24509] | 393 | }
|
---|
[24976] | 394 |
|
---|
[24509] | 395 | }
|
---|
| 396 |
|
---|
| 397 | return item;
|
---|
[24976] | 398 | }
|
---|
[24509] | 399 |
|
---|
[24976] | 400 | protected Element processDeleteDocuments(Element request)
|
---|
| 401 | {
|
---|
| 402 | Hashtable docsMap = updateDocMap(request);
|
---|
[24509] | 403 |
|
---|
| 404 | // Create a new (empty) result message
|
---|
| 405 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[24976] | 406 |
|
---|
[24509] | 407 | // Get the parameters of the request
|
---|
[24976] | 408 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
[24509] | 409 |
|
---|
[24976] | 410 | //GSXML.printXMLNode(param_list);
|
---|
| 411 |
|
---|
| 412 | if (param_list == null)
|
---|
| 413 | {
|
---|
[24509] | 414 | logger.error("DocumentBasket Error: DeleteDocument request had no paramList.");
|
---|
[24976] | 415 | return result; // Return the empty result
|
---|
[24509] | 416 | }
|
---|
| 417 |
|
---|
| 418 | HashMap params = GSXML.extractParams(param_list, false);
|
---|
| 419 |
|
---|
[24976] | 420 | String param = (String) params.get("items");
|
---|
| 421 |
|
---|
| 422 | if (param == null)
|
---|
| 423 | return result;
|
---|
| 424 |
|
---|
[24509] | 425 | String[] items = param.split("\\|");
|
---|
[24976] | 426 |
|
---|
| 427 | for (int i = 0; i < items.length; i++)
|
---|
[24509] | 428 | {
|
---|
| 429 | String item = items[i];
|
---|
[24976] | 430 | if (item.trim().length() == 0)
|
---|
| 431 | continue;
|
---|
| 432 |
|
---|
[24509] | 433 | String collection = "";
|
---|
| 434 | int pos = item.indexOf(":");
|
---|
[24976] | 435 | if (pos != -1)
|
---|
| 436 | {
|
---|
| 437 | collection = item.substring(0, pos);
|
---|
| 438 | item = item.substring(pos + 1);
|
---|
[24509] | 439 | }
|
---|
[24976] | 440 |
|
---|
| 441 | if (docsMap.containsKey(collection))
|
---|
| 442 | {
|
---|
[24509] | 443 | Hashtable itemMap = (Hashtable) docsMap.get(collection);
|
---|
[24976] | 444 | if (itemMap.containsKey(item))
|
---|
| 445 | {
|
---|
[24509] | 446 | itemMap.remove(item);
|
---|
| 447 | }
|
---|
[24976] | 448 | if (itemMap.size() == 0)
|
---|
| 449 | {
|
---|
[24509] | 450 | docsMap.remove(collection);
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | return result;
|
---|
[24976] | 456 | }
|
---|
[24509] | 457 |
|
---|
[24976] | 458 | protected Element processDeleteDocument(Element request)
|
---|
| 459 | {
|
---|
| 460 | Hashtable docsMap = updateDocMap(request);
|
---|
| 461 |
|
---|
[24509] | 462 | // Create a new (empty) result message
|
---|
| 463 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[24976] | 464 |
|
---|
[24509] | 465 | // Get the parameters of the request
|
---|
[24976] | 466 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
[24509] | 467 |
|
---|
[24976] | 468 | //GSXML.printXMLNode(param_list);
|
---|
| 469 |
|
---|
| 470 | if (param_list == null)
|
---|
| 471 | {
|
---|
[24509] | 472 | logger.error("DocumentBasket Error: DeleteDocument request had no paramList.");
|
---|
[24976] | 473 | return result; // Return the empty result
|
---|
[24509] | 474 | }
|
---|
| 475 |
|
---|
| 476 | HashMap params = GSXML.extractParams(param_list, false);
|
---|
| 477 |
|
---|
[24976] | 478 | String param = (String) params.get("item");
|
---|
| 479 |
|
---|
| 480 | if (param == null)
|
---|
| 481 | return result;
|
---|
| 482 |
|
---|
[24509] | 483 | String item = param;
|
---|
[24976] | 484 |
|
---|
[24509] | 485 | String collection = "";
|
---|
| 486 | int pos = item.indexOf(":");
|
---|
[24976] | 487 |
|
---|
| 488 | if (pos != -1)
|
---|
| 489 | {
|
---|
| 490 | collection = item.substring(0, pos);
|
---|
| 491 | item = item.substring(pos + 1);
|
---|
[24509] | 492 | }
|
---|
[24976] | 493 |
|
---|
| 494 | if (docsMap.containsKey(collection))
|
---|
| 495 | {
|
---|
[24509] | 496 | Hashtable itemMap = (Hashtable) docsMap.get(collection);
|
---|
[24976] | 497 | if (itemMap.containsKey(item))
|
---|
| 498 | {
|
---|
[24509] | 499 | itemMap.remove(item);
|
---|
| 500 | }
|
---|
[24976] | 501 | if (itemMap.size() == 0)
|
---|
| 502 | {
|
---|
[24509] | 503 | docsMap.remove(collection);
|
---|
| 504 | }
|
---|
[24976] | 505 | }
|
---|
[24509] | 506 |
|
---|
| 507 | return result;
|
---|
[24976] | 508 | }
|
---|
[24509] | 509 |
|
---|
[24976] | 510 | protected Element processGetDocuments(Element request)
|
---|
| 511 | {
|
---|
| 512 | // GSXML.printXMLNode(request);
|
---|
[24509] | 513 | Hashtable docsMap = updateDocMap(request);
|
---|
| 514 |
|
---|
| 515 | // Create a new (empty) result message
|
---|
| 516 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[24976] | 517 |
|
---|
| 518 | int size = 0;
|
---|
| 519 | String ids = "";
|
---|
| 520 | Iterator keys = docsMap.keySet().iterator();
|
---|
| 521 |
|
---|
| 522 | while (keys.hasNext())
|
---|
| 523 | {
|
---|
| 524 | Hashtable items = (Hashtable) docsMap.get((String) keys.next());
|
---|
| 525 | size += items.size();
|
---|
[24509] | 526 | Iterator values = items.values().iterator();
|
---|
[24976] | 527 | while (values.hasNext())
|
---|
| 528 | {
|
---|
| 529 | Item item = (Item) values.next();
|
---|
| 530 | result.appendChild(item.wrapIntoElement());
|
---|
| 531 | }
|
---|
[24509] | 532 | }
|
---|
| 533 |
|
---|
[24976] | 534 | Element selement = this.doc.createElement("size");
|
---|
| 535 | selement.setAttribute("value", size + "");
|
---|
| 536 | result.appendChild(selement);
|
---|
[24509] | 537 |
|
---|
[24976] | 538 | return result;
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | private Element getDocumentMetadata(String to, String lang, String uid, Iterator ids)
|
---|
| 542 | {
|
---|
| 543 |
|
---|
| 544 | // Build a request to obtain some document metadata
|
---|
[24509] | 545 | Element dm_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 546 | Element dm_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
|
---|
| 547 | dm_message.appendChild(dm_request);
|
---|
| 548 |
|
---|
| 549 | // Create a parameter list to specify the required metadata information
|
---|
| 550 | HashSet meta_names = new HashSet();
|
---|
| 551 | meta_names.add("Title"); // the default
|
---|
[24976] | 552 | meta_names.add("root_Title");
|
---|
| 553 | meta_names.add("Date");
|
---|
[24509] | 554 |
|
---|
[24976] | 555 | Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
[24509] | 556 |
|
---|
| 557 | Element param = null;
|
---|
| 558 | Iterator i = meta_names.iterator();
|
---|
[24976] | 559 | while (i.hasNext())
|
---|
| 560 | {
|
---|
| 561 | String name = (String) i.next();
|
---|
[24509] | 562 | param = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 563 | param_list.appendChild(param);
|
---|
| 564 | param.setAttribute(GSXML.NAME_ATT, "metadata");
|
---|
| 565 | param.setAttribute(GSXML.VALUE_ATT, name);
|
---|
| 566 | }
|
---|
[24976] | 567 |
|
---|
[24509] | 568 | dm_request.appendChild(param_list);
|
---|
[24976] | 569 |
|
---|
[24509] | 570 | // create the doc node list for the metadata request
|
---|
[24976] | 571 | Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
[24509] | 572 | dm_request.appendChild(dm_doc_list);
|
---|
| 573 |
|
---|
[24976] | 574 | while (ids.hasNext())
|
---|
| 575 | {
|
---|
[24509] | 576 | // Add the documentNode to the list
|
---|
| 577 | Element dm_doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
| 578 | dm_doc_list.appendChild(dm_doc_node);
|
---|
[24976] | 579 | dm_doc_node.setAttribute(GSXML.NODE_ID_ATT, (String) ids.next());
|
---|
[24509] | 580 | }
|
---|
| 581 |
|
---|
| 582 | return (Element) this.router.process(dm_message);
|
---|
[24976] | 583 | }
|
---|
[24509] | 584 |
|
---|
[24976] | 585 | protected Element processDisplayDocumentList(Element request)
|
---|
| 586 | {
|
---|
| 587 | Hashtable docsMap = updateDocMap(request);
|
---|
[24509] | 588 |
|
---|
| 589 | // Create a new (empty) result message
|
---|
| 590 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[24976] | 591 |
|
---|
| 592 | Iterator keys = docsMap.keySet().iterator();
|
---|
| 593 |
|
---|
| 594 | while (keys.hasNext())
|
---|
| 595 | {
|
---|
| 596 | String collection = (String) keys.next();
|
---|
| 597 | Hashtable items = (Hashtable) docsMap.get(collection);
|
---|
[24509] | 598 | Iterator itemItr = items.values().iterator();
|
---|
[24976] | 599 |
|
---|
[24509] | 600 | Element collectionNode = this.doc.createElement("documentList");
|
---|
[24976] | 601 | collectionNode.setAttribute("name", collection);
|
---|
[24509] | 602 | result.appendChild(collectionNode);
|
---|
[24976] | 603 |
|
---|
| 604 | while (itemItr.hasNext())
|
---|
| 605 | {
|
---|
| 606 | Item item = (Item) itemItr.next();
|
---|
[24509] | 607 | Element itemElement = this.doc.createElement("item");
|
---|
[24976] | 608 |
|
---|
[24509] | 609 | collectionNode.appendChild(itemElement);
|
---|
| 610 | itemElement.setAttribute("name", item.docid);
|
---|
| 611 | itemElement.setAttribute("collection", item.collection);
|
---|
[24976] | 612 | itemElement.setAttribute("title", item.title);
|
---|
| 613 | itemElement.setAttribute("date", item.date);
|
---|
| 614 | itemElement.setAttribute("root_title", item.rootTitle);
|
---|
| 615 | }
|
---|
[24509] | 616 | }
|
---|
[24976] | 617 |
|
---|
[24509] | 618 | return result;
|
---|
[24976] | 619 | }
|
---|
[24509] | 620 |
|
---|
[24976] | 621 | protected class Item
|
---|
| 622 | {
|
---|
[24509] | 623 | public String collection;
|
---|
| 624 | public String docid;
|
---|
[24976] | 625 | public String title = "";
|
---|
| 626 | public String query = "";
|
---|
| 627 | public String date = "";
|
---|
| 628 | public String rootTitle = "";
|
---|
| 629 |
|
---|
| 630 | public Item(String coll, String id)
|
---|
| 631 | {
|
---|
[24509] | 632 | this.collection = coll;
|
---|
| 633 | this.docid = id;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
[24976] | 636 | public boolean equals(Object o)
|
---|
| 637 | {
|
---|
| 638 | if (!(o instanceof Item))
|
---|
| 639 | {
|
---|
[24509] | 640 | return false;
|
---|
| 641 | }
|
---|
[24976] | 642 |
|
---|
| 643 | Item item = (Item) o;
|
---|
| 644 | String id = collection + ":" + docid;
|
---|
| 645 | String idin = item.collection + ":" + item.docid;
|
---|
[24509] | 646 | return id.equals(idin);
|
---|
[24976] | 647 | }
|
---|
[24509] | 648 |
|
---|
[24976] | 649 | public String toString()
|
---|
| 650 | {
|
---|
| 651 | return collection + ":" + docid + ":" + "[" + ((!rootTitle.equals("")) ? (rootTitle + ":") : "") + title + "]";
|
---|
| 652 | }
|
---|
[24509] | 653 |
|
---|
[24976] | 654 | public Element wrapIntoElement()
|
---|
| 655 | {
|
---|
| 656 | Element itemElement = doc.createElement("item");
|
---|
[24509] | 657 | itemElement.setAttribute("name", docid);
|
---|
| 658 | itemElement.setAttribute("collection", collection);
|
---|
[24976] | 659 | itemElement.setAttribute("title", title);
|
---|
| 660 | itemElement.setAttribute("date", date);
|
---|
| 661 | itemElement.setAttribute("root_title", rootTitle);
|
---|
| 662 | return itemElement;
|
---|
[24509] | 663 | }
|
---|
[24976] | 664 | }
|
---|
| 665 |
|
---|
[24509] | 666 | private class UserTimer extends Timer implements ActionListener
|
---|
| 667 | {
|
---|
[24976] | 668 | String id = "";
|
---|
[24509] | 669 |
|
---|
[24976] | 670 | public UserTimer(int delay, String id)
|
---|
| 671 | {
|
---|
| 672 | super(delay, (ActionListener) null);
|
---|
[24509] | 673 | addActionListener(this);
|
---|
[24976] | 674 | this.id = id;
|
---|
[24509] | 675 | }
|
---|
| 676 |
|
---|
[24976] | 677 | public void actionPerformed(ActionEvent e)
|
---|
| 678 | {
|
---|
| 679 | userMap.remove(id);
|
---|
[24509] | 680 | timerMap.remove(id);
|
---|
| 681 | stop();
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | }
|
---|