Java Code Examples for org.osgl.util.S#blank()

The following examples show how to use org.osgl.util.S#blank() . 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: RequestImplBase.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
public H.Method method() {
    if (null == method) {
        method = _method();
        if (method == H.Method.POST) {
            // check the method overload
            String s = header(H.Header.Names.X_HTTP_METHOD_OVERRIDE);
            if (S.blank(s)) {
                s = paramVal("_method"); // Spring convention
            }
            if (S.notBlank(s)) {
                method = H.Method.valueOfIgnoreCase(s);
            }
        }
    }
    return method;
}
 
Example 2
Source File: HttpClientService.java    From actframework with Apache License 2.0 6 votes vote down vote up
public boolean verifyReCaptchaResponse(ActionContext ctx) {
    if (S.blank(reCaptchaSercret)) {
        return false;
    }
    String url = "https://www.google.com/recaptcha/api/siteverify?secret="
            + reCaptchaSercret + "&response="
            + ctx.paramVal("g-recaptcha-response");
    Request req = new Request.Builder().url(url).get().build();
    try {
        Response response = sendRequest(req);
        JSONObject json = JSON.parseObject(response.body().string());
        return json.getBoolean("success");
    } catch (IOException e) {
        warn(e, "Error sending response");
        return false;
    }
}
 
Example 3
Source File: JobAnnotationProcessor.java    From actframework with Apache License 2.0 6 votes vote down vote up
private String evaluateExpression(String expression, Class<? extends Annotation> annoClass) {
    String prefix = annoClass.getSimpleName();
    if (S.eq(FixedDelay.class.getName(), prefix)) {
        prefix = "fixed-delay";
    } else {
        prefix = prefix.toLowerCase();
    }
    String ret = expression.trim();
    if (ret.startsWith(prefix)) {
        ret = (String) app().config().get(expression);
        if (S.blank(ret)) {
            throw E.invalidConfiguration("Expression configuration not found: %s", expression);
        }
    }
    return ret;
}
 
Example 4
Source File: JobByteCodeScanner.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(String name, Object value) {
    if ("value".equals(name)) {
        if (this.currentInfo.annotationType == FixtureLoader.class) {
            String id = S.string(value);
            if (S.blank(id)) {
                id = methodName;
            }
            method.id(id);
        } else {
            this.currentInfo.value = value.toString();
        }
    } else if ("async".equals(name)) {
        this.currentInfo.async = $.bool(value);
    } else if ("id".equals(name)) {
        this.method.id(S.string(value));
    } else if ("startImmediately".equals(name)) {
        this.currentInfo.startImmediately = Boolean.parseBoolean(value.toString());
    } else if ("delayInSeconds".equals(name)) {
        this.currentInfo.delayInSeconds = Integer.parseInt(value.toString());
    }
    super.visit(name, value);
}
 
Example 5
Source File: NoisyWordsFilter.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Filter a list of string tokens and get rid of tokens that are
 * {@link #noiseWords() noise}
 *
 * The tokens in the return list is in lower case
 *
 * @param tokens
 *      the list of string token
 * @return
 *      filtered list of lowercase string tokens
 */
static List<String> filter(List<String> tokens) {
    List<String> result = new ArrayList<>();
    Set<String> noise = noiseWords();
    for (String token : tokens) {
        if (S.blank(token)) {
            continue;
        }
        token = token.trim().toLowerCase();
        if (!noise.contains(token)) {
            result.add(token);
        }
    }
    return result;
}
 
Example 6
Source File: CliSession.java    From actframework with Apache License 2.0 5 votes vote down vote up
private File historyFile() {
    String fileName = System.getProperty("cli.history");
    if (S.blank(fileName)) {
        fileName = ".act.cli-history";
    }
    return new File(fileName);
}
 
Example 7
Source File: JobTrigger.java    From actframework with Apache License 2.0 5 votes vote down vote up
static JobTrigger of(AppConfig config, FixedDelay anno) {
    String delay = anno.value();
    if (delay.startsWith("delay.")) {
        delay = (String) config.get(delay);
    } else if (delay.startsWith("${") && delay.endsWith("}")) {
        delay = delay.substring(2, delay.length() - 1);
        delay = (String) config.get(delay);
    }
    if (S.blank(delay)) {
        throw E.invalidConfiguration("Cannot find configuration for delay: %s", anno.value());
    }
    return fixedDelay(delay, anno.startImmediately());
}
 
Example 8
Source File: ConfLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean isAppProperties(String name, String profile) {
    if (!name.endsWith(".properties")) {
        return false;
    }
    if (name.startsWith("conf/")) {
        String name0 = name.substring(5);
        if (!name0.contains("/") || name0.startsWith("common")) {
            return true;
        }
        return !S.blank(profile) && name0.startsWith(profile + "/");
    }
    return !name.contains("/") && !name.startsWith("act") && !name.startsWith("build.");
}
 
Example 9
Source File: AppDescriptor.java    From actframework with Apache License 2.0 5 votes vote down vote up
private static String ensureAppName(String appName, Class<?> entryClass, Version version) {
    if (S.blank(appName)) {
        if (!version.isUnknown()) {
            appName = version.getArtifactId();
        }
        if (S.blank(appName)) {
            appName = AppNameInferer.from(entryClass);
        }
    }
    return appName;
}
 
Example 10
Source File: CSRF.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Do sanity check to see if CSRF token is present. This method
 * is called before session resolved
 *
 * @param context the current context
 */
public void preCheck(ActionContext context) {
    if (!enabled) {
        return;
    }
    H.Method method = context.req().method();
    if (method.safe()) {
        return;
    }
    String token = retrieveCsrfToken(context);
    if (S.blank(token)) {
        raiseCsrfNotVerified(context);
    }
}
 
Example 11
Source File: SimpleMetricPlugin.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public Metric metric(String name) {
    if (!Act.appConfig().metricEnabled()) {
        return Metric.NULL_METRIC;
    }
    Logger logger = enabledMap.get(name);
    if (null == logger) {
        logger = LogManager.get("act.metric." + name);
        enabledMap.put(name, logger);
    }
    return logger.isTraceEnabled() ? S.blank(name) ? defaultMetric : new SimpleMetric(name, defaultMetricStore) : Metric.NULL_METRIC;
}
 
Example 12
Source File: HeaderValueLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Map<String, Object> map, BeanSpec beanSpec) {
    this.headerName = (String) map.get("value");
    if (S.blank(headerName)) {
        this.headerName = beanSpec.name();
    }
    E.unexpectedIf(S.blank(headerName), "header name not found");
    this.headerName = Keyword.of(this.headerName).httpHeader();
    this.targetType = beanSpec.rawType();
}
 
