use of org.dom4j.io.OutputFormat in project atlas by alibaba.
the class ManifestFileUtils method minifyManifest.
public static void minifyManifest(File mainManifest, File destManifest) throws IOException, DocumentException {
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(destManifest);
if (mainManifest.exists()) {
try {
// 读取XML文件
Document document = reader.read(mainManifest);
// removeComments(document);
Element element = document.getRootElement();
element.clearContent();
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
use of org.dom4j.io.OutputFormat in project tdi-studio-se by Talend.
the class JobJavaScriptsWSManager method editWSDDFile.
/**
* DOC x Comment method "genWebInfoForder".
*
* @param list
*/
private void editWSDDFile(ProcessItem processItem) {
String projectName = getCorrespondingProjectName(processItem);
String selectedProcessVersion = processItem.getProperty().getVersion();
if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
selectedProcessVersion = this.getSelectedJobVersion();
}
String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), selectedProcessVersion);
String deployFileName = getTmpFolder() + PATH_SEPARATOR + projectName + PATH_SEPARATOR + jobFolderName + PATH_SEPARATOR + //$NON-NLS-1$
"deploy.wsdd";
//$NON-NLS-1$
String serverConfigFile = getTmpFolder() + PATH_SEPARATOR + "server-config.wsdd";
File deployFile = new File(deployFileName);
if (!deployFile.exists()) {
//$NON-NLS-1$
log.error(org.talend.repository.i18n.Messages.getString("JobJavaScriptsWSManager.errorMessage"));
return;
}
// edit the server-config.wsdd file
try {
File wsddFile = new File(serverConfigFile);
BufferedReader reader = new BufferedReader(new FileReader(wsddFile));
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(reader);
BufferedReader wsdlreader = new BufferedReader(new FileReader(deployFile));
SAXReader wsdlsaxReader = new SAXReader();
Document wsdldoc = wsdlsaxReader.read(wsdlreader);
Element wsdlroot = wsdldoc.getRootElement();
//$NON-NLS-1$
Element element = wsdlroot.element("service");
//$NON-NLS-1$
List<Element> elements = element.elements("arrayMapping");
for (Element item : elements) {
//$NON-NLS-1$
Attribute attribute = item.attribute("qname");
item.remove(attribute);
//$NON-NLS-1$ //$NON-NLS-2$
attribute.setValue(attribute.getValue().replaceFirst(">", ""));
item.add(attribute);
}
Element root = doc.getRootElement();
List<Node> content = root.content();
for (int i = 0; i < content.size(); i++) {
Node n = content.get(i);
if (n instanceof Element) {
if (n.getName().equals("transport")) {
//$NON-NLS-1$
content.add(i - 1, element);
break;
}
}
}
//$NON-NLS-1$
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serverConfigFile), "UTF-8"));
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter output = new XMLWriter(writer, format);
output.write(doc);
output.flush();
output.close();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.dom4j.io.OutputFormat in project tdi-studio-se by Talend.
the class ComponentFolderManager method writeXMLContent.
/**
* DOC slanglois Comment method "writeXMLContent".
*
* @param iFile
* @param document
* @param enCode
* @throws CoreException
*/
private void writeXMLContent(IFile iFile, Document document, String enCode) throws CoreException {
PrintWriter pw = null;
XMLWriter writer = null;
byte[] byteArray = null;
// get xml content as inputstream
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = tf.newTransformer();
} catch (TransformerConfigurationException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
DOMSource source = new DOMSource(document);
transformer.setOutputProperty(OutputKeys.ENCODING, enCode);
//$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
ByteArrayOutputStream sw = new ByteArrayOutputStream();
pw = new PrintWriter(sw);
StreamResult result = new StreamResult(pw);
try {
transformer.transform(source, result);
} catch (TransformerException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
try {
sw.flush();
} catch (IOException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
} finally {
if (pw != null) {
pw.close();
}
}
byteArray = sw.toByteArray();
// format the xml content
SAXReader saxReader = new SAXReader();
org.dom4j.Document dom4jDocument = null;
try {
dom4jDocument = saxReader.read(new ByteArrayInputStream(byteArray));
} catch (DocumentException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
/** format the output like the webBrowser */
OutputFormat format = OutputFormat.createPrettyPrint();
/** give the xml encoding */
format.setEncoding(enCode);
sw = new ByteArrayOutputStream();
try {
writer = new XMLWriter(sw, format);
} catch (UnsupportedEncodingException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
try {
writer.write(dom4jDocument);
writer.flush();
} catch (IOException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// e.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
}
}
}
byteArray = sw.toByteArray();
// write content
iFile.setContents(new ByteArrayInputStream(byteArray), true, false, null);
}
use of org.dom4j.io.OutputFormat in project cuba by cuba-platform.
the class Dom4j method writeDocument.
public static void writeDocument(Document doc, boolean prettyPrint, Writer writer) {
XMLWriter xmlWriter;
try {
if (prettyPrint) {
OutputFormat format = OutputFormat.createPrettyPrint();
xmlWriter = new XMLWriter(writer, format);
} else {
xmlWriter = new XMLWriter(writer);
}
xmlWriter.write(doc);
} catch (IOException e) {
throw new RuntimeException("Unable to write XML", e);
}
}
use of org.dom4j.io.OutputFormat in project cuba by cuba-platform.
the class Dom4j method writeDocument.
public static void writeDocument(Document doc, boolean prettyPrint, OutputStream stream) {
XMLWriter xmlWriter;
try {
if (prettyPrint) {
OutputFormat format = OutputFormat.createPrettyPrint();
xmlWriter = new XMLWriter(stream, format);
} else {
xmlWriter = new XMLWriter(stream);
}
xmlWriter.write(doc);
} catch (IOException e) {
throw new RuntimeException("Unable to write XML", e);
}
}
Aggregations