/** * Parses a PEPEvent packet and extracts a PEPItem from it. * (There is only one per <event>.) * * @param parser the XML parser, positioned at the starting element of the extension. * @return a PacketExtension. * @throws Exception if a parsing error occurs. */ public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("event")) { } else if (parser.getName().equals("items")) { // Figure out the node for this event. String node = parser.getAttributeValue("", "node"); // Get the parser for this kind of node, and if found then parse the node. PacketExtensionProvider nodeParser = nodeParsers.get(node); if (nodeParser != null) { pepItem = nodeParser.parseExtension(parser); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("event")) { done = true; } } } return pepItem; }
private CcsClient() { // Add FcmPacketExtension ProviderManager.getInstance().addExtensionProvider(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE, new PacketExtensionProvider() { @Override public PacketExtension parseExtension(XmlPullParser parser) throws Exception { String json = parser.nextText(); FcmPacketExtension packet = new FcmPacketExtension(json); return packet; } }); }
/** * Parses a PEPEvent packet and extracts a PEPItem from it. (There is only * one per <event>.) * * @param parser * the XML parser, positioned at the starting element of the * extension. * @return a PacketExtension. * @throws Exception * if a parsing error occurs. */ public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("event")) { } else if (parser.getName().equals("items")) { // Figure out the node for this event. String node = parser.getAttributeValue("", "node"); // Get the parser for this kind of node, and if found then // parse the node. PacketExtensionProvider nodeParser = nodeParsers.get(node); if (nodeParser != null) { pepItem = nodeParser.parseExtension(parser); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("event")) { done = true; } } } return pepItem; }
private CcsClient() { // Add GcmPacketExtension ProviderManager.getInstance().addExtensionProvider(GCM_ELEMENT_NAME, GCM_NAMESPACE, new PacketExtensionProvider() { @Override public PacketExtension parseExtension(XmlPullParser parser) throws Exception { String json = parser.nextText(); GcmPacketExtension packet = new GcmPacketExtension(json); return packet; } }); }
private static void addSimplePacketExtension(final String name, final String namespace) { ProviderManager.getInstance().addExtensionProvider(name, namespace, new PacketExtensionProvider() { public PacketExtension parseExtension(XmlPullParser parser) throws Exception { StreamHandlingPacket packet = new StreamHandlingPacket(name, namespace); int attributeCount = parser.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { packet.addAttribute(parser.getAttributeName(i), parser.getAttributeValue(i)); } return packet; } }); }
/** * Parses a packet extension sub-packet. * * @param elementName the XML element name of the packet extension. * @param namespace the XML namespace of the packet extension. * @param parser the XML parser, positioned at the starting element of the extension. * @return a PacketExtension. * @throws Exception if a parsing error occurs. */ public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser) throws Exception { // See if a provider is registered to handle the extension. Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace); if (provider != null) { if (provider instanceof PacketExtensionProvider) { return ((PacketExtensionProvider)provider).parseExtension(parser); } else if (provider instanceof Class) { return (PacketExtension)parseWithIntrospection( elementName, (Class)provider, parser); } } // No providers registered, so use a default extension. DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String name = parser.getName(); // If an empty element, set the value with the empty string. if (parser.isEmptyElementTag()) { extension.setValue(name,""); } // Otherwise, get the the element text. else { eventType = parser.next(); if (eventType == XmlPullParser.TEXT) { String value = parser.getText(); extension.setValue(name, value); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { done = true; } } } return extension; }
public void registerPEPParserExtension(String node, PacketExtensionProvider pepItemParser) { nodeParsers.put(node, pepItemParser); }
/** * Parses a packet extension sub-packet. * * @param elementName the XML element name of the packet extension. * @param namespace the XML namespace of the packet extension. * @param parser the XML parser, positioned at the starting element of the extension. * @return a PacketExtension. * @throws Exception if a parsing error occurs. */ public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser) throws Exception { // See if a provider is registered to handle the extension. Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace); if (provider != null) { if (provider instanceof PacketExtensionProvider) { return ((PacketExtensionProvider)provider).parseExtension(parser); } else if (provider instanceof Class) { return (PacketExtension)parseWithIntrospection( elementName, (Class<?>)provider, parser); } } // No providers registered, so use a default extension. DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String name = parser.getName(); // If an empty element, set the value with the empty string. if (parser.isEmptyElementTag()) { extension.setValue(name,""); } // Otherwise, get the the element text. else { eventType = parser.next(); if (eventType == XmlPullParser.TEXT) { String value = parser.getText(); extension.setValue(name, value); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { done = true; } } } return extension; }
/** * Parses a packet extension sub-packet. * * @param elementName * the XML element name of the packet extension. * @param namespace * the XML namespace of the packet extension. * @param parser * the XML parser, positioned at the starting element of the * extension. * @return a PacketExtension. * @throws Exception * if a parsing error occurs. */ public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser) throws Exception { // See if a provider is registered to handle the extension. Object provider = ProviderManager.getInstance().getExtensionProvider( elementName, namespace); if (provider != null) { if (provider instanceof PacketExtensionProvider) { return ((PacketExtensionProvider) provider) .parseExtension(parser); } else if (provider instanceof Class) { return (PacketExtension) parseWithIntrospection(elementName, (Class) provider, parser); } } // No providers registered, so use a default extension. DefaultPacketExtension extension = new DefaultPacketExtension( elementName, namespace); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String name = parser.getName(); // If an empty element, set the value with the empty string. if (parser.isEmptyElementTag()) { extension.setValue(name, ""); } // Otherwise, get the the element text. else { eventType = parser.next(); if (eventType == XmlPullParser.TEXT) { String value = parser.getText(); extension.setValue(name, value); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { done = true; } } } return extension; }