Search in sources :

Example 71 with Lang

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

the class IndexerDAO method createDocument.

/**
 * Crea un oggetto Document pronto per l'indicizzazione da un oggetto Content.
 * @param entity Il contenuto dal quale ricavare il Document.
 * @return L'oggetto Document ricavato dal contenuto.
 * @throws ApsSystemException In caso di errore
 */
protected Document createDocument(IApsEntity entity) throws ApsSystemException {
    Document document = new Document();
    document.add(new StringField(CONTENT_ID_FIELD_NAME, entity.getId(), Field.Store.YES));
    document.add(new TextField(CONTENT_TYPE_FIELD_NAME, entity.getTypeCode(), Field.Store.YES));
    document.add(new StringField(CONTENT_GROUP_FIELD_NAME, entity.getMainGroup(), Field.Store.YES));
    Iterator<String> iterGroups = entity.getGroups().iterator();
    while (iterGroups.hasNext()) {
        String groupName = (String) iterGroups.next();
        document.add(new StringField(CONTENT_GROUP_FIELD_NAME, groupName, Field.Store.YES));
    }
    try {
        EntityAttributeIterator attributesIter = new EntityAttributeIterator(entity);
        while (attributesIter.hasNext()) {
            AttributeInterface currentAttribute = (AttributeInterface) attributesIter.next();
            List<Lang> langs = this.getLangManager().getLangs();
            for (int i = 0; i < langs.size(); i++) {
                Lang currentLang = (Lang) langs.get(i);
                this.indexAttribute(document, currentAttribute, currentLang);
            }
        }
        List<Category> categories = entity.getCategories();
        if (null != categories && !categories.isEmpty()) {
            for (int i = 0; i < categories.size(); i++) {
                Category category = categories.get(i);
                this.indexCategory(document, category);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error creating document", t);
        throw new ApsSystemException("Error creating document", t);
    }
    return document;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.apache.lucene.document.Document) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) ResourceAttributeInterface(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 72 with Lang

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

the class IndexerDAO method indexAttribute.

private void indexAttribute(Document document, AttributeInterface attribute, Lang lang) throws ApsSystemException {
    attribute.setRenderingLang(lang.getCode());
    if (attribute instanceof IndexableAttributeInterface) {
        String valueToIndex = ((IndexableAttributeInterface) attribute).getIndexeableFieldValue();
        String indexingType = attribute.getIndexingType();
        String fieldName = lang.getCode();
        if (attribute instanceof ResourceAttributeInterface) {
            fieldName += IIndexerDAO.ATTACHMENT_FIELD_SUFFIX;
        }
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_UNSTORED.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.NO));
        }
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_TEXT.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.YES));
        }
    }
    if (attribute.isSearchable()) {
        List<Lang> langs = new ArrayList<Lang>();
        langs.add(lang);
        AttributeTracer tracer = new AttributeTracer();
        tracer.setLang(lang);
        String name = tracer.getFormFieldName(attribute);
        List<AttributeSearchInfo> searchInfos = attribute.getSearchInfos(langs);
        if (null != searchInfos) {
            for (int i = 0; i < searchInfos.size(); i++) {
                AttributeSearchInfo info = searchInfos.get(i);
                Field field = null;
                if (null != info.getDate()) {
                    field = new TextField(name, DateTools.timeToString(info.getDate().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES);
                } else if (null != info.getBigDecimal()) {
                    field = new IntField(name, info.getBigDecimal().intValue(), Field.Store.YES);
                } else {
                    field = new TextField(name, info.getString(), Field.Store.YES);
                }
                document.add(field);
            }
        }
    }
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) ResourceAttributeInterface(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) IntField(org.apache.lucene.document.IntField) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) IntField(org.apache.lucene.document.IntField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)

Example 73 with Lang

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

the class ContentListTag method addMultilanguageWidgetParameter.

protected void addMultilanguageWidgetParameter(ApsProperties config, String widgetParamPrefix, Lang currentLang, String var) {
    if (null == var || null == config)
        return;
    String paramValue = config.getProperty(widgetParamPrefix + "_" + currentLang.getCode());
    if (null == paramValue) {
        ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
        Lang defaultLang = langManager.getDefaultLang();
        paramValue = config.getProperty(widgetParamPrefix + "_" + defaultLang.getCode());
    }
    if (null != paramValue) {
        this.pageContext.setAttribute(var, paramValue);
    }
}
Also used : ILangManager(com.agiletec.aps.system.services.lang.ILangManager) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 74 with Lang

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

the class ContentListTag method extractExtraWidgetParameters.

protected void extractExtraWidgetParameters(RequestContext reqCtx) {
    try {
        Widget currentWidget = (Widget) reqCtx.getExtraParam((SystemConstants.EXTRAPAR_CURRENT_WIDGET));
        ApsProperties config = (null != currentWidget) ? currentWidget.getConfig() : null;
        if (null != config) {
            Lang currentLang = (Lang) reqCtx.getExtraParam((SystemConstants.EXTRAPAR_CURRENT_LANG));
            this.addMultilanguageWidgetParameter(config, IContentListWidgetHelper.WIDGET_PARAM_TITLE, currentLang, this.getTitleVar());
            this.addMultilanguageWidgetParameter(config, IContentListWidgetHelper.WIDGET_PARAM_PAGE_LINK_DESCR, currentLang, this.getPageLinkDescriptionVar());
            if (null != this.getPageLinkVar()) {
                String pageLink = config.getProperty(IContentListWidgetHelper.WIDGET_PARAM_PAGE_LINK);
                if (null != pageLink) {
                    this.pageContext.setAttribute(this.getPageLinkVar(), pageLink);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting extra parameters", t);
    }
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) Lang(com.agiletec.aps.system.services.lang.Lang) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 75 with Lang

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

the class AbstractResourceAttribute method getReferences.

@Override
public List<CmsAttributeReference> getReferences(List<Lang> systemLangs) {
    List<CmsAttributeReference> refs = new ArrayList<>();
    for (int i = 0; i < systemLangs.size(); i++) {
        Lang lang = systemLangs.get(i);
        ResourceInterface res = this.getResource(lang.getCode());
        if (null != res) {
            CmsAttributeReference ref = new CmsAttributeReference(null, null, res.getId());
            refs.add(ref);
        }
    }
    return refs;
}
Also used : ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference)

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