/** * Instantiate a new TransformerFactory for this view. * <p>The default implementation simply calls * {@link javax.xml.transform.TransformerFactory#newInstance()}. * If a {@link #setTransformerFactoryClass "transformerFactoryClass"} * has been specified explicitly, the default constructor of the * specified class will be called instead. * <p>Can be overridden in subclasses. * @param transformerFactoryClass the specified factory class (if any) * @return the new TransactionFactory instance * @see #setTransformerFactoryClass * @see #getTransformerFactory() */ protected TransformerFactory newTransformerFactory( @Nullable Class<? extends TransformerFactory> transformerFactoryClass) { if (transformerFactoryClass != null) { try { return ReflectionUtils.accessibleConstructor(transformerFactoryClass).newInstance(); } catch (Exception ex) { throw new TransformerFactoryConfigurationError(ex, "Could not instantiate TransformerFactory"); } } else { return TransformerFactory.newInstance(); } }
/** * Returns an instance of the named implementation of {@code TransformerFactory}. * * @throws TransformerFactoryConfigurationError if {@code factoryClassName} is not available or * cannot be instantiated. * @since 1.6 */ public static TransformerFactory newInstance(String factoryClassName, ClassLoader classLoader) throws TransformerFactoryConfigurationError { if (factoryClassName == null) { throw new TransformerFactoryConfigurationError("factoryClassName == null"); } if (classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } try { Class<?> type = classLoader != null ? classLoader.loadClass(factoryClassName) : Class.forName(factoryClassName); return (TransformerFactory) type.newInstance(); } catch (ClassNotFoundException e) { throw new TransformerFactoryConfigurationError(e); } catch (InstantiationException e) { throw new TransformerFactoryConfigurationError(e); } catch (IllegalAccessException e) { throw new TransformerFactoryConfigurationError(e); } }
/** * Instantiate a new TransformerFactory for this view. * <p>The default implementation simply calls * {@link javax.xml.transform.TransformerFactory#newInstance()}. * If a {@link #setTransformerFactoryClass "transformerFactoryClass"} * has been specified explicitly, the default constructor of the * specified class will be called instead. * <p>Can be overridden in subclasses. * @param transformerFactoryClass the specified factory class (if any) * @return the new TransactionFactory instance * @see #setTransformerFactoryClass * @see #getTransformerFactory() */ protected TransformerFactory newTransformerFactory( @Nullable Class<? extends TransformerFactory> transformerFactoryClass) { if (transformerFactoryClass != null) { try { return ReflectionUtils.accessibleConstructor(transformerFactoryClass).newInstance(); } catch (Exception ex) { throw new TransformerFactoryConfigurationError(ex, "Could not instantiate TransformerFactory"); } } else { return TransformerFactory.newInstance(); } }
public static TransformerFactory newInstance() throws TransformerFactoryConfigurationError { try { return (TransformerFactory) FactoryFinder.find( /* The default property name according to the JAXP spec */ "javax.xml.transform.TransformerFactory", /* The fallback implementation class name, XSLTC */ "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); } catch (FactoryFinder.ConfigurationError e) { throw new TransformerFactoryConfigurationError( e.getException(), e.getMessage()); } }
private Object createFactory(String factoryClassName) throws TransformerFactoryConfigurationError { try { return Class.forName(factoryClassName).newInstance(); } catch (InstantiationException e) { throw new TransformerFactoryConfigurationError(e); } catch (IllegalAccessException e) { throw new TransformerFactoryConfigurationError(e); } catch (ClassNotFoundException e) { throw new TransformerFactoryConfigurationError(e); } }
private Object createFactory(String factoryClassName) throws TransformerFactoryConfigurationError { try { return Class.forName(factoryClassName).newInstance(); } catch (InstantiationException e) { throw new TransformerFactoryConfigurationError(e); } catch (IllegalAccessException e) { throw new TransformerFactoryConfigurationError(e); } catch (ClassNotFoundException e) { throw new TransformerFactoryConfigurationError(e); } }
/** * Get a parser by instantiating the SAXParserFactory * @return the parser (XMLReader) */ private XMLReader loadParser() { XMLReader parser; try { parser = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); } catch (ParserConfigurationException err) { throw new TransformerFactoryConfigurationError(err); } catch (SAXException err) { throw new TransformerFactoryConfigurationError(err); } return parser; }
private TransformerFactory newTransformerFactory( Class<TransformerFactory> transformerFactoryClass) { if (transformerFactoryClass != null) { try { return (TransformerFactory) transformerFactoryClass .newInstance(); } catch (Exception ex) { throw new TransformerFactoryConfigurationError(ex, "Could not instantiate TransformerFactory"); } } else { return TransformerFactory.newInstance(); } }
public SAXTransformerFactory newTransformerFactory() { TransformerFactory factory = TransformerFactory.newInstance(); if (factory.getFeature(SAXTransformerFactory.FEATURE)) return (SAXTransformerFactory)factory; throw new TransformerFactoryConfigurationError("JAXP TransformerFactory must support SAXTransformerFactory feature"); }
public MockTransformerFactory() { super(); if (isThrowInConstructor) { throw new TransformerFactoryConfigurationError("Intentionally throwing config error"); } }
/** * Build an {@link TransformerFactory} and prevent external entities from accessing. * * @see TransformerFactory#newInstance() */ public static TransformerFactory newInstance(Class<? extends TransformerFactory> transformerFactoryClass) { try { return defaultSettings(transformerFactoryClass.newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new TransformerFactoryConfigurationError(e, "Could not instantiate TransformerFactory [" + transformerFactoryClass + "]"); } }
public SAXTransformerFactory newTransformerFactory() { TransformerFactory factory = TransformerFactory.newInstance(); if (factory.getFeature(SAXTransformerFactory.FEATURE)) return (SAXTransformerFactory)factory; throw new TransformerFactoryConfigurationError("JAXP TransformerFactory must support SAXTransformerFactory feature"); }
/** * Determine whether attribute types obtained from a DTD are to be used to set type annotations * on the resulting nodes. * * @param useTypes set to true if DTD types are to be taken into account * @since 8.4 */ public void setRetainDTDAttributeTypes(boolean useTypes) throws TransformerFactoryConfigurationError { if (useTypes && !isSchemaAware(Configuration.XML_SCHEMA)) { throw new TransformerFactoryConfigurationError( "Retaining DTD attribute types requires the schema-aware product"); } retainDTDattributeTypes = useTypes; }
/** * Build an {@link TransformerFactory} and prevent external entities from accessing. * * @see TransformerFactory#newInstance() */ public static TransformerFactory newInstance(Class<? extends TransformerFactory> transformerFactoryClass) { try { return defaultSettings(transformerFactoryClass.newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new TransformerFactoryConfigurationError(e, "Could not instantiate TransformerFactory [" + transformerFactoryClass + "]"); } }
public static org.dom4j.Document convertToDom4JDoc( final org.w3c.dom.Document doc ) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, DocumentException { DOMSource source = new DOMSource( doc ); StreamResult result = new StreamResult( new StringWriter() ); TransformerFactory.newInstance().newTransformer().transform( source, result ); String theXML = result.getWriter().toString(); Document dom4jDoc = null; try { dom4jDoc = getDocFromString( theXML, null ); } catch ( XmlParseException e ) { throw new TransformerFactoryConfigurationError( e ); } return dom4jDoc; } }
/** * Determine whether attribute types obtained from a DTD are to be used to set type annotations * on the resulting nodes. * * @param useTypes set to true if DTD types are to be taken into account * @since 8.4 */ public void setRetainDTDAttributeTypes(boolean useTypes) throws TransformerFactoryConfigurationError { if (useTypes && !isSchemaAware(Configuration.XML_SCHEMA)) { throw new TransformerFactoryConfigurationError( "Retaining DTD attribute types requires the schema-aware product"); } retainDTDattributeTypes = useTypes; }
@Override public void start(BundleContext context) throws Exception { this.context = context; Bundle bundle = context.getBundle(); try { registerFactories(getFactoryClassNames(bundle.getResource(FACTORY_IMPLEMENTATIONS_FILE))); } catch (IOException ioe) { throw new TransformerFactoryConfigurationError(ioe); } }
@Override public void start(BundleContext context) throws Exception { this.context = context; Bundle bundle = context.getBundle(); try { registerFactories(getFactoryClassNames(bundle.getResource(FACTORY_IMPLEMENTATIONS_FILE))); } catch (IOException ioe) { throw new TransformerFactoryConfigurationError(ioe); } }
public static TransformerFactory newTransformerFactory(ClassLoader classLoader) { String transformerName = getSystemProperty(TRANSFORMER_FACTORY); if (transformerName != null && transformerName.length() != 0) { try { Class transformerClass = ClassLoading.loadClass(transformerName, classLoader); TransformerFactory transformerFactory = (TransformerFactory) transformerClass.newInstance(); return transformerFactory; } catch (Exception e) { throw new TransformerFactoryConfigurationError(e, "Unable to create TransformerFactory " + transformerName + ", which was specified in the " + TRANSFORMER_FACTORY + " system property"); } } return TransformerFactory.newInstance(); }
@Test(expectedExceptions = SystemException.class) public void testDecompressWhenTransformerFactoryConfigurationErrorIsThrownShouldLogError() throws TransformerConfigurationException { //GIVEN StreamResult result = new StreamResult(new StringWriter()); given(transformerFactory.createTransformer()).willThrow(new TransformerFactoryConfigurationError()); given(streamResultFactory.createStreamResult()).willReturn(result); //WHEN underTest.decompress(inputStream); //THEN it should throw exception }