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


Java TransformerFactoryImpl类代码示例

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


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

示例1: main

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public static void main(String[] args) throws TransformerException, IOException {
    if (args.length < 4) {
        System.out.println(
            "Usage : $<application> [xsl_file_path] [input_xml_file_path] [output_file_path] [param=value]");
        return;
    }
    System.out.println("Received args : \n" +
            "xslFile = "+args[0]+"\n" +
            "inputXml = "+args[1]+"\n" +
            "outputXml = "+args[2]);
    for (int i = 3; i < args.length; i++) {
      System.out.format("Parameter : %s%n", args[i]);  
    }
    File xsltFile = new File(args[0]);
    File inputXml = new File(args[1]);

    Source xmlSource = new javax.xml.transform.stream.StreamSource(inputXml);
    Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltFile);
    StringWriter sw = new StringWriter();

    Result result = new javax.xml.transform.stream.StreamResult(sw);

    TransformerFactory transFact = new TransformerFactoryImpl();
    Transformer trans = transFact.newTransformer(xsltSource);
    
    for (int i = 3; i < args.length; i++) {
      String[] parts = args[i].split("=");
      trans.setParameter(parts[0], parts[1]);
    }
    
    trans.transform(xmlSource, result);
    File file = new File(args[2]);
    new File(file.getParent()).mkdir();
    FileWriter output = new FileWriter(file);
    output.write(sw.toString());
    output.close();
}
 
开发者ID:FIXTradingCommunity,项目名称:fix-orchestra,代码行数:38,代码来源:RepositoryXslTransformer.java

示例2: call

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {                            
  StringWriter sw = new StringWriter();      
  JsonXMLConfig config = new JsonXMLConfigBuilder().        
      prettyPrint(true).
      build();    
  XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);                  
  TransformerFactory tFactory = new TransformerFactoryImpl();      
  try {
    SequenceIterator iter = arguments[0].iterate(); 
    Item item;
    while ((item = iter.next()) != null) {
      if (item instanceof NodeInfo) {
        Transformer transformer = tFactory.newTransformer();            
        XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);            
        transformer.transform((NodeInfo) item, new StAXResult(xsw));                                   
      } else {
        sw.append(item.getStringValue());
      }
    }
  } catch (Exception e) {
    throw new XPathException("Error serializing sequence to JSON", e);
  }
  return StringValue.makeStringValue(sw.toString());              
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:26,代码来源:SerializeJSON.java

示例3: saxonTransform

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt, Map<String, String> params) throws Exception {
  TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl();
  f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
  StreamSource xsrc = new StreamSource(new FileInputStream(xslt));
  f.setURIResolver(new MyURIResolver(xsltDir, alt));
  Transformer t = f.newTransformer(xsrc);
	if (params != null) {
		for (Map.Entry<String, String> entry : params.entrySet()) {
			t.setParameter(entry.getKey(), entry.getValue());
		}
	}
  
  t.setURIResolver(new MyURIResolver(xsltDir, alt));
  StreamSource src = new StreamSource(new FileInputStream(source));
  StreamResult res = new StreamResult(new FileOutputStream(dest));
  t.transform(src, res);    
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:18,代码来源:Utilities.java

示例4: saxonTransform

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt, Map<String, String> params) throws FileNotFoundException, TransformerException  {
  TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl();
  f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
  StreamSource xsrc = new StreamSource(new FileInputStream(xslt));
  f.setURIResolver(new MyURIResolver(xsltDir, alt));
  Transformer t = f.newTransformer(xsrc);
    if (params != null) {
       for (Map.Entry<String, String> entry : params.entrySet()) {
          t.setParameter(entry.getKey(), entry.getValue());
       }
 }
  
  t.setURIResolver(new MyURIResolver(xsltDir, alt));
  StreamSource src = new StreamSource(new FileInputStream(source));
  StreamResult res = new StreamResult(new FileOutputStream(dest));
  t.transform(src, res);    
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:18,代码来源:SaxonUtilities.java

示例5: TransformAction

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
/** 
    * Create a new transform action using the specified XSLT. 
    * 
    * @param xsltFile the XSL stylesheet
    * @param cacheDir the directory to cache results of resource requests
    * @param semaphore a semaphore to control the concurrent number of transforms
    * @throws FileNotFoundException stylesheet couldn't be found
    * @throws TransformerConfigurationException there is a problem with the stylesheet
    */
   public TransformAction(String xsltFile,Path cacheDir,Semaphore semaphore) throws FileNotFoundException, TransformerConfigurationException {
this.xsltFile = xsltFile;
       this.cacheDir = cacheDir;
       this.semaphore = semaphore;
factory = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null);
       if(factory instanceof TransformerFactoryImpl) {
           TransformerFactoryImpl transformerFactoryImpl = ((TransformerFactoryImpl)factory);
           logger.debug("Telling Saxon to send messages as warnings to logger");
           final Configuration tfConfig = transformerFactoryImpl.getConfiguration();
           tfConfig.setMessageEmitterClass("net.sf.saxon.serialize.MessageWarner");
           if (cacheDir != null) {
               logger.debug("Setting the URLResolve to cache in "+cacheDir);
               transformerFactoryImpl.setURIResolver(new TransformActionURLResolver(transformerFactoryImpl.getURIResolver()));
           }
       }
       factory.setErrorListener(new TransformActionErrorListener());
       Source xslSource = null;
       if (xsltFile.startsWith("http:") || xsltFile.startsWith("https:"))
           xslSource = new StreamSource(xsltFile);
       else
           xslSource = new StreamSource(new FileInputStream(xsltFile),xsltFile);
templates = factory.newTemplates(xslSource);
   }
 
