當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。