Search in sources :

Example 1 with ILangManager

use of com.agiletec.aps.system.services.lang.ILangManager in project entando-core by entando.

the class TestDataObjectDAO method init.

private void init() throws Exception {
    this._dataObjectDao = new DataObjectDAO();
    try {
        this._dataObjectManager = (IDataObjectManager) this.getService("DataObjectManager");
        DataObject mockDataObject = this.getMockDataObject();
        DataSource dataSource = (DataSource) this.getApplicationContext().getBean("servDataSource");
        this._dataObjectDao.setDataSource(dataSource);
        ILangManager langManager = (ILangManager) this.getService(SystemConstants.LANGUAGE_MANAGER);
        this._dataObjectDao.setLangManager(langManager);
        this._dataObjectDao.addEntity(mockDataObject);
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSource(javax.sql.DataSource)

Example 2 with ILangManager

use of com.agiletec.aps.system.services.lang.ILangManager in project entando-core by entando.

the class SelfRestCaller method extractParameters.

protected Properties extractParameters(SelfRestCallPostProcess selfRestCall) throws ApsSystemException {
    Properties properties = new Properties();
    try {
        ILangManager langManager = this.getLangManager();
        String langCode = selfRestCall.getLangCode();
        if (null == langCode || null == langManager.getLang(langCode)) {
            langCode = langManager.getDefaultLang().getCode();
        }
        if (null != selfRestCall.getQueryParameters()) {
            properties.putAll(selfRestCall.getQueryParameters());
        }
        properties.put(SystemConstants.API_LANG_CODE_PARAMETER, langCode);
        UserDetails user = this.getAuthenticationProvider().getUser(SystemConstants.ADMIN_USER_NAME);
        if (null != user) {
            properties.put(SystemConstants.API_USER_PARAMETER, user);
        } else {
            _logger.error("Admin user missing");
        }
    } catch (Throwable t) {
        _logger.error("Error extracting parameters", t);
        // ApsSystemUtils.logThrowable(t, this, "extractParameters", "Error extracting parameters");
        throw new ApsSystemException("Error extracting parameters", t);
    }
    return properties;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Properties(java.util.Properties)

Example 3 with ILangManager

use of com.agiletec.aps.system.services.lang.ILangManager in project entando-core by entando.

the class CurrentWidgetTag method extractTitle.

private String extractTitle(Widget widget) {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    WidgetType type = widget.getType();
    String value = type.getTitles().getProperty(currentLang.getCode());
    if (null == value || value.trim().length() == 0) {
        ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
        Lang defaultLang = langManager.getDefaultLang();
        value = type.getTitles().getProperty(defaultLang.getCode());
    }
    return value;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 4 with ILangManager

use of com.agiletec.aps.system.services.lang.ILangManager in project entando-core by entando.

the class InfoTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    try {
        if ("startLang".equals(this._key)) {
            Lang startLang = this.extractStartLang();
            this._info = startLang.getCode();
        } else if ("defaultLang".equals(this._key)) {
            ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
            this._info = langManager.getDefaultLang().getCode();
        } else if ("currentLang".equals(this._key)) {
            RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
            Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
            this._info = currentLang.getCode();
        } else if ("langs".equals(this._key)) {
            ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
            this._info = langManager.getLangs();
        } else if ("systemParam".equals(this._key)) {
            if (SystemConstants.PAR_APPL_BASE_URL.equals(this.getParamName())) {
                IURLManager urlManager = (IURLManager) ApsWebApplicationUtils.getBean(SystemConstants.URL_MANAGER, this.pageContext);
                this._info = urlManager.getApplicationBaseURL((HttpServletRequest) request);
            } else {
                ConfigInterface confManager = (ConfigInterface) ApsWebApplicationUtils.getBean(SystemConstants.BASE_CONFIG_MANAGER, this.pageContext);
                this._info = confManager.getParam(this.getParamName());
            }
        }
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        throw new JspException("Error during tag initialization", t);
    }
    return EVAL_BODY_INCLUDE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) IURLManager(com.agiletec.aps.system.services.url.IURLManager) Lang(com.agiletec.aps.system.services.lang.Lang) ConfigInterface(com.agiletec.aps.system.services.baseconfig.ConfigInterface) RequestContext(com.agiletec.aps.system.RequestContext)

Example 5 with ILangManager

use of com.agiletec.aps.system.services.lang.ILangManager in project entando-core by entando.

the class InfoTag method extractStartLang.

private Lang extractStartLang() {
    Lang startLang = null;
    ConfigInterface baseConfigManager = (ConfigInterface) ApsWebApplicationUtils.getBean(SystemConstants.BASE_CONFIG_MANAGER, this.pageContext);
    ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
    try {
        String startLangFromBrowser = baseConfigManager.getParam(SystemConstants.CONFIG_PARAM_START_LANG_FROM_BROWSER);
        if (null != startLangFromBrowser && startLangFromBrowser.equalsIgnoreCase("true")) {
            ServletRequest request = this.pageContext.getRequest();
            if (request instanceof HttpServletRequest) {
                String headerLang = ((HttpServletRequest) request).getHeader("Accept-Language");
                if (null != headerLang && headerLang.length() >= 2) {
                    String langCode = headerLang.substring(0, 2);
                    startLang = langManager.getLang(langCode);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting start lang", t);
    } finally {
        if (null == startLang) {
            startLang = langManager.getDefaultLang();
        }
    }
    return startLang;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) Lang(com.agiletec.aps.system.services.lang.Lang) ConfigInterface(com.agiletec.aps.system.services.baseconfig.ConfigInterface)

Aggregations

ILangManager (com.agiletec.aps.system.services.lang.ILangManager)17 Lang (com.agiletec.aps.system.services.lang.Lang)8 RequestContext (com.agiletec.aps.system.RequestContext)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 ConfigInterface (com.agiletec.aps.system.services.baseconfig.ConfigInterface)3 ServletRequest (javax.servlet.ServletRequest)3 DataSource (javax.sql.DataSource)3 IURLManager (com.agiletec.aps.system.services.url.IURLManager)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)1 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)1 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)1 II18nManager (com.agiletec.aps.system.services.i18n.II18nManager)1 IKeyGeneratorManager (com.agiletec.aps.system.services.keygenerator.IKeyGeneratorManager)1 IPageManager (com.agiletec.aps.system.services.page.IPageManager)1 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)1 IRoleManager (com.agiletec.aps.system.services.role.IRoleManager)1