Author: [email protected]
Date: Tue Feb 21 08:24:26 2012
New Revision: 2104

Log:
[AMDATUOPENSOCIAL-201] Fixed by adding check on default dashboard in GET to 
/gadgets

Modified:
   
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java

Modified: 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
 (original)
+++ 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
 Tue Feb 21 08:24:26 2012
@@ -67,7 +67,7 @@
 public class DashboardRESTServiceImpl extends BaseRESTServiceImpl implements 
ResourceProvider {
     // The name of the property in AppData used to store personal dashboards 
for a particular user.
     private static final String DASHBOARDS = "dashboards";
-    
+
     // The id of the default dashboard. The default dashboard is returned
     private static final String DEFAULT_DBID = "default";
 
@@ -216,7 +216,7 @@
 
                 return get200(dashboard);
             }
-            
+
             if (isAuthorized(request)) {
                 // Persist the dashboard as complete JSON expression
                 User user = getUserFromViewer(request);
@@ -288,7 +288,7 @@
                         findGadget(dashboard, 
oldGadget.getId()).setUserPrefs(oldGadget.getUserPrefs());
                     }
                 }
-                
+
                 // Remove the dashboards with the specified id, if it exists. 
Then add it.
                 dashboards.removeDashboard(dashboardid);
                 dashboard.setId(dashboardid);
@@ -330,27 +330,35 @@
         @PathParam("gadgetid") final String gadgetid,
         @QueryParam("expand") final String expand, @Context final 
