Java Code Examples for com.sun.org.apache.xpath.internal.compiler.Compiler#compileExpression()

The following examples show how to use com.sun.org.apache.xpath.internal.compiler.Compiler#compileExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
            new Object[]{Integer.toString(type)}));

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 2
Source File: XPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator,
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{
  m_funcTable = aTable;
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
          XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
          new Object[]{Integer.toString(type)}));
          //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 3
Source File: XPath.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
            new Object[]{Integer.toString(type)}));

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 4
Source File: XPath.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator,
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{
  m_funcTable = aTable;
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
          XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
          new Object[]{Integer.toString(type)}));
          //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 5
Source File: XPath.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
            new Object[]{Integer.toString(type)}));

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 6
Source File: XPath.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an XPath object.
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator,
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{
  m_funcTable = aTable;
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
          XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
          new Object[]{Integer.toString(type)}));
          //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 7
Source File: FilterExprWalker.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * Init a FilterExprWalker.
   *
   * @param compiler non-null reference to the Compiler that is constructing.
   * @param opPos positive opcode position for this step.
   * @param stepType The type of step.
   *
   * @throws javax.xml.transform.TransformerException
   */
  public void init(Compiler compiler, int opPos, int stepType)
          throws javax.xml.transform.TransformerException
  {

    super.init(compiler, opPos, stepType);

    // Smooth over an anomily in the opcode map...
    switch (stepType)
    {
    case OpCodes.OP_FUNCTION :
    case OpCodes.OP_EXTFUNCTION :
        m_mustHardReset = true;
    case OpCodes.OP_GROUP :
    case OpCodes.OP_VARIABLE :
      m_expr = compiler.compileExpression(opPos);
      m_expr.exprSetParent(this);
      //if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof com.sun.org.apache.xalan.internal.templates.FuncKey))
      if(m_expr instanceof com.sun.org.apache.xpath.internal.operations.Variable)
      {
        // hack/temp workaround
        m_canDetachNodeset = false;
      }
      break;
    default :
      m_expr = compiler.compileExpression(opPos + 2);
      m_expr.exprSetParent(this);
    }
//    if(m_expr instanceof WalkingIterator)
//    {
//      WalkingIterator wi = (WalkingIterator)m_expr;
//      if(wi.getFirstWalker() instanceof FilterExprWalker)
//      {
//              FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
//              if(null == fw.getNextWalker())
//              {
//                      m_expr = fw.m_expr;
//                      m_expr.exprSetParent(this);
//              }
//      }
//
//    }
  }
 
Example 8
Source File: FilterExprWalker.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
   * Init a FilterExprWalker.
   *
   * @param compiler non-null reference to the Compiler that is constructing.
   * @param opPos positive opcode position for this step.
   * @param stepType The type of step.
   *
   * @throws javax.xml.transform.TransformerException
   */
  public void init(Compiler compiler, int opPos, int stepType)
          throws javax.xml.transform.TransformerException
  {

    super.init(compiler, opPos, stepType);

    // Smooth over an anomily in the opcode map...
    switch (stepType)
    {
    case OpCodes.OP_FUNCTION :
    case OpCodes.OP_EXTFUNCTION :
        m_mustHardReset = true;
    case OpCodes.OP_GROUP :
    case OpCodes.OP_VARIABLE :
      m_expr = compiler.compileExpression(opPos);
      m_expr.exprSetParent(this);
      //if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof com.sun.org.apache.xalan.internal.templates.FuncKey))
      if(m_expr instanceof com.sun.org.apache.xpath.internal.operations.Variable)
      {
        // hack/temp workaround
        m_canDetachNodeset = false;
      }
      break;
    default :
      m_expr = compiler.compileExpression(opPos + 2);
      m_expr.exprSetParent(this);
    }
//    if(m_expr instanceof WalkingIterator)
//    {
//      WalkingIterator wi = (WalkingIterator)m_expr;
//      if(wi.getFirstWalker() instanceof FilterExprWalker)
//      {
//              FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
//              if(null == fw.getNextWalker())
//              {
//                      m_expr = fw.m_expr;
//                      m_expr.exprSetParent(this);
//              }
//      }
//
//    }
  }
 
Example 9
Source File: FilterExprWalker.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
   * Init a FilterExprWalker.
   *
   * @param compiler non-null reference to the Compiler that is constructing.
   * @param opPos positive opcode position for this step.
   * @param stepType The type of step.
   *
   * @throws javax.xml.transform.TransformerException
   */
  @SuppressWarnings("fallthrough")
  public void init(Compiler compiler, int opPos, int stepType)
          throws javax.xml.transform.TransformerException
  {

    super.init(compiler, opPos, stepType);

    // Smooth over an anomily in the opcode map...
    switch (stepType)
    {
    case OpCodes.OP_FUNCTION :
    case OpCodes.OP_EXTFUNCTION :
        m_mustHardReset = true;
    case OpCodes.OP_GROUP :
    case OpCodes.OP_VARIABLE :
      m_expr = compiler.compileExpression(opPos);
      m_expr.exprSetParent(this);
      //if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof com.sun.org.apache.xalan.internal.templates.FuncKey))
      if(m_expr instanceof com.sun.org.apache.xpath.internal.operations.Variable)
      {
        // hack/temp workaround
        m_canDetachNodeset = false;
      }
      break;
    default :
      m_expr = compiler.compileExpression(opPos + 2);
      m_expr.exprSetParent(this);
    }
//    if(m_expr instanceof WalkingIterator)
//    {
//      WalkingIterator wi = (WalkingIterator)m_expr;
//      if(wi.getFirstWalker() instanceof FilterExprWalker)
//      {
//              FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
//              if(null == fw.getNextWalker())
//              {
//                      m_expr = fw.m_expr;
//                      m_expr.exprSetParent(this);
//              }
//      }
//
//    }
  }