private void writeAsXML(Attributes attrs, OutputStream out) throws Exception { TransformerHandler th = getTransformerHandler(); th.getTransformer().setOutputProperty(OutputKeys.INDENT, xmlIndent ? "yes" : "no"); th.setResult(new StreamResult(out)); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(xmlIncludeKeyword); saxWriter.setIncludeNamespaceDeclaration(xmlIncludeNamespaceDeclaration); saxWriter.write(attrs); }
private void writeValues(VR vr, Object val, boolean bigEndian, SpecificCharacterSet cs) throws SAXException { if (vr.isStringType()) val = vr.toStrings(val, bigEndian, cs); int vm = vr.vmOf(val); for (int i = 0; i < vm; i++) { String s = vr.toString(val, bigEndian, i, null); addAttribute("number", Integer.toString(i + 1)); if (vr == VR.PN) { PersonName pn = new PersonName(s, true); startElement("PersonName"); writePNGroup("Alphabetic", pn, PersonName.Group.Alphabetic); writePNGroup("Ideographic", pn, PersonName.Group.Ideographic); writePNGroup("Phonetic", pn, PersonName.Group.Phonetic); endElement("PersonName"); } else { writeElement("Value", s); } } }
private void startElement(String name, String attrName, String attrValue) throws SAXException { addAttribute(attrName, attrValue); startElement(name); }
public static Attributes transform(Attributes ds, Templates templates, boolean includeNameSpaceDeclaration, boolean includeKeword, SetupTransformer setup) throws SAXException, TransformerConfigurationException { Attributes modify = new Attributes(); SAXWriter w = SAXTransformer.getSAXWriter( templates, modify, setup); w.setIncludeNamespaceDeclaration(includeNameSpaceDeclaration); w.setIncludeKeyword(includeKeword); w.write(ds); return modify; }
private static String writeXML(InputStream in, WadoURI main) throws Exception { File file = new File(main.getOutDir(), main.getOutFileName()+".xml"); TransformerHandler th = getTransformerHandler(main); th.getTransformer().setOutputProperty(OutputKeys.INDENT, main.xmlIndent ? "yes" : "no"); th.setResult(new StreamResult(file)); Attributes attrs= SAXReader.parse(in); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(main.xmlIncludeKeyword); saxWriter.write(attrs); return file.getAbsolutePath(); }
public void parse(DicomInputStream dis) throws IOException, TransformerConfigurationException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); TransformerHandler th = getTransformerHandler(); Transformer t = th.getTransformer(); t.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); t.setOutputProperty(OutputKeys.VERSION, xmlVersion); th.setResult(new StreamResult(System.out)); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(includeKeyword); saxWriter.setIncludeNamespaceDeclaration(includeNamespaceDeclaration); dis.setDicomInputHandler(saxWriter); dis.readDataset(-1, -1); }
SAXTransformer.getSAXWriter(new StreamResult(bOut)).write(instance.metadataList.get(0)); else try (JsonGenerator gen = Json.createGenerator(bOut)) {
private void writeAttribute(int tag, VR vr, Object value, SpecificCharacterSet cs, Attributes attrs) throws SAXException { if (TagUtils.isGroupLength(tag) || TagUtils.isPrivateCreator(tag)) return; String privateCreator = attrs.getPrivateCreator(tag); addAttributes(tag, vr, privateCreator); startElement("DicomAttribute"); if (value instanceof Value) writeAttribute((Value) value, attrs.bigEndian()); else if (!vr.isInlineBinary()) { writeValues(vr, value, attrs.bigEndian(), attrs.getSpecificCharacterSet(vr)); } else if (value instanceof byte[]) { writeInlineBinary(attrs.bigEndian() ? vr.toggleEndian((byte[]) value, true) : (byte[]) value); } else throw new IllegalArgumentException("vr: " + vr + ", value class: " + value.getClass()); endElement("DicomAttribute"); }
} else try { String privateCreator = attrs.getPrivateCreator(tag); addAttributes(tag, vr, privateCreator); startElement("DicomAttribute"); if (vr == VR.SQ || len == -1) { dis.readValue(dis, attrs); } else if (len > 0) { if (dis.isIncludeBulkDataURI()) { writeBulkData(dis.createBulkData(dis)); } else { byte[] b = dis.readValue(); attrs.setBytes(tag, vr, b); if (vr.isInlineBinary()) writeInlineBinary(dis.bigEndian() ? vr.toggleEndian(b, false) : b); else writeValues(vr, b, dis.bigEndian(), attrs.getSpecificCharacterSet(vr)); endElement("DicomAttribute"); } catch (SAXException e) { throw new IOException(e);
private static SAXWriter getSAXWriter(TransformerHandler th, Result result, SetupTransformer setup) { th.setResult(result); if (setup != null) setup.setup(th.getTransformer()); return new SAXWriter(th); }
private void writeBulkData(BulkData bulkData) throws SAXException { if (bulkData.getUUID() != null) addAttribute("uuid", bulkData.getUUID()); if (bulkData.getURI() != null) addAttribute("uri", bulkData.getURI()); startElement("BulkData"); endElement("BulkData"); }
private void addAttributes(int tag, VR vr, String privateCreator) { if (privateCreator != null) tag &= 0xffff00ff; if (includeKeyword) { String keyword = ElementDictionary.keywordOf(tag, privateCreator); if (keyword != null && !keyword.isEmpty()) addAttribute("keyword", keyword); } addAttribute("tag", TagUtils.toHexString(tag)); if (privateCreator != null) addAttribute("privateCreator", privateCreator); addAttribute("vr", vr.name()); }
th.setResult(new StreamResult(out)); Attributes attrs= SAXReader.parse(new ByteArrayInputStream(removeHeader(parts[i]).getBytes())); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(qidors.xmlIncludeKeyword); saxWriter.write(attrs);
public void parse(DicomInputStream dis) throws IOException, TransformerConfigurationException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); TransformerHandler th = getTransformerHandler(); Transformer t = th.getTransformer(); t.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); t.setOutputProperty(OutputKeys.VERSION, xmlVersion); th.setResult(new StreamResult(System.out)); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(includeKeyword); saxWriter.setIncludeNamespaceDeclaration(includeNamespaceDeclaration); dis.setDicomInputHandler(saxWriter); dis.readDataset(-1, -1); }
SAXTransformer.getSAXWriter(new StreamResult(bOut)).write(instance.metadataList.get(0)); else try (JsonGenerator gen = Json.createGenerator(bOut)) {
private void writeAsXML(Attributes attrs, OutputStream out) throws Exception { TransformerHandler th = getTransformerHandler(); th.getTransformer().setOutputProperty(OutputKeys.INDENT, xmlIndent ? "yes" : "no"); th.setResult(new StreamResult(out)); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(xmlIncludeKeyword); saxWriter.setIncludeNamespaceDeclaration(xmlIncludeNamespaceDeclaration); saxWriter.write(attrs); }