本文整理匯總了Java中javax.xml.transform.stax.StAXSource類的典型用法代碼示例。如果您正苦於以下問題:Java StAXSource類的具體用法?Java StAXSource怎麽用?Java StAXSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StAXSource類屬於javax.xml.transform.stax包,在下文中一共展示了StAXSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSourceImpl
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implementation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attributes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw JDBCUtil.invalidArgument("sourceClass: " + sourceClass);
}
示例2: getSourceImpl
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implmentation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attrbutes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw Util.invalidArgument("sourceClass: " + sourceClass);
}
示例3: readInternal
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.class.equals(clazz)) {
return (T) readDOMSource(body);
}
else if (SAXSource.class.equals(clazz)) {
return (T) readSAXSource(body);
}
else if (StAXSource.class.equals(clazz)) {
return (T) readStAXSource(body);
}
else if (StreamSource.class.equals(clazz) || Source.class.equals(clazz)) {
return (T) readStreamSource(body);
}
else {
throw new HttpMessageConversionException("Could not read class [" + clazz +
"]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
示例4: readStAXSource
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
private Source readStAXSource(InputStream body) {
try {
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
if (!isProcessExternalEntities()) {
inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
}
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
return new StAXSource(streamReader);
}
catch (XMLStreamException ex) {
throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
}
}
示例5: getSourceImpl
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implmentation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attrbutes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw JDBCUtil.invalidArgument("sourceClass: " + sourceClass);
}
示例6: testStAXSourceWEmptyNS
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* @bug 8152530
* Verifies that StAXSource handles empty namespace properly. NPE was thrown
* before the fix.
* @throws Exception if the test fails
*/
@Test
public final void testStAXSourceWEmptyNS() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<EntityList>\n"
+ " <Entity xmlns=\"\">\n"
+ " </Entity>\n"
+ " <Entity xmlns=\"\">\n"
+ " </Entity>\n"
+ "</EntityList> ";
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
xsr.nextTag();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
StringWriter stringResult = new StringWriter();
t.transform(new StAXSource(xsr), new StreamResult(stringResult));
System.out.println("result: \n" + stringResult.toString());
}
}
示例7: getDataValidator
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@DataProvider(name = "data_ValidatorA")
public Object[][] getDataValidator() {
DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
SAXSource ss = new SAXSource(new InputSource(xml_val_test));
ss.setSystemId(xml_val_test_id);
StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
StreamSource source = new StreamSource(new File(xml_val_test));
return new Object[][]{
// use catalog
{true, false, true, ds, null, null, xml_catalog, null},
{false, true, true, ds, null, null, null, xml_catalog},
{true, false, true, ss, null, null, xml_catalog, null},
{false, true, true, ss, null, null, null, xml_catalog},
{true, false, true, stax, null, null, xml_catalog, xml_catalog},
{false, true, true, stax1, null, null, xml_catalog, xml_catalog},
{true, false, true, source, null, null, xml_catalog, null},
{false, true, true, source, null, null, null, xml_catalog},
};
}
示例8: getDataValidator
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@DataProvider(name = "data_ValidatorC")
public Object[][] getDataValidator() {
DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
SAXSource ss = new SAXSource(new InputSource(xml_val_test));
ss.setSystemId(xml_val_test_id);
StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
StreamSource source = new StreamSource(new File(xml_val_test));
return new Object[][]{
// use catalog
{false, false, true, ds, null, null, xml_bogus_catalog, null},
{false, false, true, ds, null, null, null, xml_bogus_catalog},
{false, false, true, ss, null, null, xml_bogus_catalog, null},
{false, false, true, ss, null, null, null, xml_bogus_catalog},
{false, false, true, stax, null, null, xml_bogus_catalog, null},
{false, false, true, stax1, null, null, null, xml_bogus_catalog},
{false, false, true, source, null, null, xml_bogus_catalog, null},
{false, false, true, source, null, null, null, xml_bogus_catalog},
};
}
示例9: getDataValidator
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@DataProvider(name = "data_ValidatorC")
public Object[][] getDataValidator() {
DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
SAXSource ss = new SAXSource(new InputSource(xml_val_test));
ss.setSystemId(xml_val_test_id);
StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
StreamSource source = new StreamSource(new File(xml_val_test));
return new Object[][]{
// use catalog
{false, false, true, ds, null, null, xml_catalog, null},
{false, false, true, ds, null, null, null, xml_catalog},
{false, false, true, ss, null, null, xml_catalog, null},
{false, false, true, ss, null, null, null, xml_catalog},
{false, false, true, stax, null, null, xml_catalog, null},
{false, false, true, stax1, null, null, null, xml_catalog},
{false, false, true, source, null, null, xml_catalog, null},
{false, false, true, source, null, null, null, xml_catalog},
};
}
示例10: testStAXSource2
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@Test
public final void testStAXSource2() throws XMLStreamException {
XMLInputFactory ifactory = XMLInputFactory.newInstance();
ifactory.setProperty("javax.xml.stream.supportDTD", Boolean.TRUE);
StAXSource ss = new StAXSource(ifactory.createXMLStreamReader(getClass().getResource("5368141.xml").toString(),
getClass().getResourceAsStream("5368141.xml")));
DOMResult dr = new DOMResult();
TransformerFactory tfactory = TransformerFactory.newInstance();
try {
Transformer transformer = tfactory.newTransformer();
transformer.transform(ss, dr);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例11: readInternal
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.class == clazz) {
return (T) readDOMSource(body);
}
else if (SAXSource.class == clazz) {
return (T) readSAXSource(body);
}
else if (StAXSource.class == clazz) {
return (T) readStAXSource(body);
}
else if (StreamSource.class == clazz || Source.class == clazz) {
return (T) readStreamSource(body);
}
else {
throw new HttpMessageConversionException("Could not read class [" + clazz +
"]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
示例12: readStAXSourceExternal
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@Test
public void readStAXSourceExternal() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
converter.setSupportDtd(true);
StAXSource result = (StAXSource) converter.read(StAXSource.class, inputMessage);
XMLStreamReader streamReader = result.getXMLStreamReader();
assertTrue(streamReader.hasNext());
streamReader.next();
streamReader.next();
String s = streamReader.getLocalName();
assertEquals("root", s);
try {
s = streamReader.getElementText();
assertNotEquals("Foo Bar", s);
}
catch (XMLStreamException ex) {
// Some parsers raise a parse exception
}
streamReader.close();
}
示例13: getSource
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* Converts the inbound body to a {@link Source}, if the body is <b>not</b> already a {@link Source}.
* <p/>
* This implementation will prefer to source in the following order:
* <ul>
* <li>StAX - Is StAX is allowed</li>
* <li>SAX - SAX as 2nd choice</li>
* <li>Stream - Stream as 3rd choice</li>
* <li>DOM - DOM as 4th choice</li>
* </ul>
*/
protected Source getSource(Exchange exchange, Object body) {
// body may already be a source
if (body instanceof Source) {
return (Source) body;
}
Source source = null;
if (isAllowStAX()) {
source = exchange.getContext().getTypeConverter().tryConvertTo(StAXSource.class, exchange, body);
}
if (source == null) {
// then try SAX
source = exchange.getContext().getTypeConverter().tryConvertTo(SAXSource.class, exchange, body);
}
if (source == null) {
// then try stream
source = exchange.getContext().getTypeConverter().tryConvertTo(StreamSource.class, exchange, body);
}
if (source == null) {
// and fallback to DOM
source = exchange.getContext().getTypeConverter().tryConvertTo(DOMSource.class, exchange, body);
}
return source;
}
示例14: testParseCharacterStatesFragment
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
/**
* @throws Exception
* if there is a problem
*
*/
@Test
public final void testParseCharacterStatesFragment() throws Exception {
CategoricalCharacter categoricalCharacter = (CategoricalCharacter) super
.getUnmarshaller().unmarshal(
new StAXSource(getXMLEventReader(filename)));
assertNotNull("categoricalCharacter should not be null",
categoricalCharacter);
assertEquals("categoricalCharacter.id should equal c7", "c7",
categoricalCharacter.getId());
assertEquals(
"categoricalCharacter.representation.label should be shape",
"shape", categoricalCharacter.getRepresentation().getLabel());
assertEquals("there should be two states",3 , categoricalCharacter
.getStates().size());
}
示例15: call
import javax.xml.transform.stax.StAXSource; //導入依賴的package包/類
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String json = ((StringValue) arguments[0].head()).getStringValue();
if (StringUtils.isBlank(json)) {
return EmptySequence.getInstance();
}
XMLInputFactory factory = new JsonXMLInputFactory();
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(json));
StAXSource source = new StAXSource(reader);
Configuration config = context.getConfiguration();
PipelineConfiguration pipe = config.makePipelineConfiguration();
pipe.getParseOptions().getParserFeatures().remove("http://apache.org/xml/features/xinclude");
TinyBuilder builder = new TinyBuilder(pipe);
SerializerFactory sf = config.getSerializerFactory();
Receiver receiver = sf.getReceiver(builder, pipe, new Properties());
NamespaceReducer reducer = new NamespaceReducer(receiver);
ParseOptions options = pipe.getParseOptions();
options.setContinueAfterValidationErrors(true);
Sender.send(source, reducer, options);
return builder.getCurrentRoot();
} catch (Exception e) {
throw new XPathException("Error parsing JSON string", e);
}
}