Exemplo n.º 1
0
 protected String subparseTemplate1(String variable, int variableValue)
     throws PreprocessException {
   HashMap<String, String> subdata = new HashMap<String, String>();
   subdata.putAll(data);
   subdata.put(variable, "" + variableValue);
   MainMetaBlock block = new MainMetaBlock(template, subdata);
   return block.parseTemplate();
 }
Exemplo n.º 2
0
  protected String subparseTemplate2(String variable, String value) throws PreprocessException {
    // String subtemplate = template.replaceAll(variable, value);

    String subtemplate = new String(template);
    for (int i = 0; i < subtemplate.length() - SYMBOL_LENGTH; i++) {
      if (subtemplate.substring(i, i + SYMBOL_LENGTH).equals(SYMBOL_OPEN)) {
        // found BLOCK_OPEN
        int start = i;
        // look for close
        int j = i + SYMBOL_LENGTH;
        boolean foundClose = false;
        while (j < subtemplate.length() - SYMBOL_LENGTH + 1) {
          if (subtemplate.substring(j, j + SYMBOL_LENGTH).equals(SYMBOL_CLOSE)) {
            foundClose = true;
            break;
          }
          j++;
        }
        if (!foundClose) {
          throw new PreprocessException(start);
        }
        // found BLOCK_CLOSE at j
        int end = j + SYMBOL_LENGTH;

        String foundVariable =
            subtemplate.substring(start + SYMBOL_LENGTH, end - SYMBOL_LENGTH).trim();
        if (foundVariable.startsWith(variable))
          subtemplate =
              subtemplate.substring(0, start)
                  + SYMBOL_OPEN
                  + " "
                  + foundVariable.replaceAll(variable, value)
                  + " "
                  + SYMBOL_CLOSE
                  + subtemplate.substring(end);
      }
    }
    MainMetaBlock block = new MainMetaBlock(subtemplate, data);
    return block.parseTemplate();
  }