开发者ID:clarin-eric,项目名称:oai-harvest-manager,代码行数:33,代码来源:TransformAction.java

示例6: newTransformer

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
/**
 * Obtain a new Transformer instance for the
 * specified XSLT file name.
 * A new entry will be added to the
 * cache if this is the first request
 * for the specified file name.
 *
 * @param xsltFile the file name
 *                     of an XSLT stylesheet.
 * @return a transformation context
 *         for the given stylesheet.
 */
public static synchronized Transformer newTransformer(String xsltFile)
        throws TransformerConfigurationException {
    MapEntry entry = (MapEntry) cache.get(xsltFile);

    InputStream inputStream = StylesheetCache.class.getClassLoader().getResourceAsStream(xsltFile);


    // create a new entry in the cache if necessary
    if (entry == null) {
        Source xslSource = new StreamSource(inputStream);

        TransformerFactory transFact = TransformerFactory.newInstance();
        ((TransformerFactoryImpl) transFact).getConfiguration().setMessageEmitterClass(Log4jEmitter.class.getName());
        Templates templates = transFact.newTemplates(xslSource);

        entry = new MapEntry(xsltFile, templates);
        cache.put(xsltFile, entry);
    }

    return entry.templates.newTransformer();
}
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:34,代码来源:StylesheetCache.java

示例7: initTransformerFactory

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public void initTransformerFactory(TransformerFactory factory)
{
  super.initTransformerFactory(factory);
  if (factory instanceof TransformerFactoryImpl)
  {
    Configuration configuration = ((TransformerFactoryImpl) factory).getConfiguration();
    XPathStaticContext xpathContext = new IndependentContext(configuration);
    if (!xpathContext.getFunctionLibrary().isAvailable(LineNumberFunction.QNAME, -1))
    {
      configuration.registerExtensionFunction(new LineNumberFunction());
    }
    if (!xpathContext.getFunctionLibrary().isAvailable(ColumnNumberFunction.QNAME, -1))
    {
      configuration.registerExtensionFunction(new ColumnNumberFunction());
    }
    if (!xpathContext.getFunctionLibrary().isAvailable(SystemIdFunction.QNAME, -1))
    {
      configuration.registerExtensionFunction(new SystemIdFunction());
    }
  }
}
 
开发者ID:jcdarwin,项目名称:epubcheck-web,代码行数:22,代码来源:XMLValidator.java

