Package org.zkoss.xel

Examples of org.zkoss.xel.XelException


  private ELResolver _cdiResolver;
  public DelegatingVariableResolver() {
    _cdiResolver = CDIUtil.getBeanManager().getELResolver();
  }
  public Object resolveVariable(String name) throws XelException {
    throw new XelException("Need ZK 5.0+ ...");
  }
View Full Code Here


  public void load(String prefix, String uri, Locator locator)
  throws XelException {
    if (prefix == null || uri == null)
      throw new IllegalArgumentException("null");
    if (_mtds != null && _mtds.containsKey(prefix))
      throw new XelException("The prefix, "+prefix+", is already used");

    URL url = uri.indexOf("://") > 0 ? null: locator.getResource(uri);
    if (url == null) {
      url = Taglibs.getDefaultURL(uri);
      if (url == null)
        throw new XelException("Resource not found: "+uri);
    }

    load(prefix, url);
  }
View Full Code Here

  public void load(String prefix, Element root)
  throws XelException {
    if (prefix == null || root == null)
      throw new IllegalArgumentException("null");
    if (_mtds != null && _mtds.containsKey(prefix))
      throw new XelException("The prefix, "+prefix+", is already used");

    try {
      load0(prefix, Taglibs.load(root));
    } catch (Exception ex) {
      throw XelException.Aide.wrap(ex);
View Full Code Here

      //---
      //independent character evaluation (order not important)
      if (curChar == '"') {
        if (tkval.length() > 0) {
          //not expected
          throw new XelException("Syntax error at "+(offset-tkval.length())+". Unknow token: "+tkval);
/*          tokens.add(lastToken = new Token(tkval.toString(), TokenType.UNKNOWN, null));
          tkval = new StringBuffer(16);
          maybeIntersect = false;
*/        }
        inString = true;
        ++offset;
        continue;
      }
     
      if (curChar == '\'') {
        if (tkval.length() > 0) {
          //not expected
          throw new XelException("Syntax error at "+(offset-tkval.length())+". Unknow token: "+tkval);
/*          tokens.add(lastToken = new Token(tkval.toString(), TokenType.UNKNOWN, null));
          tkval = new StringBuffer(16);
          maybeIntersect = false;
*/        }
        inPath = true;
        ++offset;
        continue;
      }
     
      if (curChar == '[') {
        inRange = true;
        tkval.append(curChar);
        ++offset;
        continue;
      }
     
      if (curChar == '#') {
        if (tkval.length() > 0) {
          //not expected
          throw new XelException("Syntax error at "+(offset-tkval.length())+". Unknow token: "+tkval);
/*          tokens.add(lastToken = new Token(tkval.toString(), TokenType.UNKNOWN, null));
          tkval = new StringBuffer(16);
          maybeIntersect = false;
*/        }
        inError = true;
        tkval.append(curChar);
        ++offset;
        continue;
      }
       
        // mark start and end of arrays and array rows
      if (curChar == '{') {
        if (tkval.length() > 0) {
          //not expected
          throw new XelException("Syntax error at "+(offset-tkval.length())+". Unknow token: "+tkval);
/*          tokens.add(new Token(tkval.toString(), TokenType.UNKNOWN, null));
          tkval = new StringBuffer(16);
          maybeIntersect = false;
*/        }
        if (maybeIntersect) {
          tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
        }
        tokens.add(new Token("ARRAY", TokenType.FUNCTION, TokenSubtype.START));
        tokenStack.push(new Token("", TokenType.FUNCTION, TokenSubtype.STOP));

        tokens.add(lastToken = new Token("ARRAYROW", TokenType.FUNCTION, TokenSubtype.START));
        tokenStack.push(new Token("", TokenType.FUNCTION, TokenSubtype.STOP));
        maybeIntersect = false;
       
        ++offset;
        continue;
      }
     
      if (curChar == ';') {
        if (tkval.length() > 0) {
          if (maybeIntersect) {
            tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
          }
          final String val = tkval.toString();
          tokens.add(lastToken = newOperandToken(val));
          tkval = new StringBuffer(16);
        }
        tokens.add(tokenStack.pop());
        tokens.add(new Token(",", TokenType.ARGUMENT, null));
        tokens.add(lastToken = new Token("ARRAYROW", TokenType.FUNCTION, TokenSubtype.START));
        tokenStack.push(new Token("", TokenType.FUNCTION, TokenSubtype.STOP));
        maybeIntersect = false;
       
        ++offset;
        continue;
      }
     
      if (curChar == '}') {
        if (tkval.length() > 0) {
          if (maybeIntersect) {
            tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
          }
          final String val = tkval.toString();
          tokens.add(lastToken = newOperandToken(val));
          tkval = new StringBuffer(16);
        }
        tokens.add(tokenStack.pop());
        tokens.add(lastToken = (Token) tokenStack.pop());
        maybeIntersect = false;
       
        ++offset;
        continue;
      }
     
      //trim white space
      if (curChar == ' ') {
        if (tkval.length() > 0) {
          if (maybeIntersect) {
            tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
          }
          final String val = tkval.toString();
          tokens.add(lastToken = newOperandToken(val));
          tkval = new StringBuffer(16);
          maybeIntersect = false;
        }
        if (lastToken != null) {
          TokenType prevType = lastToken.getType();
          TokenSubtype prevSubtype = lastToken.getSubtype();
         
          if ((prevType == TokenType.FUNCTION && prevSubtype == TokenSubtype.STOP)
          || (prevType == TokenType.SUBEXPR && prevSubtype == TokenSubtype.STOP)
          || prevType == TokenType.OPERAND) {
            maybeIntersect = true;
          }
        }

        ++offset;
       
        while ((formula.charAt(offset) == ' ') && (offset < sz)) {
          ++offset;
        }
        continue;
      }
     
      //multi-charcter comparators
      if (offset < (sz - 1)) {
        final String dbChars = formula.substring(offset, offset + 2);
        if (MULTICOMP_PATTERN.indexOf("," + dbChars + ",") >= 0) {
          if (tkval.length() > 0) {
            if (maybeIntersect) {
              tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
            }
            final String val = tkval.toString();
            tokens.add(lastToken = newOperandToken(val));
            tkval = new StringBuffer(16);
          }
          tokens.add(lastToken = new Token(dbChars, TokenType.OP_IN, TokenSubtype.LOGICAL));
          maybeIntersect = false;
         
          offset += 2;
          continue;
        }
      }
     
      //standard infix operators
      if (INFIX_PATTERN.indexOf(curChar) >= 0) {
        if (tkval.length() > 0) {
          if (maybeIntersect) {
            tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
          }
          final String val = tkval.toString();
          tokens.add(lastToken = newOperandToken(val));
          tkval = new StringBuffer(16);
        }
        if (curChar == '-') {
          if (lastToken != null) {
            final TokenType prevType = lastToken.getType();
            final TokenSubtype prevSubtype = lastToken.getSubtype();
            if ((prevType == TokenType.FUNCTION && prevSubtype == TokenSubtype.STOP)
            || (prevType == TokenType.SUBEXPR && prevSubtype == TokenSubtype.STOP)
            || prevType == TokenType.OP_POST
            || prevType == TokenType.OPERAND) {
              tokens.add(lastToken = new Token("-", TokenType.OP_IN, TokenSubtype.MATH));
            } else {
              tokens.add(lastToken = new Token("-", TokenType.OP_PRE, null));
            }
          } else {
            tokens.add(lastToken = new Token("-", TokenType.OP_PRE, null));
          }
        } else if (curChar == '+') {
          if (lastToken != null) {
            final TokenType prevType = lastToken.getType();
            final TokenSubtype prevSubtype = lastToken.getSubtype();
            if ((prevType == TokenType.FUNCTION && prevSubtype == TokenSubtype.STOP)
            || (prevType == TokenType.SUBEXPR && prevSubtype == TokenSubtype.STOP)
            || prevType == TokenType.OP_POST
            || prevType == TokenType.OPERAND) {
              tokens.add(lastToken = new Token("+", TokenType.OP_IN, TokenSubtype.MATH));
            } //else ignore it!
          } //else ignore it!
        } else if (curChar == '=' || curChar == '>' || curChar == '<') {
          tokens.add(lastToken = new Token(""+curChar, TokenType.OP_IN, TokenSubtype.LOGICAL));
        } else if (curChar == '&') {
          tokens.add(lastToken = new Token(""+curChar, TokenType.OP_IN, TokenSubtype.CONCAT));
        } else {
          tokens.add(lastToken = new Token(""+curChar, TokenType.OP_IN, TokenSubtype.MATH));
        }
        maybeIntersect = false;
       
        ++offset;
        continue;
      }
     
      //standard postfix operators
      if (curChar == '%') {
        if (tkval.length() > 0) {
          if (maybeIntersect) {
            tokens.add(lastToken = new Token(" ", TokenType.OP_IN, TokenSubtype.INTERSECT));
          }
          final String val = tkval.toString();
          tokens.add(lastToken = newOperandToken(val));
          tkval = new StringBuffer(16);
        }
        tokens.add(lastToken = new Token(""+curChar, TokenType.OP_POST, null));
        maybeIntersect = false;
       
        ++offset;
        continue;
      }
     
      //start subexpression or function
      if (curChar == '(') {
        if (tkval.length() > 0) {
          if (tkval.charAt(0) == '@') { //pull "@" from in front of function names
            if (tkval.length() == 1) {
              throw new XelException("Syntax error at "+(offset-tkval.length())+". Unknow token: "+tkval);
/*              tokens.add(lastToken = new Token(tkval.toString(), TokenType.UNKNOWN, null));
              tkval = new StringBuffer(16);
              maybeIntersect = false;
              continue;
*/            } else {
View Full Code Here

          if (sheet1 == null) {
            sheet1 = token.toString();
            token = new StringBuffer(16);
          } else if (cell1 == null){
            if (!haveSheet) {
              throw new XelException("Incorrect Range expression. ':' appear more than once: "+range);
            }
            cell1 = token.toString();
            token = new StringBuffer(16);
          } else {
            throw new XelException("Incorrect Range expression. ':' appear more than once: "+range);
          }
        } else {
          throw new XelException("Incorrect Range expression. No definition before ':': "+range);
        }
      } else if (ch == '!') { //previous is sheet as expected
        if (haveSheet) {
          throw new XelException("Incorrect Range expression. '!' appear more than once: "+range);
        }
        haveSheet = true;
        if (token.length() > 0) {
          if (sheet1 == null) { //only one sheet
            sheet1 = token.toString();
            token = new StringBuffer(16);
          } else if (sheet2 == null) {
            sheet2 = token.toString();
            if (sheet2.equals(sheet1)) {
              sheet2 = null;
            }
            token = new StringBuffer(16);
          } else { //neither is null, something wrong
            throw new XelException("Incorrect Range expression. '!' appear more than once: "+range);
          }
        } else {
          throw new XelException("Incorrect Range expression. No sheet name before '!': "+range);
        }
      } else {
        token.append(ch);
      }
    }
    if (token.length() > 0) {
      cell2 = token.toString();
    } else {
      throw new XelException("Incorrect Range expression. no definition after '!' or ':': " + range);
    }
    if (cell1 == null) { //single cell case
      if (sheet1 == null || haveSheet) {
        cell1 = cell2;
        cell2 = null;
      } else {
        cell1 = sheet1;
        sheet1 = null;
      }
    }
    if (sheet1 != null && !haveSheet) {
      throw new XelException("Incorrect Range expression. ':' appear more than once: "+range);
    }
    return new String[] {sheet1, sheet2, cell1, cell2};
  }
View Full Code Here

      if (ch == '$') { //absolute reference?
        if (j == 0) {
          absCol = true;
        } else {
          if (mightVar) { //starts with '$', cannot be a variable, something wrong
            throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
          }
          absRow = true;
          inRow = true;
        }
      } else if (!inRow) {
        if (Character.isLetter(ch)) {
          colIndex = colIndex * 26 + (Character.toUpperCase(ch) - 'A' + 1);
          if (colIndex > colLimit()) { //exceed column limit, might be a variable
            if (absCol) { //starts with '$', cannot be variable, something wrong
              throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
            } else {
              mightVar = true; //row expression can be invalid
            }
          }
        } else if (Character.isDigit(ch)) {
          inRow = true;
          rowIndex = ch - '0';
          if (rowIndex == 0) { //might be a variable
            if (absCol || colIndex == 0) { //starts with '$' or starts with digit, cannot be a variable
              throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
            } else {
              return null; //a variable, return null
            }
          }
          if (colIndex == 0) { //no column part
            absRow = absCol;
            absCol = false;
          }
        } else if (!absCol && (ch == '_' || (ch == '.' && colIndex != 0))) {
          mightVar = true;
        } else {
          throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
        }
      } else if (Character.isDigit(ch)) {
        rowIndex = rowIndex * 10 + (ch - '0');
        if (rowIndex > rowLimit()) { //exceed 64K row limimt, must be a variable
          if (absRow || colIndex == 0) { //starts with '$', or no column part, cannot be variable, something wrong
            throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
          } else {
            return null;
          }
        }
      } else if (Character.isLetter(ch) || ch == '_' || ch == '.') { //inRow and a letter, '_', or '.', is a variable
        return null;
      } else {
        throw new XelException("Incorrect Cell expression. Incorrect variable name:" + cell);
      }
    }
    return mightVar ? null :
      new int[] {colIndex - 1, rowIndex - 1,
        (absCol || colIndex == 0) ? 1 : 0, (absRow || rowIndex == 0) ? 1 : 0};
View Full Code Here

        operands.subList(fromIndex, sz).clear();
      } else {
        operands.pop(); //no arguments function, pop the ARGUMENT_END
      }
    } else {
      throw new XelException("Unknown operator token: "+ op);
    }
    operands.push(op);
  }
