fbuploadphotorequest.java

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

JAVA
168
字号
// 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:   FbUploadPhotoRequest.java

package com.sonyericsson.fb.api.request;

import com.sonyericsson.fb.api.InvalidStateException;
import com.sonyericsson.fb.api.data.FbItemDataFactory;
import com.sonyericsson.fb.api.data.FbPhotoItemData;
import com.sonyericsson.fb.io.HttpMultipartRequest;
import com.sonyericsson.fb.io.IFbProgressListener;
import com.sonyericsson.fb.utils.Logger;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.io.*;
import se.southend.drops.xml.XMLNode;

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

public class FbUploadPhotoRequest extends FbAPIRequest
{

    public FbUploadPhotoRequest(IFbAPIRequestListener listener, IFbProgressListener progressListener, String filePath, String MIMEtype, String albumId, String caption)
    {
        _filePath = "";
        _MIMEtype = "";
        _albumId = "";
        _caption = "";
        _progressListener = null;
        _photos = new Vector();
        _listener = listener;
        _filePath = filePath;
        _MIMEtype = MIMEtype;
        _albumId = albumId;
        _caption = caption;
        _progressListener = progressListener;
    }

    public Vector getPhotos()
    {
        return _photos;
    }

    public void runRequest()
    {
        Hashtable arguments = new Hashtable();
        arguments.put("method", "facebook.photos.upload");
        if(_albumId.length() > 0)
            arguments.put("aid", _albumId);
        if(_caption.length() > 0)
            arguments.put("caption", _caption);
        Hashtable binaryArguments = new Hashtable();
        binaryArguments.put(_filePath, _MIMEtype);
        XMLNode root = new XMLNode();
        _statusCode = callMethod(arguments, binaryArguments, root);
        if(_statusCode == 0 && root != null && root.getName().equalsIgnoreCase("photos_upload_response"))
        {
            for(int i = 0; i < root.getNumberOfChildren(); i++)
            {
                XMLNode child = root.getChild(i);
                FbPhotoItemData photo = (FbPhotoItemData)FbItemDataFactory.getInstance().createItem(3, child);
                if(photo != null)
                    _photos.addElement(photo);
            }

        }
        if(_listener != null)
            _listener.requestCompleted(this);
    }

    protected int callMethod(Hashtable methodSpecificArguments, Hashtable methodSpecificBinaryArguments, XMLNode root)
    {
        String serverUrl;
        HttpConnection connection;
        byte result[];
        serverUrl = "";
        try
        {
            serverUrl = prepareMethodArguments(methodSpecificArguments);
        }
        catch(InvalidStateException exception)
        {
            return 2003;
        }
        connection = null;
        _serverTime = -1L;
        result = null;
        char c;
        connection = (HttpConnection)Connector.open(serverUrl, 3, true);
        HttpMultipartRequest multipart = new HttpMultipartRequest(connection);
        if(multipart.prepareBinaryData(methodSpecificArguments, methodSpecificBinaryArguments))
        {
            multipart.SetListener(_progressListener);
            result = multipart.send();
            try
            {
                _serverTime = connection.getHeaderFieldDate("Date", 0L) / 1000L;
            }
            catch(IOException dateException)
            {
                Logger.printErrorln("FbAPI.CallMethod(): Failed to get server timestamp! Using system time from phone\r\n");
                _serverTime = System.currentTimeMillis() / 1000L;
            }
            break MISSING_BLOCK_LABEL_180;
        }
        Logger.printErrorln("FbUploadPhotoRequest.callMethod(): Could not prepare binary multipart post.");
        c = '\u07D0';
        if(connection != null)
            try
            {
                connection.close();
            }
            catch(IOException e)
            {
                Logger.printErrorln("FbAPI.CallMethod(): Could not close stream: " + e.toString());
            }
        return c;
        IOException e;
        if(connection != null)
            try
            {
                connection.close();
            }
            // Misplaced declaration of an exception variable
            catch(IOException e)
            {
                Logger.printErrorln("FbAPI.CallMethod(): Could not close stream: " + e.toString());
            }
        break MISSING_BLOCK_LABEL_348;
        e;
        Logger.printErrorln("FbAPI.CallMethod(): 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("FbAPI.CallMethod(): Could not close stream: " + e.toString());
            }
        break MISSING_BLOCK_LABEL_348;
        Exception exception1;
        exception1;
        if(connection != null)
            try
            {
                connection.close();
            }
            catch(IOException e)
            {
                Logger.printErrorln("FbAPI.CallMethod(): Could not close stream: " + e.toString());
            }
        throw exception1;
        return result != null ? 0 : 2002;
    }

    private String _filePath;
    private String _MIMEtype;
    private String _albumId;
    private String _caption;
    private IFbProgressListener _progressListener;
    private Vector _photos;
}

⌨️ 快捷键说明

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