use of javax.xml.transform.TransformerFactoryConfigurationError in project zm-mailbox by Zimbra.
the class XsdCleaner method getTranformer.
public static Transformer getTranformer() {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
return transformer;
} catch (TransformerFactoryConfigurationError | TransformerException e) {
LOG.error("XsdCleaner:Problem getting XML Transformer", e);
}
return null;
}
use of javax.xml.transform.TransformerFactoryConfigurationError in project jabref by JabRef.
the class MSBibExportFormat method performExport.
@Override
public void performExport(final BibDatabaseContext databaseContext, final String file, final Charset encoding, List<BibEntry> entries) throws SaveException {
Objects.requireNonNull(databaseContext);
Objects.requireNonNull(entries);
if (entries.isEmpty()) {
return;
}
// forcing to use UTF8 output format for some problems with xml export in other encodings
SaveSession session = new FileSaveSession(StandardCharsets.UTF_8, false);
MSBibDatabase msBibDatabase = new MSBibDatabase(databaseContext.getDatabase(), entries);
try (VerifyingWriter ps = session.getWriter()) {
try {
DOMSource source = new DOMSource(msBibDatabase.getDomForExport());
StreamResult result = new StreamResult(ps);
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.transform(source, result);
} catch (TransformerException | IllegalArgumentException | TransformerFactoryConfigurationError e) {
throw new Error(e);
}
finalizeSaveSession(session, Paths.get(file));
} catch (IOException ex) {
throw new SaveException(ex);
}
}
use of javax.xml.transform.TransformerFactoryConfigurationError in project sling by apache.
the class SimpleXmlSerializationManager method buildSerializationData.
@Override
public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) throws SerializationException {
if (resource == null) {
return null;
}
Map<String, Object> content = resource.getProperties();
if (content == null || content.isEmpty()) {
return null;
}
try {
SAXTransformerFactory f = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
ByteArrayOutputStream result = new ByteArrayOutputStream();
StreamResult sr = new StreamResult(result);
TransformerHandler handler = f.newTransformerHandler();
Transformer t = handler.getTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
handler.setResult(sr);
handler.startDocument();
startElement(handler, TAG_RESOURCE);
Set<Entry<String, Object>> entrySet = new TreeMap<>(content).entrySet();
for (Map.Entry<String, Object> property : entrySet) {
Object value = property.getValue();
if (value instanceof String) {
String tagName = property.getKey();
String tagValue = (String) value;
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", ATT_PROPERTY_NAME, ATT_PROPERTY_NAME, null, tagName);
handler.startElement("", TAG_PROPERTY, TAG_PROPERTY, attributes);
handler.characters(tagValue.toCharArray(), 0, tagValue.length());
handler.endElement("", TAG_PROPERTY, TAG_PROPERTY);
} else {
// TODO multi-valued properties, other primitives
System.err.println("Can't yet handle property " + property.getKey() + " of type " + value.getClass());
}
}
endElement(handler, TAG_RESOURCE);
handler.endDocument();
// TODO - also add the serialization type
return new SerializationData(resource.getPath(), CONTENT_XML, result.toByteArray(), null);
} catch (TransformerConfigurationException | TransformerFactoryConfigurationError | SAXException e) {
// TODO proper exception handling
throw new RuntimeException(e);
}
}
use of javax.xml.transform.TransformerFactoryConfigurationError in project ddf by codice.
the class AbstractFeatureConverterWfs20 method readGml.
protected Object readGml(String xml) {
LOGGER.debug("readGml() input XML: {}", xml);
//Add namespace into XML for processing
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
try {
dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (ParserConfigurationException e) {
LOGGER.debug("Unable to configure features on document builder.", e);
}
DocumentBuilder dBuilder = null;
Document doc = null;
Object gml = null;
InputStream xmlIs = null;
//Check if GML 3.2.1 namespace exist on XML chunk
try {
dBuilder = dbFactory.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = dBuilder.parse(is);
} catch (ParserConfigurationException | SAXException | IOException e) {
LOGGER.debug(XML_PARSE_FAILURE);
}
if (null != doc) {
String[] namePrefix = doc.getDocumentElement().getNodeName().split(":");
String prefix = "";
if (namePrefix.length < 2) {
LOGGER.debug("Incoming XML has no GML prefix");
} else {
prefix = ":" + namePrefix[0];
}
String xmlNs = doc.getDocumentElement().getAttribute("xmlns" + prefix);
if (xmlNs.equals(Wfs20Constants.GML_3_2_NAMESPACE)) {
LOGGER.debug("Namespace already exists.");
} else {
doc.createElementNS(Wfs20Constants.GML_3_2_NAMESPACE, doc.getDocumentElement().getNodeName());
}
//Convert DOM to InputStream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(doc);
Result outputTarget = new StreamResult(outputStream);
try {
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
} catch (TransformerException | TransformerFactoryConfigurationError e) {
LOGGER.debug(CREATE_TRANSFORMER_FAILURE);
}
xmlIs = new ByteArrayInputStream(outputStream.toByteArray());
//Parse XML into a Geometry object
Configuration configurationG = new org.geotools.gml3.v3_2.GMLConfiguration();
Parser parser = new org.geotools.xml.Parser(configurationG);
parser.setStrict(false);
parser.setValidating(false);
parser.setFailOnValidationError(false);
parser.setForceParserDelegate(false);
try {
gml = parser.parse(xmlIs);
} catch (IOException | SAXException | ParserConfigurationException e) {
LOGGER.debug("{} {}", GML_FAILURE, xml);
}
}
return gml;
}
use of javax.xml.transform.TransformerFactoryConfigurationError in project che by eclipse.
the class History method save.
public synchronized void save() {
IPath stateLocation = JavaPlugin.getDefault().getStateLocation().append(fFileName);
File file = stateLocation.toFile();
OutputStream out = null;
try {
out = new FileOutputStream(file);
save(out);
} catch (IOException e) {
JavaPlugin.log(e);
} catch (CoreException e) {
JavaPlugin.log(e);
} catch (TransformerFactoryConfigurationError e) {
// The XML library can be misconficgured (e.g. via
// -Djava.endorsed.dirs=C:\notExisting\xerces-2_7_1)
JavaPlugin.log(e);
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
JavaPlugin.log(e);
}
}
}
Aggregations