/** * Send Xml response body. * * @param serializable * @param status * @throws IOException * @see DavServletResponse#sendXmlResponse(XmlSerializable, int); */ public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException { httpResponse.setStatus(status); if (serializable != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Document doc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", false); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); byte[] bytes = out.toByteArray(); httpResponse.setContentType("text/xml; charset=UTF-8"); httpResponse.setContentLength(bytes.length); httpResponse.getOutputStream().write(bytes); } catch (ParserConfigurationException e) { log.error(e.getMessage()); throw new IOException(e.getMessage()); } } }
/** * Encodes an object. * <p> * An object is encoded as an object, name pair, where the name is the name * of an element declaration in a schema. * </p> * @param object The object being encoded. * @param name The name of the element being encoded in the schema. * @param out The output stream. * * @throws IOException * @throws SAXException */ public void encode( Object object, QName name, OutputStream out ) throws IOException, SAXException { //create the document seriaizer XMLSerializer xmls = new XMLSerializer( out, outputFormat ); xmls.setNamespaces(namespaceAware); encode(object, name, xmls); }
public static String serialize(XmlSerializable serializable) throws IOException { StringWriter out = new StringWriter(); try { Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); return out.toString(); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } } }
public static String serialize(XmlSerializable serializable) throws IOException { StringWriter out = new StringWriter(); try { Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); return out.toString(); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } } }
/** * Serialize the encapsulated Document into the Writer * * @param writer writer * * @throws IOException When serialization fails */ public void serialize(Writer writer) throws IOException { Serializer genericSerializer = factory.makeSerializer(writer, format); org.apache.xml.serialize.XMLSerializer domSerializer = (org.apache.xml.serialize.XMLSerializer) genericSerializer.asDOMSerializer(); domSerializer.setNamespaces(true); domSerializer.serialize(doc); } }
xmls.setNamespaces(namespaceAware); try { encode(object, name, xmls);
/** * Encodes the internal object representation of a parameter as a string. */ public void encode( Object value, OutputStream os) throws Exception { // create the document serializer XMLSerializer serializer = new XMLSerializer(os, new OutputFormat()); serializer.setNamespaces(true); // cascade on the other encode method encode(value, serializer); }
serializer.setNamespaces(namespaceAware); serializer.startDocument();
XMLEncoderDelegate delegate = (XMLEncoderDelegate) rawResult; XMLSerializer xmls = new XMLSerializer(output, new OutputFormat()); xmls.setNamespaces(true);