jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@apache.org
Subject cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/functions Functions.java
Date Sat, 29 Mar 2003 00:10:28 GMT
pierred     2003/03/28 16:10:27

  Modified:    standard/conf fn.tld
               standard/examples/conf jstl-examples.tld
               standard/examples/web index.html
               standard/examples/web/functions Functions.jsp
               standard/src/org/apache/taglibs/standard/functions
                        Functions.java
  Log:
  Implementation for the remaining 3 functions (replace, split, join).
  Join commented out pending a fix to Jasper to support arrays as
  function arguments.
  
  Revision  Changes    Path
  1.3       +20 -0     jakarta-taglibs/standard/conf/fn.tld
  
  Index: fn.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/fn.tld,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fn.tld	25 Mar 2003 19:43:21 -0000	1.2
  +++ fn.tld	29 Mar 2003 00:10:27 -0000	1.3
  @@ -41,10 +41,30 @@
       <function-signature>int indexOf(java.lang.String, java.lang.String)</function-signature>
     </function>
   
  +<!-- need fix to jasper
  +  <function>
  +    <name>join</name>
  +    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
  +    <function-signature>java.lang.String join(java.lang.String[], java.lang.String)</function-signature>
  +  </function>
  +-->
  +
     <function>
       <name>length</name>
       <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
       <function-signature>int length(java.lang.Object)</function-signature>
  +  </function>
  +
  +  <function>
  +    <name>replace</name>
  +    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
  +    <function-signature>java.lang.String replace(java.lang.String, java.lang.String,
java.lang.String)</function-signature>
  +  </function>
  +
  +  <function>
  +    <name>split</name>
  +    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
  +    <function-signature>java.lang.String[] split(java.lang.String, java.lang.String)</function-signature>
     </function>
   
     <function>
  
  
  
  1.4       +7 -0      jakarta-taglibs/standard/examples/conf/jstl-examples.tld
  
  Index: jstl-examples.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/conf/jstl-examples.tld,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- jstl-examples.tld	13 Mar 2003 18:56:57 -0000	1.3
  +++ jstl-examples.tld	29 Mar 2003 00:10:27 -0000	1.4
  @@ -117,4 +117,11 @@
           <rtexprvalue>false</rtexprvalue>
       </attribute>
     </tag>
  +
  +  <function>
  +    <name>display</name>
  +    <function-class>org.apache.taglibs.jsptl.examples.taglib.Functions</function-class>
  +    <function-signature>java.lang.String display(java.lang.Object)</function-signature>
  +  </function>
  +
   </taglib>
  
  
  
  1.21      +1 -0      jakarta-taglibs/standard/examples/web/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/index.html,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- index.html	18 Mar 2003 23:00:45 -0000	1.20
  +++ index.html	29 Mar 2003 00:10:27 -0000	1.21
  @@ -63,6 +63,7 @@
     <li><a href="format/index.html">I18N &amp; Formatting Tags</a></li>
     <li><a href="xml/index.html">XML Tags</a></li>
     <li><a href="sql/index.jsp">SQL Tags</a></li>
  +  <li><a href="functions/index.html">Functions</a></li>
     <li><a href="tlv/index.html">Tag Library Validators</a></li>
     <li><a href="misc/index.html">Miscellaneous</a></li>
   </ul>
  
  
  
  1.4       +110 -0    jakarta-taglibs/standard/examples/web/functions/Functions.jsp
  
  Index: Functions.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/functions/Functions.jsp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Functions.jsp	26 Mar 2003 20:43:06 -0000	1.3
  +++ Functions.jsp	29 Mar 2003 00:10:27 -0000	1.4
  @@ -1,5 +1,6 @@
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  +<%@ taglib prefix="ex" uri="/jstl-examples-taglib" %>
   
   <html>
   <head>
  @@ -226,6 +227,12 @@
     </tr>
     <tr>
       <td>${s1}</td>
  +    <td>12</td>
  +    <td>5</td>
  +    <td>&nbsp;${fn:substring(s1, 12, 5)}</td>
  +  </tr>
  +  <tr>
  +    <td>${s1}</td>
       <td>23</td>
       <td>-1</td>
       <td>${fn:substring(s1, 23, -1)}</td>
  @@ -444,6 +451,109 @@
       <td>&nbsp;${fn:toUpperCase("")}</td>
     </tr>
   </table>
  +
  +<c:set var="s2" value="one two three one two three one two three"/>
  +<h4>fn:replace</h4>
  +<table cellpadding="5" border="1">
  +  <tr>
  +    <th align="left">Input String</th>
  +    <th>Substring Before</th>
  +    <th>Substring After</th>
  +    <th>Result</th>
  +  </tr>
  +  <tr>
  +    <td>${s1}</td>
  +    <td>e</td>
  +    <td>*</td>
  +    <td>${fn:replace(s1, "e", "*")}</td>
  +  </tr>
  +  <tr>
  +    <td>${s2}</td>
  +    <td>two</td>
  +    <td>empty</td>
  +    <td>${fn:replace(s2, "two", "")}</td>
  +  </tr>
  +  <tr>
  +    <td>${s2}</td>
  +    <td>empty</td>
  +    <td>one</td>
  +    <td>${fn:replace(s2, "", "one")}</td>
  +  </tr>
  +  <tr>
  +    <td>null</td>
  +    <td>one</td>
  +    <td>two</td>
  +    <td>&nbsp;${fn:replace(undefined, "one", "two")}</td>
  +  </tr>
  +</table>
  +
  +<c:set var="s3" value="one|two|three|four"/>
  +<c:set var="s5" value="one|two+three*four"/>
  +<h4>fn:split</h4>
  +<table cellpadding="5" border="1">
  +  <tr>
  +    <th align="left">Input String</th>
  +    <th>Delimiters</th>
  +    <th>Result</th>
  +  </tr>
  +  <tr>
  +    <td>${s1}</td>
  +    <td>empty</td>
  +    <td>${ex:display(fn:split(s1, ""))}</td>
  +  </tr>
  +  <tr>
  +    <td>${s3}</td>
  +    <td>|</td>
  +    <td>${ex:display(fn:split(s3, "|"))}</td>
  +  </tr>
  +  <tr>
  +    <td>${s3}</td>
  +    <td>+</td>
  +    <td>${ex:display(fn:split(s3, "+"))}</td>
  +  </tr>
  +  <tr>
  +    <td>${s5}</td>
  +    <td>|+</td>
  +    <td>${ex:display(fn:split(s5, "|+"))}</td>
  +  </tr>
  +  <tr>
  +    <td>empty</td>
  +    <td>empty</td>
  +    <td>${ex:display(fn:split("", ""))}</td>
  +  </tr>
  +</table>
  +
  +<%-- need fix to jasper
  +<c:set var="a1" value='${fn:split(s1, "")}'/>
  +<h4>fn:join</h4>
  +<table cellpadding="5" border="1">
  +  <tr>
  +    <th align="left">Input Array</th>
  +    <th>Separator</th>
  +    <th>Result</th>
  +  </tr>
  +  <tr>
  +    <td>${ex:display(s4)}</td>
  +    <td> + </td>
  +    <td>${fn:join(s4, " + ")}</td>
  +  </tr>
  +  <tr>
  +    <td>${ex:display(s4)}</td>
  +    <td>empty</td>
  +    <td>${fn:join(s4, "")}</td>
  +  </tr>
  +  <tr>
  +    <td>${ex:display(s4)}</td>
  +    <td>null</td>
  +    <td>${fn:join(s4, null)}</td>
  +  </tr>
  +  <tr>
  +    <td>null</td>
  +    <td>empty</td>
  +    <td>${fn:join(null, "")}</td>
  +  </tr>
  +</table>
  +--%>
   
   </body>
   </html>
  
  
  
  1.4       +63 -4     jakarta-taglibs/standard/src/org/apache/taglibs/standard/functions/Functions.java
  
  Index: Functions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/functions/Functions.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Functions.java	26 Mar 2003 20:43:06 -0000	1.3
  +++ Functions.java	29 Mar 2003 00:10:27 -0000	1.4
  @@ -127,6 +127,7 @@
           if (beginIndex >= input.length()) beginIndex = input.length() - 1;
           if (beginIndex < 0) beginIndex = 0;
           if (endIndex < 0 || endIndex > input.length()) endIndex = input.length();
  +        if (endIndex < beginIndex) return "";
           return input.substring(beginIndex, endIndex);
       }    
       
  @@ -171,6 +172,55 @@
           return input.trim();
       }    
   
  +    public static String replace(
  +    String input, 
  +    String substringBefore,
  +    String substringAfter) 
  +    {
  +        if (input == null) input = "";
  +        if (input.length() == 0) return "";
  +        if (substringBefore == null) substringBefore = "";
  +        if (substringBefore.length() == 0) return input;
  +                
  +        StringBuffer buf = new StringBuffer(input.length());
  +        int startIndex = 0;
  +        int index;
  +        while ((index = input.indexOf(substringBefore, startIndex)) != -1) {
  +            buf.append(input.substring(startIndex, index)).append(substringAfter);
  +            startIndex = index + substringBefore.length();
  +        }
  +        return buf.append(input.substring(startIndex)).toString();
  +    }
  +    
  +    public static String[] split(
  +    String input, 
  +    String delimiters) 
  +    {
  +        String[] array;
  +        if (input == null) input = "";
  +        if (input.length() == 0) {
  +            array = new String[1];
  +            array[0] = "";
  +            return array;
  +        }
  +        
  +        if (delimiters == null) delimiters = "";
  +
  +        StringTokenizer tok;
  +        if (delimiters.length() == 0) {
  +            tok = new StringTokenizer(input);
  +        } else {        
  +            tok = new StringTokenizer(input, delimiters);
  +        }
  +        int count = tok.countTokens();
  +        array = new String[count];
  +        int i = 0;
  +        while (tok.hasMoreTokens()) {
  +            array[i++] = tok.nextToken();
  +        }
  +        return array;
  +    }        
  +        
       //*********************************************************************
       // Collections processing
       
  @@ -207,7 +257,16 @@
           throw new JspTagException(Resources.getMessage("FOREACH_BAD_ITEMS"));        
       }      
   
  -    /** @@@ LEFT TO DO
  -     * split(), join(), replace()
  -     */    
  -}
  +    public static String join(String[] array, String separator) {
  +        if (array == null) return "";         
  +        if (separator == null) separator = "";
  +        
  +        StringBuffer buf = new StringBuffer();
  +        for (int i=0; i<array.length; i++) {
  +            buf.append(array[i]);
  +            if (i < array.length-1) buf.append(separator);
  +        }
  +        
  +        return buf.toString();
  +    }
  +}
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message