List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:de.qucosa.webapi.v1.SearchResource.java
private ResponseEntity<String> scrollAndBuildResultList(SearchResponse searchResponse) throws XMLStreamException, ParseException { StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); SearchHits searchHits = searchResponse.getHits(); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); {/* w w w . ja va 2s .c o m*/ w.writeStartElement("SearchResult"); { w.writeStartElement("Search"); w.writeAttribute("hits", String.valueOf(searchHits.getTotalHits())); w.writeEndElement(); w.writeStartElement("ResultList"); w.writeNamespace(XLINK_NAMESPACE_PREFIX, XLINK_NAMESPACE); SearchResponse scrollResponse = searchResponse; int hitcount = 0; while (true) { hitcount = writeResultElements(w, searchHits, hitcount); scrollResponse = elasticSearchClient.prepareSearchScroll(scrollResponse.getScrollId()) .setScroll(new TimeValue(60, TimeUnit.SECONDS)).execute().actionGet(); searchHits = scrollResponse.getHits(); if (searchHits.getHits().length == 0) { log.debug("Stop scrolling at hitcount: {}", hitcount); break; } } w.writeEndElement(); } w.writeEndElement(); } w.writeEndElement(); w.writeEndDocument(); w.flush(); log.debug(sw.toString()); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:DDTReporter.java
private void writeStartElement(XMLStreamWriter writer, String name, String[] attributes, String[] values) throws XMLStreamException { writer.writeStartElement(name);/* w w w . ja va 2 s .c o m*/ for (int i = 0; i < attributes.length; i++) { writer.writeAttribute(attributes[i], values[i]); } writer.writeCharacters("\n"); }
From source file:jp.co.atware.solr.geta.GETAssocComponent.java
/** * SolrGETAXML?????/*from ww w .ja va 2 s . c om*/ * ?Solr?????GETA???????? * Solr????????? * * @param xml XMLWriter * @param params SolrParams * @param paramName Solr?? * @param defaultValue * @param getaName GETA?? * @throws XMLStreamException */ protected void convReqWriteAttr(XMLStreamWriter xml, SolrParams params, String paramName, String defaultValue, String getaName) throws XMLStreamException { String value = params.get(paramName, defaultValue); if (value != null) { xml.writeAttribute(getaName, value); } }
From source file:net.solarnetwork.util.JavaBeanXmlSerializer.java
private void outputMap(Map<?, ?> map, String name, XMLStreamWriter out) throws XMLStreamException { writeElement(name, null, out, false); // for each entry, write an <entry> element for (Map.Entry<?, ?> me : map.entrySet()) { String entryName = me.getKey().toString(); out.writeStartElement("entry"); out.writeAttribute("key", entryName); Object value = me.getValue(); if (value instanceof Collection) { // special collection case, we don't add nested element for (Object o : (Collection<?>) value) { outputObject(o, "value", out); }/*ww w .ja va2 s . c om*/ } else { outputObject(value, null, out); } out.writeEndElement(); } out.writeEndElement(); }
From source file:jp.co.atware.solr.geta.GETAssocComponent.java
/** * GETAssoc??????//from ww w . j ava2 s .c om * * @param params * @param queryValue * @param queryType * @return * @throws FactoryConfigurationError * @throws IOException */ protected String convertRequest(SolrParams params, String queryValue, QueryType queryType) throws FactoryConfigurationError, IOException { String req; try { CharArrayWriter output = new CharArrayWriter(); XMLStreamWriter xml = XMLOutputFactory.newInstance().createXMLStreamWriter(output); xml.writeStartDocument(); xml.writeStartElement("gss"); if (config.settings.gss3version != null) { xml.writeAttribute("version", config.settings.gss3version); } xml.writeStartElement("assoc"); String target = params.get(PARAM_TARGET, config.defaults.target); if (target != null) { xml.writeAttribute("target", target); } convertRequestWriteStage1Param(xml, params); convertRequestWriteStage2Param(xml, params); convReqWriteQuery(xml, params, queryValue, queryType); xml.writeEndElement(); xml.writeEndElement(); xml.writeEndDocument(); xml.close(); req = output.toString(); } catch (XMLStreamException e) { throw new IOException(e); } LOG.debug(req); return req; }
From source file:com.fiorano.openesb.application.aps.OutPortInst.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start OutPortInst writer.writeStartElement("OutPortInst"); writer.writeAttribute("isSyncRequestType", "" + isSyncRequestType()); FioranoStackSerializer.writeElement("Name", m_strPortName, writer); if (!StringUtils.isEmpty(m_strDscription)) { FioranoStackSerializer.writeElement("Description", m_strDscription, writer); }// w w w . j a v a 2 s .co m boolean standardXSD = false; if ("ON_EXCEPTION".equals(m_strPortName)) standardXSD = CommonSchemas.ERROR_XSD == null ? m_strXSD == null : m_strXSD != null && CommonSchemas.ERROR_XSD.equals(m_strXSD); if (standardXSD) { writer.writeStartElement("StandardXSD"); writer.writeEndElement(); } else if (m_strXSDRef != null) { FioranoStackSerializer.writeElement(PortInstConstants.PORT_XSDREF, m_strXSDRef, writer); } if (m_strContextXSL != null) { writer.writeStartElement("SetContextXSL"); writer.writeCData(m_strContextXSL); writer.writeEndElement(); } if (m_strContextInfo != null) { writer.writeStartElement("SetContextInfo"); writer.writeCData(m_strContextInfo); writer.writeEndElement(); } if (m_transformerType != null) { writer.writeStartElement("SetTransformationType"); writer.writeCData(m_transformerType); writer.writeEndElement(); } if (!StringUtils.isEmpty(m_strJavaClass)) { FioranoStackSerializer.writeElement("JavaClass", m_strJavaClass, writer); } 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())) { if (!checkIfDefaultValue(param.getParamName(), param.getParamValue())) { param.toJXMLString(writer); } } } } //End OutPortInst writer.writeEndElement(); }
From source file:com.fiorano.openesb.application.application.OutputPortInstance.java
protected void toJXMLString_2(XMLStreamWriter writer, boolean writeSchema) throws XMLStreamException, FioranoException { if (writeSchema || publisherConfigName == null) { // We need to write port properties to stream when passing application launch packet to peer // writer.writeStartElement(ELEM_PUBLISHER); {/*www. java 2s . co m*/ writer.writeStartElement(ELEM_MESSAGES); { if (timeToLive != 0) writer.writeAttribute(ATTR_TIME_TO_LIVE, String.valueOf(timeToLive)); if (compressMessages) writer.writeAttribute(ATTR_COMPRESS_MESSAGES, String.valueOf(compressMessages)); if (priority != 4) writer.writeAttribute(ATTR_PRIORITY, String.valueOf(priority)); if (persistent) writer.writeAttribute(ATTR_PERSISTENT, String.valueOf(persistent)); } writer.writeEndElement(); } writer.writeEndElement(); } else { writer.writeStartElement(ELEM_PUBLISHER_CONFIG_NAME); { writer.writeAttribute(ATTR_NAME, publisherConfigName); } writer.writeEndElement(); } }
From source file:com.fiorano.openesb.application.application.InputPortInstance.java
protected void toJXMLString_2(XMLStreamWriter writer, boolean writeSchema) throws XMLStreamException, FioranoException { if (writeSchema || subscriberConfigName == null) { // We need to write port properties to stream when passing application launch packet to peer writer.writeStartElement(ELEM_SUBSCRIBER); {// w w w . ja v a2 s . c o m if (sessionCount != 1) writer.writeAttribute(ATTR_SESSION_COUNT, String.valueOf(sessionCount)); if (acknowledgementMode != ACKNOWLEDGEMENT_MODE_DUPS_OK) writer.writeAttribute(ATTR_ACKNOWLEDGEMENT_MODE, String.valueOf(acknowledgementMode)); if (!StringUtils.isEmpty(messageSelector)) writer.writeAttribute(ATTR_MESSAGE_SELECTOR, String.valueOf(messageSelector)); writer.writeStartElement(ELEM_TRANSACTION); { writer.writeAttribute(ATTR_TRANSACTED, String.valueOf(transacted)); if (transactionSize != 0) writer.writeAttribute(ATTR_TRANSACTION_SIZE, String.valueOf(transactionSize)); } writer.writeEndElement(); writer.writeStartElement(ELEM_SUBSCRIPTION); { writer.writeAttribute(ATTR_DURABLE_SUBSCRIPTION, String.valueOf(durableSubscription)); if (!StringUtils.isEmpty(subscriptionName)) writer.writeAttribute(ATTR_SUBSCRIPTION_NAME, String.valueOf(subscriptionName)); } writer.writeEndElement(); } writer.writeEndElement(); } else { writer.writeStartElement(ELEM_SUBSCRIBER_CONFIG_NAME); { writer.writeAttribute(ATTR_NAME, subscriberConfigName); } writer.writeEndElement(); } }
From source file:net.landora.video.info.file.FileInfoManager.java
private synchronized void writeCacheFile(File file, Map<String, FileInfo> infoMap) { OutputStream os = null;/*w w w .j a v a 2 s . c om*/ try { os = new BufferedOutputStream(new FileOutputStream(file)); if (COMPRESS_INFO_FILE) { os = new GZIPOutputStream(os); } XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(os); writer.writeStartDocument(); writer.writeStartElement("files"); writer.writeCharacters("\n"); for (Map.Entry<String, FileInfo> entry : infoMap.entrySet()) { FileInfo info = entry.getValue(); writer.writeStartElement("file"); writer.writeAttribute("filename", entry.getKey()); writer.writeAttribute("ed2k", info.getE2dkHash()); writer.writeAttribute("length", String.valueOf(info.getFileSize())); writer.writeAttribute("lastmodified", String.valueOf(info.getLastModified())); if (info.getMetadataSource() != null) { writer.writeAttribute("metadatasource", info.getMetadataSource()); } if (info.getMetadataId() != null) { writer.writeAttribute("metadataid", info.getMetadataId()); } if (info.getVideoId() != null) { writer.writeAttribute("videoid", info.getVideoId()); } writer.writeEndElement(); writer.writeCharacters("\n"); } writer.writeEndElement(); writer.writeEndDocument(); writer.close(); } catch (Exception e) { log.error("Error writing file cache.", e); } finally { if (os != null) { IOUtils.closeQuietly(os); } } }
From source file:edu.jhu.pha.vospace.node.Node.java
public String getXmlMetadata(Detail detail) { StringWriter jobWriter = new StringWriter(); try {/*w w w . j av a 2s .c o m*/ XMLStreamWriter xsw = XMLOutputFactory.newInstance().createXMLStreamWriter(jobWriter); xsw.writeStartDocument(); xsw.setDefaultNamespace(VOS_NAMESPACE); xsw.writeStartElement("node"); xsw.writeNamespace("xsi", XSI_NAMESPACE); xsw.writeNamespace(null, VOS_NAMESPACE); xsw.writeAttribute("xsi:type", this.getType().getTypeName()); xsw.writeAttribute("uri", this.getUri().toString()); if (detail == Detail.max) { xsw.writeStartElement("properties"); Map<String, String> properties = this.getMetastore().getProperties(this.getUri()); properties.put(LENGTH_PROPERTY, Long.toString(getNodeInfo().getSize())); properties.put(DATE_PROPERTY, dropboxDateFormat.format(getNodeInfo().getMtime())); if (this.getType() == NodeType.DATA_NODE || this.getType() == NodeType.STRUCTURED_DATA_NODE || this.getType() == NodeType.UNSTRUCTURED_DATA_NODE) { properties.put(CONTENTTYPE_PROPERTY, getNodeInfo().getContentType()); } for (String propUri : properties.keySet()) { xsw.writeStartElement("property"); xsw.writeAttribute("uri", propUri); xsw.writeCharacters(properties.get(propUri)); xsw.writeEndElement(); } xsw.writeEndElement(); xsw.writeStartElement("accepts"); xsw.writeEndElement(); xsw.writeStartElement("provides"); xsw.writeEndElement(); xsw.writeStartElement("capabilities"); xsw.writeEndElement(); if (this.getType() == NodeType.CONTAINER_NODE) { NodesList childrenList = ((ContainerNode) this).getDirectChildren(false, 0, -1); List<Node> children = childrenList.getNodesList(); xsw.writeStartElement("nodes"); for (Node childNode : children) { xsw.writeStartElement("node"); xsw.writeAttribute("uri", childNode.getUri().getId().toString()); xsw.writeEndElement(); } xsw.writeEndElement(); } } xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); } catch (XMLStreamException e) { e.printStackTrace(); throw new InternalServerErrorException(e); } return jobWriter.getBuffer().toString(); }