public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { 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; }
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && "tasks".equals(parser.getName())) { String showAll = parser.getAttributeValue("", "showAll"); ScratchPadPlugin.SHOW_ALL_TASKS = Boolean.parseBoolean(showAll); } if (eventType == XmlPullParser.START_TAG && "task".equals(parser.getName())) { tasks.addTask(getTask(parser)); } else if (eventType == XmlPullParser.END_TAG) { if ("scratchpad".equals(parser.getName())) { done = true; } } } return tasks; }
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && "text".equals(parser.getName())) { notes.setNotes(parser.nextText()); } else if (eventType == XmlPullParser.END_TAG) { if ("scratchpad".equals(parser.getName())) { done = true; } } } return notes; }
/** * 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 XMPPException if an error occurs getting the private data. */ public PrivateData getPrivateData(final String elementName, final String namespace) throws XMPPException { // Create an IQ packet to get the private data. IQ privateDataGet = new IQ() { public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:private\">"); buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>"); buf.append("</query>"); return buf.toString(); } }; privateDataGet.setType(IQ.Type.GET); // Address the packet to the other account if user has been set. if (user != null) { privateDataGet.setTo(user); } // Setup a listener for the reply to the set operation. String packetID = privateDataGet.getPacketID(); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID)); // Send the private data. connection.sendPacket(privateDataGet); // Wait up to five seconds for a response from the server. IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } return ((PrivateDataResult)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 XMPPException if setting the private data fails. */ public void setPrivateData(final PrivateData privateData) throws XMPPException { // Create an IQ packet to set the private data. IQ privateDataSet = new IQ() { public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:private\">"); buf.append(privateData.toXML()); buf.append("</query>"); return buf.toString(); } }; privateDataSet.setType(IQ.Type.SET); // Address the packet to the other account if user has been set. if (user != null) { privateDataSet.setTo(user); } // Setup a listener for the reply to the set operation. String packetID = privateDataSet.getPacketID(); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID)); // Send the private data. connection.sendPacket(privateDataSet); // Wait up to five seconds for a response from the server. IQ response = (IQ)collector.nextResult(5000); // Stop queuing results collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } }
/** * 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 XMPPException * if setting the private data fails. */ public void setPrivateData(final PrivateData privateData) throws XMPPException { // Create an IQ packet to set the private data. IQ privateDataSet = new IQ() { public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:private\">"); buf.append(privateData.toXML()); buf.append("</query>"); return buf.toString(); } }; privateDataSet.setType(IQ.Type.SET); // Address the packet to the other account if user has been set. if (user != null) { privateDataSet.setTo(user); } // Setup a listener for the reply to the set operation. String packetID = privateDataSet.getPacketID(); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(packetID)); // Send the private data. connection.sendPacket(privateDataSet); // Wait up to five seconds for a response from the server. IQ response = (IQ) collector.nextResult(5000); // Stop queuing results collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } }
/** * Parses the xml stream for workgroup settings. * @param parser the XmlPullParse to use. * @return the PrivateData. * @throws Exception */ public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { final Map map = new HashMap(); String t = parser.getText(); int eventType = parser.getEventType(); String privateSuperTagName = null; boolean isPersonal = true; if (eventType != XmlPullParser.START_TAG) { // throw exception } eventType = parser.nextTag(); String text = parser.getName(); while (true) { if ("entry".equals(text)) { eventType = parser.nextTag(); String name = parser.getName(); text = parser.nextText(); map.put(name, text); eventType = parser.nextTag(); eventType = parser.nextTag(); text = parser.getName(); } else { break; } } return new SettingsPrivateData("workgroup", map); }
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { GatewayPrivateData data = new GatewayPrivateData(); boolean done = false; boolean isInstalled = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateways")) { isInstalled = true; } if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateway")) { boolean gatewayDone = false; String serviceName = null; String autoLogin = null; while (!gatewayDone) { int eType = parser.next(); if (eType == XmlPullParser.START_TAG && parser.getName().equals("serviceName")) { serviceName = parser.nextText(); } else if (eType == XmlPullParser.START_TAG && parser.getName().equals("autoLogin")) { autoLogin = parser.nextText(); } else if (eType == XmlPullParser.END_TAG && parser.getName().equals("gateway")) { data.addService(serviceName, Boolean.parseBoolean(autoLogin)); gatewayDone = true; } } } else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("gateways")) { done = true; } else if (!isInstalled) { done = true; } } return data; }
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { Map<String,String> map = new HashMap<String,String>(); parser.getEventType(); parser.nextTag(); for (String text = parser.getName(); text.equals("entry"); text = parser.getName()) { parser.nextTag(); String name = parser.getName(); text = parser.nextText(); map.put(name, text); parser.nextTag(); parser.nextTag(); } return new SettingsData(map); }
public IQ parseIQ(XmlPullParser parser) throws Exception { 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 PrivateDataResult(privateData); }
PrivateDataResult(PrivateData privateData) { this.privateData = privateData; }
public PrivateData getPrivateData() { return 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 XMPPException * if an error occurs getting the private data. */ public PrivateData getPrivateData(final String elementName, final String namespace) throws XMPPException { // Create an IQ packet to get the private data. IQ privateDataGet = new IQ() { public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:private\">"); buf.append("<").append(elementName).append(" xmlns=\"") .append(namespace).append("\"/>"); buf.append("</query>"); return buf.toString(); } }; privateDataGet.setType(IQ.Type.GET); // Address the packet to the other account if user has been set. if (user != null) { privateDataGet.setTo(user); } // Setup a listener for the reply to the set operation. String packetID = privateDataGet.getPacketID(); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(packetID)); // Send the private data. connection.sendPacket(privateDataGet); // Wait up to five seconds for a response from the server. IQ response = (IQ) collector.nextResult(SmackConfiguration .getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } return ((PrivateDataResult) response).getPrivateData(); }
public IQ parseIQ(XmlPullParser parser) throws Exception { 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 PrivateDataResult(privateData); }