当前位置: 首页>>代码示例>>Java>>正文


Java StAXResult类代码示例

本文整理汇总了Java中javax.xml.transform.stax.StAXResult的典型用法代码示例。如果您正苦于以下问题:Java StAXResult类的具体用法?Java StAXResult怎么用?Java StAXResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StAXResult类属于javax.xml.transform.stax包,在下文中一共展示了StAXResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createResult

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
/**
 * Retrieves a new Result for setting the XML value designated by this
 * SQLXML instance.
 *
 * @param resultClass The class of the result, or null.
 * @throws java.sql.SQLException if there is an error processing the XML
 *         value or the state is not writable
 * @return for setting the XML value designated by this SQLXML instance.
 */
protected <T extends Result>T createResult(
        Class<T> resultClass) throws SQLException {

    checkWritable();
    setWritable(false);
    setReadable(true);

    if (JAXBResult.class.isAssignableFrom(resultClass)) {

        // Must go first presently, since JAXBResult extends SAXResult
        // (purely as an implmentation detail) and it's not possible
        // to instantiate a valid JAXBResult with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private UnmarshallerHandler)
        // FALL THROUGH... will throw an exception
    } else if ((resultClass == null)
               || StreamResult.class.isAssignableFrom(resultClass)) {
        return createStreamResult(resultClass);
    } else if (DOMResult.class.isAssignableFrom(resultClass)) {
        return createDOMResult(resultClass);
    } else if (SAXResult.class.isAssignableFrom(resultClass)) {
        return createSAXResult(resultClass);
    } else if (StAXResult.class.isAssignableFrom(resultClass)) {
        return createStAXResult(resultClass);
    }

    throw JDBCUtil.invalidArgument("resultClass: " + resultClass);
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:38,代码来源:JDBCSQLXML.java

示例2: createXMLStreamWriter

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
public javax.xml.stream.XMLStreamWriter createXMLStreamWriter(javax.xml.transform.Result result) throws javax.xml.stream.XMLStreamException {

        if (result instanceof StreamResult) {
            return createXMLStreamWriter((StreamResult) result, null);
        } else if (result instanceof DOMResult) {
            return new XMLDOMWriterImpl((DOMResult) result);
        } else if (result instanceof StAXResult) {
            if (((StAXResult) result).getXMLStreamWriter() != null) {
                return ((StAXResult) result).getXMLStreamWriter();
            } else {
                throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported");
            }
        } else {
            if (result.getSystemId() !=null) {
                //this is not correct impl of SAXResult. Keep it for now for compatibility
                return createXMLStreamWriter(new StreamResult(result.getSystemId()));
            } else {
                throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported. " +
                        "Supported result types are: DOMResult, StAXResult and StreamResult.");
            }
        }

    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:XMLOutputFactoryImpl.java

示例3: testStreamWriterWithStAXResultNStreamWriter

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testStreamWriterWithStAXResultNStreamWriter() {
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";

    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLStreamWriter writer = ofac.createXMLStreamWriter(buffer);
        StAXResult res = new StAXResult(writer);
        writer = ofac.createXMLStreamWriter(res);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("root");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();
        Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:StreamResultTest.java

示例4: testValidateStAX

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testValidateStAX() {

    File resultFile = null;
    try {
        resultFile = new File("stax.result");
        if (resultFile.exists()) {
            resultFile.delete();
        }

        Result xmlResult = new javax.xml.transform.stax.StAXResult(XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(resultFile)));
        Source xmlSource = new javax.xml.transform.stax.StAXSource(getXMLEventReader("toys.xml"));
        validate("toys.xsd", xmlSource, xmlResult);

        ((StAXResult) xmlResult).getXMLStreamWriter().close();
        Assert.assertTrue(resultFile.exists(), "result file is not created");

    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail("Exception : " + ex.getMessage());
    } finally {
        if (resultFile != null && resultFile.exists()) {
            resultFile.delete();
        }
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:ValidatorTest.java

示例5: call

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {                            
  StringWriter sw = new StringWriter();      
  JsonXMLConfig config = new JsonXMLConfigBuilder().        
      prettyPrint(true).
      build();    
  XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);                  
  TransformerFactory tFactory = new TransformerFactoryImpl();      
  try {
    SequenceIterator iter = arguments[0].iterate(); 
    Item item;
    while ((item = iter.next()) != null) {
      if (item instanceof NodeInfo) {
        Transformer transformer = tFactory.newTransformer();            
        XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);            
        transformer.transform((NodeInfo) item, new StAXResult(xsw));                                   
      } else {
        sw.append(item.getStringValue());
      }
    }
  } catch (Exception e) {
    throw new XPathException("Error serializing sequence to JSON", e);
  }
  return StringValue.makeStringValue(sw.toString());              
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:26,代码来源:SerializeJSON.java

示例6: setupStAXResultHandler

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
/**
 * Sets up handler for <code>StAXResult</code>.
 */
private void setupStAXResultHandler(StAXResult result) {
    // If there's no StAXResult, unset the validator handler
    if (result == null) {
        fStAXValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    XMLStreamWriter writer = result.getXMLStreamWriter();
    if (writer != null) {
        if (fStAXStreamResultBuilder == null) {
            fStAXStreamResultBuilder = new StAXStreamResultBuilder(fNamespaceContext);
        }
        fStAXValidatorHandler = fStAXStreamResultBuilder;
        fStAXStreamResultBuilder.setStAXResult(result);
    }
    else {
        if (fStAXEventResultBuilder == null) {
            fStAXEventResultBuilder = new StAXEventResultBuilder(this, fNamespaceContext);
        }
        fStAXValidatorHandler = fStAXEventResultBuilder;
        fStAXEventResultBuilder.setStAXResult(result);
    }
    fSchemaValidator.setDocumentHandler(fStAXValidatorHandler);
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:28,代码来源:StAXValidatorHelper.java

示例7: anyxmlNode

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
void anyxmlNode(final QName qname, final Object value) throws IOException {
    if (value != null) {
        checkArgument(value instanceof DOMSource, "AnyXML value must be DOMSource, not %s", value);
        final DOMSource domSource = (DOMSource) value;
        requireNonNull(domSource.getNode());
        checkArgument(domSource.getNode().getNodeName().equals(qname.getLocalName()));
        checkArgument(domSource.getNode().getNamespaceURI().equals(qname.getNamespace().toString()));
        try {
            // TODO can the transformer be a constant ? is it thread safe ?
            final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
            // Writer has to be wrapped in a wrapper that ignores endDocument event
            // EndDocument event forbids any other modification to the writer so a nested anyXml breaks
            // serialization
            transformer.transform(domSource, new StAXResult(new DelegateWriterNoEndDoc(writer)));
        } catch (final TransformerException e) {
            throw new IOException("Unable to transform anyXml(" + qname + ") value: " + value, e);
        }
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:20,代码来源:XMLStreamNormalizedNodeStreamWriter.java

示例8: createResult

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
/**
 * Retrieves a new Result for setting the XML value designated by this
 * SQLXML instance.
 *
 * @param resultClass The class of the result, or null.
 * @throws java.sql.SQLException if there is an error processing the XML
 *         value or the state is not writable
 * @return for setting the XML value designated by this SQLXML instance.
 */
protected <T extends Result>T createResult(
        Class<T> resultClass) throws SQLException {

    checkWritable();
    setWritable(false);
    setReadable(true);

    if (JAXBResult.class.isAssignableFrom(resultClass)) {

        // Must go first presently, since JAXBResult extends SAXResult
        // (purely as an implementation detail) and it's not possible
        // to instantiate a valid JAXBResult with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private UnmarshallerHandler)
        // FALL THROUGH... will throw an exception
    } else if ((resultClass == null)
               || StreamResult.class.isAssignableFrom(resultClass)) {
        return createStreamResult(resultClass);
    } else if (DOMResult.class.isAssignableFrom(resultClass)) {
        return createDOMResult(resultClass);
    } else if (SAXResult.class.isAssignableFrom(resultClass)) {
        return createSAXResult(resultClass);
    } else if (StAXResult.class.isAssignableFrom(resultClass)) {
        return createStAXResult(resultClass);
    }

    throw JDBCUtil.invalidArgument("resultClass: " + resultClass);
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:38,代码来源:JDBCSQLXML.java

示例9: createResult

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
/**
 * Retrieves a new Result for setting the XML value designated by this
 * SQLXML instance.
 *
 * @param resultClass The class of the result, or null.
 * @throws java.sql.SQLException if there is an error processing the XML
 *         value or the state is not writable
 * @return for setting the XML value designated by this SQLXML instance.
 */
protected <T extends Result>T createResult(
        Class<T> resultClass) throws SQLException {

    checkWritable();
    setWritable(false);
    setReadable(true);

    if (JAXBResult.class.isAssignableFrom(resultClass)) {

        // Must go first presently, since JAXBResult extends SAXResult
        // (purely as an implmentation detail) and it's not possible
        // to instantiate a valid JAXBResult with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private UnmarshallerHandler)
        // FALL THROUGH... will throw an exception
    } else if ((resultClass == null)
               || StreamResult.class.isAssignableFrom(resultClass)) {
        return createStreamResult(resultClass);
    } else if (DOMResult.class.isAssignableFrom(resultClass)) {
        return createDOMResult(resultClass);
    } else if (SAXResult.class.isAssignableFrom(resultClass)) {
        return createSAXResult(resultClass);
    } else if (StAXResult.class.isAssignableFrom(resultClass)) {
        return createStAXResult(resultClass);
    }

    throw Util.invalidArgument("resultClass: " + resultClass);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:38,代码来源:JDBCSQLXML.java

示例10: adaptsToStAXResult

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void adaptsToStAXResult() throws SAXException, XMLStreamException
{
	filter.setResult(new StAXResult(this.xmlStreamWriter));

	filter.endDocument();

	verify(this.xmlStreamWriter).writeEndDocument();
}
 
开发者ID:fluentxml4j,项目名称:fluentxml4j,代码行数:10,代码来源:AbstractSAXFilterTest.java

示例11: testEventWriterWithStAXResultNStreamWriter

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testEventWriterWithStAXResultNStreamWriter() {
    String encoding = "";
    if (getSystemProperty("file.encoding").equals("UTF-8")) {
        encoding = " encoding=\"UTF-8\"";
    }
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"" + encoding + "?><root></root>";

    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLStreamWriter swriter = ofac.createXMLStreamWriter(buffer);
        StAXResult res = new StAXResult(swriter);
        XMLEventWriter writer = ofac.createXMLEventWriter(res);

        XMLEventFactory efac = XMLEventFactory.newInstance();
        writer.add(efac.createStartDocument(null, "1.0"));
        writer.add(efac.createStartElement("", "", "root"));
        writer.add(efac.createEndElement("", "", "root"));
        writer.add(efac.createEndDocument());
        writer.close();

        Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:StreamResultTest.java

示例12: testEventWriterWithStAXResultNEventWriter

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testEventWriterWithStAXResultNEventWriter() {
    String encoding = "";
    if (getSystemProperty("file.encoding").equals("UTF-8")) {
        encoding = " encoding=\"UTF-8\"";
    }
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"" + encoding + "?><root></root>";

    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLEventWriter writer = ofac.createXMLEventWriter(buffer);
        StAXResult res = new StAXResult(writer);
        writer = ofac.createXMLEventWriter(res);

        XMLEventFactory efac = XMLEventFactory.newInstance();
        writer.add(efac.createStartDocument(null, "1.0"));
        writer.add(efac.createStartElement("", "", "root"));
        writer.add(efac.createEndElement("", "", "root"));
        writer.add(efac.createEndDocument());
        writer.close();

        Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:StreamResultTest.java

示例13: testStreamWriterWithStAXResultNEventWriter

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testStreamWriterWithStAXResultNEventWriter() throws Exception {
    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLEventWriter writer = ofac.createXMLEventWriter(buffer);
        StAXResult res = new StAXResult(writer);
        XMLStreamWriter swriter = ofac.createXMLStreamWriter(res);
        Assert.fail("Expected an Exception as XMLStreamWriter can't be created " + "with a StAXResult which has EventWriter.");
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:StreamResultTest.java

示例14: testFeatures

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
/**
 * Refer to 6631168 : StAXSource & StAXResult support in JavaSE6
 */
@Test
public final void testFeatures() {
    TransformerFactory tff = TransformerFactory.newInstance();
    Assert.assertTrue(tff.getFeature(StAXSource.FEATURE));
    Assert.assertTrue(tff.getFeature(StAXResult.FEATURE));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TransformerFactoryTest.java

示例15: testDOM2StAX

import javax.xml.transform.stax.StAXResult; //导入依赖的package包/类
@Test
public void testDOM2StAX() {
    try {
        Source input = domUtil.prepareSource(this.getClass().getResourceAsStream(XML_FILE));
        StAXResult staxResult = (StAXResult) staxUtil.prepareResult();
        idTransform.transform(input, staxResult);
        staxUtil.checkResult(staxResult, EXPECTED_VERSION, "UTF-8");

    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Bug4892774.java


注:本文中的javax.xml.transform.stax.StAXResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。