Search in sources :

Example 1 with Context

use of org.eweb4j.mvc.Context in project eweb4j-framework by laiweiwei.

the class Lang method get.

public static Locale get() {
    Locale locale = current.get();
    if (locale == null) {
        Context ctx = MVC.ctx();
        if (ctx != null) {
            HttpServletRequest req = ctx.getRequest();
            HttpServletResponse res = ctx.getResponse();
            if (req != null) {
                resolve(req, res);
            } else {
                setDefaultLocale();
            }
        } else {
            setDefaultLocale();
        }
        locale = current.get();
    }
    return locale;
}
Also used : Locale(java.util.Locale) Context(org.eweb4j.mvc.Context) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 2 with Context

use of org.eweb4j.mvc.Context in project eweb4j-framework by laiweiwei.

the class InterExecution method doIntercept.

private void doIntercept(InterConfigBean inter) throws Exception {
    Object interceptor = null;
    if ("singleton".equalsIgnoreCase(inter.getScope()))
        interceptor = SingleBeanCache.get(inter.getClazz());
    if (interceptor == null) {
        interceptor = Thread.currentThread().getContextClassLoader().loadClass(inter.getClazz()).newInstance();
        if ("singleton".equalsIgnoreCase(inter.getScope()))
            SingleBeanCache.add(inter.getClazz(), interceptor);
    }
    ReflectUtil ru = new ReflectUtil(interceptor);
    Method intercept = ru.getMethod(inter.getMethod());
    if (intercept == null) {
        this.error = null;
        return;
    }
    Method setter = ru.getSetter("Context");
    if (setter != null)
        setter.invoke(interceptor, this.context);
    Object err = null;
    Class<?>[] paramCls = intercept.getParameterTypes();
    if (paramCls.length == 1 && paramCls[0].isAssignableFrom(Context.class))
        err = intercept.invoke(interceptor, this.context);
    else
        err = intercept.invoke(interceptor);
    if (err == null) {
        this.error = null;
        return;
    }
    this.error = String.valueOf(err);
}
Also used : Context(org.eweb4j.mvc.Context) ReflectUtil(org.eweb4j.util.ReflectUtil) Method(java.lang.reflect.Method)

Aggregations

Context (org.eweb4j.mvc.Context)2 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ReflectUtil (org.eweb4j.util.ReflectUtil)1