/** * We are switching over to having a hash table for quick look * up of attributes, but up until now we haven't kept any * information in the Hashtable, so we now update the Hashtable. * Future additional attributes will update the Hashtable as * they are added. * @param numAtts */ private void switchOverToHash(int numAtts) { for (int index = 0; index < numAtts; index++) { String qName = super.getQName(index); Integer i = new Integer(index); m_indexFromQName.put(qName, i); // Add quick look-up to find with uri/local name pair String uri = super.getURI(index); String local = super.getLocalName(index); m_buff.setLength(0); m_buff.append('{').append(uri).append('}').append(local); String key = m_buff.toString(); m_indexFromQName.put(key, i); } }
/** * We are switching over to having a hash table for quick look * up of attributes, but up until now we haven't kept any * information in the Hashtable, so we now update the Hashtable. * Future additional attributes will update the Hashtable as * they are added. * @param numAtts */ private void switchOverToHash(int numAtts) { for (int index = 0; index < numAtts; index++) { String qName = super.getQName(index); Integer i = new Integer(index); m_indexFromQName.put(qName, i); // Add quick look-up to find with uri/local name pair String uri = super.getURI(index); String local = super.getLocalName(index); m_buff.setLength(0); m_buff.append('{').append(uri).append('}').append(local); String key = m_buff.toString(); m_indexFromQName.put(key, i); } }
public void endNode() { try { if (!children) { Element element = new DefaultElement((String)elementStack.pop()); for (int i = 0; i < attributes.getLength(); ++i) { element.addAttribute(attributes.getQName(i), attributes.getValue(i)); } writer.write(element); attributes.clear(); children = true; // node just closed is child of node on top of stack started = true; } else { startElement(); writer.endElement("", "", (String)elementStack.pop()); } } catch (SAXException e) { throw new StreamException(e); } catch (IOException e) { throw new StreamException(e); } }
/** * Test method for {@link XmlGeneratorUtils#addAttribute(AttributesImpl, String, String, Object)}. */ @Test public void testAddAttributeAttributesImplStringStringObject() { final AttributesImpl attributes = new AttributesImpl(); assertEquals(0, attributes.getLength()); XmlGeneratorUtils.addAttribute(attributes, "prefix", "localname", null); assertEquals(0, attributes.getLength()); XmlGeneratorUtils.addAttribute(attributes, "prefix", "localname", "value"); assertEquals(1, attributes.getLength()); assertEquals("localname", attributes.getLocalName(0)); assertEquals("prefix:localname", attributes.getQName(0)); assertEquals(NULL_NS_URI, attributes.getURI(0)); assertEquals("value", attributes.getValue(0)); }
/** * Test method for {@link XmlGeneratorUtils#addAttribute(AttributesImpl, String, Object)}. */ @Test public void testAddAttributeAttributesImplStringObject() { final AttributesImpl attributes = new AttributesImpl(); assertEquals(0, attributes.getLength()); XmlGeneratorUtils.addAttribute(attributes, "localname", null); assertEquals(0, attributes.getLength()); XmlGeneratorUtils.addAttribute(attributes, "localname", "value"); assertEquals(1, attributes.getLength()); assertEquals("localname", attributes.getLocalName(0)); assertEquals("localname", attributes.getQName(0)); assertEquals(XMLConstants.NULL_NS_URI, attributes.getURI(0)); assertEquals("value", attributes.getValue(0)); }
@Override public void removeAttribute(int index) { qNames.remove(super.getQName(index)); super.removeAttribute(index); }
@Override public void removeAttribute(int index) { qNames.remove(super.getQName(index)); super.removeAttribute(index); }
@Override public void removeAttribute(int index) { qNames.remove(super.getQName(index)); super.removeAttribute(index); }
@Override public void setQName(int index, String qName) { qNames.remove(super.getQName(index)); super.setQName(index, qName); }
@Override public void setQName(int index, String qName) { qNames.remove(super.getQName(index)); super.setQName(index, qName); }
@Override public void removeAttribute(int index) { qNames.remove(super.getQName(index)); super.removeAttribute(index); }
@Override public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { qNames.remove(super.getQName(index)); if (qNames.add(qName)) { super.setAttribute(index, uri, localName, qName, type, value); } else { handleDuplicate(qName, value); } }
@Override public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { qNames.remove(super.getQName(index)); if (qNames.add(qName)) { super.setAttribute(index, uri, localName, qName, type, value); } else { handleDuplicate(qName, value); } }
@Override public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { qNames.remove(super.getQName(index)); if (qNames.add(qName)) { super.setAttribute(index, uri, localName, qName, type, value); } else { handleDuplicate(qName, value); } }
@Override public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { qNames.remove(super.getQName(index)); if (qNames.add(qName)) { super.setAttribute(index, uri, localName, qName, type, value); } else { handleDuplicate(qName, value); } }
@Override public String getAttributePrefix(int index) { switch (state) { case StartTag: case EndTag: return getPrfix(tagInfo.atts.getQName(index)); case Payload: default: return payloadReader.getAttributePrefix(index); } }
private void set(AttributesImpl attrs, String uri, String localName, String qName, XmlAttributeType type, String value) { for (int i = 0, sz = attrs.getLength(); i < sz; i++) { if (Objects.equals(qName, attrs.getQName(i)) || Objects.equals(uri, attrs.getURI(i)) && Objects.equals(localName, attrs.getLocalName(i))) { attrs.setAttribute(i, uri, localName, qName, type.name(), value); return; } } attrs.addAttribute(uri, localName, qName, type.name(), value); } }
@Override public QName getAttributeName(int i) { switch (state) { case StartTag: case EndTag: return new QName(tagInfo.atts.getURI(i),tagInfo.atts.getLocalName(i),getPrfix(tagInfo.atts.getQName(i))); case Payload: default: return payloadReader.getAttributeName(i); } }
@Override public QName getAttributeName(int i) { switch (state) { case StartTag: case EndTag: return new QName(tagInfo.atts.getURI(i),tagInfo.atts.getLocalName(i),getPrfix(tagInfo.atts.getQName(i))); case Payload: default: return payloadReader.getAttributeName(i); } }
@Override public QName getAttributeName(int i) { switch (state) { case StartTag: case EndTag: return new QName(tagInfo.atts.getURI(i),tagInfo.atts.getLocalName(i),getPrfix(tagInfo.atts.getQName(i))); case Payload: default: return payloadReader.getAttributeName(i); } }