コード例 #1
0
ファイル: XMLDataObjectImpl.java プロジェクト: kimtang/studio
  static Parser makeParser(boolean validate) {

    SAXParserFactory factory = makeParserFactory(validate, false);

    try {
      return factory.newSAXParser().getParser();
    } catch (ParserConfigurationException ex) {
      notifyNewSAXParserEx(ex);
      return null;
    } catch (SAXException ex) {
      notifyNewSAXParserEx(ex);
      return null;
    }
  }
コード例 #2
0
ファイル: XMLDataObjectImpl.java プロジェクト: kimtang/studio
  /** Return XML reader or null if no provider exists. */
  static XMLReader makeXMLReader(boolean validating, boolean namespaces) {

    SAXParserFactory factory = makeParserFactory(validating, namespaces);

    try {
      return factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
      notifyNewSAXParserEx(ex);
      return null;
    } catch (SAXException ex) {
      notifyNewSAXParserEx(ex);
      return null;
    }
  }
コード例 #3
0
ファイル: XMLUtil.java プロジェクト: tpso-src/thirdparty
  private static SAXParserFactory createFastSAXParserFactory()
      throws ParserConfigurationException, SAXException {
    if (fastParserFactoryClass == null) {
      try {
        fastParserFactoryClass =
            Class.forName("org.apache.crimson.jaxp.SAXParserFactoryImpl"); // NOI18N
      } catch (Exception ex) {
        useFastSAXParserFactory = false;
        if (System.getProperty("java.version").startsWith("1.4")) { // NOI18N
          ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        }
      }
    }
    if (fastParserFactoryClass != null) {
      try {
        SAXParserFactory factory = (SAXParserFactory) fastParserFactoryClass.newInstance();

        return factory;
      } catch (Exception ex) {
        useFastSAXParserFactory = false;
        throw new ParserConfigurationException(ex.getMessage());
      }
    }

    return SAXParserFactory.newInstance();
  }
コード例 #4
0
ファイル: XMLDataObjectImpl.java プロジェクト: kimtang/studio
  private static SAXParserFactory makeParserFactory(boolean validating, boolean ns) {
    SAXParserFactory factory = null;

    // create factory according to javax.xml.parsers.SAXParserFactory property
    // or platform default (i.e. com.sun...)
    try {
      factory = SAXParserFactory.newInstance();
      factory.setValidating(validating);
      factory.setNamespaceAware(ns);

    } catch (FactoryConfigurationError err) {
      notifyFactoryErr(err, "javax.xml.parsers.SAXParserFactory"); // NOI18N
      throw err;
    }

    return factory;
  }
コード例 #5
0
ファイル: XMLUtil.java プロジェクト: tpso-src/thirdparty
  /**
   * Create a SAX parser from the JAXP factory. The result can be used to parse XML files.
   *
   * <p>See class Javadoc for hints on setting an entity resolver. This parser has its entity
   * resolver set to the system entity resolver chain.
   *
   * @param validate if true, a validating parser is returned
   * @param namespaceAware if true, a namespace aware parser is returned
   * @throws FactoryConfigurationError Application developers should never need to directly catch
   *     errors of this type.
   * @throws SAXException if a parser fulfilling given parameters can not be created
   * @return XMLReader configured according to passed parameters
   */
  public static XMLReader createXMLReader(boolean validate, boolean namespaceAware)
      throws SAXException {

    SAXParserFactory factory;
    if (!validate && useFastSAXParserFactory) {
      try {
        factory = createFastSAXParserFactory();
      } catch (ParserConfigurationException ex) {
        factory = SAXParserFactory.newInstance();
      } catch (SAXException ex) {
        factory = SAXParserFactory.newInstance();
      }
    } else {
      useFastSAXParserFactory = false;
      factory = SAXParserFactory.newInstance();
    }

    factory.setValidating(validate);
    factory.setNamespaceAware(namespaceAware);

    try {
      return factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
      throw new SAXException(
          "Cannot create parser satisfying configuration parameters", ex); // NOI18N
    }
  }