protected synchronized void parseCatalogFile()

in xmlresolver-1.2/src/main/java/org/apache/xml/resolver/Catalog.java [809:895]


  protected synchronized void parseCatalogFile(String fileName)
    throws MalformedURLException, IOException, CatalogException {

    CatalogEntry entry;

    // The base-base is the cwd. If the catalog file is specified
    // with a relative path, this assures that it gets resolved
    // properly...
    try {
      // tack on a basename because URLs point to files not dirs
      catalogCwd = FileURL.makeURL("basename");
    } catch (MalformedURLException e) {
      String userdir = System.getProperty("user.dir");
      userdir = userdir.replace('\\', '/');
      catalogManager.debug.message(1, "Malformed URL on cwd", userdir);
      catalogCwd = null;
    }

    // The initial base URI is the location of the catalog file
    try {
      base = new URL(catalogCwd, fixSlashes(fileName));
    } catch (MalformedURLException e) {
      try {
	base = new URL("file:" + fixSlashes(fileName));
      } catch (MalformedURLException e2) {
	catalogManager.debug.message(1, "Malformed URL on catalog filename",
		      fixSlashes(fileName));
	base = null;
      }
    }

    catalogManager.debug.message(2, "Loading catalog", fileName);
    catalogManager.debug.message(4, "Default BASE", base.toString());

    fileName = base.toString();

    DataInputStream inStream = null;
    boolean parsed = false;
    boolean notFound = false;

    for (int count = 0; !parsed && count < readerArr.size(); count++) {
      CatalogReader reader = (CatalogReader) readerArr.get(count);

      try {
	notFound = false;
        // using FileInputStream instand of URL.openStream() 
        // to walk around the file open timeout issue
        File f;
        try {
            f = new File(base.toURI());
        } catch(Exception e) {
            f = new File(base.getPath());
        }
	inStream = new DataInputStream(new FileInputStream(f));
      } catch (FileNotFoundException fnfe) {
	// No catalog; give up!
	notFound = true;
	break;
      }

      try {
	reader.readCatalog(this, inStream);
	parsed = true;
      } catch (CatalogException ce) {
	if (ce.getExceptionType() == CatalogException.PARSE_FAILED) {
	  // give up!
	  break;
	} else {
	  // try again!
	}
      }

      try {
	inStream.close();
      } catch (IOException e) {
	//nop
      }
    }

    if (!parsed) {
      if (notFound) {
	catalogManager.debug.message(3, "Catalog does not exist", fileName);
      } else {
	catalogManager.debug.message(1, "Failed to parse catalog", fileName);
      }
    }
  }