List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeOptionalAttribute(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException { if (StringUtils.isNotBlank(theValue)) { theEventWriter.writeAttribute(theName, theValue); }//from w w w .j a v a 2 s .c o m }
From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java
/** Extract as many as <code>limit</code> questions from the <code>reader</code> * provided, writing them to <code>writer</code>. * @param reader/* www. j a va 2 s . c o m*/ * @param writer * @param limit * @return * @throws XMLStreamException */ protected int extractXMLData(XMLStreamReader reader, XMLStreamWriter writer, int limit) throws XMLStreamException { int questionCount = 0; int attrCount; boolean copyElement = false; writer.writeStartDocument(); writer.writeStartElement("posts"); writer.writeCharacters("\n"); while (reader.hasNext() && questionCount < limit) { switch (reader.next()) { case XMLEvent.START_ELEMENT: if (reader.getLocalName().equals("row")) { attrCount = reader.getAttributeCount(); for (int i = 0; i < attrCount; i++) { // copy only the questions. if (reader.getAttributeName(i).getLocalPart().equals("PostTypeId") && reader.getAttributeValue(i).equals("1")) { copyElement = true; break; } } if (copyElement) { writer.writeCharacters(" "); writer.writeStartElement("row"); for (int i = 0; i < attrCount; i++) { writer.writeAttribute(reader.getAttributeName(i).getLocalPart(), reader.getAttributeValue(i)); } writer.writeEndElement(); writer.writeCharacters("\n"); copyElement = false; questionCount++; } } break; } } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); return questionCount; }
From source file:com.norconex.committer.idol.IdolCommitter.java
@Override protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("host"); writer.writeCharacters(getHost());// w w w . j ava 2s . co m writer.writeEndElement(); writer.writeStartElement("cfsPort"); writer.writeCharacters(Integer.toString(getCfsPort())); writer.writeEndElement(); writer.writeStartElement("indexPort"); writer.writeCharacters(Integer.toString(getIndexPort())); writer.writeEndElement(); writer.writeStartElement("databaseName"); writer.writeCharacters(getDatabaseName()); writer.writeEndElement(); writer.writeStartElement("dreAddDataParams"); for (String key : dreAddDataParams.keySet()) { writer.writeStartElement("param"); writer.writeAttribute(key, key); writer.writeCharacters(dreAddDataParams.get(key)); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("dreDeleteRefParams"); for (String key : dreDeleteRefParams.keySet()) { writer.writeStartElement("param"); writer.writeAttribute(key, key); writer.writeCharacters(dreDeleteRefParams.get(key)); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeOptionalTagWithValue(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException { if (StringUtils.isNotBlank(theValue)) { theEventWriter.writeStartElement(theName); theEventWriter.writeAttribute("value", theValue); theEventWriter.writeEndElement(); }// w ww . j av a2 s . c om }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeCategories(XMLStreamWriter eventWriter, TagList categories) throws XMLStreamException { if (categories != null) { for (Tag next : categories) { eventWriter.writeStartElement("category"); eventWriter.writeAttribute("term", defaultString(next.getTerm())); eventWriter.writeAttribute("label", defaultString(next.getLabel())); eventWriter.writeAttribute("scheme", defaultString(next.getScheme())); eventWriter.writeEndElement(); }//from ww w. java 2s . co m } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt) throws XMLStreamException { if (StringUtils.isNotBlank(theStringDt.getValue())) { theEventWriter.writeStartElement("link"); theEventWriter.writeAttribute("rel", theRel); theEventWriter.writeAttribute("href", theStringDt.getValue()); theEventWriter.writeEndElement(); }/*w w w.ja v a2 s.c om*/ }
From source file:com.liferay.portal.util.LocalizationImpl.java
private void _copyNonExempt(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter, String exemptLanguageId, String defaultLanguageId, boolean cdata) throws XMLStreamException { while (xmlStreamReader.hasNext()) { int event = xmlStreamReader.next(); if (event == XMLStreamConstants.START_ELEMENT) { String languageId = xmlStreamReader.getAttributeValue(null, _LANGUAGE_ID); if (Validator.isNull(languageId)) { languageId = defaultLanguageId; }/*w w w . ja va2s. c om*/ if (!languageId.equals(exemptLanguageId)) { xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName()); xmlStreamWriter.writeAttribute(_LANGUAGE_ID, languageId); while (xmlStreamReader.hasNext()) { event = xmlStreamReader.next(); if ((event == XMLStreamConstants.CHARACTERS) || (event == XMLStreamConstants.CDATA)) { String text = xmlStreamReader.getText(); if (cdata) { xmlStreamWriter.writeCData(text); } else { xmlStreamWriter.writeCharacters(xmlStreamReader.getText()); } break; } else if (event == XMLStreamConstants.END_ELEMENT) { break; } } xmlStreamWriter.writeEndElement(); } } else if (event == XMLStreamConstants.END_DOCUMENT) { break; } } }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds the "last-modification-date" attribute to the provided {@code XMLStreamWriter}.<br> The value of the * attribute is set to the value of the provided date.<br> If no date is provided, nothing is added. * * @param writer The {@code XMLStreamWriter} object to add the attribute to. * @param modifiedDate The date to set as the last modified date. * @throws XMLStreamException Thrown in case of an xml stream error. *///w w w .j ava2s. c o m public static void addLastModificationDateAttribute(final XMLStreamWriter writer, final DateTime modifiedDate) throws XMLStreamException { if (modifiedDate == null) { return; } writer.writeAttribute("last-modification-date", modifiedDate.withZone(DateTimeZone.UTC).toString(Constants.TIMESTAMP_FORMAT)); }
From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start Application Header writer.writeStartElement("ApplicationHeader"); writer.writeAttribute("isSubgraphable", "" + m_canBeSubGraphed); writer.writeAttribute("Scope", m_scope); //Write Name/*from w ww .j a v a 2s . co m*/ FioranoStackSerializer.writeElement("Name", m_appName, writer); //Write ApplicationGUID FioranoStackSerializer.writeElement("ApplicationGUID", m_appGUID, writer); //Write Auther Vector FioranoStackSerializer.writeVector("Author", m_authorNames, writer); //Write Creation Date FioranoStackSerializer.writeElement("CreationDate", m_creationDate, writer); //Write Icon if (!StringUtils.isEmpty(m_iconName)) { FioranoStackSerializer.writeElement("Icon", m_iconName, writer); } //Write Version if (m_version != null) { writer.writeStartElement("Version"); writer.writeAttribute("isLocked", "" + m_isVersionLocked); writer.writeCharacters(m_version); writer.writeEndElement(); } //Write Label FioranoStackSerializer.writeElement("Label", m_strProfile, writer); //Write CompatibleWith FioranoStackSerializer.writeVector("CompatibleWith", m_compatibleWith, writer); //Write Category FioranoStackSerializer.writeElement("Category", m_category, writer); //Write Maximum Instances if (m_maxInstLimit == -1 || m_maxInstLimit > 0) { writer.writeStartElement("MaximumInstances"); writer.writeCharacters("" + m_maxInstLimit); writer.writeEndElement(); } //Write Long Description if (!StringUtils.isEmpty(m_longDescription)) { FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer); } //Write Short Description if (!StringUtils.isEmpty(m_shortDescription)) { FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer); } //Write mParams if (m_params != null && m_params.size() > 0) { Enumeration enums = m_params.elements(); while (enums.hasMoreElements()) { Param param = (Param) enums.nextElement(); if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) param.toJXMLString(writer); } } // Write AppContext if (m_appContext != null) { m_appContext.toJXMLString(writer); } //End Application Header writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeBundleResourceLink(XMLStreamWriter theEventWriter, String theRel, StringDt theUrl) throws XMLStreamException { if (theUrl.isEmpty() == false) { theEventWriter.writeStartElement("link"); theEventWriter.writeStartElement("relation"); theEventWriter.writeAttribute("value", theRel); theEventWriter.writeEndElement(); theEventWriter.writeStartElement("url"); theEventWriter.writeAttribute("value", theUrl.getValue()); theEventWriter.writeEndElement(); theEventWriter.writeEndElement(); }//from w ww.j a v a2 s . c om }