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


Java TransformerFactory.newInstance方法代码示例

本文整理汇总了Java中javax.xml.transform.TransformerFactory.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java TransformerFactory.newInstance方法的具体用法?Java TransformerFactory.newInstance怎么用?Java TransformerFactory.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.transform.TransformerFactory的用法示例。


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

示例1: writeOut

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
private static void writeOut(Document doc) throws TransformerException {
	TransformerFactory transformerFactory = TransformerFactory
			.newInstance();
	Transformer transformer = transformerFactory.newTransformer();
	transformer.setOutputProperty(OutputKeys.INDENT, "yes");
	transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
	DOMSource source = new DOMSource(doc);
	File f = new File("splFile.xml");
	f.delete();
	StreamResult result = new StreamResult(f);

	// Output to console for testing
	// StreamResult result = new StreamResult(System.out);

	transformer.transform(source, result);

	System.out.println("File saved!");

}
 
开发者ID:NeoRoy,项目名称:KeYExperienceReport,代码行数:21,代码来源:SPL2OpltionGenerator.java

示例2: makeVerificationResult

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
 * Builds a {@link VerificationResult} from a GeTeTa {@link Message}.
 *
 * @param source the original top-level XML node of the verification result
 * @param importedMessage the JAXB-converted GeTeTa {@link Message} object
 * @return the imported result
 * @throws ImportException if an error occurs while importing
 */
