Search in sources :

Example 86 with Lang

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

the class CategoriesTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    ICategoryManager catManager = (ICategoryManager) ApsWebApplicationUtils.getBean(SystemConstants.CATEGORY_MANAGER, this.pageContext);
    try {
        List<SelectItem> categories = new ArrayList<SelectItem>();
        Category root = (null != this.getRoot()) ? catManager.getCategory(this.getRoot()) : null;
        if (null == root) {
            root = catManager.getRoot();
        }
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        String langCode = currentLang.getCode();
        String reqTitStyle = this.getTitleStyle();
        List<String> allowedStyles = Arrays.asList(ALLOWED_TITLE_TYPES);
        String titleStyle = (null != reqTitStyle && (allowedStyles.contains(reqTitStyle))) ? reqTitStyle : null;
        this.addSmallCategory(categories, root, langCode, titleStyle, catManager);
        this.pageContext.setAttribute(this.getVar(), categories);
    } catch (Throwable t) {
        _logger.error("Error starting tag", t);
        throw new JspException("Error starting tag", t);
    }
    return super.doStartTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) Category(com.agiletec.aps.system.services.category.Category) SelectItem(com.agiletec.aps.util.SelectItem) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext) ICategoryManager(com.agiletec.aps.system.services.category.ICategoryManager)

Example 87 with Lang

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

the class CurrentPageTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    try {
        IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        if (this.getParam() == null || this.getParam().equals(TITLE_INFO)) {
            this.extractPageTitle(page, currentLang, reqCtx);
        } else if (this.getParam().equals(CODE_INFO)) {
            this.setValue(page.getCode());
        } else if (this.getParam().equals(OWNER_INFO)) {
            this.extractPageOwner(page, reqCtx);
        } else if (this.getInfo().equals(CHILD_OF_INFO)) {
            this.extractIsChildOfTarget(page);
        } else if (this.getInfo().equals(HAS_CHILD)) {
            boolean hasChild = (page.getChildrenCodes() != null && page.getChildrenCodes().length > 0);
            this.setValue(new Boolean(hasChild).toString());
        }
        this.evalValue();
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error during tag initialization ", t);
    }
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 88 with Lang

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

the class I18nTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    RequestContext reqCtx = (RequestContext) this.pageContext.getRequest().getAttribute(RequestContext.REQCTX);
    try {
        Lang currentLang = null;
        if (reqCtx != null) {
            currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        } else {
            ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
            currentLang = langManager.getDefaultLang();
        }
        String label = this.extractLabel(currentLang);
        if (this._varName != null) {
            this.pageContext.setAttribute(this._varName, label);
        } else {
            if (this.getEscapeXml()) {
                out(this.pageContext, this.getEscapeXml(), label);
            } else {
                this.pageContext.getOut().print(label);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        throw new JspException("Error during tag initialization", t);
    }
    return super.doStartTag();
}
Also used : JspException(javax.servlet.jsp.JspException) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 89 with Lang

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

the class PageInfoTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    try {
        IPageManager pageManager = (IPageManager) ApsWebApplicationUtils.getBean(SystemConstants.PAGE_MANAGER, this.pageContext);
        IPage page = pageManager.getOnlinePage(this.getPageCode());
        if (null == page) {
            _logger.error("Required info for null page : inserted code '{}'", this.getPageCode());
        }
        if (this.getInfo() == null || this.getInfo().equals(CODE_INFO)) {
            this.setValue(page.getCode());
        } else if (this.getInfo().equals(TITLE_INFO)) {
            this.extractPageTitle(page, currentLang);
        } else if (this.getInfo().equals(URL_INFO)) {
            this.extractPageUrl(page, currentLang, reqCtx);
        } else if (this.getInfo().equals(OWNER_INFO)) {
            this.extractPageOwner(page, reqCtx);
        } else if (this.getInfo().equals(CHILD_OF_INFO)) {
            this.extractIsChildOfTarget(page);
        } else if (this.getInfo().equals(HAS_CHILD)) {
            boolean hasChild = (page.getChildrenCodes() != null && page.getChildrenCodes().length > 0);
            this._value = new Boolean(hasChild).toString();
        }
        this.evalValue();
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error during tag initialization ", t);
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) IPageManager(com.agiletec.aps.system.services.page.IPageManager) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 90 with Lang

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

the class NavigatorTarget method getTitle.

/**
 * Restituisce il titolo della pagina nella lingua corrente. Nel caso il
 * titolo nella lingua corrente sia assente, viene restituito il titolo
 * nella lingua di default.
 *
 * @return Il titolo della pagina.
 */
public String getTitle() {
    Lang lang = (Lang) this._reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    String title = this.getPage().getTitle(lang.getCode());
    if (title == null || title.trim().equals("")) {
        ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this._reqCtx.getRequest());
        title = this.getPage().getTitle(langManager.getDefaultLang().getCode());
    }
    if (title == null || title.trim().equals("")) {
        title = this.getPage().getCode();
    }
    return title;
}
Also used : ILangManager(com.agiletec.aps.system.services.lang.ILangManager) 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