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


Java XMLInputFactory2.newInstance方法代码示例

本文整理汇总了Java中org.codehaus.stax2.XMLInputFactory2.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java XMLInputFactory2.newInstance方法的具体用法?Java XMLInputFactory2.newInstance怎么用?Java XMLInputFactory2.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.stax2.XMLInputFactory2的用法示例。


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

示例1: testBasic

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
public void testBasic()
    throws Exception
{
    String input = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n"
        + "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n"
        + "    <artifactId>mojo-&amp;sandbox-parent</artifactId>\n" + "    <version>5-SNAPSHOT</version>\r"
        + "  </parent>\r" + "<build/></project>";

    byte[] rawInput = input.getBytes( "utf-8" );
    ByteArrayInputStream source = new ByteArrayInputStream( rawInput );
    ByteArrayOutputStream dest = new ByteArrayOutputStream();
    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLEventReader eventReader = inputFactory.createXMLEventReader( source );
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter( dest, "utf-8" );
    while ( eventReader.hasNext() )
    {
        eventWriter.add( eventReader.nextEvent() );
    }

    String output = new String( dest.toByteArray(), "utf-8" );

    assertFalse( "StAX implementation is not good enough", input.equals( output ) );
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:26,代码来源:RewriteWithStAXTest.java

示例2: testImportedPOMsRetrievedFromDependencyManagement

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Tests if imported POMs are properly read from dependency management section. Such logic is required to resolve
 * <a href="https://github.com/mojohaus/versions-maven-plugin/issues/134">bug #134</a>
 *
 * @throws Exception if the test fails.
 */
public void testImportedPOMsRetrievedFromDependencyManagement()
    throws Exception
{
    URL url = getClass().getResource( "PomHelperTest.dependencyManagementBOMs.pom.xml" );
    StringBuilder input = PomHelper.readXmlFile( new File( url.getPath() ) );

    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );

    ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory );

    List<Dependency> dependencies = PomHelper.readImportedPOMsFromDependencyManagementSection( pom );

    assertNotNull( dependencies );
    assertEquals( 1, dependencies.size() );

    Dependency dependency = dependencies.get( 0 );
    assertEquals( "org.group1", dependency.getGroupId() );
    assertEquals( "artifact-pom", dependency.getArtifactId() );
    assertEquals( "1.0-SNAPSHOT", dependency.getVersion() );
    assertEquals( "import", dependency.getScope() );
    assertEquals( "pom", dependency.getType() );
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:30,代码来源:PomHelperTest.java

示例3: testBasic

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
public void testBasic()
    throws Exception
{
    String input = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n" +
        "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n" +
        "    <artifactId>mojo-&amp;sandbox-parent</artifactId>\n" + "    <version>5-SNAPSHOT</version>\r" +
        "  </parent>\r" + "<build/></project>";

    byte[] rawInput = input.getBytes( "utf-8" );
    ByteArrayInputStream source = new ByteArrayInputStream( rawInput );
    ByteArrayOutputStream dest = new ByteArrayOutputStream();
    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLEventReader eventReader = inputFactory.createXMLEventReader( source );
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter( dest, "utf-8" );
    while ( eventReader.hasNext() )
    {
        eventWriter.add( eventReader.nextEvent() );
    }

    String output = new String( dest.toByteArray(), "utf-8" );

    assertFalse( "StAX implementation is not good enough", input.equals( output ) );
}
 
开发者ID:petr-ujezdsky,项目名称:versions-maven-plugin-svn-clone,代码行数:26,代码来源:RewriteWithStAXTest.java

