public static Document createDocument(String rootElementTagName) { Document document = createDocument(); Element rootElement = document.createElement(rootElementTagName); document.appendChild(rootElement); return document; }
public static Element addBlockElement(Element formElement) { return DomUtils.appendNewElement(formElement, BLOCK_ELEMENT); }
public static void createScript(Element parent, String script) { Element scriptElement = DomUtils.appendNewElement(parent, SCRIPT_ELEMENT); DomUtils.appendNewText(scriptElement, script); }
public static String writeToString(Node node) throws IOException { LSSerializer xmlSerializer = getSerializer(); StringWriter stringWriter = new StringWriter(); LSOutput destination = DOM_IMPLEMENTATION.createLSOutput(); destination.setCharacterStream(stringWriter); try { xmlSerializer.write(node, destination); } catch (LSException exception) { throw new IOException("Error while writing document to output stream.", exception); } return stringWriter.toString(); }
public XmlDocumentServletResponseContent(Document document, String contentType) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); writeToOutputStream(document, byteArrayOutputStream, Encoding.UTF_8); mContent = byteArrayOutputStream.toByteArray(); mContentType = contentType; }
public static void addXmlNodeProperty(JsonObjectBuilder builder, String propertName, String item, Node node) { try { builder.add(propertName, DomUtils.writeToString(node)); } catch (IOException exception) { builder.add(propertName, "Exception occurred during serialization of " + item + ": " + StringUtils.getAllMessages(exception)); } }
public static void renderInlineStringGrammar(Element grammarElement, InlineStringGrammar inlineStringGrammar) { DomUtils.appendNewCData(grammarElement, inlineStringGrammar.getSource()); setAttribute(grammarElement, BASE_ATTRIBUTE, inlineStringGrammar.getBase()); setAttribute(grammarElement, XML_LANGUAGE_ATTRIBUTE, inlineStringGrammar.getLanguage()); setAttribute(grammarElement, ROOT_ATTRIBUTE, inlineStringGrammar.getRoot()); setAttribute(grammarElement, TAG_FORMAT_ATTRIBUTE, inlineStringGrammar.getTagFormat()); setAttribute(grammarElement, VERSION_ATTRIBUTE, inlineStringGrammar.getVersion()); }
public static void writeToOutputStream(Node node, OutputStream outputStream, Encoding encoding) throws IOException { LSSerializer xmlSerializer = getSerializer(); LSOutput destination = DOM_IMPLEMENTATION.createLSOutput(); destination.setByteStream(outputStream); destination.setEncoding(encoding.getId()); try { xmlSerializer.write(node, destination); } catch (LSException exception) { throw new IOException("Error while writing document to output stream.", exception); } }
private void processRootDocument(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Document rootDocument = mRootDocumentFactory.getDocument(request); response.setContentType(VOICE_XML_CONTENT_TYPE); DomUtils.writeToOutputStream(rootDocument, response.getOutputStream(), Encoding.UTF_8); } catch (VoiceXmlDocumentRenderingException exception) { throw new ServletException("Error while rendering root document.", exception); } }
public static void createGotoSubmit(Element parent) { Element gotoElement = DomUtils.appendNewElement(parent, GOTO_ELEMENT); gotoElement.setAttribute(NEXT_ATTRIBUTE, "#" + SUBMIT_FORM_ID); }
@Override protected void fillVoiceXmlDocument(Document document, Element formElement, VoiceXmlDialogueContext dialogueContext) throws VoiceXmlDocumentRenderingException { addVariables(formElement, mVariables); Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT); if (mCode != null) { Element scriptElement = DomUtils.appendNewElement(blockElement, SCRIPT_ELEMENT); DomUtils.appendNewText(scriptElement, mCode); } StringBuffer scriptBuffer = new StringBuffer(); scriptBuffer.append(RIVR_SCOPE_OBJECT + ".addValueResult({"); boolean first = true; for (Entry<String, String> entry : mVariables) { if (!first) { scriptBuffer.append(", "); } else { first = false; } scriptBuffer.append("\""); scriptBuffer.append(entry.getKey()); scriptBuffer.append("\": "); scriptBuffer.append("dialog."); scriptBuffer.append(entry.getKey()); } scriptBuffer.append("});"); createScript(blockElement, scriptBuffer.toString()); createGotoSubmit(blockElement); }
public static Element createVoiceXmlDocumentRoot(String language) { Document document = DomUtils.createDocument(VXML_ELEMENT); Element vxmlElement = document.getDocumentElement(); vxmlElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, VOICEXML_NAMESPACE); vxmlElement.setAttribute(VERSION_ATTRIBUTE, "2.1"); setAttribute(vxmlElement, XML_LANGUAGE_ATTRIBUTE, language); return vxmlElement; }
public static void createGotoFatalHandler(Element parent) { Element gotoElement = DomUtils.appendNewElement(parent, GOTO_ELEMENT); gotoElement.setAttribute(NEXT_ATTRIBUTE, "#" + FATAL_ERROR_HANDLER_FORM_ID); }
if (audioItem instanceof AudioFile) { AudioFile audioFile = (AudioFile) audioItem; Element audioElement = DomUtils.appendNewElement(promptElement, AUDIO_ELEMENT); lastItemWasText = false; } else { DomUtils.appendNewText(audioElement, alternate.getText()); lastItemWasText = true; } else { String spaceIfRequired = lastItemWasText ? " " : ""; DomUtils.appendNewText(promptElement, spaceIfRequired + speechSynthesis.getText()); lastItemWasText = true; Element breakElement = DomUtils.appendNewElement(promptElement, BREAK_ELEMENT); setDurationAttribute(breakElement, TIME_ATTRIBUTE, pause.getDuration()); lastItemWasText = false; } else if (audioItem instanceof Mark) { Mark mark = (Mark) audioItem; Element markElement = DomUtils.appendNewElement(promptElement, MARK_ELEMENT); markElement.setAttribute(NAME_ATTRIBUTE, mark.getName()); lastItemWasText = false;
public static void createAssignation(Element parent, String variableName, String expression) { Element assingElement = DomUtils.appendNewElement(parent, ASSIGN_ELEMENT); assingElement.setAttribute(NAME_ATTRIBUTE, variableName); assingElement.setAttribute(EXPR_ATTRIBUTE, expression); }
public static Element createForm(Document document) { Element vxmlElement = document.getDocumentElement(); Element formElement = DomUtils.appendNewElement(vxmlElement, FORM_ELEMENT); formElement.setAttribute(ID_ATTRIBUTE, FORM_ID); return formElement; }
public static void createVarElement(Element parent, String name, String expr) { Element varElement = DomUtils.appendNewElement(parent, VAR_ELEMENT); varElement.setAttribute(NAME_ATTRIBUTE, name); if (expr != null) { setAttribute(varElement, EXPR_ATTRIBUTE, expr); } }
public static void addProperty(Element parent, String propertyName, String propertyValue) { Assert.notNull(propertyName, "propertyName"); if (propertyValue != null) { Element propertyElement = DomUtils.appendNewElement(parent, PROPERTY_ELEMENT); propertyElement.setAttribute(NAME_ATTRIBUTE, propertyName); propertyElement.setAttribute(VALUE_ELEMENT, propertyValue); } }
@Override protected void fillVoiceXmlDocument(Document document, Element formElement, VoiceXmlDialogueContext dialogueContext) throws VoiceXmlDocumentRenderingException { Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT); Element submitElement = DomUtils.appendNewElement(blockElement, SUBMIT_ELEMENT); VoiceXmlDomUtil.setAttribute(submitElement, VoiceXmlDomUtil.NEXT_ATTRIBUTE, mUri); if (mFetchConfiguration != null) { VoiceXmlDomUtil.applyDocumentFetchConfiguration(submitElement, dialogueContext); } }
@Override protected void fillVoiceXmlDocument(Document document, Element formElement, VoiceXmlDialogueContext dialogueContext) throws VoiceXmlDocumentRenderingException { Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT); Element exitElement = document.createElement(EXIT_ELEMENT); if (mVariables != null) { addNamelist(blockElement, exitElement, mVariables); } else if (mExpression != null) { exitElement.setAttribute(EXPR_ATTRIBUTE, mExpression); } blockElement.appendChild(exitElement); }