Example 13
Source File: ConfLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Return the name of the current conf set
 * @return the conf set name
 */
public static String confSetName() {
    String profile = SysProps.get(AppConfigKey.PROFILE.key());
    if (S.blank(profile)) {
        profile = Act.mode().name().toLowerCase();
        System.setProperty(AppConfigKey.PROFILE.key(), profile);
    }
    return profile;
}
 
Example 14
Source File: MailerClassMetaInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public MailerClassMetaInfo contextPath(String path) {
    if (S.blank(path)) {
        contextPath = "/";
    } else {
        contextPath = path;
    }
    return this;
}
 
Example 15
Source File: HelpPage.java    From actframework with Apache License 2.0 4 votes vote down vote up
private static String helpOf(Required required) {
    String help = required.help();
    return S.blank(help) ? required.value() : help;
}
 
Example 16
Source File: Echo.java    From actframework with Apache License 2.0 4 votes vote down vote up
public Echo(String msg, String contentType) {
    this.buffer = ByteBuffers.wrap(msg);
    this.contentType = S.blank(contentType) ? H.Format.TXT.contentType() : contentType;
    this.toString = "echo: " + msg;
}
 
Example 17
Source File: VersionedModel.java    From actframework with Apache License 2.0 4 votes vote down vote up
public VersionedModel(String id) {
    this.version = S.blank(id) ? S.random() : id;
}
 
Example 18
Source File: WebSocketAdminConsole.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Command(name = "act.ws.conn.by-user", help = "report websocket connection number by user")
public int userConnections(@Optional("specify user name") String username) {
    WebSocketConnectionRegistry registry = manager.usernameRegistry();
    return S.blank(username) ? registry.count() : registry.count(username);
}
 
Example 19
Source File: SObjectResolver.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public SObject resolve(String value) {
    if (value.startsWith("http://") || value.startsWith("https://")) {
        return resolveFromURL(value);
    } else if (value.startsWith("data:")) {
        int pos = value.indexOf("base64,");
        if (pos < 0) {
            return null;
        }
        String encoded = value.substring(pos + "base64,".length());
        return resolveFromBase64(encoded);
    } else {
        File file;
        CliContext cli = CliContext.current();
        if (null != cli) {
            file = cli.getFile(value);
            if (file.exists() && file.canRead()) {
                return SObject.of(file);
            }
        } else {
            ActionContext act = ActionContext.current();
            if (null != act) {
                ISObject sobj = act.upload(value);
                if (null != sobj) {
                    return (SObject)sobj;
                }
            }
        }
        if (S.blank(value)) {
            return null;
        }
        if (value.length() < 15) {
            // assume it is model name (the parameter name)
            return null;
        }
        // last try base64 decoder
        try {
            return resolveFromBase64(value);
        } catch (Exception e) {
            Act.LOGGER.warn(S.concat("Cannot resolve SObject from value: ", value));
            return null;
        }
    }
}
 
Example 20
Source File: HelpPage.java    From actframework with Apache License 2.0 4 votes vote down vote up
private static String helpOf(act.cli.Optional optional) {
    String help = optional.help();
    return S.blank(help) ? optional.value() : help;
}