Author: tyrell
Date: Wed Jun  4 09:03:14 2008
New Revision: 17934
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17934

Log:
Adding gadget URL generation.

Modified:
   trunk/mashup/java/modules/dashboard/directory.jsp

Modified: trunk/mashup/java/modules/dashboard/directory.jsp
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/dashboard/directory.jsp?rev=17934&r1=17933&r2=17934&view=diff
==============================================================================
--- trunk/mashup/java/modules/dashboard/directory.jsp   (original)
+++ trunk/mashup/java/modules/dashboard/directory.jsp   Wed Jun  4 09:03:14 2008
@@ -2,6 +2,7 @@
 <%@ page import="org.wso2.mashup.utils.QueryResults" %>
 <%@ page import="java.util.Iterator" %>
 <%@ page import="org.wso2.mashup.utils.QueryResult" %>
+<%@ page import="java.net.URL" %>
 <%--
  * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
  *
@@ -25,6 +26,24 @@
 <!--Required to keep a user logged in if 'Remember Me' option is selected-->
 <%@ include file="login_validator.jsp" %>
 
+<%
+    String currentUser = userRegistry.getUserName();
+
+    // Creating an HTTP version of the current URL to be used when required
+    String httpUrl =
+            new URL("http", request.getServerName(), 
ServerManager.getInstance().getHttpPort(), "")
+                    .toString();
+
+    // Generating the server URL
+    ConfigurationContext axis2ConfigContext = 
ServerManager.getInstance().configContext;
+    String contextRoot = axis2ConfigContext.getContextRoot();
+    if (!contextRoot.endsWith(MashupConstants.FORWARD_SLASH)) {
+        contextRoot = contextRoot + MashupConstants.FORWARD_SLASH;
+    }
+    String mashupServerURL = contextRoot + axis2ConfigContext.getServicePath() 
+
+            MashupConstants.FORWARD_SLASH;
+%>
+
 <!DOCTYPE html>
 <html>
 <head>
@@ -32,12 +51,13 @@
     <link rel="stylesheet" href="css/gadgets.css">
 
     <script type="text/javascript" language="JavaScript">
-        function addGadget() {
-            alert("in toggle add");
+        function addGadget(url) {
+            alert(url);
         }
     </script>
 </head>
 <body>
+<h2><%= bundle.getString("main.title")%> - Add Gadgets to the Dashboard 
[<%=currentUser%>]</h2>
 
 <div id="local-gadgets">
 
@@ -51,14 +71,22 @@
 
         while (iter.hasNext()) {
             QueryResult result = (QueryResult) iter.next();
+
+            // Extracting the mashup name from the registry path
+            String[] parts = 
result.getPath().split(RegistryConstants.PATH_SEPARATOR);
+            String mashup = parts[parts.length - 1];
+
+            String gadgetUrl = httpUrl + mashupServerURL + result.getAuthor() 
+ "/" + mashup +
+                    "?template&flavor=googlegadget";
     %>
     <div class="directory-entry">
         <div class="gadget">
             <%=result.getName()%>
-            <div><input type="button" onclick="addGadget();" value="Add it 
now"/></div>
+            <div><input type="button" onclick="addGadget('<%=gadgetUrl%>');" 
value="Add it now"/></div>
         </div>
         <div class="author">
-            <p>By <%=RegistryUtils.getFullName(request, 
result.getAuthor())%></p>            
+            <p>By <%=RegistryUtils.getFullName(request, 
result.getAuthor())%></p>
+            <p><a href="<%=gadgetUrl%>">View Source</a></p>
         </div>
         <div class="info">
             <%=result.getDescription()%>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to