Android Open Source - msf-spaces-sdk-android Spaces Provider






From Project

Back to project page msf-spaces-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project msf-spaces-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.imc.mirror.sdk.android;
//from  w  w w . j  ava  2s .  co m
import org.jdom2.Element;
import org.jdom2.output.XMLOutputter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;


/**
 * Provider for IQ packages starting with a <code>spaces</code> tag.
 * Used internally by the spaces manager.
 *
 */
public class SpacesProvider implements IQProvider {
  
  public class SpacesIQ extends IQ {
    private Element element;
    public SpacesIQ(Element element) {
      this.element = element;
    }
    
    @Override
    public String getChildElementXML() {
      XMLOutputter out = new XMLOutputter();
      return out.outputString(element);
    }
  }

  @Override
  public IQ parseIQ(XmlPullParser parser) throws Exception {
    String rootTagName = parser.getName();
    String namespace = parser.getNamespace();
    Element spacesElement = new Element(rootTagName, namespace); 
    boolean done = false;
    while (!done) {
      int event = parser.next();
      switch (event) {
      case XmlPullParser.START_TAG:
        String tagName = parser.getName();
        CommandType command = CommandType.getTypeForTagName(tagName);
        switch (command) {
        case CREATE:
          parseCreateTag(parser, spacesElement);
          break;
        case CHANNELS:
          parseChannelsTag(parser, spacesElement);
          break;
        case MODELS:
          parseModelsTag(parser, spacesElement);
          break;
        case VERSION:
          parseVersion(parser, spacesElement);
          break;
        case CONFIGURE:
        case DELETE:
        default:
          Element errorElement = new Element("error");
          errorElement.setText("Unsupported command: " + tagName);
          spacesElement.setContent(errorElement);
        }
        break;
      case XmlPullParser.END_TAG:
        if ("spaces".equals(parser.getName())) {
          done = true;
        }
        break;
      }
    }
    return new SpacesIQ(spacesElement);
  }
  
  /**
   * Parses a createtag.
   * @param parser The used XmlPullParser.
   * @param parent The parent of this tag.
   */
  private void parseCreateTag(XmlPullParser parser, Element parent) {
    Element createElement = new Element(parser.getName(), parent.getNamespace());
    parent.addContent(createElement);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      createElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
    }
  }
  
  /**
   * Parses the version tag.
   * @param parser The used XmlPullParser.
   * @param parent The parent of this tag.
   */
  private void parseVersion(XmlPullParser parser, Element parent) throws Exception {
    Element versionElement = new Element(parser.getName(), parent.getNamespace());
    parent.addContent(versionElement);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      versionElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
    }
    int event = parser.next();
    if (event == XmlPullParser.TEXT) {
      versionElement.setText(parser.getText());
    }
  }
  
  /**
   * Parses a channelstag.
   * @param parser The used XmlPullParser.
   * @param parent The parent of this tag.
   */
  private void parseChannelsTag(XmlPullParser parser, Element parent) throws Exception {
    String elementName = parser.getName();
    Element channelsElement = new Element(elementName, parent.getNamespace());
    parent.addContent(channelsElement);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      channelsElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
    }
    
    boolean done = false;
    while (!done) {
      int event = parser.next();
      switch (event) {
      case XmlPullParser.START_TAG:
        String tagName = parser.getName();
        if ("channel".equals(tagName)) {
          parseChannelTag(parser, channelsElement);
        } else {
          throw new RuntimeException("Illegal response: <channels /> element may not contain: " + tagName);
        }
        break;
      case XmlPullParser.END_TAG:
        if (parser.getName().equals(elementName)) {
          done = true;
        }
      }
    }
  }
  
  /**
   * Parses a channeltag.
   * @param parser The used XmlPullParser.
   * @param parent The parent of this tag.
   */
  private void parseChannelTag(XmlPullParser parser, Element parent) throws Exception {
    String elementName = parser.getName();
    Element channelElement = new Element(elementName, parent.getNamespace());
    parent.addContent(channelElement);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      channelElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
    }
    boolean done = false;
    Element propertyElement = null;
    while (!done) {
      int event = parser.next();
      switch (event) {
      case XmlPullParser.START_TAG:
        String tagName = parser.getName();
        if ("property".equals(tagName)) {
          propertyElement = new Element(tagName, parent.getNamespace());
          channelElement.addContent(propertyElement);
          for (int i = 0; i < parser.getAttributeCount(); i++) {
            propertyElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
          }
        } else {
          throw new RuntimeException("Illegal response: <channel /> element may not contain: " + tagName);
        }
        break;
      case XmlPullParser.TEXT:
        String text = parser.getText();
        if (propertyElement != null) {
          propertyElement.setText(text);
        } else {
          throw new RuntimeException("Illegal response: Invalid node content: " + text);
        }
        
      case XmlPullParser.END_TAG:
        tagName = parser.getName();
        if (elementName.equals(tagName)) {
          done = true;
        }
      }
    }    
  }
  
  /**
   * Parses a modelstag.
   * @param parser The used XmlPullParser.
   * @param parent The parent of this tag.
   */
  private void parseModelsTag(XmlPullParser parser, Element parent) throws Exception {
    String elementName = parser.getName();
    Element modelsElement = new Element(elementName, parent.getNamespace());
    parent.addContent(modelsElement);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      modelsElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
    }
    boolean done = false;
    Element modelElement = null;
    while (!done) {
      int event = parser.next();
      switch (event) {
      case XmlPullParser.START_TAG:
        String tagName = parser.getName();
        if ("model".equals(tagName)) {
          modelElement = new Element(tagName, parent.getNamespace());
          modelsElement.addContent(modelElement);
          for (int i = 0; i < parser.getAttributeCount(); i++) {
            modelElement.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
          }
        } else {
          throw new RuntimeException("Illegal response: <channel /> element may not contain: " + tagName);
        }
        break;
      case XmlPullParser.TEXT:
        String text = parser.getText();
        if (modelElement != null) {
          modelElement.setText(text);
        } else {
          throw new RuntimeException("Illegal response: Invalid node content: " + text);
        }
        
      case XmlPullParser.END_TAG:
        tagName = parser.getName();
        if (elementName.equals(tagName)) {
          done = true;
        }
      }
    }  
  }
}




