/** * Parse an XML string as DOM. */ public static Document fromString(String xml) { try { return fromInputStream( new ByteArrayInputStream(xml.getBytes("utf-8")), "utf-8" ); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Parses an InputStream as DOM. * @param in the inputstream to parse. * @param encoding the encoding of the input stream, if not null. * @return the parsed XML DOM. */ public static Document fromInputStream(InputStream in, String encoding) { InputSource is = new InputSource(in); if (encoding != null) { is.setEncoding(encoding); } return fromInputSource(is); }
return ByteString.fromString(Json.stringify((JsonNode) body)); } else if (body instanceof Document) { return XML.toBytes((Document) body); } else { Map<String, String[]> form = asFormUrlEncoded();
private static Document getXml(String response, String encoding) { try { InputSource source = new InputSource(new StringReader(response)); source.setEncoding(encoding); DocumentBuilder builder = XML.newDocumentBuilder(); return builder.parse(source); } catch (Exception e) { throw new RuntimeException(e); } }
public RenderXml(Document document) { this.xml = XML.serialize(document); }
public static DocumentBuilder newDocumentBuilder() { try { return newDocumentBuilderFactory().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
return ByteString.fromString(Json.stringify((JsonNode) body)); } else if (body instanceof Document) { return XML.toBytes((Document) body); } else { Map<String, String[]> form = asFormUrlEncoded();
/** * parse and get the response body as a {@link Document DOM document} * * @param encoding * xml charset encoding * @return a DOM document */ public Document getXml(String encoding) { try { InputSource source = new InputSource(new StringReader(getString())); source.setEncoding(encoding); DocumentBuilder builder = XML.newDocumentBuilder(); return builder.parse(source); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Parses an XML string as DOM. * * @param xml the input XML string * @return the parsed XML DOM root. */ public static Document fromString(String xml) { try { return fromInputStream( new ByteArrayInputStream(xml.getBytes("utf-8")), "utf-8" ); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Parses an InputStream as DOM. * @param in the inputstream to parse. * @param encoding the encoding of the input stream, if not null. * @return the parsed XML DOM. */ public static Document fromInputStream(InputStream in, String encoding) { InputSource is = new InputSource(in); if (encoding != null) { is.setEncoding(encoding); } return fromInputSource(is); }
return ByteString.fromString(Json.stringify((JsonNode) body)); } else if (body instanceof Document) { return XML.toBytes((Document) body); } else { Map<String, String[]> form = asFormUrlEncoded();
/** * Parse an XML string content to DOM * * @param xml * The XML string * @return null if an error occurs during parsing. */ public static Document getDocument(String xml) { InputSource source = new InputSource(new StringReader(xml)); try { return newDocumentBuilder().parse(source); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml data.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml data.", e); } return null; }
/** * Parses an XML string as DOM. * * @param xml the input XML string * @return the parsed XML DOM root. */ public static Document fromString(String xml) { try { return fromInputStream( new ByteArrayInputStream(xml.getBytes("utf-8")), "utf-8" ); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Parses an InputStream as DOM. * @param in the inputstream to parse. * @param encoding the encoding of the input stream, if not null. * @return the parsed XML DOM. */ public static Document fromInputStream(InputStream in, String encoding) { InputSource is = new InputSource(in); if (encoding != null) { is.setEncoding(encoding); } return fromInputSource(is); }
/** * Parse an XML coming from an input stream to DOM * * @param stream * The XML stream * @return null if an error occurs during parsing. */ public static Document getDocument(InputStream stream) { try { return newDocumentBuilder().parse(stream); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml data.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml data.", e); } return null; }
/** * Parses an XML string as DOM. * * @param xml the input XML string * @return the parsed XML DOM root. */ public static Document fromString(String xml) { try { return fromInputStream( new ByteArrayInputStream(xml.getBytes("utf-8")), "utf-8" ); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Set a XML to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/xml</tt>. * * @param xml the XML * @return the modified builder */ public RequestBuilder bodyXml(InputSource xml) { return bodyXml(XML.fromInputSource(xml)); }
/** * Parse an XML file to DOM * * @param file * The XML file * @return null if an error occurs during parsing. * */ public static Document getDocument(File file) { try { return newDocumentBuilder().parse(file); } catch (SAXException e) { Logger.warn("Parsing error when building Document object from xml file '" + file + "'.", e); } catch (IOException e) { Logger.warn("Reading error when building Document object from xml file '" + file + "'.", e); } return null; }
@Override protected Document parse(Http.RequestHeader request, ByteString bytes) throws Exception { return XML.fromInputStream(bytes.iterator().asInputStream(), request.charset().orElse(null)); } }
/** * Set a XML to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/xml</tt>. * * @param xml the XML * @return the modified builder */ public RequestBuilder bodyXml(InputSource xml) { return bodyXml(XML.fromInputSource(xml)); }