Search in sources :

Example 81 with Lang

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

the class ListAttribute method getStatus.

@Override
public Status getStatus() {
    Lang defaultLang = super.getLangManager().getDefaultLang();
    List<AttributeInterface> attributeList = this.getAttributeList(defaultLang.getCode());
    boolean valued = (null != attributeList && !attributeList.isEmpty());
    if (valued) {
        return Status.VALUED;
    } else {
        return Status.EMPTY;
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang)

Example 82 with Lang

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

the class TextAttribute method getSearchInfos.

@Override
public List<AttributeSearchInfo> getSearchInfos(List<Lang> systemLangs) {
    List<AttributeSearchInfo> infos = null;
    if (null != this.getTextMap() && this.getTextMap().size() > 0) {
        infos = new ArrayList<>();
        for (int i = 0; i < systemLangs.size(); i++) {
            Lang lang = systemLangs.get(i);
            String text = this.getTextMap().get(lang.getCode());
            if (null == text) {
                text = this.getTextMap().get(this.getDefaultLangCode());
            }
            if (null != text) {
                AttributeSearchInfo info = null;
                if (text.length() >= 255) {
                    info = new AttributeSearchInfo(text.substring(0, 254), null, null, lang.getCode());
                } else {
                    info = new AttributeSearchInfo(text, null, null, lang.getCode());
                }
                infos.add(info);
            }
        }
    }
    return infos;
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)

Example 83 with Lang

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

the class OgnlValidationRule method createContextForExpressionValidation.

protected OgnlContext createContextForExpressionValidation(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    OgnlContext context = new OgnlContext();
    Map<String, Lang> langs = new HashMap<>();
    List<Lang> langList = langManager.getLangs();
    for (int i = 0; i < langList.size(); i++) {
        Lang lang = langList.get(i);
        langs.put(lang.getCode(), lang);
    }
    context.put("langs", langs);
    context.put("attribute", attribute);
    context.put("entity", attribute.getParentEntity());
    if (tracer.isCompositeElement()) {
        context.put("parent", tracer.getParentAttribute());
    } else {
        if (tracer.isListElement() || tracer.isMonoListElement()) {
            context.put("parent", attribute.getParentEntity().getAttribute(attribute.getName()));
            context.put("index", tracer.getListIndex());
        }
        if (tracer.isListElement()) {
            context.put("listLang", tracer.getListLang());
        }
    }
    return context;
}
Also used : HashMap(java.util.HashMap) Lang(com.agiletec.aps.system.services.lang.Lang) OgnlContext(ognl.OgnlContext)

Example 84 with Lang

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

the class TextAttributeValidationRules method validate.

@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
    if (this.isEmpty()) {
        return errors;
    }
    try {
        List<Lang> langs = langManager.getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            if (!attribute.isMultilingual() && !lang.isDefault())
                continue;
            AttributeTracer textTracer = (AttributeTracer) tracer.clone();
            textTracer.setLang(lang);
            this.checkTextLengths(attribute, textTracer, lang, errors);
            this.checkRegExp(attribute, textTracer, lang, errors);
        }
    } catch (Throwable t) {
        // ApsSystemUtils.logThrowable(t, this, "validate");
        _logger.error("Error validating text attribute", t);
        throw new RuntimeException("Error validating text attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 85 with Lang

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

the class BaseEntityRenderer method convertSpecialCharacters.

protected List<TextAttributeCharReplaceInfo> convertSpecialCharacters(IApsEntity entity, String langCode) {
    List<TextAttributeCharReplaceInfo> conversions = new ArrayList<TextAttributeCharReplaceInfo>();
    Lang defaultLang = this.getLangManager().getDefaultLang();
    EntityAttributeIterator attributeIter = new EntityAttributeIterator(entity);
    while (attributeIter.hasNext()) {
        AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
        if (currAttribute instanceof ITextAttribute) {
            String attributeLangCode = langCode;
            ITextAttribute renderizable = (ITextAttribute) currAttribute;
            if (renderizable.needToConvertSpecialCharacter()) {
                String textToConvert = renderizable.getTextForLang(attributeLangCode);
                if (null == textToConvert || textToConvert.trim().length() == 0) {
                    attributeLangCode = defaultLang.getCode();
                    textToConvert = renderizable.getTextForLang(attributeLangCode);
                }
                if (null != textToConvert && textToConvert.trim().length() > 0) {
                    conversions.add(new TextAttributeCharReplaceInfo(renderizable, textToConvert, attributeLangCode));
                    String convertedText = StringEscapeUtils.escapeHtml(textToConvert);
                    renderizable.setText(convertedText, attributeLangCode);
                }
            }
        }
    }
    return conversions;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

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