Ejemplo n.º 1
0
  /**
   * Construct an XPath object.
   *
   * <p>(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)})); // "Can not deal with XPath type: " + type);

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

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

    if ((null != locator) && locator instanceof ExpressionNode) {
      expr.exprSetParent((ExpressionNode) locator);
    }
  }
Ejemplo n.º 2
0
  /**
   * Create a OneStepIterator object.
   *
   * @param compiler A reference to the Compiler that contains the op map.
   * @param opPos The position within the op map, which contains the location path expression for
   *     this itterator.
   * @throws javax.xml.transform.TransformerException
   */
  OneStepIterator(Compiler compiler, int opPos, int analysis)
      throws javax.xml.transform.TransformerException {
    super(compiler, opPos, analysis);
    int firstStepPos = compiler.getFirstChildPos(opPos);

    m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
  }
Ejemplo n.º 3
0
 /**
  * Create a new location path iterator.
  *
  * @param compiler The Compiler which is creating this expression.
  * @param opPos The position of this iterator in the
  * @return New location path iterator.
  * @throws javax.xml.transform.TransformerException
  */
 protected LocPathIterator createDTMIterator(Compiler compiler, int opPos)
     throws javax.xml.transform.TransformerException {
   LocPathIterator lpi =
       (LocPathIterator)
           WalkerFactory.newDTMIterator(compiler, opPos, (compiler.getLocationPathDepth() <= 0));
   return lpi;
 }
Ejemplo n.º 4
0
  /**
   * Create a UnionPathIterator object, including creation of location path iterators from the
   * opcode list, and call back into the Compiler to create predicate expressions.
   *
   * @param compiler The Compiler which is creating this expression.
   * @param opPos The position of this iterator in the opcode list from the compiler.
   * @throws javax.xml.transform.TransformerException
   */
  public UnionPathIterator(Compiler compiler, int opPos)
      throws javax.xml.transform.TransformerException {

    super();

    opPos = compiler.getFirstChildPos(opPos);

    loadLocationPaths(compiler, opPos, 0);
  }
 /*     */ protected BasicTestIterator(Compiler compiler, int opPos, int analysis)
     /*     */ throws TransformerException
       /*     */ {
   /*  78 */ super(compiler, opPos, analysis, false);
   /*     */
   /*  80 */ int firstStepPos = OpMap.getFirstChildPos(opPos);
   /*  81 */ int whatToShow = compiler.getWhatToShow(firstStepPos);
   /*     */
   /*  83 */ if ((0 == (whatToShow & 0x1043)) || (whatToShow == -1))
   /*     */ {
     /*  89 */ initNodeTest(whatToShow);
     /*     */ }
   /*     */ else {
     /*  92 */ initNodeTest(
         whatToShow, compiler.getStepNS(firstStepPos), compiler.getStepLocalName(firstStepPos));
     /*     */ }
   /*     */
   /*  95 */ initPredicateInfo(compiler, firstStepPos);
   /*     */ }
Ejemplo n.º 6
0
  /**
   * Create a WalkingIterator iterator, including creation of step walkers from the opcode list, and
   * call back into the Compiler to create predicate expressions.
   *
   * @param compiler The Compiler which is creating this expression.
   * @param opPos The position of this iterator in the opcode list from the compiler.
   * @param shouldLoadWalkers True if walkers should be loaded, or false if this is a derived
   *     iterator and it doesn't wish to load child walkers.
   * @throws javax.xml.transform.TransformerException
   */
  WalkingIterator(Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
      throws javax.xml.transform.TransformerException {
    super(compiler, opPos, analysis, shouldLoadWalkers);

    int firstStepPos = compiler.getFirstChildPos(opPos);

    if (shouldLoadWalkers) {
      m_firstWalker = WalkerFactory.loadWalkers(this, compiler, firstStepPos, 0);
      m_lastUsedWalker = m_firstWalker;
    }
  }
Ejemplo n.º 7
0
  /**
   * Initialize the location path iterators. Recursive.
   *
   * @param compiler The Compiler which is creating this expression.
   * @param opPos The position of this iterator in the opcode list from the compiler.
   * @param count The insert position of the iterator.
   * @throws javax.xml.transform.TransformerException
   */
  protected void loadLocationPaths(Compiler compiler, int opPos, int count)
      throws javax.xml.transform.TransformerException {

    // TODO: Handle unwrapped FilterExpr
    int steptype = compiler.getOp(opPos);

    if (steptype == OpCodes.OP_LOCATIONPATH) {
      loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);

      m_exprs[count] = createDTMIterator(compiler, opPos);
      m_exprs[count].exprSetParent(this);
    } else {

      // Have to check for unwrapped functions, which the LocPathIterator
      // doesn't handle.
      switch (steptype) {
        case OpCodes.OP_VARIABLE:
        case OpCodes.OP_EXTFUNCTION:
        case OpCodes.OP_FUNCTION:
        case OpCodes.OP_GROUP:
          loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);

          WalkingIterator iter = new WalkingIterator(compiler.getNamespaceContext());
          iter.exprSetParent(this);

          if (compiler.getLocationPathDepth() <= 0) iter.setIsTopLevel(true);

          iter.m_firstWalker = new com.sun.org.apache.xpath.internal.axes.FilterExprWalker(iter);

          iter.m_firstWalker.init(compiler, opPos, steptype);

          m_exprs[count] = iter;
          break;
        default:
          m_exprs = new LocPathIterator[count];
      }
    }
  }