本文整理汇总了Java中com.ctc.wstx.stax.WstxOutputFactory类的典型用法代码示例。如果您正苦于以下问题:Java WstxOutputFactory类的具体用法?Java WstxOutputFactory怎么用?Java WstxOutputFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WstxOutputFactory类属于com.ctc.wstx.stax包,在下文中一共展示了WstxOutputFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createXMLWriter
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
private XMLStreamWriter createXMLWriter(boolean fragmentMarshaller) throws XMLStreamException, IOException, TransformerException {
// String cdataElements = "data text syncTextChunk";
TransformerFactory tf = TransformerFactory.newInstance();
transformer = tf.newTransformer();
// transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS,
// cdataElements);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
bufferOutput = new ByteArrayOutputStream();
XMLOutputFactory xof = new WstxOutputFactory();
xof.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT, true);
xof.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE, true);
xof.setProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT, false);
xof.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, new InvalidCharHandler.ReplacingHandler(' '));
XMLStreamWriter xmlWriter = xof.createXMLStreamWriter(bufferOutput, "UTF-8");
return xmlWriter;
}
示例2: StaxMateFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
/**
* Constructor
* @param xml_file
*/
public StaxMateFactory(String xml_file) {
if (xml_file != null) {
WstxOutputFactory factory = new WstxOutputFactory();
factory.setProperty(WstxOutputFactory.P_AUTOMATIC_EMPTY_ELEMENTS, true);
// 1: need output factory
SMOutputFactory outf = new SMOutputFactory(factory);
try {
doc = outf.createOutputDocument(new File(xml_file));
// (optional) 3: enable indentation (note spaces after backslash!)
doc.setIndentation("\n\t\t\t\t\t", 1, 1);
// 4. comment regarding generation time
doc.addComment(" generated by "+Master.AppName+" "+Master.AppVersion+" on " + new java.util.Date().toString());
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
}
示例3: getOrCreateOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
private static XMLOutputFactory getOrCreateOutputFactory() throws FactoryConfigurationError {
if (ourOutputFactory == null) {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
if (!ourHaveLoggedStaxImplementation) {
logStaxImplementation(outputFactory.getClass());
}
/*
* Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
* being used (e.g. glassfish) so we don't set them there.
*/
try {
Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
if (outputFactory instanceof WstxOutputFactory) {
outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
}
} catch (ClassNotFoundException e) {
ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
}
ourOutputFactory = outputFactory;
}
return ourOutputFactory;
}
示例4: newXMLMapper
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的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;
}
示例5: writeBackToFile
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
public synchronized void writeBackToFile(String FilenameAndPath) {
File outFile = new File(FilenameAndPath);
try
{
outFile.createNewFile(); // will create it if it does not exist, otherwise will return false (we don't care)
FileWriter tmpoutWriter = new FileWriter(outFile);
WstxOutputFactory fout = new WstxOutputFactory();
fout.configureForXmlConformance();
SMOutputDocument doc = null;
SMOutputElement outputRootEl = null;
// output
XMLStreamWriter2 sw = (XMLStreamWriter2)fout.createXMLStreamWriter(tmpoutWriter);
doc = SMOutputFactory.createOutputDocument(sw, "1.0", "UTF-8", true);
doc.setIndentation("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 2, 1);
outputRootEl = doc.addElement(Model3dMetafile.getMetaRootTag());
createInfoInDocument(outputRootEl);
doc.closeRoot();
tmpoutWriter.close();
}
catch(Exception e)
{
return;
}
}
示例6: writeIndexBackToFile
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
/**
* Write the instance of IndexOfModelMappings back to the corresponding file
* (Used for persistence)
*/
public static synchronized void writeIndexBackToFile() {
// Write file from the Vector
File outFile = new File(Model3dIndex.getIndexPath()+"modelIndex.xml");
try
{
outFile.createNewFile(); // will create it if it does not exist, otherwise will return false (we don't care)
FileWriter tmpoutWriter = new FileWriter(outFile);
WstxOutputFactory fout = new WstxOutputFactory();
fout.configureForXmlConformance();
SMOutputDocument doc = null;
SMOutputElement outputRootEl = null;
SMOutputElement outputRootEl2 = null;
// output
XMLStreamWriter2 sw = (XMLStreamWriter2)fout.createXMLStreamWriter(tmpoutWriter);
doc = SMOutputFactory.createOutputDocument(sw, "1.0", "UTF-8", true);
doc.setIndentation("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 2, 1);
outputRootEl = doc.addElement(Model3dIndex.getRootIndexTag());
for(int i = 0; i < Model3dIndex.getListofAllMetaEntries().size(); i++) {
outputRootEl2 = outputRootEl.addElement(Model3dIndex.getMetaEntryTag());
Model3dIndex.getListofAllMetaEntries().elementAt(i).createInfoInDocument(outputRootEl2);
}
doc.closeRoot();
tmpoutWriter.close();
}
catch(Exception e)
{
return;
}
}
示例7: writeIndexBackToFile
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
/**
* Write the instance of Index Of Styles back to the corresponding file
* (Used for persistence)
*/
public static synchronized void writeIndexBackToFile() {
// Write file from the Vector
File outFile = new File(Model3dStylesList.getIndexFilenameandPath());
try {
outFile.createNewFile(); // will create it if it does not exist, otherwise will return false (we don't care)
FileWriter tmpoutWriter = new FileWriter(outFile);
WstxOutputFactory fout = new WstxOutputFactory();
fout.configureForXmlConformance();
SMOutputDocument doc = null;
SMOutputElement outputRootEl = null;
SMOutputElement outputRootEl2 = null;
// output
XMLStreamWriter2 sw = (XMLStreamWriter2)fout.createXMLStreamWriter(tmpoutWriter);
doc = SMOutputFactory.createOutputDocument(sw, "1.0", "UTF-8", true);
doc.setIndentation("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 2, 1);
outputRootEl = doc.addElement(Model3dStylesList.getRootIndexTag());
for(int i = 0; i < Model3dStylesList.getListofStyleEntriesVec().size(); i++) {
outputRootEl2 = outputRootEl.addElement(Model3dStylesList.getStyleEntryTag());
Model3dStylesList.getListofStyleEntriesVec().elementAt(i).createInfoInDocument(outputRootEl2);
}
doc.closeRoot();
tmpoutWriter.close();
} catch(Exception e) {
return;
}
}
示例8: createOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
@Override
protected XMLOutputFactory createOutputFactory() {
return new WstxOutputFactory();
}
示例9: getOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
protected XMLOutputFactory getOutputFactory() {
return new WstxOutputFactory();
}
示例10: createOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
protected XMLOutputFactory createOutputFactory()
{
return new WstxOutputFactory();
}
示例11: createOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
@Override
public XMLOutputFactory2 createOutputFactory() {
return new WstxOutputFactory();
}
示例12: getWstxOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
protected WstxOutputFactory getWstxOutputFactory() {
return (WstxOutputFactory) getOutputFactory();
}
示例13: getNewOutputFactory
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
protected static XMLOutputFactory2 getNewOutputFactory() {
return new WstxOutputFactory();
}
示例14: testConfig
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
public void testConfig()
throws XMLStreamException
{
XMLOutputFactory2 f = getNewOutputFactory();
WriterConfig cfg = ((WstxOutputFactory) f).getConfig();
assertNotNull(cfg);
assertFalse(f.isPropertySupported("foobar"));
// Let's just test some of known properties that should be supported...
assertTrue(f.isPropertySupported(WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE));
assertTrue(f.isPropertySupported(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT));
// And their default values?
assertEquals(Boolean.TRUE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE));
assertEquals(Boolean.TRUE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT));
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_ATTR));
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES));
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT));
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_COPY_DEFAULT_ATTRS));
// As per [WSTX-120], default with Woodstox 4.0 is false:
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_FIX_CONTENT));
assertEquals(Boolean.TRUE, f.getProperty(XMLOutputFactory2.P_AUTOMATIC_EMPTY_ELEMENTS));
assertEquals(Boolean.TRUE, f.getProperty(XMLStreamProperties.XSP_NAMESPACE_AWARE));
assertNull(f.getProperty(XMLStreamProperties.XSP_PROBLEM_REPORTER));
assertNull(f.getProperty(XMLOutputFactory2.P_TEXT_ESCAPER));
assertNull(f.getProperty(XMLOutputFactory2.P_ATTR_VALUE_ESCAPER));
// ... which can be changed
f.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE, Boolean.FALSE);
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE));
f.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT, Boolean.FALSE);
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT));
f.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT, Boolean.FALSE);
assertEquals(Boolean.FALSE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT));
f.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES, Boolean.TRUE);
assertEquals(Boolean.TRUE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES));
f.setProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_ATTR, Boolean.TRUE);
assertEquals(Boolean.TRUE, f.getProperty(WstxOutputProperties.P_OUTPUT_VALIDATE_ATTR));
}
示例15: previewModel
import com.ctc.wstx.stax.WstxOutputFactory; //导入依赖的package包/类
private void previewModel(HttpServletResponse response, File inFile) throws IOException
{
PrintWriter outPrintWriter = response.getWriter();
FileReader tmpInReader = new FileReader(inFile);
WstxInputFactory fin = new WstxInputFactory();
fin.configureForConvenience();
fin.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // <-- NEEDED TO GET ATTRIBUTES!
//response.setContentType("text/xml"); // for debug
//response.setHeader("Content-disposition","attachment; filename=\"previewModel.xml\""); // for debug
response.setContentType("text/kml");
response.setHeader("Content-disposition","inline; filename=\"previewModel.kml\"");
//response.setHeader("Content-disposition","attachment; filename=\"previewModel.kml\"");
//response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 <-- causes problems in explorer
response.setHeader("Pragma", "public"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
WstxOutputFactory fout = new WstxOutputFactory();
fout.configureForXmlConformance();
SMOutputDocument doc = null;
SMOutputElement outputRootEl = null;
try{
// output
XMLStreamWriter2 sw = (XMLStreamWriter2)fout.createXMLStreamWriter(outPrintWriter);
doc = SMOutputFactory.createOutputDocument(sw, "1.0", "UTF-8", true);
// Need to store some information about preceding siblings,
// so let's enable tracking. (to do) maybe we don't need this)
//
// it.setElementTracking(SMInputCursor.Tracking.VISIBLE_SIBLINGS);
// input
XMLStreamReader2 sr = (XMLStreamReader2)fin.createXMLStreamReader(tmpInReader);
SMInputCursor inputRootElement = SMInputFactory.rootElementCursor(sr);
inputRootElement.getNext();
doc.setIndentation("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 2, 1);
outputRootEl = doc.addElement(inputRootElement.getLocalName());
// Defines linefeed to use, tabs for indentation (from 2, step by 1)
SMTools.cloneAllAttributestoOutputElement(outputRootEl, inputRootElement);
parseXMLperLevel(outputRootEl, inputRootElement);
doc.closeRoot();
tmpInReader.close();
}
catch(Exception e)
{
// apparently we can do this (re-set the content-type and disposition. It works with Mozilla and Opera.
// IT DOES NOT work with Explorer who goes on to read the KML created.
response.setContentType("text/xml"); // for debug
response.setHeader("Content-disposition","attachment; filename=\"ErrorInPreviewModel.xml\""); // for debug
outPrintWriter.print("Error:"+e.getMessage());
}
outPrintWriter.flush();
outPrintWriter.close();
}