fbitemdatafactory.java

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

JAVA
173
字号
// 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:   FbItemDataFactory.java

package com.sonyericsson.fb.api.data;

import java.util.Hashtable;
import se.southend.drops.xml.XMLNode;

// Referenced classes of package com.sonyericsson.fb.api.data:
//            FbStatusItemData, FbFriendItemData, FbNewsItemData, FbPhotoItemData, 
//            FbItemData

public class FbItemDataFactory
{

    public FbItemDataFactory()
    {
    }

    public static FbItemDataFactory getInstance()
    {
        if(_instance == null)
            _instance = new FbItemDataFactory();
        return _instance;
    }

    public FbItemData createItem(int itemType, XMLNode node)
    {
        if(node == null)
            return null;
        FbItemData item = null;
        Hashtable information = new Hashtable();
        switch(itemType)
        {
        case 0: // '\0'
            if(node.getName().equalsIgnoreCase("user"))
            {
                XMLNode uid = node.getChild("uid");
                XMLNode status = node.getChild("status");
                if(uid != null && uid.getValue().length() > 0 && status != null)
                {
                    XMLNode message = status.getChild("message");
                    XMLNode time = status.getChild("time");
                    information.put("uid", uid.getValue());
                    if(message != null && message.getValue().length() > 0)
                        information.put("message", message.getValue());
                    if(time != null && time.getValue().length() > 0)
                        information.put("time", time.getValue());
                    item = new FbStatusItemData(information);
                }
            }
            break;

        case 1: // '\001'
            if(!node.getName().equalsIgnoreCase("user") && !node.getName().equalsIgnoreCase("contact_info"))
                break;
            XMLNode uid = node.getChild("uid");
            XMLNode name = node.getChild("name");
            XMLNode picUrl = node.getChild("pic_square");
            XMLNode pic = node.getChild("pic");
            XMLNode lastName = node.getChild("last_name");
            XMLNode email = node.getChild("email");
            XMLNode cell = node.getChild("cell");
            XMLNode phone = node.getChild("phone");
            XMLNode address = node.getChild("address");
            XMLNode city = node.getChild("city");
            XMLNode zip = node.getChild("zip");
            if(uid == null || uid.getValue().length() <= 0)
                break;
            information.put("uid", uid.getValue());
            if(name != null && name.getValue().length() > 0)
                information.put("name", name.getValue());
            if(picUrl != null && picUrl.getValue().length() > 0)
                information.put("pic_square", picUrl.getValue());
            if(pic != null && pic.getValue().length() > 0)
                information.put("pic", pic.getValue());
            if(lastName != null && lastName.getValue().length() > 0)
                information.put("last_name", lastName.getValue());
            if(email != null && email.getValue().length() > 0)
                information.put("email", email.getValue());
            if(cell != null && cell.getValue().length() > 0)
                information.put("cell", cell.getValue());
            if(phone != null && phone.getValue().length() > 0)
                information.put("phone", phone.getValue());
            if(address != null && address.getValue().length() > 0)
                information.put("address", address.getValue());
            if(city != null && city.getValue().length() > 0)
                information.put("city", city.getValue());
            if(zip != null && zip.getValue().length() > 0)
                information.put("zip", zip.getValue());
            FbStatusItemData statusItem = (FbStatusItemData)createItem(0, node);
            item = new FbFriendItemData(information, statusItem);
            break;

        case 2: // '\002'
            if(!node.getName().equalsIgnoreCase("feed_story"))
                break;
            XMLNode type = node.getChild("type");
            XMLNode text = node.getChild("text");
            XMLNode href = node.getChild("href");
            XMLNode icon = node.getChild("icon");
            XMLNode time = node.getChild("time");
            if(type == null || type.getValue().length() <= 0)
                break;
            information.put("type", type.getValue());
            if(text != null && text.getValue().length() > 0)
                information.put("text", text.getValue());
            if(href != null && href.getValue().length() > 0)
                information.put("href", href.getValue());
            if(icon != null && icon.getValue().length() > 0)
                information.put("icon", icon.getValue());
            if(time != null && time.getValue().length() > 0)
                information.put("time", time.getValue());
            item = new FbNewsItemData(information);
            break;

        case 3: // '\003'
            if(!node.getName().equalsIgnoreCase("photos_upload_response"))
                break;
            for(int i = 0; i < node.getNumberOfChildren(); i++)
            {
                XMLNode child = node.getChild(i);
                if(child != null && child.getValue().length() > 0)
                    information.put(child.getName(), child.getValue());
            }

            if(information.size() > 0)
                item = new FbPhotoItemData(information);
            break;

        default:
            item = null;
            break;
        }
        return item;
    }

    public FbItemData updateItem(FbItemData item, FbItemData newData)
    {
        if(item == null || newData == null)
            return null;
        FbItemData updated = null;
        if(!(item instanceof FbStatusItemData))
            if(item instanceof FbFriendItemData)
            {
                FbFriendItemData friend = (FbFriendItemData)item;
                FbFriendItemData additionalInformation = (FbFriendItemData)newData;
                if(friend.getUid().equals(additionalInformation.getUid()))
                    updated = new FbFriendItemData(friend, additionalInformation);
            } else
            if(!(item instanceof FbNewsItemData))
                if(!(item instanceof FbPhotoItemData));
        return updated;
    }

    public FbFriendItemData updateStatus(FbFriendItemData friend, FbStatusItemData status)
    {
        Hashtable newInformation = new Hashtable();
        newInformation.put("uid", friend.getUid());
        FbFriendItemData newStatus = new FbFriendItemData(newInformation, status);
        return (FbFriendItemData)updateItem(friend, newStatus);
    }

    public static final int FB_ITEM_STATUS = 0;
    public static final int FB_ITEM_FRIEND = 1;
    public static final int FB_ITEM_NEWS = 2;
    public static final int FB_ITEM_PHOTO = 3;
    private static FbItemDataFactory _instance = null;

}

⌨️ 快捷键说明

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