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

The following examples show how to use org.osgl.util.S#string() . 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: UrlPath.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static boolean matches(Object cs1, Object cs2) {
    if (DYNA_PART.equals(cs1)) {
        return true;
    }
    if (cs1 instanceof Keyword) {
        return matches((Keyword) cs1, cs2);
    } else if (cs2 instanceof Keyword) {
        return matches((Keyword) cs2, cs1);
    }
    String s1 = S.string(cs1);
    String s2 = S.string(cs2);
    int len = s1.length();
    if (len != s2.length()) {
        return false;
    }
    for (int i = len - 1; i >= 0; --i) {
        if (s1.charAt(i) != s2.charAt(i)) {
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: RouterAdmin.java    From actframework with Apache License 2.0 6 votes vote down vote up
private List<RouteInfo> routeInfoList(String portName, String q) {
    final Router router = S.blank(portName) ? app.router() : app.router(portName);
    List<RouteInfo> list = router.debug();
    if (S.notBlank(q)) {
        List<RouteInfo> toBeRemoved = new ArrayList<>();
        for (RouteInfo info: list) {
            String handler = S.string(info.handler());
            String path = info.path();
            if (path.contains(q) || handler.contains(q) || path.matches(q) || handler.matches(q)) {
                continue;
            }
            toBeRemoved.add(info);
        }
        list = C.list(list).without(toBeRemoved);
    }
    return list;
}
 
Example 3
Source File: Config.java    From actframework with Apache License 2.0 6 votes vote down vote up
public Integer getInteger(ConfigKey key, Integer def) {
    Object retVal = get(key, def);
    if (null == retVal) {
        return null;
    }
    if (retVal instanceof Number) {
        return ((Number) retVal).intValue();
    }
    String s = S.string(retVal);
    if (s.contains("*")) {
        List<String> sl = S.fastSplit(s, "*");
        int n = 1;
        for (String sn : sl) {
            n *= Integer.parseInt(sn.trim());
        }
        return n;
    }
    return Integer.parseInt(s);
}
 
Example 4
Source File: CommanderByteCodeScanner.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(String name, Object value) {
    if ("value".equals(name)) {
        String key = S.string(value);
        if (S.blank(key)) {
            sessionVariableName = fieldName;
        } else {
            sessionVariableName = key;
        }
    }
    super.visit(name, value);
}
 
Example 5
Source File: GH325.java    From actframework with Apache License 2.0 5 votes vote down vote up
@GetAction("list/{list}/{key}")
public String test3(Map<String, List<Integer>> list, String key) {
    List<Integer> l = list.get(key);
    if (null == l) {
        return "0";
    }
    int n = 0;
    for (int x : l) {
        n += x;
    }
    return S.string(n);
}
 
Example 6
Source File: GH325.java    From actframework with Apache License 2.0 5 votes vote down vote up
@GetAction("person/{name};{attributes}/{key}")
public String test2(String name, Map<String, Integer> attributes, String key) {
    if (S.eq("name", key)) {
        return name;
    }
    return S.string(attributes.get(key));
}
 
Example 7
Source File: EndpointTester.java    From actframework with Apache License 2.0 5 votes vote down vote up
private RequestBody buildFormEncoded() {
    FormBody.Builder builder = new FormBody.Builder();
    for ($.T2<String, Object> entry : postParams) {
        String val = S.string(entry._2);
        if (this.method == H.Method.GET) {
            val = Codec.encodeUrl(val);
        }
        builder.add(entry._1, val);
    }
    return builder.build();
}
 
Example 8
Source File: OptionsInfoBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
public RequestHandler optionHandler(String path, ActionContext context) {
    String s = S.string(path);
    RequestHandler handler = handlers.get(s);
    if (null == handler) {
        RequestHandler newHandler = createHandler(path, context);
        handler = handlers.putIfAbsent(s, newHandler);
        if (null == handler) {
            handler = newHandler;
        } else {
            newHandler.destroy();
        }
    }
    return handler;
}
 
Example 9
Source File: EnvAnnotationVisitor.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(String name, Object value) {
    if ("value".equals(name)) {
        String s = S.string(value);
        if (S.eq(desc, DESC_REQUIRE_MODE) || S.eq(desc, DESC_MODE)) {
            matched = Env.modeMatches(s);
        }
    } else if ("except".equals(name)) {
        except = (Boolean) value;
    }
    super.visit(name, value);
}
 
Example 10
Source File: ArithmeticGenerator.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public CaptchaSession generate() {
    ArithmeticExpression expression = new ArithmeticExpression();
    return new CaptchaSession(
            expression.toString(), S.string(expression.evaluate()), null,
            I18n.i18n(act_messages.class, "act.captcha.generator.arithmetic.instruction"),
            null
    );
}
 
Example 11
Source File: EndpointTester.java    From actframework with Apache License 2.0 5 votes vote down vote up
public ReqBuilder params(String key, Object val, Object ... otherPairs) {
    E.illegalArgumentIf(otherPairs.length % 2 != 0);
    param(key, val);
    int len = otherPairs.length;
    for (int i = 0; i < len - 1; i += 2) {
        String key0 = S.string(otherPairs[i]);
        param(key0, otherPairs[i + 1]);
    }
    return this;
}
 
Example 12
Source File: RythmView.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Transformer
public static RawData errorLine(RawData data, int errorColumn) {
    String line = S.string(data);
    if (errorColumn > -1 && errorColumn < line.length()) {
        String a = line.substring(0, errorColumn);
        char c = line.charAt(errorColumn);
        String b = line.substring(errorColumn + 1);
        line = S.concat(a, "<span_class='error-column'>", c, "</span>", b);
        line = S.replace(" ").with("&nbsp;").in(line);
        line = S.replace("span_class").with("span class").in(line);
    } else {
        line = S.replace(" ").with("&nbsp;").in(line);
    }
    return new RawData(line);
}
 
Example 13
Source File: RythmView.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Transformer
public static RawData errorLine(String data, int errorColumn) {
    String line = S.string(data);
    if (errorColumn > -1 && errorColumn < line.length()) {
        String a = line.substring(0, errorColumn);
        char c = line.charAt(errorColumn);
        String b = line.substring(errorColumn + 1);
        line = S.concat(a, "<span_class='error-column'>", c, "</span>", b);
        line = S.replace(" ").with("&nbsp;").in(line);
        line = S.replace("span_class").with("span class").in(line);
    } else {
        line = S.replace(" ").with("&nbsp;").in(line);
    }
    return new RawData(line);
}
 
Example 14
Source File: EmailHandler.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean isValid(Object val) {
    String s = S.string(val);
    boolean valid = (S.isBlank(s) || s.toLowerCase().matches("^[_a-z0-9-']+(\\.[_a-z0-9-']+)*(\\+[0-9]+)?@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,64})$"));
    if (!valid) {
        return false;
    }
    // check tld
    String tld = S.cut(s).afterLast(".");
    return tldList.isTld(tld);
}
 
Example 15
Source File: StringUtils.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public String transform(String s) {
    App app = Act.app();
    return S.string(null != app ? app.config().get(s) : System.getProperty(s));
}
 
Example 16
Source File: ConfigurationValueLoader.java    From java-di with Apache License 2.0 4 votes vote down vote up
@Override
protected void initialized() {
    this.defaultValue = S.string(options.get(Configuration.DEFAULT_VALUE_PROP));
}
 
Example 17
Source File: CommanderByteCodeScanner.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitParameterAnnotation(final int paramIndex, String desc, boolean visible) {
    AnnotationVisitor av = super.visitParameterAnnotation(paramIndex, desc, visible);
    Type type = Type.getType(desc);
    boolean isOptional = $.eq(type, AsmTypes.OPTIONAL.asmType());
    boolean isRequired = !isOptional && $.eq(type, AsmTypes.REQUIRED.asmType());

    if (isOptional || isRequired) {
        if (optionAnnoInfoMap.containsKey(paramIndex)) {
            throw E.unexpected("Option annotation already found on index %s", paramIndex);
        }
        return new ParamOptionAnnotationVisitor(av, paramIndex, isOptional);
    } else if ($.eq(type, AsmTypes.CONTEXT.asmType())) {
        contextInfo.set(paramIndex);
        return av;
    } else if ($.eq(type, AsmTypes.READ_FILE_CONTENT.asmType())) {
        readFileContentFlags.put(paramIndex, true);
        return av;
    } else if ($.eq(type, AsmTypes.CLI_SESSION_ATTRIBUTE.asmType())) {
        return new AnnotationVisitor(ASM5, av) {
            private String attributeKey = "";

            @Override
            public void visit(String name, Object value) {
                if ("value".equals(name)) {
                    attributeKey = S.string(value);
                }
                super.visit(name, value);
            }

            @Override
            public void visitEnd() {
                cliSessionAttributeMap.put(paramIndex, attributeKey);
                super.visitEnd();
            }
        };
    } else if ("Ljavax/inject/Named;".equals(desc)) {
        skipNaming.add(paramIndex);
        return av;
    } else {
        return av;
    }
}
 
Example 18
Source File: ConfigItem.java    From actframework with Apache License 2.0 4 votes vote down vote up
public String getVal() {
    return S.string(val);
}
 
Example 19
Source File: HelloController.java    From actframework with Apache License 2.0 4 votes vote down vote up
@SessionFree
@PostAction("/hello6")
public String hello6(int i) {
    return S.string(i);
}
 
Example 20
Source File: Gh906.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return S.string(id);
}