public void readDicomObject(DicomObject dcmObj) throws SAXException, IOException { parser.parse(file, new ContentHandlerAdapter(dcmObj)); }
@Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if ("attr".equals(qName)) { onEndElement(); } else if ("item".equals(qName)) { onEndItem(); } }
@Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { if ("attr".equals(qName)) { onStartElement(atts.getValue("tag"), atts.getValue("vr"), atts.getValue("src")); } else if ("item".equals(qName)) { onStartItem(atts.getValue("off"), atts.getValue("src")); } }
private void onEndItem() throws SAXException { switch (state) { case EXPECT_ELM: attrs = attrs.getParent(); break; case EXPECT_FRAG: DicomElement sq = sqStack.peek(); byte[] data = getValue(sq.vr(), null); sq.addFragment(data != null ? data : EMPTY_VALUE); sb.setLength(0); out.reset(); break; default: throw new IllegalStateException("state:" + state); } state = State.EXPECT_NEXT_ITEM; }
private byte[] getValue(VR vr, SpecificCharacterSet cs) throws SAXException { if (src == null) return vr.parseXMLValue(sb, out, true, cs); if (src.length() == 0) return EMPTY_VALUE; return readFromSrc(); }
private void onEndElement() throws SAXException { switch (state) { case EXPECT_VAL_OR_FIRST_ITEM: if (vr == VR.SQ) { attrs.putNull(tag, VR.SQ); } else { attrs.putBytes(tag, vr, getValue(vr, attrs.getSpecificCharacterSet()), false); sb.setLength(0); out.reset(); } break; case EXPECT_NEXT_ITEM: sqStack.pop(); break; default: throw new IllegalStateException("state:" + state); } state = State.EXPECT_ELM; }