List of usage examples for javax.xml.transform.sax SAXTransformerFactory FEATURE
String FEATURE
To view the source code for javax.xml.transform.sax SAXTransformerFactory FEATURE.
Click Source Link
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Set the <code>Result</code> associated with this * <code>TransformerHandler</code> to be used for the transformation. * * @param result the Result to be used for the transformation *///w w w. ja v a 2 s.c o m protected final void setHandler(final Result result) { try { TransformerFactory factory = TransformerFactory.newInstance(); if (!factory.getFeature(SAXTransformerFactory.FEATURE)) { throw new UnsupportedOperationException("SAXTransformerFactory is not supported"); } SAXTransformerFactory saxFactory = (SAXTransformerFactory) factory; handler = saxFactory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); handler.setResult(result); } catch (Exception e) { throw new MarcException(e.getMessage(), e); } }
From source file:net.sf.joost.trax.TransformerFactoryImpl.java
/** * Supplied features.//w ww . java 2 s. 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:org.lilyproject.runtime.tools.plugin.genclassloader.ClassloaderMojo.java
/** * Create a project file containing the dependencies. * * @throws IOException/*from w w w . j a v a 2 s . c o m*/ * @throws SAXException */ private void createDependencyListing(File classloaderTemplate) throws IOException, SAXException { if (classloaderTemplate != null && classloaderTemplate.exists()) { getLog().info("Found classloader template, trying to parse it..."); parseClassloaderTemplate(classloaderTemplate); } final boolean hasEntries = entryMap.size() > 0; // fill in file with all dependencies FileOutputStream fos = new FileOutputStream(projectDescriptorFile); TransformerHandler ch = null; TransformerFactory factory = TransformerFactory.newInstance(); if (factory.getFeature(SAXTransformerFactory.FEATURE)) { try { ch = ((SAXTransformerFactory) factory).newTransformerHandler(); // set properties Transformer serializer = ch.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); // set result Result result = new StreamResult(fos); ch.setResult(result); // start file generation ch.startDocument(); AttributesImpl atts = new AttributesImpl(); if (this.shareSelf != null) { atts.addAttribute("", "share-self", "share-self", "CDATA", this.shareSelf); } ch.startElement("", "classloader", "classloader", atts); atts.clear(); ch.startElement("", "classpath", "classpath", atts); SortedSet<Artifact> sortedArtifacts = new TreeSet<Artifact>(dependenciesToList); Entry entry; String entryShare; String entryVersion; for (Artifact artifact : sortedArtifacts) { atts.addAttribute("", "groupId", "groupId", "CDATA", artifact.getGroupId()); atts.addAttribute("", "artifactId", "artifactId", "CDATA", artifact.getArtifactId()); if (artifact.getClassifier() != null) { atts.addAttribute("", "classifier", "classifier", "CDATA", artifact.getClassifier()); } if (!artifact.getGroupId().equals("org.lilyproject")) { atts.addAttribute("", "version", "version", "CDATA", artifact.getBaseVersion()); } entry = new Entry(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier()); if (hasEntries && entryMap.containsKey(entry)) { entryVersion = extractAttVal(entryMap.get(entry).getAttributes(), "version"); entryShare = extractAttVal(entryMap.get(entry).getAttributes(), "share"); entryMap.remove(entry); if (entryVersion != null && !entryVersion.equals("") && !entryVersion.equals(artifact.getBaseVersion())) { getLog().warn( "version conflict between entry in template and artifact on classpath for " + entry); } if (entryShare != null) { atts.addAttribute("", "", "share", "CDATA", entryShare); } } else { // atts.addAttribute("", "", "share", "CDATA", SHARE_DEFAULT); } ch.startElement("", "artifact", "artifact", atts); ch.endElement("", "artifact", "artifact"); atts.clear(); } ch.endElement("", "classpath", "classpath"); ch.endElement("", "classloader", "classloader"); ch.endDocument(); fos.close(); if (entryMap.size() > 0) { getLog().warn("Classloader template contains entries that could not be resolved."); } } catch (TransformerConfigurationException ex) { ex.printStackTrace(); throw new SAXException("Unable to get a TransformerHandler."); } } else { throw new RuntimeException("Could not load SAXTransformerFactory."); } }
From source file:org.pepstock.jem.ant.validator.transformer.TransformerValidator.java
/** * Inits the transformer, load the xslt and validate it, load jem properties * During the transformation, the transformer onbject is locked, so the file * listner is inhibited to do a refresh. * // www . j ava 2 s. c o m * @param xsltvalidatorFile the xslt file * @return the transformer * @throws ValidationException the validation exception */ private Transformer createTransformer(String xsltvalidatorFile) throws ValidationException { Transformer t = null; // Instantiate a TransformerFactory TransformerFactory tFactory = TransformerFactory.newInstance(); // add error listner to capture validation error. ErrorListener tfel = new TransformerFactoryErrorListener(); tFactory.setErrorListener(tfel); // check the transformer compliant if (!tFactory.getFeature(SAXTransformerFactory.FEATURE)) { throw new ValidationException(AntMessage.JEMA050E.toMessage().getFormattedMessage()); } // activate xalan extension NodeInfo to map source xml code position tFactory.setAttribute(TransformerFactoryImpl.FEATURE_SOURCE_LOCATION, Boolean.TRUE); StreamSource ss = new StreamSource(xsltvalidatorFile); try { // A Transformer may be used multiple times. // Parameters and output properties are preserved across // transformations. t = tFactory.newTransformer(ss); } catch (TransformerConfigurationException e) { throw new ValidationException(AntMessage.JEMA047E.toMessage().getFormattedMessage(e.getMessage()), e); } // add custom error listener, necessary to avoid internal catch // of exception throwed by xslt ErrorListener el = new TransformerErrorListener(); t.setErrorListener(el); // pass the parameter list to the xslt for (Object key : System.getProperties().keySet()) { String keyString = key.toString(); String value = System.getProperty(keyString); t.setParameter(keyString, value); } for (String key : System.getenv().keySet()) { String value = System.getenv().get(key); t.setParameter(key, value); } return t; }