示例8: getIdentityTransformer

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public static WeaklyCachedXsltTransformer getIdentityTransformer() {
    TransformerFactoryImpl transformerFactory = (TransformerFactoryImpl) TransformerFactory.newInstance(
        TransformerFactoryImpl.class.getName(), DocumentGenerator.class.getClassLoader());
    
    WeaklyCachedXsltTransformer result = new WeaklyCachedXsltTransformer();
    result.xsltTransformerFactory = new XsltTransformerFactory() {
        @Override public Transformer newTransformer() {
            try { return transformerFactory.newTransformer(); }
            catch (TransformerConfigurationException e) { throw new RuntimeException(e); }
        }
    };
    return result;
}
 
开发者ID:onestopconcept,项目名称:onestop-endpoints,代码行数:14,代码来源:WeaklyCachedXsltTransformer.java

示例9: createTransformerFactory

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public static TransformerFactory createTransformerFactory() {
  final TransformerFactoryImpl factory = new TransformerFactoryImpl();
  factory.setAttribute(FeatureKeys.TRACE_LISTENER, new Saxon9TraceListener());
  try {
    factory.setAttribute(FeatureKeys.OPTIMIZATION_LEVEL, "0");
  } catch (IllegalArgumentException e) {
    e.printStackTrace();
  }
  return factory;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:Saxon9Support.java

示例10: testInstantiateAnInstanceOfTemplates

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
@Test
public void testInstantiateAnInstanceOfTemplates() throws Exception {
    TemplatesFactory fac = TemplatesFactory.newInstance();
    TransformerFactory factory = new TransformerFactoryImpl();
    factory.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR));
    Templates templates = fac.getTemplates(ClassLoader.getSystemResourceAsStream(rules), factory);
    Assert.assertNotNull(templates);

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:TemplatesFactoryTest.java

示例11: setUP

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
@BeforeClass
public static void setUP() {
    SchematronEndpoint endpoint = new SchematronEndpoint();
    TransformerFactory fac = new TransformerFactoryImpl();
    fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR));
    Templates templates = TemplatesFactory.newInstance().getTemplates(ClassLoader.
            getSystemResourceAsStream("sch/schematron-1.sch"), fac);
    endpoint.setRules(templates);
    producer = new SchematronProducer(endpoint);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:SchematronProducerTest.java

