本文整理匯總了Java中javax.xml.stream.XMLInputFactory.newFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLInputFactory.newFactory方法的具體用法?Java XMLInputFactory.newFactory怎麽用?Java XMLInputFactory.newFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLInputFactory
的用法示例。
在下文中一共展示了XMLInputFactory.newFactory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: baseParseXmlToBean
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
/**
* 默認轉換將指定的xml轉化為
* 方法描述
* @param inputStream
* @param fileName
* @return
* @throws JAXBException
* @throws XMLStreamException
* @創建日期 2016年9月16日
*/
public Object baseParseXmlToBean(String fileName) throws JAXBException, XMLStreamException {
// 搜索當前轉化的文件
InputStream inputStream = XmlProcessBase.class.getResourceAsStream(fileName);
// 如果能夠搜索到文件
if (inputStream != null) {
// 進行文件反序列化信息
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xmlRead = xif.createXMLStreamReader(new StreamSource(inputStream));
return unmarshaller.unmarshal(xmlRead);
}
return null;
}
示例2: readStAXSource
import javax.xml.stream.XMLInputFactory; //導入方法依賴的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);
}
}
示例3: deserialiseObject
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
/** Attempt to construct the specified object from this XML string
* @param xml the XML string to parse
* @param xsdFile the name of the XSD schema that defines the object
* @param objclass the class of the object requested
* @return if successful, an instance of class objclass that captures the data in the XML string
*/
static public Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException
{
Object obj = null;
JAXBContext jaxbContext = getJAXBContext(objclass);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final String schemaResourceFilename = new String(xsdFile);
URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
Schema schema = schemaFactory.newSchema(schemaURL);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
StringReader stringReader = new StringReader(xml);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);
obj = jaxbUnmarshaller.unmarshal(XMLreader);
return obj;
}
示例4: SchemaInfo
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
/**
* Initializes a new instance of the <see cref="SchemaInfo"/> class.
*/
public SchemaInfo(ResultSet reader,
int offset) {
try (StringReader sr = new StringReader(reader.getSQLXML(offset).getString())) {
JAXBContext jc = JAXBContext.newInstance(SchemaInfo.class);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(sr);
SchemaInfo schemaInfo = (SchemaInfo) jc.createUnmarshaller().unmarshal(xsr);
this.referenceTables = new ReferenceTableSet(schemaInfo.getReferenceTables());
this.shardedTables = new ShardedTableSet(schemaInfo.getShardedTables());
}
catch (SQLException | JAXBException | XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: FeatureConfigSnapshotHolder
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo,
final Feature feature) throws JAXBException, XMLStreamException {
Preconditions.checkNotNull(fileInfo);
Preconditions.checkNotNull(fileInfo.getFinalname());
Preconditions.checkNotNull(feature);
this.fileInfo = fileInfo;
this.featureChain.add(feature);
// TODO extract utility method for umarshalling config snapshots
JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
Unmarshaller um = jaxbContext.createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
}
示例6: fromXml
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public static Config fromXml(final File from) {
if(isEmpty(from)) {
return new Config();
}
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Config.class);
Unmarshaller um = jaxbContext.createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(from));
return (Config) um.unmarshal(xsr);
} catch (JAXBException | XMLStreamException e) {
throw new PersistException("Unable to restore configuration", e);
}
}
示例7: parse
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
@NotNull
public static PomModel parse(@NotNull String xmlContent) throws JAXBException, XMLStreamException
{
JAXBContext ctx = JAXBContext.newInstance(PomModel.class);
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xmlContent));
Unmarshaller um = ctx.createUnmarshaller();
um.setListener(new LocationListener(xsr));
PomModel pomModel = PomModel.class.cast(um.unmarshal(xsr));
List<String> lines = Arrays.asList(xmlContent.split("\\n"));
pomModel.content = new LinkedList<>(lines);
pomModel.updateDependenciesLines(lines);
if (pomModel.dependencyManagement != null)
{
pomModel.dependencyManagement.updateDependenciesLines(lines);
}
if (pomModel.nodeProperties != null)
{
pomModel.nodeProperties
.parallelStream()
.filter(element -> element.getChildNodes().getLength() > 0)
.forEach(element ->
{
String value = element.getChildNodes().item(0).getNodeValue();
pomModel.getProperties().put(element.getTagName(), value);
});
}
return pomModel;
}
示例8: test2
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
/**
* Verifies that the initial event of an XMLEventReader instance is
* START_DOCUMENT. XMLEventReader depends on XMLStreamReader.
*
* @param xml the xml input
* @param type1 the type of the 1st event
* @param type2 the type of the 2nd event
* @throws Exception if the test fails to run properly
*/
@Test(dataProvider = "xmls")
public static void test2(String xml, int type1, int type2) throws Exception {
XMLInputFactory factory = XMLInputFactory.newFactory();
XMLEventReader reader = factory.createXMLEventReader(new StringReader(xml));
int type1stEvent = reader.nextEvent().getEventType();
int type2ndEvent = reader.nextEvent().getEventType();
System.out.println("First event: " + type1stEvent);
System.out.println("2nd event: " + type2ndEvent);
Assert.assertEquals(type1, type1stEvent);
Assert.assertEquals(type2, type2ndEvent);
}
示例9: testDefaultInstance
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
/**
* Test if newDefaultFactory() method returns an instance
* of the expected factory.
* @throws Exception If any errors occur.
*/
@Test
public void testDefaultInstance() throws Exception {
XMLInputFactory if1 = XMLInputFactory.newDefaultFactory();
XMLInputFactory if2 = XMLInputFactory.newFactory();
assertNotSame(if1, if2, "same instance returned:");
assertSame(if1.getClass(), if2.getClass(),
"unexpected class mismatch for newDefaultFactory():");
assertEquals(if1.getClass().getName(), DEFAULT_IMPL_CLASS);
}
示例10: testNewFactory
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
@Test(dataProvider = "parameters")
public void testNewFactory(String factoryId, ClassLoader classLoader) {
setSystemProperty(XMLINPUT_FACTORY_ID, XMLINPUT_FACTORY_CLASSNAME);
try {
XMLInputFactory xif = XMLInputFactory.newFactory(factoryId, classLoader);
assertNotNull(xif);
} finally {
clearSystemProperty(XMLINPUT_FACTORY_ID);
}
}
示例11: parseXMLSafe1
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void parseXMLSafe1(InputStream input) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader reader = factory.createXMLStreamReader(input);
while(reader.hasNext()) {
reader.next();
}
}
示例12: parseXMLSafe2
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void parseXMLSafe2(InputStream input) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
XMLStreamReader reader = factory.createXMLStreamReader(input);
while(reader.hasNext()) {
reader.next();
}
}
示例13: parseXMLSafe3
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void parseXMLSafe3(InputStream input) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader reader = factory.createXMLStreamReader(input);
while(reader.hasNext()) {
reader.next();
}
}
示例14: parseXMLSafe4
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void parseXMLSafe4(InputStream input) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
XMLStreamReader reader = factory.createXMLStreamReader(input);
while(reader.hasNext()) {
reader.next();
}
}
示例15: parseXMLdefaultValue
import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void parseXMLdefaultValue(InputStream input) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newFactory();
// factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
// factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader reader = factory.createXMLStreamReader(input);
while(reader.hasNext()) {
reader.next();
}
}