Android Open Source - mobcomp-httpclient Auth Reader






From Project

Back to project page mobcomp-httpclient.

License

The source code is released under:

Written by: Markus Tacker <m@coderbyheart.de> | http://coderbyheart.de/ Copyright (c) Markus Tacker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and ...

If you think the Android project mobcomp-httpclient 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.hsrm.mi.mobcomp.httpclientdemo.flickr;
//w  ww  . j a v a2  s . c  o m
import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.util.Log;

/**
 * Parst eine flickr-XML-Antwort mit einem Frob
 * 
 * @author Markus Tacker <m@coderbyheart.de>
 */
public class AuthReader extends XmlReader {
  public class Auth {
    public String token;
    public String perms;
    public User user = new User();
  }

  public class User {
    public String nsid;
    public String username;
    public String fullname;
  }

  public Auth getAuth(String xmlData) {
    Auth auth = new Auth();
    DocumentBuilderFactory domBuilderFactory = DocumentBuilderFactory
        .newInstance();
    domBuilderFactory.setIgnoringElementContentWhitespace(true);
    try {
      DocumentBuilder builder = domBuilderFactory.newDocumentBuilder();
      Document doc = builder.parse(new ByteArrayInputStream(xmlData
          .getBytes()));
      NodeList authNodes = doc.getElementsByTagName("auth").item(0).getChildNodes();
      for (int i = 0; i < authNodes.getLength(); i++) {
        Node child = authNodes.item(i);
        if (child.getNodeName().equals("token")) {
          auth.token = getTextValue(child);
        }
        if (child.getNodeName().equals("perms")) {
          auth.perms = getTextValue(child);
        }
        if (child.getNodeName().equals("user")) {
          auth.user.nsid = child.getAttributes().getNamedItem("nsid")
              .getNodeValue();
          auth.user.username = child.getAttributes()
              .getNamedItem("username").getNodeValue();
          auth.user.fullname = child.getAttributes()
              .getNamedItem("fullname").getNodeValue();
        }
      }
    } catch (SAXException e) {
      Log.e(getClass().getCanonicalName(), e.getMessage());
    } catch (ParserConfigurationException e) {
      Log.e(getClass().getCanonicalName(), e.getMessage());
    } catch (IOException e) {
      Log.e(getClass().getCanonicalName(), e.getMessage());
    }
    return auth;
  }
}




Java Source Code List

de.hsrm.mi.mobcomp.httpclientdemo.FlickrAuthActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.LoadActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.MainActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.MenuActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.PrefsActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.SendActivity.java
de.hsrm.mi.mobcomp.httpclientdemo.extra.IdFile.java
de.hsrm.mi.mobcomp.httpclientdemo.extra.ParameterRunnable.java
de.hsrm.mi.mobcomp.httpclientdemo.extra.ProgressMultipartEntity.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.AuthReader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.FrobReader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.ImageLoader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.RestAPI.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.SetsReader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.SizesReader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.UploadReader.java
de.hsrm.mi.mobcomp.httpclientdemo.flickr.XmlReader.java