本文整理汇总了Java中javax.xml.transform.TransformerException类的典型用法代码示例。如果您正苦于以下问题:Java TransformerException类的具体用法?Java TransformerException怎么用?Java TransformerException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransformerException类属于javax.xml.transform包,在下文中一共展示了TransformerException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeOut
import javax.xml.transform.TransformerException; //导入依赖的package包/类
private static void writeOut(Document doc) throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
DOMSource source = new DOMSource(doc);
File f = new File("splFile.xml");
f.delete();
StreamResult result = new StreamResult(f);
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
System.out.println("File saved!");
}
示例2: execute
import javax.xml.transform.TransformerException; //导入依赖的package包/类
@Override
public void execute(BuildResult result) {
String name = (container != null) ? "container " + container : "gradle";
Report report = new Report.Builder()
.name(name)
.subname(name)
.elapsedTimeNanos(System.nanoTime() - startTimeNanos)
.addAllTestCases(failureListener.getTestCases())
.build();
Document xml = reportToXml(report);
targetFile.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(targetFile)) {
XmlUtils.write(writer, xml);
} catch (IOException | TransformerException e) {
throw new RuntimeException(e);
}
}
示例3: execute
import javax.xml.transform.TransformerException; //导入依赖的package包/类
@Override
public void execute() throws BuildException {
if (StringUtils.isEmpty(dirName)) {
throw new BuildException("dirname is mandatory");
}
if (StringUtils.isEmpty(fileName)) {
throw new BuildException("filename is mandatory");
}
File file = new File(dirName + File.separator + fileName);
if (!file.exists()) {
throw new BuildException("wsdl file does not exist");
}
try {
Document doc = parse(file);
Element element = doc.createElement("documentation");
element.setTextContent("v" + version);
doc.getElementsByTagName("definitions").item(0)
.appendChild(element);
save(dirName + File.separator + fileName, doc);
} catch (ParserConfigurationException | SAXException | IOException
| TransformerException e) {
throw new BuildException(e);
}
}
示例4: getAbsoluteURI
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Take a SystemID string and try to turn it into a good absolute URI.
*
* @param urlString SystemID string
* @param base The URI string used as the base for resolving the systemID
*
* @return The resolved absolute URI
* @throws TransformerException thrown if the string can't be turned into a URI.
*/
public static String getAbsoluteURI(String urlString, String base)
throws TransformerException
{
if (base == null)
return getAbsoluteURI(urlString);
String absoluteBase = getAbsoluteURI(base);
URI uri = null;
try
{
URI baseURI = new URI(absoluteBase);
uri = new URI(baseURI, urlString);
}
catch (MalformedURIException mue)
{
throw new TransformerException(mue);
}
return replaceChars(uri.toString());
}
示例5: getXmlFragment
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Hulpmethode om een xml fragment uit een node te halen middels xpath.
* @param locatie de locatie van de node als xpath.
* @param xPath een XPath instantie
* @param node de basis node
* @return de text
*/
protected static String getXmlFragment(final String locatie, final XPath xPath, final Node node) {
try {
final Node xPathNode = (Node) xPath.evaluate(locatie, node, XPathConstants.NODE);
if (xPathNode != null) {
final StringWriter buf = new StringWriter();
final Transformer xform = TransformerFactory.newInstance().newTransformer();
xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
xform.transform(new DOMSource(xPathNode), new StreamResult(buf));
return buf.toString();
}
} catch (final XPathExpressionException | TransformerException e) {
LOGGER.error("XPath voor text content kon niet worden geëvalueerd voor locatie {}.", locatie);
throw new UnsupportedOperationException(e);
}
return null;
}
示例6: evaluate
import javax.xml.transform.TransformerException; //导入依赖的package包/类
public Object evaluate(String expression, InputSource source,
QName returnType) throws XPathExpressionException {
isSupported(returnType);
try {
Document document = getDocument(source);
XObject resultObject = eval(expression, document);
return getResultAsType(resultObject, returnType);
} catch (TransformerException te) {
Throwable nestedException = te.getException();
if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
throw (javax.xml.xpath.XPathFunctionException)nestedException;
} else {
throw new XPathExpressionException (te);
}
}
}
示例7: docToXml
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Converts the given document to an XML string. Uses UTF-8 as character
* encoding.
*
* @return the XML as byte array
*/
byte[] docToXml() {
try {
DOMSource domSource = new DOMSource(xmldoc);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
StreamResult result = new StreamResult(buffer);
Transformer transformer = Transformers.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(domSource, result);
return buffer.toByteArray();
} catch (TransformerException e) {
throw new SaaSSystemException(e);
}
}
示例8: warn
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Warn the user of a problem.
*
* @param msg An error msgkey that corresponds to one of the constants found
* in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
* a key for a format string.
* @param args An array of arguments represented in the format string, which
* may be null.
*
* @throws TransformerException if the current ErrorListoner determines to
* throw an exception.
*/
void warn(String msg, Object[] args) throws TransformerException
{
String fmsg = XSLMessages.createXPATHWarning(msg, args);
ErrorListener ehandler = this.getErrorListener();
if (null != ehandler)
{
// TO DO: Need to get stylesheet Locator from here.
ehandler.warning(new TransformerException(fmsg, m_sourceLocator));
}
else
{
// Should never happen.
System.err.println(fmsg);
}
}
示例9: writeXml
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Write out the non-default properties in this configuration to the given
* {@link Writer}.
*
* @param out the writer to write to.
*/
public void writeXml(Writer out) throws IOException {
Document doc = asXmlDocument();
try {
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(out);
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
// Important to not hold Configuration log while writing result, since
// 'out' may be an HDFS stream which needs to lock this configuration
// from another thread.
transformer.transform(source, result);
} catch (TransformerException te) {
throw new IOException(te);
}
}
示例10: generateForecast
import javax.xml.transform.TransformerException; //导入依赖的package包/类
private void generateForecast(String c) throws IOException, SAXException, TransformerException, ParserConfigurationException {
city = c;
// creating the URL
String url = "http://api.openweathermap.org/data/2.5/forecast/daily?q=" + city + ",us&mode=xml&cnt=6&appid=" + APIKey;
// printing out XML
URL urlString = new URL(url);
URLConnection conn = urlString.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(conn.getInputStream());
TransformerFactory transformer = TransformerFactory.newInstance();
Transformer xform = transformer.newTransformer();
xform.transform(new DOMSource(doc), new StreamResult(System.out));
}
示例11: getDocAsString
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Converts a given document into its string representation.
*
* @param doc
* The document to be converted.
* @param xmlDecl
* should the output contain a XML declaration?
* @return The string representation of the document.
* @throws TransformerException
* Thrown in case the conversion fails.
*/
private String getDocAsString(final Node doc) throws TransformerException {
final DOMSource docSource = new DOMSource(doc);
final TransformerFactory transformerFactory = TransformerFactory
.newInstance();
final Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
final StringWriter buffer = new StringWriter();
transformer.transform(docSource, new StreamResult(buffer));
lastRequest = buffer.toString();
return lastRequest;
}
示例12: getFactory
import javax.xml.transform.TransformerException; //导入依赖的package包/类
TransformerFactory getFactory() throws Exception {
if (fac == null) {
fac = TransformerFactory.newInstance();
fac.setURIResolver(new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
try {
return new StreamSource(asl2xml.class.getResource("/xml/" + href).openStream());
} catch (Exception e) {
System.err.println("Error - " + href + "-" + base);
e.printStackTrace();
return null;
}
}
});
}
return fac;
}
示例13: loadSource
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* This method implements XSLTC's SourceLoader interface. It is used to
* glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
*
* @param href The URI of the document to load
* @param context The URI of the currently loaded document
* @param xsltc The compiler that resuests the document
* @return An InputSource with the loaded document
*/
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
try {
if (_uriResolver != null) {
final Source source = _uriResolver.resolve(href, context);
if (source != null) {
return Util.getInputSource(xsltc, source);
}
}
}
catch (TransformerException e) {
// should catch it when the resolver explicitly throws the exception
final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
xsltc.getParser().reportError(Constants.FATAL, msg);
}
return null;
}
示例14: passErrorsToListener
import javax.xml.transform.TransformerException; //导入依赖的package包/类
/**
* Pass error messages from the compiler to the error listener
*/
private void passErrorsToListener(ArrayList<ErrorMsg> messages) {
try {
if (_errorListener == null || messages == null) {
return;
}
// Pass messages to listener, one by one
final int count = messages.size();
for (int pos = 0; pos < count; pos++) {
String message = messages.get(pos).toString();
_errorListener.error(new TransformerException(message));
}
}
catch (TransformerException e) {
// nada
}
}
示例15: writeOut
import javax.xml.transform.TransformerException; //导入依赖的package包/类
private static void writeOut(Document doc) throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
DOMSource source = new DOMSource(doc);
File f = new File("file.xml");
f.delete();
StreamResult result = new StreamResult(f);
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
System.out.println("File saved!");
}