View Full Code Here

              ranges.add(rng);
              operand.addOperand(new Token(rng, TokenType.OPERAND, TokenSubtype.RANGE));
            } else {
              operand.addOperand(new Token(cell1, TokenType.OPERAND, TokenSubtype.VAR));
              if (!((BookImpl)book).addVariable(cell1, orgref)) {
                throw new XelException("Illegal variable name: "+cell1);
              }
            }
          } else {
            final Token token1 =
              new Token(cell1, TokenType.OPERAND, TokenSubtype.CELL);
            //TODO: matain ref DAG graph
            //TODO: How do we handle variable range2d?
//            final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//            final Abacus pabacus = psheet.getBook().getAbacus();
            final int left = lt[0];
            final int top = lt[1];
            final int right = left;
            final int bottom = top;
            final boolean absleft = lt[2] != 0;
            final boolean abstop = lt[3] != 0;
            final boolean absright = absleft;
            final boolean absbottom = abstop;
            final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
              new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
              orgref.addPrecedent(precedent);
            }
*/            token1.setValue(rng);
            operand.addOperand(token1);
          }
         
          if (var2) {
            //lookup NameRange
            final Range rng = book.lookupNameRange(cell2);
            if (rng != null) {
              ranges.add(rng);
              operand.addOperand(new Token(rng, TokenType.OPERAND, TokenSubtype.RANGE));
            } else {
              operand.addOperand(new Token(cell2, TokenType.OPERAND, TokenSubtype.VAR));
              if (!((BookImpl)book).addVariable(cell2, orgref)) {
                throw new XelException("Illegal variable name: "+cell2);
              }
            }
          } else {
            final Token token2 =
              new Token(cell2, TokenType.OPERAND, TokenSubtype.CELL);
            //TODO: matain ref DAG graph
            //TODO: How do we handle variable range2d?
//            final SheetImpl psheet = sheet2 != null ? sheet2 : sheet;
//            final Abacus pabacus = psheet.getBook().getAbacus();
            final int left = rb[0];
            final int top = rb[1];
            final int right = left;
            final int bottom = top;
            final boolean absleft = rb[2] != 0;
            final boolean abstop = rb[3] != 0;
            final boolean absright = absleft;
            final boolean absbottom = abstop;
            final Range rng =
              new RangeRef(psheet2, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
              orgref.addPrecedent(precedent);
            }
*/            token2.setValue(rng);
            operand.addOperand(token2);
          }
        } else { //a const cell or a const range
          if (sheetnm1 == null || (sheetnm2 == null || sheetnm1.equals(sheetnm2))) { //single sheet
            if (cell1.equals(cell2)) { //a cell reference
              if (lt[0] == -1 || lt[1] == -1) { //single row || single column
//                final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//                final Abacus pabacus = psheet.getBook().getAbacus();
                final int left = lt[0];
                final int top = lt[1];
                final int right = rb[0];
                final int bottom = rb[1];
                final boolean absleft = lt[2] != 0;
                final boolean abstop = lt[3] != 0;
                final boolean absright = rb[2] != 0;
                final boolean absbottom = rb[3] != 0;
                final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                  new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
                ranges.add(rng);
/*                if (orgref != null) {
                  final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                  orgref.addPrecedent(precedent);
                }
*/                operand.setValue(rng);
              } else { //degrad to single cell
                operand.setSubtype(TokenSubtype.CELL);
                //TODO: maintain DAG reference
//                final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//                final Abacus pabacus = psheet.getBook().getAbacus();
                final int left = lt[0];
                final int top = lt[1];
                final int right = left;
                final int bottom = top;
                final boolean absleft = lt[2] != 0;
                final boolean abstop = lt[3] != 0;
                final boolean absright = absleft;
                final boolean absbottom = abstop;
                final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                  new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
                ranges.add(rng);
/*                if (orgref != null) {
                  final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                  orgref.addPrecedent(precedent);
                }
*/                operand.setValue(rng);
              }
            } else { //a range reference
              //TODO: maintain DAG reference
//              final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//              final Abacus pabacus = psheet.getBook().getAbacus();
              final int left = lt[0];
              final int top = lt[1];
              final int right = rb[0];
              final int bottom = rb[1];
              final boolean absleft = lt[2] != 0;
              final boolean abstop = lt[3] != 0;
              final boolean absright = rb[2] != 0;
              final boolean absbottom = rb[3] != 0;
              final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
              ranges.add(rng);
/*              if (orgref != null) {
                final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                orgref.addPrecedent((Reference)precedent);
              }
*/              operand.setValue(rng);
            }
          } else { //range 3d
            //TODO: maintain DAG reference
            //TODO: for each sheet between two sheet name
            final int left = lt[0];
            final int top = lt[1];
            final int right = rb[0];
            final int bottom = rb[1];
            final boolean absleft = lt[2] != 0;
            final boolean abstop = lt[3] != 0;
            final boolean absright = rb[2] != 0;
            final boolean absbottom = rb[3] != 0;
            final Range rng = (psheet1 == null || psheet2 == null) ? RangeRefError.RANGE_REF_ERROR :
              new RangeRef(psheet1, psheet2, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Book pbook = sheet1.getBook();
              final int from = pbook.indexOfSheet(sheet1);
              final int to = pbook.indexOfSheet(sheet2);
              final Abacus pabacus = pbook.getAbacus();
              final List sheets = book.getSheets();
              for (int j=from; j <= to; ++j) {
                final SheetImpl psheet = (SheetImpl) sheets.get(j);
                final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                orgref.addPrecedent((Reference)precedent);
              }
            }
*/            operand.setValue(rng);
          }
        }
      } else if (var1) { //single variable
        //lookup NameRange
        final Range rng = book.lookupNameRange(cell1);
        if (rng != null) {
          ranges.add(rng);
          operand.setValue(rng);
        } else {
          operand.setSubtype(TokenSubtype.VAR);
          if (!((BookImpl)book).addVariable(cell1, orgref)) {
            throw new XelException("Illegal variable name: "+cell1);
          }
        }
      } else {//single cell
        operand.setSubtype(TokenSubtype.CELL);
        //TODO: maintain DAG reference
View Full Code Here

TOP

Related Classes of org.zkoss.xel.XelException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.