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


Java Templates.newTransformer方法代码示例

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


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

示例1: newTransformer

import javax.xml.transform.Templates; //导入方法依赖的package包/类
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Process the Source into a Templates object, which is a a compiled
 * representation of the source. Note that this method should not be
 * used with XSLTC, as the time-consuming compilation is done for each
 * and every transformation.
 *
 * @return A Templates object that can be used to create Transformers.
 * @throws TransformerConfigurationException
 */
@Override
public Transformer newTransformer(Source source) throws
    TransformerConfigurationException
{
    final Templates templates = newTemplates(source);
    final Transformer transformer = templates.newTransformer();
    if (_uriResolver != null) {
        transformer.setURIResolver(_uriResolver);
    }
    return(transformer);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:TransformerFactoryImpl.java

示例2: TrAXFilter

import javax.xml.transform.Templates; //导入方法依赖的package包/类
public TrAXFilter(Templates templates)  throws
    TransformerConfigurationException
{
    _templates = templates;
    _transformer = (TransformerImpl) templates.newTransformer();
    _transformerHandler = new TransformerHandlerImpl(_transformer);
    _useServicesMechanism = _transformer.useServicesMechnism();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:TrAXFilter.java

示例3: Export

import javax.xml.transform.Templates; //导入方法依赖的package包/类
public void Export(String path)
{
	try
	{
		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		Document doc = builder.newDocument();
		MakeXML(doc) ;
		Source source = new DOMSource(doc);
		FileOutputStream file = new FileOutputStream(path+".xml");
		StreamResult res = new StreamResult(file) ;
		Transformer xformer = TransformerFactory.newInstance().newTransformer();
		xformer.setOutputProperty(OutputKeys.ENCODING, "ISO8859-1");
		xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		xformer.setOutputProperty(OutputKeys.INDENT, "yes");
		xformer.transform(source, res);
		
		File fSS = new File(path+".xsl");
		if(!fSS.exists())
			return;
		Source stylesheet = new StreamSource(fSS) ; 
		Templates templ = TransformerFactory.newInstance().newTemplates(stylesheet) ;
		Transformer xformer2 = templ.newTransformer() ;			

		FileOutputStream file2 = new FileOutputStream(path+".html");
		StreamResult result = new StreamResult(file2) ;
		xformer2.transform(source, result);
		
	}
	catch (Exception e)
	{
		e.printStackTrace() ;
	}
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:34,代码来源:CGlobalEntityCounter.java

示例4: testTransform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
private String testTransform(String xsl) throws Exception {
    //Prepare sources for transormation
    Source src = new StreamSource(new StringReader(xml));
    Source xslsrc = new StreamSource(new StringReader(xslPre + xsl + xslPost));
    //Create factory, template and transformer
    TransformerFactory tf = TransformerFactory.newInstance();
    Templates tmpl = tf.newTemplates(xslsrc);
    Transformer t = tmpl.newTransformer();
    //Prepare output stream
    StringWriter xmlResultString = new StringWriter();
    StreamResult xmlResultStream = new StreamResult(xmlResultString);
    //Transform
    t.transform(src, xmlResultStream);
    return xmlResultString.toString().trim();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:XslSubstringTest.java

示例5: xform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
private static String xform(final String xml, final String xsl) throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new File(xsl));
    final Templates tmpl = tf.newTemplates(xslsrc);
    final Transformer t = tmpl.newTransformer();

    StringWriter writer = new StringWriter();
    final Source src = new StreamSource(new File(xml));
    final Result res = new StreamResult(writer);

    t.transform(src, res);
    return writer.toString();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:XPathNegativeZero.java

示例6: testTransform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Test
public final void testTransform() {

    try {

        String inFilename = "CR6935697.xml";
        String xslFilename = "CR6935697.xsl";
        String outFilename = "CR6935697.out";

        // Create transformer factory
        TransformerFactory factory = TransformerFactory.newInstance();
        // Use the factory to create a template containing the xsl file
        Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xslFilename)));
        // Use the template to create a transformer
        Transformer xformer = template.newTransformer();
        // Prepare the input and output files
        Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
        Result result = new StreamResult(new FileOutputStream(USER_DIR + outFilename));
        // Apply the xsl file to the source file and write the result to the
        // output file
        xformer.transform(source, result);

    } catch (Exception e) {
        // unexpected failure
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:CR6935697Test.java

示例7: test926007_1

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

示例8: test926007_2

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Test
public void test926007_2() throws Exception {
    TransformerFactory factory = TransformerFactory.newInstance();
    // factory.setAttribute("generate-translet", Boolean.TRUE);
    File f = new File(getClass().getResource("home.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,代码行数:13,代码来源:Bug6537167.java

示例9: test926007_3

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Test
public void test926007_3() throws Exception {
    TransformerFactory factory = TransformerFactory.newInstance();
    // factory.setAttribute("generate-translet", Boolean.TRUE);
    File f = new File(getClass().getResource("upload-media.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,代码行数:13,代码来源:Bug6537167.java

示例10: testTransform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Test
public final void testTransform() {

    try {

        String inFilename = "CR6935697.xml";
        String xslFilename = "CR6935697.xsl";
        String outFilename = "CR6935697.out";

        // Create transformer factory
        TransformerFactory factory = TransformerFactory.newInstance();
        // Use the factory to create a template containing the xsl file
        Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xslFilename)));
        // Use the template to create a transformer
        Transformer xformer = template.newTransformer();
        // Prepare the input and output files
        Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
        Result result = new StreamResult(new FileOutputStream(outFilename));
        // Apply the xsl file to the source file and write the result to the
        // output file
        xformer.transform(source, result);

    } catch (Exception e) {
        // unexpected failure
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:29,代码来源:CR6935697Test.java

示例11: exampleSAXTransformerFactory

import javax.xml.transform.Templates; //导入方法依赖的package包/类
/**
 * Show the Transformer using TemplatesHandler
 */
public static boolean exampleSAXTransformerFactory (final String sourceID,
                                                    final String stxID) throws TransformerException,
                                                                        TransformerConfigurationException,
                                                                        SAXException,
                                                                        IOException
{

  final TransformerFactory tfactory = TransformerFactory.newInstance ();

  // Does this factory support SAX features?
  if (tfactory.getFeature (SAXSource.FEATURE))
  {

    // If so, we can safely cast.
    final SAXTransformerFactory stfactory = ((SAXTransformerFactory) tfactory);

    final TemplatesHandler handler = stfactory.newTemplatesHandler ();
    handler.setSystemId (_getSystemId (stxID));

    final XMLReader reader = XMLReaderFactory.createXMLReader ();
    reader.setContentHandler (handler);

    reader.parse (_getInputSource (stxID));

    final Templates templates = handler.getTemplates ();

    // transform
    final Transformer transformer = templates.newTransformer ();
    transformer.transform (_getSource (sourceID), new StreamResult (System.out));

  }

  return true;
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:38,代码来源:TestCases.java

示例12: generateCSWGetRecordsRequest

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Override
public String generateCSWGetRecordsRequest(ICriteria criteria) {
  String internalRequestXml = createInternalXmlRequest(criteria);
  try (
          ByteArrayInputStream internalRequestInputStream = new ByteArrayInputStream(internalRequestXml.getBytes("UTF-8"));
          InputStream reqXsltInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(Constants.CONFIG_FOLDER_PATH + "/" + getGetRecordsReqXslt())) {
    
    // create internal request DOM
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
    builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    builderFactory.setXIncludeAware(false);
    builderFactory.setExpandEntityReferences(false);
    builderFactory.setNamespaceAware(true);
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document internalRequestDOM = builder.parse(new InputSource(internalRequestInputStream));

    // create transformer
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Templates template = transformerFactory.newTemplates(new StreamSource(reqXsltInputStream));
    Transformer transformer = template.newTransformer();
    
    // perform transformation
    StringWriter writer = new StringWriter();
    transformer.transform(new DOMSource(internalRequestDOM), new StreamResult(writer));
    
    return writer.toString();
  } catch (Exception ex) {
    LOG.warn("Error creating CSW get records request.", ex);
    return "";
  }
}
 
开发者ID:Esri,项目名称:geoportal-server-harvester,代码行数:35,代码来源:Profile.java

示例13: transform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Override
public void transform(final InputStream content, final Path transformation, final OutputStream result) throws IOException, TransformationException {
    try {
        final Templates templates = getTemplates(transformation);
        final javax.xml.transform.Transformer transformer = templates.newTransformer();
        transformer.transform(new StreamSource(content), new StreamResult(result));
    } catch (final TransformerException e) {
        throw new TransformationException(e);
    }
}
 
开发者ID:BCDH,项目名称:TEI-Completer,代码行数:11,代码来源:XMLTransformer.java

示例14: transformFromFileHandle

import javax.xml.transform.Templates; //导入方法依赖的package包/类
/**
 * Performs the XSLT transformation, possibly using a pre-compiled version.
 * Note: Does not close the supplied source
 */
private String transformFromFileHandle(final FileHandle handle, final String xslt, final StreamSource source,
	final URIResolver resolver, boolean omitXmlDeclaration)
{
	StreamSource xsltStream = null;
	Thread currentThread = Thread.currentThread();
	ClassLoader oldLoader = currentThread.getContextClassLoader();
	currentThread.setContextClassLoader(getClass().getClassLoader());
	try
	{
		Pair<Long, Templates> compiledXslt = null;
		Templates templates = null;
		final String key = getKey(handle, xslt);
		synchronized( xsltCache )
		{
			final long modified = fileSystemService.lastModified(handle, xslt);
			compiledXslt = xsltCache.get(key);
			if( compiledXslt != null )
			{
				if( compiledXslt.getFirst() != modified )
				{
					compiledXslt = null;
				}
				else
				{
					templates = compiledXslt.getSecond();
				}
			}

			if( compiledXslt == null )
			{
				xsltStream = getSource(fileSystemService.read(handle, xslt));
				templates = factory.newTemplates(xsltStream);
				xsltCache.put(key, new Pair<Long, Templates>(modified, templates));
			}
		}
		// Not sure it can be
		if( templates == null )
		{
			throw new Error("templates is null");
		}
		Transformer transformersMoreThanMeetsTheEye = templates.newTransformer();
		transformersMoreThanMeetsTheEye.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
			omitXmlDeclaration ? "yes" : "no");
		return doTransform(transformersMoreThanMeetsTheEye, source, resolver);
	}
	catch( final Exception ex )
	{
		throw new RuntimeException("Error compiling XSLT", ex);
	}
	finally
	{
		closeSource(xsltStream);
		currentThread.setContextClassLoader(oldLoader);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:60,代码来源:XsltServiceImpl.java

示例15: testTransform

import javax.xml.transform.Templates; //导入方法依赖的package包/类
@Test
public final void testTransform() {

    try {

        String inFilename = "CR7098746.xml";
        String xslFilename = "CR7098746.xsl";

        StringWriter sw = new StringWriter();
        // Create transformer factory
        TransformerFactory factory = TransformerFactory.newInstance();
        // set the translet name
        // factory.setAttribute("translet-name", "myTranslet");

        // set the destination directory
        // factory.setAttribute("destination-directory", "c:\\temp");
        // factory.setAttribute("generate-translet", Boolean.TRUE);

        // Use the factory to create a template containing the xsl file
        Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xslFilename)));
        // Use the template to create a transformer
        Transformer xformer = template.newTransformer();
        // Prepare the input and output files
        Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
        // Result result = new StreamResult(new
        // FileOutputStream(outFilename));
        Result result = new StreamResult(sw);
        // Apply the xsl file to the source file and write the result to the
        // output file
        xformer.transform(source, result);

        String out = sw.toString();
        if (out.indexOf("<p>") < 0) {
            Assert.fail(out);
        }
    } catch (Exception e) {
        // unexpected failure
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:CR7098746Test.java


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