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