src/main/java/org/jboss/util/xml/catalog/Catalog.java
protected synchronized String resolveLocalPublic(int entityType,
						   String entityName,
						   String publicId,
						   String systemId)
    throws MalformedURLException, IOException {

    // Always normalize the public identifier before attempting a match
    publicId = PublicId.normalize(publicId);

    // If there's a SYSTEM entry in this catalog, use it
    if (systemId != null) {
      String resolved = resolveLocalSystem(systemId);
      if (resolved != null) {
	return resolved;
      }
    }

    // If there's a PUBLIC entry in this catalog, use it
    boolean over = default_override;
    Enumeration enumt = catalogEntries.elements();
    while (enumt.hasMoreElements()) {
      CatalogEntry e = (CatalogEntry) enumt.nextElement();
      if (e.getEntryType() == OVERRIDE) {
	over = e.getEntryArg(0).equalsIgnoreCase("YES");
	continue;
      }

      if (e.getEntryType() == PUBLIC
	  && e.getEntryArg(0).equals(publicId)) {
	if (over || systemId == null) {
	  return e.getEntryArg(1);
	}
      }
    }

    // If there's a DELEGATE_PUBLIC entry in this catalog, use it
    over = default_override;
    enumt = catalogEntries.elements();
    Vector delCats = new Vector();
    while (enumt.hasMoreElements()) {
      CatalogEntry e = (CatalogEntry) enumt.nextElement();
      if (e.getEntryType() == OVERRIDE) {
	over = e.getEntryArg(0).equalsIgnoreCase("YES");
	continue;
      }

      if (e.getEntryType() == DELEGATE_PUBLIC
	  && (over || systemId == null)) {
	String p = e.getEntryArg(0);
	if (p.length() <= publicId.length()
	    && p.equals(publicId.substring(0, p.length()))) {
	  // delegate this match to the other catalog

	  delCats.addElement(e.getEntryArg(1));
	}
      }
    }

    if (delCats.size() > 0) {
      Enumeration enumCats = delCats.elements();

      if (catalogManager.debug.getDebug() > 1) {
	catalogManager.debug.message(2, "Switching to delegated catalog(s):");
	while (enumCats.hasMoreElements()) {
	  String delegatedCatalog = (String) enumCats.nextElement();
	  catalogManager.debug.message(2, "\t" + delegatedCatalog);
	}
      }

      Catalog dcat = newCatalog();

      enumCats = delCats.elements();
      while (enumCats.hasMoreElements()) {
	String delegatedCatalog = (String) enumCats.nextElement();
	dcat.parseCatalog(delegatedCatalog);
      }

      return dcat.resolvePublic(publicId, null);
    }

    // Nada!
    return null;
  }
protected synchronized String resolveLocalPublic(int entityType,
						   String entityName,
						   String publicId,
						   String systemId)
    throws MalformedURLException, IOException {

    // Always normalize the public identifier before attempting a match
    publicId = PublicId.normalize(publicId);

    // If there's a SYSTEM entry in this catalog, use it
    if (systemId != null) {
      String resolved = resolveLocalSystem(systemId);
      if (resolved != null) {
	return resolved;
      }
    }

    // If there's a PUBLIC entry in this catalog, use it
    boolean over = default_override;
    Enumeration enumt = catalogEntries.elements();
    while (enumt.hasMoreElements()) {
      CatalogEntry e = (CatalogEntry) enumt.nextElement();
      if (e.getEntryType() == OVERRIDE) {
	over = e.getEntryArg(0).equalsIgnoreCase("YES");
	continue;
      }

      if (e.getEntryType() == PUBLIC
	  && e.getEntryArg(0).equals(publicId)) {
	if (over || systemId == null) {
	  return e.getEntryArg(1);
	}
      }
    }

    // If there's a DELEGATE_PUBLIC entry in this catalog, use it
    over = default_override;
    enumt = catalogEntries.elements();
    Vector delCats = new Vector();
    while (enumt.hasMoreElements()) {
      CatalogEntry e = (CatalogEntry) enumt.nextElement();
      if (e.getEntryType() == OVERRIDE) {
	over = e.getEntryArg(0).equalsIgnoreCase("YES");
	continue;
      }

      if (e.getEntryType() == DELEGATE_PUBLIC
	  && (over || systemId == null)) {
	String p = e.getEntryArg(0);
	if (p.length() <= publicId.length()
	    && p.equals(publicId.substring(0, p.length()))) {
	  // delegate this match to the other catalog

	  delCats.addElement(e.getEntryArg(1));
	}
      }
    }

    if (delCats.size() > 0) {
      Enumeration enumCats = delCats.elements();

      if (catalogManager.debug.getDebug() > 1) {
	catalogManager.debug.message(2, "Switching to delegated catalog(s):");
	while (enumCats.hasMoreElements()) {
	  String delegatedCatalog = (String) enumCats.nextElement();
	  catalogManager.debug.message(2, "\t" + delegatedCatalog);
	}
      }

      Catalog dcat = newCatalog();

      enumCats = delCats.elements();
      while (enumCats.hasMoreElements()) {
	String delegatedCatalog = (String) enumCats.nextElement();
	dcat.parseCatalog(delegatedCatalog);
      }

      return dcat.resolvePublic(publicId, null);
    }

    // Nada!
    return null;
  }
