mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
First cut of Facebook integration:
1) Web Script framework extensions for supporting the development of Alfresco based Facebook applications 2) Sample Document Library Facebook application 3) FormData enhancements for supporting request args retrieval for multipart/form-data encoding 4) Sort order added to Search Javascript API Note: Stuff needs commenting, tidy up, but at least it's in SVN. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7259 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
133
source/java/org/alfresco/web/scripts/facebook/FacebookModel.java
Normal file
133
source/java/org/alfresco/web/scripts/facebook/FacebookModel.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package org.alfresco.web.scripts.facebook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.facebook.api.FacebookException;
|
||||
import com.facebook.api.FacebookRestClient;
|
||||
|
||||
|
||||
public class FacebookModel
|
||||
{
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(FacebookModel.class);
|
||||
|
||||
private FacebookServletRequest req;
|
||||
private FacebookRestClient client;
|
||||
private String[] friends;
|
||||
|
||||
public FacebookModel(FacebookServletRequest req)
|
||||
{
|
||||
this.req = req;
|
||||
}
|
||||
|
||||
private FacebookRestClient getClient()
|
||||
{
|
||||
if (client == null)
|
||||
{
|
||||
String apiKey = req.getApiKey();
|
||||
String secretKey = req.getSecretKey();
|
||||
String sessionKey = req.getSessionKey();
|
||||
if (sessionKey == null)
|
||||
{
|
||||
client = new FacebookRestClient(apiKey, secretKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
client = new FacebookRestClient(apiKey, secretKey, sessionKey);
|
||||
}
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public String[] getFriends()
|
||||
{
|
||||
if (friends == null)
|
||||
{
|
||||
friends = req.getFriends();
|
||||
if (friends == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Document friendsDoc = getClient().friends_get();
|
||||
NodeList uids = friendsDoc.getElementsByTagName("uid");
|
||||
friends = new String[uids.getLength()];
|
||||
for (int i = 0; i < uids.getLength(); i++)
|
||||
{
|
||||
friends[i] = uids.item(i).getTextContent();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
friends = new String[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return friends;
|
||||
}
|
||||
|
||||
public String getUser()
|
||||
{
|
||||
return req.getUserId();
|
||||
}
|
||||
|
||||
public String getAppId()
|
||||
{
|
||||
return req.getAppId();
|
||||
}
|
||||
|
||||
public String getSessionKey()
|
||||
{
|
||||
return req.getSessionKey();
|
||||
}
|
||||
|
||||
public String getApiKey()
|
||||
{
|
||||
return req.getApiKey();
|
||||
}
|
||||
|
||||
public String getCanvasPath()
|
||||
{
|
||||
return req.getCanvasPath();
|
||||
}
|
||||
|
||||
public String getCanvasURL()
|
||||
{
|
||||
return "http://apps.facebook.com/" + getCanvasPath();
|
||||
}
|
||||
|
||||
public String getPageURL()
|
||||
{
|
||||
return "http://apps.facebook.com" + req.getPathInfo();
|
||||
}
|
||||
|
||||
public String getSecret()
|
||||
{
|
||||
return req.getSecretKey();
|
||||
}
|
||||
|
||||
public boolean postUserAction(String title, String body)
|
||||
{
|
||||
try
|
||||
{
|
||||
Document result = getClient().feed_publishActionOfUser(title, body);
|
||||
// TODO: check result
|
||||
return true;
|
||||
}
|
||||
catch (FacebookException e)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Failed to post user action [title=" + title + ", body=" + body + "] due to " + e.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Failed to post user action [title=" + title + ", body=" + body + "] due to " + e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user