Java Code Examples for org.jivesoftware.smack.provider.ExtensionElementProvider#parse()
The following examples show how to use
org.jivesoftware.smack.provider.ExtensionElementProvider#parse() .
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: ReferenceProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public ReferenceElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { Integer begin = ParserUtils.getIntegerAttribute(parser, ReferenceElement.ATTR_BEGIN); Integer end = ParserUtils.getIntegerAttribute(parser, ReferenceElement.ATTR_END); String typeString = parser.getAttributeValue(null, ReferenceElement.ATTR_TYPE); ReferenceElement.Type type = ReferenceElement.Type.valueOf(typeString); String anchor = parser.getAttributeValue(null, ReferenceElement.ATTR_ANCHOR); String uriString = parser.getAttributeValue(null, ReferenceElement.ATTR_URI); URI uri; try { uri = uriString != null ? new URI(uriString) : null; } catch (URISyntaxException e) { // TODO: Should be SmackParseException and probably be factored into ParserUtils. throw new IOException(e); } ExtensionElement child = null; outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { String elementName = parser.getName(); String namespace = parser.getNamespace(); ExtensionElementProvider<?> provider = ProviderManager.getExtensionProvider(elementName, namespace); if (provider != null) { child = provider.parse(parser); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { break outerloop; } } return new ReferenceElement(begin, end, type, anchor, uri, child); }
Example 2
Source File: ItemProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public Item parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { String id = parser.getAttributeValue(null, "id"); String node = parser.getAttributeValue(null, "node"); String xmlns = parser.getNamespace(); ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns); XmlPullParser.Event tag = parser.next(); if (tag == XmlPullParser.Event.END_ELEMENT) { return new Item(itemNamespace, id, node); } else { String payloadElemName = parser.getName(); String payloadNS = parser.getNamespace(); final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS); if (extensionProvider == null) { // TODO: Should we use StandardExtensionElement in this case? And probably remove SimplePayload all together. CharSequence payloadText = PacketParserUtils.parseElement(parser, true); return new PayloadItem<>(itemNamespace, id, node, new SimplePayload(payloadText.toString())); } else { return new PayloadItem<>(itemNamespace, id, node, extensionProvider.parse(parser)); } } }
Example 3
Source File: JingleProvider.java From jitsi-hammer with Apache License 2.0 | 4 votes |
@Override public NewJingleIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { NewJingleIQ jingleIQ = new NewJingleIQ(); NewJingleAction action = NewJingleAction.parseString(parser.getAttributeValue("", "action")); String initiator = parser.getAttributeValue("", "initiator"); String responder = parser.getAttributeValue("", "responder"); String sid = parser.getAttributeValue("", "sid"); jingleIQ.setAction(action); jingleIQ.setInitiator(initiator); jingleIQ.setResponder(responder); jingleIQ.setSID(sid); boolean done = false; try { while (!done) { int eventType = parser.next(); String elementName = parser.getName(); String namespace = parser.getNamespace(); if (eventType == XmlPullParser.START_TAG) { ExtensionElementProvider provider = ProviderManager.getExtensionProvider(elementName, namespace); if (provider != null) { Element child = provider.parse(parser); if (child instanceof NewContentPacketExtension) { jingleIQ.addContent((NewContentPacketExtension)child); } else { throw new IOException("JingleProvider doesn't handle child element " + elementName + " in namespace " + namespace); } } else { throw new IOException("JingleProvider: no provider found for element " + elementName + " in namespace " + namespace); } } if (eventType == XmlPullParser.END_TAG && parser.getName().equals("jingle")) { done = true; } } } catch (Exception e) { } return jingleIQ; }
Example 4
Source File: AbstractXMPPConnection.java From Smack with Apache License 2.0 | 4 votes |
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException { streamFeatures.clear(); final int initialDepth = parser.getDepth(); while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getDepth() == initialDepth + 1) { FullyQualifiedElement streamFeature = null; String name = parser.getName(); String namespace = parser.getNamespace(); switch (name) { case StartTls.ELEMENT: streamFeature = PacketParserUtils.parseStartTlsFeature(parser); break; case Mechanisms.ELEMENT: streamFeature = new Mechanisms(PacketParserUtils.parseMechanisms(parser)); break; case Bind.ELEMENT: streamFeature = Bind.Feature.INSTANCE; break; case Session.ELEMENT: streamFeature = PacketParserUtils.parseSessionFeature(parser); break; case Compress.Feature.ELEMENT: streamFeature = PacketParserUtils.parseCompressionFeature(parser); break; default: ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace); if (provider != null) { streamFeature = provider.parse(parser, incomingStreamXmlEnvironment); } break; } if (streamFeature != null) { addStreamFeature(streamFeature); } } else if (eventType == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth) { break; } } }
Example 5
Source File: PacketParserUtils.java From Smack with Apache License 2.0 | 3 votes |
/** * Parses an extension element. * * @param elementName the XML element name of the extension element. * @param namespace the XML namespace of the stanza extension. * @param parser the XML parser, positioned at the starting element of the extension. * @param outerXmlEnvironment the outer XML environment (optional). * * @return an extension element. * @throws XmlPullParserException if an error in the XML parser occurred. * @throws IOException if an I/O error occurred. * @throws SmackParsingException if the Smack parser (provider) encountered invalid input. */ public static ExtensionElement parseExtensionElement(String elementName, String namespace, XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { ParserUtils.assertAtStartTag(parser); // See if a provider is registered to handle the extension. ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace); if (provider != null) { return provider.parse(parser, outerXmlEnvironment); } // No providers registered, so use a default extension. return StandardExtensionElementProvider.INSTANCE.parse(parser, outerXmlEnvironment); }