1 8 package org.apache.avalon.excalibur.catalog; 9 10 import java.io.FileNotFoundException; 11 import java.io.IOException; 12 import java.lang.Integer; 13 import java.net.MalformedURLException; 14 import java.net.URL; 15 import java.util.Enumeration; 16 import java.util.Hashtable; 17 import java.util.Vector; 18 import org.xml.sax.SAXException; 19 20 122 public class Catalog 123 { 124 138 public int debug = 0; 139 140 144 private URL base; 145 146 149 private URL catalogCwd; 150 151 154 private Vector catalogEntries = new Vector(); 155 156 159 private boolean default_override = true; 160 161 173 private Vector catalogFiles = new Vector(); 174 175 194 private Vector localCatalogFiles = new Vector(); 195 196 214 private Vector catalogs = new Vector(); 215 216 232 private Vector localDelegate = new Vector(); 233 234 244 private String parserClass = null; 245 246 254 public Catalog() 255 { 256 String property = System.getProperty( "xml.catalog.debug" ); 257 258 if( property != null ) 259 { 260 try 261 { 262 debug = Integer.parseInt( property ); 263 } 264 catch( NumberFormatException e ) 265 { 266 debug = 0; 267 } 268 } 269 270 property = System.getProperty( "xml.catalog.override" ); 271 272 if( property != null ) 273 { 274 default_override = ( property.equalsIgnoreCase( "true" ) 275 || property.equalsIgnoreCase( "yes" ) 276 || property.equalsIgnoreCase( "1" ) ); 277 } 278 } 279 280 292 public void loadSystemCatalogs() 293 throws MalformedURLException, IOException 294 { 295 String PCS = System.getProperty( "path.separator" ); 296 String catalog_files = System.getProperty( "xml.catalog.files" ); 297 298 while( catalog_files != null ) 299 { 300 int pos = catalog_files.indexOf( PCS ); 301 String catfile = null; 302 303 if( pos > 0 ) 304 { 305 catfile = catalog_files.substring( 0, pos ); 306 catalog_files = catalog_files.substring( pos + 1 ); 307 } 308 else 309 { 310 catfile = catalog_files; 311 catalog_files = null; 312 } 313 314 catalogFiles.addElement( catfile ); 315 } 316 317 if( catalogFiles.size() > 0 ) 318 { 319 String catfile = (String)catalogFiles.lastElement(); 332 catalogFiles.removeElement( catfile ); 333 parseCatalog( catfile ); 334 } 335 } 336 337 347 public synchronized void parseCatalog( String fileName ) 348 throws MalformedURLException, IOException 349 { 350 351 catalogFiles.addElement( fileName ); 355 356 int curCat = 0; 360 while( curCat < catalogFiles.size() ) 361 { 362 String catfile = (String)catalogFiles.elementAt( curCat++ ); 363 364 if( catalogEntries.size() == 0 && catalogs.size() == 0 ) 365 { 366 parseCatalogFile( catfile ); 369 } 370 else 371 { 372 catalogs.addElement( catfile ); 375 } 376 377 if( !localCatalogFiles.isEmpty() ) 378 { 379 Vector newQueue = new Vector(); 382 Enumeration q = localCatalogFiles.elements(); 383 while( q.hasMoreElements() ) 384 { 385 newQueue.addElement( q.nextElement() ); 386 } 387 388 while( curCat < catalogFiles.size() ) 390 { 391 catfile = (String)catalogFiles.elementAt( curCat++ ); 392 newQueue.addElement( catfile ); 393 } 394 395 localCatalogFiles = new Vector(); 396 catalogFiles = newQueue; 397 curCat = 0; 398 } 399 400 if( !localDelegate.isEmpty() ) 401 { 402 Enumeration e = localDelegate.elements(); 403 while( e.hasMoreElements() ) 404 { 405 catalogEntries.addElement( e.nextElement() ); 406 } 407 localDelegate = new Vector(); 408 } 409 } 410 411 catalogFiles = new Vector(); 413 } 414 415 450 public void parseAllCatalogs() 451 throws MalformedURLException, IOException 452 { 453 454 for( int catPos = 0; catPos < catalogs.size(); catPos++ ) 456 { 457 Catalog c = null; 458 459 try 460 { 461 c = (Catalog)catalogs.elementAt( catPos ); 462 } 463 catch( ClassCastException e ) 464 { 465 String catfile = (String)catalogs.elementAt( catPos ); 466 c = new Catalog(); 467 c.setParserClass( parserClass ); 468 c.debug = debug; 469 470 c.parseCatalog( catfile ); 471 catalogs.setElementAt( c, catPos ); 472 c.parseAllCatalogs(); 473 } 474 } 475 476 Enumeration enum = catalogEntries.elements(); 478 while( enum.hasMoreElements() ) 479 { 480 CatalogEntry e = (CatalogEntry)enum.nextElement(); 481 if( e.entryType() == CatalogEntry.DELEGATE ) 482 { 483 Catalog dcat = new Catalog(); 484 dcat.setParserClass( parserClass ); 485 dcat.debug = debug; 486 dcat.parseCatalog( e.formalSystemIdentifier() ); 487 } 488 } 489 } 490 491 492 508 public String resolveDoctype( String entityName, 509 String publicId, 510 String systemId ) 511 throws MalformedURLException, IOException 512 { 513 String resolved = null; 514 515 if( systemId != null ) 516 { 517 resolved = resolveLocalSystem( systemId ); 519 if( resolved != null ) 520 { 521 return resolved; 522 } 523 } 524 525 if( publicId != null ) 526 { 527 resolved = resolveLocalPublic( CatalogEntry.DOCTYPE, 529 entityName, 530 publicId, 531 systemId ); 532 if( resolved != null ) 533 { 534 return resolved; 535 } 536 } 537 538 boolean over = default_override; 540 Enumeration enum = catalogEntries.elements(); 541 while( enum.hasMoreElements() ) 542 { 543 CatalogEntry e = (CatalogEntry)enum.nextElement(); 544 if( e.entryType() == CatalogEntry.OVERRIDE ) 545 { 546 over = e.yes_or_no().equalsIgnoreCase( "YES" ); 547 continue; 548 } 549 550 if( e.entryType() == CatalogEntry.DOCTYPE 551 && e.entityName().equals( entityName ) ) 552 { 553 if( over || systemId == null ) 554 { 555 return e.formalSystemIdentifier(); 556 } 557 } 558 } 559 560 return resolveSubordinateCatalogs( CatalogEntry.DOCTYPE, 562 entityName, 563 publicId, 564 systemId ); 565 } 566 567 577 public String resolveDocument() 578 throws MalformedURLException, IOException 579 { 580 Enumeration enum = catalogEntries.elements(); 582 while( enum.hasMoreElements() ) 583 { 584 CatalogEntry e = (CatalogEntry)enum.nextElement(); 585 if( e.entryType() == CatalogEntry.DOCUMENT ) 586 { 587 return e.formalSystemIdentifier(); 588 } 589 } 590 591 return resolveSubordinateCatalogs( CatalogEntry.DOCUMENT, 592 null, null, null ); 593 } 594 595 611 public String resolveEntity( String entityName, 612 String publicId, 613 String systemId ) 614 throws MalformedURLException, IOException 615 { 616 String resolved = null; 617 618 if( systemId != null ) 619 { 620 resolved = resolveLocalSystem( systemId ); 622 if( resolved != null ) 623 { 624 return resolved; 625 } 626 } 627 628 if( publicId != null ) 629 { 630 resolved = resolveLocalPublic( CatalogEntry.ENTITY, 632 entityName, 633 publicId, 634 systemId ); 635 if( resolved != null ) 636 { 637 return resolved; 638 } 639 } 640 641 boolean over = default_override; 643 Enumeration enum = catalogEntries.elements(); 644 while( enum.hasMoreElements() ) 645 { 646 CatalogEntry e = (CatalogEntry)enum.nextElement(); 647 if( e.entryType() == CatalogEntry.OVERRIDE ) 648 { 649 over = e.yes_or_no().equalsIgnoreCase( "YES" ); 650 continue; 651 } 652 653 if( e.entryType() == CatalogEntry.ENTITY 654 && e.entityName().equals( entityName ) ) 655 { 656 if( over || systemId == null ) 657 { 658 return e.formalSystemIdentifier(); 659 } 660 } 661 } 662 663 return resolveSubordinateCatalogs( CatalogEntry.ENTITY, 665 entityName, 666 publicId, 667 systemId ); 668 } 669 670 686 public String resolveNotation( String notationName, 687 String publicId, 688 String systemId ) 689 throws MalformedURLException, IOException 690 { 691 String resolved = null; 692 693 if( systemId != null ) 694 { 695 resolved = resolveLocalSystem( systemId ); 697 if( resolved != null ) 698 { 699 return resolved; 700 } 701 } 702 703 if( publicId != null ) 704 { 705 resolved = resolveLocalPublic( CatalogEntry.NOTATION, 707 notationName, 708 publicId, 709 systemId ); 710 if( resolved != null ) 711 { 712 return resolved; 713 } 714 } 715 716 boolean over = default_override; 718 Enumeration enum = catalogEntries.elements(); 719 while( enum.hasMoreElements() ) 720 { 721 CatalogEntry e = (CatalogEntry)enum.nextElement(); 722 if( e.entryType() == CatalogEntry.OVERRIDE ) 723 { 724 over = e.yes_or_no().equalsIgnoreCase( "YES" ); 725 continue; 726 } 727 728 if( e.entryType() == CatalogEntry.NOTATION 729 && e.entityName().equals( notationName ) ) 730 { 731 if( over || systemId == null ) 732 { 733 return e.formalSystemIdentifier(); 734 } 735 } 736 } 737 738 return resolveSubordinateCatalogs( CatalogEntry.NOTATION, 740 notationName, 741 publicId, 742 systemId ); 743 } 744 745 765 public String resolvePublic( String publicId, String systemId ) 766 throws MalformedURLException, IOException 767 { 768 769 if( systemId != null ) 771 { 772 String resolved = resolveLocalSystem( systemId ); 773 if( resolved != null ) 774 { 775 return resolved; 776 } 777 } 778 779 String resolved = resolveLocalPublic( CatalogEntry.PUBLIC, 781 null, 782 publicId, 783 systemId ); 784 if( resolved != null ) 785 { 786 return resolved; 787 } 788 789 return resolveSubordinateCatalogs( CatalogEntry.PUBLIC, 791 null, 792 publicId, 793 systemId ); 794 } 795 796 819 public String resolveSystem( String systemId ) 820 throws MalformedURLException, IOException 821 { 822 823 if( systemId != null ) 825 { 826 String resolved = resolveLocalSystem( systemId ); 827 if( resolved != null ) 828 { 829 return resolved; 830 } 831 } 832 833 return resolveSubordinateCatalogs( CatalogEntry.SYSTEM, 835 null, 836 null, 837 systemId ); 838 } 839 840 853 public void setParserClass( String parser ) 854 { 855 parserClass = parser; 856 } 857 858 868 private synchronized void parseCatalogFile( String fileName ) 869 throws MalformedURLException, IOException 870 { 871 872 CatalogEntry entry; 873 874 try 878 { 879 String userdir = fixSlashes( System.getProperty( "user.dir" ) ); 881 catalogCwd = new URL( new StringBuffer("file:///").append(userdir).append("/basename").toString() ); 882 } 883 catch( MalformedURLException e ) 884 { 885 String userdir = fixSlashes( System.getProperty( "user.dir" ) ); 886 debug( 1, "Malformed URL on cwd", userdir ); 887 catalogCwd = null; 888 } 889 890 try 892 { 893 base = new URL( catalogCwd, fixSlashes( fileName ) ); 894 } 895 catch( MalformedURLException e ) 896 { 897 try 898 { 899 base = new URL( "file:///" + fixSlashes( fileName ) ); 900 } 901 catch( MalformedURLException e2 ) 902 { 903 debug( 1, "Malformed URL on catalog filename", 904 fixSlashes( fileName ) ); 905 base = null; 906 } 907 } 908 909 debug( 1, "Loading catalog", fileName ); 910 debug( 3, "Default BASE", base.toString() ); 911 912 fileName = base.toString(); 913 914 if( parserClass != null ) 915 { 916 try 917 { 918 XMLCatalogReader catfile = new XMLCatalogReader(); 919 catfile.setParserClass( parserClass ); 920 catfile.parseCatalog( fileName ); 921 922 CatalogEntry ce = null; 923 while( ( ce = catfile.nextEntry() ) != null ) 924 { 925 addEntry( ce ); 926 } 927 return; 928 } 929 catch( SAXException e1 ) 930 { 931 } 933 catch( NoXMLParserException e2 ) 934 { 935 } 937 catch( NotXMLCatalogException e2 ) 938 { 939 } 941 catch( InstantiationException e3 ) 942 { 943 debug( 1, "Cannot instantiate XML Parser class", parserClass ); 944 } 945 catch( IllegalAccessException e4 ) 946 { 947 debug( 1, "Cannot access XML Parser class", parserClass ); 948 } 949 catch( ClassNotFoundException e5 ) 950 { 951 debug( 1, "Cannot load XML Parser class", parserClass ); 952 } 953 catch( UnknownCatalogFormatException e6 ) 954 { 955 debug( 1, "Unrecognized XML Catalog format." ); 956 return; 957 } 958 } 959 960 CatalogReader catfile = new CatalogReader(); 961 catfile.parseCatalog( fileName ); 962 963 while( ( entry = catfile.nextEntry() ) != null ) 966 { 967 addEntry( entry ); 968 } 969 } 970 971 982 private void addEntry( CatalogEntry entry ) 983 { 984 switch ( entry.entryType() ) 985 { 986 case CatalogEntry.BASE: 987 { 988 String value = entry.formalSystemIdentifier(); 989 URL newbase = null; 990 991 debug( 3, "BASE", value ); 992 993 try 994 { 995 value = fixSlashes( value ); 996 newbase = new URL( catalogCwd, value ); 997 } 998 catch( MalformedURLException e ) 999 { 1000 try 1001 { 1002 newbase = new URL( "file:///" + value ); 1003 } 1004 catch( MalformedURLException e2 ) 1005 { 1006 debug( 1, "Malformed URL on base", value ); 1007 newbase = null; 1008 } 1009 } 1010 1011 if( newbase != null ) 1012 { 1013 base = newbase; 1014 } 1015 1016 break; 1017 } 1018 1019 case CatalogEntry.CATALOG: 1020 { 1021 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1022 1023 debug( 3, "CATALOG", fsi ); 1024 1025 localCatalogFiles.addElement( fsi ); 1026 break; 1027 } 1028 1029 case CatalogEntry.DOCUMENT: 1030 { 1031 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1032 entry.updateFormalSystemIdentifier( fsi ); 1033 1034 debug( 3, "DOCUMENT", fsi ); 1035 1036 catalogEntries.addElement( entry ); 1037 break; 1038 } 1039 case CatalogEntry.OVERRIDE: 1040 { 1041 debug( 3, "OVERRIDE", entry.yes_or_no() ); 1042 1043 catalogEntries.addElement( entry ); 1044 break; 1045 } 1046 case CatalogEntry.SGMLDECL: 1047 { 1048 break; 1050 } 1051 case CatalogEntry.DELEGATE: 1052 { 1053 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1054 entry.updateFormalSystemIdentifier( fsi ); 1055 1056 debug( 3, "DELEGATE", entry.partialPublicId(), fsi ); 1057 1058 addDelegate( entry ); 1059 break; 1060 } 1061 case CatalogEntry.DOCTYPE: 1062 { 1063 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1064 entry.updateFormalSystemIdentifier( fsi ); 1065 1066 debug( 3, "DOCTYPE", entry.publicId(), fsi ); 1067 1068 catalogEntries.addElement( entry ); 1069 break; 1070 } 1071 case CatalogEntry.DTDDECL: 1072 { 1073 break; 1075 } 1076 case CatalogEntry.ENTITY: 1077 { 1078 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1079 entry.updateFormalSystemIdentifier( fsi ); 1080 1081 debug( 3, "ENTITY", entry.entityName(), fsi ); 1082 1083 catalogEntries.addElement( entry ); 1084 break; 1085 } 1086 case CatalogEntry.LINKTYPE: 1087 { 1088 break; 1090 } 1091 case CatalogEntry.NOTATION: 1092 { 1093 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1094 entry.updateFormalSystemIdentifier( fsi ); 1095 1096 debug( 3, "NOTATION", entry.entityName(), fsi ); 1097 1098 catalogEntries.addElement( entry ); 1099 break; 1100 } 1101 case CatalogEntry.PUBLIC: 1102 { 1103 String publicid = entry.publicId(); 1106 String systemid = makeAbsolute( entry.formalSystemIdentifier() ); 1107 1108 debug( 3, "PUBLIC", publicid, systemid ); 1109 1110 entry.updateFormalSystemIdentifier( systemid ); 1111 catalogEntries.addElement( entry ); 1112 break; 1113 } 1114 case CatalogEntry.SYSTEM: 1115 { 1116 String systemid = entry.systemId(); 1117 String fsi = makeAbsolute( entry.formalSystemIdentifier() ); 1118 1119 debug( 3, "SYSTEM", systemid, fsi ); 1120 1121 entry.updateFormalSystemIdentifier( fsi ); 1122 catalogEntries.addElement( entry ); 1123 break; 1124 } 1125 } 1126 } 1127 1128 1174 private synchronized String resolveLocalPublic( int entityType, 1175 String entityName, 1176 String publicId, 1177 String systemId ) 1178 throws MalformedURLException, IOException 1179 { 1180 1181 publicId = CatalogReader.normalize( publicId ); 1183 1184 if( systemId != null ) 1186 { 1187 String resolved = resolveLocalSystem( systemId ); 1188 if( resolved != null ) 1189 { 1190 return resolved; 1191 } 1192 } 1193 1194 boolean over = default_override; 1196 Enumeration enum = catalogEntries.elements(); 1197 while( enum.hasMoreElements() ) 1198 { 1199 CatalogEntry e = (CatalogEntry)enum.nextElement(); 1200 if( e.entryType() == CatalogEntry.OVERRIDE ) 1201 { 1202 over = e.yes_or_no().equalsIgnoreCase( "YES" ); 1203 continue; 1204 } 1205 1206 if( e.entryType() == CatalogEntry.PUBLIC 1207 && e.publicId().equals( publicId ) ) 1208 { 1209 if( over || systemId == null ) 1210 { 1211 return e.formalSystemIdentifier(); 1212 } 1213 } 1214 } 1215 1216 over = default_override; 1218 enum = catalogEntries.elements(); 1219 Vector delCats = new Vector(); 1220 while( enum.hasMoreElements() ) 1221 { 1222 CatalogEntry e = (CatalogEntry)enum.nextElement(); 1223 if( e.entryType() == CatalogEntry.OVERRIDE ) 1224 { 1225 over = e.yes_or_no().equalsIgnoreCase( "YES" ); 1226 continue; 1227 } 1228 1229 if( e.entryType() == CatalogEntry.DELEGATE 1230 && ( over || systemId == null ) ) 1231 { 1232 String p = (String)e.partialPublicId(); 1233 if( p.length() <= publicId.length() 1234 && p.equals( publicId.substring( 0, p.length() ) ) ) 1235 { 1236 1238 delCats.addElement( e.formalSystemIdentifier() ); 1239 } 1240 } 1241 } 1242 1243 if( delCats.size() > 0 ) 1244 { 1245 Enumeration enumCats = delCats.elements(); 1246 1247 if( debug > 0 ) 1248 { 1249 debug( 1, "Switching to delegated catalog(s):" ); 1250 while( enumCats.hasMoreElements() ) 1251 { 1252 String delegatedCatalog = (String)enumCats.nextElement(); 1253 debug( 1, "\t" + delegatedCatalog ); 1254 } 1255 } 1256 1257 Catalog dcat = new Catalog(); 1258 dcat.setParserClass( parserClass ); 1259 dcat.debug = debug; 1260 1261 enumCats = delCats.elements(); 1262 while( enumCats.hasMoreElements() ) 1263 { 1264 String delegatedCatalog = (String)enumCats.nextElement(); 1265 dcat.parseCatalog( delegatedCatalog ); 1266 } 1267 1268 return dcat.resolvePublic( publicId, null ); 1269 } 1270 1271 return null; 1273 } 1274 1275 1286 private String resolveLocalSystem( String systemId ) 1287 { 1288 String osname = System.getProperty( "os.name" ); 1289 boolean windows = ( osname.indexOf( "Windows" ) >= 0 ); 1290 Enumeration enum = catalogEntries.elements(); 1291 while( enum.hasMoreElements() ) 1292 { 1293 CatalogEntry e = (CatalogEntry)enum.nextElement(); 1294 if( e.entryType() == CatalogEntry.SYSTEM 1295 && ( e.systemId().equals( systemId ) 1296 || ( windows 1297 && e.systemId().equalsIgnoreCase( systemId ) ) ) ) 1298 { 1299 return e.formalSystemIdentifier(); 1300 } 1301 } 1302 return null; 1303 } 1304 1305 1306 1331 private synchronized String resolveSubordinateCatalogs( int entityType, 1332 String entityName, 1333 String publicId, 1334 String systemId ) 1335 throws MalformedURLException, IOException 1336 { 1337 1338 for( int catPos = 0; catPos < catalogs.size(); catPos++ ) 1339 { 1340 Catalog c = null; 1341 1342 try 1343 { 1344 c = (Catalog)catalogs.elementAt( catPos ); 1345 } 1346 catch( ClassCastException e ) 1347 { 1348 String catfile = (String)catalogs.elementAt( catPos ); 1349 c = new Catalog(); 1350 c.setParserClass( parserClass ); 1351 c.debug = debug; 1352 1353 try 1354 { 1355 c.parseCatalog( catfile ); 1356 } 1357 catch( MalformedURLException mue ) 1358 { 1359 debug( 1, "Malformed Catalog URL", catfile ); 1360 } 1361 catch( FileNotFoundException fnfe ) 1362 { 1363 debug( 1, "Failed to load catalog, file not found", 1364 catfile ); 1365 } 1366 catch( IOException ioe ) 1367 { 1368 debug( 1, "Failed to load catalog, I/O error", catfile ); 1369 } 1370 1371 catalogs.setElementAt( c, catPos ); 1372 } 1373 1374 String resolved = null; 1375 1376 switch ( entityType ) 1378 { 1379 case CatalogEntry.DOCTYPE: 1380 { 1381 resolved = c.resolveDoctype( entityName, 1382 publicId, 1383 systemId ); 1384 break; 1385 } 1386 case CatalogEntry.DOCUMENT: 1387 { 1388 resolved = c.resolveDocument(); 1389 break; 1390 } 1391 case CatalogEntry.ENTITY: 1392 { 1393 resolved = c.resolveEntity( entityName, 1394 publicId, 1395 systemId ); 1396 break; 1397 } 1398 case CatalogEntry.NOTATION: 1399 { 1400 resolved = c.resolveNotation( entityName, 1401 publicId, 1402 systemId ); 1403 break; 1404 } 1405 case CatalogEntry.PUBLIC: 1406 { 1407 resolved = c.resolvePublic( publicId, systemId ); 1408 break; 1409 } 1410 case CatalogEntry.SYSTEM: 1411 { 1412 resolved = c.resolveSystem( systemId ); 1413 break; 1414 } 1415 } 1416 1417 if( resolved != null ) 1418 { 1419 return resolved; 1420 } 1421 } 1422 1423 return null; 1424 } 1425 1426 1428 1438 private String fixSlashes( String sysid ) 1439 { 1440 return sysid.replace( '\\', '/' ); 1441 } 1442 1443 1453 private String makeAbsolute( String sysid ) 1454 { 1455 URL local = null; 1456 1457 sysid = fixSlashes( sysid ); 1458 1459 try 1460 { 1461 local = new URL( base, sysid ); 1462 } 1463 catch( MalformedURLException e ) 1464 { 1465 debug( 1, "Malformed URL on system identifier", sysid ); 1466 } 1467 1468 if( local != null ) 1469 { 1470 return local.toString(); 1471 } 1472 else 1473 { 1474 return sysid; 1475 } 1476 } 1477 1478 1488 private void debug( int level, String message ) 1489 { 1490 if( debug >= level ) 1491 { 1492 System.out.println( message ); 1493 } 1494 } 1495 1496 1507 private void debug( int level, String message, String spec ) 1508 { 1509 if( debug >= level ) 1510 { 1511 System.out.println( new StringBuffer(message).append(": ").append(spec) ); 1512 } 1513 } 1514 1515 1527 private void debug( int level, String message, String spec1, String spec2 ) 1528 { 1529 if( debug >= level ) 1530 { 1531 System.out.println( new StringBuffer(message).append(": ").append(spec1) ); 1532 System.out.println( "\t" + spec2 ); 1533 } 1534 } 1535 1536 1538 1548 private void addDelegate( CatalogEntry entry ) 1549 { 1550 int pos = 0; 1551 String partial = entry.partialPublicId(); 1552 1553 Enumeration local = localDelegate.elements(); 1554 while( local.hasMoreElements() ) 1555 { 1556 CatalogEntry dpe = (CatalogEntry)local.nextElement(); 1557 String dp = dpe.partialPublicId(); 1558 if( dp.equals( partial ) ) 1559 { 1560 return; 1562 } 1563 if( dp.length() > partial.length() ) 1564 { 1565 pos++; 1566 } 1567 if( dp.length() < partial.length() ) 1568 { 1569 break; 1570 } 1571 } 1572 1573 if( localDelegate.size() == 0 ) 1575 { 1576 localDelegate.addElement( entry ); 1577 } 1578 else 1579 { 1580 localDelegate.insertElementAt( entry, pos ); 1581 } 1582 } 1583} 1584 | Popular Tags |