本文整理汇总了Java中com.ctc.wstx.stax.WstxInputFactory类的典型用法代码示例。如果您正苦于以下问题:Java WstxInputFactory类的具体用法?Java WstxInputFactory怎么用?Java WstxInputFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WstxInputFactory类属于com.ctc.wstx.stax包,在下文中一共展示了WstxInputFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfig
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
public void testConfig()
throws XMLStreamException
{
XMLInputFactory2 f = getNewInputFactory();
ReaderConfig cfg = ((WstxInputFactory) f).getConfig();
assertNotNull(cfg);
assertNull(f.getEventAllocator());
assertNull(f.getXMLResolver());
assertNull(f.getXMLReporter());
MyReporter rep = new MyReporter();
f.setXMLReporter(rep);
assertEquals(rep, f.getXMLReporter());
assertFalse(f.isPropertySupported("foobar"));
}
示例2: newXMLMapper
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
* Creates a new {@link com.fasterxml.jackson.dataformat.xml.XmlMapper} using Woodstox
* with Logback and Joda Time support.
* Also includes all {@link io.dropwizard.jackson.Discoverable} interface implementations.
*
* @return XmlMapper
*/
public static XmlMapper newXMLMapper(JacksonXmlModule jacksonXmlModule) {
final XmlFactory woodstoxFactory = new XmlFactory(new WstxInputFactory(), new WstxOutputFactory());
final XmlMapper mapper = new XmlMapper(woodstoxFactory, jacksonXmlModule);
mapper.registerModule(new GuavaModule());
mapper.registerModule(new LogbackModule());
mapper.registerModule(new GuavaExtrasModule());
mapper.registerModule(new JodaModule());
mapper.registerModule(new FuzzyEnumModule());
mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
return mapper;
}
示例3: main
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
* How to use it
* <p>
* This class require a single parameter which is the input file containng the french
* corpus from Le Monde manually annotated.
* <p>
* The class will output the cONLL 2013 format in a file having the same name as the input
* suffixed with .output.
*/
public static void main(String[] args) throws IOException, XMLStreamException {
if (args.length == 0) {
System.out.println("Missing input file. First parameter.");
System.exit(-1);
}
WstxInputFactory inputFactory = new WstxInputFactory();
Writer writer = new FileWriter(args[0] + ".output");
INRIALeMondeCorpusStaxHandler inriaLeMondeCorpusStaxHandler = new INRIALeMondeCorpusStaxHandler(writer);
InputStream is = new FileInputStream(args[0]);
XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(is);
StaxUtils.traverse(reader, inriaLeMondeCorpusStaxHandler);
writer.close();
}
示例4: defaultObjectMapper
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
public static ObjectMapper defaultObjectMapper() {
return new XmlMapper(new XmlFactory(new WstxInputFactory(), new WstxPrefixedOutputFactory()))
.enable(SerializationFeature.INDENT_OUTPUT)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.registerModule(new ParserModule())
.setAnnotationIntrospector(AnnotationIntrospector.pair(
new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()),
new JacksonAnnotationIntrospector()));
}
示例5: loadTermStats
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private void loadTermStats() {
XMLInputFactory inputFactory = new WstxInputFactory();
try {
XMLEventReader eventReader = inputFactory.createXMLEventReader(
this.getClass().getClassLoader().getResourceAsStream("Terms.xml"));
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
StartElement startElement = event.asStartElement();
switch (startElement.getName().getLocalPart()) {
case "Collection":
termCount = Long.parseLong(startElement.getAttributeByName(QName.valueOf("termCount")).getValue());
docCount = Long.parseLong(startElement.getAttributeByName(QName.valueOf("docCount")).getValue());
break;
case "Term":
String name = startElement.getAttributeByName(QName.valueOf("name")).getValue();
long ctf = Long.parseLong(startElement.getAttributeByName(QName.valueOf("ctf")).getValue());
long df = Long.parseLong(startElement.getAttributeByName(QName.valueOf("ctf")).getValue());
double idf = Double.parseDouble(startElement.getAttributeByName(QName.valueOf("idf")).getValue());
double ictf = Double.parseDouble(startElement.getAttributeByName(QName.valueOf("ictf")).getValue());
termStatMap.put(name, new Stat(ctf, df, idf, ictf));
break;
}
}
}
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
示例6: loadTagStats
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private void loadTagStats() {
XMLInputFactory inputFactory = new WstxInputFactory();
try {
XMLEventReader eventReader = inputFactory.createXMLEventReader(
this.getClass().getClassLoader().getResourceAsStream("Tags.xml"));
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
StartElement startElement = event.asStartElement();
switch (startElement.getName().getLocalPart()) {
case "Collection":
tagCount = Long.parseLong(startElement.getAttributeByName(QName.valueOf("tagCount")).getValue());
docCount = Long.parseLong(startElement.getAttributeByName(QName.valueOf("docCount")).getValue());
break;
case "Tag":
String name = startElement.getAttributeByName(QName.valueOf("name")).getValue();
long ctf = Long.parseLong(startElement.getAttributeByName(QName.valueOf("ctf")).getValue());
long df = Long.parseLong(startElement.getAttributeByName(QName.valueOf("ctf")).getValue());
double idf = Double.parseDouble(startElement.getAttributeByName(QName.valueOf("idf")).getValue());
double ictf = Double.parseDouble(startElement.getAttributeByName(QName.valueOf("ictf")).getValue());
tagStatMap.put(name, new Stat(ctf, df, idf, ictf));
break;
}
}
}
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
示例7: WstxSAXParser
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
*<p>
* NOTE: this was a protected constructor for versions 4.0
* and 3.2; changed to public in 4.1
*/
public WstxSAXParser(WstxInputFactory sf, boolean nsPrefixes)
{
mStaxFactory = sf;
mFeatNsPrefixes = nsPrefixes;
mConfig = sf.createPrivateConfig();
mConfig.doSupportDTDs(true);
/* Lazy parsing is a tricky thing: although most of the time
* it's useless with SAX, it is actually necessary to be able
* to properly model internal DTD subsets, for example. So,
* we can not really easily determine defaults.
*/
ResolverProxy r = new ResolverProxy();
/* SAX doesn't distinguish between DTD (ext. subset, PEs) and
* entity (external general entities) resolvers, so let's
* assign them both:
*/
mConfig.setDtdResolver(r);
mConfig.setEntityResolver(r);
mConfig.setDTDEventListener(this);
/* These settings do NOT make sense as generic defaults, but
* are helpful when using some test frameworks. Specifically,
* - DTD caching may remove calls to resolvers, changing
* observed behavior
* - Using min. segment length of 1 will force flushing of
* all content before entity expansion, which will
* completely serialize entity resolution calls wrt.
* CHARACTERS events.
*/
// !!! ONLY for testing; never remove for prod use
//mConfig.setShortestReportedTextSegment(1);
//mConfig.doCacheDTDs(false);
}
示例8: WstxSAXParserFactory
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
* @since 4.0.8
*/
public WstxSAXParserFactory(WstxInputFactory f)
{
mStaxFactory = f;
/* defaults should be fine... except that for some weird
* reason, by default namespace support is defined to be off
*/
setNamespaceAware(true);
}
示例9: getReader
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private XMLStreamReader getReader(String contents, boolean nsAware)
throws XMLStreamException
{
WstxInputFactory f = getWstxInputFactory();
f.getConfig().doValidateWithDTD(false);
f.getConfig().doSupportNamespaces(nsAware);
return constructStreamReader(f, contents);
}
示例10: getValidatingReader
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private XMLStreamReader getValidatingReader(String contents, boolean nsAware)
throws XMLStreamException
{
WstxInputFactory f = getWstxInputFactory();
f.getConfig().doSupportNamespaces(nsAware);
f.getConfig().doSupportDTDs(true);
f.getConfig().doValidateWithDTD(true);
return constructStreamReader(f, contents);
}
示例11: doTest
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
* Main branching point has settings for standard features; it
* will further need to loop over Woodstox-specific settings.
*/
private void doTest(boolean ns, boolean coalescing, boolean autoEntity)
throws Exception
{
/* Let's generate seed from args so it's reproducible; String hash
* code only depend on text it contains, so it'll be fixed for
* specific String.
*/
String baseArgStr = "ns: "+ns+", coalesce: "+coalescing+", entityExp: "+autoEntity;
long seed = baseArgStr.hashCode();
WstxInputFactory f = (WstxInputFactory) getInputFactory();
ReaderConfig cfg = f.getConfig();
// Settings we always need:
cfg.doSupportDTDs(true);
cfg.doValidateWithDTD(false);
// Then variable ones we got settings for:
cfg.doSupportNamespaces(ns);
cfg.doCoalesceText(coalescing);
cfg.doReplaceEntityRefs(autoEntity);
/* How many random permutations do we want to try?
*/
final int ROUNDS = 5;
for (int round = 0; round < ROUNDS; ++round) {
Random r = new Random(seed+round);
StringBuffer inputBuf = new StringBuffer(1000);
StringBuffer expOutputBuf = new StringBuffer(1000);
generateData(r, inputBuf, expOutputBuf, autoEntity);
mInput = inputBuf.toString();
normalizeLFs(expOutputBuf);
mExpOutputNorm = expOutputBuf.toString();
mConfigs.iterate(f, this);
}
}
示例12: getReader
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private XMLStreamReader2 getReader(String contents, boolean coalesce)
throws XMLStreamException
{
WstxInputFactory f = getWstxInputFactory();
f.getConfig().doSupportNamespaces(true);
f.getConfig().doCoalesceText(coalesce);
f.getConfig().setInputBufferLength(16);
f.getConfig().setShortestReportedTextSegment(4);
return constructStreamReader(f, contents);
}
示例13: doTestOffset
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
public void doTestOffset(boolean coal, boolean readAll)
throws XMLStreamException
{
// First, let's create some input...
StringBuffer inputBuf = new StringBuffer();
StringBuffer expOut = new StringBuffer();
generateData(new Random(123), inputBuf, expOut, true);
String inputStr = inputBuf.toString();
WstxInputFactory f = getWstxInputFactory();
// Should shrink it to get faster convergence
f.getConfig().setInputBufferLength(17);
f.getConfig().doCoalesceText(coal);
XMLStreamReader2 sr = (XMLStreamReader2) f.createXMLStreamReader(new StringReader(inputStr));
int lastLine = 0;
int lastOffset = 0;
while (sr.next() != XMLStreamConstants.END_DOCUMENT) {
Location loc = sr.getLocation();
int line = loc.getLineNumber();
int offset = loc.getCharacterOffset();
if (line < lastLine) {
fail("Location.getLineNumber() should increase steadily, old value: "+lastLine+", new: "+line);
}
if (offset < lastOffset) {
fail("Location.getCharacterOffset() should increase steadily, old value: "+lastOffset+", new: "+offset);
}
lastLine = line;
lastOffset = offset;
if (readAll) { // read it, or just skip?
if (sr.hasText()) {
/*String text =*/ sr.getText();
}
}
}
}
示例14: getReader
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
private XMLStreamReader getReader(String contents, boolean prologWS,
boolean lazyParsing)
throws XMLStreamException
{
WstxInputFactory f = (WstxInputFactory) getInputFactory();
ReaderConfig cfg = f.getConfig();
cfg.doReportPrologWhitespace(prologWS);
cfg.doParseLazily(lazyParsing);
return constructStreamReader(f, contents);
}
示例15: parseIndexFromFile
import com.ctc.wstx.stax.WstxInputFactory; //导入依赖的package包/类
/**
* Creates a new instance of Index Of Model Mappings read from the corresponding file
* (Used for persistence)
*/
public static void parseIndexFromFile() {
// Read file and create the Index
// check if file exists. If it exists open it and parse it.
// Else return
//
File inFile = new File(Model3dIndex.getIndexPath()+"modelIndex.xml");
// error state check
if(inFile.exists())
{
try{
Model3dIndex.getListofAllMetaEntries().clear();
FileReader tmpInReader = new FileReader(inFile);
WstxInputFactory fin = new WstxInputFactory();
fin.configureForConvenience();
fin.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // <-- NEEDED TO GET ATTRIBUTES!
// input
XMLStreamReader2 sr = (XMLStreamReader2)fin.createXMLStreamReader(tmpInReader);
SMInputCursor inputRootElement = SMInputFactory.rootElementCursor(sr);
inputRootElement.getNext();
SMInputCursor childInElement = inputRootElement.childCursor();
String myText="";
while (childInElement.getNext() != null) {
if(!childInElement.getCurrEvent().hasText() &&
childInElement.getLocalName().toLowerCase().equals(Model3dIndex.getMetaEntryTag().toLowerCase() ) )
{
Model3dIndex.getListofAllMetaEntries().add(new Model3dIndexEntry(childInElement));
}
}
tmpInReader.close();
}
catch(Exception e)
{
return;
}
}
else
return;
}