List of usage examples for javax.xml.stream XMLStreamReader require
public void require(int type, String namespaceURI, String localName) throws XMLStreamException;
From source file:org.maodian.flyingcat.xmpp.codec.SessionCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { try {//from w w w . j a v a 2 s . co m xmlsr.require(XMLStreamConstants.START_ELEMENT, XmppNamespace.SESSION, "session"); return new Session(); } catch (XMLStreamException e) { throw new XmppException(e, StreamError.INVALID_XML); } }
From source file:org.maodian.flyingcat.xmpp.extensions.xep0030.QueryItemCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { try {// w w w. j a va2 s . co m xmlsr.require(XMLStreamConstants.START_ELEMENT, ServiceDiscovery.ITEM, "query"); return new QueryItem(); } catch (XMLStreamException e) { throw new XmppException(e, StreamError.INVALID_XML); } }
From source file:org.maodian.flyingcat.xmpp.extensions.xep0030.QueryInfoCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { try {//w ww . ja v a 2 s . co m xmlsr.require(XMLStreamConstants.START_ELEMENT, ServiceDiscovery.INFORMATION, "query"); return new QueryInfo(); } catch (XMLStreamException e) { throw new XmppException(e, StreamError.INVALID_XML); } }
From source file:org.maodian.flyingcat.xmpp.codec.BindCodec.java
@Override public Bind decode(XMLStreamReader xmlsr) { try {// www . j av a2 s.c o m xmlsr.nextTag(); xmlsr.require(XMLStreamConstants.START_ELEMENT, XmppNamespace.BIND, "resource"); Bind bind = new Bind(); bind.setResource(xmlsr.getElementText()); return bind; } catch (XMLStreamException e) { throw new XmppException(e, StreamError.INVALID_XML); } }
From source file:org.maodian.flyingcat.xmpp.extensions.xep0077.RegistrationCodec.java
@Override public Object decode(XMLStreamReader xmlsr) { try {//from www .j a v a 2s.c o m xmlsr.require(XMLStreamConstants.START_ELEMENT, InBandRegistration.REGISTER, "query"); String username = null; String password = null; while (xmlsr.nextTag() == XMLStreamConstants.START_ELEMENT) { if (xmlsr.getName().equals(new QName(InBandRegistration.REGISTER, "username"))) { username = xmlsr.getElementText(); } else if (xmlsr.getName().equals(new QName(InBandRegistration.REGISTER, "password"))) { password = xmlsr.getElementText(); } } return new Registration(username, password); } catch (XMLStreamException e) { throw new XmppException(e, StreamError.INVALID_XML); } }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private byte[] readData(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, DATA_NODE); String text = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, DATA_NODE); return Base64.decodeBase64(text); }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private Object readDate(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, DATE_NODE); String text = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, DATE_NODE); try {// ww w . ja va 2 s. c o m return format.parse(text); } catch (ParseException e) { throw new XMLStreamException("Invalid date: '" + text + "'", e); } }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private List<?> readArray(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, ARRAY_NODE); reader.nextTag();/*from w w w. j a v a 2 s . c o m*/ List<Object> array = new ArrayList<Object>(); for (;;) { int type = reader.getEventType(); if (XMLStreamConstants.END_ELEMENT == type && ARRAY_NODE.equals(reader.getLocalName())) { reader.nextTag(); break; } array.add(readValue(reader)); } return array; }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private Map<String, ?> readDict(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, DICT_NODE); reader.nextTag();/*from w w w . jav a 2 s.c o m*/ Map<String, Object> map = new HashMap<String, Object>(); for (;;) { int type = reader.getEventType(); if (XMLStreamConstants.END_ELEMENT == type && DICT_NODE.equals(reader.getLocalName())) { reader.nextTag(); break; } String key = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, KEY_NODE); if (key != null) { map.put(key, readValue(reader)); } } return map; }
From source file:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Parses the operation response as an entity. Reads entity data from the specified * <code>XMLStreamReader</code> using the specified class type and optionally projects the entity result with the * specified resolver into a {@link TableResult} object. * /*w w w .j a va 2 s.co m*/ * @param xmlr * The <code>XMLStreamReader</code> to read the data to parse from. * @param httpStatusCode * The HTTP status code returned with the operation response. * @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 entitys as 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} object with the parsed operation response. * * @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. */ private static <T extends TableEntity, R> TableResult parseSingleOpAtomResponse(final InputStream inStream, final int httpStatusCode, final Class<T> clazzType, final EntityResolver<R> resolver, final OperationContext opContext) throws XMLStreamException, ParseException, InstantiationException, IllegalAccessException, StorageException { XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream); try { xmlr.require(XMLStreamConstants.START_DOCUMENT, null, null); xmlr.next(); final TableResult res = parseAtomEntity(xmlr, clazzType, resolver, opContext); res.setHttpStatusCode(httpStatusCode); return res; } finally { xmlr.close(); } }