List of usage examples for javax.xml.stream XMLStreamWriter close
public void close() throws XMLStreamException;
From source file:DDTReporter.java
/** * Report Generator logic/*from ww w . ja v a2 s .c o m*/ * @param description * @param emailBody */ public void generateDefaultReport(String description, String emailBody) { if (getDDTests().size() < 1) { System.out.println("No Test Steps to report on. Report Generation aborted."); return; } String extraEmailBody = (isBlank(emailBody) ? "" : "<br>" + emailBody) + "</br>"; // Create the values for the various top sections of the report // Project, Module, Mode, Summary String[][] environmentItems = getEnvironmentItems(); String projectName = settings.projectName(); if (isBlank(projectName)) projectName = "Selenium Based Java DDT Automation Project"; String moduleName = description; if (isBlank(moduleName)) moduleName = "Selenium based Java DDT Test Results"; projectName = Util.sq(projectName); moduleName = Util.sq(moduleName); String durationBlurb = " (Session duration: " + sessionDurationString() + ", Reported tests duration: " + durationString() + ")"; // @TODO - When documentation mode becomes available, weave that in... using "Documentation" instead of "Results" String mode = "Test Results as of " + new SimpleDateFormat("HH:mm:ss - yyyy, MMMM dd").format(new Date()) + durationBlurb; String osInfo = environmentItems[0][1]; String envInfo = environmentItems[1][1]; String javaInfo = environmentItems[2][1]; String userInfo = environmentItems[3][1]; String summary = sectionSummary() + " " + sessionSummary(); // String summarizing the scope of this report section String rangeClause = " Reportable steps included in this report: " + firstReportStep() + " thru " + (lastReportStep()); if (lastReportStep() != firstReportStep() || isNotBlank(settings.dontReportActions())) { rangeClause += " - Actions excluded from reporting: " + settings.dontReportActions().replace(",", ", "); } String underscore = "<br>==================<br>"; // Assuming html contents of email message String emailSubject = "Test Results for Project: " + projectName + ", Section: " + moduleName; summary += rangeClause; summary += " - Item status included: " + settings.statusToReport().replace(",", ", ") + " (un-reported action steps not counted.)"; String fileName = new SimpleDateFormat("yyyyMMdd-HHmmss.SSS").format(new Date()) + ".xml"; String folder = settings.reportsFolder() + Util.asSafePathString(description); // Ensure the folder exists - if no exception is thrown, it does! File tmp = Util.setupReportFolder(DDTSettings.asValidOSPath(folder, true)); String fileSpecs = folder + File.separator + DDTSettings.asValidOSPath(fileName, true); String extraBlurb = ""; int nReportableSteps = 0; XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = factory.createXMLStreamWriter(new FileWriter(fileSpecs)); writer.writeStartDocument(); writer.writeCharacters("\n"); // build the xml hierarchy - the innermost portion of it are the steps (see below) writeStartElement(writer, "Project", new String[] { "name" }, new String[] { projectName }); writeStartElement(writer, "Module", new String[] { "name" }, new String[] { moduleName }); writeStartElement(writer, "Mode", new String[] { "name" }, new String[] { mode }); writeStartElement(writer, "OperatingSystem", new String[] { "name" }, new String[] { osInfo }); writeStartElement(writer, "Environment", new String[] { "name" }, new String[] { envInfo }); writeStartElement(writer, "Java", new String[] { "name" }, new String[] { javaInfo }); writeStartElement(writer, "User", new String[] { "name" }, new String[] { userInfo }); writeStartElement(writer, "Summary", new String[] { "name" }, new String[] { summary }); writeStartElement(writer, "Steps"); // Failures will be added to the mailed message body - we construct it here. int nFailures = 0; for (DDTReportItem t : getDDTests()) { // Only report the statuses indicated for reporting in the settings. if (!(settings.statusToReport().contains(t.getStatus()))) continue; String[] attributes = new String[] { "Id", "Name", "Status", "ErrDesc" }; String[] values = new String[] { t.paddedReportedStepNumber(), t.getUserReport(), t.getStatus(), t.getErrors() }; writeStartElement(writer, "Step", attributes, values); // If step failed, add its description to the failedTestsSummary. if (t.hasErrors()) { nFailures++; String failureBlurb = underscore + "Failure " + nFailures + " - Step: " + t.paddedReportedStepNumber() + underscore; failedTestsSummary .add(failureBlurb + t.toString() + "<p>Errors:</p>" + t.errorsAsHtml() + "<br>"); } // If step has any events to report - list those if (t.hasEventsToReport()) { String eventsToReport = settings.eventsToReport(); writeStartElement(writer, "Events"); for (TestEvent e : t.getEvents()) { if (eventsToReport.contains(e.getType().toString())) { writeStartElement(writer, "Event", new String[] { "name" }, new String[] { e.toString() }); writeEndElement(writer); } } writeEndElement(writer); // step's events } writeEndElement(writer); // step nReportableSteps++; } // If no reportable steps recorded, write a step element to indicate so... if (nReportableSteps < 1) { extraBlurb = "*** No Reportable Steps encountered ***"; String[] attributes = new String[] { "Id", "Name", "Status", "ErrDesc" }; String[] values = new String[] { "------", extraBlurb, "", "" }; writeStartElement(writer, "Step", attributes, values); writeEndElement(writer); // step } // close each of the xml hierarchy elements in reverse order writeEndElement(writer); // steps writeEndElement(writer); // summary writeEndElement(writer); // user writeEndElement(writer); // java writeEndElement(writer); // environment writeEndElement(writer); // operating system writeEndElement(writer); // mode writeEndElement(writer); // module writeEndElement(writer); // project writer.writeEndDocument(); writer.flush(); writer.close(); try { transformXmlFileToHtml(fileSpecs, folder); } catch (Exception e) { System.out.println("Error encountered while transofrming xml file to html.\nReport not generated."); e.printStackTrace(); return; } reportGenerated = true; } catch (XMLStreamException e) { System.out.println( "XML Stream Exception Encountered while transforming xml file to html.\nReport not generated."); e.printStackTrace(); return; } catch (IOException e) { System.out.println( "IO Exception Encountered while transforming xml file to html.\nReport not generated."); e.printStackTrace(); return; } if (isBlank(settings.emailRecipients())) { System.out.println("Empty Email Recipients List - Test Results not emailed. Report Generated"); } else { String messageBody = "Attached is a summary of test results run titled " + Util.dq(description) + "<br>" + (isBlank(extraBlurb) ? "" : "<br>" + extraBlurb) + extraEmailBody; try { Email.sendMail(emailSubject, messageBody, fileSpecs.replace(".xml", ".html"), failedTestsSummary); System.out.println("Report Generated. Report Results Emailed to: " + settings.emailRecipients()); } catch (MessagingException e) { System.out.println( "Messaging Exception Encountered while emailing test results.\nResults not sent, Report generated."); e.printStackTrace(); } } reset(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeBundleToWriterDstu2(Bundle theBundle, XMLStreamWriter theEventWriter) throws XMLStreamException { theEventWriter.writeStartElement("Bundle"); theEventWriter.writeDefaultNamespace(FHIR_NS); writeOptionalTagWithValue(theEventWriter, "id", theBundle.getId().getIdPart()); InstantDt updated = (InstantDt) theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED); IdDt bundleId = theBundle.getId();//from w w w .j a v a 2 s . c om if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) { theEventWriter.writeStartElement("meta"); writeOptionalTagWithValue(theEventWriter, "versionId", bundleId.getVersionIdPart()); if (updated != null) { writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString()); } theEventWriter.writeEndElement(); } writeOptionalTagWithValue(theEventWriter, "type", theBundle.getType().getValue()); writeOptionalTagWithValue(theEventWriter, "total", theBundle.getTotalResults().getValueAsString()); writeBundleResourceLink(theEventWriter, "first", theBundle.getLinkFirst()); writeBundleResourceLink(theEventWriter, "previous", theBundle.getLinkPrevious()); writeBundleResourceLink(theEventWriter, "next", theBundle.getLinkNext()); writeBundleResourceLink(theEventWriter, "last", theBundle.getLinkLast()); writeBundleResourceLink(theEventWriter, "self", theBundle.getLinkSelf()); for (BundleEntry nextEntry : theBundle.getEntries()) { theEventWriter.writeStartElement("entry"); boolean deleted = false; if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) { deleted = true; } writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate()); if (nextEntry.getResource() != null && nextEntry.getResource().getId().getBaseUrl() != null) { writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue()); } IResource resource = nextEntry.getResource(); if (resource != null && !resource.isEmpty() && !deleted) { theEventWriter.writeStartElement("resource"); encodeResourceToXmlStreamWriter(resource, theEventWriter, false, true); theEventWriter.writeEndElement(); // content } else { ourLog.debug("Bundle entry contains null resource"); } if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) { theEventWriter.writeStartElement("search"); writeOptionalTagWithValue(theEventWriter, "mode", nextEntry.getSearchMode().getValueAsString()); writeOptionalTagWithValue(theEventWriter, "score", nextEntry.getScore().getValueAsString()); theEventWriter.writeEndElement(); // IResource nextResource = nextEntry.getResource(); } if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) { theEventWriter.writeStartElement("request"); writeOptionalTagWithValue(theEventWriter, "method", nextEntry.getTransactionMethod().getValue()); writeOptionalTagWithValue(theEventWriter, "url", nextEntry.getLinkSearch().getValue()); theEventWriter.writeEndElement(); } if (deleted) { theEventWriter.writeStartElement("deleted"); writeOptionalTagWithValue(theEventWriter, "type", nextEntry.getId().getResourceType()); writeOptionalTagWithValue(theEventWriter, "id", nextEntry.getId().getIdPart()); writeOptionalTagWithValue(theEventWriter, "versionId", nextEntry.getId().getVersionIdPart()); writeOptionalTagWithValue(theEventWriter, "instant", nextEntry.getDeletedAt().getValueAsString()); theEventWriter.writeEndElement(); } theEventWriter.writeEndElement(); // entry } theEventWriter.writeEndElement(); theEventWriter.close(); }
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 ww w. j a va 2s . c o 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:ca.uhn.fhir.parser.XmlParser.java
private void encodeBundleToWriterDstu1(Bundle theBundle, XMLStreamWriter eventWriter) throws XMLStreamException { eventWriter.writeStartElement("feed"); eventWriter.writeDefaultNamespace(ATOM_NS); writeTagWithTextNode(eventWriter, "title", theBundle.getTitle()); writeTagWithTextNode(eventWriter, "id", theBundle.getBundleId()); writeAtomLink(eventWriter, Constants.LINK_SELF, theBundle.getLinkSelf()); writeAtomLink(eventWriter, Constants.LINK_FIRST, theBundle.getLinkFirst()); writeAtomLink(eventWriter, Constants.LINK_PREVIOUS, theBundle.getLinkPrevious()); writeAtomLink(eventWriter, Constants.LINK_NEXT, theBundle.getLinkNext()); writeAtomLink(eventWriter, Constants.LINK_LAST, theBundle.getLinkLast()); writeAtomLink(eventWriter, Constants.LINK_FHIR_BASE, theBundle.getLinkBase()); if (theBundle.getTotalResults().getValue() != null) { eventWriter.writeStartElement("os", "totalResults", OPENSEARCH_NS); eventWriter.writeNamespace("os", OPENSEARCH_NS); eventWriter.writeCharacters(theBundle.getTotalResults().getValue().toString()); eventWriter.writeEndElement();/*from ww w. j a v a 2 s . c o m*/ } writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated()); writeAuthor(eventWriter, theBundle); writeCategories(eventWriter, theBundle.getCategories()); for (BundleEntry nextEntry : theBundle.getEntries()) { boolean deleted = false; if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) { deleted = true; eventWriter.writeStartElement("at", "deleted-entry", TOMBSTONES_NS); eventWriter.writeNamespace("at", TOMBSTONES_NS); if (nextEntry.getDeletedResourceId().isEmpty()) { writeOptionalAttribute(eventWriter, "ref", nextEntry.getId().getValueAsString()); } else { writeOptionalAttribute(eventWriter, "ref", nextEntry.getDeletedResourceId().getValueAsString()); } writeOptionalAttribute(eventWriter, "when", nextEntry.getDeletedAt().getValueAsString()); if (nextEntry.getDeletedByEmail().isEmpty() == false || nextEntry.getDeletedByName().isEmpty() == false) { eventWriter.writeStartElement(TOMBSTONES_NS, "by"); if (nextEntry.getDeletedByName().isEmpty() == false) { eventWriter.writeStartElement(TOMBSTONES_NS, "name"); eventWriter.writeCharacters(nextEntry.getDeletedByName().getValue()); eventWriter.writeEndElement(); } if (nextEntry.getDeletedByEmail().isEmpty() == false) { eventWriter.writeStartElement(TOMBSTONES_NS, "email"); eventWriter.writeCharacters(nextEntry.getDeletedByEmail().getValue()); eventWriter.writeEndElement(); } eventWriter.writeEndElement(); } if (nextEntry.getDeletedComment().isEmpty() == false) { eventWriter.writeStartElement(TOMBSTONES_NS, "comment"); eventWriter.writeCharacters(nextEntry.getDeletedComment().getValue()); eventWriter.writeEndElement(); } } else { eventWriter.writeStartElement("entry"); } writeOptionalTagWithTextNode(eventWriter, "title", nextEntry.getTitle()); if (!deleted) { if (nextEntry.getId().isEmpty() == false) { writeTagWithTextNode(eventWriter, "id", nextEntry.getId()); } else { writeTagWithTextNode(eventWriter, "id", nextEntry.getResource().getId()); } } writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated()); writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished()); writeAuthor(eventWriter, nextEntry); writeCategories(eventWriter, nextEntry.getCategories()); if (!nextEntry.getLinkSelf().isEmpty()) { writeAtomLink(eventWriter, "self", nextEntry.getLinkSelf()); } if (!nextEntry.getLinkAlternate().isEmpty()) { writeAtomLink(eventWriter, "alternate", nextEntry.getLinkAlternate()); } if (!nextEntry.getLinkSearch().isEmpty()) { writeAtomLink(eventWriter, "search", nextEntry.getLinkSearch()); } IResource resource = nextEntry.getResource(); if (resource != null && !resource.isEmpty() && !deleted) { eventWriter.writeStartElement("content"); eventWriter.writeAttribute("type", "text/xml"); encodeResourceToXmlStreamWriter(resource, eventWriter, false, true); eventWriter.writeEndElement(); // content } else { ourLog.debug("Bundle entry contains null resource"); } if (!nextEntry.getSummary().isEmpty()) { eventWriter.writeStartElement("summary"); eventWriter.writeAttribute("type", "xhtml"); encodeXhtml(nextEntry.getSummary(), eventWriter); eventWriter.writeEndElement(); } eventWriter.writeEndElement(); // entry } eventWriter.writeEndElement(); eventWriter.close(); }
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. ja va 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: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 {//from ww w. j a v a 2 s.c om 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.soap.Wsdl.java
/** * Writes the WSDL to an output stream//www . jav a 2s . c om * @param out * @param servlet The servlet what is used as the web service (because this needs to be present in the WSDL) * @throws XMLStreamException * @throws IOException */ public void wsdl(OutputStream out, String servlet) throws XMLStreamException, IOException, ConfigurationException, NamingException { XMLStreamWriter w = WsdlUtils.getWriter(out, isIndent()); w.writeStartDocument(XmlUtils.STREAM_FACTORY_ENCODING, "1.0"); w.setPrefix(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.setPrefix(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.setPrefix(soapPrefix, soapNamespace); if (jmsActive) { if (esbSoap) { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, ESB_SOAP_JMS_NAMESPACE); w.setPrefix(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } else { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, SOAP_JMS_NAMESPACE); } } w.setPrefix(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.setPrefix(prefix, namespaceByPrefix.get(prefix)); } w.writeStartElement(WSDL_NAMESPACE, "definitions"); { w.writeNamespace(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.writeNamespace(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.writeNamespace(soapPrefix, soapNamespace); if (esbSoap) { w.writeNamespace(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } w.writeNamespace(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.writeNamespace(prefix, namespaceByPrefix.get(prefix)); } w.writeAttribute("targetNamespace", getTargetNamespace()); documentation(w); types(w); messages(w); portType(w); binding(w); service(w, servlet); } w.writeEndDocument(); warnings(w); w.close(); }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
public static void main(String[] args) { logger.info("Starting application [ rtd ] ..."); try {//from ww w . j av a2 s. c o m config.addConfiguration( new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME))); HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT); EodDataProvider eodDataProvider = null; OutputStream out = new FileOutputStream(OUTPUT_FILENAME); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(out); eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME); writer.writeStartDocument("utf-8", "1.0"); writer.writeCharacters(NEWLINE); writer.writeComment("Test data for running DataScraper unit tests against"); writer.writeCharacters(NEWLINE); writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI); writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME); writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI); writer.writeCharacters(NEWLINE); serializeExchanges(eodDataProvider, writer); serializeSymbols(eodDataProvider, writer); serializeQuotes(eodDataProvider, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (ConfigurationException ce) { logger.error(ce.toString()); ce.printStackTrace(); } catch (Exception e) { logger.error(e.toString()); logger.error(e); } logger.info("Exiting application [ rtd ] ..."); }
From source file:org.activiti.bpmn.converter.BpmnXMLConverter.java
public byte[] convertToXML(BpmnModel model, String encoding) { try {/*from w w w . j av a 2 s .com*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLOutputFactory xof = XMLOutputFactory.newInstance(); OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding); XMLStreamWriter writer = xof.createXMLStreamWriter(out); XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer); DefinitionsRootExport.writeRootElement(model, xtw, encoding); SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw); PoolExport.writePools(model, xtw); for (Process process : model.getProcesses()) { if (process.getFlowElements().size() == 0 && process.getLanes().size() == 0) { // empty process, ignore it continue; } ProcessExport.writeProcess(process, xtw); for (FlowElement flowElement : process.getFlowElements()) { createXML(flowElement, model, xtw); } for (Artifact artifact : process.getArtifacts()) { createXML(artifact, model, xtw); } // end process element xtw.writeEndElement(); } BPMNDIExport.writeBPMNDI(model, xtw); // end definitions root element xtw.writeEndElement(); xtw.writeEndDocument(); xtw.flush(); outputStream.close(); xtw.close(); return outputStream.toByteArray(); } catch (Exception e) { LOGGER.error("Error writing BPMN XML", e); throw new XMLException("Error writing BPMN XML", e); } }
From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java
public byte[] convertToXML(DmnDefinition model, String encoding) { try {//from w ww. ja va 2s . com ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLOutputFactory xof = XMLOutputFactory.newInstance(); OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding); XMLStreamWriter writer = xof.createXMLStreamWriter(out); XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer); xtw.writeStartElement(ELEMENT_DEFINITIONS); xtw.writeDefaultNamespace(DMN_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_ID, model.getId()); if (StringUtils.isNotEmpty(model.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, model.getName()); } xtw.writeAttribute(ATTRIBUTE_NAMESPACE, MODEL_NAMESPACE); DmnXMLUtil.writeElementDescription(model, xtw); DmnXMLUtil.writeExtensionElements(model, xtw); for (ItemDefinition itemDefinition : model.getItemDefinitions()) { xtw.writeStartElement(ELEMENT_ITEM_DEFINITION); xtw.writeAttribute(ATTRIBUTE_ID, itemDefinition.getId()); if (StringUtils.isNotEmpty(itemDefinition.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, itemDefinition.getName()); } DmnXMLUtil.writeElementDescription(itemDefinition, xtw); DmnXMLUtil.writeExtensionElements(itemDefinition, xtw); xtw.writeStartElement(ELEMENT_TYPE_DEFINITION); xtw.writeCharacters(itemDefinition.getTypeDefinition()); xtw.writeEndElement(); xtw.writeEndElement(); } for (Decision decision : model.getDrgElements()) { xtw.writeStartElement(ELEMENT_DECISION); xtw.writeAttribute(ATTRIBUTE_ID, decision.getId()); if (StringUtils.isNotEmpty(decision.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, decision.getName()); } DmnXMLUtil.writeElementDescription(decision, xtw); DmnXMLUtil.writeExtensionElements(decision, xtw); DecisionTable decisionTable = decision.getDecisionTable(); xtw.writeStartElement(ELEMENT_DECISION_TABLE); xtw.writeAttribute(ATTRIBUTE_ID, decisionTable.getId()); if (decisionTable.getHitPolicy() != null) { xtw.writeAttribute(ATTRIBUTE_HIT_POLICY, decisionTable.getHitPolicy().toString()); } DmnXMLUtil.writeElementDescription(decisionTable, xtw); DmnXMLUtil.writeExtensionElements(decisionTable, xtw); for (InputClause clause : decisionTable.getInputs()) { xtw.writeStartElement(ELEMENT_INPUT_CLAUSE); if (StringUtils.isNotEmpty(clause.getId())) { xtw.writeAttribute(ATTRIBUTE_ID, clause.getId()); } if (StringUtils.isNotEmpty(clause.getLabel())) { xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel()); } DmnXMLUtil.writeElementDescription(clause, xtw); DmnXMLUtil.writeExtensionElements(clause, xtw); if (clause.getInputExpression() != null) { xtw.writeStartElement(ELEMENT_INPUT_EXPRESSION); xtw.writeAttribute(ATTRIBUTE_ID, clause.getInputExpression().getId()); if (StringUtils.isNotEmpty(clause.getInputExpression().getTypeRef())) { xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getInputExpression().getTypeRef()); } if (StringUtils.isNotEmpty(clause.getInputExpression().getText())) { xtw.writeStartElement(ELEMENT_TEXT); xtw.writeCharacters(clause.getInputExpression().getText()); xtw.writeEndElement(); } xtw.writeEndElement(); } xtw.writeEndElement(); } for (OutputClause clause : decisionTable.getOutputs()) { xtw.writeStartElement(ELEMENT_OUTPUT_CLAUSE); if (StringUtils.isNotEmpty(clause.getId())) { xtw.writeAttribute(ATTRIBUTE_ID, clause.getId()); } if (StringUtils.isNotEmpty(clause.getLabel())) { xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel()); } if (StringUtils.isNotEmpty(clause.getName())) { xtw.writeAttribute(ATTRIBUTE_NAME, clause.getName()); } if (StringUtils.isNotEmpty(clause.getTypeRef())) { xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getTypeRef()); } DmnXMLUtil.writeElementDescription(clause, xtw); DmnXMLUtil.writeExtensionElements(clause, xtw); xtw.writeEndElement(); } for (DecisionRule rule : decisionTable.getRules()) { xtw.writeStartElement(ELEMENT_RULE); if (StringUtils.isNotEmpty(rule.getId())) { xtw.writeAttribute(ATTRIBUTE_ID, rule.getId()); } DmnXMLUtil.writeElementDescription(rule, xtw); DmnXMLUtil.writeExtensionElements(rule, xtw); for (RuleInputClauseContainer container : rule.getInputEntries()) { xtw.writeStartElement(ELEMENT_INPUT_ENTRY); xtw.writeAttribute(ATTRIBUTE_ID, container.getInputEntry().getId()); xtw.writeStartElement(ELEMENT_TEXT); xtw.writeCharacters(container.getInputEntry().getText()); xtw.writeEndElement(); xtw.writeEndElement(); } for (RuleOutputClauseContainer container : rule.getOutputEntries()) { xtw.writeStartElement(ELEMENT_OUTPUT_ENTRY); xtw.writeAttribute(ATTRIBUTE_ID, container.getOutputEntry().getId()); xtw.writeStartElement(ELEMENT_TEXT); xtw.writeCharacters(container.getOutputEntry().getText()); xtw.writeEndElement(); xtw.writeEndElement(); } xtw.writeEndElement(); } xtw.writeEndElement(); xtw.writeEndElement(); } // end definitions root element xtw.writeEndElement(); xtw.writeEndDocument(); xtw.flush(); outputStream.close(); xtw.close(); return outputStream.toByteArray(); } catch (Exception e) { LOGGER.error("Error writing BPMN XML", e); throw new DmnXMLException("Error writing BPMN XML", e); } }