private static String serializeNode(final Node node, final String encoding, final boolean indent, final boolean omitXMLDeclaration) { SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(encoding!=null ? encoding : "UTF-8"); serializationOptions.setIndenting(indent); serializationOptions.setIncludingXMLDeclaration(!omitXMLDeclaration); return XMLUtilities.serializeNode(node, serializationOptions); }
boolean requiresXSLT20 = false; if (serializationOptions!=null) { if (serializationOptions.getSerializationMethod()==SerializationMethod.HTML) { else if (serializationOptions.getSerializationMethod()==SerializationMethod.STRICTLY_HTML) { if (serializationOptions.isUsingNamedEntities() && supportsXSLT20) { SerializationMethod serializationMethod = serializationOptions.getSerializationMethod(); if (serializationMethod==SerializationMethod.XHTML && !supportsXSLT20) { serializer.setOutputProperty(OutputKeys.INDENT, StringUtilities.toYesNo(serializationOptions.isIndenting())); if (serializationOptions.isIndenting()) { XMLUtilities.setIndentation(serializer, serializationOptions.getIndent()); serializer.setOutputProperty(OutputKeys.ENCODING, serializationOptions.getEncoding()); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, StringUtilities.toYesNo(!serializationOptions.isIncludingXMLDeclaration())); if (serializationOptions.getDoctypePublic()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, serializationOptions.getDoctypePublic()); if (serializationOptions.getDoctypeSystem()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, serializationOptions.getDoctypeSystem());
private void handle(DOMBuilder builder, Element parentElement, final ArgumentContainerToken content, final boolean isBlock) throws SnuggleParseException { /* Build children as normal */ builder.handleTokens(parentElement, content, true); /* Serialize child content to text and replace all children with this text inside * an appropriate container */ SerializationSpecifier options = new SerializationOptions(); options.setIndenting(isBlock); options.setEncoding("UTF-8"); String parentContentUnparsed = XMLUtilities.serializeNodeChildren(builder.getSessionContext().getStylesheetManager(), parentElement, options); NodeList childNodes = parentElement.getChildNodes(); for (int i=childNodes.getLength()-1; i>=0; i--) { parentElement.removeChild(childNodes.item(i)); } Element resultElement = builder.appendXHTMLTextElement(parentElement, isBlock ? "pre" : "span", parentContentUnparsed, true); resultElement.setAttribute("class", "unparsed-xml"); } }
protected LinkedHashMap<String, String> unwrapMathmlElement(final Element mathElement) { final LinkedHashMap<String, String> result = new LinkedHashMap<String, String>(); /* These options are used to serialize MathML that might get used, i.e. no entities */ final SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setIndenting(true); /* These options are used to serialize MathML that will only be displayed as source */ final SerializationSpecifier sourceOptions = new SerializationOptions(); sourceOptions.setIndenting(true); sourceOptions.setUsingNamedEntities(true); /* Isolate various annotations from the result */ final Document pmathSemanticDocument = MathMLUtilities.isolateFirstSemanticsBranch(mathElement); final Document pmathBracketedDocument = MathMLUtilities.isolateAnnotationXML(mathElement, MathMLUpConverter.BRACKETED_PRESENTATION_MATHML_ANNOTATION_NAME); final Document cmathDocument = MathMLUtilities.isolateAnnotationXML(mathElement, MathMLUpConverter.CONTENT_MATHML_ANNOTATION_NAME); final String maximaAnnotation = MathMLUtilities.extractAnnotationString(mathElement, MathMLUpConverter.MAXIMA_ANNOTATION_NAME); final Document contentFailuresAnnotation = MathMLUtilities.isolateAnnotationXML(mathElement, MathMLUpConverter.CONTENT_FAILURES_ANNOTATION_NAME); final Document maximaFailuresAnnotation = MathMLUtilities.isolateAnnotationXML(mathElement, MathMLUpConverter.MAXIMA_FAILURES_ANNOTATION_NAME); /* Build up result */ maybeAddResult(result, "pmathParallel", mathElement, sourceOptions); maybeAddResult(result, "pmathSemantic", pmathSemanticDocument, sourceOptions); maybeAddResult(result, "pmathBracketed", pmathBracketedDocument, serializationOptions); maybeAddResult(result, "cmath", cmathDocument, sourceOptions); maybeAddResult(result, "maxima", maximaAnnotation); maybeAddResult(result, "cmathFailures", contentFailuresAnnotation, sourceOptions); maybeAddResult(result, "maximaFailures", maximaFailuresAnnotation, sourceOptions); return result; }
boolean supportsXSLT20 = supportsXSLT20(); try { if (serializationOptions!=null && serializationOptions.isUsingNamedEntities() && supportsXSLT20) { SerializationMethod serializationMethod = serializationOptions.getSerializationMethod(); if (serializationMethod==SerializationMethod.XHTML && !supportsXSLT20) { serializer.setOutputProperty(OutputKeys.INDENT, StringUtilities.toYesNo(serializationOptions.isIndenting())); serializer.setOutputProperty(OutputKeys.ENCODING, serializationOptions.getEncoding()); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, StringUtilities.toYesNo(!serializationOptions.isIncludingXMLDeclaration())); if (serializationOptions.getDoctypePublic()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, serializationOptions.getDoctypePublic()); if (serializationOptions.getDoctypeSystem()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, serializationOptions.getDoctypeSystem());
private void handle(DOMBuilder builder, Element parentElement, final ArgumentContainerToken content, final boolean isBlock) throws SnuggleParseException { /* Build children as normal */ builder.handleTokens(parentElement, content, true); /* Serialize child content to text and replace all children with this text inside * an appropriate container */ SerializationSpecifier options = new SerializationOptions(); options.setIndenting(isBlock); options.setEncoding("UTF-8"); String parentContentUnparsed = XMLUtilities.serializeNodeChildren(builder.getSessionContext().getStylesheetManager(), parentElement, options); NodeList childNodes = parentElement.getChildNodes(); for (int i=childNodes.getLength()-1; i>=0; i--) { parentElement.removeChild(childNodes.item(i)); } Element resultElement = builder.appendXHTMLTextElement(parentElement, isBlock ? "pre" : "tt", parentContentUnparsed, true); resultElement.setAttribute("class", "unparsed-xml"); } }
boolean supportsXSLT20 = supportsXSLT20(); try { if (serializationOptions!=null && serializationOptions.isUsingNamedEntities() && supportsXSLT20) { SerializationMethod serializationMethod = serializationOptions.getSerializationMethod(); if (serializationMethod==SerializationMethod.XHTML && !supportsXSLT20) { serializer.setOutputProperty(OutputKeys.INDENT, StringUtilities.toYesNo(serializationOptions.isIndenting())); serializer.setOutputProperty(OutputKeys.ENCODING, serializationOptions.getEncoding()); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, StringUtilities.toYesNo(!serializationOptions.isIncludingXMLDeclaration())); if (serializationOptions.getDoctypePublic()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, serializationOptions.getDoctypePublic()); if (serializationOptions.getDoctypeSystem()!=null) { serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, serializationOptions.getDoctypeSystem());
private static String serializeNode(final Node node, final String encoding, final boolean indent, final boolean omitXMLDeclaration) { SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(encoding != null ? encoding : "UTF-8"); serializationOptions.setIndenting(indent); serializationOptions.setIncludingXMLDeclaration(!omitXMLDeclaration); return XMLUtilities.serializeNode(node, serializationOptions); }
/** * Convenience method to create a well-formed external general parsed entity out of the * currently parsed tokens. * <p> * The given {@link DOMOutputOptions} Object is used to configure the process. * * @param indent whether to indent the resulting XML or not * * @return resulting XML if the process completed successfully, null if the process was * terminated by an error in the input LaTeX and if the session was configured to fail on * the first error. * * @deprecated Use {@link #buildXMLString(XMLStringOutputOptions)} instead. */ @Deprecated public String buildXMLString(final DOMOutputOptions options, final boolean indent) { DocumentBuilder documentBuilder = XMLUtilities.createNSAwareDocumentBuilder(); Document document = documentBuilder.newDocument(); Element temporaryRoot = document.createElement("root"); document.appendChild(temporaryRoot); if (!buildDOMSubtree(temporaryRoot, options)) { return null; } SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(XMLStringOutputOptions.DEFAULT_ENCODING); serializationOptions.setIndenting(indent); return XMLUtilities.serializeNodeChildren(getStylesheetManager(), temporaryRoot, serializationOptions); }
private static String serializeNode(final Node node, final String encoding, final boolean indent, final boolean omitXMLDeclaration) { SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(encoding!=null ? encoding : "UTF-8"); serializationOptions.setIndenting(indent); serializationOptions.setIncludingXMLDeclaration(!omitXMLDeclaration); return XMLUtilities.serializeNode(node, serializationOptions); }
/** * Convenience method to create a well-formed external general parsed entity out of the * currently parsed tokens. * <p> * The given {@link DOMOutputOptions} Object is used to configure the process. * * @param indent whether to indent the resulting XML or not * * @return resulting XML if the process completed successfully, null if the process was * terminated by an error in the input LaTeX and if the session was configured to fail on * the first error. * * @deprecated Use {@link #buildXMLString(XMLStringOutputOptions)} instead. */ @Deprecated public String buildXMLString(final DOMOutputOptions options, final boolean indent) { DocumentBuilder documentBuilder = XMLUtilities.createNSAwareDocumentBuilder(); Document document = documentBuilder.newDocument(); Element temporaryRoot = document.createElement("root"); document.appendChild(temporaryRoot); if (!buildDOMSubtree(temporaryRoot, options)) { return null; } SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(XMLStringOutputOptions.DEFAULT_ENCODING); serializationOptions.setIndenting(indent); return XMLUtilities.serializeNodeChildren(getStylesheetManager(), temporaryRoot, serializationOptions); }
private void handle(DOMBuilder builder, Element parentElement, final ArgumentContainerToken content, final boolean isBlock) throws SnuggleParseException { /* Build children as normal */ builder.handleTokens(parentElement, content, true); /* Serialize child content to text and replace all children with this text inside * an appropriate container */ SerializationSpecifier options = new SerializationOptions(); options.setIndenting(isBlock); options.setEncoding("UTF-8"); String parentContentUnparsed = XMLUtilities.serializeNodeChildren(builder.getSessionContext().getStylesheetManager(), parentElement, options); NodeList childNodes = parentElement.getChildNodes(); for (int i=childNodes.getLength()-1; i>=0; i--) { parentElement.removeChild(childNodes.item(i)); } Element resultElement = builder.appendXHTMLTextElement(parentElement, isBlock ? "pre" : "tt", parentContentUnparsed, true); resultElement.setAttribute("class", "unparsed-xml"); } }
/** * Convenience method to create a well-formed external general parsed entity out of the * currently parsed tokens. * <p> * The given {@link DOMOutputOptions} Object is used to configure the process. * * @param indent whether to indent the resulting XML or not * * @return resulting XML if the process completed successfully, null if the process was * terminated by an error in the input LaTeX and if the session was configured to fail on * the first error. * * @deprecated Use {@link #buildXMLString(XMLStringOutputOptions)} instead. */ @Deprecated public String buildXMLString(final DOMOutputOptions options, final boolean indent) { DocumentBuilder documentBuilder = XMLUtilities.createNSAwareDocumentBuilder(); Document document = documentBuilder.newDocument(); Element temporaryRoot = document.createElement("root"); document.appendChild(temporaryRoot); if (!buildDOMSubtree(temporaryRoot, options)) { return null; } SerializationSpecifier serializationOptions = new SerializationOptions(); serializationOptions.setEncoding(XMLStringOutputOptions.DEFAULT_ENCODING); serializationOptions.setIndenting(indent); return XMLUtilities.serializeNodeChildren(getStylesheetManager(), temporaryRoot, serializationOptions); }