1 4 package org.enhydra.snapper.business; 5 6 10 11 import java.io.File ; 12 import java.sql.Timestamp ; 13 import java.util.Date ; 14 import java.util.Enumeration ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 import java.util.TreeSet ; 19 import java.util.Vector ; 20 import java.util.Hashtable ; 21 22 import org.enhydra.snapper.SnapperAdmin; 23 import org.enhydra.snapper.SnapperManager; 24 import org.enhydra.snapper.api.*; 25 import org.enhydra.snapper.parsers.Parser; 26 import org.enhydra.snapper.spec.*; 27 28 import com.lutris.appserver.server.sql.DBTransaction; 29 import com.lutris.appserver.server.sql.DatabaseManager; 30 31 32 33 35 36 52 53 56 63 64 public class Updater implements UpdaterSpec{ 65 66 Reader reader; 67 Vector notIndexed = new Vector (); 68 69 TreeSet filesToCheck = new TreeSet (); 70 Vector filesToAdd = new Vector (); 71 72 Vector timestamps = new Vector (); 73 Vector tempFiles = new Vector (); 74 Hashtable ftpFilesToAdd = new Hashtable (); 75 Vector origfiles = new Vector (); 76 DocumentStore ds = null; 77 int documentNo = 0; 78 Vector filtered = new Vector (); 79 80 FileChecker fc; 81 Site site; 82 Path[] pathArray; 83 String metaDB ="", metaTable="", metaFileColumn="", metaKeyColumn="", metaValueColumn=""; 84 private boolean doStop; 85 String siteName; 86 private DatabaseManager dbm; 87 88 private String originalHost = ""; 89 90 public Updater(){ 91 } 92 93 public Updater(Site site, Path[] pathArray) { 94 this.site = site; 95 this.pathArray = pathArray; 96 } 97 98 private void setUpReader() { 99 try { 100 siteName = site.getName(); 101 reader = ReaderFactory.createReader("org.enhydra.snapper.wrapper.lucene.LuceneReader"); 102 if (site.getINDEXDIR().length()==0) 103 reader.setUpReader(SnapperAdmin.getIndexDir() + File.separator + siteName); 104 else reader.setUpReader(site.getINDEXDIR()); 105 106 } 107 catch (Exception e) { 108 SnapperManager.getInstance().getLoggingManager().error( 109 "Could not setup reader"); 110 SnapperManager.getInstance().getLoggingManager().debug(e.toString()); 111 112 } 113 } 114 115 public void updateIndex(Site site, Path[] pathArray){ 116 this.site = site; 117 this.pathArray = pathArray; 118 120 try{ 121 setUpReader(); 122 initChecker(this.site.getAge(), this.site.getSize(), this.site); 123 documentNo = this.site.getFILENR(); 124 } 125 catch(Exception ex) { 126 127 SnapperManager.getInstance().getLoggingManager().error( 128 "Could not setup reader"); 129 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 130 } 131 132 try{ 134 if ( site.getINCLUDEDB() != null && site.getINCLUDEDB().length() != 0 135 && site.getINCLUDETABLE() != null && site.getINCLUDETABLE().length() != 0 136 && site.getINCLUDECOLUMN() != null && site.getINCLUDECOLUMN().length() != 0 137 && site.getINCLUDECOLUMNMODIFIED() != null && site.getINCLUDECOLUMNMODIFIED().length() !=0) { 138 139 BusinessUtil bu = new BusinessUtil(dbm); 140 Timestamp start = new Timestamp (System.currentTimeMillis()); 141 TreeSet filesToCheck = bu.getIncludedFiles(site.getINCLUDEDB(), site.getINCLUDETABLE(), site.getINCLUDECOLUMN()); 142 Timestamp end = new Timestamp (System.currentTimeMillis()); 143 SnapperManager.getInstance().getLoggingManager().debug("Getting included files trajalo: " + (end.getTime() - start.getTime()) 144 + " total milliseconds"); 145 146 start = new Timestamp (System.currentTimeMillis()); 147 Map data = new HashMap (bu.getData(site.getINCLUDEDB(), site.getINCLUDETABLE(), site.getINCLUDECOLUMN(), site.getINCLUDECOLUMNMODIFIED(), reader.lastModified())); 148 end = new Timestamp (System.currentTimeMillis()); 150 SnapperManager.getInstance().getLoggingManager().debug("Getting metadata took: " + (end.getTime() - start.getTime()) 151 + " total milliseconds"); 152 site.setLOCKED(null); 153 site.save(); 154 start = new Timestamp (System.currentTimeMillis()); 155 reader.checkDeleted(filesToCheck); 156 end = new Timestamp (System.currentTimeMillis()); 157 SnapperManager.getInstance().getLoggingManager().debug("Check deleted took: " + (end.getTime() - start.getTime()) 158 + " total milliseconds"); 159 start = new Timestamp (System.currentTimeMillis()); 160 for (Iterator iterator = data.entrySet().iterator(); iterator.hasNext();){ 161 Map.Entry entry = (Map.Entry ) iterator.next(); 162 String path = (String )entry.getKey(); 163 filesToAdd.add(new File ((String )entry.getKey())); 164 165 } 166 167 reader.closeReader(); 168 169 setUpReader(); 170 reader.removeDocuments(data); 171 end = new Timestamp (System.currentTimeMillis()); 172 SnapperManager.getInstance().getLoggingManager().debug("Check timestamps took: " + (end.getTime() - start.getTime()) 173 + " total milliseconds"); 174 reader.closeReader(); 175 176 reader = null; 177 Indexer indexer = SnapperManager.getInstance().getIndexerFactory().newIndexer(); 178 if (site.getINDEXDIR().length() == 0) { 179 indexer.setUpIndexer(SnapperAdmin.getIndexDir() + File.separator + site.getName(), "EN", false, SnapperAdmin.getmaxFieldLength()); 180 181 } 182 else { 183 indexer.setUpIndexer(site.getINDEXDIR(), "EN", false, SnapperAdmin.getmaxFieldLength()); 184 } 185 indexer.optimize(); 186 indexer.close(); 187 188 if (filesToAdd.size() > 0) 189 parseAndAdd("","",""); 190 filesToCheck = null; 192 filesToAdd.removeAllElements(); 193 filesToAdd = null; 194 tempFiles.removeAllElements(); 195 tempFiles = null; 196 filtered.removeAllElements(); 197 filtered = null; 198 bu.gc(); 199 bu = null; 200 return; 201 } 202 } 203 catch (Exception e) { 204 SnapperManager.getInstance().getLoggingManager().error( 205 "Could not update include list"); 206 } 207 208 for (int i = 0 ; i < pathArray.length; i++) 210 { if (doStop) 211 { 212 try{ 213 reader.closeReader(); 214 } 215 catch (Exception e) { 216 SnapperManager.getInstance().getLoggingManager().error( 217 "Could not close reader files"); 218 } 219 return; 220 } 221 try{ 222 PathType pathType; 223 String pType; 224 pathType = PathTypeFactory.getPathType("org.enhydra.snapper.business.PathTypeImpl"); 225 DBTransaction dbt = dbm.createTransaction(); 226 pType = (pathType.findPathTypeByID(pathArray[i].getType(), dbt)).getName(); 227 dbt.release(); 228 if (pType.equals("FTP")) 229 { 230 getFTPFiles(pathArray[i]); 231 } 232 else{ 233 getFiles(pathArray[i]); 234 } 235 }catch (Exception e) { 236 SnapperManager.getInstance().getLoggingManager().error( 237 "Could not get files"); 238 } 239 } 240 try{ 241 reader.checkDeleted(filesToCheck); 242 Iterator itr = origfiles.iterator(); 243 while (itr.hasNext()) 244 { 245 Object obj = itr.next(); 246 filesToCheck.remove(obj); 247 } 248 checkFTPFiles(); 249 checkFiles(); 250 } 251 catch (Exception e) { 252 SnapperManager.getInstance().getLoggingManager().error( 253 "Could not check files"); 254 } 255 try{ 256 reader.closeReader(); 257 parseAndAdd(site.getFILTERDB(), site.getFILTERTABLE(), site.getFILTERCOLUMN()); 258 259 filesToCheck = null; 260 filesToAdd.removeAllElements(); 261 filesToAdd = null; 262 origfiles.clear(); 263 origfiles = null; 264 filtered.removeAllElements(); 265 filtered = null; 266 ftpFilesToAdd.clear(); 267 ftpFilesToAdd = null; 268 269 if(ds!=null) 270 { 271 ds.delTempFiles(tempFiles); 272 } 273 ds = null; 274 } 275 catch(Exception ex) { 276 try { 277 SnapperManager.getInstance().getLoggingManager().error( 278 "Could not parse files"); 279 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 280 281 } catch (Exception e) { 282 System.out.println("Could not parse files"); 283 284 }} 285 286 } 287 288 289 public void getFiles(Path path){ 291 292 293 try { 294 originalHost = path.getRoot(); 295 File loc = new File (path.getRoot()); 296 297 if (loc.canRead()) { 298 if (loc.isDirectory()) { 299 String [] files = loc.list(); 300 if (files != null) { 301 for (int p = 0; p < files.length; p++) { 302 if (doStop) return; 303 304 File fl = new File (loc, files[p]); 305 if (fl.isDirectory()) { 306 String [] fls = fl.list(); 307 subfolders(fl, fls); 308 } 309 310 if (fileOK(fl)) 311 filesToCheck.add(fl.getPath()); 312 } 313 } 314 } 315 } 316 317 318 } catch (Exception e) { 319 320 SnapperManager.getInstance().getLoggingManager().error( 321 "Could not get files"); 322 SnapperManager.getInstance().getLoggingManager().debug(e.toString()); 323 } 324 325 } 326 public void getFTPFiles(Path path){ 327 328 try { 329 originalHost = path.getRoot(); 330 ds = new DocumentStore(path.getUser(), path.getRoot(), "FTP", path.getHost(), "", path.getUser(), path.getPass()); 331 ds.connect(); 332 ds.retrieveFile(path.getRoot()); 333 334 timestamps = ds.getTimeStamps(); 335 tempFiles = ds.getTempFiles(); 336 origfiles = ds.getOriginalFiles(); 337 for (int i=0; i< origfiles.size(); i++){ 338 if (doStop){ds.disconnect(); 339 return; 340 } 341 342 if (fileOK(new File (origfiles.elementAt(i).toString()))) 343 filesToCheck.add(origfiles.elementAt(i)); 344 } 345 346 347 ds.disconnect(); 349 } catch (Exception e) { 350 try { 351 SnapperManager.getInstance().getLoggingManager().error( 352 "Could not get files"); 353 SnapperManager.getInstance().getLoggingManager().debug(e.toString()); 354 355 } catch (Exception ex) { 356 System.out.println("Could not get files"); 357 358 }} 359 } 360 361 private void subfolders(File dir, String [] files){ 362 if (files != null) { 363 for (int q = 0; q < files.length; q++) { 364 if (doStop) return; 365 File fl = new File (dir, files[q]); 366 if (fl.isDirectory()) { 367 String [] fls = fl.list(); 368 subfolders(fl, fls); 369 } 370 371 if (fileOK(new File (dir, files[q]))) 372 { 373 filesToCheck.add((new File (dir, files[q])).getPath()); 374 } 375 } 376 } 377 378 } 379 380 381 public boolean fileOK(File file){ 382 return fc.check(file); 383 } 384 385 public void initChecker(int age, int size, Site site){ 386 try{ 387 fc = new FileChecker(age, size, site.getDOC(), site.getHTML(), site.getMSG(), 388 site.getPDF(), site.getRTF(), site.getTXT(), site.getXLS(), site.getPPT(), 389 site.getPPS(), site.getEML(), site.getZIP(), site.getOO(), site.getOO(), site.getOTHER()); 390 } catch (Exception e) { 391 try { 392 SnapperManager.getInstance().getLoggingManager().error( 393 "Could not setup FileChecker"); 394 SnapperManager.getInstance().getLoggingManager().debug( 395 e.toString()); 396 } catch (Exception ex) { 397 System.out.println("Could not setup FileChecker"); 398 } 399 } 400 } 401 416 417 public void checkFiles(){ 418 boolean modified = false; 419 boolean exists = false; 420 String fileToCheck = ""; 421 422 Iterator itr = filesToCheck.iterator(); 423 while (itr.hasNext()){ 424 Object obj = itr.next(); 425 426 try{ 427 428 fileToCheck = String.valueOf(obj.toString()); 429 exists = reader.fileExists(fileToCheck); 431 432 }catch (Exception ex){ 433 try { 434 SnapperManager.getInstance().getLoggingManager().error( 435 "Could not check files"); 436 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 437 438 } catch (Exception e) { 439 System.out.println("Could not check files"); 440 441 }} 442 443 if (exists){ 444 try{ 445 modified = reader.checkLastModified(new File (String.valueOf(obj.toString()))); 446 } catch (Exception ex){ 447 try { 448 SnapperManager.getInstance().getLoggingManager().error( 449 "Could not check files"); 450 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 451 452 } catch (Exception e) { 453 System.out.println("Could not check files"); 454 455 }} 456 if (modified) 457 filesToAdd.add(new String (String.valueOf(obj.toString()))); 458 } 459 else 460 filesToAdd.add(new String (String.valueOf(obj.toString()))); 461 } 462 463 } 464 465 public void checkFiles(Map data){ 466 boolean modified = false; 467 boolean exists = false; 468 File fileToCheck = null; 469 470 471 for (Iterator iterator = data.entrySet().iterator(); iterator.hasNext();){ 472 Map.Entry entry = (Map.Entry ) iterator.next(); 473 474 try{ 475 String path = (String )entry.getKey(); 476 exists = reader.fileExists(path); 477 478 }catch (Exception ex){ 479 try { 480 SnapperManager.getInstance().getLoggingManager().error( 481 "Could not check files"); 482 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 483 484 } catch (Exception e) { 485 System.out.println("Could not check files"); 486 487 }} 488 489 if (exists){ 490 try{ 491 String path = (String )entry.getKey(); 492 long mod = ((Date )entry.getValue()).getTime(); 493 modified = reader.checkLastModified(path, mod); 494 } catch (Exception ex){ 495 try { 496 SnapperManager.getInstance().getLoggingManager().error( 497 "Could not check files"); 498 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 499 500 } catch (Exception e) { 501 System.out.println("Could not check files"); 502 503 }} 504 if (modified) 505 filesToAdd.add(new File ((String )entry.getKey())); 506 } 507 else 508 filesToAdd.add(new File ((String )entry.getKey())); 509 } 510 511 } 512 514 public void checkFTPFiles(){ 515 boolean modified = false; 516 boolean exists = false; 517 File fileToCheck = null; 518 519 Iterator itr = origfiles.iterator(); 520 int i=-1; 521 while (itr.hasNext()){ 522 i++; 523 Object obj = itr.next(); 524 try{ 525 if (((String )obj).endsWith("zip") 526 || ((String )obj).endsWith("ZIP")) { 527 continue; 528 } 529 exists = reader.fileExists((String )obj); 530 } catch (Exception ex){ 531 try { 532 SnapperManager.getInstance().getLoggingManager().error( 533 "Could not check files"); 534 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 535 536 } catch (Exception e) { 537 System.out.println("Could not check files"); 538 539 }} 540 541 if (exists){ 542 try{ 543 modified = reader.checkLastModified((File )tempFiles.elementAt(i), ((Long ) timestamps.elementAt(i)).longValue() ); 544 } catch (Exception ex){ 545 try { 546 SnapperManager.getInstance().getLoggingManager().error( 547 "Could not check files"); 548 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 549 550 } catch (Exception e) { 551 System.out.println("Could not check files"); 552 553 }} 554 if (modified){ 555 if(!((File )tempFiles.elementAt(i)).getAbsolutePath().endsWith("zip")) 556 ftpFilesToAdd.put((String )(origfiles.elementAt(i)),(File )tempFiles.elementAt(i)); 557 } 558 559 } 560 else 561 { 562 if(!((File )tempFiles.elementAt(i)).getAbsolutePath().endsWith("zip")) 563 ftpFilesToAdd.put((String )(origfiles.elementAt(i)),(File )tempFiles.elementAt(i)); 564 } 565 } 566 } 567 568 public void parseAndAdd(String db, String tb, String co){ 570 Parser parser = new Parser(); 573 Indexer indexer = null; 574 filtered = new Vector (); 575 try{ 576 if (db.length()!=0 && tb.length()!= 0 && co.length() != 0) { 577 BusinessUtil bu = new BusinessUtil(dbm); 578 filtered = bu.getFilteredFiles(db, tb, co); 579 } 580 indexer = SnapperManager.getInstance().getIndexerFactory().newIndexer(); 582 if (site.getINDEXDIR().length() == 0) { 583 indexer.setUpIndexer(SnapperAdmin.getIndexDir() + File.separator + site.getName(), "EN", false, SnapperAdmin.getmaxFieldLength()); 584 585 } 586 else { 587 indexer.setUpIndexer(site.getINDEXDIR(), "EN", false, SnapperAdmin.getmaxFieldLength()); 588 } 589 } 590 catch (Exception ex) { 591 592 SnapperManager.getInstance().getLoggingManager().error( 593 "Could not setup indexer"); 594 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 595 596 } 597 boolean error = false; 598 for (int i = 0; i < filesToAdd.size(); i++){ 599 error = false; 600 if (doStop){ 601 indexer.optimize(); 602 indexer.close(); 603 return; 604 } 605 606 if (isFiltered(String.valueOf(filesToAdd.elementAt(i)))) continue; 607 608 609 610 Vector data = parser.parse(new File (String.valueOf(filesToAdd.elementAt(i)))); 611 612 if (String.valueOf(filesToAdd.elementAt(i)).endsWith("zip") 613 || String.valueOf(filesToAdd.elementAt(i)).endsWith("ZIP")) { 614 615 indexUnZippedFiles(data); 616 continue; 617 } 618 619 620 if ((data == null) || (data.size() == 0)){ 621 try{ 622 SnapperManager.getInstance().getLoggingManager().error("Could not index file: " + String.valueOf(filesToAdd.elementAt(i))); 623 } catch (Exception ex) { 624 System.out.println("Could not index file: " + String.valueOf(filesToAdd.elementAt(i))); 625 } 626 error = true; 629 } 630 for (int p = 0; p< data.size(); p++){ 631 if (data.elementAt(p) == null){ 632 try{ 633 SnapperManager.getInstance().getLoggingManager().debug("Could not index file: " + String.valueOf(filesToAdd.elementAt(i))); 634 } catch (Exception ex) { 635 System.out.println("Could not index file: " + String.valueOf(filesToAdd.elementAt(i))); 636 } 637 error = true; 639 } 640 } 641 642 if (error){ 643 644 String filePath = String.valueOf(filesToAdd.elementAt(i)); 645 646 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 647 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 648 filePath= filePath.replaceAll("\\\\","/"); 649 } 650 651 notIndexed.add(filePath); 652 error = false; 657 continue; 658 } 659 try{ 660 try{ 661 SnapperManager.getInstance().getLoggingManager().debug("Updating " + (new File (String.valueOf(filesToAdd.elementAt(i))))); 662 } catch (Exception ex) { 663 System.out.println("Updating " + (new File (String.valueOf(filesToAdd.elementAt(i))))); 664 } 665 666 BusinessUtil bu = new BusinessUtil(dbm); 667 String metadata = new String (bu.getMetadata(String.valueOf(filesToAdd.elementAt(i)), metaDB, metaTable, metaFileColumn, metaKeyColumn, metaValueColumn)); 668 669 String title = ""; 670 if (SnapperManager.getInstance().getLogicalNameFromDatabase().equals("1")) 671 title = new String (bu.title); 672 673 if (title.length() == 0) 674 title = new String (data.elementAt(4).toString()); 675 String confPath = data.elementAt(1).toString(); 676 677 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 678 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 679 680 confPath = confPath.replaceAll("\\\\","/"); 681 originalHost = originalHost.replaceAll("\\\\","/"); 682 } 683 684 if(SnapperManager.getInstance().getRelativeIndexPaths() !=null && 685 SnapperManager.getInstance().getRelativeIndexPaths().equalsIgnoreCase("true")) { 686 687 if(confPath.startsWith(originalHost)){ 688 confPath=confPath.substring(originalHost.length()); 689 if(confPath.startsWith("/")) 690 confPath=confPath.substring(1); 691 } 692 } 693 694 indexer.indexDoc(((Long ) data.elementAt(0)).longValue(), confPath, 695 data.elementAt(2).toString(), data.elementAt(3).toString(), title, 696 data.elementAt(5).toString(), metadata, new File (String.valueOf(filesToAdd.elementAt(i))).getName()); 697 698 try{ 699 SnapperManager.getInstance().getLoggingManager().debug("Updated " + String.valueOf(filesToAdd.elementAt(i))); 700 } catch (Exception ex) { 701 System.out.println("Updated " + String.valueOf(filesToAdd.elementAt(i))); 702 } 703 } 704 catch (Exception ex) { 705 SnapperManager.getInstance().getLoggingManager().error( 706 "Could not index files"); 707 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 708 } 709 710 } 711 for (Enumeration e = ftpFilesToAdd.keys() ; e.hasMoreElements() ;) { 716 717 Object path =null; 718 File tempFile =null; 719 path = e.nextElement(); 720 tempFile = (File )ftpFilesToAdd.get(path); 721 error = false; 722 723 if (doStop){ 724 indexer.optimize(); 725 indexer.close(); 726 return; 727 } 728 729 if (isFiltered(String.valueOf((String )path))) continue; 730 731 Vector data = parser.parse(tempFile); 732 733 if(((String )path).endsWith("zip") || ((String )path).endsWith("ZIP")){ 734 continue; 735 } 736 737 if ((data == null) || (data.size() == 0)){ 738 try{ 739 SnapperManager.getInstance().getLoggingManager().error("Could not index file: " + path); 740 } catch (Exception ex) { 741 System.out.println("Could not index file: " + path); 742 } 743 error = true; 744 } 745 746 for (int p = 0; p< data.size(); p++){ 747 if (data.elementAt(p) == null){ 748 try{ 749 SnapperManager.getInstance().getLoggingManager().debug("Could not index file: " + path); 750 } catch (Exception ex) { 751 System.out.println("Could not index file: " + path); 752 } 753 error = true; 754 } 755 } 756 if (error){ 757 758 String filePath = (String )path; 759 760 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 761 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 762 filePath= filePath.replaceAll("\\\\","/"); 763 } 764 765 notIndexed.add(filePath); 766 error = false; 767 continue; 768 } 769 try{ 770 try{ 771 SnapperManager.getInstance().getLoggingManager().debug("Updating " + path); 772 } catch (Exception ex) { 773 System.out.println("Updating " + path); 774 } 775 776 BusinessUtil bu = new BusinessUtil(dbm); 777 String metadata = new String (bu.getMetadata(((String )path), metaDB, metaTable, metaFileColumn, metaKeyColumn, metaValueColumn)); 778 779 String title = ""; 780 if (SnapperManager.getInstance().getLogicalNameFromDatabase().equals("1")) 781 title = new String (bu.title); 782 783 if (title.length() == 0) 784 title = new String (data.elementAt(4).toString()); 785 786 String confPath = (String )path; 787 788 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 789 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 790 791 confPath = confPath.replaceAll("\\\\","/"); 792 originalHost = originalHost.replaceAll("\\\\","/"); 793 } 794 795 if(SnapperManager.getInstance().getRelativeIndexPaths() !=null && 796 SnapperManager.getInstance().getRelativeIndexPaths().equalsIgnoreCase("true")) { 797 798 if(confPath.startsWith(originalHost)){ 799 confPath=confPath.substring(originalHost.length()); 800 if(confPath.startsWith("/")) 801 confPath=confPath.substring(1); 802 } 803 } 804 805 indexer.indexDoc(((Long ) data.elementAt(0)).longValue(), confPath, 806 data.elementAt(2).toString(), data.elementAt(3).toString(), title, 807 data.elementAt(5).toString(), metadata, tempFile.getName()); 808 809 try{ 810 SnapperManager.getInstance().getLoggingManager().debug("Updated " + path); 811 } catch (Exception ex) { 812 System.out.println("Updated " + path); 813 } 814 815 } 816 catch (Exception ex) { 817 818 SnapperManager.getInstance().getLoggingManager().error( 819 "Could not index files"); 820 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 821 } 822 path =null; 823 tempFile =null; 824 } 825 if (!error){ 826 indexer.optimize(); 827 indexer.close(); 828 } 829 } 830 831 public void addFile(Vector data){ 833 } 834 835 public int getDocumentNo(){ 836 return documentNo; 837 } 838 839 public Vector getNotIndexed(){ 840 return notIndexed; 841 } 842 843 private boolean isFiltered(String filePath){ 844 String path = filePath; 845 path = path.replaceAll("\\\\","/"); 846 if (filtered.contains(path)){ 848 try{ 849 SnapperManager.getInstance().getLoggingManager().debug("File filtered! ---> " + filePath); 850 } catch (Exception ex) { 851 System.out.println("File filtered! ---> " + filePath); 852 } 853 return true; 854 } 855 return false; 856 } 857 858 public void setMeta (String db, String table, String file, String key, String value){ 859 this.metaDB=db; 860 this.metaTable=table; 861 this.metaFileColumn=file; 862 this.metaKeyColumn=key; 863 this.metaValueColumn=value; 864 865 869 } 870 871 public void setDoStop(boolean n) { 872 doStop = n; 873 } 874 875 public void setDBM(DatabaseManager dbm){ 876 this.dbm = dbm; 877 } 878 879 public void indexUnZippedFiles(Vector files) { 880 Parser parser = new Parser(); 881 Indexer indexer = null; 882 filtered = new Vector (); 883 try{ 884 indexer = SnapperManager.getInstance().getIndexerFactory().getIndexer(); 885 886 } 887 catch (Exception ex) { 888 SnapperManager.getInstance().getLoggingManager().error( 889 "Could not setup indexer"); 890 SnapperManager.getInstance().getLoggingManager().debug(ex.toString()); 891 892 } 893 for (int i = 0; i < files.size(); i++) { 894 895 Vector data = (Vector ) files.elementAt(i); 896 if (!checkData(data)) { 897 continue; 898 } 899 try { 900 SnapperManager.getInstance().getLoggingManager().debug( 901 "adding : " + data.elementAt(4).toString()); 902 903 String title = new String (data.elementAt(4).toString()); 904 String confPath = data.elementAt(1).toString(); 906 907 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 908 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 909 confPath = confPath.replaceAll("\\\\","/"); 910 originalHost = originalHost.replaceAll("\\\\","/"); 911 } 912 913 if(SnapperManager.getInstance().getRelativeIndexPaths() !=null && 914 SnapperManager.getInstance().getRelativeIndexPaths().equalsIgnoreCase("true")) { 915 916 917 if(confPath.startsWith(originalHost)){ 918 confPath=confPath.substring(originalHost.length()); 919 if(confPath.startsWith("/")) 920 confPath=confPath.substring(1); 921 } 922 } 923 924 indexer.indexDoc(((Long ) data.elementAt(0)).longValue(), confPath, 925 data.elementAt(2).toString(), 926 data.elementAt(3).toString(), data.elementAt(4) 927 .toString(), data.elementAt(5).toString(), "", 928 data.elementAt(4).toString()); 929 SnapperManager.getInstance().getLoggingManager().debug( 930 "done adding : " + data.elementAt(4).toString()); 931 } 932 933 catch (Exception ex) { 934 parser = null; 935 data.removeAllElements(); 936 data = null; 937 try { 938 SnapperManager.getInstance().getLoggingManager().error( 939 "Could not remove site-lock!"); 940 } catch (Exception e) { 941 System.out.println("Could not remove site-lock!"); 942 } 943 } 944 finally { 945 if (data != null) 946 data.removeAllElements(); 947 data = null; 948 parser = null; 949 } 950 951 952 953 } 954 955 } 956 957 private boolean checkData(Vector data) { 958 if ((data == null) || (data.size() == 0)) { 959 return false; 960 } 961 for (int i = 0; i < data.size(); i++) { 962 if (data.elementAt(i) == null) { 963 try { 964 SnapperManager.getInstance().getLoggingManager().debug( 965 "Could not index file: " 966 + data.elementAt(1).toString()); 967 968 String filePath = data.elementAt(1).toString(); 969 970 if(SnapperManager.getInstance().getFileSeparatorConvention()!=null && 971 SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix")) { 972 filePath= filePath.replaceAll("\\\\","/"); 973 } 974 975 976 notIndexed.add(new String (filePath)); 977 978 979 } catch (Exception ex) { 980 System.out.println("Could not index file: " 981 + data.elementAt(1).toString()); 982 } 983 return false; 984 } 985 986 } 987 return true; 988 } 989 990 991 992 } 993 | Popular Tags |