Android Open Source - android-rackspacecloud Servers X M L Parser






From Project

Back to project page android-rackspacecloud.

License

The source code is released under:

MIT License

If you think the Android project android-rackspacecloud 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

/**
 * /*from w w  w.j a  v  a2  s  .c o m*/
 */
package com.rackspace.cloud.servers.api.client.parsers;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

import com.rackspace.cloud.servers.api.client.Server;


/**
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
 *
 */
public class ServersXMLParser extends DefaultHandler {

  private Server server;
  private ArrayList<Server> servers;
  private ArrayList<String> publicAddresses;
  private ArrayList<String> privateAddresses;
  private boolean parsingPublicAddresses;
  private StringBuffer currentData;

  public void startDocument() {
  }

  public void endDocument() {
  }

  public void startElement(String uri, String name, String qName, Attributes atts) {

    currentData = new StringBuffer();
    if ("servers".equals(name)) {
      servers = new ArrayList<Server>();
    } else if ("server".equals(name)) {
      server = new Server();
      server.setStatus(atts.getValue("status"));
      server.setProgress(atts.getValue("progress"));
      server.setHostId(atts.getValue("hostId"));
      server.setFlavorId(atts.getValue("flavorId"));
      server.setImageId(atts.getValue("imageId"));
      server.setId(atts.getValue("id"));
      server.setName(atts.getValue("name"));
    } else if ("addresses".equals(name)) {
      //addresses = new ArrayList<String>();
    } else if ("public".equals(name)) {
      parsingPublicAddresses = true;
      publicAddresses = new ArrayList<String>();
    } else if ("private".equals(name)) {
      parsingPublicAddresses = false;
      privateAddresses = new ArrayList<String>();
    } else if ("ip".equals(name)) {
      String ipAddress = atts.getValue("addr");
      if (parsingPublicAddresses) {
        publicAddresses.add(ipAddress);
      } else {
        privateAddresses.add(ipAddress);
      }
    }
  }

  public void endElement(String uri, String name, String qName) {
    if ("servers".equals(name)) {
      
    } else if ("server".equals(name)) {
      if (servers != null) {
        servers.add(server);
      }
    } else if ("addresses".equals(name)) {
      
      String[] privateIpAddresses = new String[privateAddresses.size()];
      String[] publicIpAddresses = new String[publicAddresses.size()];
      
      for (int i = 0; i < privateAddresses.size(); i++) {
        privateIpAddresses[i] = privateAddresses.get(i);
      }
      for (int i = 0; i < publicAddresses.size(); i++) {
        publicIpAddresses[i] = publicAddresses.get(i);
      }
      
      server.setPublicIpAddresses(publicIpAddresses);
      server.setPrivateIpAddresses(privateIpAddresses);      
    }
  }

  public void characters(char ch[], int start, int length) {
    Log.d("Rackspace-Cloud", "Characters:    \"");
    for (int i = start; i < start + length; i++) {
      switch (ch[i]) {
      case '\\':
        Log.d("Rackspace-Cloud", "\\\\");
        break;
      case '"':
        Log.d("Rackspace-Cloud", "\\\"");
        break;
      case '\n':
        Log.d("Rackspace-Cloud", "\\n");
        break;
      case '\r':
        Log.d("Rackspace-Cloud", "\\r");
        break;
      case '\t':
        Log.d("Rackspace-Cloud", "\\t");
        break;
      default:
        Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
        break;
      }
    }
    Log.d("Rackspace-Cloud", "\"\n");
    
    
    for (int i = start; i < (start + length); i++) {
      currentData.append(ch[i]);
    }
  }

  public Server getServer() {
    return server;
  }

  public void setServer(Server server) {
    this.server = server;
  }

  /**
   * @return the servers
   */
  public ArrayList<Server> getServers() {
    return servers;
  }

  /**
   * @param servers the servers to set
   */
  public void setServers(ArrayList<Server> servers) {
    this.servers = servers;
  }

  
}




Java Source Code List

