fbsessionstartrequest.java

来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 221 行

JAVA
221
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   FbSessionStartRequest.java

package com.sonyericsson.fb.api.request;

import com.sonyericsson.fb.api.FbSessionHandler;
import com.sonyericsson.fb.io.HttpMultipartRequest;
import com.sonyericsson.fb.utils.Logger;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Hashtable;
import javax.microedition.io.*;
import se.southend.drops.xml.XMLListener;
import se.southend.drops.xml.XMLParser;

// Referenced classes of package com.sonyericsson.fb.api.request:
//            FbAPIRequest, IFbAPIRequestListener

public class FbSessionStartRequest extends FbAPIRequest
    implements XMLListener
{

    public FbSessionStartRequest(String user, String password, IFbAPIRequestListener listener)
    {
        _user = "";
        _password = "";
        _validResponse = false;
        _currentTag = "";
        _uid = "";
        _sessionKey = "";
        _secret = "";
        _expires = 0;
        _user = user;
        _password = password;
        _listener = listener;
        _statusCode = 2003;
    }

    public void runRequest()
    {
        Hashtable table;
        HttpConnection connection;
        byte result[];
        table = new Hashtable();
        table.put("method", "facebook.auth.login");
        table.put("api_key", "cab9b0c2b22b9628e5d4966412f1c1a1");
        table.put("email", _user);
        table.put("password", _password);
        table.put("v", "1.0");
        String signature = FbSessionHandler.getInstance().calculateSignature(table, "4c2ba82712e7fc831c0ad4f9865922ae");
        table.put("sig", signature);
        connection = null;
        result = null;
        connection = (HttpConnection)Connector.open("https://api.facebook.com/restserver.php", 3, true);
        HttpMultipartRequest multipart = new HttpMultipartRequest(connection);
        multipart.preparePostData(table);
        result = multipart.send();
        IOException e;
        if(connection != null)
            try
            {
                connection.close();
            }
            // Misplaced declaration of an exception variable
            catch(IOException e)
            {
                Logger.printErrorln("FbSessionStartRequest.runRequest(): Could not close stream: " + e.toString());
            }
        break MISSING_BLOCK_LABEL_277;
        e;
        Logger.printErrorln("FbSessionStartRequest.runRequest(): Error when trying to start a new facebook session: " + e.toString());
        if(connection != null)
            try
            {
                connection.close();
            }
            // Misplaced declaration of an exception variable
            catch(IOException e)
            {
                Logger.printErrorln("FbSessionStartRequest.runRequest(): Could not close stream: " + e.toString());
            }
        break MISSING_BLOCK_LABEL_277;
        Exception exception;
        exception;
        if(connection != null)
            try
            {
                connection.close();
            }
            catch(IOException e)
            {
                Logger.printErrorln("FbSessionStartRequest.runRequest(): Could not close stream: " + e.toString());
            }
        throw exception;
        if(result == null)
        {
            _statusCode = 2002;
        } else
        {
            ByteArrayInputStream bais = new ByteArrayInputStream(result);
            try
            {
                XMLParser.getInstance().open(bais, this);
                if(_validResponse)
                    _statusCode = 0;
            }
            catch(Exception e)
            {
                Logger.printErrorln("FbSessionStartRequest.runRequest(): Error when trying to parse XML response from server: " + e.toString());
                _statusCode = 2001;
            }
        }
        if(_listener != null)
            _listener.requestCompleted(this);
        return;
    }

    public void startDocument()
        throws Exception
    {
    }

    public void endDocument()
        throws Exception
    {
    }

    public void startElement(String tag, Hashtable attlist)
        throws Exception
    {
        if(tag.equalsIgnoreCase("auth_login_response"))
            _validResponse = true;
        else
        if(_validResponse && tag.equalsIgnoreCase("session_key"))
            _currentTag = "session_key";
        else
        if(_validResponse && tag.equalsIgnoreCase("uid"))
            _currentTag = "uid";
        else
        if(_validResponse && tag.equalsIgnoreCase("secret"))
            _currentTag = "secret";
        else
        if(_validResponse && tag.equalsIgnoreCase("expires"))
            _currentTag = "expires";
        else
        if(tag.equalsIgnoreCase("error_code"))
            _currentTag = "error_code";
    }

    public void text(String text)
        throws Exception
    {
        if(_validResponse && _currentTag.equals("session_key"))
            _sessionKey = text;
        else
        if(_validResponse && _currentTag.equalsIgnoreCase("uid"))
            _uid = text;
        else
        if(_validResponse && _currentTag.equalsIgnoreCase("secret"))
            _secret = text;
        else
        if(_validResponse && _currentTag.equalsIgnoreCase("expires"))
            try
            {
                _expires = Integer.parseInt(text);
            }
            catch(NumberFormatException e)
            {
                Logger.printErrorln("Could not parse experation time from response XML: " + e.toString());
            }
        else
        if(_currentTag.equals("error_code"))
            try
            {
                _statusCode = Integer.parseInt(text);
            }
            catch(NumberFormatException e)
            {
                Logger.printErrorln("Could not parse error code from response XML: " + e.toString());
            }
    }

    public void endElement(String tag)
        throws Exception
    {
        if(_currentTag.equalsIgnoreCase(tag))
            _currentTag = "";
    }

    public String getUid()
    {
        return _uid;
    }

    public String getSessionKey()
    {
        return _sessionKey;
    }

    public String getSecret()
    {
        return _secret;
    }

    public int getExpires()
    {
        return _expires;
    }

    private String _user;
    private String _password;
    private boolean _validResponse;
    private String _currentTag;
    private String _uid;
    private String _sessionKey;
    private String _secret;
    private int _expires;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?