Search in sources :

Example 21 with Lang

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

the class LangManagerCacheWrapper method getLangs.

@Override
public List<Lang> getLangs() {
    List<Lang> langs = new ArrayList<>();
    Cache cache = this.getCache();
    List<String> codes = (List<String>) this.get(cache, LANG_CODES_CACHE_NAME, List.class);
    if (null != codes) {
        for (String code : codes) {
            Lang lang = this.get(cache, LANG_CACHE_NAME_PREFIX + code, Lang.class);
            if (lang.isDefault()) {
                langs.add(0, lang);
            } else {
                langs.add(lang);
            }
        }
    }
    return langs;
}
Also used : ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) List(java.util.List) ArrayList(java.util.ArrayList) Cache(org.springframework.cache.Cache)

Example 22 with Lang

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

the class LangManagerCacheWrapper method initCache.

@Override
public void initCache(String xmlConfig) throws ApsSystemException {
    try {
        Cache cache = this.getCache();
        this.releaseCachedObjects(cache);
        LangDOM langDom = new LangDOM(xmlConfig);
        Map<String, Lang> langMap = new HashMap<>();
        List<Lang> systemLangs = langDom.getLangs();
        for (Lang lang : systemLangs) {
            if (lang.isDefault()) {
                cache.put(LANG_DEFAULT_CACHE_NAME, lang);
            }
            langMap.put(lang.getCode(), lang);
        }
        super.insertObjectsOnCache(cache, langMap);
    } catch (Throwable t) {
        logger.error("Error loading the system langs", t);
        throw new ApsSystemException("Error loading the system langs", t);
    }
}
Also used : HashMap(java.util.HashMap) LangDOM(com.agiletec.aps.system.services.lang.LangDOM) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Cache(org.springframework.cache.Cache)

Example 23 with Lang

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

the class URLManager method getURLString.

/**
 * Crea un URL completo ad una pagina del portale a partire dalle
 * informazioni essenziali contenute nell'oggetto pageUrl passato come
 * parametro.<br>
 * In questa implementazione, l'URL è costruito come concatenazione dei
 * seguenti elementi:
 * <ul>
 * <li>parametro di configurazione PAR_APPL_BASE_URL, che rappresenta l'URL
 * base della web application così come viene visto dall'esterno; deve
 * comprendere la stringa "http://" e deve terminare con "/";</li>
 * <li>codice della lingua impostata nell'oggetto pageUrl, oppure la lingua
 * corrente, oppure la lingua di default;</li>
 * <li>se il parametro "urlStyle" è settato a "classic", codice della pagina
 * corrente impostata nell'oggetto pageUrl seguito dal suffisso ".page",
 * altrimenti, se il parametro "urlStyle" è settato a "breadcrumbs",
 * "/pages/" seguito dal'insieme del codici pagina dalla root alla pagina
 * corrente separati da "/";</li>
 * <li>eventuale query string se sull'oggetto pageUrl sono stati impostati
 * parametri.</li>
 * </ul>
 *
 * @param pageUrl L'oggetto contenente le informazioni da tradurre in URL.
 * @param reqCtx Il contesto della richiesta.
 * @return La Stringa contenente l'URL.
 * @see com.agiletec.aps.system.services.url.AbstractURLManager#getURLString(com.agiletec.aps.system.services.url.PageURL,
 * com.agiletec.aps.system.RequestContext)
 */
@Override
public String getURLString(PageURL pageUrl, RequestContext reqCtx) {
    try {
        String langCode = pageUrl.getLangCode();
        Lang lang = this.getLangManager().getLang(langCode);
        if (lang == null && null != reqCtx) {
            lang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        }
        if (lang == null) {
            lang = this.getLangManager().getDefaultLang();
        }
        String pageCode = pageUrl.getPageCode();
        IPage page = this.getPageManager().getOnlinePage(pageCode);
        if (page == null && null != reqCtx) {
            page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        }
        if (page == null) {
            page = this.getPageManager().getOnlineRoot();
        }
        HttpServletRequest request = (null != reqCtx) ? reqCtx.getRequest() : null;
        String url = this.createURL(page, lang, pageUrl.getParams(), pageUrl.isEscapeAmp(), request);
        if (null != reqCtx && this.useJsessionId()) {
            HttpServletResponse resp = reqCtx.getResponse();
            String encUrl = resp.encodeURL(url.toString());
            return encUrl;
        } else {
            return url;
        }
    } catch (Throwable t) {
        _logger.error("Error creating url", t);
        throw new RuntimeException("Error creating url", t);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 24 with Lang

use of com.agiletec.aps.system.services.lang.Lang 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 25 with Lang

use of com.agiletec.aps.system.services.lang.Lang 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)

Aggregations

Lang (com.agiletec.aps.system.services.lang.Lang)90 ArrayList (java.util.ArrayList)15 ApsProperties (com.agiletec.aps.util.ApsProperties)14 IPage (com.agiletec.aps.system.services.page.IPage)12 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)11 RequestContext (com.agiletec.aps.system.RequestContext)10 Widget (com.agiletec.aps.system.services.page.Widget)10 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)8 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)7 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HashMap (java.util.HashMap)6 ServletRequest (javax.servlet.ServletRequest)6 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)4 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)4 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)4 Category (com.agiletec.aps.system.services.category.Category)4 Properties (java.util.Properties)4 JspException (javax.servlet.jsp.JspException)4 StringField (org.apache.lucene.document.StringField)4