roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r470112 - in /incubator/roller/trunk: src/org/apache/roller/util/URLUtilities.java src/org/apache/roller/webservices/json/TagStatsServlet.java web/WEB-INF/jsps/authoring/WeblogEdit.jsp
Date Wed, 01 Nov 2006 21:52:21 GMT
Author: agilliland
Date: Wed Nov  1 13:52:20 2006
New Revision: 470112

URL: http://svn.apache.org/viewvc?view=rev&rev=470112
Log:
fixing up a conflicting url situation with JSON tags stats servlet.

- modified TagStatsServlet to expect an additional path element which specifies the defined
context or scope of the request.  current options are 'all' for site-wide behavior or 'weblog'
for single weblog.  the rest works the same aside from that.

- updated entry edit jsp to use the proper new urls for the tags stats service.

- added a new method in URLUtilities for getting the json tags stags service url.


Modified:
    incubator/roller/trunk/src/org/apache/roller/util/URLUtilities.java
    incubator/roller/trunk/src/org/apache/roller/webservices/json/TagStatsServlet.java
    incubator/roller/trunk/web/WEB-INF/jsps/authoring/WeblogEdit.jsp

Modified: incubator/roller/trunk/src/org/apache/roller/util/URLUtilities.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/util/URLUtilities.java?view=diff&rev=470112&r1=470111&r2=470112
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/util/URLUtilities.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/util/URLUtilities.java Wed Nov  1 13:52:20
2006
@@ -357,6 +357,34 @@
     
     
     /**
+     * Get url to JSON tags service url, optionally for a given weblog.
+     */
+    public static final String getWeblogTagsJsonURL(WebsiteData weblog,
+                                                    boolean absolute) {
+        
+        StringBuffer url = new StringBuffer();
+        
+        if(absolute) {
+            url.append(RollerRuntimeConfig.getAbsoluteContextURL());
+        } else {
+            url.append(RollerRuntimeConfig.getRelativeContextURL());
+        }
+        
+        // json tags service base
+        url.append("/roller-services/json/tags/");
+        
+        // is this for a specific weblog or site-wide?
+        if(weblog == null) {
+            url.append("all/");
+        } else {
+            url.append("weblog/").append(weblog.getHandle()).append("/");
+        }
+        
+        return url.toString();
+    }
+    
+    
+    /**
      * Get root url for a given *preview* weblog.  
      * Optionally for a certain locale.
      */

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/json/TagStatsServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/webservices/json/TagStatsServlet.java?view=diff&rev=470112&r1=470111&r2=470112
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/json/TagStatsServlet.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/json/TagStatsServlet.java Wed
Nov  1 13:52:20 2006
@@ -1,20 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* 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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
 package org.apache.roller.webservices.json;
 
 import java.io.IOException;
@@ -37,20 +38,19 @@
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.util.Utilities;
 
+
 /**
  * Return list of tags matching a startsWith strings. <br />
  * 
  * @web.servlet name="TagStatsServlet" 
  * @web.servlet-mapping url-pattern="/roller-services/json/tags/*"
+ *
  * @author Elias Torres (<a href="mailto:eliast@us.ibm.com">eliast@us.ibm.com</a>)
  */
 public class TagStatsServlet extends HttpServlet {
     
     private final int MAX_LENGTH = 100;
     
-    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
-        doGet(request, response);
-    }
     
     public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {    
@@ -58,6 +58,9 @@
         int limit = MAX_LENGTH;       
         try { 
             limit = Integer.parseInt(request.getParameter("limit"));
+            if(limit > MAX_LENGTH) {
+                limit = MAX_LENGTH;
+            }
         } catch (Throwable ignored) {}
         
         String pathInfo = request.getPathInfo();
@@ -75,24 +78,32 @@
             WebsiteData website = null;
             String startsWith = null;            
             
-            // website handle is always the first path segment,
-            // only throw an exception when not found if we have a tag prefix 
+            // request context is always the first path segment,
+            // we expect the value to be either 'all' or 'weblog'
+            // if the context is 'weblog' then the next part is a weblog handle
             if(path.length > 0) {
-                try {
-                    UserManager umgr = RollerFactory.getRoller().getUserManager();
-                    website = umgr.getWebsiteByHandle(path[0], Boolean.TRUE);
-                    if (website == null && path.length > 1)
-                        throw new RollerException();                
-                } catch (RollerException ex) {
-                    response.sendError(HttpServletResponse.SC_NOT_FOUND, "Weblog handle not
found.");
+                String context = path[0];
+                if(context != null && "weblog".equals(context)) {
+                    try {
+                        UserManager umgr = RollerFactory.getRoller().getUserManager();
+                        website = umgr.getWebsiteByHandle(path[1], Boolean.TRUE);
+                        if (website == null)
+                            throw new RollerException();
+                    } catch (RollerException ex) {
+                        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Weblog not
found.");
+                        return;
+                    }
+                } else if(context == null || !"all".equals(context) || path.length > 3)
{
+                    // bad url for this servlet
+                    response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bad url.");
                     return;
-                }    
+                }
             }
             
-            if(path.length == 2) {
+            if(path.length == 3) {
+                startsWith = path[2].trim();
+            } else if(path.length == 2 && website == null) {
                 startsWith = path[1].trim();
-            } else if(path.length == 1 && website == null) {
-                startsWith = path[0].trim();
             }
                                     
             List tags = wmgr.getTags(website, null, startsWith, limit);
@@ -119,8 +130,10 @@
             response.getWriter().println("\n  ]\n}");
             
             response.flushBuffer();
+            
         } catch (RollerException e) {
             throw new ServletException(e.getMessage());
         }
     }
+    
 }

Modified: incubator/roller/trunk/web/WEB-INF/jsps/authoring/WeblogEdit.jsp
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/jsps/authoring/WeblogEdit.jsp?view=diff&rev=470112&r1=470111&r2=470112
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/jsps/authoring/WeblogEdit.jsp (original)
+++ incubator/roller/trunk/web/WEB-INF/jsps/authoring/WeblogEdit.jsp Wed Nov  1 13:52:20 2006
@@ -17,6 +17,7 @@
 -->
 <%@ include file="/taglibs.jsp" %>
 <%@ page import="org.apache.roller.pojos.*" %>
+<%@ page import="org.apache.roller.util.URLUtilities" %>
 <%@ page import="org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryFormEx" %>
 <%@ page import="org.apache.roller.ui.authoring.struts.actions.WeblogEntryPageModel" %>
 <%
@@ -173,7 +174,7 @@
 		<br/>
         <script type="text/javascript">
         <!--
-		new RollerTagsAutoCompleter("entryEditTags", "entryEditTagsChoices", "<%= request.getContextPath()
%>/roller-services/json/tags/<%= model.getWeblogEntry().getWebsite().getHandle() %>",
{ tokens : [' ',','], minChars: 2 });
+		new RollerTagsAutoCompleter("entryEditTags", "entryEditTagsChoices", "<%= URLUtilities.getWeblogTagsJsonURL(model.getWeblogEntry().getWebsite(),
false) %>", { tokens : [' ',','], minChars: 2 });
         // --></script>
     </td></tr> 
     



Mime
View raw message