Java Source Code List

de.imc.mirror.sdk.android.CDMDataBuilder.java
de.imc.mirror.sdk.android.CDMData.java
de.imc.mirror.sdk.android.CommandType.java
de.imc.mirror.sdk.android.ConnectionConfigurationBuilder.java
de.imc.mirror.sdk.android.ConnectionConfiguration.java
de.imc.mirror.sdk.android.ConnectionHandler.java
de.imc.mirror.sdk.android.DataHandler.java
de.imc.mirror.sdk.android.DataModel.java
de.imc.mirror.sdk.android.DataObjectBuilder.java
de.imc.mirror.sdk.android.DataObject.java
de.imc.mirror.sdk.android.DataWrapper.java
de.imc.mirror.sdk.android.NetworkInformation.java
de.imc.mirror.sdk.android.OrgaSpace.java
de.imc.mirror.sdk.android.PrivateSpace.java
de.imc.mirror.sdk.android.ProviderInitializer.java
de.imc.mirror.sdk.android.RequestFuture.java
de.imc.mirror.sdk.android.SpaceChannel.java
de.imc.mirror.sdk.android.SpaceConfiguration.java
de.imc.mirror.sdk.android.SpaceHandler.java
de.imc.mirror.sdk.android.SpaceMember.java
de.imc.mirror.sdk.android.Space.java
de.imc.mirror.sdk.android.SpacesProvider.java
de.imc.mirror.sdk.android.TeamSpace.java
de.imc.mirror.sdk.android.UserInfo.java
de.imc.mirror.sdk.android.cdm.CDMData_0_1.java
de.imc.mirror.sdk.android.cdm.CDMData_0_2.java
de.imc.mirror.sdk.android.cdm.CDMData_1_0.java
de.imc.mirror.sdk.android.cdm.CDMData_2_0.java
de.imc.mirror.sdk.android.cdm.CreationInfo.java
de.imc.mirror.sdk.android.cdm.Reference.java
de.imc.mirror.sdk.android.cdm.References.java
de.imc.mirror.sdk.android.cdm.Summary.java
de.imc.mirror.sdk.android.data.ChannelsTable.java
de.imc.mirror.sdk.android.data.DataDB.java
de.imc.mirror.sdk.android.data.DataTable.java
de.imc.mirror.sdk.android.data.MembersTable.java
de.imc.mirror.sdk.android.data.SendTable.java
de.imc.mirror.sdk.android.data.SpacesTable.java
de.imc.mirror.sdk.android.exceptions.InvalidBuildException.java
de.imc.mirror.sdk.android.exceptions.RequestException.java
de.imc.mirror.sdk.android.filter.AndFilter.java
de.imc.mirror.sdk.android.filter.DataModelFilter.java
de.imc.mirror.sdk.android.filter.NamespaceFilter.java
de.imc.mirror.sdk.android.filter.OrFilter.java
de.imc.mirror.sdk.android.filter.PeriodFilter.java
de.imc.mirror.sdk.android.filter.PublisherFilter.java
de.imc.mirror.sdk.android.filter.ReferencesFilter.java
de.imc.mirror.sdk.android.packet.DeleteRequestIQ.java
de.imc.mirror.sdk.android.packet.DeleteResponseIQ.java
de.imc.mirror.sdk.android.packet.PersistenceServiceDeleteProvider.java
de.imc.mirror.sdk.android.packet.PersistenceServiceQueryProvider.java
de.imc.mirror.sdk.android.packet.QueryRequestIQ.java
de.imc.mirror.sdk.android.packet.QueryResponseIQ.java
de.imc.mirror.sdk.android.utils.DatatypeConverter.java
de.imc.mirror.sdk.android.utils.DateToXsdDatetimeFormatter.java
org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.java
org.apache.xerces.jaxp.datatype.DurationImpl.java
org.apache.xerces.jaxp.datatype.SerializedDuration.java
org.apache.xerces.jaxp.datatype.SerializedXMLGregorianCalendar.java
org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl.java
org.apache.xerces.util.DatatypeMessageFormatter.java