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

The following examples show how to use org.osgl.util.S#newBuffer() . 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: TemplatePathResolver.java    From actframework with Apache License 2.0 6 votes vote down vote up
public final String resolveWithContextMethodPath(ActContext context) {
    String methodPath = context.methodPath();
    String path = context.templatePath();
    String[] sa = path.split("\\.");
    int level = sa.length + 1;
    S.Buffer sb;
    if (S.notBlank(methodPath)) {
        while (--level > 0) {
            methodPath = S.beforeLast(methodPath, ".");
        }
        sb = S.newBuffer(methodPath);
    } else {
        sb = S.newBuffer();
    }
    if (!path.startsWith("/")) {
        sb.append("/");
    }
    path = sb.append(path).toString().replace('.', '/');
    return resolveTemplatePath(path, context);
}
 
Example 2
Source File: InterceptorMethodMetaInfo.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
protected S.Buffer toStrBuffer(S.Buffer sb) {
    S.Buffer prependix = S.newBuffer();
    if (null != priority) {
        prependix.append("p[")
                .append(priority).append("] ");
    }
    if (!whiteList.isEmpty()) {
        prependix.append("+").append(whiteList).append(" ");
    }
    if (!blackList.isEmpty()) {
        prependix.append("-").append(blackList).append(" ");
    }

    return super.toStrBuffer(sb).prepend(prependix);
}
 
Example 3
Source File: ControllerClassMetaInfo.java    From actframework with Apache License 2.0 6 votes vote down vote up
public String templateContext() {
    if (null != parent) {
        if (S.notBlank(templateContext) && templateContext.length() > 1 && templateContext.startsWith("/")) {
            return templateContext;
        }
        String parentContextPath = parent.templateContext();
        if (null == templateContext) {
            return parentContextPath;
        }
        if (null == parentContextPath) {
            return templateContext;
        }
        S.Buffer sb = S.newBuffer(parentContextPath);
        if (parentContextPath.endsWith("/")) {
            sb.deleteCharAt(sb.length() - 1);
        }
        if (!templateContext.startsWith("/")) {
            sb.append("/");
        }
        sb.append(templateContext);
        return sb.toString();
    }
    return templateContext;
}
 
Example 4
Source File: ControllerClassMetaInfo.java    From actframework with Apache License 2.0 6 votes vote down vote up
public String urlContext() {
    if (null != parent) {
        if (S.notBlank(urlContext) && urlContext.length() > 1 && urlContext.startsWith("/")) {
            return urlContext;
        }
        String parentContextPath = parent.urlContext();
        if (null == urlContext) {
            return parentContextPath;
        }
        if (null == parentContextPath) {
            return urlContext;
        }
        S.Buffer sb = S.newBuffer(parentContextPath);
        if (parentContextPath.endsWith("/")) {
            sb.deleteCharAt(sb.length() - 1);
        }
        if (!urlContext.startsWith("/")) {
            sb.append("/");
        }
        sb.append(urlContext);
        return sb.toString();
    }
    return urlContext;
}
 
Example 5
Source File: JsonDtoClassGenerator.java    From actframework with Apache License 2.0 6 votes vote down vote up
private String typeDesc(BeanSpec spec) {
    String root = classDesc(spec.rawType());
    List<java.lang.reflect.Type> typeParams = spec.typeParams();
    if (typeParams.isEmpty()) {
        return root;
    }
    S.Buffer sb = S.newBuffer("<");
    for (java.lang.reflect.Type type : typeParams) {
        BeanSpec specx = BeanSpec.of(type, null, spec.injector(), typeParamLookup);
        sb.append(typeDesc(specx));
    }
    sb.append(">");
    FastStr str = FastStr.of(root);
    str = str.take(str.length() - 1).append(sb.toString()).append(";");
    return str.toString();
}
 
Example 6
Source File: JobMethodMetaInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    S.Buffer sb = S.newBuffer();
    sb.append(_invokeType())
            .append(_return())
            .append(fullName());
    return sb.toString();
}
 
Example 7
Source File: SenderMethodMetaInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    S.Buffer sb = S.newBuffer();
    sb.append(_invokeType())
            .append(_return())
            .append(fullName())
            .append("(")
            .append(_params())
            .append(")");
    return sb.toString();
}
 
Example 8
Source File: IdGenerator.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a unique ID across the cluster
 * @return generated ID
 */
public String genId() {
    S.Buffer sb = S.newBuffer();
    sb.a(longEncoder.longToStr(nodeIdProvider.nodeId()))
      .a(longEncoder.longToStr(startIdProvider.startId()))
      .a(longEncoder.longToStr(sequenceProvider.seqId()));
    return sb.toString();
}
 
Example 9
Source File: ConfigKeyHelper.java    From actframework with Apache License 2.0 5 votes vote down vote up
public String evaluate(String s, Map<String, ?> map) {
    int n = 0, n0 = 0, len = s.length();
    S.Buffer sb = S.newBuffer();
    while (n > -1 && n < len) {
        n = s.indexOf("${", n);
        if (n < 0) {
            if (n0 == 0) {
                return s;
            }
            sb.append(s.substring(n0, len));
            break;
        }
        sb.append(s.substring(n0, n));
        // now search for "}"
        n += 2;
        n0 = n;
        n = s.indexOf("}", n0 + 1);
        if (n < 0) {
            logger.warn("Invalid expression found in the configuration value: %s", s);
            return s;
        }
        String expression = s.substring(n0, n);
        if (S.notBlank(expression)) {
            // in case getting from Env variable
            Object o = map.get(expression);
            if (null == o) {
                o = getConfiguration(expression, null, map);
            }
            if (null != o) {
                sb.append(o);
            } else {
                logger.warn("Cannot find expression value for: %s", expression);
            }
        }
        n += 1;
        n0 = n;
    }
    return sb.toString();
}
 
Example 10
Source File: RouteInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static String compactHandler(String handler) {
    String[] sa = handler.split("\\.");
    int len = sa.length;
    if (len == 1) {
        return handler;
    }
    S.Buffer sb = S.newBuffer();
    for (int i = 0; i < len - 2; ++i) {
        sb.append(sa[i].charAt(0)).append('.');
    }
    sb.append(sa[len - 2]).append('.').append(sa[len - 1]);
    return sb.toString();
}