示例12: tryTemplatesCache

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public Templates tryTemplatesCache(String transformationPath,  
    ErrorListener errorListener) throws Exception {
  String key = FilenameUtils.normalize(transformationPath);
  Templates templates = templatesCache.get(key);    
  if (templates == null) {
    logger.info("Compiling and caching STX stylesheet \"" + transformationPath + "\" ...");                 
    try {
      SAXParserFactory spf = SAXParserFactory.newInstance();
      spf.setNamespaceAware(true);
      spf.setXIncludeAware(true);
      spf.setValidating(false);
      SAXParser parser = spf.newSAXParser();
      XMLReader reader = parser.getXMLReader();        
      Source source = new SAXSource(reader, new InputSource(transformationPath));         
      net.sf.joost.trax.TransformerFactoryImpl tfi = new net.sf.joost.trax.TransformerFactoryImpl();
      tfi.setAttribute(TrAXConstants.MESSAGE_EMITTER_CLASS, new MessageEmitter());
      tfi.setErrorListener(errorListener);
      templates = tfi.newTemplates(source);
    } catch (Exception e) {
      logger.error("Could not compile STX stylesheet \"" + transformationPath + "\"", e);
      throw e;
    }      
    if (!developmentMode) {
      templatesCache.put(key, templates);
    }      
  }
  return templates;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:29,代码来源:WebApp.java

示例13: trySchematronCache

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public XsltExecutable trySchematronCache(String schematronPath, String phase, 
    ErrorListener errorListener) throws Exception {
  String key = FilenameUtils.normalize(schematronPath) + (phase != null ? phase : "");
  XsltExecutable templates = xsltExecutableCache.get(key);    
  if (templates == null) {
    logger.info("Compiling and caching schematron schema \"" + schematronPath + "\" ...");                 
    try {
      Source source = new StreamSource(new File(schematronPath));
      File schematronDir = new File(Context.getInstance().getHomeDir(), "common/xsl/system/schematron");
      
      ErrorListener listener = new TransformationErrorListener(null, developmentMode); 
      MessageWarner messageWarner = new MessageWarner();
      
      Xslt30Transformer stage1 = tryXsltExecutableCache(new File(schematronDir, "iso_dsdl_include.xsl").getAbsolutePath(), errorListener, false).load30();
      stage1.setErrorListener(listener);
      stage1.getUnderlyingController().setMessageEmitter(messageWarner);
      Xslt30Transformer stage2 = tryXsltExecutableCache(new File(schematronDir, "iso_abstract_expand.xsl").getAbsolutePath(), errorListener, false).load30();
      stage2.setErrorListener(listener);
      stage2.getUnderlyingController().setMessageEmitter(messageWarner);
      Xslt30Transformer stage3 = tryXsltExecutableCache(new File(schematronDir, "iso_svrl_for_xslt2.xsl").getAbsolutePath(), errorListener, false).load30();
      stage3.setErrorListener(listener);
      stage3.getUnderlyingController().setMessageEmitter(messageWarner);
     
      XdmDestination destStage1 = new XdmDestination();
      XdmDestination destStage2 = new XdmDestination();
      XdmDestination destStage3 = new XdmDestination();

      stage1.applyTemplates(source, destStage1);
      stage2.applyTemplates(destStage1.getXdmNode().asSource(), destStage2);
      stage3.applyTemplates(destStage2.getXdmNode().asSource(), destStage3);
      
      Source generatedXsltSource = destStage3.getXdmNode().asSource();
      
      if (this.developmentMode) {
        TransformerFactory factory = new TransformerFactoryImpl();
        Transformer transformer = factory.newTransformer();
        Properties props = new Properties();
        props.put(OutputKeys.INDENT, "yes");
        transformer.setOutputProperties(props);
        StringWriter sw = new StringWriter();
        transformer.transform(generatedXsltSource, new StreamResult(sw));
        logger.info("Generated Schematron XSLT for \"" + schematronPath + "\", phase \"" + (phase != null ? phase : "") + "\" [" + sw.toString() + "]");
      }
      
      
      XsltCompiler comp = processor.newXsltCompiler();
      comp.setErrorListener(errorListener);
      templates = comp.compile(generatedXsltSource);
      
    } catch (Exception e) {
      logger.error("Could not compile schematron schema \"" + schematronPath + "\"", e);
      throw e;
    }      
    if (!developmentMode) {
      xsltExecutableCache.put(key, templates);
    }      
  }
  return templates;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:60,代码来源:WebApp.java

示例14: serialize

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
protected void serialize(NodeInfo nodeInfo, Result result, Properties outputProperties) throws XPathException {
  try {
    TransformerFactory factory = new TransformerFactoryImpl();
    Transformer transformer = factory.newTransformer();
    if (outputProperties != null) {
      transformer.setOutputProperties(outputProperties);
    }
    transformer.transform(nodeInfo, result);
  } catch (Exception e) {
    throw new XPathException(e);
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:13,代码来源:ExtensionFunctionCall.java

示例15: DocumentInProgress

import net.sf.saxon.TransformerFactoryImpl; //导入依赖的package包/类
public DocumentInProgress(FileStore store, String encoding) throws TeiidComponentException{
  	final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(store, encoding);
      this.xml = new SQLXMLImpl(fsisf);
      this.xml.setEncoding(encoding);
      SAXTransformerFactory factory = new TransformerFactoryImpl();
      try {
	//SAX2.0 ContentHandler
	handler = factory.newTransformerHandler();
	handler.setResult(new StreamResult(fsisf.getOuputStream()));
} catch (Exception e) {
	 throw new TeiidComponentException(QueryPlugin.Event.TEIID30204, e);
}
      transformer = handler.getTransformer();
      transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
  }
 
开发者ID:kenweezy,项目名称:teiid,代码行数:16,代码来源:DocumentInProgress.java


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