Package javax.xml.stream

Examples of javax.xml.stream.XMLEventReader


    case DOCUMENT: //filter the doc declaration
      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      if (!(r instanceof BufferedReader)) {
        r = new BufferedReader(r);
      }
      XMLEventReader eventReader = inputFactory.createXMLEventReader(r);
      eventReader = inputFactory.createFilteredReader(eventReader, new EventFilter() {
        @Override
        public boolean accept(XMLEvent event) {
          return !event.isStartDocument() && !event.isEndDocument();
        }
View Full Code Here


          throws ThreddsXmlParserException
  {
    try
    {
      XMLInputFactory factory = getFactory();
      XMLEventReader eventReader = factory.createXMLEventReader( source );

      ThreddsBuilderFactory catBuilderFac = new ThreddsBuilderFactoryImpl();
      ThreddsBuilder threddsBuilder = null;
      while ( eventReader.hasNext() )
      {
        XMLEvent event = eventReader.peek();
        if ( event.isEndDocument())
        { // Done!
          eventReader.next();
          break;
        }
        else if ( event.isStartDocument())
        { // Don't need any info from StartDocument event.
          eventReader.next();
        }
        else if ( event.isStartElement())
        {
          if ( this.catElemParserFactory.isEventMyStartElement( event.asStartElement() ))
          {
            CatalogElementParser catElemParser = this.catElemParserFactory.getNewParser( source.getSystemId(),
                                                                                         eventReader, catBuilderFac);
            threddsBuilder = catElemParser.parse();
          }
          // ToDo Implement reading a document with "dataset" root element.
          // ToDo Implement reading a document with "metadata" root element.
          else
          {
            // ToDo Save the results in a ThreddsXmlParserIssue (Warning) and report.
            StaxThreddsXmlParserUtils.consumeElementAndConvertToXmlString( eventReader );
            log.warn( "readCatalogXML(): Unrecognized start element [" + event.asStartElement().getName() + "]." );
            //eventReader.next();
          }
        }
        else if ( event.isEndElement())
        {
          log.error( "readCatalogXML(): Unrecognized end element [" + event.asEndElement().getName() + "]." );
          break;
        }
        else
        {
          log.debug( "readCatalogXML(): Unhandled event [" + event.getLocation() + "--" + event + "].");
          eventReader.next();
          continue;
        }
      }

      eventReader.close();

      if ( threddsBuilder == null )
        return null;

      return (CatalogBuilder) threddsBuilder;
View Full Code Here

    if ( authorityAttValue != null )
      attributes.put( authorityAttName, authorityAttValue );

    String xml = StaxParserUtils.wrapContentXmlInXmlDocRootElement( elemName, attributes, phrase );

    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( xml, "http://test.catalog2.thredds/DateTypeParserTest/someTest.xml" );

    KeyphraseElementParser.Factory fac = new KeyphraseElementParser.Factory();
    StaxParserUtils.advanceReaderToFirstStartElement( reader );
    assertTrue( fac.isEventMyStartElement( reader.peek() ) );

    KeyphraseElementParser keyphraseParser = fac.getNewParser( reader, this.fac, this.tmBldr );
    ThreddsMetadataBuilder.KeyphraseBuilder keyphraseBldr = (ThreddsMetadataBuilder.KeyphraseBuilder) keyphraseParser.parse();
    assertNotNull( keyphraseBldr );
View Full Code Here

  private void assertDateTypeXmlAsExpected( String startDate, String endDate,
                                            String duration, String resolution, String xml )
          throws XMLStreamException, ThreddsXmlParserException
  {
    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( xml, "http://test.catalog2.thredds/DateTypeParserTest/someTest.xml" );
    StaxParserUtils.advanceReaderToFirstStartElement( reader );

    TimeCoverageElementParser.Factory timeCovParserFactory = new TimeCoverageElementParser.Factory();

    assertTrue( timeCovParserFactory.isEventMyStartElement( reader.peek() ));

    TimeCoverageElementParser parser = timeCovParserFactory.getNewParser( reader, this.fac, this.tmBldr );

    ThreddsBuilder bldr = parser.parse();
    assertNotNull( bldr );
View Full Code Here

  private void assertDateTypeXmlAsExpected( String startDate, String endDate,
                                            String duration, String resolution, String xml )
          throws XMLStreamException, ThreddsXmlParserException
  {
    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( xml, "http://test.catalog2.thredds/DateTypeParserTest/someTest.xml" );
    StaxParserUtils.advanceReaderToFirstStartElement( reader );

    TimeCoverageElementParser.Factory timeCovParserFactory = new TimeCoverageElementParser.Factory();

    assertTrue( timeCovParserFactory.isEventMyStartElement( reader.peek() ));

    TimeCoverageElementParser parser = timeCovParserFactory.getNewParser( reader, this.fac, this.tmBldr );

    ThreddsBuilder bldr = parser.parse();
    assertNotNull( bldr );
View Full Code Here

    String xml = CatalogXmlUtils.wrapThreddsXmlInCatalog( "<serviceName>OPeNDAP</serviceName>", null, null, null );
    String baseUriString = "http://test.metadata.parser/tmd.xml";

    Reader reader = new StringReader( xml );
    Source source = new StreamSource( reader, baseUriString );
    XMLEventReader eventReader = factory.createXMLEventReader( source );

    StringWriter writer = new StringWriter();

    while ( eventReader.hasNext() )
    {
      XMLEvent event = eventReader.nextEvent();
      event.writeAsEncodedUnicode( writer );
    }

    writer.flush();
    String resultingXml = writer.toString();
View Full Code Here

    if ( authorityAttValue != null )
      attributes.put( authorityAttName, authorityAttValue );

    String xml = StaxParserUtils.wrapContentXmlInXmlDocRootElement( elemName, attributes, projName );

    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( xml, docBaseUriString );

    ProjectElementParser.Factory fac = new ProjectElementParser.Factory();
    StaxParserUtils.advanceReaderToFirstStartElement( reader );
    assertTrue( fac.isEventMyStartElement( reader.peek() ) );

    ProjectElementParser projectNameParser = fac.getNewParser( reader, this.fac, this.tmBldr );
    ThreddsMetadataBuilder.ProjectNameBuilder projNameBldr = (ThreddsMetadataBuilder.ProjectNameBuilder) projectNameParser.parse();
    assertNotNull( projNameBldr );
View Full Code Here

  }

  private void assertDateTypeXmlAsExpected( QName elemName, String date, String format, String type, String xml )
          throws XMLStreamException, ThreddsXmlParserException
  {
    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( xml, "http://test.catalog2.thredds/DateTypeParserTest/someTest.xml" );

    DateTypeParser.Factory fac = new DateTypeParser.Factory( elemName );
    StaxParserUtils.advanceReaderToFirstStartElement( reader );
    assertTrue( fac.isEventMyStartElement( reader.peek() ));

    DateTypeParser dateTypeParser = fac.getNewDateTypeParser();
    assertNotNull( dateTypeParser );

    dateTypeParser.parseElement( reader );
View Full Code Here

                                                       String expectedRootElementName,
                                                       String expectedStart, String expectedSize,
                                                       String expectedResolution, String expectedUnits )
          throws XMLStreamException, ThreddsXmlParserException
  {
    XMLEventReader reader = StaxParserUtils.createXmlEventReaderOnXmlString( docXml, docBaseUri );
    StaxParserUtils.advanceReaderToFirstStartElement( reader );

    QName rootElemQName = CatalogNamespaceUtils.getThreddsCatalogElementQualifiedName( expectedRootElementName );
    GeospatialRangeTypeParser.Factory factory = new GeospatialRangeTypeParser.Factory( rootElemQName );
    assertNotNull( factory);

    assertTrue( factory.isEventMyStartElement( reader.peek() ));

    GeospatialRangeTypeParser parser = factory.getNewParser( reader, this.fac, this.gspCovBldr );
    assertNotNull( parser);

    ThreddsMetadataBuilder.GeospatialRangeBuilder bldr = (ThreddsMetadataBuilder.GeospatialRangeBuilder) parser.parse();
View Full Code Here

   * @throws ThreddsXmlParserException if have problems reading the source.
   */
  static XMLEventReader getEventReaderFromSource( Source source, XMLInputFactory factory )
          throws ThreddsXmlParserException
  {
    XMLEventReader reader;
    try
    {
      reader = factory.createXMLEventReader( source );
    }
    catch( XMLStreamException e )
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLEventReader

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.