Search in sources :

Example 26 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.

the class SAXCodeAdapter method visitMethodInsn.

public final void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) {
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "owner", "owner", "", owner);
    attrs.addAttribute("", "name", "name", "", name);
    attrs.addAttribute("", "desc", "desc", "", desc);
    addElement(AbstractVisitor.OPCODES[opcode], attrs);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 27 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.

the class SAXCodeAdapter method visitLookupSwitchInsn.

public final void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {
    AttributesImpl att = new AttributesImpl();
    att.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
    String o = AbstractVisitor.OPCODES[Opcodes.LOOKUPSWITCH];
    addStart(o, att);
    for (int i = 0; i < labels.length; i++) {
        AttributesImpl att2 = new AttributesImpl();
        att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
        att2.addAttribute("", "key", "key", "", Integer.toString(keys[i]));
        addElement("label", att2);
    }
    addEnd(o);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 28 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.

the class SAXCodeAdapter method visitLineNumber.

public final void visitLineNumber(final int line, final Label start) {
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "line", "line", "", Integer.toString(line));
    attrs.addAttribute("", "start", "start", "", getLabel(start));
    addElement("LineNumber", attrs);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 29 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.

the class SAXCodeAdapter method visitIntInsn.

public final void visitIntInsn(final int opcode, final int operand) {
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "value", "value", "", Integer.toString(operand));
    addElement(AbstractVisitor.OPCODES[opcode], attrs);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 30 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project hudson-2.x by hudson.

the class MorphTagLibrary method createTagScript.

@Override
public TagScript createTagScript(final String tagName, Attributes attributes) throws JellyException {
    return new TagScript() {

        private Object evalAttribute(String name, JellyContext context) {
            ExpressionAttribute e = attributes.get(name);
            if (e == null)
                return null;
            return e.exp.evaluate(context);
        }

        private Collection<?> getExclusions(JellyContext context) {
            Object exclusion = evalAttribute(EXCEPT_ATTRIBUTES, context);
            if (exclusion == null)
                return Collections.emptySet();
            if (exclusion instanceof String)
                // split by whitespace
                return Arrays.asList(exclusion.toString().split("\\s+"));
            if (exclusion instanceof Collection)
                return (Collection) exclusion;
            throw new IllegalArgumentException("Expected collection for exclusion but found :" + exclusion);
        }

        @Override
        public void run(JellyContext context, XMLOutput output) throws JellyTagException {
            AttributesImpl actual = new AttributesImpl();
            Collection<?> exclusions = getExclusions(context);
            Map<String, ?> meta = (Map) evalAttribute(META_ATTRIBUTES, context);
            if (meta != null) {
                for (Map.Entry<String, ?> e : meta.entrySet()) {
                    String key = e.getKey();
                    // @see jelly.impl.DynamicTag.setAttribute() -- ${attrs} has duplicates with "Attr" suffix
                    if (key.endsWith("Attr") && meta.containsKey(key.substring(0, key.length() - 4)))
                        continue;
                    // @see http://github.com/hudson/jelly/commit/4ae67d15957b5b4d32751619997a3cb2a6ad56ed
                    if (key.equals("ownerTag"))
                        continue;
                    if (!exclusions.contains(key)) {
                        Object v = e.getValue();
                        if (v != null)
                            actual.addAttribute("", key, key, "CDATA", v.toString());
                    }
                }
            } else {
                meta = Collections.emptyMap();
            }
            for (Map.Entry<String, ExpressionAttribute> e : attributes.entrySet()) {
                String name = e.getKey();
                // already handled
                if (name.equals(META_ATTRIBUTES) || name.equals(EXCEPT_ATTRIBUTES))
                    continue;
                if (meta.containsKey(name)) {
                    // if the explicit value is also generated by a map, delete it first.
                    // this is O(N) operation, but we don't expect there to be a lot of collisions.
                    int idx = actual.getIndex(name);
                    if (idx >= 0)
                        actual.removeAttribute(idx);
                }
                Expression expression = e.getValue().exp;
                actual.addAttribute("", name, name, "CDATA", expression.evaluateAsString(context));
            }
            try {
                output.startElement(tagName, actual);
                getTagBody().run(context, output);
                output.endElement(tagName);
            } catch (SAXException x) {
                throw new JellyTagException(x);
            }
        }
    };
}
Also used : JellyTagException(org.apache.commons.jelly.JellyTagException) XMLOutput(org.apache.commons.jelly.XMLOutput) SAXException(org.xml.sax.SAXException) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ExpressionAttribute(org.apache.commons.jelly.impl.ExpressionAttribute) Expression(org.apache.commons.jelly.expression.Expression) TagScript(org.apache.commons.jelly.impl.TagScript) Collection(java.util.Collection) JellyContext(org.apache.commons.jelly.JellyContext) Map(java.util.Map)

Aggregations

AttributesImpl (org.xml.sax.helpers.AttributesImpl)310 SAXException (org.xml.sax.SAXException)53 Test (org.junit.Test)34 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)23 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)23 ContentHandler (org.xml.sax.ContentHandler)21 Attributes (org.xml.sax.Attributes)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 Map (java.util.Map)16 PackOut (org.adempiere.pipo.PackOut)16 IOException (java.io.IOException)15 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)12 Iterator (java.util.Iterator)11 TransformerHandler (javax.xml.transform.sax.TransformerHandler)11 StreamResult (javax.xml.transform.stream.StreamResult)11 Metadata (org.apache.tika.metadata.Metadata)11 File (java.io.File)9 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)9 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)9