Java Code Examples for org.rapidoid.u.U#frmt()
The following examples show how to use
org.rapidoid.u.U#frmt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractHttpHandler.java From rapidoid with Apache License 2.0 | 6 votes |
protected String contentTypeInfo(String inside) { String type; if (contentType == MediaType.HTML_UTF_8) { type = options.mvc() ? "mvc" : "html"; } else if (contentType == MediaType.JSON) { type = "json"; } else if (contentType == MediaType.PLAIN_TEXT_UTF_8) { type = "plain"; } else if (contentType == MediaType.BINARY) { type = "binary"; } else { return inside; } return U.frmt("%s(%s)", type, inside); }
Example 2
Source File: PathPattern.java From rapidoid with Apache License 2.0 | 6 votes |
public static PathPattern from(String path) { final Map<String, String> groups = U.map(); final AtomicInteger counter = new AtomicInteger(); String regex = Str.replace(path, PATH_PARAM_REGEX, gr -> toPathParamRegex(groups, counter, gr[1])); if (regex.equals("/*")) { regex = "/" + toPathParamRegex(groups, counter, ANY, ".*"); } else if (regex.endsWith("/*")) { regex = Str.trimr(regex, "/*"); regex += U.frmt("(?:/%s)?", toPathParamRegex(groups, counter, ANY, ".*")); } Pattern pattern = Pattern.compile(regex); return new PathPattern(path, pattern, groups); }
Example 3
Source File: ConfigHelp.java From rapidoid with Apache License 2.0 | 5 votes |
private static void showOpts(List<ConfigOption> opts) { for (ConfigOption opt : opts) { Object def = opt.getDefaultValue(); String desc = opt.getDesc(); if (def != null) { desc = U.frmt("%s (default: %s)", desc, def); } opt(opt.getName(), desc); } }
Example 4
Source File: ConfigLoaderUtil.java From rapidoid with Apache License 2.0 | 5 votes |
static void loadBuiltInConfig(Config config, List<String> loaded) { String nameBase = config.getFilenameBase(); if (U.notEmpty(nameBase)) { ConfigUtil.load("built-in-config.yml", config, loaded); for (String profile : Env.profiles()) { String filename = U.frmt("built-in-config-%s.yml", profile); ConfigUtil.load(filename, config, loaded); } } }
Example 5
Source File: Grid.java From rapidoid with Apache License 2.0 | 5 votes |
protected String onClickScript(Item item) { String uri; if (toUri != null) { uri = Lmbd.eval(toUri, item.value()); } else { uri = GUI.uriFor(item.value()); if (U.notEmpty(uri)) { uri = Msc.uri(uri, "view"); } } return U.notEmpty(uri) ? U.frmt("Rapidoid.goAt('%s');", uri) : null; }
Example 6
Source File: TemplateCompiler.java From rapidoid with Apache License 2.0 | 5 votes |
private static void addConstants(Map<String, String> constants, CtClass cls) throws CannotCompileException { for (Map.Entry<String, String> expr : constants.entrySet()) { String fld = "private static final %s = (%s);"; String field = U.frmt(fld, expr.getKey(), expr.getValue()); cls.addField(CtField.make(field, cls)); } }
Example 7
Source File: TemplateToCode.java From rapidoid with Apache License 2.0 | 5 votes |
public static String generate(XNode x, Map<String, String> expressions, Map<String, String> constants, Class<?> modelType) { String body; switch (x.op) { case OP_ROOT: return "{" + join("", x.children, expressions, constants, modelType) + "}"; case OP_TEXT: return U.notEmpty(x.text) ? print(literal(x.text), constants) : ""; case OP_PRINT: return val(x.text, true, expressions); case OP_PRINT_RAW: return val(x.text, false, expressions); case OP_IF_NOT: body = join("", x.children, expressions, constants, modelType); return U.frmt("if (!$1.cond(%s)) { %s }", literal(x.text), body); case OP_IF: body = join("", x.children, expressions, constants, modelType); return U.frmt("if ($1.cond(%s)) { %s }", literal(x.text), body); case OP_INCLUDE: return U.frmt("$1.call(%s);", literal(x.text)); case OP_FOREACH: body = join("", x.children, expressions, constants, modelType); String retrId = expr(expressions, x.text); return iterList(body, retrId); default: throw Err.notExpected(); } }
Example 8
Source File: TemplateToCode.java From rapidoid with Apache License 2.0 | 5 votes |
private static String iterList(String body, String retrId) { String list = "v" + ID_GEN.incrementAndGet(); String ind = "v" + ID_GEN.incrementAndGet(); String code = "java.util.List %s = $1.iter(%s);" + " for (int %s = 0; %s < %s.size(); %s++) {\n" + " %s\n }"; return U.frmt(code, list, retrId, ind, ind, list, ind, scopedList(ind, list, body)); }
Example 9
Source File: TemplateToCode.java From rapidoid with Apache License 2.0 | 5 votes |
private static String iterArr(String body, String retrId) { String arr = "v" + ID_GEN.incrementAndGet(); String ind = "v" + ID_GEN.incrementAndGet(); String code = "Object[] %s = $1.iter(%s);" + " for (int %s = 0; %s < %s.length; %s++) {\n" + " %s\n }"; return U.frmt(code, arr, retrId, ind, ind, arr, ind, scopedArr(ind, arr, body)); }
Example 10
Source File: GUI.java From rapidoid with Apache License 2.0 | 5 votes |
public static Tag media(Object left, Object title, Object body, String targetUrl) { Tag mhead = h4(title).class_("media-heading"); Tag mleft = div(left).class_("media-left"); Tag mbody = div(mhead, body).class_("media-body"); String divClass = targetUrl != null ? "media pointer" : "media"; String js = targetUrl != null ? U.frmt("goAt('%s');", targetUrl) : null; return div(mleft, mbody).class_(divClass).onclick(js); }
Example 11
Source File: RespBodyBuffer.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public String toString() { return U.frmt("RespBodyBuffer(%s bytes)", length()); }
Example 12
Source File: RapidoidInfo.java From rapidoid with Apache License 2.0 | 4 votes |
public static String nameAndInfo() { String info = U.frmt("v%s, built on %s", Msc.maybeMasked(version()), Msc.maybeMasked(builtOn())); String notes = Str.render(notes(), " [%s]", ""); return "Rapidoid " + info + notes; }
Example 13
Source File: Dir.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public synchronized String toString() { return U.frmt("Dir(%s, %d files, %d folders)", path, files.size(), folders.size()); }
Example 14
Source File: AbstractRapidoidMojo.java From rapidoid with Apache License 2.0 | 4 votes |
protected void failIf(boolean failureCondition, String msg, Object... args) throws MojoExecutionException { if (failureCondition) { throw new MojoExecutionException(U.frmt(msg, args)); } }
Example 15
Source File: TimeSeries.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public String toString() { return U.frmt("TimeSerie(%s)", stats); }
Example 16
Source File: SubUrlParams.java From rapidoid with Apache License 2.0 | 4 votes |
@GET("/hey/{name}/{age:\\d+}") public String hey(String name, int age) { return U.frmt("Hey %s (%s)", name, age); }
Example 17
Source File: Err.java From rapidoid with Apache License 2.0 | 4 votes |
public static void secure(boolean condition, String msg, Object arg1, Object arg2) { if (!condition) { throw new SecurityException(U.frmt(msg, arg1, arg2)); } }
Example 18
Source File: Err.java From rapidoid with Apache License 2.0 | 4 votes |
public static void secure(boolean condition, String msg, Object arg) { if (!condition) { throw new SecurityException(U.frmt(msg, arg)); } }
Example 19
Source File: RespBodyBytes.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public String toString() { return U.frmt("RespBodyBytes(%s bytes)", length()); }
Example 20
Source File: DocTest.java From rapidoid with Apache License 2.0 | 3 votes |
private void appendToIndex(String examplesDir, String filename) { String toIndex = U.frmt("include::%s[]\n\n", filename); String index = Msc.path(examplesDir, "index.adoc"); IO.append(index, toIndex.getBytes()); }