private void testIsNotRemovedAndRetainsValue( String description, AttributeTag creatorTag, String creator, Attribute privateAttribute, String expectValue) throws DicomException { AttributeList list = new AttributeList(); { Attribute a = new LongStringAttribute(creatorTag); a.addValue(creator); list.put(a); } list.put(privateAttribute); AttributeTag privateTag = privateAttribute.getTag(); list.removeUnsafePrivateAttributes(); assertTrue("Checking Creator is not removed", list.get(creatorTag) != null); assertEquals( "Checking Creator retains value", creator, Attribute.getDelimitedStringValuesOrEmptyString(list, creatorTag)); assertTrue("Checking " + description + " is not removed", list.get(privateTag) != null); assertEquals( "Checking " + description + " retains value", expectValue, Attribute.getDelimitedStringValuesOrEmptyString(list, privateTag)); }
/** * Adds an attribute to the list of attributes * * @param attr the attribute to add to the list */ /*package*/ public final void add(Attribute attr) { // if an attribute with same tag exists, replace it for (int i = 0; i < attributes.length; i++) { if (attributes[i].getTag() == attr.getTag()) { attributes[i] = attr; return; } } // add the new attribute at the end of the list Attribute[] temp = new Attribute[attributes.length + 1]; System.arraycopy(attributes, 0, temp, 0, attributes.length); attributes = temp; attributes[attributes.length - 1] = attr; }
/** * @param list * @param document * @param parent */ void addAttributesFromListToNode(AttributeList list, Document document, Node parent) { DicomDictionary dictionary = list.getDictionary(); Iterator i = list.values().iterator(); while (i.hasNext()) { Attribute attribute = (Attribute) i.next(); AttributeTag tag = attribute.getTag(); String elementName = dictionary.getNameFromTag(tag); if (elementName == null) { elementName = makeElementNameFromHexadecimalGroupElementValues(tag); } Node node = document.createElement(elementName); parent.appendChild(node); { Attr attr = document.createAttribute("group"); attr.setValue(HexDump.shortToPaddedHexString(tag.getGroup())); node.getAttributes().setNamedItem(attr); } { Attr attr = document.createAttribute("element"); attr.setValue(HexDump.shortToPaddedHexString(tag.getElement())); node.getAttributes().setNamedItem(attr); } { Attr attr = document.createAttribute("vr"); attr.setValue(ValueRepresentation.getAsString(attribute.getVR())); node.getAttributes().setNamedItem(attr); } if (attribute instanceof SequenceAttribute) { int count = 0; Iterator si = ((SequenceAttribute) attribute).iterator(); while (si.hasNext()) { SequenceItem item = (SequenceItem) si.next(); Node itemNode = document.createElement("Item"); Attr numberAttr = document.createAttribute("number"); numberAttr.setValue(Integer.toString(++count)); itemNode.getAttributes().setNamedItem(numberAttr); node.appendChild(itemNode); addAttributesFromListToNode(item.getAttributeList(), document, itemNode); } } else { // Attr attr = document.createAttribute("value"); // attr.setValue(attribute.getDelimitedStringValuesOrEmptyString()); // node.getAttributes().setNamedItem(attr); // node.appendChild(document.createTextNode(attribute.getDelimitedStringValuesOrEmptyString())); String values[] = null; try { values = attribute.getStringValues(); } catch (DicomException e) { // e.printStackTrace(System.err); } if (values != null) { for (int j = 0; j < values.length; ++j) { Node valueNode = document.createElement("value"); Attr numberAttr = document.createAttribute("number"); numberAttr.setValue(Integer.toString(j + 1)); valueNode.getAttributes().setNamedItem(numberAttr); valueNode.appendChild(document.createTextNode(values[j])); node.appendChild(valueNode); } } } } }