/** * 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(); } }
pfe.printStackTrace(dumpWriter);
/** * Parses the source and sends SAX events to a content handler. * * @param contentHandler * The SAX content handler to use for parsing. */ public void parse(ContentHandler contentHandler) throws IOException { if (contentHandler != null) { try { Result result = new SAXResult(contentHandler); TransformerFactory.newInstance().newTransformer() .transform(getSaxSource(), result); } catch (TransformerConfigurationException tce) { throw new IOException( "Couldn't parse the source representation: " + tce.getMessage(), tce); } catch (TransformerException te) { throw new IOException( "Couldn't parse the source representation: " + te.getMessage(), te); } catch (TransformerFactoryConfigurationError tfce) { throw new IOException( "Couldn't parse the source representation: " + tfce.getMessage(), tfce); } } else { throw new IOException( "Couldn't parse the source representation: no content restlet defined."); } }
/** * Generate XML. * * @param doc the doc * @return the string */ private String generateXML(Document doc) { StringWriter stringWriter = new StringWriter(); try { // Output the XML file contents TransformerFactory tf = TransformerFactory.newInstance(); tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, SLDEditorFileHandler.YES); transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, SLDEditorFileHandler.YES); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); } catch (TransformerException e) { ConsoleManager.getInstance().exception(this, e); return null; } catch (TransformerFactoryConfigurationError e) { ConsoleManager.getInstance().exception(this, e.getException()); return null; } return stringWriter.getBuffer().toString(); }
public static void serialize(Document document, OutputStream ostream) throws IOException { Source domSource = new DOMSource(document); try { Transformer serializer = TransformerFactory.newInstance().newTransformer(); try { serializer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-16"); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // unsupported properties } serializer.transform(domSource, new StreamResult(ostream)); } catch (TransformerConfigurationException e) { throw new IOException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new IOException(e.getMessage()); } catch (TransformerException e) { throw new IOException(e.getMessage()); } } }
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, parameters); Source source = null; try { this.resolver = resolver; source = this.resolver.resolveURI(src); String systemId = source.getURI(); if (!(source instanceof ModifiableSource)) { throw new ProcessingException("Source '" + systemId + "' is not writeable."); } if (this.osCommand != null) { // FileSource is the only option when using the system command feature fileName = ((FileSource)source).getFile().getAbsolutePath(); } this.serializer = this.transformerFactory.newTransformerHandler(); os = ((ModifiableSource) source).getOutputStream(); this.serializer.setResult(new StreamResult(os)); } catch (SourceException e) { throw SourceUtil.handle(e); } catch (TransformerConfigurationException e) { throw new ProcessingException(e); } catch (TransformerFactoryConfigurationError error) { throw new ProcessingException(error.getException()); } finally { if (source != null) { this.resolver.release(source); } } }
/** * 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); } }
private void processEndGroup (Ending ending) { // Merge any remaining TU while ( !referents.isEmpty() ) { mergeTextUnit((ITextUnit)referents.pop()); } group--; try { if ( group != 1 ) { // Not a story group return; } } catch ( TransformerFactoryConfigurationError e ) { throw new OkapiIOException("Transform configuration error.\n"+e.getMessage(), e); } }
private void storeXmlDom(final OutputStream outZip, final Document xml) throws DSSException { try { final DOMSource xmlSource = new DOMSource(xml); final StreamResult outputTarget = new StreamResult(outZip); TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); } catch (TransformerException e) { throw new DSSException(e); } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError.printStackTrace(); } }
/** * 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(); } }
throw new IOException( "Couldn't parse the source representation: " + te.getMessage()); } catch (TransformerFactoryConfigurationError tfce) { throw new IOException( "Couldn't parse the source representation: " + tfce.getMessage());
private InputStream document2InputStream(Document document) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(document); Result outputTarget = new StreamResult(outputStream); try { TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } InputStream is = new ByteArrayInputStream(outputStream.toByteArray()); return is; }
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()); } }
throw new IOException( "Couldn't parse the source representation: " + te.getMessage()); } catch (TransformerFactoryConfigurationError tfce) { throw new IOException( "Couldn't parse the source representation: " + tfce.getMessage());
/** * @param node * the node to convert * @return the node */ public static String nodeToStr(final Node node) { final String YES = "yes"; StringWriter sw = new StringWriter(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, YES); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, YES); transformer.transform(new DOMSource(node), new StreamResult(sw)); return sw.toString(); } catch (TransformerFactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }
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); } }
@Override public void write(OutputStream outputStream) throws IOException { try { if (getDocument() != null) { final Transformer transformer = createTransformer(); transformer.transform(new DOMSource(getDocument()), new StreamResult(outputStream)); } } catch (TransformerConfigurationException tce) { throw new IOException("Couldn't write the XML representation: " + tce.getMessage()); } catch (TransformerException te) { throw new IOException("Couldn't write the XML representation: " + te.getMessage()); } catch (TransformerFactoryConfigurationError tfce) { throw new IOException("Couldn't write the XML representation: " + tfce.getMessage()); } } }
public ContentHandler xsl(ContentHandler consumer, String xslPath) throws IOException { try { // 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().getClassLoader().getResourceAsStream(xslPath))); // Use the template to create a transformer TransformerFactory transFact = TransformerFactory.newInstance(); SAXTransformerFactory saxTransFact = (SAXTransformerFactory) transFact; // create a ContentHandler TransformerHandler transHand = saxTransFact .newTransformerHandler(template); transHand.setResult(new SAXResult(consumer)); return transHand; } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } throw new IllegalStateException("Can't transform xml."); }
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); } }
@Override public void write(OutputStream outputStream) throws IOException { try { if (getDocument() != null) { final Transformer transformer = createTransformer(); transformer.transform(new DOMSource(getDocument()), new StreamResult(outputStream)); } } catch (TransformerConfigurationException tce) { throw new IOException("Couldn't write the XML representation: " + tce.getMessage()); } catch (TransformerException te) { throw new IOException("Couldn't write the XML representation: " + te.getMessage()); } catch (TransformerFactoryConfigurationError tfce) { throw new IOException("Couldn't write the XML representation: " + tfce.getMessage()); } } }