use of org.xml.sax.helpers.AttributesImpl in project geode by apache.
the class ManagedEntityConfigXmlGenerator method parse.
/**
* Called by the transformer to parse the "input source". We ignore the input source and, instead,
* generate SAX events to the {@link #setContentHandler ContentHandler}.
*/
public void parse(InputSource input) throws SAXException {
Assert.assertTrue(this.handler != null);
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", ID, "", String.valueOf(this.system.getConfig().getSystemId()));
handler.startElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM, atts);
// Add generation methods here
try {
generateRemoteCommand();
generateDiscovery();
generateSSL();
generateCacheServers();
} catch (AdminException ex) {
throw new SAXException(LocalizedStrings.ManagedEntityConfigXmlGenerator_AN_ADMINEXCEPTION_WAS_THROWN_WHILE_GENERATING_XML.toLocalizedString(), ex);
}
handler.endElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM);
handler.endDocument();
}
use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.
the class AbstractStaxXMLReaderTestCase method mockContentHandler.
protected final ContentHandler mockContentHandler() throws Exception {
ContentHandler contentHandler = mock(ContentHandler.class);
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
return null;
}
}).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
return contentHandler;
}
use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.
the class StaxEventXMLReader method getAttributes.
private Attributes getAttributes(StartElement event) {
AttributesImpl attributes = new AttributesImpl();
for (Iterator i = event.getAttributes(); i.hasNext(); ) {
Attribute attribute = (Attribute) i.next();
QName qName = attribute.getName();
String namespace = qName.getNamespaceURI();
if (namespace == null || !hasNamespacesFeature()) {
namespace = "";
}
String type = attribute.getDTDType();
if (type == null) {
type = "CDATA";
}
attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue());
}
if (hasNamespacePrefixesFeature()) {
for (Iterator i = event.getNamespaces(); i.hasNext(); ) {
Namespace namespace = (Namespace) i.next();
String prefix = namespace.getPrefix();
String namespaceUri = namespace.getNamespaceURI();
String qName;
if (StringUtils.hasLength(prefix)) {
qName = "xmlns:" + prefix;
} else {
qName = "xmlns";
}
attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
}
}
return attributes;
}
use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.
the class StaxStreamXMLReader method getAttributes.
private Attributes getAttributes() {
AttributesImpl attributes = new AttributesImpl();
for (int i = 0; i < this.reader.getAttributeCount(); i++) {
String namespace = this.reader.getAttributeNamespace(i);
if (namespace == null || !hasNamespacesFeature()) {
namespace = "";
}
String type = this.reader.getAttributeType(i);
if (type == null) {
type = "CDATA";
}
attributes.addAttribute(namespace, this.reader.getAttributeLocalName(i), toQualifiedName(this.reader.getAttributeName(i)), type, this.reader.getAttributeValue(i));
}
if (hasNamespacePrefixesFeature()) {
for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
String prefix = this.reader.getNamespacePrefix(i);
String namespaceUri = this.reader.getNamespaceURI(i);
String qName;
if (StringUtils.hasLength(prefix)) {
qName = "xmlns:" + prefix;
} else {
qName = "xmlns";
}
attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
}
}
return attributes;
}
use of org.xml.sax.helpers.AttributesImpl in project robovm by robovm.
the class AttributesImplTest method testSetAttributes.
public void testSetAttributes() {
// Ordinary cases
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("http://yet.another.uri", "doe", "john:doe", "boolean", "false");
attrs.setAttributes(empty);
assertEquals(0, attrs.getLength());
attrs.setAttributes(multi);
assertEquals(multi.getLength(), attrs.getLength());
for (int i = 0; i < multi.getLength(); i++) {
assertEquals(multi.getURI(i), attrs.getURI(i));
assertEquals(multi.getLocalName(i), attrs.getLocalName(i));
assertEquals(multi.getQName(i), attrs.getQName(i));
assertEquals(multi.getType(i), attrs.getType(i));
assertEquals(multi.getValue(i), attrs.getValue(i));
}
// null case
try {
attrs.setAttributes(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected, but must be empty now
assertEquals(0, attrs.getLength());
}
}
Aggregations