List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:com.hdsfed.cometapi.XMLHelper.java
public static XMLStreamWriter CreateTagListTuplet(XMLStreamWriter serializer, int i, String key, String value) throws XMLStreamException { if (value == null || key == null) return serializer; serializer.writeCharacters("\t"); serializer.writeStartElement("tag"); serializer.writeAttribute("id", String.valueOf(i)); serializer.writeCharacters("\n\t\t"); serializer = XMLHelper.CreateSimpleTagAndContent(serializer, "name", key); serializer.writeCharacters("\n\t\t"); serializer = XMLHelper.CreateSimpleTagAndContent(serializer, "value", value); serializer.writeCharacters("\n\t"); serializer.writeEndElement(); //end tag serializer.writeCharacters("\n"); return serializer; }
From source file:gdv.xport.util.HtmlFormatter.java
/** * Urspruenglich war diese Methode dazu gedacht, um Umlaute zu ersetzen. Das "Escaping" wird aber bereits vom * XMLStreamWriter uebernommen, der aber leider die Umlaute nicht ersetzt. Der Versuch, die Umlaute zu ersetzen, * endete leider mit "...Ü..." im erzeugten HTML. * * @param xmlStreamWriter/*from w w w .j av a 2 s . c o m*/ * the xml stream writer * @param feld * the feld * @throws XMLStreamException * the xML stream exception */ private static void writeInhaltTo(final XMLStreamWriter xmlStreamWriter, final Feld feld) throws XMLStreamException { String inhalt = feld.getInhalt(); xmlStreamWriter.writeCharacters(inhalt); }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeTagTo(final XMLStreamWriter xmlStreamWriter, final String tag, final String content) throws XMLStreamException { xmlStreamWriter.writeStartElement(tag); xmlStreamWriter.writeCharacters(content); xmlStreamWriter.writeEndElement();/*w ww . ja v a 2s .c o m*/ }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Satz satz, final int zeile) throws XMLStreamException { xmlStreamWriter.writeStartElement("h3"); xmlStreamWriter .writeCharacters("Satzart " + satz.getSatzart() + " (" + satz.getClass().getSimpleName() + ")"); xmlStreamWriter.writeEndElement();/* ww w . j a v a 2s . com*/ xmlStreamWriter.writeCharacters("\n"); int n = zeile; for (Iterator<Teildatensatz> iterator = satz.getTeildatensaetze().iterator(); iterator.hasNext();) { Teildatensatz teildatensatz = iterator.next(); writeDetailsTo(xmlStreamWriter, teildatensatz, n); n++; } xmlStreamWriter.flush(); }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Teildatensatz teildatensatz, final int zeile) throws XMLStreamException { xmlStreamWriter.writeStartElement("h4"); xmlStreamWriter .writeCharacters("Zeile " + zeile + ": Teildatensatz " + teildatensatz.getNummer().getInhalt()); xmlStreamWriter.writeEndElement();//from w ww . j av a 2s . c o m xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("table"); xmlStreamWriter.writeStartElement("thead"); xmlStreamWriter.writeStartElement("tr"); writeTagTo(xmlStreamWriter, "th", "Nr"); writeTagTo(xmlStreamWriter, "th", "Byte"); writeTagTo(xmlStreamWriter, "th", "Bezeichner"); writeTagTo(xmlStreamWriter, "th", "Datentyp"); writeTagTo(xmlStreamWriter, "th", "Inhalt"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("tbody"); int nr = 1; for (Iterator<Feld> iterator = teildatensatz.getFelder().iterator(); iterator.hasNext();) { Feld feld = iterator.next(); writeDetailsTo(xmlStreamWriter, feld, zeile, nr); nr++; } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.flush(); }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * @param xmlNode XML node/*from ww w . j a v a 2s . com*/ * @param xmlStreamWriter XML stream writer * @throws XMLStreamException the XML stream exception */ public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (xmlNode instanceof Element) { addElement((Element) xmlNode, xmlStreamWriter); } else if (xmlNode instanceof Text) { xmlStreamWriter.writeCharacters(xmlNode.getNodeValue()); } else if (xmlNode instanceof CDATASection) { xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData()); } else if (xmlNode instanceof Comment) { xmlStreamWriter.writeComment(((Comment) xmlNode).getData()); } else if (xmlNode instanceof EntityReference) { xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue()); } else if (xmlNode instanceof ProcessingInstruction) { ProcessingInstruction procInst = (ProcessingInstruction) xmlNode; xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(), procInst.getData()); } else if (xmlNode instanceof Document) { writeToDocument((Document) xmlNode, xmlStreamWriter); } }
From source file:org.elasticsearch.discovery.ec2.Ec2DiscoveryClusterFormationTests.java
/** * Creates mock EC2 endpoint providing the list of started nodes to the DescribeInstances API call */// www .j ava 2s. c o m @BeforeClass public static void startHttpd() throws Exception { logDir = createTempDir(); httpServer = MockHttpServer .createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0), 0); httpServer.createContext("/", (s) -> { Headers headers = s.getResponseHeaders(); headers.add("Content-Type", "text/xml; charset=UTF-8"); String action = null; for (NameValuePair parse : URLEncodedUtils.parse(IOUtils.toString(s.getRequestBody()), StandardCharsets.UTF_8)) { if ("Action".equals(parse.getName())) { action = parse.getValue(); break; } } assertThat(action, equalTo("DescribeInstances")); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); StringWriter out = new StringWriter(); XMLStreamWriter sw; try { sw = xmlOutputFactory.createXMLStreamWriter(out); sw.writeStartDocument(); String namespace = "http://ec2.amazonaws.com/doc/2013-02-01/"; sw.setDefaultNamespace(namespace); sw.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "DescribeInstancesResponse", namespace); { sw.writeStartElement("requestId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("reservationSet"); { Path[] files = FileSystemUtils.files(logDir); for (int i = 0; i < files.length; i++) { Path resolve = files[i].resolve("transport.ports"); if (Files.exists(resolve)) { List<String> addresses = Files.readAllLines(resolve); Collections.shuffle(addresses, random()); sw.writeStartElement("item"); { sw.writeStartElement("reservationId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instancesSet"); { sw.writeStartElement("item"); { sw.writeStartElement("instanceId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("imageId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instanceState"); { sw.writeStartElement("code"); sw.writeCharacters("16"); sw.writeEndElement(); sw.writeStartElement("name"); sw.writeCharacters("running"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateDnsName"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("dnsName"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("instanceType"); sw.writeCharacters("m1.medium"); sw.writeEndElement(); sw.writeStartElement("placement"); { sw.writeStartElement("availabilityZone"); sw.writeCharacters("use-east-1e"); sw.writeEndElement(); sw.writeEmptyElement("groupName"); sw.writeStartElement("tenancy"); sw.writeCharacters("default"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateIpAddress"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("ipAddress"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } } } sw.writeEndElement(); } sw.writeEndElement(); sw.writeEndDocument(); sw.flush(); final byte[] responseAsBytes = out.toString().getBytes(StandardCharsets.UTF_8); s.sendResponseHeaders(200, responseAsBytes.length); OutputStream responseBody = s.getResponseBody(); responseBody.write(responseAsBytes); responseBody.close(); } catch (XMLStreamException e) { Loggers.getLogger(Ec2DiscoveryClusterFormationTests.class).error("Failed serializing XML", e); throw new RuntimeException(e); } }); httpServer.start(); }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Feld feld, final int zeile, final int nr) throws XMLStreamException { String typ = feld.getClass().getSimpleName(); xmlStreamWriter.writeStartElement("tr"); xmlStreamWriter.writeAttribute("class", typ); writeTagTo(xmlStreamWriter, "td", Integer.toString(nr)); xmlStreamWriter.writeStartElement("td"); xmlStreamWriter.writeStartElement("a"); xmlStreamWriter.writeAttribute("name", getAnchorFor(zeile, feld)); xmlStreamWriter.writeEndElement();//from ww w . j a va 2 s .c o m if (feld.getAnzahlBytes() == 1) { xmlStreamWriter.writeCharacters(Integer.toString(feld.getByteAdresse())); } else { xmlStreamWriter.writeCharacters(feld.getByteAdresse() + " - " + feld.getEndAdresse()); } xmlStreamWriter.writeEndElement(); writeTagTo(xmlStreamWriter, "td", feld.getBezeichnung()); writeTagTo(xmlStreamWriter, "td", typ); xmlStreamWriter.writeStartElement("td"); writeInhaltTo(xmlStreamWriter, feld); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); }
From source file:com.fiorano.openesb.application.DmiObject.java
protected static void writeElement(XMLStreamWriter writer, String element, String content) throws XMLStreamException { if (!StringUtils.isEmpty(content)) { writer.writeStartElement(element); writer.writeCharacters(content); writer.writeEndElement();/*from www . j ava 2s. c om*/ } }
From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java
public static void write(List<Scale> modeList, String fileName) { XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null; // <mode> // <name>Peruvian tritonic 2</name> // <interval>3</interval> // <interval>4</interval> // <interval>5</interval> // </mode> String ns = "http://rockhoppertech.com/modes-1.0"; // StringWriter sw = new StringWriter(); try {/*from w w w . j a v a2 s .c om*/ xtw = xof.createXMLStreamWriter(new FileWriter(fileName)); // xtw = xof.createXMLStreamWriter(sw); xtw.writeComment("all elements here are explicitly in the mode namespace"); xtw.writeStartDocument("utf-8", "1.0"); xtw.setPrefix("modes", ns); xtw.writeStartElement(ns, "modes"); xtw.writeNamespace("modes", ns); for (Scale scale : modeList) { // xtw.writeStartElement(ns, "mode"); xtw.writeStartElement("mode"); // xtw.writeStartElement(ns, "name"); xtw.writeStartElement("name"); xtw.writeCharacters(scale.getName()); xtw.writeEndElement(); // xtw.writeStartElement(ns, "intervals"); // xtw.writeStartElement(ns, "interval"); xtw.writeStartElement("intervals"); int[] intervals = scale.getIntervals(); for (int i = 0; i < intervals.length; i++) { xtw.writeStartElement("interval"); xtw.writeCharacters("" + intervals[i]); xtw.writeEndElement(); } xtw.writeEndElement(); // intervals xtw.writeEndElement(); // mode } xtw.writeEndElement(); // modes xtw.writeEndDocument(); xtw.flush(); xtw.close(); // System.err.println(sw.toString()); } catch (XMLStreamException | IOException e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); } }