/** * 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); } }
/** * 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)); }
public String getURI(int index) { return adjustedAttributes.getURI(index); }
@Override public String getAttributeNamespace(int index) { switch (state) { case StartTag: case EndTag: return tagInfo.atts.getURI(index); case Payload: default: return payloadReader.getAttributeNamespace(index); } }
@Override public String getAttributeNamespace(int index) { switch (state) { case StartTag: case EndTag: return tagInfo.atts.getURI(index); case Payload: default: return payloadReader.getAttributeNamespace(index); } }
@Override public String getAttributeNamespace(int index) { switch (state) { case StartTag: case EndTag: return tagInfo.atts.getURI(index); case Payload: default: return payloadReader.getAttributeNamespace(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); } }
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); } }
/** * Remove the named attribute, having the specified namespace. * @param namespaceURI The attribute namespace. * @param name The attribute name. */ public void removeAttributeNS(String namespaceURI, String name) { int attribCount = attributes.getLength(); for(int i = 0; i < attribCount; i++) { if(namespaceURI.equals(attributes.getURI(i))) { boolean isQName = (name.indexOf(":") != -1); if(isQName && name.equals(attributes.getQName(i))) { attributes.removeAttribute(i); } else if(!isQName && name.equals(attributes.getLocalName(i))) { attributes.removeAttribute(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); } }
/** * Remove the named attribute, having the specified namespace. * @param namespaceURI The attribute namespace. * @param name The attribute name. */ public void removeAttributeNS(String namespaceURI, String name) { int attribCount = attributes.getLength(); for(int i = 0; i < attribCount; i++) { if(namespaceURI.equals(attributes.getURI(i))) { boolean isQName = (name.indexOf(":") != -1); if(isQName && name.equals(attributes.getQName(i))) { attributes.removeAttribute(i); } else if(!isQName && name.equals(attributes.getLocalName(i))) { attributes.removeAttribute(i); } } } }
/** * Remove the named attribute, having the specified namespace. * @param namespaceURI The attribute namespace. * @param name The attribute name. */ public void removeAttributeNS(String namespaceURI, String name) { int attribCount = attributes.getLength(); for(int i = 0; i < attribCount; i++) { if(namespaceURI.equals(attributes.getURI(i))) { boolean isQName = (name.indexOf(":") != -1); if(isQName && name.equals(attributes.getQName(i))) { attributes.removeAttribute(i); } else if(!isQName && name.equals(attributes.getLocalName(i))) { attributes.removeAttribute(i); } } } }
/** * Remove the named attribute, having the specified namespace. * @param namespaceURI The attribute namespace. * @param name The attribute name. */ public void removeAttributeNS(String namespaceURI, String name) { int attribCount = attributes.getLength(); for(int i = 0; i < attribCount; i++) { if(namespaceURI.equals(attributes.getURI(i))) { boolean isQName = (name.indexOf(":") != -1); if(isQName && name.equals(attributes.getQName(i))) { attributes.removeAttribute(i); } else if(!isQName && name.equals(attributes.getLocalName(i))) { attributes.removeAttribute(i); } } } }
public void startElement(String namespaceURI, String localName, String rawName, Attributes attrs) throws SAXException { if (filter.isFilteredNamespace(namespaceURI) || filter.isFilteredRawName(rawName)) { log.trace("Filtering: {" + namespaceURI + "}" + localName + " -> " + rawName); } else { AttributesImpl fAttrs = new AttributesImpl(attrs); for (int i = 0; i < fAttrs.getLength(); i++) { String uri = fAttrs.getURI(i); if (filter.isFilteredNamespace(uri)) { fAttrs.removeAttribute(i); } } super.startElement(namespaceURI, localName, rawName, fAttrs); } }
/** * remove an element * @param attrName name of the element * @return true if the attribute was found and removed. * @see javax.xml.soap.SOAPElement#removeAttribute(javax.xml.soap.Name) */ public boolean removeAttribute(Name attrName) { AttributesImpl attributes = makeAttributesEditable(); boolean removed = false; for (int i = 0; i < attributes.getLength() && !removed; i++) { if (attributes.getURI(i).equals(attrName.getURI()) && attributes.getLocalName(i).equals(attrName.getLocalName())) { attributes.removeAttribute(i); removed = true; } } return removed; }
/** * remove an element * @param attrName name of the element * @return true if the attribute was found and removed. * @see javax.xml.soap.SOAPElement#removeAttribute(javax.xml.soap.Name) */ public boolean removeAttribute(Name attrName) { AttributesImpl attributes = makeAttributesEditable(); boolean removed = false; for (int i = 0; i < attributes.getLength() && !removed; i++) { if (attributes.getURI(i).equals(attrName.getURI()) && attributes.getLocalName(i).equals(attrName.getLocalName())) { attributes.removeAttribute(i); removed = true; } } return removed; }