org.jivesoftware.smackx.iqprivate.packet.PrivateData Java Examples

The following examples show how to use org.jivesoftware.smackx.iqprivate.packet.PrivateData. 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: Bookmarks.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
    Bookmarks storage = new Bookmarks();

    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT && "url".equals(parser.getName())) {
            final BookmarkedURL urlStorage = getURLStorage(parser);
            if (urlStorage != null) {
                storage.addBookmarkedURL(urlStorage);
            }
        }
        else if (eventType == XmlPullParser.Event.START_ELEMENT &&
                "conference".equals(parser.getName())) {
            final BookmarkedConference conference = getConferenceStorage(parser);
            storage.addBookmarkedConference(conference);
        }
        else if (eventType == XmlPullParser.Event.END_ELEMENT && "storage".equals(parser.getName())) {
            done = true;
        }
    }


    return storage;
}
 
Example #2
Source File: Tasks.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
          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;
      }
 
Example #3
Source File: PrivateNotes.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
          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;
      }
 
Example #4
Source File: SettingsDataProvider.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException
   {
       Map<String,String> map = new HashMap<>();
       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);
   }
 
Example #5
Source File: GetBookmarksTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
PrivateDataResult(PrivateData privateData) {
    this.privateData = privateData;
}
 
Example #6
Source File: GetBookmarksTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
public PrivateData getPrivateData() {
    return privateData;
}
 
Example #7
Source File: JMeterXMPPSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
PrivateDataResult(PrivateData privateData) {
    this.privateData = privateData;
}
 
Example #8
Source File: JMeterXMPPSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
public PrivateData getPrivateData() {
    return privateData;
}
 
Example #9
Source File: PrivateDataManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public PrivateDataIQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
                throws XmlPullParserException, IOException {
    PrivateData privateData = null;
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            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) {
                    XmlPullParser.Event event = parser.next();
                    if (event == XmlPullParser.Event.START_ELEMENT) {
                        String name = parser.getName();
                        event = parser.next();
                        if (event == XmlPullParser.Event.TEXT_CHARACTERS) {
                            String value = parser.getText();
                            data.setValue(name, value);
                        }
                        else if (event == XmlPullParser.Event.END_ELEMENT) {
                            // If an empty element, set the value with the empty string.
                            data.setValue(name, "");
                        }
                    }
                    else if (event == XmlPullParser.Event.END_ELEMENT) {
                        if (parser.getName().equals(elementName)) {
                            finished = true;
                        }
                    }
                }
                privateData = data;
            }
        }
        else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return new PrivateDataIQ(privateData);
}
 
Example #10
Source File: GatewayPrivateData.java    From Spark with Apache License 2.0 4 votes vote down vote up
@Override
public PrivateData parsePrivateData(XmlPullParser parser) throws IOException, XmlPullParserException
      {
          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;
                  DomainBareJid serviceName = null;
                  String autoLogin = null;
                  while (!gatewayDone) {
                      int eType = parser.next();
                      if (eType == XmlPullParser.START_TAG && parser.getName().equals("serviceName")) {
                          String serviceNameString = parser.nextText();
                          serviceName = JidCreate.domainBareFrom(serviceNameString);
                      }
                      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;
      }
 
Example #11
Source File: PrivateDataManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * 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 if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Create an IQ packet to get the private data.
    IQ privateDataGet = new PrivateDataIQ(elementName, namespace);

    PrivateDataIQ response = connection().createStanzaCollectorAndSend(
                    privateDataGet).nextResultOrThrow();
    return response.getPrivateData();
}
 
Example #12
Source File: PrivateDataManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * 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 if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void setPrivateData(final PrivateData privateData) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Create an IQ packet to set the private data.
    IQ privateDataSet = new PrivateDataIQ(privateData);

    connection().createStanzaCollectorAndSend(privateDataSet).nextResultOrThrow();
}
 
Example #13
Source File: PrivateDataProvider.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 * @throws XmlPullParserException if an error in the XML parser occurred.
 * @throws IOException if an I/O error occurred.
 */
PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException;