List of usage examples for javax.xml.stream XMLStreamReader getAttributeValue
public String getAttributeValue(String namespaceURI, String localName);
From source file:Main.java
public static Integer readOptionalIntegerAttribute(XMLStreamReader reader, String attributeName) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Integer.valueOf(attributeValue) : null; }
From source file:Main.java
public static float readOptionalFloatAttribute(XMLStreamReader reader, String attributeName) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Float.valueOf(attributeValue) : Float.NaN; }
From source file:Main.java
/** * Fetches the attribute name from the current elements namespace. * /* w w w. j a v a 2 s .c o m*/ * @param reader * active pull parser to read XML from * @param name * name of the attribute to read the value of * @return the value of attribute {@code attribute} */ public static String getAttributeValue(final XMLStreamReader reader, final String name) { return reader.getAttributeValue(null, name); }
From source file:Main.java
public static int readOptionalIntegerAttributeValue(XMLStreamReader reader, String attributeName, int defaultValue) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Integer.valueOf(attributeValue) : defaultValue; }
From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java
/** * Reserved for internal use. Parses the operation response as an entity. Parses the result returned in the * specified stream in AtomPub format into a {@link TableResult} containing an entity of the specified class type * projected using the specified resolver. * /*www. ja va2s . c o m*/ * @param xmlr * An <code>XMLStreamReader</code> on the input stream. * @param clazzType * The class type <code>T</code> implementing {@link TableEntity} for the entity returned. Set to * <code>null</code> to ignore the returned entity and copy only response properties into the * {@link TableResult} object. * @param resolver * An {@link EntityResolver} instance to project the entity into an instance of type <code>R</code>. Set * to <code>null</code> to return the entity as an instance of the class type <code>T</code>. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * @return * A {@link TableResult} containing the parsed entity result of the operation. * * @throws XMLStreamException * if an error occurs while accessing the stream. * @throws ParseException * if an error occurs while parsing the stream. * @throws InstantiationException * if an error occurs while constructing the result. * @throws IllegalAccessException * if an error occurs in reflection while parsing the result. * @throws StorageException * if a storage service error occurs. */ protected static <T extends TableEntity, R> TableResult parseEntity(final XMLStreamReader xmlr, final Class<T> clazzType, final EntityResolver<R> resolver, final OperationContext opContext) throws XMLStreamException, ParseException, InstantiationException, IllegalAccessException, StorageException { int eventType = xmlr.getEventType(); final TableResult res = new TableResult(); xmlr.require(XMLStreamConstants.START_ELEMENT, null, ODataConstants.ENTRY); res.setEtag(StringEscapeUtils.unescapeHtml4( xmlr.getAttributeValue(ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.ETAG))); while (xmlr.hasNext()) { eventType = xmlr.next(); if (eventType == XMLStreamConstants.CHARACTERS) { xmlr.getText(); continue; } final String name = xmlr.getName().toString(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (name.equals(ODataConstants.BRACKETED_ATOM_NS + ODataConstants.ID)) { res.setId(Utility.readElementFromXMLReader(xmlr, ODataConstants.ID)); } else if (name .equals(ODataConstants.BRACKETED_DATA_SERVICES_METADATA_NS + ODataConstants.PROPERTIES)) { // Do read properties if (resolver == null && clazzType == null) { return res; } else { res.setProperties(readProperties(xmlr, opContext)); break; } } } } // Move to end Content eventType = xmlr.next(); if (eventType == XMLStreamConstants.CHARACTERS) { eventType = xmlr.next(); } xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.CONTENT); eventType = xmlr.next(); if (eventType == XMLStreamConstants.CHARACTERS) { eventType = xmlr.next(); } xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.ENTRY); String rowKey = null; String partitionKey = null; Date timestamp = null; // Remove core properties from map and set individually EntityProperty tempProp = res.getProperties().get(TableConstants.PARTITION_KEY); if (tempProp != null) { res.getProperties().remove(TableConstants.PARTITION_KEY); partitionKey = tempProp.getValueAsString(); } tempProp = res.getProperties().get(TableConstants.ROW_KEY); if (tempProp != null) { res.getProperties().remove(TableConstants.ROW_KEY); rowKey = tempProp.getValueAsString(); } tempProp = res.getProperties().get(TableConstants.TIMESTAMP); if (tempProp != null) { res.getProperties().remove(TableConstants.TIMESTAMP); timestamp = tempProp.getValueAsDate(); } if (resolver != null) { // Call resolver res.setResult(resolver.resolve(partitionKey, rowKey, timestamp, res.getProperties(), res.getEtag())); } else if (clazzType != null) { // Generate new entity and return final T entity = clazzType.newInstance(); entity.setEtag(res.getEtag()); entity.setPartitionKey(partitionKey); entity.setRowKey(rowKey); entity.setTimestamp(timestamp); entity.readEntity(res.getProperties(), opContext); res.setResult(entity); } return res; }
From source file:org.maodian.flyingcat.xmpp.codec.PresenceCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { Presence p = new Presence(); String id = xmlsr.getAttributeValue("", "id"); if (StringUtils.isNotBlank(id)) { p.setId(id);// w ww . java 2s.c o m } String t = xmlsr.getAttributeValue("", "to"); if (StringUtils.isNotBlank(t)) { JabberID to = JabberID.fromString(t); p.setTo(to); } String type = xmlsr.getAttributeValue("", "type"); if (StringUtils.isNotBlank(type)) { p.setType(PresenceType.fromString(type)); } return p; }
From source file:com.predic8.membrane.core.interceptor.cbr.Case.java
@Override protected void parseAttributes(XMLStreamReader token) throws XMLStreamException { xPath = token.getAttributeValue("", "xPath"); url = token.getAttributeValue("", "url"); if (token.getAttributeValue("", "service") != null) { url = "service:" + token.getAttributeValue("", "service"); }//from w w w .j a v a 2s . com }
From source file:com.predic8.membrane.core.config.AbstractXmlElement.java
protected boolean getBoolean(XMLStreamReader token, String attr) { return "true".equals(token.getAttributeValue("", attr)); }
From source file:com.predic8.membrane.core.interceptor.balancer.XMLElementSessionIdExtractor.java
@Override protected void parseAttributes(XMLStreamReader token) throws XMLStreamException { localName = token.getAttributeValue("", "localName"); namespace = token.getAttributeValue("", "namespace"); }
From source file:org.maodian.flyingcat.xmpp.codec.InfoQueryCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { try {/* w w w .ja va2s . co m*/ String id = xmlsr.getAttributeValue("", "id"); String type = xmlsr.getAttributeValue("", "type"); Builder builder = new Builder(id, type); String from = xmlsr.getAttributeValue("", "from"); String to = xmlsr.getAttributeValue("", "to"); String language = xmlsr.getAttributeValue(XMLConstants.XML_NS_URI, "lang"); builder.from(from).to(to).language(language); switch (type) { case InfoQuery.GET: case InfoQuery.SET: if (xmlsr.nextTag() != XMLStreamConstants.START_ELEMENT) { throw new XmppException(StanzaErrorCondition.BAD_REQUEST); } QName key = xmlsr.getName(); builder.payload(findDecoder(key, builder.build()).decode(xmlsr)); break; case InfoQuery.RESULT: // do nothing break; case InfoQuery.ERROR: throw new IllegalStateException( "Since this is a server, it should not dealing with incoming result and error"); default: break; } return builder.build(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }