avt.java

来自「java jdk 1.4的源码」· Java 代码 · 共 643 行 · 第 1/2 页

JAVA
643
字号
                          // Proper close of attribute template.                          // Evaluate the expression.                          buffer.setLength(0);                          XPath xpath =                                       handler.createXPath(exprBuffer.toString(), owner);                          m_parts.addElement(new AVTPartXPath(xpath));                          lookahead = null;  // breaks out of inner while loop                          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.                      exprBuffer.append(lookahead);                      lookahead = tokenizer.nextToken();                    }                  }  // end while(!lookahead.equals("}"))                  if (error != null)                  {                    break;  // from inner while loop                  }                }                break;              }              catch (java.util.NoSuchElementException ex)              {                error = XSLMessages.createMessage(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE_VALUE, new Object[]{ name, stringedValue });                 break;              }            }            case ('}') :            {              lookahead = tokenizer.nextToken();              if (lookahead.equals("}"))              {                // Double curlys mean escape to show curly                buffer.append(lookahead);                lookahead = null;  // swallow              }              else              {                // Illegal, I think...                try                {                  handler.warn(XSLTErrorResources.WG_FOUND_CURLYBRACE, null);  //"Found \"}\" but no attribute template open!");                }                catch (org.xml.sax.SAXException se)                {                  throw new TransformerException(se);                }                buffer.append("}");                // leave the lookahead to be processed by the next round.              }              break;            }            default :            {              // Anything else just add to string.              buffer.append(t);            }            }  // end switch t          }  // end if length == 1          else          {            // Anything else just add to string.            buffer.append(t);          }          if (null != error)          {            try            {              handler.warn(XSLTErrorResources.WG_ATTR_TEMPLATE,                           new Object[]{ error });  //"Attr Template, "+error);            }            catch (org.xml.sax.SAXException se)            {              throw new TransformerException(se);            }            break;          }        }  // end while(tokenizer.hasMoreTokens())        if (buffer.length() > 0)        {          m_parts.addElement(new AVTPartSimple(buffer.toString()));          buffer.setLength(0);        }      }      finally      {        StringBufferPool.free(buffer);        StringBufferPool.free(exprBuffer);      }    }  // end else nTokens > 1    if (null == m_parts && (null == m_simpleString))    {      // Error?      m_simpleString = "";    }  }  /**   * Get the AVT as the original string.   *   * @return The AVT as the original string   */  public String getSimpleString()  {    if (null != m_simpleString)    {      return m_simpleString;    }    else if (null != m_parts)    {      FastStringBuffer buf = StringBufferPool.get();      String s;      try      {        buf.setLength(0);        int n = m_parts.size();        for (int i = 0; i < n; i++)        {          AVTPart part = (AVTPart) m_parts.elementAt(i);          buf.append(part.getSimpleString());        }        s = buf.toString();      }      finally      {        StringBufferPool.free(buf);      }      return s;    }    else    {      return "";    }  }  /**   * Evaluate the AVT and return a String.   *   * @param xctxt Te XPathContext to use to evaluate this.   * @param context The current source tree context.   * @param nsNode The current namespace context (stylesheet tree context).   * @param NodeList The current Context Node List.   *   * @return The AVT evaluated as a string   *   * @throws javax.xml.transform.TransformerException   */  public String evaluate(          XPathContext xctxt, int context, org.apache.xml.utils.PrefixResolver nsNode)            throws javax.xml.transform.TransformerException  {    FastStringBuffer buf = StringBufferPool.get();    try    {      if (null != m_simpleString)      {        return m_simpleString;      }      else if (null != m_parts)      {        buf.setLength(0);        int n = m_parts.size();        for (int i = 0; i < n; i++)        {          AVTPart part = (AVTPart) m_parts.elementAt(i);          part.evaluate(xctxt, buf, context, nsNode);        }        return buf.toString();      }      else      {        return "";      }    }    finally    {      StringBufferPool.free(buf);    }  }  /**   * Test whether the AVT is insensitive to the context in which   *  it is being evaluated. This is intended to facilitate   *  compilation of templates, by allowing simple AVTs to be   *  converted back into strings.   *   *  Currently the only case we recognize is simple strings.   * ADDED 9/5/2000 to support compilation experiment   *   * @return True if the m_simpleString member of this AVT is not null   */  public boolean isContextInsensitive()  {    return null != m_simpleString;  }  /**   * Tell if this expression or it's subexpressions can traverse outside   * the current subtree.   *   * @return true if traversal outside the context node's subtree can occur.   */  public boolean canTraverseOutsideSubtree()  {    if (null != m_parts)    {      int n = m_parts.size();      for (int i = 0; i < n; i++)      {        AVTPart part = (AVTPart) m_parts.elementAt(i);        if (part.canTraverseOutsideSubtree())          return true;      }    }    return false;  }    /**   * This function is used to fixup variables from QNames to stack frame    * indexes at stylesheet build time.   * @param vars List of QNames that correspond to variables.  This list    * should be searched backwards for the first qualified name that    * corresponds to the variable reference qname.  The position of the    * QName in the vector from the start of the vector will be its position    * in the stack frame (but variables above the globalsTop value will need    * to be offset to the current stack frame).   */  public void fixupVariables(java.util.Vector vars, int globalsSize)  {    if (null != m_parts)    {      int n = m_parts.size();      for (int i = 0; i < n; i++)      {        AVTPart part = (AVTPart) m_parts.elementAt(i);        part.fixupVariables(vars, globalsSize);      }    }  }    /**   * @see XSLTVisitable#callVisitors(XSLTVisitor)   */  public void callVisitors(XSLTVisitor visitor)  {  	if(visitor.visitAVT(this) && (null != m_parts))  	{      int n = m_parts.size();      for (int i = 0; i < n; i++)      {        AVTPart part = (AVTPart) m_parts.elementAt(i);        part.callVisitors(visitor);      }  		  	}  }  /**   * Returns true if this AVT is simple   */  public boolean isSimple() {  	return m_simpleString != null;  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?