public String getAsXML() { // following lines uses the old JDOM jar // xmlOutputter.setIndent(true); // xmlOutputter.setIndent(" "); // xmlOutputter.setNewlines(true); // xmlOutputter.setExpandEmptyElements(false); // xmlOutputter.setOmitEncoding(true); // xmlOutputter.setOmitDeclaration(true); // xmlOutputter.setTextNormalize(true); final Format prettyFormat = Format.getPrettyFormat(); prettyFormat.setExpandEmptyElements(false); prettyFormat.setOmitEncoding(true); prettyFormat.setOmitDeclaration(true); prettyFormat.setTextMode(Format.TextMode.NORMALIZE); final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat); return xmlOutputter.outputString(createRootTree("class name list template")); }
/** * Creates a single String out of the Document document * * @param document * @param encoding The character encoding to use. If null, a standard utf-8 encoding will be used * @return */ public static String getStringFromDocument(Document document, String encoding) { if (document == null) { logger.warn("Trying to convert null document to String. Aborting"); return null; } if (encoding == null) encoding = CommonUtils.encoding; XMLOutputter outputter = new XMLOutputter(); Format xmlFormat = outputter.getFormat(); if (!(encoding == null) && !encoding.isEmpty()) xmlFormat.setEncoding(encoding); // xmlFormat.setOmitDeclaration(true); xmlFormat.setExpandEmptyElements(true); outputter.setFormat(xmlFormat); String docString = outputter.outputString(document); return docString; }
/** {@inheritDoc} */ public String getString() throws IOException { Element rootElement = m_document.getRootElement(); processChildren(rootElement); m_document.setContext(m_context); XMLOutputter output = new XMLOutputter(); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements(false); fmt.setLineSeparator(LINEBREAK); output.setFormat(fmt); output.outputElementContent(m_document.getRootElement(), out); return out.toString(); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Document doc = (Document) _doc.clone(); String profileName = request.getParameter("profile"); if (profileName == null || profileName.length() < 1) { // default to jbpm profileName = "jbpm"; } IDiagramProfile profile = _profileService.findProfile(request, profileName); if (profile == null) { _logger.error("No profile with the name " + profileName + " was registered"); throw new IllegalArgumentException( "No profile with the name " + profileName + " was registered"); } IDiagramPreprocessingUnit preprocessingUnit = null; if (_preProcess) { if (_logger.isInfoEnabled()) { _logger.info("Performing diagram information pre-processing steps. "); } preprocessingUnit = _preProcessingService.findPreprocessingUnit(request, profile); preprocessingUnit.preprocess(request, response, profile); } // output env javascript files if (_devMode) { for (String jsFile : _envFiles) { addScript(doc, oryx_path + jsFile, true); } } else { addScript(doc, oryx_path + "jsc/env_combined.js", true); } // generate script tags for plugins. // they are located after the initialization script. if (_pluginfiles.get(profileName) == null) { List<IDiagramPlugin> compressed = new ArrayList<IDiagramPlugin>(); List<IDiagramPlugin> uncompressed = new ArrayList<IDiagramPlugin>(); _pluginfiles.put(profileName, compressed); _uncompressedPlugins.put(profileName, uncompressed); for (String pluginName : profile.getPlugins()) { IDiagramPlugin plugin = _pluginService.findPlugin(request, pluginName); if (plugin == null) { _logger.warn( "Could not find the plugin " + pluginName + " requested by the profile " + profile.getName()); continue; } if (plugin.isCompressable()) { compressed.add(plugin); } else { uncompressed.add(plugin); } } if (!_devMode) { // let's call the compression routine String rs = compressJS(_pluginfiles.get(profileName), getServletContext()); try { FileWriter w = new FileWriter(getServletContext().getRealPath("jsc/plugins_" + profileName + ".js")); w.write(rs.toString()); w.close(); } catch (Exception e) { _logger.error(e.getMessage(), e); } } } if (_devMode) { for (IDiagramPlugin jsFile : _pluginfiles.get(profileName)) { addScript(doc, oryx_path + "plugin/" + jsFile.getName() + ".js", true); } } else { addScript(doc, oryx_path + "jsc/plugins_" + profileName + ".js", false); } for (IDiagramPlugin uncompressed : _uncompressedPlugins.get(profileName)) { addScript(doc, oryx_path + "plugin/" + uncompressed.getName() + ".js", false); } // send the updated editor.html to client if (!isIE(request)) { response.setContentType("application/xhtml+xml"); } XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setExpandEmptyElements(true); outputter.setFormat(format); String html = outputter.outputString(doc); StringTokenizer tokenizer = new StringTokenizer(html, "@", true); StringBuilder resultHtml = new StringBuilder(); boolean tokenFound = false; boolean replacementMade = false; IDiagramPreference pref = PREFERENCE_FACTORY.createPreference(request); int autoSaveInt = pref.getAutosaveInterval(); boolean autoSaveOn = pref.isAutoSaveEnabled(); while (tokenizer.hasMoreTokens()) { String elt = tokenizer.nextToken(); if ("title".equals(elt)) { resultHtml.append(profile.getTitle()); replacementMade = true; } else if ("stencilset".equals(elt)) { resultHtml.append(profile.getStencilSet()); replacementMade = true; } else if ("debug".equals(elt)) { resultHtml.append(_devMode); replacementMade = true; } else if ("autosaveinterval".equals(elt)) { resultHtml.append(autoSaveInt); replacementMade = true; } else if ("autosavedefault".equals(elt)) { resultHtml.append(autoSaveOn); replacementMade = true; } else if ("preprocessing".equals(elt)) { resultHtml.append(preprocessingUnit == null ? "" : preprocessingUnit.getOutData()); replacementMade = true; } else if ("externalprotocol".equals(elt)) { resultHtml.append(ExternalInfo.getExternalProtocol(profile)); replacementMade = true; } else if ("externalhost".equals(elt)) { resultHtml.append(ExternalInfo.getExternalHost(profile)); replacementMade = true; } else if ("externalsubdomain".equals(elt)) { resultHtml.append( profile .getExternalLoadURLSubdomain() .substring(0, profile.getExternalLoadURLSubdomain().indexOf("/"))); replacementMade = true; } else if ("designerversion".equals(elt)) { resultHtml.append(_designerVersion); replacementMade = true; } else if ("profileplugins".equals(elt)) { StringBuilder plugins = new StringBuilder(); boolean commaNeeded = false; for (String ext : profile.getPlugins()) { if (commaNeeded) { plugins.append(","); } else { commaNeeded = true; } plugins.append("\"").append(ext).append("\""); } resultHtml.append(plugins.toString()); replacementMade = true; } else if ("ssextensions".equals(elt)) { StringBuilder ssexts = new StringBuilder(); boolean commaNeeded = false; for (String ext : profile.getStencilSetExtensions()) { if (commaNeeded) { ssexts.append(","); } else { commaNeeded = true; } ssexts.append("\"").append(ext).append("\""); } resultHtml.append(ssexts.toString()); replacementMade = true; } else if ("@".equals(elt)) { if (replacementMade) { tokenFound = false; replacementMade = false; } else { tokenFound = true; } } else { if (tokenFound) { tokenFound = false; resultHtml.append("@"); } resultHtml.append(elt); } } response.getWriter().write(resultHtml.toString()); }