List of usage examples for javax.xml.transform TransformerConfigurationException TransformerConfigurationException
public TransformerConfigurationException(Throwable e)
TransformerConfigurationException
with a given Exception
base cause of the error. From source file:Main.java
/** * @return a new XSLT transformer/*from w w w.j a v a 2 s . c om*/ * @throws TransformerConfigurationException if no TransformerFactory can be located in the * runtime environment. */ public static Transformer getTransformer() throws TransformerConfigurationException { TransformerFactory tf; try { tf = TransformerFactory.newInstance(); } catch (TransformerFactoryConfigurationError e) { System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_JDK5); tf = TransformerFactory.newInstance(); } if (tf != null) { return tf.newTransformer(); } else { throw new TransformerConfigurationException("Unable to instantiate a TransformerFactory"); } }
From source file:net.sf.joost.trax.TrAXHelper.java
/** * Helpermethod for getting an InputSource from a StreamSource. * @param source <code>Source</code> * @return An <code>InputSource</code> object or null * @throws TransformerConfigurationException *//*from w w w .j ava2 s . com*/ protected static InputSource getInputSourceForStreamSources(Source source, ErrorListener errorListener) throws TransformerConfigurationException { if (DEBUG) log.debug("getting an InputSource from a StreamSource"); InputSource input = null; String systemId = source.getSystemId(); if (systemId == null) { systemId = ""; } try { if (source instanceof StreamSource) { if (DEBUG) log.debug("Source is a StreamSource"); StreamSource stream = (StreamSource) source; InputStream istream = stream.getInputStream(); Reader reader = stream.getReader(); // Create InputSource from Reader or InputStream in Source if (istream != null) { input = new InputSource(istream); } else { if (reader != null) { input = new InputSource(reader); } else { input = new InputSource(systemId); } } } else { //Source type is not supported if (errorListener != null) { try { errorListener .fatalError(new TransformerConfigurationException("Source is not a StreamSource")); return null; } catch (TransformerException e2) { if (DEBUG) log.debug("Source is not a StreamSource"); throw new TransformerConfigurationException("Source is not a StreamSource"); } } if (DEBUG) log.debug("Source is not a StreamSource"); throw new TransformerConfigurationException("Source is not a StreamSource"); } //setting systemId input.setSystemId(systemId); // } catch (NullPointerException nE) { // //catching NullPointerException // if(errorListener != null) { // try { // errorListener.fatalError( // new TransformerConfigurationException(nE)); // return null; // } catch( TransformerException e2) { // log.debug(nE); // throw new TransformerConfigurationException(nE.getMessage()); // } // } // log.debug(nE); // throw new TransformerConfigurationException(nE.getMessage()); } catch (SecurityException sE) { //catching SecurityException if (errorListener != null) { try { errorListener.fatalError(new TransformerConfigurationException(sE)); return null; } catch (TransformerException e2) { if (DEBUG) log.debug(sE); throw new TransformerConfigurationException(sE.getMessage()); } } if (DEBUG) log.debug(sE); throw new TransformerConfigurationException(sE.getMessage()); } return (input); }
From source file:net.sf.joost.trax.TemplatesImpl.java
/** * Configures the <code>Templates</code> - initializing with a completed * <code>Parser</code> object. * @param stxParser A <code>Parser</code> * @throws TransformerConfigurationException When an error occurs while * initializing the <code>Templates</code>. *//*from w w w . jav a 2 s .c o m*/ private void init(Parser stxParser) throws TransformerConfigurationException { if (DEBUG) log.debug("init without InputSource "); try { // check if transformerfactory is in debug mode boolean debugmode = ((Boolean) this.factory.getAttribute(DEBUG_FEATURE)).booleanValue(); if (debugmode) { if (log != null) log.info("init transformer in debug mode"); processor = new DebugProcessor(stxParser); } else { processor = new Processor(stxParser); } processor.setTransformerHandlerResolver(factory.thResolver); processor.setOutputURIResolver(factory.outputUriResolver); } catch (org.xml.sax.SAXException sE) { if (log != null) log.fatal(sE); throw new TransformerConfigurationException(sE.getMessage()); } catch (java.lang.NullPointerException nE) { if (log != null) log.fatal(nE); throw new TransformerConfigurationException( "Could not found value for property javax.xml.parsers.SAXParser " + nE.getMessage()); } }
From source file:net.sf.joost.trax.TransformerFactoryImpl.java
/** * Returns the <code>Source</code> of the stylesheet associated with * the xml-document.//w w w.j a v a 2 s . co m * Feature is not supported. * @param source The <code>Source</code> of the xml-document. * @param media Matching media-type. * @param title Matching title-type. * @param charset Matching charset-type. * @return A <code>Source</code> of the stylesheet. * @throws TransformerConfigurationException */ public Source getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException { TransformerConfigurationException tE = new TransformerConfigurationException("Feature not supported"); defaultErrorListener.fatalError(tE); return null; }
From source file:cz.cas.lib.proarc.common.export.cejsh.CejshBuilder.java
public CejshBuilder(CejshConfig config) throws TransformerConfigurationException, ParserConfigurationException, XPathExpressionException { this.gcalendar = new GregorianCalendar(UTC); this.logLevel = config.getLogLevel(); TransformerFactory xslFactory = TransformerFactory.newInstance(); tranformationErrorHandler = new TransformErrorListener(); bwmetaXsl = xslFactory.newTransformer(new StreamSource(config.getCejshXslUrl())); if (bwmetaXsl == null) { throw new TransformerConfigurationException("Cannot load XSL: " + config.getCejshXslUrl()); }/* ww w. j a v a2s. co m*/ bwmetaXsl.setOutputProperty(OutputKeys.INDENT, "yes"); bwmetaXsl.setErrorListener(tranformationErrorHandler); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); db = dbf.newDocumentBuilder(); XPathFactory xPathFactory = ProarcXmlUtils.defaultXPathFactory(); XPath xpath = xPathFactory.newXPath(); xpath.setNamespaceContext(new SimpleNamespaceContext().add("m", ModsConstants.NS)); issnPath = xpath.compile("m:mods/m:identifier[@type='issn' and not(@invalid)]"); partNumberPath = xpath.compile("m:mods/m:titleInfo/m:partNumber"); dateIssuedPath = xpath.compile("m:mods/m:originInfo/m:dateIssued"); reviewedArticlePath = xpath.compile("m:mods/m:genre[text()='article' and @type='peer-reviewed']"); }
From source file:net.sf.joost.trax.TemplatesImpl.java
/** * Method returns a Transformer-instance for transformation-process * @return A <code>Transformer</code> object. * @throws TransformerConfigurationException *//*from w w w .ja v a 2s. co m*/ public Transformer newTransformer() throws TransformerConfigurationException { synchronized (reentryGuard) { if (DEBUG) log.debug("calling newTransformer to get a " + "Transformer object for Transformation"); try { // register the processor Transformer transformer = new TransformerImpl(processor.copy()); if (factory.getURIResolver() != null) transformer.setURIResolver(factory.getURIResolver()); return transformer; } catch (SAXException e) { if (log != null) log.fatal(e); throw new TransformerConfigurationException(e.getMessage()); } } }
From source file:net.sf.joost.trax.TransformerFactoryImpl.java
/** * Supplied features./* w w w. j a v a2s . c o m*/ * @param name Name of the feature. * @return true if feature is supported. */ public boolean getFeature(String name) { if (name.equals(SAXSource.FEATURE)) { return true; } if (name.equals(SAXResult.FEATURE)) { return true; } if (name.equals(DOMSource.FEATURE)) { return true; } if (name.equals(DOMResult.FEATURE)) { return true; } if (name.equals(StreamSource.FEATURE)) { return true; } if (name.equals(StreamResult.FEATURE)) { return true; } if (name.equals(SAXTransformerFactory.FEATURE)) { return true; } if (name.equals(SAXTransformerFactory.FEATURE_XMLFILTER)) { return true; } String errMsg = "Unknown feature " + name; TransformerConfigurationException tE = new TransformerConfigurationException(errMsg); try { defaultErrorListener.error(tE); return false; } catch (TransformerException e) { throw new IllegalArgumentException(errMsg); } }
From source file:net.sf.joost.trax.TransformerFactoryImpl.java
/** * Method creates a new Emitter for stx:message output * @param emitterClass the name of the emitter class * @return a <code>StxEmitter</code> * @throws TransformerConfigurationException in case of errors *//* w w w .j a v a 2s. co m*/ public StxEmitter buildMessageEmitter(String emitterClass) throws TransformerConfigurationException { Object emitter = null; try { emitter = loadClass(emitterClass).newInstance(); if (!(emitter instanceof StxEmitter)) { throw new TransformerConfigurationException(emitterClass + " is not an StxEmitter"); } } catch (InstantiationException ie) { throw new TransformerConfigurationException(ie.getMessage(), ie); } catch (IllegalAccessException ile) { throw new TransformerConfigurationException(ile.getMessage(), ile); } return (StxEmitter) emitter; }
From source file:nl.b3p.catalog.xml.mdeXml2Html.java
/** * The following transformers should be present in de configuration under * mdeConfig://from w ww .j av a 2s.c o m * <li> mdemain * <li> mdeXmlPreprocessor * <li> ISO19115toDC * <li> DCtoISO19115 * The next transformers may be present: * <li> extrapreprocessor1 * <li> extrapreprocessor2 * <li> extrasync1 * <li> extrasync2 * <li> extrapostprocessor1 * * @param xslName * @return inputstream to transformer * @throws TransformerConfigurationException * @throws FileNotFoundException */ private static InputStream getXslStream(String xslName) throws TransformerConfigurationException, FileNotFoundException { CatalogAppConfig cfg = CatalogAppConfig.getConfig(); Map<String, String> params = cfg.getMdeConfig(); if (params == null) { throw new TransformerConfigurationException("Transformers are missing from configuration!"); } String xslPath = params.get(xslName); if (xslPath == null) { return null; } File f = new File(xslPath); if (!f.isAbsolute()) { f = new File(cfg.getConfigFilePath(), xslPath); } return new FileInputStream(f); }
From source file:nl.b3p.catalog.xml.mdeXml2Html.java
private static Document transformIntern(Document doc, String xslName, Boolean viewMode, boolean ignoreAllowed) throws JDOMException, IOException, TransformerConfigurationException, TransformerException { log.debug("XML before transformation with '" + xslName + "':\n" + DocumentHelper.getDocumentString(doc)); Templates aTemplates = null;//from w w w . j a v a2 s.c om if (!transformerTemplates.containsKey(xslName)) { InputStream is = getXslStream(xslName); if (is != null) { if (transformerFactory == null) { transformerFactory = TransformerFactory.newInstance(); } aTemplates = transformerFactory.newTemplates(new StreamSource(is)); } transformerTemplates.put(xslName, aTemplates); } else { aTemplates = transformerTemplates.get(xslName); } if (aTemplates == null) { if (ignoreAllowed) { // ignore transformer return doc; } else { throw new TransformerConfigurationException( "Transformer [" + xslName + "] is missing from configuration!"); } } Transformer t = aTemplates.newTransformer(); Map<String, String> params = CatalogAppConfig.getConfig().getMdeConfig(); if (params != null) { for (Map.Entry<String, String> param : params.entrySet()) { t.setParameter(param.getKey(), param.getValue()); } if (viewMode != null) { t.setParameter("globalReadonly_init", viewMode.toString()); } } JDOMResult result = new JDOMResult(); t.transform(new JDOMSource(doc), result); log.debug("XML after transformation with '" + xslName + "':\n" + DocumentHelper.getDocumentString(result.getDocument())); return result.getDocument(); }