Java Code Examples for javax.xml.stream.events.XMLEvent#isAttribute()

The following examples show how to use javax.xml.stream.events.XMLEvent#isAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationConfigurationStaxUnmarshaller.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Id (aka configuration name) isn't modeled on the actual {@link NotificationConfiguration}
 * class but as the key name in the map of configurations in
 * {@link BucketNotificationConfiguration}
 */
@Override
public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    T topicConfig = createConfiguration();
    String id = null;

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig);
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (handleXmlEvent(topicConfig, context, targetDepth)) {
                // Do nothing, subclass has handled it
            } else if (context.testExpression("Id", targetDepth)) {
                id = StringStaxUnmarshaller.getInstance().unmarshall(context);
            } else if (context.testExpression("Event", targetDepth)) {
                topicConfig.addEvent(StringStaxUnmarshaller.getInstance().unmarshall(context));
            } else if (context.testExpression("Filter", targetDepth)) {
                topicConfig.setFilter(FilterStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig);
            }
        }
    }
}
 
Example 2
Source File: S3KeyFilterStaxUnmarshaller.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    S3KeyFilter filter = new S3KeyFilter();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("FilterRule", targetDepth)) {
                filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }
}
 
Example 3
Source File: FilterStaxUnmarshaller.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Filter unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    Filter filter = new Filter();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("S3Key", targetDepth)) {
                filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }
}
 
Example 4
Source File: FilterRuleStaxUnmarshaller.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public FilterRule unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    FilterRule filter = new FilterRule();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }
        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("Name", targetDepth)) {
                filter.setName(StringStaxUnmarshaller.getInstance().unmarshall(context));
            } else if (context.testExpression("Value", targetDepth)) {
                filter.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }

}
 
Example 5
Source File: LambdaConfigurationStaxUnmarshaller.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    String id = null;
    List<String> events = new ArrayList<String>();
    Filter filter = null;
    String functionArn = null;
    String invocationRole = null;

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return createLambdaConfig(id, events, functionArn, invocationRole, filter);
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("Id", targetDepth)) {
                id = StringStaxUnmarshaller.getInstance().unmarshall(context);
            } else if (context.testExpression("Event", targetDepth)) {
                events.add(StringStaxUnmarshaller.getInstance().unmarshall(context));
            } else if (context.testExpression("Filter", targetDepth)) {
                filter = FilterStaxUnmarshaller.getInstance().unmarshall(context);
            } else if (context.testExpression("CloudFunction", targetDepth)) {
                functionArn = StringStaxUnmarshaller.getInstance().unmarshall(context);
            } else if (context.testExpression("InvocationRole", targetDepth)) {
                invocationRole = StringStaxUnmarshaller.getInstance().unmarshall(context);
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return createLambdaConfig(id, events, functionArn, invocationRole, filter);
            }
        }
    }
}
 
Example 6
Source File: AnyAttributeProtocol.java    From ts-reaktive with MIT License 5 votes vote down vote up
@Override
public Reader<XMLEvent,Tuple2<QName,String>> reader() {
    return new Reader<XMLEvent,Tuple2<QName,String>>() {
        private int level = 0;

        @Override
        public Try<Tuple2<QName,String>> reset() {
            level = 0;
            return none();
        }

        @Override
        public Try<Tuple2<QName,String>> apply(XMLEvent evt) {
            if (level == 0 && evt.isAttribute()) {
                Attribute attr = Attribute.class.cast(evt);
                return Try.success(Tuple.of(attr.getName(), attr.getValue()));
            } else if (evt.isStartElement()) {
                level++;
                return none();
            } else if (evt.isEndElement()) {
                level--;
                return none();
            } else {
                return none();
            }
        }
    };
}
 
Example 7
Source File: SAAJInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException {
    if (events != null) {
        for (XMLEvent ev : events) {
            if (ev.isNamespace()) {
                el.addNamespaceDeclaration(((Namespace)ev).getPrefix(), ((Namespace)ev).getNamespaceURI());
            } else if (ev.isAttribute()) {
                el.addAttribute(((Attribute)ev).getName(), ((Attribute)ev).getValue());
            }
        }
    }
}
 
Example 8
Source File: AttributeProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
public AttributeProtocol(QName name) {
    super(new Protocol<XMLEvent,String>() {
        Writer<XMLEvent,String> writer = Writer.of(s -> Vector.of(factory.createAttribute(name, s)));
        @Override
        public Class<? extends XMLEvent> getEventType() {
            return Attribute.class;
        }
        
        @Override
        public String toString() {
            return "@" + name;
        }

        @Override
        public Reader<XMLEvent,String> reader() {
            return new Reader<XMLEvent,String>() {
                private int level = 0;

                @Override
                public Try<String> reset() {
                    level = 0;
                    return none();
                }

                @Override
                public Try<String> apply(XMLEvent evt) {
                    if (level == 0 && evt.isAttribute() && matches(Attribute.class.cast(evt))) {
                        return Try.success(Attribute.class.cast(evt).getValue());
                    } else if (evt.isStartElement()) {
                        level++;
                        return none();
                    } else if (evt.isEndElement()) {
                        level--;
                        return none();
                    } else {
                        return none();
                    }
                }

                private boolean matches(Attribute attr) {
                    return name.equals(attr.getName());
                }
                
            };
        }
        
        @Override
        public Writer<XMLEvent,String> writer() {
            return writer;
        }
    }, XMLProtocol.locator);
}
 
Example 9
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void addEvent(XMLEvent event) {
    if (event.isStartElement()) {
        lastStartElementQName = event.asStartElement().getName();
        if (header.equals(lastStartElementQName.getLocalPart())
            && ns.equals(lastStartElementQName.getNamespaceURI())) {
            // process all events recorded so far
            context = new StreamToDOMContext(true, false, false);
            doc = DOMUtils.createDocument();
            parent = doc;
            try {
                for (XMLEvent ev : events) {
                    parent = StaxUtils.readDocElement(doc, parent, ev, context);
                }
            } catch (XMLStreamException e) {
                throw new Fault(e);
            }
        } else {
            if (ns.equals(lastStartElementQName.getNamespaceURI())) {
                if (body.equals(lastStartElementQName.getLocalPart())) {
                    bodyPrefix = lastStartElementQName.getPrefix();
                } else if (envelope.equals(lastStartElementQName.getLocalPart())) {
                    envelopePrefix = lastStartElementQName.getPrefix();
                }
            }
            events.add(event);
        }
    } else {
        if (event.isNamespace() || event.isAttribute()) {
            final String lastEl = lastStartElementQName.getLocalPart();
            if (body.equals(lastEl) && ns.equals(lastStartElementQName.getNamespaceURI())) {
                if (bodyEvents == null) {
                    bodyEvents = new ArrayList<>();
                }
                bodyEvents.add(event);
            } else if (envelope.equals(lastEl) && ns.equals(lastStartElementQName.getNamespaceURI())) {
                if (envEvents == null) {
                    envEvents = new ArrayList<>();
                }
                envEvents.add(event);
            }
        }
        events.add(event);
    }
}