catalog.java

来自「JAVA 所有包」· Java 代码 · 共 1,991 行 · 第 1/5 页

JAVA
1,991
字号
      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;    en = catalogEntries.elements();    Vector delCats = new Vector();    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == OVERRIDE) {	over = e.getEntryArg(0).equalsIgnoreCase("YES");	continue;      }      if (e.getEntryType() == DELEGATE_PUBLIC	  && (over || systemId == null)) {	String p = (String) 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 enCats = delCats.elements();      if (catalogManager.debug.getDebug() > 1) {	catalogManager.debug.message(2, "Switching to delegated catalog(s):");	while (enCats.hasMoreElements()) {	  String delegatedCatalog = (String) enCats.nextElement();	  catalogManager.debug.message(2, "\t" + delegatedCatalog);	}      }      Catalog dcat = newCatalog();      enCats = delCats.elements();      while (enCats.hasMoreElements()) {	String delegatedCatalog = (String) enCats.nextElement();	dcat.parseCatalog(delegatedCatalog);      }      return dcat.resolvePublic(publicId, null);    }    // Nada!    return null;  }  /**   * Return the applicable SYSTEM system identifier.   *   * <p>If a SYSTEM entry exists in the Catalog   * for the system ID specified, return the mapped value.</p>   *   * <p>On Windows-based operating systems, the comparison between   * the system identifier provided and the SYSTEM entries in the   * Catalog is case-insensitive.</p>   *   * @param systemId The system ID to locate in the catalog.   *   * @return The resolved system identifier.   *   * @throws MalformedURLException The formal system identifier of a   * subordinate catalog cannot be turned into a valid URL.   * @throws IOException Error reading subordinate catalog file.   */  public String resolveSystem(String systemId)    throws MalformedURLException, IOException {    catalogManager.debug.message(3, "resolveSystem("+systemId+")");    systemId = normalizeURI(systemId);    if (systemId != null && systemId.startsWith("urn:publicid:")) {      systemId = PublicId.decodeURN(systemId);      return resolvePublic(systemId, null);    }    // If there's a SYSTEM entry in this catalog, use it    if (systemId != null) {      String resolved = resolveLocalSystem(systemId);      if (resolved != null) {	return resolved;      }    }    // Otherwise, look in the subordinate catalogs    return resolveSubordinateCatalogs(SYSTEM,				      null,				      null,				      systemId);  }  /**   * Return the applicable SYSTEM system identifier in this   * catalog.   *   * <p>If a SYSTEM entry exists in the catalog file   * for the system ID specified, return the mapped value.</p>   *   * @param systemId The system ID to locate in the catalog   *   * @return The mapped system identifier or null   */  protected String resolveLocalSystem(String systemId)    throws MalformedURLException, IOException {    String osname = System.getProperty("os.name");    boolean windows = (osname.indexOf("Windows") >= 0);    Enumeration en = catalogEntries.elements();    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == SYSTEM	  && (e.getEntryArg(0).equals(systemId)	      || (windows		  && e.getEntryArg(0).equalsIgnoreCase(systemId)))) {	return e.getEntryArg(1);      }    }    // If there's a REWRITE_SYSTEM entry in this catalog, use it    en = catalogEntries.elements();    String startString = null;    String prefix = null;    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == REWRITE_SYSTEM) {	String p = (String) e.getEntryArg(0);	if (p.length() <= systemId.length()	    && p.equals(systemId.substring(0, p.length()))) {	  // Is this the longest prefix?	  if (startString == null	      || p.length() > startString.length()) {	    startString = p;	    prefix = e.getEntryArg(1);	  }	}      }    }    if (prefix != null) {      // return the systemId with the new prefix      return prefix + systemId.substring(startString.length());    }    // If there's a SYSTEM_SUFFIX entry in this catalog, use it    en = catalogEntries.elements();    String suffixString = null;    String suffixURI = null;    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == SYSTEM_SUFFIX) {	String p = (String) e.getEntryArg(0);	if (p.length() <= systemId.length()	    && systemId.endsWith(p)) {	  // Is this the longest prefix?	  if (suffixString == null	      || p.length() > suffixString.length()) {	    suffixString = p;	    suffixURI = e.getEntryArg(1);	  }	}      }    }    if (suffixURI != null) {      // return the systemId for the suffix      return suffixURI;    }    // If there's a DELEGATE_SYSTEM entry in this catalog, use it    en = catalogEntries.elements();    Vector delCats = new Vector();    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == DELEGATE_SYSTEM) {	String p = (String) e.getEntryArg(0);	if (p.length() <= systemId.length()	    && p.equals(systemId.substring(0, p.length()))) {	  // delegate this match to the other catalog	  delCats.addElement(e.getEntryArg(1));	}      }    }    if (delCats.size() > 0) {      Enumeration enCats = delCats.elements();      if (catalogManager.debug.getDebug() > 1) {	catalogManager.debug.message(2, "Switching to delegated catalog(s):");	while (enCats.hasMoreElements()) {	  String delegatedCatalog = (String) enCats.nextElement();	  catalogManager.debug.message(2, "\t" + delegatedCatalog);	}      }      Catalog dcat = newCatalog();      enCats = delCats.elements();      while (enCats.hasMoreElements()) {	String delegatedCatalog = (String) enCats.nextElement();	dcat.parseCatalog(delegatedCatalog);      }      return dcat.resolveSystem(systemId);    }    return null;  }  /**   * Return the applicable URI.   *   * <p>If a URI entry exists in the Catalog   * for the URI specified, return the mapped value.</p>   *   * <p>URI comparison is case sensitive.</p>   *   * @param uri The URI to locate in the catalog.   *   * @return The resolved URI.   *   * @throws MalformedURLException The system identifier of a   * subordinate catalog cannot be turned into a valid URL.   * @throws IOException Error reading subordinate catalog file.   */  public String resolveURI(String uri)    throws MalformedURLException, IOException {    catalogManager.debug.message(3, "resolveURI("+uri+")");    uri = normalizeURI(uri);    if (uri != null && uri.startsWith("urn:publicid:")) {      uri = PublicId.decodeURN(uri);      return resolvePublic(uri, null);    }    // If there's a URI entry in this catalog, use it    if (uri != null) {      String resolved = resolveLocalURI(uri);      if (resolved != null) {	return resolved;      }    }    // Otherwise, look in the subordinate catalogs    return resolveSubordinateCatalogs(URI,				      null,				      null,				      uri);  }  /**   * Return the applicable URI in this catalog.   *   * <p>If a URI entry exists in the catalog file   * for the URI specified, return the mapped value.</p>   *   * @param uri The URI to locate in the catalog   *   * @return The mapped URI or null   */  protected String resolveLocalURI(String uri)    throws MalformedURLException, IOException {    Enumeration en = catalogEntries.elements();    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == URI	  && (e.getEntryArg(0).equals(uri))) {	return e.getEntryArg(1);      }    }    // If there's a REWRITE_URI entry in this catalog, use it    en = catalogEntries.elements();    String startString = null;    String prefix = null;    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == REWRITE_URI) {	String p = (String) e.getEntryArg(0);	if (p.length() <= uri.length()	    && p.equals(uri.substring(0, p.length()))) {	  // Is this the longest prefix?	  if (startString == null	      || p.length() > startString.length()) {	    startString = p;	    prefix = e.getEntryArg(1);	  }	}      }    }    if (prefix != null) {      // return the uri with the new prefix      return prefix + uri.substring(startString.length());    }    // If there's a URI_SUFFIX entry in this catalog, use it    en = catalogEntries.elements();    String suffixString = null;    String suffixURI = null;    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == URI_SUFFIX) {	String p = (String) e.getEntryArg(0);	if (p.length() <= uri.length()	    && uri.endsWith(p)) {	  // Is this the longest prefix?	  if (suffixString == null	      || p.length() > suffixString.length()) {	    suffixString = p;	    suffixURI = e.getEntryArg(1);	  }	}      }    }    if (suffixURI != null) {      // return the uri for the suffix      return suffixURI;    }    // If there's a DELEGATE_URI entry in this catalog, use it    en = catalogEntries.elements();    Vector delCats = new Vector();    while (en.hasMoreElements()) {      CatalogEntry e = (CatalogEntry) en.nextElement();      if (e.getEntryType() == DELEGATE_URI) {	String p = (String) e.getEntryArg(0);	if (p.length() <= uri.length()	    && p.equals(uri.substring(0, p.length()))) {	  // delegate this match to the other catalog	  delCats.addElement(e.getEntryArg(1));	}      }    }    if (delCats.size() > 0) {      Enumeration enCats = delCats.elements();      if (catalogManager.debug.getDebug() > 1) {	catalogManager.debug.message(2, "Switching to delegated catalog(s):");	while (enCats.hasMoreElements()) {	  String delegatedCatalog = (String) enCats.nextElement();	  catalogManager.debug.message(2, "\t" + delegatedCatalog);	}      }      Catalog dcat = newCatalog();      enCats = delCats.elements();      while (enCats.hasMoreElements()) {	String delegatedCatalog = (String) enCats.nextElement();	dcat.parseCatalog(delegatedCatalog);      }      return dcat.resolveURI(uri);    }    return null;  }  /**   * Search the subordinate catalogs, in order, looking for a match.   *   * <p>This method searches the Catalog and returns the system   * identifier specified for the given entity type with the given   * name, public, and system identifiers. In some contexts, these   * may be null.</p>   *   * @param entityType The CatalogEntry type for which this query is   * being conducted. This is necessary in order to do the approprate   * query on a subordinate catalog.   * @param entityName The name of the entity being searched for, if   * ap

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?