Search in sources :

Example 1 with ResultConfig

use of com.opensymphony.xwork2.config.entities.ResultConfig in project entando-core by entando.

the class FrontServletActionRedirectResult method execute.

@Override
public void execute(ActionInvocation invocation) throws Exception {
    try {
        this._actionName = this.conditionalParse(this._actionName, invocation);
        if (this._namespace == null) {
            this._namespace = invocation.getProxy().getNamespace();
        } else {
            this._namespace = this.conditionalParse(this._namespace, invocation);
        }
        if (this._method == null) {
            this._method = "";
        } else {
            this._method = this.conditionalParse(this._method, invocation);
        }
        String anchorDest = null;
        Map<String, String> redirectParams = new HashMap<String, String>();
        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
        if (resultConfig != null) {
            this.extractResultParams(redirectParams, resultConfig, invocation);
            anchorDest = this.extractAnchorDest(resultConfig, invocation);
        }
        HttpServletRequest request = ServletActionContext.getRequest();
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        this.extractInternalServletParams(redirectParams, reqCtx);
        IURLManager urlManager = (IURLManager) ApsWebApplicationUtils.getBean(SystemConstants.URL_MANAGER, request);
        Page currentPage = (Page) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        String url = urlManager.createURL(currentPage, currentLang, redirectParams, false, request);
        if (null != anchorDest) {
            url += "#" + anchorDest;
        }
        this.setLocation(url);
    } catch (Throwable t) {
        _logger.error("error in execute", t);
    }
    super.execute(invocation);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) HashMap(java.util.HashMap) IURLManager(com.agiletec.aps.system.services.url.IURLManager) Page(com.agiletec.aps.system.services.page.Page) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 2 with ResultConfig

use of com.opensymphony.xwork2.config.entities.ResultConfig in project qi4j-sdk by Qi4j.

the class Qi4jCodebehindPackageProvider method processActionClass.

/**
 * Create a default action mapping for a class instance.
 *
 * The namespace annotation is honored, if found, otherwise
 * the Java package is converted into the namespace
 * by changing the dots (".") to slashes ("/").
 *
 * @param cls  Action or POJO instance to process
 * @param pkgs List of packages that were scanned for Actions
 */
protected void processActionClass(Class<?> cls, String[] pkgs) {
    String name = cls.getName();
    String actionPackage = cls.getPackage().getName();
    String actionNamespace = null;
    String actionName = null;
    org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
    if (actionAnn != null) {
        actionName = actionAnn.name();
        if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) {
            actionNamespace = "";
        } else {
            actionNamespace = actionAnn.namespace();
        }
    } else {
        for (String pkg : pkgs) {
            if (name.startsWith(pkg)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("ClasspathPackageProvider: Processing class " + name);
                }
                name = name.substring(pkg.length() + 1);
                actionNamespace = "";
                actionName = name;
                int pos = name.lastIndexOf('.');
                if (pos > -1) {
                    actionNamespace = "/" + name.substring(0, pos).replace('.', '/');
                    actionName = name.substring(pos + 1);
                }
                break;
            }
        }
        // Truncate Action suffix if found
        if (actionName.endsWith(getClassSuffix())) {
            actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
        }
        // Force initial letter of action to lowercase, if desired
        if ((forceLowerCase) && (actionName.length() > 1)) {
            int lowerPos = actionName.lastIndexOf('/') + 1;
            StringBuilder sb = new StringBuilder();
            sb.append(actionName.substring(0, lowerPos));
            sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
            sb.append(actionName.substring(lowerPos + 1));
            actionName = sb.toString();
        }
    }
    PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls);
    // In case the package changed due to namespace annotation processing
    if (!actionPackage.equals(pkgConfig.getName())) {
        actionPackage = pkgConfig.getName();
    }
    Annotation annotation = cls.getAnnotation(ParentPackage.class);
    if (annotation != null) {
        String parent = ((ParentPackage) annotation).value()[0];
        PackageConfig parentPkg = configuration.getPackageConfig(parent);
        if (parentPkg == null) {
            throw new ConfigurationException("ClasspathPackageProvider: Unable to locate parent package " + parent, annotation);
        }
        pkgConfig.addParent(parentPkg);
        if (!isNotEmpty(pkgConfig.getNamespace()) && isNotEmpty(parentPkg.getNamespace())) {
            pkgConfig.namespace(parentPkg.getNamespace());
        }
    }
    ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
    ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()).addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build();
    pkgConfig.addActionConfig(actionName, actionConfig);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) Annotation(java.lang.annotation.Annotation) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) org.apache.struts2.config(org.apache.struts2.config)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)1 Lang (com.agiletec.aps.system.services.lang.Lang)1 Page (com.agiletec.aps.system.services.page.Page)1 IURLManager (com.agiletec.aps.system.services.url.IURLManager)1 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)1 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)1 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 org.apache.struts2.config (org.apache.struts2.config)1