mmidy       01/10/09 08:15:07

  Modified:    java/src/org/apache/xalan/templates AVT.java
  Log:
  Bugzilla 1009: Catch NoSuchElementException from java.util.StringTokenizer
  
  Revision  Changes    Path
  1.16      +88 -80    xml-xalan/java/src/org/apache/xalan/templates/AVT.java
  
  Index: AVT.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVT.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AVT.java  2001/06/13 20:58:05     1.15
  +++ AVT.java  2001/10/09 15:15:07     1.16
  @@ -240,97 +240,109 @@
               case ('{') :
               {
   
  -              // Attribute Value Template start
  -              lookahead = tokenizer.nextToken();
  -
  -              if (lookahead.equals("{"))
  +              try
                 {
  +                // Attribute Value Template start
  +                lookahead = tokenizer.nextToken();
   
  -                // Double curlys mean escape to show curly
  -                buffer.append(lookahead);
  +                if (lookahead.equals("{"))
  +                {
   
  -                lookahead = null;
  +                  // Double curlys mean escape to show curly
  +                  buffer.append(lookahead);
   
  -                break;  // from switch
  -              }
  +                  lookahead = null;
   
  -              /*
  -              else if(lookahead.equals("\"") || lookahead.equals("\'"))
  -              {
  -              // Error. Expressions can not begin with quotes.
  -              error = "Expressions can not begin with quotes.";
  -              break; // from switch
  -              }
  -              */
  -              else
  -              {
  -                if (buffer.length() > 0)
  +                  break;  // from switch
  +                }
  +
  +                /*
  +                else if(lookahead.equals("\"") || lookahead.equals("\'"))
                   {
  -                  m_parts.addElement(new AVTPartSimple(buffer.toString()));
  -                  buffer.setLength(0);
  +                // Error. Expressions can not begin with quotes.
  +                error = "Expressions can not begin with quotes.";
  +                break; // from switch
                   }
  +                */
  +                else
  +                {
  +                  if (buffer.length() > 0)
  +                  {
  +                    m_parts.addElement(new AVTPartSimple(buffer.toString()));
  +                    buffer.setLength(0);
  +                  }
   
  -                exprBuffer.setLength(0);
  +                  exprBuffer.setLength(0);
   
  -                while (null != lookahead)
  -                {
  -                  if (lookahead.length() == 1)
  +                  while (null != lookahead)
                     {
  -                    switch (lookahead.charAt(0))
  +                    if (lookahead.length() == 1)
                       {
  -                    case '\'' :
  -                    case '\"' :
  -                    {
  +                      switch (lookahead.charAt(0))
  +                      {
  +                      case '\'' :
  +                      case '\"' :
  +                        {
   
  -                      // String start
  -                      exprBuffer.append(lookahead);
  +                          // String start
  +                          exprBuffer.append(lookahead);
   
  -                      String quote = lookahead;
  +                          String quote = lookahead;
   
  -                      // Consume stuff 'till next quote
  -                      lookahead = tokenizer.nextToken();
  +                          // Consume stuff 'till next quote
  +                          lookahead = tokenizer.nextToken();
   
  -                      while (!lookahead.equals(quote))
  -                      {
  -                        exprBuffer.append(lookahead);
  +                          while (!lookahead.equals(quote))
  +                          {
  +                            exprBuffer.append(lookahead);
   
  -                        lookahead = tokenizer.nextToken();
  -                      }
  +                            lookahead = tokenizer.nextToken();
  +                          }
   
  -                      exprBuffer.append(lookahead);
  +                          exprBuffer.append(lookahead);
   
  -                      lookahead = tokenizer.nextToken();
  +                          lookahead = tokenizer.nextToken();
   
  -                      break;
  -                    }
  -                    case '{' :
  -                    {
  +                          break;
  +                        }
  +                      case '{' :
  +                        {
   
  -                      // What's another curly doing here?
  -                      error = XSLMessages.createMessage(
  -                        XSLTErrorResources.ER_NO_CURLYBRACE, null);  
//"Error: Can not have \"{\" within expression.";
  -                      
  -                      lookahead = null;  // breaks out of inner while loop
  +                          // What's another curly doing here?
  +                          error = XSLMessages.createMessage(
  +                                                            
XSLTErrorResources.ER_NO_CURLYBRACE, null);  //"Error: Can not have \"{\" 
within expression.";
  +                          
  +                          lookahead = null;  // breaks out of inner while 
loop
   
  -                      break;
  -                    }
  -                    case '}' :
  -                    {
  +                          break;
  +                        }
  +                      case '}' :
  +                        {
   
  -                      // Proper close of attribute template.
  -                      // Evaluate the expression.
  -                      buffer.setLength(0);
  +                          // Proper close of attribute template.
  +                          // Evaluate the expression.
  +                          buffer.setLength(0);
   
  -                      XPath xpath =
  -                        handler.createXPath(exprBuffer.toString());
  +                          XPath xpath =
  +                                       
handler.createXPath(exprBuffer.toString());
   
  -                      m_parts.addElement(new AVTPartXPath(xpath));
  +                          m_parts.addElement(new AVTPartXPath(xpath));
   
  -                      lookahead = null;  // breaks out of inner while loop
  +                          lookahead = null;  // breaks out of inner while 
loop
   
  -                      break;
  -                    }
  -                    default :
  +                          break;
  +                        }
  +                      default :
  +                        {
  +
  +                          // part of the template stuff, just add it.
  +                          exprBuffer.append(lookahead);
  +
  +                          lookahead = tokenizer.nextToken();
  +                        }
  +                      }  // end inner switch
  +                    }  // end if lookahead length == 1
  +                    else
                       {
   
                         // part of the template stuff, just add it.
  @@ -338,25 +350,21 @@
   
                         lookahead = tokenizer.nextToken();
                       }
  -                    }  // end inner switch
  -                  }  // end if lookahead length == 1
  -                  else
  -                  {
  +                  }  // end while(!lookahead.equals("}"))
   
  -                    // part of the template stuff, just add it.
  -                    exprBuffer.append(lookahead);
  -
  -                    lookahead = tokenizer.nextToken();
  +                  if (error != null)
  +                  {
  +                    break;  // from inner while loop
                     }
  -                }  // end while(!lookahead.equals("}"))
  -
  -                if (error != null)
  -                {
  -                  break;  // from inner while loop
                   }
  -              }
   
  -              break;
  +                break;
  +              }
  +              catch (java.util.NoSuchElementException ex)
  +              {
  +                error = 
XSLMessages.createMessage(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE_VALUE, new 
Object[]{ name, stringedValue }); 
  +                break;
  +              }
               }
               case ('}') :
               {
  
  
  

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

Reply via email to