本文整理汇总了Java中org.apache.xml.serializer.SerializerFactory类的典型用法代码示例。如果您正苦于以下问题:Java SerializerFactory类的具体用法?Java SerializerFactory怎么用?Java SerializerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializerFactory类属于org.apache.xml.serializer包,在下文中一共展示了SerializerFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createContentHandler
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* @param outputStream The output
* @return A content handler
* @throws IOException When there's an XML error
*/
private ContentHandler createContentHandler(OutputStream outputStream) throws IOException {
Properties outputProperties = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
outputProperties.setProperty("indent", "yes");
outputProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "2");
outputProperties.setProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n");
Serializer serializer = SerializerFactory.getSerializer(outputProperties);
serializer.setOutputStream(outputStream);
return serializer.asContentHandler();
}
开发者ID:alfasoftware,项目名称:morf,代码行数:15,代码来源:XmlDataSetConsumer.java
示例2: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* This function serializes the generated Schematron schema to the given
* directory. The document name is derived from the name of the GML
* application schema. Serialization takes place only if at least one
* rule has been generated.
* @param outputDirectory
*/
public void write(String outputDirectory) {
if (printed || !assertion) {
return;
}
// Choose serialization parameters
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
// outputFormat.setProperty("encoding", model.characterEncoding());
outputFormat.setProperty("encoding", "UTF-8");
// Do the actual writing
try {
OutputStream fout = new FileOutputStream(outputDirectory + "/" + pi.xsdDocument() + "_SchematronSchema.xml");
OutputStreamWriter outputXML = new OutputStreamWriter(fout, outputFormat.getProperty("encoding"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
// Indicate we did it to avoid doing it again
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:42,代码来源:SchematronSchema.java
示例3: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void write() {
if (printed)
return;
if (diagnosticsOnly)
return;
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "no");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"0");
outputFormat.setProperty("encoding", "UTF-8");
try {
File file = new File(
outputDirectory + "/" + pi.name() + " Mapping Table.xml");
FileWriter outputXML = new FileWriter(file);
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
result.addResult(getTargetName(), outputDirectory,
pi.name() + " Mapping Table.xml", pi.targetNamespace());
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:35,代码来源:Excel.java
示例4: print
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
private void print(Document document, String filenameSuffix) {
String outFileName = outputFilename + filenameSuffix;
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
/*
* Uses OutputStreamWriter instead of FileWriter to set character
* encoding (see doc in Serializer.setWriter and FileWriter)
*/
File res = new File(outputDirectoryFile, outFileName);
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(res), "UTF-8"))) {
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(writer);
serializer.asDOMSerializer().serialize(document);
result.addResult(getTargetName(), outputDirectory, outFileName,
null);
} catch (IOException ioe) {
result.addError(this, 3, outFileName, ioe.getMessage());
}
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:35,代码来源:CDB.java
示例5: testPipe
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
@Test
public void testPipe()
throws TransformerException, TransformerConfigurationException,
SAXException, IOException
{
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
{
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
// Create a TransformerHandler for each stylesheet.
TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo1.xsl")));
TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo2.xsl")));
TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo3.xsl")));
// Create an XMLReader.
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(tHandler1);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);
tHandler1.setResult(new SAXResult(tHandler2));
tHandler2.setResult(new SAXResult(tHandler3));
// transformer3 outputs SAX events to the serializer.
java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
xmlProps.setProperty("indent", "yes");
xmlProps.setProperty("standalone", "no");
Serializer serializer = SerializerFactory.getSerializer(xmlProps);
serializer.setOutputStream(System.out);
tHandler3.setResult(new SAXResult(serializer.asContentHandler()));
// Parse the XML input document. The input ContentHandler and output ContentHandler
// work in separate threads to optimize performance.
reader.parse(new InputSource(PipeTest.class.getResourceAsStream("foo.xml")));
}
}
开发者ID:kuali,项目名称:kc-rice,代码行数:40,代码来源:PipeTest.java
示例6: LSSerializerImpl
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* Constructor: Creates a LSSerializerImpl object. The underlying
* XML 1.0 or XML 1.1 org.apache.xml.serializer.Serializer object is
* created and initialized the first time any of the write methods are
* invoked to serialize the Node. Subsequent write methods on the same
* LSSerializerImpl object will use the previously created Serializer object.
*/
public LSSerializerImpl () {
// set default parameters
fFeatures |= CDATA;
fFeatures |= COMMENTS;
fFeatures |= ELEM_CONTENT_WHITESPACE;
fFeatures |= ENTITIES;
fFeatures |= NAMESPACES;
fFeatures |= NAMESPACEDECLS;
fFeatures |= SPLITCDATA;
fFeatures |= WELLFORMED;
fFeatures |= DISCARDDEFAULT;
fFeatures |= XMLDECL;
// New OutputFormat properties
fDOMConfigProperties = new Properties();
// Initialize properties to be passed on the underlying serializer
initializeSerializerProps();
// Create the underlying serializer.
Properties configProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
// change xml version from 1.0 to 1.1
//configProps.setProperty("version", "1.1");
// Get a serializer that seriailizes according the the properties,
// which in this case is to xml
fXMLSerializer = SerializerFactory.getSerializer(configProps);
// Initialize Serializer
fXMLSerializer.setOutputFormat(fDOMConfigProperties);
}
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:40,代码来源:LSSerializerImpl.java
示例7: testPipe
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
@Test
public void testPipe()
throws TransformerException, TransformerConfigurationException,
SAXException, IOException
{
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
{
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
// Create a TransformerHandler for each stylesheet.
TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo1.xsl")));
TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo2.xsl")));
TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo3.xsl")));
// Create an XMLReader.
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(tHandler1);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);
tHandler1.setResult(new SAXResult(tHandler2));
tHandler2.setResult(new SAXResult(tHandler3));
// transformer3 outputs SAX events to the serializer.
java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
xmlProps.setProperty("indent", "yes");
xmlProps.setProperty("standalone", "no");
Serializer serializer = SerializerFactory.getSerializer(xmlProps);
serializer.setOutputStream(System.out);
tHandler3.setResult(new SAXResult(serializer.asContentHandler()));
// Parse the XML input document. The input ContentHandler and output ContentHandler
// work in separate threads to optimize performance.
reader.parse(new InputSource(Pipe.class.getResourceAsStream("foo.xml")));
}
}
开发者ID:aapotts,项目名称:kuali_rice,代码行数:40,代码来源:Pipe.java
示例8: resetSerializer
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* Resets the serializer, if resetting is possible. If not, re-creates the
* serializer.
*/
void resetSerializer() {
if(!serializer.reset()) {
serializer // create new unless re-useable
= SerializerFactory.getSerializer(xmlProperties);
}
}
开发者ID:OpenCCG,项目名称:openccg,代码行数:11,代码来源:XSLTProcessor.java
示例9: main
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public static void main(String[] args)
throws TransformerException, TransformerConfigurationException,
SAXException, IOException
{
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)) {
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
// Create an XMLFilter for each stylesheet.
XMLFilter xmlFilter = saxTFactory.newXMLFilter(new StreamSource("C:\\Users\\Gian\\Desktop\\config.xsl"));
// Create an XMLReader.
XMLReader reader = XMLReaderFactory.createXMLReader();
// xmlFilter uses the XMLReader as its reader.
xmlFilter.setParent(reader);
// xmlFilter3 outputs SAX events to the serializer.
java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
xmlProps.setProperty("indent", "yes");
xmlProps.setProperty("standalone", "no");
FileOutputStream fileOutputStream = null;
File file = null;
try {
file = new File("C:\\Users\\Gian\\Desktop\\target.profile");
file.createNewFile();
fileOutputStream = new FileOutputStream(file);
Serializer serializer = SerializerFactory.getSerializer(xmlProps);
serializer.setOutputStream(fileOutputStream);
xmlFilter.setContentHandler(serializer.asContentHandler());
xmlFilter.parse(new InputSource("C:\\Users\\Gian\\Desktop\\Enterprise - Area Channel Sales Manager.profile"));
} catch(IOException ex){
} finally {
fileOutputStream.close();
}
}
}
开发者ID:piegandolfi,项目名称:SalesforceProfiler,代码行数:48,代码来源:UtilsXsl.java
示例10: loadSerializer
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* Create an instance of Xalan serializer for the sake of serializing an XML
* value according the SQL/XML specification for serialization.
*/
private void loadSerializer() throws java.io.IOException {
// Set serialization properties.
Properties props = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
/* (original code)
Properties props = OutputProperties.getDefaultMethodProperties("xml");
*/
// SQL/XML[2006] 10.15:General Rules:6 says method is "xml".
props.setProperty(OutputKeys.METHOD, "xml");
/* Since the XMLSERIALIZE operator doesn't currently support
* the DOCUMENT nor CONTENT keywords, SQL/XML spec says that
* the default is CONTENT (6.7:Syntax Rules:2.a). Further,
* since the XMLSERIALIZE operator doesn't currently support the
* <XML declaration option> syntax, the SQL/XML spec says
* that the default for that option is "Unknown" (6.7:General
* Rules:2.f). Put those together and that in turn means that
* the value of "OMIT XML DECLARATION" must be "Yes", as
* stated in section 10.15:General Rules:8.c. SO, that's what
* we set here.
*
* NOTE: currently the only way to view the contents of an
* XML column is by using an explicit XMLSERIALIZE operator.
* This means that if an XML document is stored and it
* begins with an XML declaration, the user will never be
* able to _see_ that declaration after inserting the doc
* because, as explained above, our current support for
* XMLSERIALIZE dictates that the declaration must be
* omitted. Similarly, other transformations that may
* occur from serialization (ex. entity replacement,
* attribute order, single-to-double quotes, etc)) will
* always be in effect for the string returned to the user;
* the original form of the XML document, if different
* from the serialized version, is not currently retrievable.
*/
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
// We serialize everything as UTF-8 to match what we
// store on disk.
props.setProperty(OutputKeys.ENCODING, "UTF-8");
// Load the serializer with the correct properties.
serializer = SerializerFactory.getSerializer(props);
}
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:51,代码来源:SqlXmlHelperXalan.java
示例11: toFile
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void toFile(String filename) {
if (document == null) {
return;
}
try {
root.setAttribute("config", options.configFile);
root.setAttribute("end", (new Date()).toString());
// check that directory exists and create it if necessary
File f = new File(filename);
f = f.getParentFile();
if (f != null && !f.exists()) {
FileUtils.forceMkdir(f);
}
BufferedWriter outputXML = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(filename), "UTF-8"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
String xsltfileName = options.parameter("xsltFile");
if (xsltfileName != null && !xsltfileName.isEmpty()) {
StreamSource xsltSource;
if (xsltfileName.toLowerCase().startsWith("http")) {
// get xslt via URL
URL url = new URL(xsltfileName);
URLConnection urlConnection = url.openConnection();
xsltSource = new StreamSource(
urlConnection.getInputStream());
} else {
InputStream stream = getClass()
.getResourceAsStream("/xslt/result.xsl");
if (stream == null) {
// get it from the file system
File xsltFile = new File(xsltfileName);
if (!xsltFile.canRead()) {
throw new Exception(
"Cannot read " + xsltFile.getName());
}
xsltSource = new StreamSource(xsltFile);
} else {
// get it from the JAR file
xsltSource = new StreamSource(stream);
}
}
File outHTML = new File(filename.replace(".xml", ".html"));
if (outHTML.exists())
outHTML.delete();
BufferedWriter outputHTML = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outHTML), "UTF-8"));;
if (xsltSource != null) {
Source xmlSource = new DOMSource(document);
Result res = new StreamResult(outputHTML);
TransformerFactory transFact = TransformerFactory
.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, res);
/*
* Apparently, the following is necessary to close streams
* appropriately when running ShapeChange in a separate
* process that was spawned by another process (in the given
* case, a server application):
*/
xsltSource.getInputStream().close();
outputHTML.close();
}
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:81,代码来源:ShapeChangeResult.java
示例12: writeAll
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
@Override
public void writeAll(ShapeChangeResult r) {
if (printed || diagnosticsOnly) {
return;
}
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
/*
* Uses OutputStreamWriter instead of FileWriter to set character
* encoding (see doc in Serializer.setWriter and FileWriter)
*/
try {
File repXsd = new File(outputDirectoryFile, outputFilename);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(repXsd), "UTF-8"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(writer);
serializer.asDOMSerializer().serialize(document);
writer.close();
r.addResult(getTargetName(), outputDirectory, outputFilename,
schemaTargetNamespace);
} catch (IOException ioe) {
r.addError(this, 3, outputFilename, ioe.getMessage());
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:42,代码来源:ApplicationSchemaMetadata.java
示例13: printFile
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/** Dump XML Schema file */
public void printFile(Properties outputFormat) throws Exception {
if (printed) {
return;
}
Node anchor = rootAnnotation;
Element e;
Collections.sort(includes);
for (Iterator<String> i = includes.iterator(); i.hasNext();) {
e = document.createElementNS(Options.W3C_XML_SCHEMA, "include");
addAttribute(e, "schemaLocation", i.next());
if (anchor == null) {
root.insertBefore(e, root.getFirstChild());
} else {
root.insertBefore(e, anchor.getNextSibling());
}
anchor = e;
}
String s;
String loc;
Collections.sort(imports);
for (Iterator<String> i = imports.iterator(); i.hasNext();) {
e = document.createElementNS(Options.W3C_XML_SCHEMA, "import");
s = i.next();
addAttribute(e, "namespace", s);
loc = options.schemaLocationOfNamespace(s);
if (loc != null) {
addAttribute(e, "schemaLocation", loc);
}
if (anchor == null) {
root.insertBefore(e, root.getFirstChild());
} else {
root.insertBefore(e, anchor.getNextSibling());
}
anchor = e;
}
// Check whether we can use the given output directory
File outputDirectoryFile = new File(outputDirectory);
boolean exi = outputDirectoryFile.exists();
if (!exi) {
outputDirectoryFile.mkdirs();
exi = outputDirectoryFile.exists();
}
boolean dir = outputDirectoryFile.isDirectory();
boolean wrt = outputDirectoryFile.canWrite();
boolean rea = outputDirectoryFile.canRead();
if (!exi || !dir || !wrt || !rea) {
result.addFatalError(this, 12, outputDirectory);
throw new ShapeChangeAbortException();
}
/*
* Uses OutputStreamWriter instead of FileWriter to set character
* encoding (see doc in Serializer.setWriter and FileWriter)
*/
try {
String fname = outputDirectory + "/" + name;
new File(fname).getCanonicalPath();
OutputStream fout = new FileOutputStream(fname);
OutputStream bout = new BufferedOutputStream(fout);
OutputStreamWriter outputXML = new OutputStreamWriter(bout,
outputFormat.getProperty("encoding"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
} catch (IOException ioe) {
result.addError(null, 171, name);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:81,代码来源:XsdDocument.java
示例14: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
/**
* @see de.interactive_instruments.ShapeChange.Target.Target#write()
*/
public void write() {
if (printed) {
return;
}
if (diagnosticsOnly) {
return;
}
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
try {
FileWriter outputXML;
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
for (String className : documentMap.keySet()) {
Document doc = documentMap.get(className);
if (doc != null) {
outputXML = new FileWriter(
outputDirectory + "/" + className + ".xml");
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(doc);
outputXML.close();
result.addResult(getTargetName(), outputDirectory,
className + ".xml", null);
}
}
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:51,代码来源:AppConfiguration.java
示例15: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
@Override
public void write() {
if (printed || diagnosticsOnly) {
return;
}
addImports();
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
/*
* Uses OutputStreamWriter instead of FileWriter to set character
* encoding (see doc in Serializer.setWriter and FileWriter)
*/
try {
File repXsd = new File(outputDirectoryFile, outputFilename);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(repXsd), "UTF-8"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(writer);
serializer.asDOMSerializer().serialize(document);
writer.close();
result.addResult(getTargetName(), outputDirectory, outputFilename,
schemaPi.targetNamespace());
} catch (IOException ioe) {
result.addError(null, 171, outputFilename);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:44,代码来源:ReplicationXmlSchema.java
示例16: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void write() {
if (printed) {
return;
}
if (diagnosticsOnly)
return;
if (aborted)
return;
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
try {
File file = new File(outputDirectory + "/index." + pi.xmlns()
+ ".definitions.xml");
FileWriter outputXML = new FileWriter(file);
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
result.addResult(getTargetName(), outputDirectory, "index." + pi.xmlns() + ".definitions.xml", pi.targetNamespace());
if (!schema) {
for (Iterator<ClassInfo> i = model.classes(pi).iterator(); i.hasNext();) {
ClassInfo ci = i.next();
Document cDocument = documentMap.get(ci.id());
if (cDocument != null) {
outputXML = new FileWriter(outputDirectory + "/" + ci.name() + ".definitions.xml");
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(cDocument);
outputXML.close();
result.addResult(getTargetName(), outputDirectory, ci.name() + ".definitions.xml", ci.qname());
}
}
}
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:53,代码来源:Definitions.java
示例17: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void write() {
if (printed) {
return;
}
if (diagnosticsOnly) {
return;
}
try {
Properties outputFormat = OutputPropertiesFactory.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", "UTF-8");
Serializer serializer = SerializerFactory.getSerializer(outputFormat);
for (Iterator<ClassInfo> i = model.classes(pi).iterator(); i.hasNext();) {
ClassInfo ci = i.next();
Document cDocument = documentMap.get(ci.id());
if (cDocument != null) {
String dir = options.parameter(this.getClass().getName(),"outputDirectory");
if (dir==null)
dir = options.parameter("outputDirectory");
if (dir==null)
dir = options.parameter(".");
File outDir = new File(dir);
if(!outDir.exists())
outDir.mkdirs();
/*
* SO: Used OutputStreamWriter instead of FileWriter to set character encoding
* (see doc in Serializer.setWriter and FileWriter)
*/
OutputStream fout= new FileOutputStream(dir + "/" + ci.name() + ".xml");
OutputStreamWriter outputXML = new OutputStreamWriter(fout, outputFormat.getProperty("encoding"));
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(cDocument);
outputXML.close();
result.addResult(getTargetName(), dir, ci.name()+".xml", ci.qname());
}
}
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:54,代码来源:CodelistDictionariesML.java
示例18: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void write() {
if (printed) {
return;
}
if (diagnosticsOnly) {
return;
}
try {
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty(
"{http://xml.apache.org/xalan}indent-amount", "2");
outputFormat.setProperty("encoding", "UTF-8");
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
for (Iterator<ClassInfo> i = model.classes(pi).iterator(); i
.hasNext();) {
ClassInfo ci = i.next();
Document cDocument = documentMap.get(ci.id());
if (cDocument != null) {
String dir = options.parameter(this.getClass().getName(),
"outputDirectory");
if (dir == null)
dir = options.parameter("outputDirectory");
if (dir == null)
dir = options.parameter(".");
File outDir = new File(dir);
if (!outDir.exists())
outDir.mkdirs();
/*
* SO: Used OutputStreamWriter instead of FileWriter to set
* character encoding (see doc in Serializer.setWriter and
* FileWriter)
*/
OutputStream fout = new FileOutputStream(
dir + "/" + ci.name() + ".xml");
OutputStreamWriter outputXML = new OutputStreamWriter(fout,
outputFormat.getProperty("encoding"));
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(cDocument);
outputXML.close();
result.addResult(getTargetName(), dir, ci.name() + ".xml",
ci.qname());
}
}
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:61,代码来源:CodelistDictionaries.java
示例19: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
public void write() {
if (error || printed)
return;
// Check whether we can use the given output directory
File outputDirectoryFile = new File(outputDirectory);
boolean exi = outputDirectoryFile.exists();
if (!exi) {
outputDirectoryFile.mkdirs();
exi = outputDirectoryFile.exists();
}
boolean dir = outputDirectoryFile.isDirectory();
boolean wrt = outputDirectoryFile.canWrite();
boolean rea = outputDirectoryFile.canRead();
if (!exi || !dir || !wrt || !rea) {
result.addFatalError(this, 12, outputDirectory);
return;
}
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
outputFormat.setProperty("encoding", encoding);
String fileName = pi.name().replace("/", "_").replace(" ", "_")
+ ".rdf";
try {
OutputStream fout = new FileOutputStream(
outputDirectory + "/" + fileName);
OutputStream bout = new BufferedOutputStream(fout);
OutputStreamWriter outputXML = new OutputStreamWriter(bout,
outputFormat.getProperty("encoding"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
result.addResult(getTargetName(), outputDirectory, fileName,
pi.targetNamespace() + "#");
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:53,代码来源:RDF.java
示例20: write
import org.apache.xml.serializer.SerializerFactory; //导入依赖的package包/类
@Override
public void write() {
if (printed || !atLeastOneSchematronRuleExists) {
return;
}
// Choose serialization parameters
Properties outputFormat = OutputPropertiesFactory
.getDefaultMethodProperties("xml");
outputFormat.setProperty("indent", "yes");
outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount",
"2");
// outputFormat.setProperty("encoding", model.characterEncoding());
outputFormat.setProperty("encoding", "UTF-8");
// Do the actual writing
try {
String fileName = schema.name().replace("/", "_").replace(" ", "_")
+ "_SchematronSchema.xml";
OutputStream fout = new FileOutputStream(outputDirectory + "/"
+ fileName);
OutputStreamWriter outputXML = new OutputStreamWriter(fout,
outputFormat.getProperty("encoding"));
Serializer serializer = SerializerFactory
.getSerializer(outputFormat);
serializer.setWriter(outputXML);
serializer.asDOMSerializer().serialize(document);
outputXML.close();
} catch (Exception e) {
String m = e.getMessage();
if (m != null) {
result.addError(m);
}
e.printStackTrace(System.err);
}
// Indicate we did it to avoid doing it again
printed = true;
}
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:47,代码来源:FOL2Schematron.java
注:本文中的org.apache.xml.serializer.SerializerFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论