本文整理匯總了Java中javax.xml.stream.XMLEventFactory.newFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventFactory.newFactory方法的具體用法?Java XMLEventFactory.newFactory怎麽用?Java XMLEventFactory.newFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLEventFactory
的用法示例。
在下文中一共展示了XMLEventFactory.newFactory方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Override
public void initialize(ByteBuf buffer) throws Exception {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
this.writer = factory.createXMLEventWriter(new ByteBufOutputStream(buffer));
this.eventFactory = XMLEventFactory.newFactory();
startTag("html");
startTag("head");
startTag("title");
text("LiveOak");
endTag("title");
startTag("link");
attribute("rel", "stylesheet");
attribute("type", "text/css");
attribute("href", "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css");
endTag("link");
startTag("style");
text(getCss());
endTag("style");
endTag("head");
startTag("body");
}
示例2: testDefaultInstance
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
/**
* Test if newDefaultFactory() method returns an instance
* of the expected factory.
* @throws Exception If any errors occur.
*/
@Test
public void testDefaultInstance() throws Exception {
XMLEventFactory ef1 = XMLEventFactory.newDefaultFactory();
XMLEventFactory ef2 = XMLEventFactory.newFactory();
assertNotSame(ef1, ef2, "same instance returned:");
assertSame(ef1.getClass(), ef2.getClass(),
"unexpected class mismatch for newDefaultFactory():");
assertEquals(ef1.getClass().getName(), DEFAULT_IMPL_CLASS);
}
示例3: testNewFactory
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Test(dataProvider = "parameters")
public void testNewFactory(String factoryId, ClassLoader classLoader) {
setSystemProperty(XMLEVENT_FACTORY_ID, XMLEVENT_FACTORY_CLASSNAME);
try {
XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
assertNotNull(xef);
} finally {
clearSystemProperty(XMLEVENT_FACTORY_ID);
}
}
示例4: testNewFactory
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Test(dataProvider = "parameters")
public void testNewFactory(String factoryId, ClassLoader classLoader) {
setSystemProperty(XMLEVENT_FACRORY_ID, XMLEVENT_FACTORY_CLASSNAME);
try {
XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
assertNotNull(xef);
} finally {
setSystemProperty(XMLEVENT_FACRORY_ID, null);
}
}
示例5: open
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Override
public void open(final Serializable checkpoint) throws Exception {
if (output == null) {
throw new BatchRuntimeException("output should be set");
}
if (marshallingPackage == null && marshallingClasses == null) {
throw new BatchRuntimeException("marshallingPackage should be set");
}
if (encoding == null) {
encoding = "UTF-8";
}
if (rootTag == null) {
rootTag = "root";
}
if (version == null) {
version = "1.0";
}
marshaller = JAXBContextFactory.getJaxbContext(marshallingPackage, marshallingClasses).createMarshaller();
final File file = new File(output);
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
throw new BatchRuntimeException("Output parent file can't be created");
}
final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
woodStoxConfig(xmlOutputFactory);
xmlEventFactory = XMLEventFactory.newFactory();
txWriter = new TransactionalWriter(file, encoding, checkpoint);
writer = xmlOutputFactory.createXMLEventWriter(txWriter);
if (txWriter.position() == 0) {
writer.add(xmlEventFactory.createStartDocument(encoding, version));
writer.add(xmlEventFactory.createStartElement("", "", rootTag));
writer.flush();
}
}
示例6: run
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
private void run(
final XMLEventReader r,
final XMLEventWriter w
)
throws XMLStreamException,JAXBException
{
final XMLEventFactory eventFactory=XMLEventFactory.newFactory();
boolean prev_was_iteration=false;
while(r.hasNext())
{
final XMLEvent evt=r.peek();
QName qname=null;
if(evt.isStartElement() && (qname=evt.asStartElement().getName()).getLocalPart().equals("Iteration"))
{
final Iteration iteration = this.unmarshaller.unmarshal(r, Iteration.class).getValue();
if(!iteration.getIterationHits().getHit().isEmpty()) {
if(!this.keep_message) iteration.setIterationMessage(null);
if(!this.keep_stats) iteration.setIterationStat(null);
this.marshaller.marshal(
new JAXBElement<Iteration>(qname,Iteration.class , iteration),
w);
w.add(eventFactory.createCharacters("\n"));
}
prev_was_iteration=true;
continue;
}
else if(prev_was_iteration && evt.isCharacters() && is_empty(evt.asCharacters().getData())) {
r.nextEvent();
continue;
}
w.add(r.nextEvent());
prev_was_iteration=false;
}
}
示例7: testNewFactoryNeg
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
XMLEventFactory.newFactory(null, null);
}
示例8: get
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
@Override
public XMLEventFactory get() {
System.setProperty("javax.xml.stream.XMLEventFactory", FACTORY_CLASS);
// NOTE: In case the newFactory(String, ClassLoader) is used, XMLEventFactory treats the string as classname.
return XMLEventFactory.newFactory();
}
示例9: initialValue
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
protected XMLEventFactory initialValue() {
return XMLEventFactory.newFactory();
}
示例10: getXMLEventFactory
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public XMLEventFactory getXMLEventFactory()
{
if (null == xmlEventFactory)
xmlEventFactory = XMLEventFactory.newFactory();
return xmlEventFactory;
}
示例11: parse
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public static ContentModel parse(XMLEventReader xml, String containerName) throws XMLStreamException, IllegalSchemaException {
final StringWriter schema = new StringWriter();
final XMLEventFactory xef = XMLEventFactory.newFactory();
final XMLEventWriter grammar = XML.outputFactory().createXMLEventWriter(new StreamResult(schema));
try {
grammar.add(xef.createStartDocument());
grammar.add(xef.createStartElement("", RELAX_NG, "grammar"));
grammar.add(xef.createStartElement("", RELAX_NG, "define",
Collections.singleton(xef.createAttribute("name", CONTENT_MODEL_DEF)).iterator(),
Collections.emptySet().iterator()));
while (xml.hasNext()) {
final XMLEvent event = xml.nextEvent();
if (event.isEndElement()) {
if (XML.hasName(event.asEndElement(), Namespaceable.DEFAULT_NS_STR, containerName)) {
break;
}
}
grammar.add(event);
}
grammar.add(xef.createEndElement("", RELAX_NG, "define"));
grammar.add(xef.createStartElement("", RELAX_NG, "start"));
grammar.add(xef.createStartElement("", RELAX_NG, "ref",
Collections.singleton(xef.createAttribute("name", CONTENT_MODEL_DEF)).iterator(),
Collections.emptySet().iterator()));
grammar.add(xef.createEndElement("", RELAX_NG, "ref"));
grammar.add(xef.createEndElement("", RELAX_NG, "start"));
grammar.add(xef.createEndElement("", RELAX_NG, "grammar"));
grammar.add(xef.createEndDocument());
} finally {
grammar.close();
}
final String grammarStr = schema.toString();
try {
final DPattern grammarPattern = (DPattern) new SAXParseable(
new InputSource(new StringReader(grammarStr)),
XML.STRICT_ERROR_HANDLER
).parse(new DSchemaBuilderImpl());
final List<DPattern> root = new ArrayList<>();
grammarPattern.accept(new DPatternWalker() {
@Override
public Void onRef(DRefPattern p) {
final DDefine target = p.getTarget();
if (target != null && CONTENT_MODEL_DEF.equals(p.getName())) {
root.add(target.getPattern());
}
return null;
}
});
return new ContentModel(grammarPattern, root.stream().findFirst().orElse(null));
} catch (BuildException e) {
throw new UnsupportedOperationException(grammarStr, e);
}
}
示例12: createEventStreamWriter
import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
/**
* Return a {@link XMLStreamWriter} that writes to a {@link XMLEventWriter}.
* @return a stream writer that writes to an event writer
* @since 3.2
*/
public static XMLStreamWriter createEventStreamWriter(XMLEventWriter eventWriter) {
return new XMLEventStreamWriter(eventWriter, XMLEventFactory.newFactory());
}