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


Java XMLInputFactory.newFactory方法代码示例

本文整理汇总了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;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:27,代码来源:XmlProcessBase.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:SourceHttpMessageConverter.java

示例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;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:28,代码来源:SchemaHelper.java

示例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();
    }
}
 
开发者ID:Microsoft,项目名称:elastic-db-tools-for-java,代码行数:24,代码来源:SchemaInfo.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:FeatureConfigSnapshotHolder.java

示例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);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:Config.java

示例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;
}
 
开发者ID:miche-atucha,项目名称:deps-checker,代码行数:32,代码来源:PomModel.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:BugTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:XMLInputFactoryNewInstanceTest.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:XMLInputFactoryNewInstanceTest.java

示例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();
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:11,代码来源:XmlInputFactorySafe.java

示例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();
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:10,代码来源:XmlInputFactorySafe.java

示例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();
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:10,代码来源:XmlInputFactorySafe.java

示例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();
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:10,代码来源:XmlInputFactorySafe.java

示例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();
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:11,代码来源:XmlInputFactoryVulnerable.java


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