source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentBasket.java@ 32453

Last change on this file since 32453 was 28966, checked in by kjdon, 10 years ago

Lots of changes. Mainly to do with removing this.doc from everywhere. Document is not thread safe. Now we tend to create a new Document everytime we are starting a new page/message etc. in service this.desc_doc is available as teh document to create service info stuff. But it should only be used for this and not for other messages. newDOM is now static for XMLConverter. method param changes for some GSXML methods.

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