Search in sources :

Example 1 with ExprInfoString

use of org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString in project org.csstudio.display.builder by kasemir.

the class RulesWidgetProperty method readExpressions.

private List<ExpressionInfo<?>> readExpressions(final ModelReader model_reader, final String prop_id, final boolean prop_as_expr, final Element xml) throws Exception {
    // Replace "pvSev0" by "pvLegacySev0"?
    final boolean patch_severity = model_reader.getVersion().getMajor() < 2;
    final List<ExpressionInfo<?>> exprs = new ArrayList<>();
    final Iterable<Element> exprs_xml = XMLUtil.getChildElements(xml, "exp");
    final String tagstr = (prop_as_expr) ? "expression" : "value";
    for (final Element exp_xml : exprs_xml) {
        String bool_exp = exp_xml.getAttribute("bool_exp");
        if (bool_exp.isEmpty())
            logger.log(Level.WARNING, "Missing exp 'bool_exp'");
        if (patch_severity && bool_exp.contains("pvSev")) {
            logger.log(Level.WARNING, "Patching rule with legacy '" + bool_exp + "' into 'pvLegacySev..'");
            bool_exp = PVSEV_PATTERN.matcher(bool_exp).replaceAll("pvLegacySev$1");
        }
        final Element tag_xml = XMLUtil.getChildElement(exp_xml, tagstr);
        // Legacy case where value is used for all value expression
        final Element val_xml = (tag_xml == null) ? XMLUtil.getChildElement(exp_xml, "value") : tag_xml;
        if (prop_as_expr) {
            final String val_str = (val_xml != null) ? XMLUtil.getString(val_xml) : "";
            // if (patch_severity  &&  val_str.contains("pvSev")) ..?
            // val_str was a Javascript expression,
            // now needs to be a python expression.
            // -> Not patching for now
            exprs.add(new ExprInfoString(bool_exp, val_str));
        } else {
            final String val_str = (val_xml != null) ? XMLUtil.elementsToString(val_xml.getChildNodes(), false) : "";
            final WidgetProperty<?> val_prop = propIDToNewProp(getWidget(), prop_id, val_str);
            if (!miscUnknownPropID.getName().equals(val_prop.getName()))
                val_prop.readFromXML(model_reader, val_xml);
            exprs.add(new ExprInfoValue<>(bool_exp, val_prop));
        }
    }
    return exprs;
}
Also used : ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo)

Aggregations

ArrayList (java.util.ArrayList)1 ExprInfoString (org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString)1 ExpressionInfo (org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo)1 Element (org.w3c.dom.Element)1