示例4: testReplace

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
public void testReplace()
    throws Exception
{
    String input = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n"
        + "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n"
        + "    <artifactId>mojo-&amp;sandbox-parent</artifactId>\n" + "    <version>5-SNAPSHOT</version>\r"
        + "  </parent>\r" + "<build/></project>";
    String expected = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n"
        + "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n" + "    <artifactId>my-artifact</artifactId>\n"
        + "    <version>5-SNAPSHOT</version>\r" + "  </parent>\r" + "<build/></project>";

    StringBuilder output = new StringBuilder( input );

    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
    ModifiedPomXMLEventReader eventReader = new ModifiedPomXMLEventReader( output, inputFactory );
    while ( eventReader.hasNext() )
    {
        XMLEvent event = eventReader.nextEvent();
        if ( event instanceof StartElement
            && event.asStartElement().getName().getLocalPart().equals( "artifactId" ) )
        {
            eventReader.mark( 0 );
        }
        if ( event instanceof EndElement && event.asEndElement().getName().getLocalPart().equals( "artifactId" ) )
        {
            eventReader.mark( 1 );
            if ( eventReader.hasMark( 0 ) )
            {
                eventReader.replaceBetween( 0, 1, "my-artifact" );
            }
        }
    }

    assertEquals( expected, output.toString() );
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:37,代码来源:RewriteWithStAXTest.java

示例5: testReplace

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
public void testReplace()
    throws Exception
{
    String input = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n" +
        "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n" +
        "    <artifactId>mojo-&amp;sandbox-parent</artifactId>\n" + "    <version>5-SNAPSHOT</version>\r" +
        "  </parent>\r" + "<build/></project>";
    String expected = "<?xml version='1.0' encoding='utf-8'?>\n" + "<project>\n\r\n\r\n\r\n\r" + "  <parent>\r\n" +
        "    <groupId xmlns='foo'>org.codehaus.mojo</groupId>\n" + "    <artifactId>my-artifact</artifactId>\n" +
        "    <version>5-SNAPSHOT</version>\r" + "  </parent>\r" + "<build/></project>";

    StringBuilder output = new StringBuilder( input );

    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );
    ModifiedPomXMLEventReader eventReader = new ModifiedPomXMLEventReader( output, inputFactory );
    while ( eventReader.hasNext() )
    {
        XMLEvent event = eventReader.nextEvent();
        if ( event instanceof StartElement &&
            event.asStartElement().getName().getLocalPart().equals( "artifactId" ) )
        {
            eventReader.mark( 0 );
        }
        if ( event instanceof EndElement && event.asEndElement().getName().getLocalPart().equals( "artifactId" ) )
        {
            eventReader.mark( 1 );
            if ( eventReader.hasMark( 0 ) )
            {
                eventReader.replaceBetween( 0, 1, "my-artifact" );
            }
        }
    }

    assertEquals( expected, output.toString() );
}
 
开发者ID:petr-ujezdsky,项目名称:versions-maven-plugin-svn-clone,代码行数:37,代码来源:RewriteWithStAXTest.java

示例6: XmlDumpParser

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Constructor used by Multistream parser
 * @param header   parsed header
 * @param xmlInput parallel input stream
 */
public XmlDumpParser(Header header, InputStream xmlInput) {
    try {
        this.header = header;

        XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory2.newInstance();
        factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, WstxInputProperties.PARSING_MODE_FRAGMENT);

        xmlReader = (XMLStreamReader2)factory.createXMLStreamReader(xmlInput);

    } catch (XMLStreamException e) {
        throw new IOError(e);
    }
}
 
开发者ID:marcusklang,项目名称:wikiforia,代码行数:20,代码来源:XmlDumpParser.java

示例7: parseHeader

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Header parsing code
 * @param xml the header xml
 * @return true if match
 * @throws javax.xml.stream.XMLStreamException
 */
public static Header parseHeader(String xml) throws XMLStreamException
{
    XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory2.newInstance();
    factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
    BufferedReader buffreader = new BufferedReader(new StringReader(xml));

    XMLStreamReader2 xmlReader = (XMLStreamReader2)factory.createXMLStreamReader(buffreader);
    return XmlDumpParser.readHeader(xmlReader);
}
 
