public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException { Bookmarks storage = new Bookmarks(); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && "url".equals(parser.getName())) { final BookmarkedURL urlStorage = getURLStorage(parser); if (urlStorage != null) { storage.addBookmarkedURL(urlStorage); } } else if (eventType == XmlPullParser.START_TAG && "conference".equals(parser.getName())) { final BookmarkedConference conference = getConferenceStorage(parser); storage.addBookmarkedConference(conference); } else if (eventType == XmlPullParser.END_TAG && "storage".equals(parser.getName())) { done = true; } } return storage; }
PrivateDataResult(PrivateData privateData) { this.privateData = privateData; }
public PrivateData getPrivateData() { return privateData; }
@Override public PrivateDataIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { PrivateData privateData = null; boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String elementName = parser.getName(); String namespace = parser.getNamespace(); // See if any objects are registered to handle this private data type. PrivateDataProvider provider = getPrivateDataProvider(elementName, namespace); // If there is a registered provider, use it. if (provider != null) { privateData = provider.parsePrivateData(parser); } // Otherwise, use a DefaultPrivateData instance to store the private data. else { DefaultPrivateData data = new DefaultPrivateData(elementName, namespace); boolean finished = false; while (!finished) { int event = parser.next(); if (event == XmlPullParser.START_TAG) { String name = parser.getName(); // If an empty element, set the value with the empty string. if (parser.isEmptyElementTag()) { data.setValue(name,""); } // Otherwise, get the the element text. else { event = parser.next(); if (event == XmlPullParser.TEXT) { String value = parser.getText(); data.setValue(name, value); } } } else if (event == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { finished = true; } } } privateData = data; } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("query")) { done = true; } } } return new PrivateDataIQ(privateData); }
/** * Returns the private data specified by the given element name and namespace. Each chunk * of private data is uniquely identified by an element name and namespace pair.<p> * * If a PrivateDataProvider is registered for the specified element name/namespace pair then * that provider will determine the specific object type that is returned. If no provider * is registered, a {@link DefaultPrivateData} instance will be returned. * * @param elementName the element name. * @param namespace the namespace. * @return the private data. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException { // Create an IQ packet to get the private data. IQ privateDataGet = new PrivateDataIQ(elementName, namespace); PrivateDataIQ response = connection().createPacketCollectorAndSend( privateDataGet).nextResultOrThrow(); return response.getPrivateData(); }
/** * Sets a private data value. Each chunk of private data is uniquely identified by an * element name and namespace pair. If private data has already been set with the * element name and namespace, then the new private data will overwrite the old value. * * @param privateData the private data. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ public void setPrivateData(final PrivateData privateData) throws NoResponseException, XMPPErrorException, NotConnectedException { // Create an IQ packet to set the private data. IQ privateDataSet = new PrivateDataIQ(privateData); connection().createPacketCollectorAndSend(privateDataSet).nextResultOrThrow(); }
/** * Parse the private data sub-document and create a PrivateData instance. At the * beginning of the method call, the xml parser will be positioned at the opening * tag of the private data child element. At the end of the method call, the parser * <b>must</b> be positioned on the closing tag of the child element. * * @param parser an XML parser. * @return a new PrivateData instance. */ public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException;