List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeTo(final XMLStreamWriter xmlStreamWriter, final Satz satz, final int zeile) throws XMLStreamException { xmlStreamWriter.writeStartElement("div"); xmlStreamWriter.writeAttribute("class", "Satz"); if (satz instanceof Datensatz) { Datensatz datensatz = (Datensatz) satz; xmlStreamWriter.writeAttribute("title", "Satzart " + datensatz.getSatzartFeld().getInhalt() + "." + datensatz.getSparteFeld().getInhalt()); } else {// w ww . j ava 2s .com xmlStreamWriter.writeAttribute("title", "Satzart " + satz.getSatzartFeld().getInhalt()); } int n = zeile; for (Iterator<Teildatensatz> iterator = satz.getTeildatensaetze().iterator(); iterator.hasNext();) { Teildatensatz teildatensatz = iterator.next(); writeTo(xmlStreamWriter, teildatensatz, n); if (iterator.hasNext()) { xmlStreamWriter.writeCharacters("\n"); } n++; } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.flush(); }
From source file:com.fiorano.openesb.application.DmiObject.java
protected static void writeCollection(XMLStreamWriter writer, Collection/*<DmiObject>*/ c, String element, boolean writeCDataSections) throws XMLStreamException, FioranoException { if (c.size() > 0) { if (element != null) writer.writeStartElement(element); for (Object obj : c) { DmiObject dmi = (DmiObject) obj; dmi.toJXMLString(writer, writeCDataSections); }/*from w w w.j a va 2 s . co m*/ if (element != null) writer.writeEndElement(); } }
From source file:de.qucosa.webapi.v1.RelationResource.java
private void writeRelationElement(List<Tuple<String>> tuples, XMLStreamWriter w, String name, String type) throws XMLStreamException { for (Tuple<String> t : tuples) { w.writeStartElement(name);//from w w w . j a v a2 s . c o m w.writeStartElement("DocumentId"); w.writeCharacters(t.get(0)); w.writeEndElement(); w.writeStartElement("Value"); w.writeCharacters(t.get(1)); w.writeEndElement(); w.writeStartElement("Relation"); w.writeCharacters(type); w.writeEndElement(); w.writeStartElement("TitleMain"); w.writeCharacters(t.get(2)); w.writeEndElement(); w.writeEmptyElement("Label"); w.writeEmptyElement("SortOrder"); w.writeEmptyElement("Issue"); w.writeEndElement(); } }
From source file:com.predic8.membrane.core.interceptor.balancer.Node.java
@Override public void write(XMLStreamWriter out) throws XMLStreamException { out.writeStartElement("node"); out.writeAttribute("host", host); out.writeAttribute("port", "" + port); out.writeEndElement(); }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeTo(final XMLStreamWriter xmlStreamWriter, final Teildatensatz teildatensatz, final int zeile) throws XMLStreamException { xmlStreamWriter.writeStartElement("span"); xmlStreamWriter.writeAttribute("class", "Teildatensatz"); xmlStreamWriter.writeAttribute("title", "Nr. " + teildatensatz.getNummer().getInhalt()); int endAdresse = 1; for (Iterator<Feld> iterator = teildatensatz.getFelder().iterator(); iterator.hasNext();) { Feld feld = iterator.next();/*from ww w . jav a 2 s . c om*/ int gap = feld.getByteAdresse() - endAdresse; if (gap > 1) { Feld undefiniert = new Undefiniert(gap - 1, endAdresse + 1); writeTo(xmlStreamWriter, undefiniert, zeile); } writeTo(xmlStreamWriter, feld, zeile); endAdresse = feld.getEndAdresse(); } if (endAdresse < 256) { Feld undefiniert = new Undefiniert(256 - endAdresse, endAdresse + 1); writeTo(xmlStreamWriter, undefiniert, zeile); } xmlStreamWriter.writeEndElement(); }
From source file:com.norconex.collector.http.checksum.impl.DefaultHttpDocumentChecksummer.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/* w w w. ja va 2 s . c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpDocumentChecksummer"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("field"); writer.writeCharacters(field); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.flexive.core.IMParser.java
/** * Parse an identify stdOut result (from in) and convert it to an XML content * * @param in identify response/*from w ww . ja va 2 s . c o m*/ * @return XML content * @throws XMLStreamException on errors * @throws IOException on errors */ public static String parse(InputStream in) throws XMLStreamException, IOException { StringWriter sw = new StringWriter(2000); BufferedReader br = new BufferedReader(new InputStreamReader(in)); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); writer.writeStartDocument(); int lastLevel = 0, level, lastNonValueLevel = 1; boolean valueEntry; String curr = null; String[] entry; try { while ((curr = br.readLine()) != null) { if (curr.indexOf(':') == -1 || curr.trim().length() == 0) { System.out.println("skipping: [" + curr + "]"); continue; //ignore lines without ':' } level = getLevel(curr); curr = curr.trim(); if (level == 0 && curr.startsWith("Image:")) { writer.writeStartElement("Image"); entry = curr.split(": "); if (entry.length >= 2) writer.writeAttribute("source", entry[1]); lastLevel = level; continue; } if (!(valueEntry = pNumeric.matcher(curr).matches())) { while (level < lastLevel--) writer.writeEndElement(); lastNonValueLevel = level; } else level = lastNonValueLevel + 1; if (curr.endsWith(":")) { writer.writeStartElement(cleanElement(curr.substring(0, curr.lastIndexOf(':')))); lastLevel = level + 1; continue; } else if (pColormap.matcher(curr).matches()) { writer.writeStartElement(cleanElement(curr.substring(0, curr.lastIndexOf(':')))); writer.writeAttribute("colors", curr.split(": ")[1].trim()); lastLevel = level + 1; continue; } entry = curr.split(": "); if (entry.length == 2) { if (!valueEntry) { writer.writeStartElement(cleanElement(entry[0])); writer.writeCharacters(entry[1]); writer.writeEndElement(); } else { writer.writeEmptyElement("value"); writer.writeAttribute("key", cleanElement(entry[0])); writer.writeAttribute("data", entry[1]); // writer.writeEndElement(); } } else { // System.out.println("unknown line: "+curr); } lastLevel = level; } } catch (Exception e) { System.err.println("Error at [" + curr + "]:" + e.getMessage()); e.printStackTrace(); } writer.writeEndDocument(); writer.flush(); writer.close(); return sw.getBuffer().toString(); }
From source file:net.danizen.norconex.committer.kafka.KafkaCommitter.java
@Override protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException { if (StringUtils.isNotBlank(topicName)) { writer.writeStartElement("topicName"); writer.writeCharacters(topicName); writer.writeEndElement(); }/*from w w w . ja v a 2 s . co m*/ if (StringUtils.isNotBlank(brokerList)) { writer.writeStartElement("brokerList"); writer.writeCharacters(brokerList); writer.writeEndElement(); } }
From source file:de.qucosa.webapi.v1.RelationResource.java
@RequestMapping(value = "/relation/urn/{URN}", method = RequestMethod.GET) public ResponseEntity<String> describeRelationships(@PathVariable String URN) throws XMLStreamException, IOException, FedoraClientException { String pid = fedoraRepository.getPIDByIdentifier(URN); List<Tuple<String>> constituentPredecessorPids = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativePredecessorPIDs = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); List<Tuple<String>> constituentSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativeSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Opus_Document"); w.writeStartElement("DocumentId"); w.writeCharacters(stripPrefix(pid)); w.writeEndElement(); w.writeStartElement("Relations"); writeRelationElement(constituentPredecessorPids, w, "PredecessorRelation", "journal"); writeRelationElement(derivativePredecessorPIDs, w, "PredecessorRelation", "predecessor"); writeRelationElement(constituentSuccessorPids, w, "SuccessorRelation", "issue"); writeRelationElement(derivativeSuccessorPids, w, "SuccessorRelation", "predecessor"); w.writeEndElement();/* ww w. java 2s. c o m*/ w.writeEndElement(); w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:com.predic8.membrane.core.http.xml.Response.java
@Override public void write(XMLStreamWriter out) throws XMLStreamException { out.writeStartElement("http", ELEMENT_NAME, Constants.HTTP_NS); out.writeNamespace("http", Constants.HTTP_NS); out.writeStartElement("status"); out.writeAttribute("code", "" + statusCode); out.writeCharacters(statusMessage);/* w ww. j a v a 2 s. c o m*/ out.writeEndElement(); writeIfNotNull(headers, out); if (body != null) { out.writeStartElement("body"); body.write(out); out.writeEndElement(); } out.writeEndElement(); }