snagy       01/08/07 08:39:56

  Modified:    src/java/org/apache/ecs ElementAttributes.java
  Log:
  Submitted by: [EMAIL PROTECTED]
  Reviewed by: [EMAIL PROTECTED]
  
  Change the way keyword/value pair is delimited with quotes.
  
  Revision  Changes    Path
  1.12      +98 -11    jakarta-ecs/src/java/org/apache/ecs/ElementAttributes.java
  
  Index: ElementAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/ElementAttributes.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ElementAttributes.java    2001/04/13 14:35:20     1.11
  +++ ElementAttributes.java    2001/08/07 15:39:56     1.12
  @@ -62,7 +62,7 @@
   /**
       This class provides a common set of attributes set* methods for all classes.
       It is abstract to prevent direct instantiation.
  -    @version $Id: ElementAttributes.java,v 1.11 2001/04/13 14:35:20 snagy Exp $
  +    @version $Id: ElementAttributes.java,v 1.12 2001/08/07 15:39:56 snagy Exp $
       @author <a href="mailto:[EMAIL PROTECTED]";>Stephan Nagy</a>
       @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
   */
  @@ -353,17 +353,104 @@
               }
               out.append(' ');
               out.append(alterCase(attr));
  -            if(!value.equalsIgnoreCase(NO_ATTRIBUTE_VALUE) && getAttributeQuote())
  -            {
  -                out.append(getAttributeEqualitySign());
  -                out.append(getAttributeQuoteChar());
  -                out.append(value);
  -                out.append(getAttributeQuoteChar());
  -            }
  -            else if( !getAttributeQuote() )
  +                     int iStartPos = out.length();
  +            out.append(alterCase(attr));
  +            if ( !value.equalsIgnoreCase(NO_ATTRIBUTE_VALUE) )
               {
  -                out.append(getAttributeEqualitySign());
  -                out.append(value);
  +                // we have a value 
  +                // we might still enclose in quotes
  +                boolean quoteThisAttribute = attribute_quote;
  +                int singleQuoteFound = 0;
  +                int doubleQuoteFound = 0;
  +                if ( value.length() == 0 )
  +                { // quote a null string
  +                    quoteThisAttribute = true;
  +                }
  +                for ( int ii = 0; ii < value.length(); ii++ )
  +                {
  +                    char c = value.charAt( ii );
  +                    if ( 'a' <= c && c <= 'z' )
  +                    {
  +                        continue;
  +                    }
  +                    if ( 'A' <= c && c <= 'Z' )
  +                    {
  +                        continue;
  +                    }
  +                    if ( '0' <= c && c <= '9' )
  +                    {
  +                        continue;
  +                    }
  +                    if ( c == ':' ||
  +                         c == '-' ||
  +                         c == '_' ||
  +                         c == '.' )
  +                    {
  +                        continue;
  +                    }
  +                    if ( c == '\'' )
  +                    {
  +                        singleQuoteFound++;
  +                    }
  +                    if ( c == '"' )
  +                    {
  +                        doubleQuoteFound++;
  +                    }
  +                    quoteThisAttribute = true;
  +                }
  +                out.append( getAttributeEqualitySign() );
  +                if ( !quoteThisAttribute )
  +                { // no need to append quotes
  +                    out.append( value );
  +                }
  +                else
  +                { // use single quotes if possible
  +                    if ( singleQuoteFound == 0 )
  +                    { // no single quotes, safe to use them to quote
  +                        out.append( '\'' );
  +                        out.append( value );
  +                        out.append( '\'' );
  +                    }
  +                    else
  +                    if ( doubleQuoteFound == 0 )
  +                    { // no double quotes, safe to use them to quote
  +                        out.append( '"' );
  +                        out.append( value );
  +                        out.append( '"' );
  +                    }
  +                    else if ( singleQuoteFound <= doubleQuoteFound )
  +                    { // use single quotes, convert embedded single quotes
  +                        out.append( '\'' );
  +                        int startPos = out.length();
  +                        out.append( value );
  +                        for ( int ii = startPos; ii < out.length(); ii++ )
  +                        { // note out.length() may change during processing
  +                            if ( out.charAt( ii ) == '\'' )
  +                            {
  +                                out.setCharAt( ii, '&');
  +                                out.insert( ii+1, "#39;" );
  +                                ii++;
  +                            }
  +                        }
  +                        out.append( '\'' );
  +                    }
  +                    else
  +                    { // use double quotes, convert embedded double quotes
  +                        out.append( '"' );
  +                        int startPos = out.length();
  +                        out.append( value );
  +                        for ( int ii = startPos; ii < out.length(); ii++ )
  +                        { // note out.length() may change during processing
  +                            if ( out.charAt( ii ) == '"' )
  +                            {
  +                                out.setCharAt( ii, '&');
  +                                out.insert( ii+1, "#34;" );
  +                                ii++;
  +                            }
  +                        }
  +                        out.append( '"' );
  +                    }
  +                }
               }
           }
           if(getBeginEndModifierDefined())
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to