HttpServletRequest request) {
         try {
-            if (isAuthorized(request)) {
+            if (!DEFAULT_DBID.equals(dashboardid) && !isAuthorized(request)) {
+                return get401("Error 401 - Unauthorized. Only authenticated 
users can retrieve gadgets.");
+            }
+            Dashboard dashboard = null;
+            if (DEFAULT_DBID.equals(dashboardid)) {
+                // Special case: the default dashboard is requested
+                dashboard = getDefaultDashboard(request);
+            }
+            else {
                 User user = getUserFromViewer(request);
                 Dashboards dashboards = load(user);
-                Dashboard dashboard = findDashboard(dashboards, dashboardid);
-                if (dashboard != null) {
-                    // Find the gadget
-                    Gadget gadget = findGadget(dashboard, gadgetid);
-
-                    // Expand gadget specs if requested
-                    if ("true".equals(expand)) {
-                        expandGadgetSpec(gadget, request);
-                    }
+                dashboard = findDashboard(dashboards, dashboardid);
+            }
+            if (dashboard != null) {
+                // Find the gadget
+                Gadget gadget = findGadget(dashboard, gadgetid);
 
-                    return get200(gadget);
-                }
-                else {
-                    return get404("No gadget exists with id '" + gadgetid + "' 
on dashboard with id '" + dashboardid
-                        + "'");
+                // Expand gadget specs if requested
+                if ("true".equals(expand)) {
+                    expandGadgetSpec(gadget, request);
                 }
+
+                return get200(gadget);
+            }
+            else {
+                return get404("No gadget exists with id '" + gadgetid + "' on 
dashboard with id '"
+                    + dashboardid
+                    + "'");
             }
-            return get401("Error 401 - Unauthorized. Only authenticated users 
can retrieve gadgets.");
         }
         catch (Exception e) {
             return get500(e, "Error 500 - An error has occurred while 
retrieving gadget with id '" + gadgetid + "'");
@@ -447,7 +455,8 @@
                 Dashboard dashboard;
                 if (defaultDb) {
                     dashboard = getDefaultDashboard(request);
-                } else {
+                }
+                else {
                     User user = getUserFromViewer(request);
                     dashboard = findDashboard(load(user), dashboardid);
                 }
@@ -466,307 +475,307 @@
                                 UserPrefsBean upb = new UserPrefsBean();
                                 upb.setUserprefs(userPrefs);
                                 return get200(upb);
-                                }
                             }
-                            return get204("No UserPrefs saved yet for this 
user");
-                        }
-                        else {
-                            return get404("No gadget exists with id '" + 
gadgetid + "'");
                         }
+                        return get204("No UserPrefs saved yet for this user");
                     }
                     else {
-                        return get404("No dashboard exists with id '" + 
dashboardid + "'");
+                        return get404("No gadget exists with id '" + gadgetid 
+ "'");
                     }
                 }
-
-                return get401("Error 401 - Unauthorized. Only authenticated 
users can retrieve UserPrefs for a gadget.");
-            }
-            catch (Exception e) {
-                return get500(e, "Error 500 - An error has occurred while 
retrieving userPrefs for dashboard '"
-                                + dashboardid + "', gadget '" + gadgetid + 
"'");
+                else {
+                    return get404("No dashboard exists with id '" + 
dashboardid + "'");
+                }
             }
+
+            return get401("Error 401 - Unauthorized. Only authenticated users 
can retrieve UserPrefs for a gadget.");
         }
+        catch (Exception e) {
+            return get500(e, "Error 500 - An error has occurred while 
retrieving userPrefs for dashboard '"
+                + dashboardid + "', gadget '" + gadgetid + "'");
+        }
+    }
 
-        /**
-         * Returns the user preferences of a single gadget on a specific 
dashboard. If the user
-         * that invoked the request is authenticated (determined from the 
session cookie), the default values
-         * of the user preferences from the gadgetSpec of this gadget will be 
overruled by the users personal settings.
-         * If the user is not authenticated
-         * 
-         * @see org.amdatu.opensocial.gadgetmanagement.UserPrefsBean
-         * @param dashboardid The id of the dashboard to retrieve the widget 
from
-         * @param gadgetid The id of the widget to retrieve the user 
preferences for
-         * @param request The http request
-         * @return <ul>
-         *         <li>200 (OK) : The user preferences were saved 
successfully.</li>
-         *         <li>401 (UNAUTHORIZED) : returned in case the user is not 
authenticated.</li>
-         *         <li>404 (NOT FOUND) : The user preferences could not be 
retrieved since either the widgetid
-         *         does not refer to an existing widget, or the gadgetspec 
could not be retrieved from the
-         *         specified uri </li>
-         *         <li>500 (INTERNAL SERVER ERROR) : returned in case an 
unexpected internal error occurred.</li>
-         *         </ul>
-         */
-        @PUT
-        @Path("{dashboardid}/gadgets/{gadgetid}/userprefs")
-        @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-        @Produces({ MediaType.TEXT_PLAIN })
-        public Response setUserPrefs(@PathParam("dashboardid") final String 
dashboardid,
-            @PathParam("gadgetid") final String gadgetid, UserPrefsBean 
userPrefs, @Context final HttpServletRequest request) {
-            try {
-                if (DEFAULT_DBID.equals(dashboardid)) {
-                    return get401("Error 401 - Unauthorized. The default 
dashboard cannot be updated.");
-                }
-                if (isAuthorized(request)) {
-                    // Persist the dashboard as complete JSON expression
-                    User user = getUserFromViewer(request);
-                    Dashboards dashboards = load(user);
-                    Dashboard dashboard = findDashboard(dashboards, 
dashboardid);
-                    if (dashboard != null) {
-                        // Find the gadget
-                        Gadget gadget = null;
-                        for (Gadget g : dashboard.getGadgets()) {
-                            if (g.getId().equals(gadgetid)) {
-                                gadget = g;
-                            }
-                        }
-                        if (gadget != null) {
-                            gadget.setUserPrefs(userPrefs);
-                            save(user, dashboards);
-                            return get200("Dashboard '" + dashboardid + "' for 
user '" + user.getName()
-                                + "' saved successfully.");
-                        }
-                        else {
-                            return get404("No gadget exists with id '" + 
gadgetid + "'");
+    /**
+     * Returns the user preferences of a single gadget on a specific 
dashboard. If the user
+     * that invoked the request is authenticated (determined from the session 
cookie), the default values
+     * of the user preferences from the gadgetSpec of this gadget will be 
overruled by the users personal settings.
+     * If the user is not authenticated
+     * 
+     * @see org.amdatu.opensocial.gadgetmanagement.UserPrefsBean
+     * @param dashboardid The id of the dashboard to retrieve the widget from
+     * @param gadgetid The id of the widget to retrieve the user preferences 
for
+     * @param request The http request
+     * @return <ul>
+     *         <li>200 (OK) : The user preferences were saved 
successfully.</li>
+     *         <li>401 (UNAUTHORIZED) : returned in case the user is not 
authenticated.</li>
+     *         <li>404 (NOT FOUND) : The user preferences could not be 
retrieved since either the widgetid
+     *         does not refer to an existing widget, or the gadgetspec could 
not be retrieved from the
+     *         specified uri </li>
+     *         <li>500 (INTERNAL SERVER ERROR) : returned in case an 
unexpected internal error occurred.</li>
+     *         </ul>
+     */
+    @PUT
+    @Path("{dashboardid}/gadgets/{gadgetid}/userprefs")
+    @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.TEXT_PLAIN })
+    public Response setUserPrefs(@PathParam("dashboardid") final String 
dashboardid,
+        @PathParam("gadgetid") final String gadgetid, UserPrefsBean userPrefs, 
@Context final HttpServletRequest request) {
+        try {
+            if (DEFAULT_DBID.equals(dashboardid)) {
+                return get401("Error 401 - Unauthorized. The default dashboard 
cannot be updated.");
+            }
+            if (isAuthorized(request)) {
+                // Persist the dashboard as complete JSON expression
+                User user = getUserFromViewer(request);
+                Dashboards dashboards = load(user);
+                Dashboard dashboard = findDashboard(dashboards, dashboardid);
+                if (dashboard != null) {
+                    // Find the gadget
+                    Gadget gadget = null;
+                    for (Gadget g : dashboard.getGadgets()) {
+                        if (g.getId().equals(gadgetid)) {
+                            gadget = g;
                         }
                     }
+                    if (gadget != null) {
+                        gadget.setUserPrefs(userPrefs);
+                        save(user, dashboards);
+                        return get200("Dashboard '" + dashboardid + "' for 
user '" + user.getName()
+                            + "' saved successfully.");
+                    }
                     else {
-                        return get404("No dashboard exists with id '" + 
dashboardid + "'");
+                        return get404("No gadget exists with id '" + gadgetid 
+ "'");
                     }
                 }
-                return get401("Error 401 - Unauthorized. Only authenticated 
users can save user preferences.");
-            }
-            catch (Exception e) {
-                return get500(e, "Error 500 - An error has occurred while 
saving userPrefs for dashboard '" + dashboardid
-                    + "', gadget '" + gadgetid + "'");
+                else {
+                    return get404("No dashboard exists with id '" + 
dashboardid + "'");
+                }
             }
+            return get401("Error 401 - Unauthorized. Only authenticated users 
can save user preferences.");
         }
-
-        private String generateId(Dashboards dashboards) {
-            int id = dashboards.getDashboards() != null ? 
dashboards.getDashboards().size() + 1 : 1;
-            while (findDashboard(dashboards, new Integer(id).toString()) != 
null) {
-                id++;
-            }
-            return new Integer(id).toString();
+        catch (Exception e) {
+            return get500(e, "Error 500 - An error has occurred while saving 
userPrefs for dashboard '" + dashboardid
+                + "', gadget '" + gadgetid + "'");
         }
+    }
 
-        private String generateId(Dashboard dashboard) {
-            List<Gadget> gadgets = dashboard.getGadgets();
-            int id = gadgets != null ? gadgets.size() + 1 : 1;
-            while (findGadget(dashboard, new Integer(id).toString()) != null) {
-                id++;
-            }
-            return new Integer(id).toString();
+    private String generateId(Dashboards dashboards) {
+        int id = dashboards.getDashboards() != null ? 
dashboards.getDashboards().size() + 1 : 1;
+        while (findDashboard(dashboards, new Integer(id).toString()) != null) {
+            id++;
         }
+        return new Integer(id).toString();
+    }
 
-        // Load the dashboards for the specified user
-        private Dashboards load(User user) throws ClassNotFoundException, 
IOException {
-            Object appData = user.getProperties().get(APP_DATA);
-            if (appData != null) {
-                Map<String, Object> appDataValue = (Map<String, Object>) 
ConversionUtil.byteArrayToObject((byte[]) appData);
-                if (appDataValue.get(DASHBOARDS) != null) {
-                    String json = appDataValue.get(DASHBOARDS).toString();
-                    return GSON.fromJson(json, Dashboards.class);
-                }
-            }
-            return new Dashboards();
+    private String generateId(Dashboard dashboard) {
+        List<Gadget> gadgets = dashboard.getGadgets();
+        int id = gadgets != null ? gadgets.size() + 1 : 1;
+        while (findGadget(dashboard, new Integer(id).toString()) != null) {
+            id++;
         }
+        return new Integer(id).toString();
+    }
 
-        // Save the dashboards for the specified user
-        private void save(User user, Dashboards dashboards) throws 
IOException, ClassNotFoundException {
-            Object appData = user.getProperties().get(APP_DATA);
-            Map<String, Object> appDataValue;
-            if (appData != null) {
-                appDataValue = (Map<String, Object>) 
ConversionUtil.byteArrayToObject((byte[]) appData);
-            }
-            else {
-                appDataValue = new HashMap<String, Object>();
+// Load the dashboards for the specified user
+    private Dashboards load(User user) throws ClassNotFoundException, 
IOException {
+        Object appData = user.getProperties().get(APP_DATA);
+        if (appData != null) {
+            Map<String, Object> appDataValue = (Map<String, Object>) 
ConversionUtil.byteArrayToObject((byte[]) appData);
+            if (appDataValue.get(DASHBOARDS) != null) {
+                String json = appDataValue.get(DASHBOARDS).toString();
+                return GSON.fromJson(json, Dashboards.class);
             }
-
-            // Convert to JSON and write it to APP_DATA
-            String json = GSON.toJson(dashboards);
-            appDataValue.put(DASHBOARDS, json);
-            user.getProperties().put(APP_DATA, 
ConversionUtil.objectToByteArray(appDataValue));
         }
+        return new Dashboards();
+    }
 
-        private Dashboard findDashboard(Dashboards dashboards, String 
dashboardId) {
-            if (dashboards.getDashboards() != null) {
-                for (Dashboard dashboard : dashboards.getDashboards()) {
-                    if (dashboard.getId().equals(dashboardId)) {
-                        return dashboard;
-                    }
-                }
-            }
-            return null;
+// Save the dashboards for the specified user
+    private void save(User user, Dashboards dashboards) throws IOException, 
ClassNotFoundException {
+        Object appData = user.getProperties().get(APP_DATA);
+        Map<String, Object> appDataValue;
+        if (appData != null) {
+            appDataValue = (Map<String, Object>) 
ConversionUtil.byteArrayToObject((byte[]) appData);
+        }
+        else {
+            appDataValue = new HashMap<String, Object>();
         }
 
-        private Gadget findGadget(Dashboard dashboard, String gadgetId) {
-            List<Gadget> gadgets = dashboard.getGadgets();
-            if (gadgets != null) {
-                for (Gadget gadget : gadgets) {
-                    if (gadget.getId().equals(gadgetId)) {
-                        return gadget;
-                    }
+        // Convert to JSON and write it to APP_DATA
+        String json = GSON.toJson(dashboards);
+        appDataValue.put(DASHBOARDS, json);
+        user.getProperties().put(APP_DATA, 
ConversionUtil.objectToByteArray(appDataValue));
+    }
+
+    private Dashboard findDashboard(Dashboards dashboards, String dashboardId) 
{
+        if (dashboards.getDashboards() != null) {
+            for (Dashboard dashboard : dashboards.getDashboards()) {
+                if (dashboard.getId().equals(dashboardId)) {
+                    return dashboard;
                 }
             }
-            return null;
         }
+        return null;
+    }
 
-        private Dashboard getDefaultDashboard(final HttpServletRequest 
request) throws Exception {
-            Dashboard dashboard = new Dashboard();
-            Layout layout = new Layout();
-            layout.setId("layout3");
-            dashboard.setId(DEFAULT_DBID);
-            dashboard.setLayout(layout);
-            List<Gadget> gadgets = getDefaultGadgets(request);
+    private Gadget findGadget(Dashboard dashboard, String gadgetId) {
+        List<Gadget> gadgets = dashboard.getGadgets();
+        if (gadgets != null) {
             for (Gadget gadget : gadgets) {
-                gadget.getState().setWindowstate("open");
+                if (gadget.getId().equals(gadgetId)) {
+                    return gadget;
+                }
             }
-            dashboard.setGadgets(gadgets);
-            return dashboard;
         }
+        return null;
+    }
 
-        private List<Gadget> getDefaultGadgets(final HttpServletRequest 
request) throws Exception {
-            // No widgets are associated with this user, by default we assign 
the default gadgets (duh)
-            GadgetDefinition[] defaultGadgets = 
getGadgetManagement().getDefaultGadgets();
-
-            List<Gadget> gadgets = new ArrayList<Gadget>();
-            for (int i = 0; i < defaultGadgets.length; i++) {
-                Gadget gadget = new Gadget();
-                gadget.setId(Integer.toString(i + 1));
+    private Dashboard getDefaultDashboard(final HttpServletRequest request) 
throws Exception {
+        Dashboard dashboard = new Dashboard();
+        Layout layout = new Layout();
+        layout.setId("layout3");
+        dashboard.setId(DEFAULT_DBID);
+        dashboard.setLayout(layout);
+        List<Gadget> gadgets = getDefaultGadgets(request);
+        for (Gadget gadget : gadgets) {
+            gadget.getState().setWindowstate("open");
+        }
+        dashboard.setGadgets(gadgets);
+        return dashboard;
+    }
 
-                // Set the state
-                State state = new State();
-                state.setPosition("first");
-                gadget.setState(state);
+    private List<Gadget> getDefaultGadgets(final HttpServletRequest request) 
throws Exception {
+        // No widgets are associated with this user, by default we assign the 
default gadgets (duh)
+        GadgetDefinition[] defaultGadgets = 
getGadgetManagement().getDefaultGadgets();
+
+        List<Gadget> gadgets = new ArrayList<Gadget>();
+        for (int i = 0; i < defaultGadgets.length; i++) {
+            Gadget gadget = new Gadget();
+            gadget.setId(Integer.toString(i + 1));
+
+            // Set the state
+            State state = new State();
+            state.setPosition("first");
+            gadget.setState(state);
 
-                // Retrieve the gadgetspec to get the title of the gadget
-                String gadgetUrl = defaultGadgets[i].getUrl();
-                if (!gadgetUrl.startsWith("http://";) && 
!gadgetUrl.startsWith("https://";)) {
-                    // This is a relative URL
-                    gadgetUrl = toAbsoluteUrl(gadgetUrl, request);
-                }
+            // Retrieve the gadgetspec to get the title of the gadget
+            String gadgetUrl = defaultGadgets[i].getUrl();
+            if (!gadgetUrl.startsWith("http://";) && 
!gadgetUrl.startsWith("https://";)) {
+                // This is a relative URL
+                gadgetUrl = toAbsoluteUrl(gadgetUrl, request);
+            }
 
-                // Set the spec
-                Spec spec = new Spec();
-                spec.setUrl(gadgetUrl);
-                gadget.setSpec(spec);
+            // Set the spec
+            Spec spec = new Spec();
+            spec.setUrl(gadgetUrl);
+            gadget.setSpec(spec);
 
-                // Generate a security token and retrieve the title and height 
from the spec
-                updateSecureToken(gadget, request);
+            // Generate a security token and retrieve the title and height 
from the spec
+            updateSecureToken(gadget, request);
 
-                gadgets.add(gadget);
-            }
-            return gadgets;
+            gadgets.add(gadget);
         }
+        return gadgets;
+    }
 
-        private String generateSecurityToken(final String gagdgetUrl, final 
HttpServletRequest request) {
-            if (gagdgetUrl == null || gagdgetUrl.isEmpty()) {
-                return "";
-            }
+    private String generateSecurityToken(final String gagdgetUrl, final 
HttpServletRequest request) {
+        if (gagdgetUrl == null || gagdgetUrl.isEmpty()) {
+            return "";
+        }
 
-            // Retrieve the gadgetspec to get the title of the gadget
-            String url = gagdgetUrl;
-            if (!url.startsWith("http://";) && !url.startsWith("https://";)) {
-                // This is a relative URL
-                url = toAbsoluteUrl(gagdgetUrl, request);
+        // Retrieve the gadgetspec to get the title of the gadget
+        String url = gagdgetUrl;
+        if (!url.startsWith("http://";) && !url.startsWith("https://";)) {
+            // This is a relative URL
+            url = toAbsoluteUrl(gagdgetUrl, request);
 
-            }
-            return getOpenSocialContainer().getSecurityToken(url, request);
         }
+        return getOpenSocialContainer().getSecurityToken(url, request);
+    }
 
-        private void addDashboardLinks(Dashboard dashboard, HttpServletRequest 
request) {
-            String baseUrl =
-                            request.getServerName() + ":" + 
request.getServerPort() + "/rest/dashboards/" + dashboard.getId();
-            dashboard.addLink(baseUrl + "?alt=json", "alternate", 
MediaType.APPLICATION_JSON);
-            dashboard.addLink(baseUrl + "?alt=xml", "alternate", 
MediaType.APPLICATION_XML);
-        }
+    private void addDashboardLinks(Dashboard dashboard, HttpServletRequest 
request) {
+        String baseUrl =
+            request.getServerName() + ":" + request.getServerPort() + 
"/rest/dashboards/" + dashboard.getId();
+        dashboard.addLink(baseUrl + "?alt=json", "alternate", 
MediaType.APPLICATION_JSON);
+        dashboard.addLink(baseUrl + "?alt=xml", "alternate", 
MediaType.APPLICATION_XML);
+    }
 
-        private void createGadgetLinks(Dashboard dashboard, Gadget gadget, 
HttpServletRequest request) {
-            String baseUrl = request.getServerName() + ":" + 
request.getServerPort() + "/rest/dashboards/"
-                            + dashboard.getId() + "/gadgets/" + gadget.getId();
-            gadget.addLink(baseUrl + "?alt=json", "alternate", 
MediaType.APPLICATION_JSON);
-            gadget.addLink(baseUrl + "?alt=xml", "alternate", 
MediaType.APPLICATION_XML);
-        }
+    private void createGadgetLinks(Dashboard dashboard, Gadget gadget, 
HttpServletRequest request) {
+        String baseUrl = request.getServerName() + ":" + 
request.getServerPort() + "/rest/dashboards/"
+            + dashboard.getId() + "/gadgets/" + gadget.getId();
+        gadget.addLink(baseUrl + "?alt=json", "alternate", 
MediaType.APPLICATION_JSON);
+        gadget.addLink(baseUrl + "?alt=xml", "alternate", 
MediaType.APPLICATION_XML);
+    }
 
-        // Generate new security tokens for the gadgets stored in each 
dashboard.
-        // Security tokens are stored in APP_DATA but are typically short lived
-        // and so they probably expired when the user logs in. Security tokens
-        // should be re-generated each time the user opens the dashboard.
-        private void updateSecureTokens(Dashboards dashboards, 
HttpServletRequest request) throws Exception {
-            if (dashboards.getDashboards() != null) {
-                for (Dashboard dashboard : dashboards.getDashboards()) {
-                    if (dashboard.getGadgets() != null) {
-                        for (Gadget gadget : dashboard.getGadgets()) {
-                            // Generate a security token and retrieve the 
title and height from the spec
-                            updateSecureToken(gadget, request);
-                        }
+// Generate new security tokens for the gadgets stored in each dashboard.
+// Security tokens are stored in APP_DATA but are typically short lived
+// and so they probably expired when the user logs in. Security tokens
+// should be re-generated each time the user opens the dashboard.
+    private void updateSecureTokens(Dashboards dashboards, HttpServletRequest 
request) throws Exception {
+        if (dashboards.getDashboards() != null) {
+            for (Dashboard dashboard : dashboards.getDashboards()) {
+                if (dashboard.getGadgets() != null) {
+                    for (Gadget gadget : dashboard.getGadgets()) {
+                        // Generate a security token and retrieve the title 
and height from the spec
+                        updateSecureToken(gadget, request);
                     }
                 }
             }
         }
+    }
 
-        // Generate a new secure token and sets it in the gadget state
-        private void updateSecureToken(Gadget gadget, HttpServletRequest 
request) throws Exception {
-            if (gadget.getSpec() != null) {
-                String st = generateSecurityToken(gadget.getSpec().getUrl(), 
request);
-                gadget.getState().setSecureToken(st);
-            }
+// Generate a new secure token and sets it in the gadget state
+    private void updateSecureToken(Gadget gadget, HttpServletRequest request) 
throws Exception {
+        if (gadget.getSpec() != null) {
+            String st = generateSecurityToken(gadget.getSpec().getUrl(), 
request);
+            gadget.getState().setSecureToken(st);
         }
+    }
 
-        // Expands the properties (title, height and UserPrefs) of all gadgets 
on the dashboard
-        private void expandGadgetSpecs(Dashboards dashboards, 
HttpServletRequest request) {
-            for (Dashboard dashboard : dashboards.getDashboards()) {
-                expandGadgetSpecs(dashboard, request);
-            }
+// Expands the properties (title, height and UserPrefs) of all gadgets on the 
dashboard
+    private void expandGadgetSpecs(Dashboards dashboards, HttpServletRequest 
request) {
+        for (Dashboard dashboard : dashboards.getDashboards()) {
+            expandGadgetSpecs(dashboard, request);
         }
+    }
 
-        // Expands the properties (title, height and UserPrefs) of all gadgets 
on the dashboard
-        private void expandGadgetSpecs(Dashboard dashboard, HttpServletRequest 
request) {
-            for (Gadget gadget : dashboard.getGadgets()) {
-                expandGadgetSpec(gadget, request);
-            }
+// Expands the properties (title, height and UserPrefs) of all gadgets on the 
dashboard
+    private void expandGadgetSpecs(Dashboard dashboard, HttpServletRequest 
request) {
+        for (Gadget gadget : dashboard.getGadgets()) {
+            expandGadgetSpec(gadget, request);
         }
+    }
 
-        // Expands the properties (title, height and UserPrefs) of the gadget 
spec from the gadget spec url
-        private void expandGadgetSpec(Gadget gadget, HttpServletRequest 
request) {
-            Spec spec = gadget.getSpec();
-            String url = spec.getUrl();
-            Map<String, String> gadgetSpec = 
getOpenSocialContainer().getGadgetSpec(request, url, null);
-            if (gadgetSpec != null) {
-                spec.setHeight(getGadgetSpecValue(gadgetSpec, "height", ""));
-                spec.setTitle(getGadgetSpecValue(gadgetSpec, "title", ""));
-                UserPrefsBean userPrefs = 
getOpenSocialContainer().getUserPreferences(url, null);
-                gadget.getSpec().setUserprefs(userPrefs.getUserprefs());
-            }
+// Expands the properties (title, height and UserPrefs) of the gadget spec 
from the gadget spec url
+    private void expandGadgetSpec(Gadget gadget, HttpServletRequest request) {
+        Spec spec = gadget.getSpec();
+        String url = spec.getUrl();
+        Map<String, String> gadgetSpec = 
getOpenSocialContainer().getGadgetSpec(request, url, null);
+        if (gadgetSpec != null) {
+            spec.setHeight(getGadgetSpecValue(gadgetSpec, "height", ""));
+            spec.setTitle(getGadgetSpecValue(gadgetSpec, "title", ""));
+            UserPrefsBean userPrefs = 
getOpenSocialContainer().getUserPreferences(url, null);
+            gadget.getSpec().setUserprefs(userPrefs.getUserprefs());
         }
+    }
 
-        // FIXE; currently only /doc/api/dashboards/ works properly, without 
the last '.' the CSS is missing
-        public URL getResource(String name) {
-            if (name.startsWith(Activator.DASHBOARDS_DOC_ALIAS)) {
-                String resource = 
name.substring(Activator.DASHBOARDS_DOC_ALIAS.length());
-                if (resource.startsWith("/")) {
-                    resource = resource.substring(1);
-                }
-                String resName = "static/help/";
-                if (resource.isEmpty()) {
-                    resName += this.getClass().getName() + "-api.html";
-                }
-                else {
-                    resName += resource;
-                }
-                return m_bundleContext.getBundle().getResource(resName);
+// FIXE; currently only /doc/api/dashboards/ works properly, without the last 
'.' the CSS is missing
+    public URL getResource(String name) {
+        if (name.startsWith(Activator.DASHBOARDS_DOC_ALIAS)) {
+            String resource = 
name.substring(Activator.DASHBOARDS_DOC_ALIAS.length());
+            if (resource.startsWith("/")) {
+                resource = resource.substring(1);
+            }
+            String resName = "static/help/";
+            if (resource.isEmpty()) {
+                resName += this.getClass().getName() + "-api.html";
             }
-
-            return null;
+            else {
+                resName += resource;
+            }
+            return m_bundleContext.getBundle().getResource(resName);
         }
+
+        return null;
     }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to