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