Search in sources :

Example 46 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class TestNavigatorWidgetConfigAction method testFailureAddExpression_2.

public void testFailureAddExpression_2() throws Throwable {
    Map<String, String> params = new HashMap<String, String>();
    params.put("pageCode", "pagina_2");
    params.put("frame", "3");
    params.put("widgetTypeCode", "leftmenu");
    params.put("navSpec", "parent.subtree(2)+abs(1).subtree(2)+current");
    params.put("specId", "3");
    params.put("specSuperLevel", "-2");
    String result = this.executeAddExpression("admin", params);
    assertEquals(Action.INPUT, result);
    ActionSupport action = this.getAction();
    assertEquals(1, action.getActionErrors().size());
    NavigatorWidgetConfigAction navAction = (NavigatorWidgetConfigAction) action;
    Widget widget = navAction.getWidget();
    assertNotNull(widget);
    ApsProperties props = widget.getConfig();
    assertEquals(0, props.size());
    assertEquals("parent.subtree(2)+abs(1).subtree(2)+current", navAction.getNavSpec());
    assertEquals(3, navAction.getExpressions().size());
}
Also used : HashMap(java.util.HashMap) Widget(com.agiletec.aps.system.services.page.Widget) ActionSupport(com.opensymphony.xwork2.ActionSupport) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 47 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class I18nDAO method loadLabelGroups.

/**
 * Carica la mappa che contiene tutte le label in tutte le lingue.
 * @return La mappa contenente tutte le label.
 */
public Map<String, ApsProperties> loadLabelGroups() {
    Connection conn = null;
    Statement stat = null;
    ResultSet res = null;
    Map<String, ApsProperties> labels = null;
    try {
        conn = this.getConnection();
        stat = conn.createStatement();
        res = stat.executeQuery(LOAD_ALL_LABELS);
        labels = this.createLabels(res);
    } catch (Throwable t) {
        _logger.error("Error loading labels", t);
        throw new RuntimeException("Error loading labels", t);
    // processDaoException(t, "Error loading label", "loadLabelMap");
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return labels;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 48 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class I18nManager method renderLabel.

@Override
public String renderLabel(String key, String renderingLang, boolean keyIfEmpty) throws ApsSystemException {
    String label = null;
    ApsProperties labelsProp = this.getLabelGroup(key);
    if (labelsProp != null) {
        label = labelsProp.getProperty(renderingLang);
        if (StringUtils.isEmpty(label)) {
            label = labelsProp.getProperty(this.getDefaultLang());
        }
    }
    if (keyIfEmpty && StringUtils.isEmpty(label)) {
        label = key;
    }
    return label;
}
Also used : ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 49 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class I18nManager method getLabel.

/**
 * Restituisce una label in base alla chiave ed alla lingua specificata.
 * @param key La chiave
 * @param langCode Il codice della lingua.
 * @return La label richiesta.
 * @throws ApsSystemException
 */
@Override
public String getLabel(String key, String langCode) throws ApsSystemException {
    String label = null;
    ApsProperties labelsProp = (ApsProperties) this.getCacheWrapper().getLabelGroups().get(key);
    if (labelsProp != null) {
        label = labelsProp.getProperty(langCode);
    }
    return label;
}
Also used : ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 50 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class I18nManager method searchLabelsKey.

/**
 * Restituisce la lista di chiavi di gruppi di labels
 * in base ai parametri segbalati.
 * @param insertedText Il testo tramite il quale effettuare la ricerca.
 * @param doSearchByKey Specifica se effettuare la ricerca sulle chiavi,
 * in base al testo inserito.
 * @param doSearchByLang Specifica se effettuare la ricerca
 * sul testo di una lingua, in base al testo inserito.
 * @param langCode Specifica la lingua della label sulla quale effettuare
 * la ricerca, in base al testo inserito.
 * @return La lista di chiavi di gruppi di labels
 * in base ai parametri segbalati.
 */
@Override
public List<String> searchLabelsKey(String insertedText, boolean doSearchByKey, boolean doSearchByLang, String langCode) {
    List<String> keys = new ArrayList<String>();
    Pattern pattern = Pattern.compile(insertedText, Pattern.CASE_INSENSITIVE + Pattern.LITERAL);
    Matcher matcher = pattern.matcher("");
    List<String> allKeys = new ArrayList<String>(this.getLabelGroups().keySet());
    for (int i = 0; i < allKeys.size(); i++) {
        String key = allKeys.get(i);
        ApsProperties properies = (ApsProperties) this.getLabelGroups().get(key);
        if (!doSearchByKey && !doSearchByLang) {
            matcher = matcher.reset(key);
            if (matcher.find()) {
                keys.add(key);
            } else {
                Enumeration<Object> langKeys = properies.keys();
                while (langKeys.hasMoreElements()) {
                    String lang = (String) langKeys.nextElement();
                    String target = properies.getProperty(lang);
                    if (this.labelMatch(target, matcher)) {
                        keys.add(key);
                        break;
                    }
                }
            }
        } else if (doSearchByKey && !doSearchByLang) {
            matcher = matcher.reset(key);
            if (matcher.find()) {
                keys.add(key);
            }
        } else if (!doSearchByKey && doSearchByLang) {
            String target = properies.getProperty(langCode);
            if (this.labelMatch(target, matcher)) {
                keys.add(key);
            }
        }
    }
    return keys;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

ApsProperties (com.agiletec.aps.util.ApsProperties)146 Widget (com.agiletec.aps.system.services.page.Widget)62 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)34 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)29 HashMap (java.util.HashMap)17 IPage (com.agiletec.aps.system.services.page.IPage)16 Lang (com.agiletec.aps.system.services.lang.Lang)14 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)10 Properties (java.util.Properties)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 List (java.util.List)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 Page (com.agiletec.aps.system.services.page.Page)6 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)6 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 ArrayList (java.util.ArrayList)6 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)6 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6