use of javax.xml.transform.TransformerException in project Apktool by iBotPeaches.
the class ResXmlPatcher method removeManifestVersions.
/**
* Removes attributes like "versionCode" and "versionName" from file.
*
* @param file File representing AndroidManifest.xml
* @throws AndrolibException
*/
public static void removeManifestVersions(File file) throws AndrolibException {
if (file.exists()) {
try {
Document doc = loadDocument(file);
Node manifest = doc.getFirstChild();
NamedNodeMap attr = manifest.getAttributes();
Node vCode = attr.getNamedItem("android:versionCode");
Node vName = attr.getNamedItem("android:versionName");
if (vCode != null) {
attr.removeNamedItem("android:versionCode");
}
if (vName != null) {
attr.removeNamedItem("android:versionName");
}
saveDocument(file, doc);
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
}
}
}
use of javax.xml.transform.TransformerException in project jOOQ by jOOQ.
the class XMLDatabase method info.
private InformationSchema info() {
if (info == null) {
String xml = getProperties().getProperty(P_XML_FILE);
String xsl = getProperties().getProperty(P_XSL_FILE);
InputStream xmlIs = null;
InputStream xslIs = null;
log.info("Using XML file", xml);
try {
xmlIs = XMLDatabase.class.getResourceAsStream(xml);
if (xmlIs == null)
xmlIs = new FileInputStream(xml);
if (StringUtils.isBlank(xsl)) {
info = JAXB.unmarshal(new File(xml), InformationSchema.class);
} else {
log.info("Using XSL file", xsl);
xslIs = XMLDatabase.class.getResourceAsStream(xsl);
if (xslIs == null)
xslIs = new FileInputStream(xsl);
try {
StringWriter writer = new StringWriter();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslIs));
transformer.transform(new StreamSource(xmlIs), new StreamResult(writer));
info = JAXB.unmarshal(new StringReader(writer.getBuffer().toString()), InformationSchema.class);
} catch (TransformerException e) {
throw new RuntimeException("Error while transforming XML file " + xml + " with XSL file " + xsl, e);
}
}
} catch (IOException e) {
throw new RuntimeException("Error while opening files " + xml + " or " + xsl, e);
} finally {
if (xmlIs != null) {
try {
xmlIs.close();
} catch (Exception ignore) {
}
}
if (xslIs != null) {
try {
xslIs.close();
} catch (Exception ignore) {
}
}
}
}
return info;
}
use of javax.xml.transform.TransformerException in project sonarqube by SonarSource.
the class DebtModelXMLExporter method prettyFormatXml.
private static String prettyFormatXml(String xml) {
try {
Transformer serializer = SAXTransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", DEFAULT_INDENT);
Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))));
StreamResult res = new StreamResult(new ByteArrayOutputStream());
serializer.transform(xmlSource, res);
return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray(), StandardCharsets.UTF_8);
} catch (TransformerException ignored) {
// Ignore, raw XML will be returned
}
return xml;
}
use of javax.xml.transform.TransformerException in project openhab1-addons by openhab.
the class Helper method nodeToString.
/***
* Converts a xml Node into String
*
* @param node to convert
* @return converted string
*/
public static String nodeToString(Node node) {
StringWriter sw = new StringWriter();
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
logger.warn("nodeToString Transformer Exception", te);
}
return sw.toString();
}
use of javax.xml.transform.TransformerException in project OpenAM by OpenRock.
the class XMLResourceExceptionHandler method write.
@Override
public void write(MessageContext context, AuthenticationException exception) {
Reject.ifNull(exception);
try {
ResourceException jre;
if (exception instanceof AuthenticationFailedException) {
jre = new PermanentException(Status.UNAUTHORIZED.getCode(), exception.getMessage(), null);
} else if (exception.getCause() instanceof ResourceException) {
jre = (ResourceException) exception.getCause();
} else {
LOGGER.error(exception.getMessage(), exception);
jre = new InternalServerErrorException("Authentication Failed", exception);
}
AuditTrail auditTrail = context.getAuditTrail();
List<Map<String, Object>> failureReasonList = auditTrail.getFailureReasons();
if (failureReasonList != null && !failureReasonList.isEmpty()) {
jre.setDetail(json(object(field("failureReasons", failureReasonList))));
}
Response response = context.getResponse();
response.setStatus(Status.valueOf(jre.getCode()));
context.<Response>getResponse().getHeaders().put(ContentTypeHeader.valueOf(MediaType.XML_UTF_8.toString()));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Transformer transformer = XMLUtils.getTransformerFactory().newTransformer();
transformer.transform(new DOMSource(asXMLDOM(jre.includeCauseInJsonValue().toJsonValue().asMap())), new StreamResult(outputStream));
response.getEntity().setBytes(outputStream.toByteArray());
} catch (TransformerException e1) {
throw new IllegalStateException("Could not write XML to response", e1);
}
}
Aggregations