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


Java Serializer类代码示例

本文整理汇总了Java中org.apache.xml.serializer.Serializer的典型用法代码示例。如果您正苦于以下问题:Java Serializer类的具体用法?Java Serializer怎么用?Java Serializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createContentHandler

import org.apache.xml.serializer.Serializer; //导入依赖的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.Serializer; //导入依赖的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.Serializer; //导入依赖的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.Serializer; //导入依赖的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.Serializer; //导入依赖的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: testPipe

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例7: main

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例8: toFile

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例9: writeAll

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例10: printFile

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例11: write

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例12: write

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例13: write

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例14: write

import org.apache.xml.serializer.Serializer; //导入依赖的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

示例15: write

import org.apache.xml.serializer.Serializer; //导入依赖的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


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