com.rackspace.cloud.files.api.client.ContainerManager.java
com.rackspace.cloud.files.api.client.ContainerObjectManager.java
com.rackspace.cloud.files.api.client.ContainerObjects.java
com.rackspace.cloud.files.api.client.Container.java
com.rackspace.cloud.files.api.client.CustomHttpClient.java
com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser.java
com.rackspace.cloud.files.api.client.parsers.ContainerXMLParser.java
com.rackspace.cloud.servers.api.client.Account.java
com.rackspace.cloud.servers.api.client.Backup.java
com.rackspace.cloud.servers.api.client.CloudServersException.java
com.rackspace.cloud.servers.api.client.EntityManager.java
com.rackspace.cloud.servers.api.client.Entity.java
com.rackspace.cloud.servers.api.client.FlavorManager.java
com.rackspace.cloud.servers.api.client.Flavor.java
com.rackspace.cloud.servers.api.client.ImageManager.java
com.rackspace.cloud.servers.api.client.Image.java
com.rackspace.cloud.servers.api.client.ServerManager.java
com.rackspace.cloud.servers.api.client.Server.java
com.rackspace.cloud.servers.api.client.http.Authentication.java
com.rackspace.cloud.servers.api.client.http.HttpBundle.java
com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser.java
com.rackspace.cloud.servers.api.client.parsers.FlavorsXMLParser.java
com.rackspace.cloud.servers.api.client.parsers.ImagesXMLParser.java
com.rackspace.cloud.servers.api.client.parsers.ServersXMLParser.java
com.rackspacecloud.android.AddAccountActivity.java
com.rackspacecloud.android.AddContainerActivity.java
com.rackspacecloud.android.AddFileActivity.java
com.rackspacecloud.android.AddServerActivity.java
com.rackspacecloud.android.AndroidCloudApplication.java
com.rackspacecloud.android.BackupServerActivity.java
com.rackspacecloud.android.Config.java
com.rackspacecloud.android.ConfirmResizeActivity.java
com.rackspacecloud.android.ContactActivity.java
com.rackspacecloud.android.ContainerObjectDetails.java
com.rackspacecloud.android.ContainerObjectsActivity.java
com.rackspacecloud.android.CreatePasswordActivity.java
com.rackspacecloud.android.EnableCDNActivity.java
com.rackspacecloud.android.ErrorDetailsActivity.java
com.rackspacecloud.android.GaActivity.java
com.rackspacecloud.android.GaListActivity.java
com.rackspacecloud.android.ListAccountsActivity.java
com.rackspacecloud.android.ListContainerActivity.java
com.rackspacecloud.android.ListServersActivity.java
com.rackspacecloud.android.PasswordManager.java
com.rackspacecloud.android.PasswordServerActivity.java
com.rackspacecloud.android.PingServerActivity.java
com.rackspacecloud.android.Preferences.java
com.rackspacecloud.android.ServerErrorActivity.java
com.rackspacecloud.android.TabViewActivity.java
com.rackspacecloud.android.ViewServerActivity.java
net.elasticgrid.rackspace.cloudservers.Addresses.java
net.elasticgrid.rackspace.cloudservers.BackupSchedule.java
net.elasticgrid.rackspace.cloudservers.CloudServersException.java
net.elasticgrid.rackspace.cloudservers.CloudServers.java
net.elasticgrid.rackspace.cloudservers.File.java
net.elasticgrid.rackspace.cloudservers.Flavor.java
net.elasticgrid.rackspace.cloudservers.HTTPVerb.java
net.elasticgrid.rackspace.cloudservers.Image.java
net.elasticgrid.rackspace.cloudservers.Limits.java
net.elasticgrid.rackspace.cloudservers.Personality.java
net.elasticgrid.rackspace.cloudservers.RebootType.java
net.elasticgrid.rackspace.cloudservers.Server.java
net.elasticgrid.rackspace.cloudservers.SharedIPGroup.java
net.elasticgrid.rackspace.cloudservers.XMLCloudServers.java
net.elasticgrid.rackspace.cloudservers.package-info.java
net.elasticgrid.rackspace.common.RackspaceConnection.java
net.elasticgrid.rackspace.common.RackspaceException.java
net.elasticgrid.rackspace.common.package-info.java
org.jclouds.date.joda.JodaDateService.java
org.jclouds.date.joda.config.JodaDateServiceModule.java
org.jclouds.encryption.bouncycastle.BouncyCastleEncryptionService.java
org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule.java
org.jclouds.enterprise.config.EnterpriseConfigurationModule.java
org.jclouds.gae.GaeHttpCommandExecutorService.java
org.jclouds.gae.config.GoogleAppEngineConfigurationModule.java
org.jclouds.http.apachehc.ApacheHCHttpCommandExecutorService.java
org.jclouds.http.apachehc.ApacheHCUtils.java
org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule.java
org.jclouds.http.httpnio.config.NioTransformingHttpCommandExecutorServiceModule.java
org.jclouds.http.httpnio.pool.NioHttpCommandConnectionHandle.java
org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPool.java
org.jclouds.http.httpnio.pool.NioHttpCommandExecutionHandler.java
org.jclouds.http.httpnio.pool.NioTransformingHttpCommandExecutorService.java
org.jclouds.http.httpnio.util.NioHttpUtils.java
org.jclouds.http.pool.ConnectionPoolTransformingHttpCommandExecutorService.java
org.jclouds.http.pool.HttpCommandConnectionHandle.java
org.jclouds.http.pool.HttpCommandConnectionPool.java
org.jclouds.http.pool.config.ConnectionPoolCommandExecutorServiceModule.java
org.jclouds.logging.log4j.Log4JLogger.java
org.jclouds.logging.log4j.config.Log4JLoggingModule.java
org.jclouds.ssh.jsch.JschSshClient.java
org.jclouds.ssh.jsch.config.JschSshClientModule.java