jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From felip...@apache.org
Subject cvs commit: jakarta-taglibs/string/xml string.xml
Date Tue, 09 Mar 2004 05:44:00 GMT
felipeal    2004/03/08 21:44:00

  Modified:    string/src/org/apache/taglibs/string WordWrapTag.java
               string/src/org/apache/taglibs/string/util StringW.java
               string/xml string.xml
  Log:
  added attribute delimiterInside for tag wordWrap - see bug 21866
  
  Revision  Changes    Path
  1.9       +23 -1     jakarta-taglibs/string/src/org/apache/taglibs/string/WordWrapTag.java
  
  Index: WordWrapTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/string/src/org/apache/taglibs/string/WordWrapTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WordWrapTag.java	9 Mar 2004 00:54:45 -0000	1.8
  +++ WordWrapTag.java	9 Mar 2004 05:44:00 -0000	1.9
  @@ -39,6 +39,10 @@
    *             Character to use when a word has to be split.
    *             Default is a - character.
    * </dd>
  + * <dt>delimiterInside</dt><dd>
  + *             Flag indicating if the delimiter should be included in chunk before length
reaches width.
  + *             Default is true.
  + * </dd>
    * </dl>
    * 
    * @author bayard@generationjava.com
  @@ -48,6 +52,7 @@
       private String delimiter;
       private String width;
       private String split;
  +    private boolean delimiterInside;
   
       public WordWrapTag() {
           super();
  @@ -109,10 +114,26 @@
           this.split = split;
       }
   
  +    /**
  +     * Get the delimiterInside property
  +     *
  +     * @return delimiterInside property
  +     */
  +    public boolean getDelimiterInside() {
  +        return this.delimiterInside;
  +    }
   
  +    /**
  +     * Set the delimiterInside property
  +     *
  +     * @param delimiterInside property
  +     */
  +    public void setDelimiterInside(boolean delimiterInside) {
  +        this.delimiterInside = delimiterInside;
  +    }
   
       public String changeString(String text) throws JspException {
  -        return StringW.wordWrap(text, NumberUtils.stringToInt(width), delimiter, split);
  +        return StringW.wordWrap(text, NumberUtils.stringToInt(width), delimiter, split,
delimiterInside );
       }
   
       public void initAttributes() {
  @@ -123,6 +144,7 @@
   
           this.split = "-";
   
  +        this.delimiterInside = true;
       }
   
   }
  
  
  
  1.18      +31 -5     jakarta-taglibs/string/src/org/apache/taglibs/string/util/StringW.java
  
  Index: StringW.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/string/src/org/apache/taglibs/string/util/StringW.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- StringW.java	6 Mar 2004 06:58:49 -0000	1.17
  +++ StringW.java	9 Mar 2004 05:44:00 -0000	1.18
  @@ -68,7 +68,7 @@
        * use a - sign to split it.
        */
       static public String wordWrap(String str) {
  -        return wordWrap(str, 80, "\n", "-");
  +        return wordWrap(str, 80, "\n", "-", true);
       }
       /**
        * Create a word-wrapped version of a String. Wrap at a specified width and 
  @@ -76,7 +76,7 @@
        * use a - sign to split it.
        */
       static public String wordWrap(String str, int width) {
  -        return wordWrap(str, width, "\n", "-");
  +        return wordWrap(str, width, "\n", "-", true);
       }
       /**
        * Word-wrap a string.
  @@ -86,19 +86,43 @@
        * @param delim String to use to separate lines
        * @param split String to use to split a word greater than width long
        *
  +     * @return String that has been word wrapped (with the delim inside width boundaries)
  +     */
  +  static public String wordWrap(String str, int width, String delim, String split ) {
  +    return wordWrap(str, width, delim, split, true);
  +  }
  +  
  +    /**
  +     * Word-wrap a string.
  +     *
  +     * @param str   String to word-wrap
  +     * @param width int to wrap at
  +     * @param delim String to use to separate lines
  +     * @param split String to use to split a word greater than width long
  +     * @param delimInside wheter or not delim should be included in chunk before length
reaches width.
  +     *
        * @return String that has been word wrapped
        */
  -    static public String wordWrap(String str, int width, String delim, String split) {
  +    static public String wordWrap(String str, int width, String delim,
  +                                  String split, boolean delimInside) {
           int sz = str.length();
   
  +        //        System.err.println( ">>>> inside: " + delimInside  + " sz
: " + sz );
  +
           /// shift width up one. mainly as it makes the logic easier
           width++;
   
           // our best guess as to an initial size
           StringBuffer buffer = new StringBuffer(sz/width*delim.length()+sz);
   
  -        // every line will include a delim on the end
  -        width = width - delim.length();
  +        // every line might include a delim on the end
  +        //        System.err.println( "width before: "+ width );
  +        if ( delimInside ) {
  +          width = width - delim.length();
  +        } else {
  +          width --;
  +        }
  +        //        System.err.println( "width after: "+ width );
   
           int idx = -1;
           String substr = null;
  @@ -116,9 +140,11 @@
   //            System.err.println("loop[i] is: "+i);
               // the current line
               substr = str.substring(i, i+width);
  +            //            System.err.println( "substr: " + substr );
   
               // is the delim already on the line
               idx = substr.indexOf(delim);
  +            //            System.err.println( "i: " + i + " idx : " + idx );
               if(idx != -1) {
                   buffer.append(substr.substring(0,idx));
   //                System.err.println("Substr: '"substr.substring(0,idx)+"'");
  
  
  
  1.30      +11 -0     jakarta-taglibs/string/xml/string.xml
  
  Index: string.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/string/xml/string.xml,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- string.xml	9 Mar 2004 00:48:03 -0000	1.29
  +++ string.xml	9 Mar 2004 05:44:00 -0000	1.30
  @@ -1427,6 +1427,17 @@
             </description>
             <availability>1.0</availability>
           </attribute>
  +        <attribute>
  +          <name>delimiterInside</name>
  +          <required>false</required>
  +          <rtexprvalue>false</rtexprvalue>
  +          <type>boolean</type>
  +          <description>
  +              Flag indicating if the delimiter should be included in chunk before length
reaches width.
  +              Default is true.
  +          </description>
  +          <availability>1.1</availability>
  +        </attribute>
           <example>
             <usage>
               <comment>
  
  
  

---------------------------------------------------------------------
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