Author: keith
Date: Thu Feb 12 03:20:24 2009
New Revision: 30718
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=30718

Log:
fix for 

Author: jonathan
Date: Fri Sep  5 10:46:59 2008
New Revision: 21529
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=21529

Log:
MASHUP-1018: Developed a function to trim visible characters from a string
without damaging markup.  Deployed the function in search.jsp, index.jsp,
user.jsp.  Minor style improvements as well.



Modified:
   
branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java
   branches/mashup/java/1.5/java/modules/www/css/styles.css
   branches/mashup/java/1.5/java/modules/www/index.jsp
   branches/mashup/java/1.5/java/modules/www/search.jsp
   branches/mashup/java/1.5/java/modules/www/user.jsp

Modified: 
branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java?rev=30718&r1=30717&r2=30718&view=diff
==============================================================================
--- 
branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java
    (original)
+++ 
branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java
    Thu Feb 12 03:20:24 2009
@@ -137,4 +137,70 @@
 
         return queryString;
     }
+
+
+    /*
+        Utility function to trim a string, which may include markup, to an 
approximately fixed length
+        of visible characters, preserving markup.
+
+        Known limitations:
+            - truncating a list may result in an orphaned bullet
+            - whitespace collapsing may affect <pre> tags
+            - visible markup won't be trimmed (e.g. <hr>, <img>)
+    */
+    public static String trimVisibleChars(String markup, int length) {
+        // Optimization - if no trimming is necessary, return immediately.
+        if (markup.length() <= length) {
+            return markup;
+        }
+
+        String trimmedMarkup = "";
+        int charactersDisplayed = 0;
+        boolean parsingTag = false;
+        boolean completingWord = true;
+
+        // Walk through the string a character at a time.
+        for (int i=0; i<markup.length(); i++) {
+            char c = markup.charAt(i);
+            if (parsingTag) {
+                // preserve all markup (anything between < and >)
+                trimmedMarkup += c;
+                if (c == '>') {
+                    parsingTag = false;
+                }
+            } else {
+                if (c == '<') {
+                    // entering a tag.  Anything from now till > will be 
passed through.
+                    trimmedMarkup += c;
+                    parsingTag = true;
+                } else {
+                    if (c == ' ' && i > 0 && markup.charAt(i-1) == ' ') {
+                        // collapse whitespace
+                    } else {
+                        if (charactersDisplayed < length) {
+                            // this character is before the trimming mark, 
show it.
+                            trimmedMarkup += c;
+                            charactersDisplayed++;
+                        } else {
+                            // now we're past the trimming mark, but we still 
might want to show a few characters.
+                            if (completingWord) {
+                                // if we're in the middle of a word, keep a 
few more characters.
+                                if (('0' <= c && c <= '9') || ('A' <= c && c 
<= 'Z') || ('a' <= c && c <= 'z')) {
+                                    trimmedMarkup += c;
+                                    charactersDisplayed++;
+                                } else {
+                                    // now we just completed the word, no 
other visible characters will be displayed.
+                                    // add an ellipsis to indicate that 
trimming occurred.
+                                    completingWord = false;
+                                    trimmedMarkup += "&hellip;";
+                                    charactersDisplayed++;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return trimmedMarkup;
+    }
 }

Modified: branches/mashup/java/1.5/java/modules/www/css/styles.css
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/www/css/styles.css?rev=30718&r1=30717&r2=30718&view=diff
==============================================================================
--- branches/mashup/java/1.5/java/modules/www/css/styles.css    (original)
+++ branches/mashup/java/1.5/java/modules/www/css/styles.css    Thu Feb 12 
03:20:24 2009
@@ -400,6 +400,10 @@
     width: 685px;
 }
 
+div.querypane-wide {
+    width: 945px;
+}
+
 div.query-controls {
     text-align: right;
 }
@@ -441,6 +445,10 @@
     margin: 2em 2em 4em 2em;
 }
 
+div.querypane p, div.querypane-comment p {
+    margin:0px;
+}
+
 div.querypane .data .headers {
     background-color: #ECFEC4;
     font-weight: bold;

Modified: branches/mashup/java/1.5/java/modules/www/index.jsp
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/www/index.jsp?rev=30718&r1=30717&r2=30718&view=diff
==============================================================================
--- branches/mashup/java/1.5/java/modules/www/index.jsp (original)
+++ branches/mashup/java/1.5/java/modules/www/index.jsp Thu Feb 12 03:20:24 2009
@@ -338,19 +338,11 @@
     </td>
     <td colspan="2">
         <div id="<%=result.getAuthor() + "_" + result.getName()%>">
-            <%
-                if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) {
-            %>
-            <div style="color: red;">This mashup is marked faulty by the 
system. Please click on its
-                name for further information.
-            </div>
-            <%
-            } else {
-            %>
-            <%=result.getDescription() %>
-            <%
-                }
-            %>
+            <%  if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) { %>
+            <div style="color: red;">This mashup is marked faulty by the 
system. Please click on its name for further information.</div>
+            <%  } else { %>
+            <%= QueryParamUtils.trimVisibleChars(result.getDescription(), 160) 
%>
+            <%  } %>
         </div>
     </td>
     <td nowrap class="right">

Modified: branches/mashup/java/1.5/java/modules/www/search.jsp
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/www/search.jsp?rev=30718&r1=30717&r2=30718&view=diff
==============================================================================
--- branches/mashup/java/1.5/java/modules/www/search.jsp        (original)
+++ branches/mashup/java/1.5/java/modules/www/search.jsp        Thu Feb 12 
03:20:24 2009
@@ -930,7 +930,7 @@
                             
queryPath.equals(MashupConstants.ACTIVITY_QUERY_PATH);
 
 %>
-<div class="querypane<% if (commentsQuery) { %>-comment<% } %>">
+<div class="querypane<% if (commentsQuery) { %>-comment<% } %> querypane-wide">
 <div class="heading"><%= queryTitle%>
     <span class="edit-link"><a
             href="search.jsp?<%=QueryParamUtils.paramsFromQuery(queryPath, 
queryParams)%>&format=rss"
@@ -1059,18 +1059,11 @@
     </td>
     <td class="desc">
         <div id="<%=result.getAuthor() + "_" + result.getName()%>">
-            <%
-                if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) {
-            %>
-            <div style="color: red;" >This mashup is marked faulty by the 
system. Please click on its name for further information.
-                </div>
-            <%
-            } else {
-            %>
-            <%=result.getDescription() %>
-            <%
-                }
-            %>
+            <%  if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) { %>
+            <div style="color: red;" >This mashup is marked faulty by the 
system. Please click on its name for further information.</div>
+            <%  } else { %>
+            <%= QueryParamUtils.trimVisibleChars(result.getDescription(), 270) 
%>
+            <%  } %>
         </div>
     </td>
     <td nowrap>

Modified: branches/mashup/java/1.5/java/modules/www/user.jsp
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/www/user.jsp?rev=30718&r1=30717&r2=30718&view=diff
==============================================================================
--- branches/mashup/java/1.5/java/modules/www/user.jsp  (original)
+++ branches/mashup/java/1.5/java/modules/www/user.jsp  Thu Feb 12 03:20:24 2009
@@ -419,20 +419,12 @@
                         </a>
                     </td>
                     <td>
-                        <%
-                            if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) {
-                        %>
-                        <div style="color: red;">This mashup is marked faulty 
by the system. Please
-                            click on its
-                            name for further information.
-                        </div>
-                        <%
-                        } else {
-                        %>
-                        <%=result.getDescription() %>
-                        <%
-                            }
-                        %>
+                        <%  if (RegistryUtils.isFaultyMashup(userRegistry, 
result.getPath())) { %>
+                        <div style="color: red;" >This mashup is marked faulty 
by the system. Please click on its name for further information.</div>
+                        <%  } else { %>
+                        <%=
+QueryParamUtils.trimVisibleChars(result.getDescription(), 160) %>
+                        <%  } %>
                     </td>
                     <td class="right" nowrap>
                         <%@ include file="rating.jsp" %>

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

Reply via email to