com.sun.org.apache.xml.internal.resolver.CatalogException Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.resolver.CatalogException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedXMLCatalogReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = Catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #2
Source File: XCatalogReader.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #3
Source File: ExtendedXMLCatalogReader.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #4
Source File: DOMCatalogReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #5
Source File: XCatalogReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #6
Source File: ExtendedXMLCatalogReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #7
Source File: DOMCatalogReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #8
Source File: XCatalogReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #9
Source File: ExtendedXMLCatalogReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #10
Source File: DOMCatalogReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #11
Source File: XCatalogReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = Catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = Catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicID"));
    entryArgs.add(atts.getValue("HRef"));

    debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicID")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = Catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = Catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicID"));
    entryArgs.add(atts.getValue("HRef"));

    debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicID")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = Catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemID"));
    entryArgs.add(atts.getValue("HRef"));

    debug.message(4, "Remap",
                  atts.getValue("SystemID"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
}
 
Example #12
Source File: DOMCatalogReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #13
Source File: DOMCatalogReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #14
Source File: XCatalogReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #15
Source File: ExtendedXMLCatalogReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #16
Source File: DOMCatalogReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #17
Source File: XCatalogReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #18
Source File: ExtendedXMLCatalogReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #19
Source File: DOMCatalogReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #20
Source File: XCatalogReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #21
Source File: ExtendedXMLCatalogReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #22
Source File: XCatalogReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #23
Source File: DOMCatalogReader.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #24
Source File: ExtendedXMLCatalogReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #25
Source File: DOMCatalogReader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}
 
Example #26
Source File: ExtendedXMLCatalogReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #27
Source File: XCatalogReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #28
Source File: XCatalogReader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method recognizes elements
 * from the plain catalog format and instantiates CatalogEntry
 * objects for them.
 *
 * @param namespaceURI The namespace name of the element.
 * @param localName The local name of the element.
 * @param qName The QName of the element.
 * @param atts The list of attributes on the element.
 *
 * @see CatalogEntry
 */
public void startElement (String namespaceURI,
                          String localName,
                          String qName,
                          Attributes atts)
  throws SAXException {

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (localName.equals("Base")) {
    entryType = catalog.BASE;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
  } else if (localName.equals("Delegate")) {
    entryType = catalog.DELEGATE_PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Delegate",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Extend")) {
    entryType = catalog.CATALOG;
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
  } else if (localName.equals("Map")) {
    entryType = catalog.PUBLIC;
    entryArgs.add(atts.getValue("PublicId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Map",
                  PublicId.normalize(atts.getValue("PublicId")),
                  atts.getValue("HRef"));
  } else if (localName.equals("Remap")) {
    entryType = catalog.SYSTEM;
    entryArgs.add(atts.getValue("SystemId"));
    entryArgs.add(atts.getValue("HRef"));

    catalog.getCatalogManager().debug.message(4, "Remap",
                  atts.getValue("SystemId"),
                  atts.getValue("HRef"));
  } else if (localName.equals("XMLCatalog")) {
    // nop, start of catalog
  } else {
    // This is equivalent to an invalid catalog entry type
    catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
  }

  if (entryType >= 0) {
    try {
      CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
      catalog.addEntry(ce);
    } catch (CatalogException cex) {
      if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
      } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
        catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
      }
    }
  }
  }
 
Example #29
Source File: ExtendedXMLCatalogReader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example #30
Source File: DOMCatalogReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read a catalog from an input stream.
 *
 * <p>This class reads a catalog from an input stream:</p>
 *
 * <ul>
 * <li>Based on the QName of the root element, it determines which
 * parser to instantiate for this catalog.</li>
 * <li>It constructs a DOM Document from the catalog and</li>
 * <li>For each child of the root node, it calls the parser's
 * parseCatalogEntry method. This method is expected to make
 * appropriate calls back into the catalog to add entries for the
 * entries in the catalog. It is free to do this in whatever manner
 * is appropriate (perhaps using just the node passed in, perhaps
 * wandering arbitrarily throughout the tree).</li>
 * </ul>
 *
 * @param catalog The catalog for which this reader is called.
 * @param is The input stream that is to be read.
 * @throws IOException if the URL cannot be read.
 * @throws UnknownCatalogFormatException if the catalog format is
 * not recognized.
 * @throws UnparseableCatalogException if the catalog cannot be parsed.
 * (For example, if it is supposed to be XML and isn't well-formed or
 * if the parser class cannot be instantiated.)
 */
public void readCatalog(Catalog catalog, InputStream is)
  throws IOException, CatalogException {

  DocumentBuilderFactory factory = null;
  DocumentBuilder builder = null;

  factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(false);
  factory.setValidating(false);
  try {
    builder = factory.newDocumentBuilder();
  } catch (ParserConfigurationException pce) {
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Document doc = null;

  try {
    doc = builder.parse(is);
  } catch (SAXException se) {
    throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
  }

  Element root = doc.getDocumentElement();

  String namespaceURI = Namespaces.getNamespaceURI(root);
  String localName    = Namespaces.getLocalName(root);

  String domParserClass = getCatalogParser(namespaceURI,
                                           localName);

  if (domParserClass == null) {
    if (namespaceURI == null) {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + localName);
    } else {
      catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
                                                + "{" + namespaceURI + "}"
                                                + localName);
    }
    return;
  }

  DOMCatalogParser domParser = null;

  try {
    domParser = (DOMCatalogParser) ReflectUtil.forName(domParserClass).newInstance();
  } catch (ClassNotFoundException cnfe) {
    catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (InstantiationException ie) {
    catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (IllegalAccessException iae) {
    catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  } catch (ClassCastException cce ) {
    catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
    throw new CatalogException(CatalogException.UNPARSEABLE);
  }

  Node node = root.getFirstChild();
  while (node != null) {
    domParser.parseCatalogEntry(catalog, node);
    node = node.getNextSibling();
  }
}