Ejemplo n.º 1
0
  private void checkBodyEnd(String endTag, Map replaces) {
    int index = test.length() - endTag.length();
    if (index >= 0) {
      test = test.substring(index);
      if (test.equalsIgnoreCase(endTag)) {
        if (index > 0) {

          buf.setLength(index);
          String temp = buf.toString();
          if (replaces != null) temp = StringUtils.replaceStrings(temp, replaces);

          unitList.add(new ParseUnit(temp, mode));
        }
        mode = NORMAL;
      } else {
        test = null;
      }
    } else {
      test = null;
    }
  }
Ejemplo n.º 2
0
  private void parseStream(BufferedReader in, Map replaces) throws IOException {
    int c;
    ParseUnit unit;

    unitList.clear();
    mode = NORMAL;
    buf = new StringBuffer();

    c = in.read();
    while (c >= 0) {
      switch (c) {
        case '<':
          if (mode == NORMAL && buf.length() > 0) {
            test = buf.toString();
            if (test.startsWith("<!--")) {
              mode = COMMENT;
            } else if (test.startsWith("<%--")) {
              mode = JSP_COMMENT;
            } else if (test.startsWith("<%")) {
              mode = JSP;
            } else {
              if (replaces != null) test = StringUtils.replaceStrings(test, replaces);
              // test = StringUtils.stripEnterSymbol(test);
              unitList.add(new ParseUnit(test, mode));
              buf.setLength(0);
            }
          }
          buf.append((char) c);
          break;
        case '>':
          buf.append((char) c);
          test = buf.toString();
          if (mode == NORMAL) {
            if (test.startsWith("<!--")) {
              mode = COMMENT;
            } else if (test.startsWith("<%--")) {
              mode = JSP_COMMENT;
            } else if (test.startsWith("<%")) {
              mode = JSP;
            }
          }
          switch (mode) {
            case COMMENT:
              if (!test.endsWith("-->")) {
                test = null;
              }
              break;
            case JSP_COMMENT:
              if (!test.endsWith("--%>")) {
                test = null;
              }
              break;
            case JSP:
              if (!test.endsWith("%>")) {
                test = null;
              }
              break;
            case SCRIPT_BODY:
              checkBodyEnd("</SCRIPT>", replaces);
              break;
            case STYLE_BODY:
              checkBodyEnd("</STYLE>", replaces);
              break;
          }

          if (test != null) {
            //
            if (replaces != null) test = StringUtils.replaceStrings(test, replaces);

            unit = new ParseUnit(test, mode);
            unitList.add(unit);
            buf.setLength(0);
            mode = NORMAL;
            if (unit.isStartTag()) {
              test = unit.getTagName();
              if (test.equals("script")) {
                mode = SCRIPT_BODY;
              } else if (test.equals("style")) {
                mode = STYLE_BODY;
              }
            }
          }
          break;
        default:
          buf.append((char) c);
      }
      c = in.read();
    }
    if (buf.length() > 0) {
      String temp = buf.toString();
      if (replaces != null) temp = StringUtils.replaceStrings(temp, replaces);

      unitList.add(new ParseUnit(temp, mode));
    }
    units = new ParseUnit[unitList.size()];
    unitList.toArray(units);
  }