Java 类freemarker.template.utility.StringUtil 实例源码

项目:freemarker-support-for-netbeans    文件:FMParserWSTokenManager.java   
private TokenMgrError newNameConventionMismatchException(Token tok) {
    return new TokenMgrError(
            "Naming convention mismatch. "
            + "Identifiers that are part of the template language (not the user specified ones) "
            + (initialNamingConvention == Configuration.AUTO_DETECT_NAMING_CONVENTION
                ? "must consistently use the same naming convention within the same template. This template uses "
                : "must use the configured naming convention, which is the ")
            + (namingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION
                        ? "camel case naming convention (like: exampleName) "
                        : (namingConvention == Configuration.LEGACY_NAMING_CONVENTION
                                ? "legacy naming convention (directive (tag) names are like examplename, "
                                  + "everything else is like example_name) "
                                : "??? (internal error)"
                                ))
            + (namingConventionEstabilisher != null
                    ? "estabilished by auto-detection at "
                        + MessageUtil.formatPosition(
                                namingConventionEstabilisher.beginLine, namingConventionEstabilisher.beginColumn)
                        + " by token " + StringUtil.jQuote(namingConventionEstabilisher.image.trim())
                    : "")
            + ", but the problematic token, " + StringUtil.jQuote(tok.image.trim())
            + ", uses a different convention.",
            TokenMgrError.LEXICAL_ERROR,
            tok.beginLine, tok.beginColumn, tok.endLine, tok.endColumn);
}
项目:struts2    文件:FreemarkerManager.java   
public void addSetting(String name, String value) throws TemplateException {
    // Process all other init-params:
    if (name.equals(INITPARAM_NOCACHE)) {
        nocache = StringUtil.getYesNo(value);
    } else if (name.equals(INITPARAM_DEBUG)) {
        debug = StringUtil.getYesNo(value);
    } else if (name.equals(INITPARAM_CONTENT_TYPE)) {
        contentType = value;
    } else {
        config.setSetting(name, value);
    }

    if (contentType != null && !contentTypeEvaluated) {
        int i = contentType.toLowerCase().indexOf("charset=");
        contentTypeEvaluated = true;
        if (i != -1) {
            char c = ' ';
            i--;
            while (i >= 0) {
                c = contentType.charAt(i);
                if (!Character.isWhitespace(c)) break;
                i--;
            }
            if (i == -1 || c == ';') {
                noCharsetInContentType = false;
            }
        }
    }
}
项目:freemarker-support-for-netbeans    文件:FMParserWS.java   
final public StringLiteral StringLiteral(boolean interpolate) throws ParseException {
  Token t;
  boolean raw = false;
  switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  case STRING_LITERAL:
    t = jj_consume_token(STRING_LITERAL);
    break;
  case RAW_STRING:
    t = jj_consume_token(RAW_STRING);
                         raw = true;
    break;
  default:
    jj_la1[17] = jj_gen;
    jj_consume_token(-1);
    throw new ParseException();
  }
      String s = t.image;
      // Get rid of the quotes.
      s = s.substring(1, s.length() -1);
      if (raw) {
          s = s.substring(1);
      } else try {
          s = StringUtil.FTLStringLiteralDec(s);
      } catch (ParseException pe) {
          pe.lineNumber = t.beginLine;
          pe.columnNumber = t.beginColumn;
          pe.endLineNumber = t.endLine;
          pe.endColumnNumber = t.endColumn;
          {if (true) throw pe;}
      }
      StringLiteral result = new StringLiteral(s);
      result.setLocation(template, t, t);
      if (interpolate && !raw) {
          // TODO: This logic is broken. It can't handle literals that contains both ${...} and $\{...}. 
          if (t.image.indexOf("${") >= 0 || t.image.indexOf("#{") >= 0) result.parseValue(token_source);
      }
      {if (true) return result;}
  throw new Error("Missing return statement in function");
}
项目:freemarker-support-for-netbeans    文件:ParseException.java   
private String getCustomTokenErrorDescription() {
    final Token nextToken = currentToken.next;
    final int kind = nextToken.kind;
    if (kind == EOF) {
        Set/*<String>*/ endNames = new HashSet();
        for (int i = 0; i < expectedTokenSequences.length; i++) {
            int[] sequence = expectedTokenSequences[i];
            for (int j = 0; j < sequence.length; j++) {
                switch (sequence[j]) {
                case END_FOREACH:
                    endNames.add( "#foreach");
                    break;
                case END_LIST:
                    endNames.add( "#list");
                    break;
                case END_SWITCH:
                    endNames.add( "#switch");
                    break;
                case END_IF:
                    endNames.add( "#if");
                    break;
                case END_COMPRESS:
                    endNames.add( "#compress");
                    break;
                case END_MACRO:
                    endNames.add( "#macro");
                case END_FUNCTION:
                    endNames.add( "#function");
                    break;
                case END_TRANSFORM:
                    endNames.add( "#transform");
                    break;
                case END_ESCAPE:
                    endNames.add( "#escape");
                    break;
                case END_NOESCAPE:
                    endNames.add( "#noescape");
                    break;
                case END_ASSIGN:
                    endNames.add( "#assign");
                    break;
                case END_LOCAL:
                    endNames.add( "#local");
                    break;
                case END_GLOBAL:
                    endNames.add( "#global");
                    break;
                case END_ATTEMPT:
                    endNames.add( "#attempt");
                    break;
                case CLOSING_CURLY_BRACKET:
                    endNames.add( "\"{\"");
                    break;
                case CLOSE_BRACKET:
                    endNames.add( "\"[\"");
                    break;
                case CLOSE_PAREN:
                    endNames.add( "\"(\"");
                    break;
                case UNIFIED_CALL_END:
                    endNames.add( "@...");
                    break;
                }
            }
        }
        return "Unexpected end of file reached."
                + (endNames.size() == 0 ? "" : " You have an unclosed " + concatWithOrs(endNames) + ".");
    } else if (kind == END_IF || kind == ELSE_IF || kind == ELSE) {
        return "Unexpected directive, "
                + StringUtil.jQuote(nextToken)
                + ". Check whether you have a valid #if-#elseif-#else structure.";
    }
    return null;
}
项目:jmigration    文件:BatExporter.java   
public static String decToHex(int dec, int len){
    return StringUtil.leftPad(Integer.toHexString(dec).toUpperCase(Locale.ENGLISH), len, "0");
}
项目:Cherry    文件:FreeMarkerService.java   
public void process(final String name, final TemplateModel model, final Locale locale, final Writer writer) throws IOException {
  debug("Requested template : [{}]", StringUtil.jQuoteNoXSS(name));

  final Template template = getTemplate(name, locale);

  process(template, model, writer);
}
项目:Cherry    文件:FreeMarkerService.java   
public void process(final String name, final TemplateModel model, final Writer writer) throws IOException {
  debug("Requested template : [{}]", StringUtil.jQuoteNoXSS(name));

  final Template template = getTemplate(name);

  process(template, model, writer);
}