Package org.dom4j.io

Examples of org.dom4j.io.SAXReader


      log.warn( "Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null." );
      return;
    }
    XMLHelper xmlHelper = new XMLHelper();
    List errors = new ArrayList();
    SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, cfg.getEntityResolver() );
    try {
      saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
      //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
      //set the default schema locators
      saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
          "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd");
    }
    catch (SAXException e) {
      saxReader.setValidation( false );
    }

    for ( String xmlFile : xmlFiles ) {

      InputStream resourceAsStream = newTempClassLoader.getResourceAsStream( xmlFile );
      if (resourceAsStream == null) continue;
      BufferedInputStream is = new BufferedInputStream( resourceAsStream );
      try {
        errors.clear();
        org.dom4j.Document doc = saxReader.read( is );
        if ( errors.size() != 0 ) {
          throw new MappingException( "invalid mapping: " + xmlFile, (Throwable) errors.get( 0 ) );
        }
        Element rootElement = doc.getRootElement();
        if ( rootElement != null && "entity-mappings".equals( rootElement.getName() ) ) {
View Full Code Here


  /**
   * Create a dom4j SAXReader which will append all validation errors
   * to errorList
   */
  public SAXReader createSAXReader(String file, List errorsList, EntityResolver entityResolver) {
    if (saxReader==null) saxReader = new SAXReader();
    saxReader.setEntityResolver(entityResolver);
    saxReader.setErrorHandler( new ErrorLogger(file, errorsList) );
    saxReader.setMergeAdjacentText(true);
    saxReader.setValidation(true);
    return saxReader;
View Full Code Here

  @Override
  public AnnotationConfiguration addInputStream(InputStream xmlInputStream) throws MappingException {
    try {
      List errors = new ArrayList();
      SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, getEntityResolver() );
      try {
        saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
        //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
        //set the default schema locators
        saxReader.setProperty(
            "http://apache.org/xml/properties/schema/external-schemaLocation",
            "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
        );
      }
      catch (SAXException e) {
        saxReader.setValidation( false );
      }
      org.dom4j.Document doc = saxReader
          .read( new InputSource( xmlInputStream ) );

      if ( errors.size() != 0 ) {
        throw new MappingException( "invalid mapping", (Throwable) errors.get( 0 ) );
      }
View Full Code Here

      log.warn( "Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null." );
      return;
    }
    XMLHelper xmlHelper = new XMLHelper();
    List errors = new ArrayList();
    SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, cfg.getEntityResolver() );
    try {
      saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
      //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
      //set the default schema locators
      saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
          "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd");
    }
    catch (SAXException e) {
      saxReader.setValidation( false );
    }

    for ( String xmlFile : xmlFiles ) {

      InputStream resourceAsStream = newTempClassLoader.getResourceAsStream( xmlFile );
      if (resourceAsStream == null) continue;
      BufferedInputStream is = new BufferedInputStream( resourceAsStream );
      try {
        errors.clear();
        org.dom4j.Document doc = saxReader.read( is );
        if ( errors.size() != 0 ) {
          throw new MappingException( "invalid mapping: " + xmlFile, (Throwable) errors.get( 0 ) );
        }
        Element rootElement = doc.getRootElement();
        if ( rootElement != null && "entity-mappings".equals( rootElement.getName() ) ) {
View Full Code Here

    Exception failure;

    ErrorLogger errorHandler = new ErrorLogger();

    SAXReader saxReader = new SAXReader();
    saxReader.setEntityResolver( entityResolver );
    saxReader.setErrorHandler( errorHandler );
    saxReader.setMergeAdjacentText( true );
    saxReader.setValidation( true );

    Document document = null;
    try {
      // first try with orm 2.1 xsd validation
      setValidationFor( saxReader, "orm_2_1.xsd" );
      document = saxReader.read( source );
      if ( errorHandler.hasErrors() ) {
        throw errorHandler.getErrors().get( 0 );
      }
      return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
    }
    catch ( Exception e ) {
      if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Problem parsing XML using orm 2.1 xsd, trying 2.0 xsd : %s", e.getMessage() );
      }
      failure = e;
      errorHandler.reset();

      if ( document != null ) {
        // next try with orm 2.0 xsd validation
        try {
          setValidationFor( saxReader, "orm_2_0.xsd" );
          document = saxReader.read( new StringReader( document.asXML() ) );
          if ( errorHandler.hasErrors() ) {
            errorHandler.logErrors();
            throw errorHandler.getErrors().get( 0 );
          }
          return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
        }
        catch ( Exception e2 ) {
          if ( LOG.isDebugEnabled() ) {
            LOG.debugf( "Problem parsing XML using orm 2.0 xsd, trying 1.0 xsd : %s", e2.getMessage() );
          }
          errorHandler.reset();

          if ( document != null ) {
            // next try with orm 1.0 xsd validation
            try {
              setValidationFor( saxReader, "orm_1_0.xsd" );
              document = saxReader.read( new StringReader( document.asXML() ) );
              if ( errorHandler.hasErrors() ) {
                errorHandler.logErrors();
                throw errorHandler.getErrors().get( 0 );
              }
              return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
View Full Code Here

   *
   * @return Create and return a dom4j {@code SAXReader} which will append all validation errors
   *         to the passed error list
   */
  public SAXReader createSAXReader(ErrorHandler errorHandler, EntityResolver entityResolver) {
    SAXReader saxReader = resolveSAXReader();
    saxReader.setEntityResolver( entityResolver );
    saxReader.setErrorHandler( errorHandler );
    return saxReader;
  }
View Full Code Here

    return saxReader;
  }

  private SAXReader resolveSAXReader() {
    if ( saxReader == null ) {
      saxReader = new SAXReader();
      saxReader.setMergeAdjacentText( true );
      saxReader.setValidation( true );
    }
    return saxReader;
  }
View Full Code Here

        return Parseable.parse(str, cls);
    }

    static Document parse(final String xmlStr) {
        try {
            final SAXReader saxReader = new SAXReader();
            Document doc = saxReader.read(new StringReader(xmlStr));
            return doc;
        } catch (DocumentException e) {
            throw new IsisException(e);
        }
    }
View Full Code Here

     */
    static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException, InterruptedException {
        List<SuiteResult> r = new ArrayList<SuiteResult>();

        // parse into DOM
        SAXReader saxReader = new SAXReader();
        ParserConfigurator.applyConfiguration(saxReader,new SuiteResultParserConfigurationContext(xmlReport));

        Document result = saxReader.read(xmlReport);
        Element root = result.getRootElement();

        parseSuite(xmlReport,keepLongStdio,r,root);

        return r;
View Full Code Here

        p.writeTo(bean,depth,Flavor.XML.createDataWriter(bean,sw));

        // apply XPath
        Object result;
        try {
            Document dom = new SAXReader().read(new StringReader(sw.toString()));

            // apply exclusions
            if (excludes!=null) {
                for (String exclude : excludes) {
                    List<org.dom4j.Node> list = (List<org.dom4j.Node>)dom.selectNodes(exclude);
View Full Code Here

TOP

Related Classes of org.dom4j.io.SAXReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.