org.jivesoftware.smack.provider.ExtensionElementProvider Java Examples
The following examples show how to use
org.jivesoftware.smack.provider.ExtensionElementProvider.
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: 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 #6
Source File: JingleProvider.java From Smack with Apache License 2.0 | 4 votes |
/** * Parse a iq/jingle 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. */ @Override public Jingle parse(XmlPullParser parser, int intialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException, SmackParsingException { Jingle jingle = new Jingle(); String sid; JingleActionEnum action; Jid initiator, responder; boolean done = false; JingleContent currentContent = null; // Sub-elements providers JingleContentProvider jcp = new JingleContentProvider(); JingleDescriptionProvider jdpAudio = new JingleDescriptionProvider.Audio(); JingleTransportProvider jtpRawUdp = new JingleTransportProvider.RawUdp(); JingleTransportProvider jtpIce = new JingleTransportProvider.Ice(); ExtensionElementProvider<?> jmipAudio = new JingleContentInfoProvider.Audio(); XmlPullParser.Event eventType; String elementName; String namespace; // Get some attributes for the <jingle> element sid = parser.getAttributeValue("", "sid"); action = JingleActionEnum.getAction(parser.getAttributeValue("", "action")); initiator = ParserUtils.getJidAttribute(parser, "initiator"); responder = ParserUtils.getJidAttribute(parser, "responder"); jingle.setSid(sid); jingle.setAction(action); jingle.setInitiator(initiator); jingle.setResponder(responder); // Start processing sub-elements while (!done) { eventType = parser.next(); elementName = parser.getName(); namespace = parser.getNamespace(); if (eventType == XmlPullParser.Event.START_ELEMENT) { // Parse some well know subelements, depending on the namespaces // and element names... if (elementName.equals(JingleContent.NODENAME)) { // Add a new <content> element to the jingle currentContent = jcp.parse(parser); jingle.addContent(currentContent); } else if (elementName.equals(JingleDescription.NODENAME) && namespace.equals(JingleDescription.Audio.NAMESPACE)) { // Set the <description> element of the <content> currentContent.setDescription(jdpAudio.parse(parser)); } else if (elementName.equals(JingleTransport.NODENAME)) { // Add all of the <transport> elements to the <content> of the jingle // Parse the possible transport namespaces if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) { currentContent.addJingleTransport(jtpRawUdp.parse(parser)); } else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) { currentContent.addJingleTransport(jtpIce.parse(parser)); } else { // TODO: Should be SmackParseException. throw new IOException("Unknown transport namespace \"" + namespace + "\" in Jingle packet."); } } else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) { jingle.setContentInfo((JingleContentInfo) jmipAudio.parse(parser)); } else { // TODO: Should be SmackParseException. throw new IOException("Unknown combination of namespace \"" + namespace + "\" and element name \"" + elementName + "\" in Jingle packet."); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals(Jingle.NODENAME)) { done = true; } } } return jingle; }
Example #7
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); }