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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations