Package org.zkoss.zss.model

Examples of org.zkoss.zss.model.ModelException


   * @return The added Sheet.
   */
  public Sheet addSheet(String name, int colSize, int rowSize) {
    final SheetImpl sheet = new SheetImpl(this, name, colSize, rowSize);
    if (_sheetMap.containsKey(name)) {
      throw new ModelException("Duplicated sheet name: "+name);
    }
    _sheetMap.put(name, sheet);
    _sheetidMap.put(sheet.getId(), sheet);
    _sheets.add(sheet);
   
View Full Code Here


  private void validateCorner(int left, int top, int right, int bottom, Collection refs) {
    for (final Iterator it = refs.iterator(); it.hasNext();) {
      final Reference ref = (Reference) it.next();
      if (left > ref.getLeft() || right < ref.getRight()
          || top > ref.getTop() || bottom < ref.getBottom()) {
        throw new ModelException("Cannot change part of a merged cell");
      }
    }
  }
View Full Code Here

      ctx.resetForNextSection();
      break;

    case '*':
      if (ctx.aRepeat == true) { // ever repeat
        throw new ModelException(
            "Only one repeat is allowed. Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
      } else {
        ctx.aRepeat = true; // set ever repeat
        ctx.state = STATE_TEXT_REPEAT;
      }
      break;

    case '_':
      ctx.state = STATE_TEXT_SKIP;
      break;

    case '^':
      if (j == 0) {
        ctx.aControl = true;// might be aControl
      } else {
        ctx.state = STATE_TEXT;
      }
      break;

    case '"':
      if (j == 1 && ctx.aControl) {
        ctx.aControl = false;
        ctx.state = STATE_CONTROL;
      } else {
        ctx.aString = true;
        ctx.state = STATE_TEXT;
      }
      break;

    case '\\':
      ctx.state = STATE_TEXT;
      ctx.anEscape = true;
      break;

    case '/':
      if (ctx.aSlash == 1) { // ever ?
        final FormatToken fmtToken = new FormatToken(
            FormatToken.TEXT_SLASH, "" + ch);
        ctx.fmtSection.addToken(fmtToken);
        ctx.token = new StringBuffer(32);
        ctx.state = STATE_UNKNOWN;
        ctx.aSlash = 2;
      } else if (ctx.aSlash == 2) {// ever text_slash
        throw new ModelException(
            "Only one slash is alloweed. Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
      } else {
        appendChar(ctx, ch);
        ctx.state = STATE_TEXT;
      }
      break;

    case '$':
    case '-':
    case '+':
    case '(':
    case ')':
    case ':':
    case ' ':
    case '!':
    case '&':
    case '\'':
    case '~':
    case '{':
    case '}':
    case '=':
    case '<':
    case '>':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      appendChar(ctx, ch);
      if (ch >= '1' && ch <= '9' && ctx.aSlash == 2) {
        ctx.state = STATE_TEXT_NUMBER;
      } else {
        ctx.state = STATE_TEXT;
      }
      break;
    default:
      throw new ModelException("Incorrect format at " + j + ", charcter "
          + ch + " in \"" + format + "\"");
    }
  }
View Full Code Here

      case 'E':
      case '-':
      case '+':
        if (ctx.aScience > 0) {
          if (ch != '+' && ch != '-') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          } else {
            ctx.aScience = -1;
          }
        } else if (ctx.aScience < 0) {
          if (ch == 'E' || ch == 'e') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          }
        } else if (ch == 'E' || ch == 'e') {
          ctx.aScience = 1;
          ctx.aNumberDot = false;
        } else if (ctx.aNumberDot) {
          if (ch == '0' || ch == '#') {
            ++ctx.scale;
          }
        } else if (ch == '.' && ctx.aScience < 1) {
          ctx.aNumberDot = true;
        }
        appendChar(ctx, ch);
        break;

      default:
        if (ch == '?') {
          if (ctx.aScience > 0) {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          }
          if (ctx.aSlash == 0) {
            ctx.aSlash = 1;
          }
          appendChar(ctx, ch);
        } else {
          addToken(FormatToken.NUMBER, ctx.token.toString(), -1, ctx);
          ctx.aScience = 0;
          ctx.aNumberSpace = false;
          ctx.aNumberDot = false;
          dispatchState(format, ch, j, ctx);
        }
        break;
      }
      break;

    case STATE_DATE:
      switch (ch) {
      case 'm':
      case 'd':
      case 'y':
        appendChar(ctx, ch);
        break;
      default:
        if (ch == 's') {
          final StringBuffer tmp = new StringBuffer(32);
          final int index = ctx.token.length();
          int k = index - 1;
          for (; k >= 0; --k) {
            final char prech = ctx.token.charAt(k);
            if (prech != 'm') {
              break;
            }
            tmp.append('m');
          }

          final int mlength = tmp.length();
          if (mlength > 0 && mlength < 3) { // s after m, change to
                            // minute
            if (mlength < index) { // partial replace
              final FormatToken fmtToken = new FormatToken(
                  FormatToken.DATE, ctx.token.substring(0,
                      k + 1).toString());
              ctx.fmtSection.addToken(fmtToken);
            }
            ctx.token = tmp;
            ctx.aM = 0;
            ctx.state = STATE_TIME;
            appendChar(ctx, ch);
            break;
          }
        }
        addToken(FormatToken.DATE, ctx.token.toString(), -1, ctx);
        ctx.aM = 0;
        dispatchState(format, ch, j, ctx);
        break;
      }
      break;

    case STATE_TIME:
      switch (ch) {
      case 'h':
      case 's':
      case 'a':
      case 'A':
      case 'p':
      case 'P':
      case 'm':
      case 'M':
      case '/':
        if (ctx.anAm == 4) {
          if (ch != 'm' && ch != 'M') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          } else {
            ch = 'M';
            ctx.anAm = 0;
          }
        } else if (ctx.anAm == 3) {
          if (ch != 'p' && ch != 'P') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          } else {
            ch = 'P';
            ctx.anAm = 4;
          }
        } else if (ctx.anAm == 2) {
          if (ch != '/') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          } else {
            ctx.anAm = 3;
          }
        } else if (ctx.anAm == 1) {
          if (ch != 'm' && ch != 'M') {
            throw new ModelException("Incorrect format at " + j
                + ", charcter " + ch + " in \"" + format + "\"");
          } else {
            ch = 'M';
            ctx.anAm = 2;
          }
        } else {
          if (ch == 'A' || ch == 'a') {
            ch = 'A';
            ctx.anAm = 1;
          } else if (ch == 'm') {
            ctx.aTime = false;
            ++ctx.aM;
            if (ctx.aM >= 3) { // mmm, must be a month
              ctx.state = STATE_DATE;
            }
          }
        }
        appendChar(ctx, ch);
        break;
      default:
        addToken(FormatToken.TIME, ctx.token.toString(), -1, ctx);
        dispatchState(format, ch, j, ctx);
        break;
      }
      break;

    case STATE_MILLISECOND:
      if (ch == '0') {
        ++ctx.milliSecond;
      } else {
        addToken(FormatToken.TIME_MILLISECOND, "" + ctx.milliSecond,
            -1, ctx);
        dispatchState(format, ch, j, ctx);
      }
      break;

    case STATE_MISC_DROP:
      //until ch == ']'
      if (ch == ']') {
        ctx.state = STATE_UNKNOWN;
      }
      break;
     
    case STATE_MISC:
      //try to locate [$-Xxx] pattern
      if (ctx.misc_count == 1) {
        if (ch == '$') {
          ctx.misc_count = 2;
          break;
        } else {
          ctx.misc_count = 0;
        }
      } else if (ctx.misc_count == 2) {
        if (ch == '-') {
          ctx.state = STATE_MISC_DROP;
          ctx.misc_count = 0;
          break;
        } else {
          appendChar(ctx, '$');
          ctx.misc_count = 0;
        }
      }
      switch (ch) {
      case '<':
      case '>':
      case '=':
        ctx.state = STATE_MISC_CONDITION;
        appendChar(ctx, ch);
        break;

      case 'b':
      case 'B':
      case 'c':
      case 'C':
      case 'g':
      case 'G':
      case 'M':
      case 'r':
      case 'R':
      case 'w':
      case 'W':
      case 'y':
      case 'Y':
        ctx.state = STATE_MISC_COLOR;
        appendChar(ctx, ch);
        break;

      case 'h':
      case 's':
        ctx.state = STATE_MISC_TIME;
        appendChar(ctx, ch);
        break;

      case 'm':
        if (!ctx.aMagenta) {
          ctx.aMagenta = true;
        } else {
          ctx.aMagenta = false;
          ctx.state = STATE_MISC_TIME;
        }
        appendChar(ctx, ch);
        break;

      default:
        if (ctx.aMagenta) {
          ctx.aMagenta = false;
          if (ch == ']') {
            ctx.state = STATE_MISC_TIME;
            parseChar(format, ch, j, ctx); // recursive
          } else if (ch == 'a' || ch == 'A') {
            ctx.state = STATE_MISC_COLOR;
            appendChar(ctx, ch);
          }
          break;
        }
        throw new ModelException("Incorrect format at " + j
            + ", charcter " + ch + " in \"" + format + "\"");
      }
      break;

    case STATE_MISC_CONDITION:
      if (ch == ']') {
        if (ctx.token.length() < 2) {
          throw new ModelException("Incorrect condition format at "
              + j + " in \"" + format + "\"");
        }
        final char ch1 = ctx.token.charAt(0);
        final char ch2 = ctx.token.charAt(1);
        if (ch1 == '<' && ch2 == '>') { // <>
          addToken(FormatToken.CONDITION_NE, ctx.token.substring(2)
              .trim(), STATE_UNKNOWN, ctx);
        } else if (ch1 == '=') { // =
          addToken(FormatToken.CONDITION_EQ, ctx.token.substring(1)
              .trim(), STATE_UNKNOWN, ctx);
        } else if (ch1 == '<') { // <= or <
          if (ch2 == '=') {
            addToken(FormatToken.CONDITION_LE, ctx.token.substring(
                2).trim(), STATE_UNKNOWN, ctx);
          } else {
            addToken(FormatToken.CONDITION_LT, ctx.token.substring(
                1).trim(), STATE_UNKNOWN, ctx);
          }
        } else if (ch1 == '>') { // >= or >
          if (ch2 == '=') {
            addToken(FormatToken.CONDITION_GE, ctx.token.substring(
                2).trim(), STATE_UNKNOWN, ctx);
          } else {
            addToken(FormatToken.CONDITION_GT, ctx.token.substring(
                1).trim(), STATE_UNKNOWN, ctx);
          }
        } else {
          throw new ModelException("Incorrect condition format at "
              + j + " in \"" + format + "\"");
        }
      } else {
        appendChar(ctx, ch);
      }
      break;

    case STATE_MISC_COLOR:
      if (ch == ']') {
        String data = ctx.token.toString().trim();
        final String datau = data.toUpperCase();
        if (datau.startsWith("COLOR")) {
          final int colorIndex = Integer.parseInt(data.substring(5)
              .trim());
          if (colorIndex <= 0 || colorIndex >= 56) {
            throw new ModelException("Incorrect color index at "
                + j + ", index: " + colorIndex + " in \""
                + format + "\"");
          } else {
            data = PALETTE[colorIndex - 1];
          }
        } else {
          if (!NAME_PALETTE.containsKey(data.toUpperCase())) {
            throw new ModelException("Incorrect color format at "
                + j + ", color: " + data + " in \"" + format
                + "\"");
          } else {
            data = (String) NAME_PALETTE.get(datau);
          }
        }
        addToken(FormatToken.COLOR, "#" + data, STATE_UNKNOWN, ctx);
      } else {
        appendChar(ctx, ch);
      }
      break;

    case STATE_MISC_TIME:
      if (ctx.aTimePassed) { // allow only one aTimePassed
        throw new ModelException(
            "Only one [h], [m], or [s] is allowed. Incorrect format at "
                + j + ", charcter " + ch + " in \"" + format
                + "\"");
      } else {
        ctx.aTimePassed = true;
      }
      if (ch == ']') {
        int type = -1;
        final String data = ctx.token.toString();
        final char fch = data.charAt(0);
        switch (fch) {
        case 'h':
          type = FormatToken.TIME_HOUR_PASSED;
          break;
        case 'm':
          type = FormatToken.TIME_MINUTE_PASSED;
          break;
        case 's':
          type = FormatToken.TIME_SECOND_PASSED;
          break;
        default:
          throw new ModelException("Unknown TIME_PASSED formate: "
              + fch);
        }
        addToken(type, data, STATE_UNKNOWN, ctx);
      } else {
        if (ch != 'h' && ch != 'm' && ch != 's') {
          throw new ModelException("Incorrect format at " + j
              + ", charcter " + ch + " in \"" + format + "\"");
        } else {
          final int index = ctx.token.length() - 1;
          if (index >= 0) {
            final char prech = ctx.token.charAt(index);
            if (prech != ch) {
              throw new ModelException("Incorrect format at " + j
                  + ", charcter " + ch + " in \"" + format
                  + "\"");
            }
          }
          appendChar(ctx, ch);
        }
      }
      break;
    default:
      throw new ModelException("Unknown State: " + ctx.state);
    }
  }
View Full Code Here

       
      case FormatToken.CONTROL:
        return Format.TYPE_CONTROL;
       
      default:
        throw new ModelException(
            "Unknown format major type (General, Text, Number, Date, Control): "+type);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.zss.model.ModelException

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.