开发者ID:marcusklang,项目名称:wikiforia,代码行数:16,代码来源:MultistreamBzip2XmlDumpParser.java

示例8: run

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
@Override
public void run(InputStream stream) throws Exception {
    XMLInputFactory factory = XMLInputFactory2.newInstance();
    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);

    read(factory.createXMLStreamReader(stream));
}
 
开发者ID:atlanmod,项目名称:NeoEMF,代码行数:8,代码来源:XmiStAXCursorReader.java

示例9: run

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
@Override
public void run(InputStream stream) throws Exception {
    XMLInputFactory factory = XMLInputFactory2.newInstance();
    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);

    read(factory.createXMLEventReader(factory.createXMLStreamReader(stream)));
}
 
开发者ID:atlanmod,项目名称:NeoEMF,代码行数:8,代码来源:XmiStAXIteratorReader.java

示例10: getSchemaLocation

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Get the xsi:schemaLocation for the OAI response
 * 
 * @return the xsi:schemaLocation value
 */
public String getSchemaLocation() throws TransformerException, ParserConfigurationException, SAXException, IOException, XMLStreamException {
    if (this.schemaLocation == null) {
        if (hasDocument()) {
            this.schemaLocation = getSingleString("/*/@xsi:schemaLocation");
            logger.debug("found schemaLocation["+schemaLocation+"] in the XML tree");
        } else {
            XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance();
            xmlif.configureForConvenience();
            XMLStreamReader2 xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(getStream());
            int state = 1; // 1:START 0:STOP -1:ERROR
            while (state > 0) {
                int eventType = xmlr.getEventType();
                switch (eventType) {
                    case XMLEvent2.START_ELEMENT:
                        schemaLocation = xmlr.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","schemaLocation");
                        if (schemaLocation != null)
                            state = 0;
                        break;
                }
                if (xmlr.hasNext())
                    xmlr.next();
                else
                    state = state == 1? 0: -1;// if START then STOP else ERROR
            }
            xmlr.close();
            logger.debug("found schemaLocation["+schemaLocation+"] in the XML stream");
        }

        // The URIs in xsi:schemaLocation are separated by (any kind
        // of) white space. Normalize it to a single space.
        this.schemaLocation = schemaLocation.trim().replaceAll("\\s+", " ");
    }
    return schemaLocation;
}
 
开发者ID:clarin-eric,项目名称:oai-harvest-manager,代码行数:40,代码来源:HarvesterVerb.java

示例11: AbstractXMLTokenizer

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * @param inputReader a reader on the XML source to tokenized
 */
AbstractXMLTokenizer(Reader inputReader) {
    XMLInputFactory2 inputFactory = (XMLInputFactory2) XMLInputFactory2.newInstance();
    inputFactory.configureForConvenience();
    inputFactory.setProperty(XMLInputFactory2.SUPPORT_DTD, false);
    inputFactory.setProperty(XMLInputFactory2.IS_COALESCING, false);

    try {
        reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(inputReader);
    } catch (XMLStreamException e) {
        throw new AgilentParseException("Cannot create StAX reader: " + e.getMessage(), e);
    }

    currentToken = getNextToken();
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:18,代码来源:AbstractXMLTokenizer.java

示例12: parse

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
public Feed parse(String datasource, String feedtype, InputStream is)
		throws ParseFeedException, XMLStreamException, IOException {
	Reader reader = new InputStreamReader(is);

	XMLInputFactory2 xmlFactory = (XMLInputFactory2) XMLInputFactory2
			.newInstance();
	xmlFactory.configureForLowMemUsage();
	xmlFactory.setProperty("javax.xml.stream.supportDTD", false);
	XMLStreamReader2 xmlReader = (XMLStreamReader2) xmlFactory
			.createXMLStreamReader(reader);
	
	return parseGsafeedElement(datasource, feedtype, xmlReader);
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:14,代码来源:FeedStaxParser.java

示例13: createInputFactory

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
private static XMLInputFactory createInputFactory()
{
    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, true );
    return inputFactory;
}
 
开发者ID:mojohaus,项目名称:tidy-maven-plugin,代码行数:7,代码来源:XMLEventReaderFactory.java

示例14: testLongProperties

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Tests what happens when changing a long property substitution pattern, e.g.
 * <a href="http://jira.codehaus.org/browse/MVERSIONS-44">MVERSIONS-44</a>
 *
 * @throws Exception if the test fails.
 */
public void testLongProperties()
    throws Exception
{
    URL url = getClass().getResource( "PomHelperTest.testLongProperties.pom.xml" );
    StringBuilder input = PomHelper.readXmlFile( new File( url.getPath() ) );

    XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
    inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE );

    ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory );

    String oldVersion = PomHelper.getProjectVersion( pom );

    String newVersion = "1";

    assertTrue( "The pom has been modified", PomHelper.setProjectVersion( pom, newVersion ) );

    assertEquals( newVersion, PomHelper.getProjectVersion( pom ) );

    assertNotSame( oldVersion, newVersion );
}
 
