Author: chathura
Date: Mon Dec 17 21:48:45 2007
New Revision: 11315

Log:


Now we have AJAX taggings!



Added:
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/TagUtil.java
   trunk/registry/modules/webapps/src/main/webapp/admin/ajax/
Modified:
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
   trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   Mon Dec 17 21:48:45 2007
@@ -24,6 +24,7 @@
 import org.wso2.registry.servlet.FileUploadUtil;
 import org.wso2.registry.servlet.Utils;
 import org.wso2.registry.web.actions.*;
+import org.wso2.registry.web.utils.TagUtil;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -135,6 +136,17 @@
                 response.sendRedirect("/wso2registry/system/people");
                 //forwardToUserManagement(request, response);
 
+            } else if (command.equals("/applyTag")) {
+
+                try {
+                    TagUtil.applyTag(request);
+                    TagUtil.sendTagCloud(request, response);
+                    
+                } catch (RegistryException e) {
+                    setErrorMessage(request, e.getMessage());
+                    forwardToResources(request, response, path);
+                }
+
             } else if (command.equals("/tag")) {
 
                 AddTagAction addTagAction = new AddTagAction();
@@ -530,6 +542,17 @@
 
                 forwardToSearch(request, response);
 
+            } else if (command.equals("/getTagCloud")) {
+
+                try {
+                    TagUtil.sendTagCloud(request, response);
+                    return;
+                } catch (RegistryException e) {
+                    setErrorMessage(request, e.getMessage());
+                }
+
+                forwardToResources(request, response, path);
+
             } else if (command.equals("/getInitialRating")) {
 
                 AjaxRatingAction ajaxRatingAction = new AjaxRatingAction();

Added: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
    Mon Dec 17 21:48:45 2007
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.web.utils;
+
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.web.ConsoleConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+
+public class CommonUtil {
+
+    public static SecureRegistry getUserRegistry(HttpServletRequest request)
+            throws RegistryException {
+
+        SecureRegistry userRegistry =
+                (SecureRegistry) 
request.getSession().getAttribute(ConsoleConstants.USER_REGISTRY);
+
+        if (userRegistry == null) {
+
+            // user is not logged in. create a annoymous userRegistry for the 
user.
+
+            ServletContext context =
+                    request.getSession().getServletContext();
+
+            JDBCRegistry jdbcRegistry =
+                    (JDBCRegistry) 
context.getAttribute(RegistryConstants.REGISTRY);
+
+            RegistryRealm realm = (RegistryRealm) 
request.getSession().getServletContext().
+                    getAttribute(RegistryConstants.REGISTRY_REALM);
+
+            SecureRegistry secureRegistry = new SecureRegistry(
+                    RegistryConstants.ANONYMOUS_USER, "guest", jdbcRegistry, 
realm);
+
+            request.getSession().setAttribute(ConsoleConstants.USER_REGISTRY, 
secureRegistry);
+
+            userRegistry = secureRegistry;
+        }
+
+        return userRegistry;
+    }
+}

Added: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/TagUtil.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/TagUtil.java
       Mon Dec 17 21:48:45 2007
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.web.utils;
+
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Tag;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+public class TagUtil {
+
+    public static void applyTag(HttpServletRequest request) throws 
RegistryException {
+
+        SecureRegistry secureRegistry = CommonUtil.getUserRegistry(request);
+
+        String resourcePath = request.getParameter("resourcePath");
+        String tag = request.getParameter("tag");
+
+        secureRegistry.applyTag(resourcePath, tag);
+    }
+
+    public static void sendTagCloud(HttpServletRequest request, 
HttpServletResponse response)
+            throws RegistryException {
+
+        SecureRegistry secureRegistry = CommonUtil.getUserRegistry(request);
+        response.setContentType("text/html");
+        PrintWriter out = null;
+        try {
+            out = response.getWriter();
+        } catch (IOException e) {
+            throw new RegistryException(e.getMessage());
+        }
+
+        String resourcePath = request.getParameter("resourcePath");
+        Tag[] tags = secureRegistry.getTags(resourcePath);
+
+        for (int i = 0; i < tags.length; i++) {
+            Tag tag = tags[i];
+            out.println("<a href='/wso2registry/system/search?criteria=" + 
tag.getTagName() + " class='cloud-x" + tag.getCategary() + ">" + 
tag.getTagName() + "</a>");
+        }
+
+        out.flush();
+        out.close();
+    }
+}

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   Mon Dec 
17 21:48:45 2007
@@ -174,7 +174,7 @@
     var edit_button = document.getElementById('editButton');
 
     if (edit_button.value=='Save Description') {
-       tinyMCE.triggerSave();
+        tinyMCE.triggerSave();
         var desc = tinyMCE.getContent();
         tinyMCE.execCommand('mceRemoveControl', false, 'descEdit');
         new Ajax.Updater('descView', '/wso2registry/system/setDescription', { 
method: 'post', parameters: {description: desc} });
@@ -221,6 +221,24 @@
 
 }
 
+function applyTag(e) {
+
+    var keyCode;
+    if (window.event) {
+        keyCode = window.event.keyCode;
+    } else {
+        keyCode = e.which;
+    }
+
+    if (keyCode == 13) {
+
+        var resourcePath = document.getElementById('tfPath').value;
+        var tag = document.getElementById('tfTag').value;
+        new Ajax.Updater('cloude-text', '/wso2registry/system/applyTag', { 
method: 'post', parameters: {resourcePath: resourcePath, tag: tag} });
+        document.getElementById('tfTag').value = "";
+    }
+}
+
 // media type map to store file_extension -> media type pairs.
 // these media type data will be retrieved upon the first request and stored 
in memory.
 var mediaTypeMap = null;
@@ -333,13 +351,13 @@
     rForm.submit();
 }
 function doGreeting(){
-       datetoday = new Date();
-       timenow=datetoday.getTime();
-       datetoday.setTime(timenow);
-       thehour = datetoday.getHours();
-       if (thehour > 18) display = "evening";
-       else if (thehour >12) display = "afternoon";
-       else display = "morning";
-       var greeting = ("Good " + display);
-       document.write(greeting);
+    datetoday = new Date();
+    timenow=datetoday.getTime();
+    datetoday.setTime(timenow);
+    thehour = datetoday.getHours();
+    if (thehour > 18) display = "evening";
+    else if (thehour >12) display = "afternoon";
+    else display = "morning";
+    var greeting = ("Good " + display);
+    document.write(greeting);
 }

Modified: 
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
Mon Dec 17 21:48:45 2007
@@ -418,7 +418,7 @@
                                Expand to view details
                        </div>
                        <div class="box2-mid" id="tagExpanded">
-                       <div class="cloude-text">
+                       <div id="cloude-text" class="cloude-text">
                                <%
                                    Iterator iTags = 
details.getTags().iterator();
                                    while (iTags.hasNext()) {
@@ -428,11 +428,12 @@
                                <% } %>
                            </div>
                        
-                           <form action="/wso2registry/system/tag" 
method="post">
+                           <%--<form id="formTag" onsubmit="applyTag()">--%>
                                <table cellpadding="0" cellspacing="0" 
border="0" style="width:100%" class="form-table">
                                    <tr>
                                        <td>
-                                           <input type="text" name="tag" />
+                                <input id="tfPath" type="hidden" 
name="resourcePath" value="<%=details.getPath()%>"/>
+                                <input id="tfTag" type="text" name="tag" 
onkeypress="applyTag(event)"/>
                                        </td>
                                        
                                    </tr>
@@ -442,7 +443,7 @@
                                        </td>
                                    </tr>
                                </table>
-                           </form>
+                           <!--</form>-->
                        <!-- END add tag box -->
                        
                        </div>

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to