private VerificationResult makeVerificationResult(Node source, Message importedMessage)
    throws ImportException {
  try {
    /* Write log to file */
    File logFile = File.createTempFile("log-verification-", ".xml");
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource domSource = new DOMSource(source);
    StreamResult result = new StreamResult(logFile);
    transformer.transform(domSource, result);

    /* Return appropriate VerificationResult */
    switch (importedMessage.getReturncode()) {
      case RETURN_CODE_SUCCESS:
        return new VerificationSuccess(logFile);
      case RETURN_CODE_NOT_VERIFIED:
        return new edu.kit.iti.formal.stvs.model.verification.Counterexample(
            parseCounterexample(importedMessage), logFile);
      default:
        return new VerificationError(VerificationError.Reason.ERROR, logFile);
    }
  } catch (TransformerException | IOException exception) {
    throw new ImportException(exception);
  }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:34,代码来源:GeTeTaImporter.java

示例3: getTransformer

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
Transformer getTransformer() {
    Transformer transformer = null;
    try {
        InputStream xin = this.getClass().getResourceAsStream("BugDB12665704.xsl");
        StreamSource xslt = new StreamSource(xin);
        TransformerFactory fc = TransformerFactory.newInstance();
        transformer = fc.newTransformer(xslt);

    } catch (Exception e) {
        // unexpected failure
        e.printStackTrace();
        Assert.fail(e.toString());
    }

    return transformer;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BugDB12665704Test.java

示例4: saveEmitter

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
 * Save a single emitter to the XML file
 * 
 * @param out
 *            The location to which we should save
 * @param emitter
 *            The emitter to store to the XML file
 * @throws IOException
 *             Indicates a failure to write or encode the XML
 */
public static void saveEmitter(OutputStream out, ConfigurableEmitter emitter)
		throws IOException {
	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();
		Document document = builder.newDocument();

		document.appendChild(emitterToElement(document, emitter));
		Result result = new StreamResult(new OutputStreamWriter(out,
				"utf-8"));
		DOMSource source = new DOMSource(document);

		TransformerFactory factory = TransformerFactory.newInstance();
		Transformer xformer = factory.newTransformer();
		xformer.setOutputProperty(OutputKeys.INDENT, "yes");

		xformer.transform(source, result);
	} catch (Exception e) {
		Log.error(e);
		throw new IOException("Failed to save emitter");
	}
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:33,代码来源:ParticleIO.java

示例5: createTransformer

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
Transformer createTransformer() throws Exception {
    // Prepare sources for transormation
    Source xslsrc = new StreamSource(new StringReader(xsl));

    // Create factory and transformer
    TransformerFactory tf;
    // newTransformer() method doc states that different transformer
    // factories can be used concurrently by different Threads.
    synchronized (TransformerFactory.class) {
        tf = TransformerFactory.newInstance();
    }
    Transformer t = tf.newTransformer(xslsrc);

    // Set URI Resolver to return the newly constructed xml
    // stream source object from xml test string
    t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
    return t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TransformationWarningsTest.java

示例6: synchroGraphicalToXml

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
public void synchroGraphicalToXml(){
	Document doc=this.buildDocument();
	if(doc==null)return;
	TransformerFactory factory=TransformerFactory.newInstance();
	try{
		Transformer transformer=factory.newTransformer();
		transformer.setOutputProperty("encoding","utf-8");
		transformer.setOutputProperty(OutputKeys.INDENT,"yes");				
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		transformer.transform(new DOMSource(doc),new StreamResult(out));
		xmlEditor.getDocumentProvider().getDocument(xmlEditor.getEditorInput()).set(out.toString("utf-8"));
		out.close();
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:17,代码来源:GraphicalEditorPage.java

示例7: ModelContext

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
 * Creates a new model context with the specified processing environment for the specified generator.
 * @param procEnv
 * @param generatorId
 */
ModelContext(ProcessingEnvironment procEnv, String generatorId) {
	super();
	typeUtils = procEnv.getTypeUtils();
	elementUtils = procEnv.getElementUtils();
       filer = procEnv.getFiler();
       messager = procEnv.getMessager();
       moduleAnnotation = elementUtils.getTypeElement(AlvisNLPModule.class.getCanonicalName());
       converterAnnotation = elementUtils.getTypeElement(Converter.class.getCanonicalName());
       libraryAnnotation = elementUtils.getTypeElement(Library.class.getCanonicalName());
       moduleBase = getModuleBase(typeUtils, elementUtils);
       TypeElement fle = getTypeElement(elementUtils, FunctionLibrary.class);
       for (ExecutableElement m : ElementFilter.methodsIn(fle.getEnclosedElements())) {
       	if (m.getSimpleName().toString().equals("resolveExpression")) {
       		resolveFunction = m;
       		break;
       	}
       }
       functionLibrary = fle.asType();
	corpusModule = getCorpusModule(typeUtils, elementUtils);
	element = getTypeMirror(elementUtils, fr.inra.maiage.bibliome.alvisnlp.core.corpus.Element.class);
	evaluationContext = getTypeMirror(elementUtils, EvaluationContext.class);
	libraryResolver = getTypeMirror(elementUtils, LibraryResolver.class);
	evaluator = getTypeMirror(elementUtils, Evaluator.class);
	expression = getTypeMirror(elementUtils, Expression.class);
	string = getTypeMirror(elementUtils, String.class);
	charSequence = getTypeMirror(elementUtils, CharSequence.class);
	processingContext = typeUtils.erasure(getTypeMirror(elementUtils, ProcessingContext.class));
	elementList = getElementList(typeUtils, elementUtils);
	elementIterator = getElementIterator(typeUtils, elementUtils);
	transformerFactory = TransformerFactory.newInstance();
       options = procEnv.getOptions();
       this.generatorId = generatorId;
       version = new Versioned("fr.inra.maiage.bibliome.alvisnlp.core.app.AlvisNLPVersion");
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:40,代码来源:ModelContext.java

示例8: getXMLFile

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
public static String getXMLFile(Document document) throws TransformerException {
	String finalProcessedXml = Util.getTempFile();
	TransformerFactory tf = TransformerFactory.newInstance();
	Transformer t = tf.newTransformer();
	t.transform(new DOMSource(document), new StreamResult(new File(finalProcessedXml)));
	return finalProcessedXml;
}
 
开发者ID:Esprizzle,项目名称:allure-report-processor,代码行数:8,代码来源:Util.java

示例9: libraryDoc

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@CLIOption(value="-libraryDoc", stop=true)
public final void libraryDoc(String name) throws TransformerException { 
	Document doc = getLibraryDocumentation(name);
	// same ClassLoader as this class
	Source xslt = new StreamSource(getClass().getResourceAsStream(noColors ? "alvisnlp-doc2txt.xslt" : "alvisnlp-doc2ansi.xslt"));
	TransformerFactory transformerFactory = TransformerFactory.newInstance();
	Transformer transformer = transformerFactory.newTransformer(xslt);
	transformer.setParameter("name", bundle.getString(DocResourceConstants.MODULE_NAME).toUpperCase(locale));
	transformer.setParameter("synopsis", bundle.getString(DocResourceConstants.SYNOPSIS).toUpperCase(locale));
	transformer.setParameter("functions", bundle.getString(DocResourceConstants.FUNCTIONS).toUpperCase(locale));
	Source source = new DOMSource(doc);
	Result result = new StreamResult(System.out);
	transformer.transform(source, result);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:15,代码来源:AbstractAlvisNLP.java

示例10: test926007_1

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void test926007_1() throws Exception {
    TransformerFactory factory = TransformerFactory.newInstance();
    File f = new File(getClass().getResource("logon.xsl").getPath());
    Templates t = factory.newTemplates(new StreamSource(f));
    Transformer transformer = t.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    transformer.transform(new StreamSource(getClass().getResourceAsStream("src.xml")), new StreamResult(System.out));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Bug6537167.java

示例11: writeXML

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
 * Writes dataset to an XML file using this specified formatter
 * 
 * @param outputFile
 * @param dataset
 * @throws ParserConfigurationException
 * @throws TransformerException
 * @throws FileNotFoundException
 */
public void writeXML(File outputFile, Processable<RecordType> dataset)
		throws ParserConfigurationException, TransformerException,
		FileNotFoundException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	DocumentBuilder builder;

	builder = factory.newDocumentBuilder();
	Document doc = builder.newDocument();
	Element root = createRootElement(doc);

	doc.appendChild(root);

	for (RecordType record : dataset.get()) {
		root.appendChild(createElementFromRecord(record, doc));
	}

	TransformerFactory tFactory = TransformerFactory.newInstance();
	Transformer transformer;
	transformer = tFactory.newTransformer();
	transformer.setOutputProperty(OutputKeys.INDENT, "yes");
	transformer.setOutputProperty(
			"{http://xml.apache.org/xslt}indent-amount", "2");
	DOMSource source = new DOMSource(root);
	StreamResult result = new StreamResult(new FileOutputStream(outputFile));

	transformer.transform(source, result);

}
 
开发者ID:olehmberg,项目名称:winter,代码行数:39,代码来源:XMLFormatter.java

示例12: testReuseTemplates

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void testReuseTemplates() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    for (int i = 0; i < TRANSF_COUNT; i++) {
        checkResult(doTransformation(tmpl.newTransformer()));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:NamespacePrefixTest.java

示例13: printDocument

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
protected void printDocument(Document document) throws TransformerException {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer trans = tf.newTransformer();
//        trans.setOutputProperty(OutputKeys.INDENT, "yes");
//        trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        trans.transform(new DOMSource(document), new StreamResult(System.out));
    }
 
开发者ID:woefe,项目名称:xmlrss,代码行数:8,代码来源:AbstractXMLRSSTest.java

示例14: resolver02

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
 * This is to test the URIResolver.resolve() method when a transformer is
 * created using DOMSource. style-sheet file has xsl:include in it.
 *
 * @throws Exception If any errors occur.
 */
@Test
public static void resolver02() throws Exception {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
    tfactory.setURIResolver(resolver);

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(XSL_INCLUDE_FILE);
    DOMSource domSource = new DOMSource(document, SYSTEM_ID);

    assertNotNull(tfactory.newTransformer(domSource));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:URIResolverTest.java

示例15: tfce01

import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test(expectedExceptions = ClassNotFoundException.class)
public void tfce01() throws Exception {
    try{
        setSystemProperty("javax.xml.transform.TransformerFactory","xx");
        TransformerFactory.newInstance();
        fail("Expect TransformerFactoryConfigurationError here");
    } catch (TransformerFactoryConfigurationError expected) {
        throw expected.getException();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TFCErrorTest.java


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