开发者ID:mojohaus,项目名称:versions-maven-plugin,代码行数:28,代码来源:PomHelperTest.java

示例15: getResumptionToken

import org.codehaus.stax2.XMLInputFactory2; //导入方法依赖的package包/类
/**
 * Get the oai:resumptionToken from the response
 * 
 * @return the oai:resumptionToken value
 * @throws TransformerException
 * @throws NoSuchFieldException
 */
public String getResumptionToken()
throws TransformerException, NoSuchFieldException, ParserConfigurationException, SAXException, IOException, XMLStreamException {
    String schemaLocation = getSchemaLocation();
    if (schemaLocation.indexOf(SCHEMA_LOCATION_V2_0) != -1) {
        if (hasDocument())
            return getSingleString("/oai20:OAI-PMH/oai20:ListRecords/oai20:resumptionToken");
        String token = null;
        XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance();
        xmlif.configureForConvenience();
        XMLStreamReader2 xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(getStream());
        int state = 1; // 1:START 2:FOUND 0:STOP -1:ERROR
        while (state > 0) {
            int eventType = xmlr.getEventType();
            switch (state) {
                case 1://START
                    switch (eventType) {
                        case XMLEvent2.START_ELEMENT:
                            QName qn = xmlr.getName();
                            //logger.debug("finding token in the XML stream: node["+qn.getNamespaceURI()+"]["+qn.getLocalPart()+"]");
                            if (qn.getNamespaceURI().equals("http://www.openarchives.org/OAI/2.0/") && qn.getLocalPart().equals("resumptionToken"))
                                state = 2;//FOUND
                            break;
                    }
                    break;
                case 2://FOUND
                    switch (eventType) {
                        case XMLEvent2.CHARACTERS:
                            token = xmlr.getText();
                            state = 0;//STOP
                            break;
                        default:
                            state = -1;//ERROR
                            break;
                    }
                    break;
            }
            if (xmlr.hasNext())
                xmlr.next();
            else
                state = state == 1? 0: -1;// if START then STOP else ERROR
        }
        if (state < 0 || token == null) {
            logger.warn("couldn't find token in the XML stream!");
            return null;
        }
        logger.debug("found token["+token+"] in the XML stream!");
        return token;
    } else if (schemaLocation.indexOf(SCHEMA_LOCATION_V1_1_LIST_RECORDS) != -1) {
        return getSingleString("/oai11_ListRecords:ListRecords/oai11_ListRecords:resumptionToken");
    } else {
        throw new NoSuchFieldException(schemaLocation);
    }
}
 
开发者ID:clarin-eric,项目名称:oai-harvest-manager,代码行数:61,代码来源:ListRecords.java


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