Author: scottbw
Date: Tue Mar  9 22:14:39 2010
New Revision: 921164

URL: http://svn.apache.org/viewvc?rev=921164&view=rev
Log:
This is part 3 of 3 updates of the Shindig integration code that brings it up 
to date with the other changes to the Wookie core code; See WOOKIE-52 for more 
information on wookie-shindig integration.

Modified:
    incubator/wookie/trunk/src/opensocial.properties
    incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetUtils.java
    
incubator/wookie/trunk/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
    incubator/wookie/trunk/src/widgetserver.properties

Modified: incubator/wookie/trunk/src/opensocial.properties
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/opensocial.properties?rev=921164&r1=921163&r2=921164&view=diff
==============================================================================
--- incubator/wookie/trunk/src/opensocial.properties (original)
+++ incubator/wookie/trunk/src/opensocial.properties Tue Mar  9 22:14:39 2010
@@ -1,4 +1,4 @@
 opensocial.enable=true
-opensocial.token=secure
+opensocial.token=plain
 opensocial.key=UNSECURED_TOKEN_KEY
 opensocial.proxy.id=gadgetsdefaultkey
\ No newline at end of file

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetUtils.java?rev=921164&r1=921163&r2=921164&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetUtils.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetUtils.java 
Tue Mar  9 22:14:39 2010
@@ -27,7 +27,11 @@ import org.apache.commons.httpclient.Htt
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wookie.beans.Name;
+import org.apache.wookie.beans.Description;
+import org.apache.wookie.beans.StartFile;
 import org.apache.wookie.beans.Widget;
