List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String localName) throws XMLStreamException;
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleContainerLocation(HttpServletResponse response, BlobStore blobStore, String containerName) throws IOException { try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument();/*from w ww.jav a2s . co m*/ // TODO: using us-standard semantics but could emit actual location xml.writeStartElement("LocationConstraint"); xml.writeDefaultNamespace(AWS_XMLNS); xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleCopyBlob(HttpServletRequest request, HttpServletResponse response, InputStream is, BlobStore blobStore, String destContainerName, String destBlobName) throws IOException, S3Exception { String copySourceHeader = request.getHeader("x-amz-copy-source"); copySourceHeader = URLDecoder.decode(copySourceHeader, "UTF-8"); if (copySourceHeader.startsWith("/")) { // Some clients like boto do not include the leading slash copySourceHeader = copySourceHeader.substring(1); }//w ww .j a v a2s .co m String[] path = copySourceHeader.split("/", 2); if (path.length != 2) { throw new S3Exception(S3ErrorCode.INVALID_REQUEST); } String sourceContainerName = path[0]; String sourceBlobName = path[1]; boolean replaceMetadata = "REPLACE".equalsIgnoreCase(request.getHeader("x-amz-metadata-directive")); if (sourceContainerName.equals(destContainerName) && sourceBlobName.equals(destBlobName) && !replaceMetadata) { throw new S3Exception(S3ErrorCode.INVALID_REQUEST); } CopyOptions.Builder options = CopyOptions.builder(); String ifMatch = request.getHeader("x-amz-copy-source-if-match"); if (ifMatch != null) { options.ifMatch(ifMatch); } String ifNoneMatch = request.getHeader("x-amz-copy-source-if-none-match"); if (ifNoneMatch != null) { options.ifNoneMatch(ifNoneMatch); } long ifModifiedSince = request.getDateHeader("x-amz-copy-source-if-modified-since"); if (ifModifiedSince != -1) { options.ifModifiedSince(new Date(ifModifiedSince)); } long ifUnmodifiedSince = request.getDateHeader("x-amz-copy-source-if-unmodified-since"); if (ifUnmodifiedSince != -1) { options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); } if (replaceMetadata) { ContentMetadataBuilder contentMetadata = ContentMetadataBuilder.create(); ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { String headerValue = Strings.nullToEmpty(request.getHeader(headerName)); if (headerName.equalsIgnoreCase(HttpHeaders.CACHE_CONTROL)) { contentMetadata.cacheControl(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_DISPOSITION)) { contentMetadata.contentDisposition(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_ENCODING)) { contentMetadata.contentEncoding(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LANGUAGE)) { contentMetadata.contentLanguage(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE)) { contentMetadata.contentType(headerValue); } else if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put(headerName.substring(USER_METADATA_PREFIX.length()), headerValue); } // TODO: Expires } options.contentMetadata(contentMetadata.build()); options.userMetadata(userMetadata.build()); } String eTag; try { eTag = blobStore.copyBlob(sourceContainerName, sourceBlobName, destContainerName, destBlobName, options.build()); } catch (KeyNotFoundException knfe) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY, knfe); } // TODO: jclouds should include this in CopyOptions String cannedAcl = request.getHeader("x-amz-acl"); if (cannedAcl != null && !cannedAcl.equalsIgnoreCase("private")) { handleSetBlobAcl(request, response, is, blobStore, destContainerName, destBlobName); } BlobMetadata blobMetadata = blobStore.blobMetadata(destContainerName, destBlobName); try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument(); xml.writeStartElement("CopyObjectResult"); xml.writeDefaultNamespace(AWS_XMLNS); writeSimpleElement(xml, "LastModified", formatDate(blobMetadata.getLastModified())); writeSimpleElement(xml, "ETag", maybeQuoteETag(eTag)); xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:com.fiorano.openesb.application.aps.ServiceInstance.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException, FioranoException { //Start ServiceInstance writer.writeStartElement("ServiceInstance"); //Write Attributes writer.writeAttribute("isManualLaunch", "" + m_isManualLaunch); writer.writeAttribute("isStateful", "" + m_isStateful); writer.writeAttribute("isDelayedLaunch", "" + m_isDelayedLaunch); writer.writeAttribute("delayedPort", "" + m_delayedPortName); writer.writeAttribute("maxRetries", "" + m_maxRetries); writer.writeAttribute("isTransacted", "" + m_isTransacted); writer.writeAttribute("isErrorHandlingEnabled", "" + m_isErrorHandlingEnabled); writer.writeAttribute("isInMemoryLaunch", "" + m_isInMemoryLaunch); writer.writeAttribute("isEndOfWorkflow", "" + m_isEndOfWorkflow); writer.writeAttribute("preferLaunchOnHigherLevelNode", "" + m_bPreferLaunchOnHigherLevelNode); writer.writeAttribute("killPrimaryOnSecondaryLaunch", "" + m_bKillPrimaryOnSecondaryLaunch); writer.writeAttribute("isDebugMode", "" + m_bIsDebugMode); writer.writeAttribute("debugPort", "" + m_iDebugPort); writer.writeAttribute("isTransportLPC", "" + m_isTransportLPC); writer.writeAttribute("profile", "" + m_profile); FioranoStackSerializer.writeElement("ServiceInstanceName", m_servInstName, writer); FioranoStackSerializer.writeElement("ServiceGUID", m_servGUID, writer); FioranoStackSerializer.writeElement("BufferSizePerPort", m_dBufferSizePerPort + "", writer); if (m_version != null) { writer.writeStartElement("Version"); writer.writeAttribute("isLocked", "" + m_isVersionLocked); writer.writeCharacters(m_version); writer.writeEndElement();//from ww w . ja v a2 s .c o m } if (m_nodes != null && m_nodes.size() > 0) { Enumeration nodeNameEnum = m_nodes.keys(); Enumeration nodeLevelEnum = m_nodes.elements(); while (nodeNameEnum.hasMoreElements()) { String nodeName = (String) nodeNameEnum.nextElement(); String nodeLevel = (String) nodeLevelEnum.nextElement(); writer.writeStartElement("Node"); writer.writeAttribute("level", nodeLevel); writer.writeCharacters(nodeName); writer.writeEndElement(); } } if (m_eventHandler > 0) { writer.writeStartElement("EventHandler"); writer.writeAttribute("deliveryMode", "" + m_eventDeliveryMode); writer.writeAttribute("expiryTime", "" + m_eventExpiryTime); writer.writeCharacters("" + m_eventHandler); writer.writeEndElement(); } if (m_runtimeDependencies != null && m_runtimeDependencies.size() > 0) { Enumeration enums = m_runtimeDependencies.elements(); while (enums.hasMoreElements()) { RuntimeDependency runtimeDependency = (RuntimeDependency) enums.nextElement(); runtimeDependency.toJXMLString(writer); } } if (m_runtimeArgs != null) { m_runtimeArgs.toJXMLString(writer); } if (m_portInstDescriptor != null) { m_portInstDescriptor.toJXMLString(writer); } if (!StringUtils.isEmpty(m_longDescription)) { FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer); } if (!StringUtils.isEmpty(m_shortDescription)) { FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer); } //LogManager if (m_logManager != null) { //Start LogMangaer writer.writeStartElement("LogManager"); FioranoStackSerializer.writeElement("Name", m_logManager, writer); if (m_logParams != null && m_logParams.size() > 0) { Enumeration enums = m_logParams.elements(); while (enums.hasMoreElements()) { Param param = (Param) enums.nextElement(); if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) { param.toJXMLString(writer); } } } //End LogManager writer.writeEndElement(); } 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); } } if (m_statusTracking != null) { m_statusTracking.toJXMLString(writer); } if (m_vecEndStates != null) { for (int i = 0; i < m_vecEndStates.size(); i++) { EndState endState = (EndState) m_vecEndStates.get(i); endState.toJXMLString(writer); } } if (m_monitor != null) { m_monitor.toJXMLString(writer); } if (m_logModules != null) { m_logModules.toJXMLString(writer); } //End ServiceInstance writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the representation of the {@link AttributedElementClass} * <code>aeclass</code>.<br /> * A {@link GraphClass} is represented as a UML class with stereotype * <code><<graphclass>></code>.<br /> * A {@link VertexClass} is represented as a UML class.<br /> * An {@link EdgeClass} is represented as a UML association, if it has no * attributes and otherwise as a UML associationClass.<br /> * Furthermore the attribute abstract is generated, if the * {@link VertexClass} or {@link EdgeClass} is abstract. {@link Comment}s, * {@link Constraint}s, generalization and {@link Attribute}s are * represented as well.<br />/*from w w w. j a va 2 s. c o m*/ * The {@link IncidenceClass} representations are created if needed. To get * more information if it is needed, have a look at * {@link SchemaGraph2XMI#createIncidences(XMLStreamWriter, EdgeClass)} and * {@link SchemaGraph2XMI#createIncidences(XMLStreamWriter, VertexClass)}. * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param aeclass * {@link AttributedElementClass} the current * {@link AttributedElementClass} * @throws XMLStreamException */ private void createAttributedElementClass(XMLStreamWriter writer, AttributedElementClass aeclass) throws XMLStreamException { // if aeclass is a GraphElementClass without any attributes, comments // and constraints then an empty tag is created. Furthermore an // EdgeClass could only be empty if the associations are created // bidirectional. boolean isEmptyGraphElementClass = aeclass.getFirstAnnotatesIncidence() == null && aeclass.getFirstHasAttributeIncidence() == null && aeclass.getFirstHasConstraintIncidence() == null && (aeclass instanceof GraphElementClass && !((GraphElementClass) aeclass).is_abstract()) && (aeclass instanceof VertexClass && ((VertexClass) aeclass) .getFirstSpecializesVertexClassIncidence(EdgeDirection.OUT) == null && !hasChildIncidence((VertexClass) aeclass) || aeclass instanceof EdgeClass && ((EdgeClass) aeclass) .getFirstSpecializesEdgeClassIncidence(EdgeDirection.OUT) == null && isBidirectional); // start packagedElement if (isEmptyGraphElementClass) { writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT); } else { writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT); } // set type if (aeclass instanceof EdgeClass) { if (aeclass.getFirstHasAttributeIncidence() == null) { writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_ASSOCIATION); } else { writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_ASSOCIATIONCLASS); } } else { writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_CLASS); } writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, aeclass.get_qualifiedName()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, extractSimpleName(aeclass.get_qualifiedName())); // set EdgeClass specific memberEnd if (aeclass instanceof EdgeClass) { EdgeClass ec = (EdgeClass) aeclass; writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_MEMBEREND, ((VertexClass) ((IncidenceClass) ec.getFirstComesFromIncidence().getThat()) .getFirstEndsAtIncidence().getThat()).get_qualifiedName() + "_incidence_" + ec.get_qualifiedName() + "_from " + ((VertexClass) ((IncidenceClass) ec.getFirstGoesToIncidence().getThat()) .getFirstEndsAtIncidence().getThat()).get_qualifiedName() + "_incidence_" + ec.get_qualifiedName() + "_to"); } // set abstract if (aeclass instanceof GraphElementClass && ((GraphElementClass) aeclass).is_abstract()) { writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_ISABSTRACT, XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE_TRUE); createExtension(writer, aeclass, "abstract"); } // create <<graphclass>> for graph classes if (aeclass instanceof GraphClass) { createExtension(writer, aeclass, "graphclass"); } // create comments createComments(writer, aeclass); // create constraints createConstraints(writer, aeclass); // create generalization if (aeclass instanceof VertexClass) { for (SpecializesVertexClass svc : ((VertexClass) aeclass) .getSpecializesVertexClassIncidences(EdgeDirection.OUT)) { createGeneralization(writer, "generalization_" + aeclass.get_qualifiedName(), ((VertexClass) svc.getThat()).get_qualifiedName()); } } else if (aeclass instanceof EdgeClass) { for (SpecializesEdgeClass svc : ((EdgeClass) aeclass) .getSpecializesEdgeClassIncidences(EdgeDirection.OUT)) { createGeneralization(writer, "generalization_" + aeclass.get_qualifiedName(), ((EdgeClass) svc.getThat()).get_qualifiedName()); } } // create attributes createAttributes(writer, aeclass); // create incidences of EdgeClasses at VertexClass aeclass if (aeclass instanceof VertexClass) { createIncidences(writer, (VertexClass) aeclass); } else if (aeclass instanceof EdgeClass) { createIncidences(writer, (EdgeClass) aeclass); } // close packagedElement if (!isEmptyGraphElementClass) { writer.writeEndElement(); } }
From source file:com.github.lindenb.jvarkit.tools.vcfcmp.VcfCompareCallers.java
@Override public Collection<Throwable> call() throws Exception { htsjdk.samtools.util.IntervalTreeMap<Boolean> capture = null; PrintWriter exampleWriter = null; XMLStreamWriter exampleOut = null; PrintStream pw = null;//from ww w.java 2 s . c o m VcfIterator vcfInputs[] = new VcfIterator[] { null, null }; VCFHeader headers[] = new VCFHeader[] { null, null }; final List<String> args = getInputFiles(); try { if (args.size() == 1) { LOG.info("Reading from stdin and " + args.get(0)); vcfInputs[0] = VCFUtils.createVcfIteratorStdin(); vcfInputs[1] = VCFUtils.createVcfIterator(args.get(0)); } else if (args.size() == 2) { LOG.info("Reading from stdin and " + args.get(0) + " and " + args.get(1)); vcfInputs[0] = VCFUtils.createVcfIterator(args.get(0)); vcfInputs[1] = VCFUtils.createVcfIterator(args.get(1)); } else { return wrapException(getMessageBundle("illegal.number.of.arguments")); } if (super.captureFile != null) { LOG.info("Reading " + super.captureFile); capture = super.readBedFileAsBooleanIntervalTreeMap(super.captureFile); } for (int i = 0; i < vcfInputs.length; ++i) { headers[i] = vcfInputs[i].getHeader(); } /* dicts */ final SAMSequenceDictionary dict0 = headers[0].getSequenceDictionary(); final SAMSequenceDictionary dict1 = headers[1].getSequenceDictionary(); final Comparator<VariantContext> ctxComparator; if (dict0 == null && dict1 == null) { ctxComparator = VCFUtils.createChromPosRefComparator(); } else if (dict0 != null && dict1 != null) { if (!SequenceUtil.areSequenceDictionariesEqual(dict0, dict1)) { return wrapException(getMessageBundle("not.the.same.sequence.dictionaries")); } ctxComparator = VCFUtils.createTidPosRefComparator(dict0); } else { return wrapException(getMessageBundle("not.the.same.sequence.dictionaries")); } /* samples */ Set<String> samples0 = new HashSet<>(headers[0].getSampleNamesInOrder()); Set<String> samples1 = new HashSet<>(headers[1].getSampleNamesInOrder()); Set<String> samples = new TreeSet<>(samples0); samples.retainAll(samples1); if (samples.size() != samples0.size() || samples.size() != samples1.size()) { LOG.warn("Warning: Not the same samples set. Using intersection of both lists."); } if (samples.isEmpty()) { return wrapException("No common samples"); } Map<String, Counter<Category>> sample2info = new HashMap<String, Counter<Category>>(samples.size()); for (String sampleName : samples) { sample2info.put(sampleName, new Counter<Category>()); } if (super.exampleFile != null) { exampleWriter = new PrintWriter(exampleFile, "UTF-8"); XMLOutputFactory xof = XMLOutputFactory.newFactory(); exampleOut = xof.createXMLStreamWriter(exampleWriter); exampleOut.writeStartDocument("UTF-8", "1.0"); exampleOut.writeStartElement("compare-callers"); } SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(dict0); VariantContext buffer[] = new VariantContext[vcfInputs.length]; VariantContext prev[] = new VariantContext[vcfInputs.length]; for (;;) { VariantContext smallest = null; //refill buffer for (int i = 0; i < vcfInputs.length; ++i) { if (buffer[i] == null && vcfInputs[i] != null) { if (vcfInputs[i].hasNext()) { buffer[i] = vcfInputs[i].peek(); /* check data are sorted */ if (prev[i] != null && ctxComparator.compare(prev[i], buffer[i]) > 0) { return wrapException("Input " + (i + 1) + "/2 is not sorted" + (((i == 0 && dict0 == null) || (i == 1 && dict1 == null)) ? "on chrom/pos/ref" : "on sequence dictionary") + ". got\n" + buffer[i] + "\nafter\n" + prev[i]); } } else { vcfInputs[i].close(); vcfInputs[i] = null; } } if (buffer[i] != null) { if (smallest == null || ctxComparator.compare(buffer[i], smallest) < 0) { smallest = buffer[i]; } } } if (smallest == null) break; VariantContext ctx0 = null; VariantContext ctx1 = null; Interval interval = null; if (buffer[0] != null && ctxComparator.compare(buffer[0], smallest) == 0) { prev[0] = progress.watch(vcfInputs[0].next()); ctx0 = prev[0]; buffer[0] = null; interval = new Interval(ctx0.getContig(), ctx0.getStart(), ctx0.getEnd()); } if (buffer[1] != null && ctxComparator.compare(buffer[1], smallest) == 0) { prev[1] = progress.watch(vcfInputs[1].next()); ctx1 = prev[1]; buffer[1] = null; interval = new Interval(ctx1.getContig(), ctx1.getStart(), ctx1.getEnd()); } boolean in_capture = true; if (capture != null && interval != null) { in_capture = capture.containsOverlapping(interval); } for (final String sampleName : sample2info.keySet()) { final Counter<Category> sampleInfo = sample2info.get(sampleName); Genotype g0 = (ctx0 == null ? null : ctx0.getGenotype(sampleName)); Genotype g1 = (ctx1 == null ? null : ctx1.getGenotype(sampleName)); if (g0 != null && (g0.isNoCall() || !g0.isAvailable())) g0 = null; if (g1 != null && (g1.isNoCall() || !g1.isAvailable())) g1 = null; if (g0 == null && g1 == null) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.both_missing); continue; } else if (g0 != null && g1 == null) { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_only_1); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1); if (ctx0.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1_indel); } else if (ctx0.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1_snp); } continue; } else if (g0 == null && g1 != null) { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_only_2); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2); if (ctx1.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2_indel); } else if (ctx1.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2_snp); } continue; } else { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_both); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context); if (ctx0.isIndel() && ctx1.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_indel); } else if (ctx0.isSNP() && ctx1.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_snp); } if ((ctx0.hasID() && !ctx1.hasID()) || (!ctx0.hasID() && ctx1.hasID()) || (ctx0.hasID() && ctx1.hasID() && !ctx0.getID().equals(ctx1.getID()))) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_discordant_id); } if (g0.sameGenotype(g1)) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same); if (g0.isHomRef()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_hom_ref); } if (g0.isHomVar()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_hom_var); } else if (g0.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_het); } } else { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant); if (g0.isHom() && g1.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_hom1_het2); } else if (g0.isHet() && g1.isHom()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_het1_hom2); } else if (g0.isHom() && g1.isHom()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_hom1_hom2); } else if (g0.isHet() && g1.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_het1_het2); } else { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_others); } } } } } progress.finish(); pw = openFileOrStdoutAsPrintStream(); pw.print("#Sample"); for (Category c : Category.values()) { pw.print('\t'); pw.print(c.name()); } pw.println(); for (String sample : sample2info.keySet()) { Counter<Category> count = sample2info.get(sample); pw.print(sample); for (Category c : Category.values()) { pw.print('\t'); pw.print(count.count(c)); } pw.println(); if (pw.checkError()) break; } pw.flush(); if (exampleOut != null) { exampleOut.writeEndElement(); exampleOut.writeEndDocument(); exampleOut.flush(); exampleOut.close(); } return RETURN_OK; } catch (Exception err) { return wrapException(err); } finally { if (getOutputFile() != null) CloserUtil.close(pw); CloserUtil.close(exampleWriter); } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException { if (theDt == null || theDt.getValue() == null) { return;/*from w w w .j a v a 2 s .co m*/ } boolean firstElement = true; for (XMLEvent event : theDt.getValue()) { switch (event.getEventType()) { case XMLStreamConstants.ATTRIBUTE: Attribute attr = (Attribute) event; if (isBlank(attr.getName().getPrefix())) { if (isBlank(attr.getName().getNamespaceURI())) { theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue()); } else { theEventWriter.writeAttribute(attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } } else { theEventWriter.writeAttribute(attr.getName().getPrefix(), attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } break; case XMLStreamConstants.CDATA: theEventWriter.writeCData(((Characters) event).getData()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: String data = ((Characters) event).getData(); theEventWriter.writeCharacters(data); break; case XMLStreamConstants.COMMENT: theEventWriter.writeComment(((Comment) event).getText()); break; case XMLStreamConstants.END_ELEMENT: theEventWriter.writeEndElement(); break; case XMLStreamConstants.ENTITY_REFERENCE: EntityReference er = (EntityReference) event; theEventWriter.writeEntityRef(er.getName()); break; case XMLStreamConstants.NAMESPACE: Namespace ns = (Namespace) event; theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI()); break; case XMLStreamConstants.START_ELEMENT: StartElement se = event.asStartElement(); if (firstElement) { if (StringUtils.isBlank(se.getName().getPrefix())) { String namespaceURI = se.getName().getNamespaceURI(); if (StringUtils.isBlank(namespaceURI)) { namespaceURI = "http://www.w3.org/1999/xhtml"; } theEventWriter.writeStartElement(se.getName().getLocalPart()); theEventWriter.writeDefaultNamespace(namespaceURI); } else { String prefix = se.getName().getPrefix(); String namespaceURI = se.getName().getNamespaceURI(); theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI); theEventWriter.writeNamespace(prefix, namespaceURI); } firstElement = false; } else { if (isBlank(se.getName().getPrefix())) { if (isBlank(se.getName().getNamespaceURI())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); } else { if (StringUtils.isBlank(se.getName().getPrefix())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI()); } else { theEventWriter.writeStartElement(se.getName().getNamespaceURI(), se.getName().getLocalPart()); } } } else { theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(), se.getName().getNamespaceURI()); } for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext();) { Attribute next = (Attribute) attrIter.next(); theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue()); } } break; case XMLStreamConstants.DTD: case XMLStreamConstants.END_DOCUMENT: case XMLStreamConstants.ENTITY_DECLARATION: case XMLStreamConstants.NOTATION_DECLARATION: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.START_DOCUMENT: break; } } }
From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java
private void sparqlQuery(String sparql, TripleStore ts, Map<String, String[]> params, String pathInfo, HttpServletResponse res) throws Exception { if (sparql == null) { Map err = error(SC_BAD_REQUEST, "No query specified.", null); output(err, params, pathInfo, res); return;//from w w w. j ava2 s .co m } else { log.info("sparql: " + sparql); } // sparql query BindingIterator objs = ts.sparqlSelect(sparql); // start output String sparqlNS = "http://www.w3.org/2005/sparql-results#"; res.setContentType("application/sparql-results+xml"); OutputStream out = res.getOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter stream = factory.createXMLStreamWriter(out); stream.setDefaultNamespace(sparqlNS); stream.writeStartDocument(); stream.writeStartElement("sparql"); // output bindings boolean headerWritten = false; while (objs.hasNext()) { Map<String, String> binding = objs.nextBinding(); // write header on first binding if (!headerWritten) { Iterator<String> it = binding.keySet().iterator(); stream.writeStartElement("head"); while (it.hasNext()) { String k = it.next(); stream.writeStartElement("variable"); stream.writeAttribute("name", k); stream.writeEndElement(); } stream.writeEndElement(); stream.writeStartElement("results"); // ordered='false' distinct='false' headerWritten = true; } stream.writeStartElement("result"); Iterator<String> it = binding.keySet().iterator(); while (it.hasNext()) { String k = it.next(); String v = binding.get(k); stream.writeStartElement("binding"); stream.writeAttribute("name", k); String type = null; if (v.startsWith("\"") && v.endsWith("\"")) { type = "literal"; v = v.substring(1, v.length() - 1); } else if (v.startsWith("_:")) { type = "bnode"; v = v.substring(2); } else { type = "uri"; } stream.writeStartElement(type); stream.writeCharacters(v); stream.writeEndElement(); stream.writeEndElement(); } stream.writeEndElement(); } // finish output stream.writeEndElement(); stream.writeEndDocument(); stream.flush(); stream.close(); }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException { StringWriter stringWriter = new StringWriter(); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlStreamWriter; try {// w ww .j a va2 s . c o m xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter); xmlStreamWriter.writeStartDocument(); xmlStreamWriter.writeStartElement("root"); xmlStreamWriter.writeAttribute("url", getUrl()); // xmlStreamWriter.writeAttribute("level", // String.valueOf(getLevel())); process(xmlStreamWriter, getUrl(), getLevel()); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.flush(); xmlStreamWriter.close(); } catch (XMLStreamException e) { throw new PipeRunException(this, "XMLStreamException", e); } catch (DomBuilderException e) { throw new PipeRunException(this, "DomBuilderException", e); } catch (XPathExpressionException e) { throw new PipeRunException(this, "XPathExpressionException", e); } return new PipeRunResult(getForward(), stringWriter.getBuffer().toString()); }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
public void process(XMLStreamWriter xmlStreamWriter, String cUrl, int cLevel) throws XMLStreamException, DomBuilderException, XPathExpressionException { String html;//from ww w.jav a 2 s. com try { html = getHtml(cUrl); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting html", e, true); html = null; } if (html != null) { Collection<String> c = XmlUtils.evaluateXPathNodeSet(html, "html/body/ul/li/a/@href"); if (c != null) { for (Iterator<String> it = c.iterator(); it.hasNext();) { String token = it.next(); if (token.equals("../")) { // skip reference to parent directory } else if (cLevel == 0 && !token.equals("BW/") && !token.equals("SOA/")) { skipDir(xmlStreamWriter, token); // } else if (cLevel == 1 && // !token.startsWith("Customer")) { // skipDir(xmlStreamWriter, token); } else if (cLevel == 2 && (token.equals("branches/") || token.equals("tags/")) && c.contains("trunk/")) { skipDir(xmlStreamWriter, token); } else if (cLevel == 3 && !token.equals("src/") && c.contains("src/") && !token.equals("release/")) { skipDir(xmlStreamWriter, token); // } else if (cLevel == 5 && token.endsWith("/")) { // skipDir(xmlStreamWriter, token); } else { String newUrl = cUrl + token; boolean dir = false; if (token.endsWith("/")) { dir = true; } if (dir) { xmlStreamWriter.writeStartElement("dir"); xmlStreamWriter.writeAttribute("name", skipLastCharacter(token)); // xmlStreamWriter.writeAttribute("level", // String.valueOf(cLevel + 1)); if (cLevel == 1 || cLevel == 4) { addCommit(xmlStreamWriter, newUrl); } process(xmlStreamWriter, newUrl, cLevel + 1); } else { xmlStreamWriter.writeStartElement("file"); xmlStreamWriter.writeAttribute("name", token); if (cLevel > 5) { if (token.endsWith(".jmsDest")) { addFileContent(xmlStreamWriter, newUrl, "jmsDest"); } if (token.endsWith(".jmsDestConf")) { addFileContent(xmlStreamWriter, newUrl, "jmsDestConf"); } if (token.endsWith(".composite")) { addFileContent(xmlStreamWriter, newUrl, "composite"); } if (token.endsWith(".process")) { addFileContent(xmlStreamWriter, newUrl, "process"); } if (token.equals("defaultVars.substvar")) { addFileContent(xmlStreamWriter, newUrl, "substVar"); } } } xmlStreamWriter.writeEndElement(); } } } } }