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


Java Transformer.setParameter方法代码示例

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


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

示例1: colorizeXML

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
String colorizeXML(String xml, String xsltFilename) throws TransformerConfigurationException, TransformerException {

       // Get the XSLT file as a resource
       InputStream xslt = getClass().getResourceAsStream(xsltFilename);
       
       // Create and configure XSLT Transformer 
       TransformerFactory factory = TransformerFactory.newInstance();
       Transformer transformer = factory.newTransformer(new StreamSource(xslt));
       transformer.setParameter("indent-elements", "yes");
       
       OutputStream outputStream = new ByteArrayOutputStream();
       InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
       
       // Convert the XML into HTML per the XSLT file
       transformer.transform(new StreamSource(inputStream), new StreamResult(outputStream));
       
       return new String(((ByteArrayOutputStream)outputStream).toByteArray());
   }
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:19,代码来源:WfDefinitionServiceImpl.java

示例2: moduleDoc

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * CLI option: print the documentation for the specified module.
 * @param name
 * @throws TransformerException
 * @throws XPathExpressionException
 * @throws UnsupportedServiceException
 * @throws ServiceInstanciationException
 * @throws AmbiguousAliasException
 */
@CLIOption(value="-moduleDoc", stop=true)
public final void moduleDoc(String name) throws TransformerException, XPathExpressionException, UnsupportedServiceException, AmbiguousAliasException { 
	Document doc = getModuleDocumentation(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("description", bundle.getString(DocResourceConstants.MODULE_DESCRIPTION).toUpperCase(locale));
	transformer.setParameter("parameters", bundle.getString(DocResourceConstants.MODULE_PARAMETERS).toUpperCase(locale));
	Source source = new DOMSource(doc);
	Result result = new StreamResult(System.out);
	transformer.transform(source, result);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:25,代码来源:AbstractAlvisNLP.java

示例3: converterDoc

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * print the documentation for the specified type converter.
 * @param name
 * @throws UnsupportedServiceException
 * @throws ServiceInstanciationException
 * @throws AmbiguousAliasException
 * @throws TransformerException
 */
@CLIOption(value="-converterDoc", stop=true)
public final void converterDoc(String name) throws UnsupportedServiceException, AmbiguousAliasException, TransformerException { 
	ParamConverter converter = converterFactory.getServiceByAlias(name);
	Document doc = converter.getDocumentation().getDocument();
	// 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));
	transformer.setParameter("synopsis", bundle.getString(DocResourceConstants.SYNOPSIS));
	transformer.setParameter("string-conversion", bundle.getString(DocResourceConstants.STRING_CONVERSION));
	transformer.setParameter("xml-conversion", bundle.getString(DocResourceConstants.XML_CONVERSION));
	Source source = new DOMSource(doc);
	Result result = new StreamResult(System.out);
	transformer.transform(source, result);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:25,代码来源:AbstractAlvisNLP.java

示例4: clear09

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter whose initiated with a dom source with
 * the a name that set before. Value should be same as set one.
 * @throws Exception If any errors occur.
 */
@Test
public void clear09() throws Exception {
    TransformerFactory tfactory = TransformerFactory.newInstance();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File(XSL_FILE));
    DOMSource domSource = new DOMSource((Node)document);

    Transformer transformer = tfactory.newTransformer(domSource);

    transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
    assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TfClearParamTest.java

示例5: clear10

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter whose initiated with a dom source with
 * the a name that wasn't set before. Null is expected.
 * @throws Exception If any errors occur.
 */
@Test
public void clear10() throws Exception {
    TransformerFactory tfactory = TransformerFactory.newInstance();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File(XSL_FILE));
    DOMSource domSource = new DOMSource((Node)document);

    Transformer transformer = tfactory.newTransformer(domSource);
    transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
    transformer.clearParameters();
    assertNull(transformer.getParameter(LONG_PARAM_NAME));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TfClearParamTest.java

示例6: process

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Override
public boolean process(String confName, Document result) {
  StreamSource resultSummaryProcessor = new StreamSource(
      ConfigUpgradeTool.class.getClassLoader()
                             .getResourceAsStream("validation_result_summary.xslt"));

  try {
    Transformer summaryTransform =
        TransformerFactory.newInstance().newTransformer(resultSummaryProcessor);
    summaryTransform.setParameter("solrOpVersion", this.params.getUpgradeProcessorConf().getOutputVersion());
    summaryTransform.setParameter("dryRun", this.params.isDryRun());
    summaryTransform.transform(new DOMSource(result), new StreamResult(System.out));

    // Store the results in the specified directory.
    Transformer saveTransform = TransformerFactory.newInstance().newTransformer();
    saveTransform.setOutputProperty(OutputKeys.INDENT, "yes");
    saveTransform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    saveTransform.transform(new DOMSource(result),
        new StreamResult(this.params.getResultDirPath().resolve(confName+"_validation.xml").toFile()));

    if (evaluateXPathExpression(result, "/result/incompatibility[contains(level, 'error')]").getLength() == 0) {
      System.out.println();
      System.out.printf("Solr %s validation is successful. Please review %s for more details. \n",
          confName, params.getResultDirPath().resolve(confName+"_validation.xml").toAbsolutePath());
      System.out.println();
      return true;
    } else {
      System.out.println();
      System.out.printf("Solr %s validation failed. Please review %s for more details. \n",
          confName, params.getResultDirPath().resolve(confName+"_validation.xml"));
      System.out.println();
      return false;
    }

  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:hgadre,项目名称:solr-upgrade-tool,代码行数:39,代码来源:DefaultValidationResultProcessor.java

示例7: libraryDoc

import javax.xml.transform.Transformer; //导入方法依赖的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

示例8: processFile

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private void processFile(ProcessingContext<Corpus> ctx, Logger logger, Corpus corpus, InputStream file, Transformer transformer) throws ModuleException, IOException {
   	try {
   		String name = sourcePath.getStreamName(file);
   		logger.finer("reading: " + name);
   		transformer.reset();
   		transformer.setParameter(SOURCE_PATH_PARAMETER, name);
   		transformer.setParameter(SOURCE_BASENAME_PARAMETER, new File(name).getName());
   		transformer.setParameter(XML_READER_CONTEXT_PARAMETER, new XMLReaderContext(this, corpus));
   		Source source = getSource(ctx, file);
   		doTransform(ctx, transformer, source);
   	}
   	catch (TransformerException|SAXException|ParserConfigurationException e) {
   		rethrow(e);
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:16,代码来源:XMLReader.java

示例9: run

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Test
public void run() throws TransformerFactoryConfigurationError, TransformerException {
    Transformer t = getTransformer();
    t.setParameter("config", getClass().getResource("config.xml").toString());
    t.setParameter("mapsFile", getClass().getResource("maps.xml").toString());
    StringWriter resultWriter = new StringWriter();
    t.transform(getStreamSource(), new StreamResult(resultWriter));
    String resultString = resultWriter.toString();
    Assert.assertTrue(resultString.contains("map1key1value") && resultString.contains("map2key1value"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TransformerTest.java

示例10: testDisableOutputEscaping

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Test
public void testDisableOutputEscaping() throws Exception {
    final String xsl ="generate-catalog.xsl";
    final String xml ="simple-entity-resolver-config.xml";
    final String expectedOutput ="simple-entity-resolver-config-transformed.xml";
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTemplates(new StreamSource(new StringReader(read(xsl)))).newTransformer();

    String key = "schemaBase";
    String value = "schemas";
    transformer.setParameter(key, value);
    StringWriter writer = new StringWriter();
    transformer.transform(new StreamSource(new StringReader(read(xml))), new StreamResult(writer));
    assertEquals(writer.toString().replaceAll("\r\n", "\n"), read(expectedOutput));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:PrettyPrintTest.java

示例11: clear01

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter with the same name that set before. Value
 * should be same as set one.
 * @throws TransformerConfigurationException If for some reason the
 *         TransformerHandler can not be created.
 */
@Test
public void clear01() throws TransformerConfigurationException {
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
    assertEquals(transformer.getParameter(LONG_PARAM_NAME).toString(), PARAM_VALUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:TfClearParamTest.java

示例12: newStellarTypeFilter

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Override
public TransformerHandler newStellarTypeFilter(String type) throws TransformerConfigurationException, SAXException, ParserConfigurationException,
        IOException {
    TransformerHandler retval = getTransformerHandler(getStellarXsl());
    Transformer xformer = retval.getTransformer();
    xformer.setParameter("type", type);
    return retval;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AbstractFilterFactory.java

示例13: clear03

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter with a short name that set before. Value
 * should be same as set one.
 * @throws TransformerConfigurationException If for some reason the
 *         TransformerHandler can not be created.
 */
@Test
public void clear03() throws TransformerConfigurationException {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer();

    transformer.setParameter(SHORT_PARAM_NAME, PARAM_VALUE);
    assertEquals(transformer.getParameter(SHORT_PARAM_NAME).toString(), PARAM_VALUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TfClearParamTest.java

示例14: clear04

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter with a short name that set with an integer
 * object before. Value should be same as the set integer object.
 * @throws TransformerConfigurationException If for some reason the
 *         TransformerHandler can not be created.
 */
@Test
public void clear04() throws TransformerConfigurationException {
    Transformer transformer = TransformerFactory.newInstance().newTransformer();

    int intObject = 5;
    transformer.setParameter(SHORT_PARAM_NAME, intObject);
    assertEquals(transformer.getParameter(SHORT_PARAM_NAME), intObject);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TfClearParamTest.java

示例15: clear05

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Obtains transformer's parameter whose initiated with a stream source with
 * the a name that set before. Value should be same as set one.
 * @throws TransformerConfigurationException If for some reason the
 *         TransformerHandler can not be created.
 */
@Test
public void clear05() throws TransformerConfigurationException {
    Transformer transformer = TransformerFactory.newInstance().
            newTransformer(new StreamSource(new File(XSL_FILE)));

    transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
    assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TfClearParamTest.java


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