List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:jp.co.atware.solr.geta.GETAssocComponent.java
/** * GETAssoc??????// ww w .j a v a2s .c o m * * @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.concursive.connect.web.modules.api.services.BackupService.java
private void save(XMLStreamWriter writer, DataRecord record, String recordId, Object object, PacketContext context) throws Exception { // Data record writer.writeCharacters(" "); writer.writeStartElement("dataRecord"); writer.writeAttribute("name", record.getName()); writer.writeAttribute("id", recordId); writer.writeCharacters(System.getProperty("line.separator")); // Data fields for (DataField thisField : record) { writer.writeCharacters(" "); writer.writeStartElement(thisField.getName()); if (thisField.getValue() != null) { if (StringUtils.countLines(thisField.getValue()) > 1) { writer.writeCData(thisField.getValue()); } else { writer.writeCharacters(thisField.getValue()); }/*from ww w. j a va 2 s . c o m*/ } else { writer.writeCharacters(DataRecord.NULL); } writer.writeEndElement(); writer.writeCharacters(System.getProperty("line.separator")); } // If this is a file, stream it too if (object instanceof FileItem) { // Find the file in the filesystem File file = new File(context.getBaseFilePath() + DateUtils.getDatePath(record.getValueAsTimestamp("modified")) + record.getValue("filename")); if (!file.exists()) { LOG.error("File not found: " + file.getAbsolutePath()); } else { // If there is a fileAttachment, then attach it as base64 writer.writeCharacters(" "); writer.writeStartElement("fileAttachment"); // Convert to base64 and append writer.writeCData(new String(Base64.encodeBase64(FileUtils.getBytesFromFile(file), true))); // Close the element writer.writeEndElement(); writer.writeCharacters(System.getProperty("line.separator")); } } // Close the record writer.writeCharacters(" "); writer.writeEndElement(); writer.writeCharacters(System.getProperty("line.separator")); }
From source file:jodtemplate.pptx.io.xml.SlideXmlRelsWriter.java
@Override public void write(final Resources resources, final Slide slide, final XMLOutputFactory xmlOutputFactory) throws XMLStreamException, IOException { final String slideXmlPath = FilenameUtils .normalize(slide.getPresentation().getFullPath() + slide.getRelationship().getTarget(), true); final String slideXmlRelsPath = Utils.getRelsPathNoPrefixSeparator(slideXmlPath); final Resource slideXmlRelsRes = resources.getResource(slideXmlRelsPath); try (final OutputStream os = slideXmlRelsRes.getOutputStream()) { os.write(//w w w . j a v a 2s .co m "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n".getBytes(CharEncoding.UTF_8)); final XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(os); writer.writeStartElement(OOXMLDocument.RELATIONSHIPS_ELEMENT); writer.writeNamespace("", OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE); for (Relationship rel : slide.getOtherRelationships()) { writer.writeEmptyElement(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.RELATIONSHIP_ELEMENT); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.ID_ATTRIBUTE, rel.getId()); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TYPE_ATTRIBUTE, rel.getType()); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TARGET_ATTRIBUTE, rel.getTarget()); if (StringUtils.isNotBlank(rel.getTargetMode())) { writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TARGET_MODE_ATTRIBUTE, rel.getTargetMode()); } writer.flush(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } }
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); {/*w w w . j ava 2s .c om*/ 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:de.qucosa.webapi.v1.DocumentResource.java
private String getDocumentCreatedResponse(String id) throws XMLStreamException { StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Opus_Document"); w.writeNamespace(XLINK_NAMESPACE_PREFIX, XLINK_NAMESPACE); w.writeAttribute(XLINK_NAMESPACE, "href", getHrefLink(id)); w.writeAttribute("id", id); w.writeEndElement(); w.writeEndElement();/*w ww. j ava 2 s . co m*/ w.writeEndDocument(); w.flush(); return sw.toString(); }
From source file:com.github.lindenb.jvarkit.tools.vcfcmp.VcfCompareCallers.java
private void watch(XMLStreamWriter out, VariantContext ctx0, VariantContext ctx1, Genotype g0, Genotype g1, String sampleName, Counter<Category> count, Category cat) throws XMLStreamException { long n = count.incr(cat); if (out == null || n > super.numberOfExampleVariants) return;// www . j a v a2 s . c om VariantContext variants[] = new VariantContext[] { ctx0, ctx1 }; Genotype gts[] = new Genotype[] { g0, g1 }; out.writeStartElement("diff"); out.writeAttribute("type", cat.name()); out.writeAttribute("sample", sampleName); for (int i = 0; i < 2; ++i) { if (variants[i] == null) continue; out.writeStartElement("variant"); out.writeAttribute("file", String.valueOf(i + 1)); out.writeAttribute("type", String.valueOf(variants[i].getType())); out.writeStartElement("chrom"); out.writeCharacters(variants[i].getContig()); out.writeEndElement(); out.writeStartElement("pos"); out.writeCharacters(String.valueOf(variants[i].getStart())); out.writeEndElement(); out.writeStartElement("id"); out.writeCharacters(variants[i].hasID() ? variants[i].getID() : "."); out.writeEndElement(); out.writeStartElement("ref"); out.writeCharacters(String.valueOf(variants[i].getReference())); out.writeEndElement(); out.writeStartElement("alts"); out.writeCharacters(String.valueOf(variants[i].getAlternateAlleles())); out.writeEndElement(); if (gts[i] != null) { out.writeStartElement("genotype"); out.writeAttribute("type", String.valueOf(gts[i].getType())); for (Allele a : gts[i].getAlleles()) { out.writeStartElement("allele"); out.writeCharacters(a.toString()); out.writeEndElement(); } if (gts[i].hasDP()) { out.writeStartElement("dp"); out.writeCharacters(String.valueOf(gts[i].getDP())); out.writeEndElement(); } out.writeEndElement(); } out.writeEndElement(); } out.writeEndElement(); out.writeCharacters("\n"); }
From source file:org.sfs.nodes.compute.container.GetContainer.java
@Override public void handle(final SfsRequest httpServerRequest) { VertxContext<Server> vertxContext = httpServerRequest.vertxContext(); aVoid().flatMap(new Authenticate(httpServerRequest)) .flatMap(new ValidateActionAuthenticated(httpServerRequest)) .map(aVoid -> fromSfsRequest(httpServerRequest)).map(new ValidateContainerPath()) .flatMap(new LoadAccountAndContainer(vertxContext)) .flatMap(new ValidateActionContainerListObjects(httpServerRequest)).flatMap(persistentContainer -> { HttpServerResponse httpServerResponse = httpServerRequest.response(); MultiMap queryParams = httpServerRequest.params(); MultiMap headerParams = httpServerRequest.headers(); String format = queryParams.get(FORMAT); String accept = headerParams.get(ACCEPT); MediaType parsedAccept = null; if (equalsIgnoreCase("xml", format)) { parsedAccept = APPLICATION_XML_UTF_8; } else if (equalsIgnoreCase("json", format)) { parsedAccept = JSON_UTF_8; }/* www .j a v a2s . c om*/ if (parsedAccept == null) { if (!isNullOrEmpty(accept)) { parsedAccept = parse(accept); } } if (parsedAccept == null || (!PLAIN_TEXT_UTF_8.is(parsedAccept) && !APPLICATION_XML_UTF_8.is(parsedAccept) && !JSON_UTF_8.equals(parsedAccept))) { parsedAccept = PLAIN_TEXT_UTF_8; } Observable<Optional<ContainerStats>> oContainerStats; boolean hasPrefix = !Strings.isNullOrEmpty(queryParams.get(SfsHttpQueryParams.PREFIX)); if (hasPrefix) { oContainerStats = just(persistentContainer) .flatMap(new LoadContainerStats(httpServerRequest.vertxContext())) .map(Optional::of); } else { oContainerStats = Defer.just(Optional.<ContainerStats>absent()); } Observable<ObjectList> oObjectListing = just(persistentContainer) .flatMap(new ListObjects(httpServerRequest)); MediaType finalParsedAccept = parsedAccept; return combineSinglesDelayError(oContainerStats, oObjectListing, (containerStats, objectList) -> { if (containerStats.isPresent()) { Metadata metadata = persistentContainer.getMetadata(); for (String key : metadata.keySet()) { SortedSet<String> values = metadata.get(key); if (values != null && !values.isEmpty()) { httpServerResponse.putHeader( format("%s%s", X_ADD_CONTAINER_META_PREFIX, key), values); } } httpServerResponse.putHeader(X_CONTAINER_OBJECT_COUNT, valueOf(containerStats.get().getObjectCount())); httpServerResponse.putHeader(X_CONTAINER_BYTES_USED, BigDecimal.valueOf(containerStats.get().getBytesUsed()) .setScale(0, ROUND_HALF_UP).toString()); } BufferOutputStream bufferOutputStream = new BufferOutputStream(); if (JSON_UTF_8.is(finalParsedAccept)) { try { JsonFactory jsonFactory = vertxContext.verticle().jsonFactory(); JsonGenerator jg = jsonFactory.createGenerator(bufferOutputStream, UTF8); jg.writeStartArray(); for (ListedObject listedObject : ordered(objectList.getObjects())) { jg.writeStartObject(); jg.writeStringField("hash", base16().lowerCase().encode(listedObject.getEtag())); jg.writeStringField("last_modified", toDateTimeString(listedObject.getLastModified())); jg.writeNumberField("bytes", listedObject.getLength()); jg.writeStringField("content_type", listedObject.getContentType()); jg.writeStringField("name", listedObject.getName()); jg.writeEndObject(); } jg.writeEndArray(); jg.close(); } catch (IOException e) { throw new RuntimeException(e); } } else if (APPLICATION_XML_UTF_8.is(finalParsedAccept)) { String charset = UTF_8.toString(); XMLStreamWriter writer = null; try { writer = newFactory().createXMLStreamWriter(bufferOutputStream, charset); writer.writeStartDocument(charset, "1.0"); writer.writeStartElement("container"); writer.writeAttribute("name", fromPaths(persistentContainer.getId()).containerName().get()); for (ListedObject listedObject : ordered(objectList.getObjects())) { writer.writeStartElement("object"); writer.writeStartElement("name"); writer.writeCharacters(listedObject.getName()); writer.writeEndElement(); writer.writeStartElement("hash"); writer.writeCharacters( base16().lowerCase().encode(listedObject.getEtag())); writer.writeEndElement(); writer.writeStartElement("bytes"); writer.writeCharacters(valueOf(listedObject.getLength())); writer.writeEndElement(); writer.writeStartElement("content_type"); writer.writeCharacters(listedObject.getContentType()); writer.writeEndElement(); writer.writeStartElement("last_modified"); writer.writeCharacters( toDateTimeString(listedObject.getLastModified())); writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { try { if (writer != null) { writer.close(); } } catch (XMLStreamException e) { LOGGER.warn(e.getLocalizedMessage(), e); } } } else { String charset = UTF_8.toString(); try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter( bufferOutputStream, charset)) { for (ListedObject listedObject : ordered(objectList.getObjects())) { outputStreamWriter.write(listedObject.getName()); outputStreamWriter.write("\n"); } } catch (IOException e) { throw new RuntimeException(e); } } objectList.clear(); return bufferOutputStream; }).flatMap(bufferOutputStream -> { Buffer buffer = bufferOutputStream.toBuffer(); httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, finalParsedAccept.toString()) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length())); return AsyncIO.append(buffer, httpServerRequest.response()); }); }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) { @Override public void onNext(Void aVoid) { } } ); }
From source file:de.qucosa.webapi.v1.SearchResource.java
private int writeResultElements(XMLStreamWriter w, SearchHits searchHits, int starthitcount) throws XMLStreamException, ParseException { int i = starthitcount; for (SearchHit hit : searchHits) { w.writeStartElement("Result"); w.writeAttribute("number", String.valueOf(i++)); String docid = mapToQucosaId(head(values(hit.field(searchFieldnameMap.get("docid"))))); w.writeAttribute("docid", docid); w.writeAttribute(XLINK_NAMESPACE, "href", getHrefLink(docid)); w.writeAttribute("title", head(values(hit.field(searchFieldnameMap.get("title"))))); w.writeAttribute("author", join(values(hit.field(searchFieldnameMap.get("author"))))); w.writeAttribute("year", ""); w.writeAttribute("completeddate", mapToQucosaDate(head(values(hit.field(searchFieldnameMap.get("completeddate")))))); w.writeAttribute("doctype", head(values(hit.field(searchFieldnameMap.get("doctype"))))); w.writeAttribute("issue", ""); w.writeEndElement(); }// w w w . j ava2 s .c o m return i; }
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. ja va2 s . c o 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.Application.java
protected void toJXMLString_1(XMLStreamWriter writer, boolean writeManageableProperties) throws XMLStreamException, FioranoException { MapThreadLocale.getInstance().getMap().put("ERROR_XSD", CommonSchemas.ERROR_XSD); try {//from ww w. j av a 2s. c om if (applicationContext != null) applicationContext.toJXMLString(writer, writeManageableProperties); if (serviceInstances.size() > 0 || remoteServiceInstances.size() > 0) { writer.writeStartElement(ELEM_SERVICE_INSTANCES); { writeCollection(writer, serviceInstances, null, writeManageableProperties); writeCollection(writer, remoteServiceInstances, null); } writer.writeEndElement(); } writeCollection(writer, routes, ELEM_ROUTES, writeManageableProperties); writeCDATAElement(writer, ELEM_LAYOUT, layout); } finally { MapThreadLocale.getInstance().getMap().clear(); } }