Java Code Examples for org.jivesoftware.smack.provider.ProviderManager#getExtensionProvider()
The following examples show how to use
org.jivesoftware.smack.provider.ProviderManager#getExtensionProvider() .
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: OpenPgpContentElementProvider.java From Smack with Apache License 2.0 | 4 votes |
protected static OpenPgpContentElementData parseOpenPgpContentElementData(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackParsingException { Set<Jid> to = new HashSet<>(); Date timestamp = null; String rpad = null; List<ExtensionElement> payload = new LinkedList<>(); outerloop: while (true) { XmlPullParser.Event tag = parser.next(); String name = parser.getName(); switch (tag) { case START_ELEMENT: switch (name) { case OpenPgpContentElement.ELEM_TIME: String stamp = parser.getAttributeValue("", OpenPgpContentElement.ATTR_STAMP); timestamp = ParserUtils.getDateFromXep82String(stamp); break; case OpenPgpContentElement.ELEM_TO: String jid = parser.getAttributeValue("", OpenPgpContentElement.ATTR_JID); to.add(JidCreate.bareFrom(jid)); break; case EncryptedOpenPgpContentElement.ELEM_RPAD: rpad = parser.nextText(); break; case OpenPgpContentElement.ELEM_PAYLOAD: innerloop: while (true) { XmlPullParser.Event ptag = parser.next(); String pname = parser.getName(); String pns = parser.getNamespace(); switch (ptag) { case START_ELEMENT: ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(pname, pns); if (provider == null) { LOGGER.log(Level.INFO, "No provider found for " + pname + " " + pns); continue innerloop; } payload.add(provider.parse(parser)); break; case END_ELEMENT: break innerloop; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } break; } break; case END_ELEMENT: switch (name) { case CryptElement.ELEMENT: case SigncryptElement.ELEMENT: case SignElement.ELEMENT: break outerloop; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } return new OpenPgpContentElementData(to, timestamp, rpad, payload); }
Example 5
Source File: MoodProvider.java From Smack with Apache License 2.0 | 4 votes |
@Override public MoodElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { String text = null; Mood mood = null; MoodConcretisation concretisation = null; outerloop: while (true) { XmlPullParser.Event tag = parser.next(); String name = parser.getName(); String namespace = parser.getNamespace(); switch (tag) { case START_ELEMENT: if (MoodElement.ELEM_TEXT.equals(name)) { text = parser.nextText(); continue outerloop; } if (!MoodElement.NAMESPACE.equals(namespace)) { LOGGER.log(Level.FINE, "Foreign namespace " + namespace + " detected. Try to find suitable MoodConcretisationProvider."); MoodConcretisationProvider<?> provider = (MoodConcretisationProvider<?>) ProviderManager.getExtensionProvider(name, namespace); if (provider != null) { concretisation = provider.parse(parser); } else { LOGGER.log(Level.FINE, "No provider for <" + name + " xmlns:'" + namespace + "'/> found. Ignore."); } continue outerloop; } try { mood = Mood.valueOf(name); continue outerloop; } catch (IllegalArgumentException e) { throw new XmlPullParserException("Unknown mood value: " + name + " encountered."); } case END_ELEMENT: if (MoodElement.ELEMENT.equals(name)) { MoodElement.MoodSubjectElement subjectElement = (mood == null && concretisation == null) ? null : new MoodElement.MoodSubjectElement(mood, concretisation); return new MoodElement(subjectElement, text); } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } }
Example 6
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); }