List of usage examples for org.dom4j.io XMLWriter setMaximumAllowedCharacter
public void setMaximumAllowedCharacter(int maximumAllowedCharacter)
From source file:com.tedi.engine.XMLOutput.java
License:Open Source License
/** * Handles functionality of formatting and writing document. * /*from w ww . ja va 2 s . co m*/ * @param doc * The document * @return the cleaned document. * @throws Exception */ private String cleanDocument(Document doc) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Cleaning the document object."); } String docStr = ""; // --COMMENTED OUT 10-10-2005 // JBG---------------------------------------------------------------------------------- // if (dtd != null && dtd.length()>0) { // xmlUtils.setDocument(doc); // try { // AbstractSchemaDescriptor schema = // AbstractSchemaDescriptor.createDescriptor(absoluteDTD_URL.toString()); // schema.processSchema(doc.getRootElement().getName()); // xmlUtils.setSchema(schema); // xmlUtils.cleanDocument(); // } // catch (Exception e) { // execResults.addMessage(ExecutionResults.M_WARNING, // ExecutionResults.J2EE_TARGET_ERR, // "Error removing optional attributes/elements: " + e.getMessage()); // } // } // ---------------------------------------------------------------------------------------------------------------- cleanElement(doc.getRootElement()); StringWriter sw = new StringWriter(); OutputFormat format = isCompact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(false); XMLWriter writer = new XMLWriter(sw, format); writer.setMaximumAllowedCharacter(127); writer.write(doc); writer.close(); docStr = sw.toString(); if (isSuppressDocType && doc.getDocType() != null) { int ndx = docStr.indexOf("<" + doc.getRootElement().getName()); docStr = docStr.substring(ndx); } return docStr; }
From source file:org.talend.core.model.genhtml.XMLHandler.java
License:Open Source License
/** * Generates xml file base on inputted path, file path and an instance of <code>Document</code> * /*www. j a v a 2 s . c om*/ * @param tempFolderPath * @param filePath * @param document */ public static void generateXMLFile(String tempFolderPath, String filePath, Document document) { XMLWriter output = null; FileOutputStream out = null; Writer writer = null; try { // OutputFormat format = OutputFormat.createPrettyPrint(); out = new java.io.FileOutputStream(filePath); writer = new OutputStreamWriter(out, "UTF-8"); //$NON-NLS-1$ OutputFormat format = OutputFormat.createPrettyPrint(); output = new XMLWriter(writer, format) { /* * (non-Javadoc) * * @see org.dom4j.io.XMLWriter#writeDeclaration() */ @Override protected void writeDeclaration() throws IOException { OutputFormat formatTmp = this.getOutputFormat(); String encoding = formatTmp.getEncoding(); // Only print of declaration is not suppressed if (!formatTmp.isSuppressDeclaration()) { // Assume 1.0 version if (encoding.equals("UTF8")) { //$NON-NLS-1$ writer.write("<?xml version=\"1.1\""); //$NON-NLS-1$ if (!formatTmp.isOmitEncoding()) { writer.write(" encoding=\"UTF-8\""); //$NON-NLS-1$ } writer.write("?>"); //$NON-NLS-1$ } else { writer.write("<?xml version=\"1.1\""); //$NON-NLS-1$ if (!formatTmp.isOmitEncoding()) { writer.write(" encoding=\"" + encoding + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } writer.write("?>"); //$NON-NLS-1$ } if (formatTmp.isNewLineAfterDeclaration()) { println(); } } } }; output.setMaximumAllowedCharacter(127); output.write(document); output.flush(); } catch (Exception e) { ExceptionHandler.process(e); } finally { if (output != null) { try { output.close(); } catch (Exception e) { ExceptionHandler.process(e); } } if (writer != null) { try { writer.close(); } catch (Exception e) { ExceptionHandler.process(e); } } if (out != null) { try { out.close(); } catch (Exception e) { ExceptionHandler.process(e); } } } }