You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2014/02/09 21:45:30 UTC

svn commit: r1566404 - /wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java

Author: scottbw
Date: Sun Feb  9 20:45:30 2014
New Revision: 1566404

URL: http://svn.apache.org/r1566404
Log:
Changed WidgetInstancesHelper to, in effect, being a facade for returning AuthToken info. Eventually it will be renamed.

Modified:
    wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java

Modified: wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java?rev=1566404&r1=1566403&r2=1566404&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java (original)
+++ wookie/trunk/wookie-server/src/main/java/org/apache/wookie/helpers/WidgetInstanceHelper.java Sun Feb  9 20:45:30 2014
@@ -15,8 +15,10 @@ package org.apache.wookie.helpers;
 
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.log4j.Logger;
+import org.apache.wookie.auth.AuthToken;
+import org.apache.wookie.auth.AuthTokenUtils;
 import org.apache.wookie.beans.IWidget;
-import org.apache.wookie.beans.IWidgetInstance;
+import org.apache.wookie.services.WidgetMetadataService;
 import org.apache.wookie.w3c.IW3CXMLConfiguration;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -25,27 +27,26 @@ import org.json.JSONObject;
  * A helper to create representations of Widget Instance resources
  */
 public class WidgetInstanceHelper {
-	
-  static Logger logger = Logger.getLogger(WidgetInstanceHelper.class.getName());
-  
+
+	static Logger logger = Logger.getLogger(WidgetInstanceHelper.class.getName());
+
 	private static final String XMLDECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 
 	/**
-	 * Generate a Widget Instance representation doc in XML for a single instance of the given widget
-	 * @param instance the widget instance
-	 * @param url the URL of the widget instance
-	 * @param locale the locale of the widget instance
-	 * @return an XML representation of the Widget Instance as a String
+	 * Generate an XML representation for a session
+	 * @param authtoken the auth token for the sesson
+	 * @param url the URL of the widget 
+	 * @param locale the locale of the widget 
+	 * @return an XML representation of the session as a String
+	 * @throws Exception 
 	 */
-	public static String createXMLWidgetInstanceDocument(IWidgetInstance instance, String url, String locale, boolean useDefaultSizes){
+	public static String createXMLWidgetInstanceDocument(AuthToken authToken, String url, boolean useDefaultSizes) throws Exception{
 		String xml = XMLDECLARATION;
-		IWidget widget = instance.getWidget();
-		
+		IWidget widget = WidgetMetadataService.Factory.getInstance().getWidget(authToken.getWidgetId());
 
-		
 		String width = null;
 		String height = null;
-		
+
 		// Return a default width and height where the original value is either not provided
 		// or of an invalid range (<0)
 		if (useDefaultSizes){
@@ -54,43 +55,52 @@ public class WidgetInstanceHelper {
 		}
 		if (widget.getWidth()!=null && widget.getWidth()>0) width = widget.getWidth().toString();
 		if (widget.getHeight()!=null && widget.getHeight()>0) height = widget.getHeight().toString();
-				
+
 		xml += "<widgetdata>"; //$NON-NLS-1$
 		xml += "\t<url>"+url+"</url>"; //$NON-NLS-1$ //$NON-NLS-2$
-		xml += "\t<identifier>"+instance.getIdKey()+"</identifier>\n"; //$NON-NLS-1$ //$NON-NLS-2$
-		xml += "\t<title>"+StringEscapeUtils.escapeXml(widget.getLocalName(locale))+"</title>\n"; //$NON-NLS-1$ //$NON-NLS-2$
+		xml += "\t<identifier>"+AuthTokenUtils.encryptAuthToken(authToken)+"</identifier>\n"; //$NON-NLS-1$ //$NON-NLS-2$
+		xml += "\t<title>"+StringEscapeUtils.escapeXml(widget.getLocalName(authToken.getLang()))+"</title>\n"; //$NON-NLS-1$ //$NON-NLS-2$
 		if (height != null) xml += "\t<height>"+height+"</height>\n"; //$NON-NLS-1$ //$NON-NLS-2$
 		if (width != null) xml += "\t<width>"+width+"</width>\n"; //$NON-NLS-1$ //$NON-NLS-2$
 		xml += "</widgetdata>"; //$NON-NLS-1$
-		
+
 		return xml;
 	}
-	
-  public static String toJson(IWidgetInstance instance, String url, String locale, boolean useDefaultSizes) {
-    IWidget widget = instance.getWidget();
-    
-    String width = null;
-    String height = null;
-    
-    if (useDefaultSizes){
-    	width = String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
-    	height = String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
-    }
-    if (widget.getWidth() != null && widget.getWidth() > 0)
-      width = widget.getWidth().toString();
-    if (widget.getHeight() != null && widget.getHeight() > 0)
-      height = widget.getHeight().toString();
-    JSONObject json = new JSONObject();
-    try {
-      json.put("url", url);
-      json.put("identifier", instance.getIdKey());
-      json.put("title", widget.getLocalName(locale));
-      if (height != null) json.put("height", height);
-      if (width != null) json.put("width", width);
-    } catch (JSONException e) {
-      logger.error("Problem rendering instance using JSON",e);
-    }
-    return json.toString();
-  }
-	
+
+	/**
+	 * Create a JSON object for the session
+	 * @param authToken
+	 * @param url
+	 * @param locale
+	 * @param useDefaultSizes
+	 * @return
+	 * @throws Exception
+	 */
+	public static String toJson(AuthToken authToken, String url, boolean useDefaultSizes) throws Exception {
+		IWidget widget = WidgetMetadataService.Factory.getInstance().getWidget(authToken.getWidgetId());
+
+		String width = null;
+		String height = null;
+
+		if (useDefaultSizes){
+			width = String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
+			height = String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+		}
+		if (widget.getWidth() != null && widget.getWidth() > 0)
+			width = widget.getWidth().toString();
+		if (widget.getHeight() != null && widget.getHeight() > 0)
+			height = widget.getHeight().toString();
+		JSONObject json = new JSONObject();
+		try {
+			json.put("url", url);
+			json.put("identifier", AuthTokenUtils.encryptAuthToken(authToken));
+			json.put("title", widget.getLocalName(authToken.getLang()));
+			if (height != null) json.put("height", height);
+			if (width != null) json.put("width", width);
+		} catch (JSONException e) {
+			logger.error("Problem rendering instance using JSON",e);
+		}
+		return json.toString();
+	}
+
 }