Search in sources :

Example 26 with Lang

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

Example 27 with Lang

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

the class CurrentUserProfileAction method addLabelGroups.

protected void addLabelGroups(String key, String defaultValue) throws ApsSystemException {
    try {
        ApsProperties properties = new ApsProperties();
        Lang defaultLang = super.getLangManager().getDefaultLang();
        properties.put(defaultLang.getCode(), defaultValue);
        this.getI18nManager().addLabelGroup(key, properties);
    } catch (Throwable t) {
        _logger.error("Error adding label groups - key '{}'", key, t);
        // ApsSystemUtils.logThrowable(t, this, "addLabelGroups");
        throw new RuntimeException("Error adding label groups - key '" + key + "'", t);
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 28 with Lang

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

the class DataObjectActionHelper method createActivityStreamInfo.

@Override
public ActivityStreamInfo createActivityStreamInfo(DataObject dataobject, int strutsAction, boolean addLink) {
    ActivityStreamInfo asi = new ActivityStreamInfo();
    asi.setActionType(strutsAction);
    Lang defaultLang = this.getLangManager().getDefaultLang();
    Properties titles = new Properties();
    titles.setProperty(defaultLang.getCode(), (null != dataobject.getDescription()) ? dataobject.getDescription() : "-");
    asi.setObjectTitles(titles);
    if (addLink) {
        asi.setLinkNamespace("/do/dataobject");
        asi.setLinkActionName("edit");
        asi.addLinkParameter("dataId", dataobject.getId());
        asi.setLinkAuthGroup(dataobject.getMainGroup());
        asi.setLinkAuthPermission(Permission.CONTENT_EDITOR);
    }
    List<String> groupCodes = new ArrayList<String>();
    if (null != dataobject.getMainGroup()) {
        groupCodes.addAll(dataobject.getGroups());
    }
    groupCodes.add(dataobject.getMainGroup());
    asi.setGroups(groupCodes);
    return asi;
}
Also used : ActivityStreamInfo(org.entando.entando.aps.system.services.actionlog.model.ActivityStreamInfo) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) Properties(java.util.Properties)

Example 29 with Lang

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

the class ContentListViewerWidgetAction method validateTitle.

protected void validateTitle() {
    String titleParamPrefix = IContentListWidgetHelper.WIDGET_PARAM_TITLE + "_";
    if (this.isMultilanguageParamValued(titleParamPrefix)) {
        Lang defaultLang = this.getLangManager().getDefaultLang();
        String defaultTitleParam = titleParamPrefix + defaultLang.getCode();
        String defaultTitle = this.getWidget().getConfig().getProperty(defaultTitleParam);
        if (defaultTitle == null || defaultTitle.length() == 0) {
            String[] args = { defaultLang.getDescr() };
            this.addFieldError(defaultTitleParam, this.getText("error.widget.listViewer.defaultLangTitle.required", args));
        }
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang)

Example 30 with Lang

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

the class AbstractMultiLangAttributeManager method updateAttribute.

@Override
protected void updateAttribute(AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request) {
    List<Lang> langs = this.getLangManager().getLangs();
    for (int i = 0; i < langs.size(); i++) {
        Lang currentLang = langs.get(i);
        tracer.setLang(currentLang);
        String value = this.getValueFromForm(attribute, tracer, request);
        // TODO PAY ATTENTION TO THIS CHECK
        if (value != null) {
            if (value.trim().length() == 0) {
                value = null;
            }
            this.setValue(attribute, currentLang, value);
        }
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang)

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