+import org.apache.wookie.beans.WidgetIcon;
 import org.json.JSONArray;
 import org.json.JSONObject;
 /**
@@ -72,6 +76,7 @@ public class GadgetUtils {
                        if (properties.getString("widget.metadata.url")!=null) 
svc = properties.getString("widget.metadata.url");
                        if (properties.getString("widget.shindig.url")!=null) 
shindig = properties.getString("widget.shindig.url");
                } catch (Exception e) {
+                       e.printStackTrace();
                        // Problem with the servlet context; we'll just let it 
go for now
                        // TODO log this error
                }
@@ -120,7 +125,7 @@ public class GadgetUtils {
                        post.setRequestHeader("Content-Length", 
String.valueOf(req.getContentLength()));
                        response = executeMethod(post);
                } catch (Exception e) {
-                       System.err.println(e.getMessage());
+                       e.printStackTrace();
                        throw new Exception("There was a problem connecting to 
the Shindig metadata service");
                }
                return response;
@@ -173,6 +178,7 @@ public class GadgetUtils {
                if (gadgets.length() > 0){
                        gadget = gadgets.getJSONObject(0);
                        if (gadget.has("errors")) throw new Exception("Invalid 
gadget - Shindig error");
+                       
                        widget = new Widget();
                        // Defaults
                        String title = "Untitled Gadget";
@@ -197,8 +203,11 @@ public class GadgetUtils {
                        // We should be able to use the "iframeUrl" property 
here, but
                        // it isn't very reliable at generating a usable value, 
so we construct
                        // a very basic URL instead
-                       
//widget.setUrl(shindig+"/gadgets/ifr?url="+gadget.getString("url")+"&lang=en&country=UK");
 //TODO FIXME Later
-
+                       StartFile sf = new StartFile();
+                       sf.setWidget(widget);
+                       // FIXME we need to use real locales in these URLs
+                       
sf.setUrl(shindig+"/gadgets/ifr?url="+gadget.getString("url")+"&lang=en&country=UK");
+                       
                        if (gadget.has("height")) if (gadget.getInt("height") 
!= 0) height = gadget.getInt("height");
                        if (gadget.has("width")) if (gadget.getInt("width") != 
0) width = gadget.getInt("width");
 
@@ -246,11 +255,23 @@ public class GadgetUtils {
                        widget.setMaximize(false);
                        widget.setHeight(height);
                        widget.setWidth(width);
-                       //widget.setWidgetTitle(title); // TODO FIXME 
-                       //widget.setWidgetDescription(description);     //TODO 
FIXME    
-                       //widget.setWidgetIconLocation(icon); //TODO FIXME
+                       Name name = new Name();
+                       name.setWidget(widget);
+                       name.setName(title);
+                       Description desc = new Description();
+                       desc.setWidget(widget);
+                       desc.setContent(description);
+                       WidgetIcon wicon = new WidgetIcon();
+                       wicon.setSrc(icon);
+                       wicon.setWidget(widget);
                        widget.setWidgetAuthor(author);
-
+                       
+                       widget.save();
+                       sf.save();
+                       name.save();
+                       wicon.save();
+                       desc.save();
+                       
                }
                return widget;
        }

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java?rev=921164&r1=921163&r2=921164&view=diff
==============================================================================
--- 
incubator/wookie/trunk/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 (original)
+++ 
incubator/wookie/trunk/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 Tue Mar  9 22:14:39 2010
@@ -21,7 +21,9 @@ import org.apache.log4j.Logger;
 import org.apache.shindig.auth.BlobCrypterSecurityToken;
 import org.apache.shindig.common.crypto.BasicBlobCrypter;
 import org.apache.wookie.Messages;
+import org.apache.wookie.beans.StartFile;
 import org.apache.wookie.beans.WidgetInstance;
+import org.apache.wookie.w3c.util.LocalizationUtils;
 
 /**
  * Utilities for supporting OpenSocial integration, such as creation of 
security tokens that
@@ -36,8 +38,6 @@ public class OpenSocialUtils {
        private static final String DOMAIN_ID = "wookie"; //$NON-NLS-1$
        // TODO once we have an API Key implementation, we can convey the 
actual container id rather than Wookie
        private static final String CONTAINER_ID = "wookie"; //$NON-NLS-1$
-       // TODO once we get plugins to send owner Id, we can remove this
-       private static final String OWNER_ID = "0"; //$NON-NLS-1$
        
        
        /**
@@ -65,15 +65,11 @@ public class OpenSocialUtils {
                        throw new 
Exception(localizedMessages.getString("OpenSocialUtils.1")); //$NON-NLS-1$
                }
 
-               // We really need to implement viewer/owner info
-               String userid = "@anon"; //$NON-NLS-1$
-               if (instance.getUserId()!=null) 
if(!instance.getUserId().equals("")) userid = instance.getUserId(); 
//$NON-NLS-1$
-               
                // Order of fields is:
                // owner, viewer, app_id, domain, app_url, mod_id, container
                // NOTE that we're hacking this now to push the id_key through 
the container value as Shindig won't let us use Strings for mod_id, only Longs
                // TODO replace hack with a real solution
-               String[] fields = {OWNER_ID, userid, 
instance.getWidget().getGuid(), DOMAIN_ID, instance.getWidget().getUrl(), "0", 
String.valueOf(instance.getIdKey())}; //$NON-NLS-1$
+               String[] fields = {getOwnerId(instance), getUserId(instance), 
instance.getWidget().getGuid(), DOMAIN_ID, getUrl(instance), "0", 
String.valueOf(instance.getIdKey())}; //$NON-NLS-1$
                for (int i = 0; i < fields.length; i++) {
                        // escape each field individually, for metachars in URL
                        fields[i] = URLEncoder.encode(fields[i], "UTF-8"); 
//$NON-NLS-1$
@@ -86,7 +82,7 @@ public class OpenSocialUtils {
        
        /**
         * Utility method for producing an encrypted token for OpenSocial 
applications
-        * TODO Fix this method, its broken
+        * TODO FIXME this method is broken, or at least a pain to test in real 
deployment
         * @param instance the widget instance to generate a token for
         * @return the encrypted token for the widget instance
         * @throws Exception
@@ -99,22 +95,39 @@ public class OpenSocialUtils {
                        throw new 
Exception(localizedMessages.getString("OpenSocialUtils.1")); //$NON-NLS-1$
                }
                
-               @SuppressWarnings("unused")
-               String userid = "@anon"; //$NON-NLS-1$
-               if (instance.getUserId()!=null) 
if(!instance.getUserId().equals("")) userid = instance.getUserId(); 
//$NON-NLS-1$
-               
                BasicBlobCrypter crypter = new BasicBlobCrypter(key.getBytes());
                BlobCrypterSecurityToken token = new 
BlobCrypterSecurityToken(crypter, CONTAINER_ID, DOMAIN_ID);
-               token.setAppUrl(instance.getWidget().getUrl());
+               token.setAppUrl(getUrl(instance));
                // The ModuleId only takes a long, so we just have to hash the 
idKey for now. We could use the instance id,
                // but this would involve updating the instance object in a 
two-step create, which is more fiddly and expensive.
-               token.setModuleId(0);
-               token.setOwnerId(OWNER_ID);
-               token.setViewerId(instance.getUserId());
-               String encryptedToken = null;
-               encryptedToken = token.encrypt();
+               token.setModuleId(instance.getIdKey().hashCode());
+               token.setOwnerId(getOwnerId(instance));
+               token.setViewerId(getUserId(instance));
+               // The URL used in the active request
+               token.setActiveUrl(getUrl(instance));
+               
+               String encryptedToken = token.encrypt();
+               
                encryptedToken = URLEncoder.encode(encryptedToken, "UTF-8"); 
//$NON-NLS-1$
+               
                return encryptedToken;
        }
+       
+       private static String getOwnerId(WidgetInstance instance){
+               //TODO FIXME
+               return getUserId(instance);
+       }
+       
+       private static String getUserId(WidgetInstance instance){
+               String userid = "@anon"; //$NON-NLS-1$
+               if (instance.getUserId()!=null) 
if(!instance.getUserId().equals("")) userid = instance.getUserId(); 
//$NON-NLS-1$
+               return userid;
+       }
+       
+       private static String getUrl(WidgetInstance instance){
+               StartFile[] files = StartFile.findByValue("widget", 
instance.getWidget());
+               StartFile start = (StartFile) 
LocalizationUtils.getLocalizedElement(files, new String[]{"en"});
+               return start.getUrl();
+       }
 
 }

Modified: incubator/wookie/trunk/src/widgetserver.properties
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/widgetserver.properties?rev=921164&r1=921163&r2=921164&view=diff
==============================================================================
--- incubator/wookie/trunk/src/widgetserver.properties (original)
+++ incubator/wookie/trunk/src/widgetserver.properties Tue Mar  9 22:14:39 2010
@@ -1,7 +1,7 @@
-widget.version=0.8
-widget.build.date=12 January 2009
[email protected]
-widget.web.page=http://incubator.apache.org/projects/wookie.html
+widget.version=0.8.1
+widget.build.date=
[email protected]
+widget.web.page=http://incubator.apache.org/wookie
 # Keep this true while developing, but set to false for a build
 widget.debug=true
 #######################################################################
@@ -20,8 +20,8 @@ widget.deployfolder=/deploy
 widget.hot_deploy=true
 #######################################################################
 # Location of Shindig services
-widget.shindig.url=/wookie
-widget.metadata.url=/wookie/gadgets/metadata
+widget.shindig.url=/
+widget.metadata.url=/gadgets/metadata
 #######################################################################
 widget.proxy.usewhitelist=true
 widget.proxy.checkdomain=false


Reply via email to