use of javax.xml.transform.sax.TransformerHandler in project knime-core by knime.
the class WorkflowSetMetaInfoEditor method doSave.
/**
* {@inheritDoc}
*/
@Override
public void doSave(final IProgressMonitor monitor) {
try {
URI path = ((IURIEditorInput) getEditorInput()).getURI();
File inputFile = new File(path);
SAXTransformerFactory fac = (SAXTransformerFactory) TransformerFactory.newInstance();
TransformerHandler handler = fac.newTransformerHandler();
Transformer t = handler.getTransformer();
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.INDENT, "yes");
OutputStream out = new FileOutputStream(inputFile);
handler.setResult(new StreamResult(out));
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(null, null, "nrOfElements", "CDATA", "" + m_elements.size());
handler.startElement(null, null, "KNIMEMetaInfo", atts);
monitor.beginTask("Saving meta information...", m_elements.size());
for (MetaGUIElement element : m_elements) {
element.saveTo(handler);
monitor.worked(1);
}
handler.endElement(null, null, "KNIMEMetaInfo");
handler.endDocument();
out.close();
setDirty(false);
} catch (Exception e) {
LOGGER.error("An error ocurred while saving " + getEditorInput().toString(), e);
} finally {
monitor.done();
}
}
Aggregations