protected synchronized String resolveLocalPublic ( int entityType , String entityName , String publicId , String systemId ) throws MalformedURLException , IOException { // Always normalize the public identifier before attempting a match publicId = PublicId . normalize ( publicId ) ; // If there's a SYSTEM entry in this catalog, use it if ( systemId != null ) { String resolved = resolveLocalSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } } // If there's a PUBLIC entry in this catalog, use it boolean over = default_override ; Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == OVERRIDE ) { over = e . getEntryArg ( 0 ) . equalsIgnoreCase ( "YES" ) ; continue ; } if ( e . getEntryType ( ) == PUBLIC && e . getEntryArg ( 0 ) . equals ( publicId ) ) { if ( over || systemId == null ) { return e . getEntryArg ( 1 ) ; } } } // If there's a DELEGATE_PUBLIC entry in this catalog, use it over = default_override ; enumt = catalogEntries . elements ( ) ; Vector delCats = new Vector ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == OVERRIDE ) { over = e . getEntryArg ( 0 ) . equalsIgnoreCase ( "YES" ) ; continue ; } if ( e . getEntryType ( ) == DELEGATE_PUBLIC && ( over || systemId == null ) ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= publicId . length ( ) && p . equals ( publicId . substring ( 0 , p . length ( ) ) ) ) { // delegate this match to the other catalog delCats . addElement ( e . getEntryArg ( 1 ) ) ; } } } if ( delCats . size ( ) > 0 ) { Enumeration enumCats = delCats . elements ( ) ; if ( catalogManager . debug . getDebug ( ) > 1 ) { catalogManager . debug . message ( 2 , "Switching to delegated catalog(s):" ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; catalogManager . debug . message ( 2 , "\t" + delegatedCatalog ) ; } } Catalog dcat = newCatalog ( ) ; enumCats = delCats . elements ( ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; dcat . parseCatalog ( delegatedCatalog ) ; } return dcat . resolvePublic ( publicId , null ) ; } // Nada! return null ; }
Return the applicable PUBLIC or SYSTEM identifier.

<p>This method searches the Catalog and returns the system
identifier specified for the given system or public identifiers.
If no appropriate PUBLIC or SYSTEM entry is found in the Catalog,
delegated Catalogs are interrogated.</p>

<p>There are four possible cases:</p>

<ul>
<li>If the system identifier provided matches a SYSTEM entry
in the current catalog, the SYSTEM entry is returned.
<li>If the system identifier is not null, the PUBLIC entries
that were encountered when OVERRIDE YES was in effect are
interrogated and the first matching entry is returned.</li>
<li>If the system identifier is null, then all of the PUBLIC
entries are interrogated and the first matching entry
is returned. This may not be the same as the preceding case, if
some PUBLIC entries are encountered when OVERRIDE NO is in effect. In
XML, the only place where a public identifier may occur without
a system identifier is in a notation declaration.</li>
<li>Finally, if the public identifier matches one of the partial
public identifiers specified in a DELEGATE* entry in
the Catalog, the delegated catalog is interrogated. The first
time that the delegated catalog is required, it will be
retrieved and parsed. It is subsequently cached.
</li>
</ul>

@param entityType The CatalogEntry type for which this query is
being conducted. This is necessary in order to do the approprate
query on a delegated catalog.
@param entityName The name of the entity being searched for, if
appropriate.
@param publicId The public identifier of the entity in question.
@param systemId The nominal system identifier for the entity
in question (as provided in the source document).

@throws MalformedURLException The formal system identifier of a
delegated catalog cannot be turned into a valid URL.
@throws IOException Error reading delegated catalog file.

@return The system identifier to use.
Note that the nominal system identifier is not returned if a
match is not found in the catalog, instead null is returned
to indicate that no match was found.
Return the applicable PUBLIC or SYSTEM identifier .