/** * @param node a node * @return the xml representation according to the setting of this serializer * @throws IOException in case of problem saving resources */ public String asXml(final DomElement node) throws IOException { builder_.setLength(0); indent_.setLength(0); final SgmlPage page = node.getPage(); if (null != page && page.isHtmlPage()) { final Charset charsetName = page.getCharset(); if (charsetName != null && node instanceof HtmlHtml) { builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } } printXml(node); final String response = builder_.toString(); builder_.setLength(0); return response; }
/** * Converts an HTML element to XML. * @param node a node * @return the text representation according to the setting of this serializer */ public String asXml(final HtmlElement node) { buffer_.setLength(0); indent_.setLength(0); String charsetName = null; if (node.getPage() instanceof HtmlPage) { charsetName = node.getPage().getPageEncoding(); } if (charsetName != null && node instanceof HtmlHtml) { buffer_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } printXml(node); final String response = buffer_.toString(); buffer_.setLength(0); return response; }
/** * @param node a node * @return the xml representation according to the setting of this serializer * @throws IOException in case of problem saving resources */ public String asXml(final DomElement node) throws IOException { builder_.setLength(0); indent_.setLength(0); final SgmlPage page = node.getPage(); if (null != page && page.isHtmlPage()) { final Charset charsetName = page.getCharset(); if (charsetName != null && node instanceof HtmlHtml) { builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } } printXml(node); final String response = builder_.toString(); builder_.setLength(0); return response; }
/** * Converts an HTML element to XML. * @param node a node * @return the text representation according to the setting of this serializer */ public String asXml(final HtmlElement node) { buffer_.setLength(0); indent_.setLength(0); String charsetName = null; if (node.getPage() instanceof HtmlPage) { charsetName = node.getPage().getPageEncoding(); } if (charsetName != null && node instanceof HtmlHtml) { buffer_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } printXml(node); final String response = buffer_.toString(); buffer_.setLength(0); return response; }
/** * Converts an HTML element to XML. * @param node a node * @return the text representation according to the setting of this serializer */ public String asXml(final HtmlElement node) { buffer_.setLength(0); indent_.setLength(0); String charsetName = null; if (node.getPage() instanceof HtmlPage) { charsetName = node.getPage().getPageEncoding(); } if (charsetName != null && node instanceof HtmlHtml) { buffer_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } printXml(node); final String response = buffer_.toString(); buffer_.setLength(0); return response; }
public void save(final SgmlPage page, final File file) throws IOException { String fileName = file.getName(); if (!fileName.endsWith(".htm") && !fileName.endsWith(".html")) { fileName += ".html"; } final File outputFile = new File(file.getParentFile(), fileName); if (outputFile.exists()) { throw new IOException("File already exists: " + outputFile); } fileName = fileName.substring(0, fileName.lastIndexOf('.')); outputDir_ = new File(file.getParentFile(), fileName); // don't use asXml here because we have to sync the encoding from the // header with the one used by the writer final DomElement node = page.getDocumentElement(); Charset charsetName = ISO_8859_1; builder_.setLength(0); indent_.setLength(0); if (page.isHtmlPage()) { charsetName = page.getCharset(); if (charsetName != null && node instanceof HtmlHtml) { builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } } printXml(node); final String response = builder_.toString(); builder_.setLength(0); FileUtils.writeStringToFile(outputFile, response, charsetName); }
protected void printXml(final DomElement node) throws IOException { if (!isExcluded(node)) { final boolean hasChildren = node.getFirstChild() != null; builder_.append(indent_).append('<'); printOpeningTag(node); if (!hasChildren && !node.isEmptyXmlTagExpanded()) { builder_.append("/>").append('\n'); } else { builder_.append('>').append('\n'); for (DomNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) { indent_.append(" "); if (child instanceof DomElement) { printXml((DomElement) child); } else { builder_.append(child); } indent_.setLength(indent_.length() - 2); } builder_.append(indent_).append("</").append(node.getTagName()).append('>').append('\n'); } } }
protected void printXml(final DomElement node) throws IOException { if (!isExcluded(node)) { final boolean hasChildren = node.getFirstChild() != null; builder_.append(indent_).append('<'); printOpeningTag(node); if (!hasChildren && !node.isEmptyXmlTagExpanded()) { builder_.append("/>").append('\n'); } else { builder_.append(">").append('\n'); for (DomNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) { indent_.append(" "); if (child instanceof DomElement) { printXml((DomElement) child); } else { builder_.append(child); } indent_.setLength(indent_.length() - 2); } builder_.append(indent_).append("</").append(node.getTagName()).append('>').append('\n'); } } }
protected void printXml(final DomElement node) { if (!isExcluded(node)) { final boolean hasChildren = node.getFirstChild() != null; buffer_.append(indent_).append('<'); printOpeningTag(node); if (!hasChildren && !isEmptyXmlTagExpanded(node)) { buffer_.append("/>").append('\n'); } else { buffer_.append(">").append('\n'); for (DomNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) { indent_.append(" "); if (child instanceof DomElement) { printXml((DomElement) child); } else { buffer_.append(child); } indent_.setLength(indent_.length() - 2); } buffer_.append(indent_).append("</").append(node.getTagName()).append('>').append('\n'); } } }
protected void printXml(final DomElement node) { if (!isExcluded(node)) { final boolean hasChildren = node.getFirstChild() != null; buffer_.append(indent_).append('<'); printOpeningTag(node); if (!hasChildren && !isEmptyXmlTagExpanded(node)) { buffer_.append("/>").append('\n'); } else { buffer_.append(">").append('\n'); for (DomNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) { indent_.append(" "); if (child instanceof DomElement) { printXml((DomElement) child); } else { buffer_.append(child); } indent_.setLength(indent_.length() - 2); } buffer_.append(indent_).append("</").append(node.getTagName()).append('>').append('\n'); } } }
protected void printXml(final DomElement node) { if (!isExcluded(node)) { final boolean hasChildren = node.getFirstChild() != null; buffer_.append(indent_).append('<'); printOpeningTag(node); if (!hasChildren && !isEmptyXmlTagExpanded(node)) { buffer_.append("/>").append('\n'); } else { buffer_.append(">").append('\n'); for (DomNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) { indent_.append(" "); if (child instanceof DomElement) { printXml((DomElement) child); } else { buffer_.append(child); } indent_.setLength(indent_.length() - 2); } buffer_.append(indent_).append("</").append(node.getTagName()).append('>').append('\n'); } } }