Package org.apache.tuscany.sca.common.xml.stax

Examples of org.apache.tuscany.sca.common.xml.stax.StAXHelper$Attribute


    @org.junit.Test
    public void testReader() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();

        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);
        XMLStreamReader r1 = helper.createXMLStreamReader(new StringReader(xml));
        XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1);
        XMLStreamReader2String t1 = new XMLStreamReader2String(extensionPointRegistry);
        String result = t1.transform(r2, null);
        System.out.println(result);
        XMLStreamReader r3 = helper.createXMLStreamReader(new StringReader(xml));
        r3.nextTag();
        r3.nextTag();
        Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType());
        Assert.assertEquals(new QName(null, "e2"), r3.getName());
        XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3);
View Full Code Here


        // This is a hack to create an instance of the binding using the XML QName
        StringBuffer xml = new StringBuffer();
        xml.append("<").append(mappedBinding.getLocalPart()).append(" xmlns:b=\"").append(mappedBinding
            .getNamespaceURI()).append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));
        return binding;
    }
View Full Code Here

        }

        StringBuffer xml = new StringBuffer();
        xml.append("<").append(bindingType.getLocalPart()).append(" xmlns:b=\"").append(bindingType.getNamespaceURI()).append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));
       
        return binding;
    }
View Full Code Here

    @org.junit.Test
    public void testReader() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();

        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);
        XMLStreamReader r1 = helper.createXMLStreamReader(new StringReader(xml));
        XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1);
        XMLStreamReader2String t1 = new XMLStreamReader2String(extensionPointRegistry);
        String result = t1.transform(r2, null);
        System.out.println(result);
        XMLStreamReader r3 = helper.createXMLStreamReader(new StringReader(xml));
        r3.nextTag();
        r3.nextTag();
        Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType());
        Assert.assertEquals(new QName(null, "e2"), r3.getName());
        XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3);
View Full Code Here

        "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my json string\"}}}";

    @Test
    public void testXML2JSON() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper staxHelper = StAXHelper.getInstance(extensionPointRegistry);

        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(IPO_XML));
        XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(extensionPointRegistry);
        JSONObject json = (JSONObject)t1.transform(reader, null);
        Assert.assertNotNull(json);

        // Cannot round-trip as we hit a bug in Jettison: http://jira.codehaus.org/browse/JETTISON-93
View Full Code Here

    }

    @Test
    public void testJSON2XML() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);

        JSON2XMLStreamReader t2 = new JSON2XMLStreamReader();
        XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null);
        StringWriter sw = new StringWriter();
        XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
        helper.save(reader2, streamWriter);
        Assert.assertTrue(sw.toString()
            .contains("<xsl:root xmlns:xsl=\"http://foo.com\"><data>my json string</data></xsl:root>"));
    }
View Full Code Here

        // This is a hack to create an instance of the binding using the XML QName
        StringBuffer xml = new StringBuffer();
        xml.append("<").append(mappedBinding.getLocalPart()).append(" xmlns:b=\"").append(mappedBinding
            .getNamespaceURI()).append("\"/>");

        StAXHelper staxHelper = StAXHelper.getInstance(registry);
        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(xml.toString()));
        reader.nextTag();
        Binding binding = (Binding)processor.read(reader, new ProcessorContext(registry));
        return binding;
    }
View Full Code Here

    @org.junit.Test
    public void testReader() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();

        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);
        XMLStreamReader r1 = helper.createXMLStreamReader(new StringReader(xml));
        XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1);
        XMLStreamReader2String t1 = new XMLStreamReader2String(extensionPointRegistry);
        String result = t1.transform(r2, null);
        System.out.println(result);
        XMLStreamReader r3 = helper.createXMLStreamReader(new StringReader(xml));
        r3.nextTag();
        r3.nextTag();
        Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType());
        Assert.assertEquals(new QName(null, "e2"), r3.getName());
        XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3);
View Full Code Here

    this.handleQCInformation();

    this.ncFile.addAttribute( null, qcFlagsAtt );

    // Add some general metadata in global attributes.
    this.ncFile.addAttribute( null, new Attribute( "title",
                                                   new StringBuffer("NGDC archived ")
                                                   .append( datasetIdAtt.getStringValue())
                                                   .append( " data with start time ")
                                                   .append( startDateAtt.getStringValue())
                                                   .toString()));
    this.ncFile.addAttribute( null, new Attribute( "Convention", _Coordinate.Convention));

    // Add some THREDDS specific metadata in global attributes.
    this.ncFile.addAttribute( null, new Attribute( "thredds_creator", "DOD/USAF/SMC > Space and Missile Systems Center (SMC), U.S. Air Force, U.S. Department of Defense"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_contributor", "DOC/NOAA/NESDIS/NGDC > National Geophysical Data Center, NESDIS, NOAA, U.S. Department of Commerce"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_contributor_role", "archive"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher", "DOC/NOAA/NESDIS/NGDC > National Geophysical Data Center, NESDIS, NOAA, U.S. Department of Commerce"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher_url", "http://dmsp.ngdc.noaa.gov/"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher_email", "ngdc.dmsp@noaa.gov"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_summary",
                                                   new StringBuffer("This dataset contains data from the DMSP ").append( spacecraftIdAtt.getStringValue())
                                                   .append( " satellite OLS instrument and includes both visible smooth and thermal smooth imagery with 2.7km resolution.")
                                                   .append( " The start time for this data is ").append( startDateAtt.getStringValue())
                                                   .append( " and the northerly equatorial crossing longitude is ").append( startLongitudeAtt.getNumericValue())
                                                   .append( ".  The DMSP satellite is a polar-orbiting satellite crossing the equator, depending on the satellite, at either dawn/dusk or noon/midnight.")
                                                   .append( " This data is in the NOAA/NGDC DMSP archive format.")
                                                   .toString()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_history", ""));
    this.ncFile.addAttribute( null, new Attribute( "thredds_timeCoverage_start", startDateAtt.getStringValue()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_timeCoverage_end", endDateAtt.getStringValue()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_geospatialCoverage",
                                                   new StringBuffer("Polar orbit with northerly equatorial crossing at longitude ")
                                                   .append( ascendingNodeAtt.getNumericValue()).append( ".")
                                                   .toString()));

View Full Code Here

   * @throws IOException if any problems reading the file (or validating the file).
   */
  private void handleFileInformation()
          throws IOException
  {
    fileIdAtt = new Attribute( this.fileIdAttName,
                               (String) headerInfo.get( HeaderInfoTitle.FILE_ID.toString() ) );
    datasetIdAtt = new Attribute( this.datasetIdAttName,
                                  (String) headerInfo.get( HeaderInfoTitle.DATA_SET_ID.toString() ) );
    recordSizeInBytes = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.RECORD_BYTES.toString() ) );
    numRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_RECORDS.toString() ) );
    numHeaderRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_HEADER_RECORDS.toString() ) );
    numDataRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_DATA_RECORDS.toString() ) );
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.common.xml.stax.StAXHelper$Attribute

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.