List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
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 . jav a 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.armatiek.xslweb.serializer.RequestSerializer.java
private void dataElement(XMLStreamWriter xsw, String uri, String localName, String text) throws XMLStreamException { if (text == null) { return;//from ww w . j av a 2 s . c om } if (text.equals("")) { xsw.writeEmptyElement(uri, localName); } else { xsw.writeStartElement(uri, localName); xsw.writeCharacters(text); xsw.writeEndElement(); } }
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 www. j a v 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(); } } } } }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void skipDir(XMLStreamWriter xmlStreamWriter, String token) throws XMLStreamException { xmlStreamWriter.writeStartElement("dir"); xmlStreamWriter.writeAttribute("name", skipLastCharacter(token)); xmlStreamWriter.writeAttribute("skip", "true"); xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void addCommit(XMLStreamWriter xmlStreamWriter, String urlString) throws XMLStreamException { xmlStreamWriter.writeStartElement("commit"); try {/*from www .ja v a 2 s.c o m*/ String logReport = SvnUtils.getLogReport(urlString); String creator = XmlUtils.evaluateXPathNodeSetFirstElement(logReport, "log-report/log-item/creator-displayname"); xmlStreamWriter.writeAttribute("creator", creator); String date = XmlUtils.evaluateXPathNodeSetFirstElement(logReport, "log-report/log-item/date"); xmlStreamWriter.writeAttribute("date", date); } catch (Exception e) { error(xmlStreamWriter, "error occured during adding commit info", e, false); } xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void addFileContent(XMLStreamWriter xmlStreamWriter, String urlString, String type) throws XMLStreamException { xmlStreamWriter.writeStartElement("content"); xmlStreamWriter.writeAttribute("type", type); String content;/*from ww w .j av a2 s . c o m*/ try { content = getHtml(urlString); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting file content", e, true); content = null; } if (content != null) { Vector<String> warnMessage = new Vector<String>(); try { if (type.equals("jmsDest") || type.equals("jmsDestConf")) { // AMX - receive (for jmsInboundDest) Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/@name"); if (c1 != null && c1.size() > 0) { if (c1.size() > 1) { warnMessage.add("more then one resourceName found"); } String resourceName = (String) c1.iterator().next(); xmlStreamWriter.writeStartElement("resourceName"); xmlStreamWriter.writeCharacters(resourceName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceName found"); } Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/configuration/@jndiName"); if (c2 != null && c2.size() > 0) { if (c2.size() > 1) { warnMessage.add("more then one resourceJndiName found"); } String resourceJndiName = (String) c2.iterator().next(); xmlStreamWriter.writeStartElement("resourceJndiName"); xmlStreamWriter.writeCharacters(resourceJndiName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceJndiName found"); } } else if (type.equals("composite")) { // AMX - receive Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "composite/service/bindingAdjunct/property[@name='JmsInboundDestinationConfig']/@simpleValue"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsInboundDest"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsInboundDest found"); } // AMX - send Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "composite/reference/interface.wsdl/@wsdlLocation"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { String itn = c2it.next(); String wsdl = null; try { URL url = new URL(urlString); URL wsdlUrl = new URL(url, itn); wsdl = getHtml(wsdlUrl.toString()); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting wsdl file content", e, true); wsdl = null; } if (wsdl != null) { Collection<String> c3 = XmlUtils.evaluateXPathNodeSet(wsdl, // "definitions/service/port/targetAddress", // "concat(.,';',../../@name)"); "definitions/service/port/targetAddress"); if (c3 != null && c3.size() > 0) { for (Iterator<String> c3it = c3.iterator(); c3it.hasNext();) { xmlStreamWriter.writeStartElement("targetAddr"); xmlStreamWriter.writeCharacters(c3it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no targetAddr found"); } } else { warnMessage.add("wsdl [" + itn + "] not found"); } } } else { warnMessage.add("no wsdlLocation found"); } } else if (type.equals("process")) { // BW - receive Double d1 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config)"); if (d1 > 0) { Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config/sharedChannels/jmsChannel/JMSTo"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapEventSource"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapEventSource"); } } else { warnMessage.add("no soapEventSource found"); } // BW - send Double d2 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config)"); if (d2 > 0) { Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config/sharedChannels/jmsChannel/JMSTo"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapSendReceiveActivity"); xmlStreamWriter.writeCharacters(c2it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapSendReceiveActivity"); } } else { warnMessage.add("no soapSendReceiveActivity found"); } } else if (type.equals("substVar")) { String path = StringUtils .substringBeforeLast(StringUtils.substringAfterLast(urlString, "/defaultVars/"), "/"); Map<String, String> m1 = XmlUtils.evaluateXPathNodeSet(content, "repository/globalVariables/globalVariable", "name", "value"); if (m1 != null && m1.size() > 0) { for (Iterator<String> m1it = m1.keySet().iterator(); m1it.hasNext();) { Object key = m1it.next(); Object value = m1.get(key); xmlStreamWriter.writeStartElement("globalVariable"); xmlStreamWriter.writeAttribute("name", (String) key); xmlStreamWriter.writeAttribute("ref", "%%" + path + "/" + key + "%%"); xmlStreamWriter.writeCharacters((String) value); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no globalVariable found"); } /* * } else { content = XmlUtils.removeNamespaces(content); * xmlStreamWriter.writeCharacters(content); */ } } catch (Exception e) { error(xmlStreamWriter, "error occured during processing " + type + " file", e, true); } if (warnMessage.size() > 0) { xmlStreamWriter.writeStartElement("warnMessages"); for (int i = 0; i < warnMessage.size(); i++) { xmlStreamWriter.writeStartElement("warnMessage"); xmlStreamWriter.writeCharacters(warnMessage.elementAt(i)); xmlStreamWriter.writeEndElement(); } xmlStreamWriter.writeEndElement(); } } xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void error(XMLStreamWriter xmlStreamWriter, String msg, Throwable t, boolean printStackTrace) throws XMLStreamException { log.warn(msg, t);// w ww.j a va 2 s . com xmlStreamWriter.writeStartElement("errorMessage"); String errorMsg; if (printStackTrace) { StringWriter trace = new StringWriter(); t.printStackTrace(new PrintWriter(trace)); errorMsg = msg + ": " + trace; } else { errorMsg = msg + ": " + t.getMessage(); } xmlStreamWriter.writeCharacters(errorMsg); xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Outputs a 'documentation' section of the WSDL *//* w w w. jav a 2 s . co m*/ protected void documentation(XMLStreamWriter w) throws XMLStreamException { if (documentation != null) { w.writeStartElement(WSDL_NAMESPACE, "documentation"); w.writeCharacters(documentation); w.writeEndElement(); } }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Output the 'types' section of the WSDL * @param w//from ww w . j ava 2 s . c o m * @throws XMLStreamException * @throws IOException */ protected void types(XMLStreamWriter w) throws XMLStreamException, IOException, ConfigurationException { w.writeStartElement(WSDL_NAMESPACE, "types"); if (isUseIncludes()) { SchemaUtils.mergeRootXsdsGroupedByNamespaceToSchemasWithIncludes( SchemaUtils.getXsdsGroupedByNamespace(rootXsds, true), w); } else { SchemaUtils.mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes( pipeLine.getAdapter().getConfiguration().getClassLoader(), xsdsGroupedByNamespace, w); } w.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void message(XMLStreamWriter w, String root, Collection<QName> parts) throws XMLStreamException, IOException { if (!parts.isEmpty()) { w.writeStartElement(WSDL_NAMESPACE, "message"); w.writeAttribute("name", "Message_" + root); {/*from w w w .j ava 2s .c o m*/ for (QName part : parts) { w.writeEmptyElement(WSDL_NAMESPACE, "part"); w.writeAttribute("name", "Part_" + part.getLocalPart()); String type = part.getPrefix() + ":" + part.getLocalPart(); w.writeAttribute("element", type); } } w.writeEndElement(); } }