Search in sources :

Example 6 with MadvocException

use of jodd.madvoc.MadvocException in project jodd by oblac.

the class ActionsManager method register.

/**
	 * Registers action with provided action signature.
	 */
public ActionConfig register(String actionSignature, ActionDef actionDef) {
    int ndx = actionSignature.indexOf('#');
    if (ndx == -1) {
        throw new MadvocException("Madvoc action signature syntax error: " + actionSignature);
    }
    String actionClassName = actionSignature.substring(0, ndx);
    String actionMethodName = actionSignature.substring(ndx + 1);
    Class actionClass;
    try {
        actionClass = ClassLoaderUtil.loadClass(actionClassName);
    } catch (ClassNotFoundException cnfex) {
        throw new MadvocException("Madvoc action class not found: " + actionClassName, cnfex);
    }
    return register(actionClass, actionMethodName, actionDef);
}
Also used : MadvocException(jodd.madvoc.MadvocException)

Example 7 with MadvocException

use of jodd.madvoc.MadvocException in project jodd by oblac.

the class MadvocController method render.

// ---------------------------------------------------------------- render
/**
	 * Invokes a result after the action invocation.
	 * <p>
	 * Results may be objects that specify which action result will be used
	 * to render the result.
	 * <p>
	 * Result value may consist of two parts: type and value. Result type is optional and, if exists, it is separated
	 * by semi-colon from the value. If type is not specified
	 * then the default result type if still not defined. Result type defines which
	 * {@link ActionResult} should be used for rendering the value.
	 * <p>
	 * Result value is first checked against aliased values. Then, it is resolved and then passed
	 * to the founded {@link ActionResult}.
	 *
	 * @see ActionResult#render(jodd.madvoc.ActionRequest, Object)
	 */
@SuppressWarnings("unchecked")
public void render(ActionRequest actionRequest, Object resultObject) throws Exception {
    ActionResult actionResult = resultsManager.lookup(actionRequest, resultObject);
    if (actionResult == null) {
        throw new MadvocException("Action result not found");
    }
    if (madvocConfig.isPreventCaching()) {
        ServletUtil.preventCaching(actionRequest.getHttpServletResponse());
    }
    actionResult.render(actionRequest, actionRequest.getActionResult());
}
Also used : ActionResult(jodd.madvoc.result.ActionResult) MadvocException(jodd.madvoc.MadvocException)

Example 8 with MadvocException

use of jodd.madvoc.MadvocException in project jodd by oblac.

the class WrapperManager method expand.

/**
	 * Replaces all {@link #getDefaultWebAppWrapper()} with {@link #getDefaultWebAppWrapper()}
	 * and {@link BaseActionWrapperStack} with stack values.
	 */
protected Class<? extends T>[] expand(Class<? extends T>[] actionWrappers) {
    if (actionWrappers == null) {
        return null;
    }
    List<Class<? extends T>> list = new ArrayList<>(actionWrappers.length);
    list.addAll(Arrays.asList(actionWrappers));
    int i = 0;
    while (i < list.size()) {
        Class<? extends T> wrapperClass = list.get(i);
        if (wrapperClass == null) {
            continue;
        }
        if (wrapperClass.equals(getDefaultWebAppWrapper())) {
            list.remove(i);
            // add default wrappers list
            Class<? extends T>[] defaultWrappers = getDefaultWrappers();
            if (defaultWrappers != null) {
                int ndx = i;
                for (Class<? extends T> defaultWrapper : defaultWrappers) {
                    // can't add default list stack to default list
                    if (defaultWrapper.equals(getDefaultWebAppWrapper())) {
                        throw new MadvocException("Default wrapper list is self-contained (cyclic dependency)!");
                    }
                    list.add(ndx, defaultWrapper);
                    ndx++;
                }
            }
            continue;
        }
        if (ReflectUtil.isTypeOf(wrapperClass, BaseActionWrapperStack.class)) {
            BaseActionWrapperStack stack = (BaseActionWrapperStack) resolve(wrapperClass);
            list.remove(i);
            Class<? extends T>[] stackWrappers = stack.getWrappers();
            if (stackWrappers != null) {
                list.addAll(i, Arrays.asList(stackWrappers));
            }
            i--;
        //continue;
        }
        i++;
    }
    return list.toArray(new Class[list.size()]);
}
Also used : BaseActionWrapperStack(jodd.madvoc.BaseActionWrapperStack) ArrayList(java.util.ArrayList) MadvocException(jodd.madvoc.MadvocException)

Example 9 with MadvocException

use of jodd.madvoc.MadvocException in project jodd by oblac.

the class ServletDispatcherResultWithJspp method processTarget.

@Override
protected String processTarget(ActionRequest actionRequest, String target) {
    ServletContext servletContext = actionRequest.getHttpServletRequest().getServletContext();
    String jspPath = servletContext.getRealPath(target);
    if (jspPath == null) {
        throw new MadvocException("Real path not found: " + target);
    }
    File jspFile = new File(jspPath);
    File targetFile = new File(convertToNewName(jspPath));
    target = convertToNewName(target);
    if (!targetFile.exists() || FileUtil.isNewer(jspFile, targetFile)) {
        if (log.isDebugEnabled()) {
            log.debug("JSPP target: " + target);
        }
        if (jspp == null) {
            jspp = createJspp(servletContext);
        }
        try {
            preprocess(jspFile, targetFile);
        } catch (IOException ioex) {
            throw new JsppException(ioex);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("JSPP ok: " + target);
        }
    }
    return target;
}
Also used : ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException) File(java.io.File) MadvocException(jodd.madvoc.MadvocException)

Aggregations

MadvocException (jodd.madvoc.MadvocException)9 ArrayList (java.util.ArrayList)2 File (java.io.File)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 ServletContext (javax.servlet.ServletContext)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 PropertyDescriptor (jodd.introspector.PropertyDescriptor)1 ActionConfigSet (jodd.madvoc.ActionConfigSet)1 ActionNames (jodd.madvoc.ActionNames)1 BaseActionWrapperStack (jodd.madvoc.BaseActionWrapperStack)1 ScopeData (jodd.madvoc.ScopeData)1 Target (jodd.madvoc.injector.Target)1 ActionAnnotationData (jodd.madvoc.meta.ActionAnnotationData)1 In (jodd.madvoc.meta.In)1 InOut (jodd.madvoc.meta.InOut)1 Out (jodd.madvoc.meta.Out)1 ActionNamingStrategy (jodd.madvoc.path.ActionNamingStrategy)1 ActionResult (jodd.madvoc.result.ActionResult)1