• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Serializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: write

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


示例17: write

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


示例18: testPipeUsingTemplate

import org.apache.xml.serializer.Serializer; //导入依赖的package包/类
@Test public void testPipeUsingTemplate(){
	try{
		// 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);	  
	        // Get Relevant StyleSheets
	        URIResolver resolver = new WidgetURITestResolver();
	        saxTFactory.setURIResolver(resolver);
	        
	        /*
	        Document edlStyle,templateStyle;
	        edlStyle=XMLUtil.parseInputStream(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml"));
	        // Get Template Name
	        XPathFactory xPathFactory=XPathFactory.newInstance();
            XPath xPath=xPathFactory.newXPath();
            Node node=(Node)xPath.evaluate("//use[0]",edlStyle,XPathConstants.NODE);
            //Node node=nodes.item(0);
            if(node!=null){
            	if(node.hasAttributes()){
            		Node testAttri=node.getAttributes().getNamedItem("name");
            		if(testAttri!=null){
            			templateName=testAttri.getNodeValue();
            		}else{
            			//set default template as widgets
            			templateName="widgets";
            		}
            	}
            }
           
            System.out.println(templateName);
             */
            //templateStyle=XMLUtil.parseInputStream(PipeTransformationTest.class.getResourceAsStream("widgets_pipeTest.xml"));
	        // Create a TransformerHandler for each stylesheet.
	        TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml")));
	       // TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("trans.xml")));
	        	//TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource("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);
	        FileOutputStream transformedXML=new FileOutputStream("c://file.xml");
	        serializer.setOutputStream(transformedXML);
	        tHandler1.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(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop.xml")));
	    }
		
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:68,代码来源:PipeTransformationTest.java


示例19: getOutputHandler

import org.apache.xml.serializer.Serializer; //导入依赖的package包/类
public ContentHandler getOutputHandler(OutputStream out) throws IOException
{
	if (!isAvailable()) return null;

	try
	{
		XSLTTransform xsltTransform = (XSLTTransform) transformerHolder.get();
		if (xsltTransform == null)
		{
			xsltTransform = new XSLTTransform();
			xsltTransform.setXslt(new InputSource(this.getClass()
					.getResourceAsStream(xslt)));
			transformerHolder.set(xsltTransform);
		}
		SAXResult sr = new SAXResult();
		
		TransformerHandler th = xsltTransform.getContentHandler();
		
		Transformer transformer = th.getTransformer();
		if (transformParameters != null) {
			for (Map.Entry<String, String> entry: transformParameters.entrySet()) {
				transformer.setParameter(entry.getKey(), entry.getValue());
			}
		}

		Properties p = OutputPropertiesFactory.getDefaultMethodProperties("xml");
	
		// SAK-14388 - use the alternate XHTMLSerializer2 for Websphere environments
		if ("websphere".equals(ServerConfigurationService.getString("servlet.container")))
		{
			// SAK-16712: null in java.util.Properties causes NullPointerException
			if (getXalan270ContentHandler() != null )
			{
				outputProperties.put("{http://xml.apache.org/xalan}content-handler", getXalan270ContentHandler());
			}
		}
		p.putAll(outputProperties);
		
		/*
		S_KEY_CONTENT_HANDLER:{http://xml.apache.org/xalan}content-handler
			S_KEY_ENTITIES:{http://xml.apache.org/xalan}entities
			S_KEY_INDENT_AMOUNT:{http://xml.apache.org/xalan}indent-amount
			S_OMIT_META_TAG:{http://xml.apache.org/xalan}omit-meta-tag
			S_USE_URL_ESCAPING:{http://xml.apache.org/xalan}use-url-escaping
		*/
		
		Serializer s = SerializerFactory.getSerializer(p);
		s.setOutputStream(out);
		sr.setHandler(s.asContentHandler());
		th.setResult(sr);
		return th;
	}
	catch (Exception ex)
	{
		throw new RuntimeException("Failed to create Content Handler", ex); //$NON-NLS-1$
		/*
		 * String stackTrace = null; try { StringWriter exw = new
		 * StringWriter(); PrintWriter pw = new PrintWriter(exw);
		 * log.error(ex.getMessage(), ex); stackTrace = exw.toString(); } catch
		 * (Exception ex2) { stackTrace =
		 * MessageFormat.format(defaultStackTrace, new Object[] {
		 * ex.getMessage() }); } out.write(MessageFormat.format(errorFormat,
		 * new Object[] { ex.getMessage(), stackTrace }));
		 */
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:67,代码来源:XSLTEntityHandler.java


示例20: startElement

import org.apache.xml.serializer.Serializer; //导入依赖的package包/类
/**
 * Receive notification of the start of an element.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to take specific actions at the start of
 * each element (such as allocating a new tree node or writing
 * output to a file).</p>
 *
 * @param uri The Namespace URI, or the empty string if the
 *        element has no Namespace URI or if Namespace
 *        processing is not being performed.
 * @param localName The local name (without prefix), or the
 *        empty string if Namespace processing is not being
 *        performed.
 * @param qName The qualified name (with prefix), or the
 *        empty string if qualified names are not available.
 * @param attributes The specified or defaulted attributes.
 * @throws org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.ContentHandler#startElement
 *
 * @throws SAXException
 */
public void startElement(
        String uri, String localName, String qName, Attributes attributes)
          throws SAXException
{

  if (!m_foundFirstElement && null != m_serializer)
  {
    m_foundFirstElement = true;

    Serializer newSerializer;

    try
    {
      newSerializer = SerializerSwitcher.switchSerializerIfHTML(uri,
              localName, m_outputFormat.getProperties(), m_serializer);
    }
    catch (TransformerException te)
    {
      throw new SAXException(te);
    }

    if (newSerializer != m_serializer)
    {
      try
      {
        m_resultContentHandler = newSerializer.asContentHandler();
      }
      catch (IOException ioe)  // why?
      {
        throw new SAXException(ioe);
      }

      if (m_resultContentHandler instanceof DTDHandler)
        m_resultDTDHandler = (DTDHandler) m_resultContentHandler;

      if (m_resultConten 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InstanceKlass类代码示例发布时间:2022-05-22
下一篇:
Java OFFlowModFlagsSerializerVer13类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap