Search in sources :

Example 11 with Attributes2Impl

use of org.xml.sax.ext.Attributes2Impl in project intellij-community by JetBrains.

the class Psi2SaxAdapter method visitXmlTag.

@Override
public void visitXmlTag(XmlTag tag) {
    try {
        setLocation(tag);
        final Map<String, String> map = tag.getLocalNamespaceDeclarations();
        final String[] prefixes = map.keySet().toArray(new String[map.size()]);
        for (String prefix : prefixes) {
            myHandler.startPrefixMapping(prefix, map.get(prefix));
        }
        final Attributes2Impl atts = new Attributes2Impl();
        final XmlAttribute[] xmlAttributes = tag.getAttributes();
        for (XmlAttribute attribute : xmlAttributes) {
            final String s = attribute.getName();
            if (!"xmlns".equals(s) && !s.startsWith("xmlns:")) {
                final String uri = attribute.getNamespace();
                atts.addAttribute(s.contains(":") ? uri : "", attribute.getLocalName(), s, "PCDATA", attribute.getValue());
            }
        }
        final String namespace = tag.getNamespace();
        final String localName = tag.getLocalName();
        final String name = tag.getName();
        myHandler.startElement(namespace, localName, name, atts);
        PsiElement child = tag.getFirstChild();
        while (child != null) {
            child.accept(this);
            child = child.getNextSibling();
        }
        myHandler.endElement(namespace, localName, name);
        for (int i = prefixes.length - 1; i >= 0; i--) {
            String prefix = prefixes[i];
            myHandler.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new ParseError(e);
    }
}
Also used : Attributes2Impl(org.xml.sax.ext.Attributes2Impl) PsiElement(com.intellij.psi.PsiElement) SAXException(org.xml.sax.SAXException)

Example 12 with Attributes2Impl

use of org.xml.sax.ext.Attributes2Impl in project jPOS by jpos.

the class XMLPackagerTest method onSetup.

@Before
public void onSetup() throws ISOException, NoSuchFieldException {
    // PrintStream p = new PrintStream(new ByteArrayOutputStream())
    xMLPackager = new XMLPackager();
    atts = new Attributes2Impl();
    logger = new Logger();
    logger.addListener(new SimpleLogListener());
    isoMsg = xMLPackager.createISOMsg();
    xMLPackager.setLogger(logger, xMLPackager.getClass().getName());
    isoMsg.setPackager(xMLPackager);
}
Also used : SimpleLogListener(org.jpos.util.SimpleLogListener) Attributes2Impl(org.xml.sax.ext.Attributes2Impl) Logger(org.jpos.util.Logger) Before(org.junit.Before)

Example 13 with Attributes2Impl

use of org.xml.sax.ext.Attributes2Impl in project jPOS by jpos.

the class GenericValidatingPackagerTest method testGenericValidatorContentHandlerStartElementThrowsSAXException2.

@Test
public void testGenericValidatorContentHandlerStartElementThrowsSAXException2() throws Throwable {
    GenericValidatingPackager.GenericValidatorContentHandler genericValidatorContentHandler = new GenericValidatingPackager().new GenericValidatorContentHandler();
    Attributes atts = new Attributes2Impl();
    try {
        genericValidatorContentHandler.startElement("testGenericValidatorContentHandlerNamespaceURI", null, "testGenericValidatorContentHandlerQName", atts);
        fail("Expected SAXException to be thrown");
    } catch (SAXException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
        assertNull("ex.getException().getMessage()", ex.getException().getMessage());
    }
}
Also used : Attributes2Impl(org.xml.sax.ext.Attributes2Impl) Attributes(org.xml.sax.Attributes) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Aggregations

Attributes2Impl (org.xml.sax.ext.Attributes2Impl)13 Test (org.junit.Test)7 Attributes (org.xml.sax.Attributes)7 SAXException (org.xml.sax.SAXException)5 AttributesImpl (org.xml.sax.helpers.AttributesImpl)3 PsiElement (com.intellij.psi.PsiElement)1 Logger (org.jpos.util.Logger)1 SimpleLogListener (org.jpos.util.SimpleLogListener)1 Before (org.junit.Before)1