Search in sources :

Example 1 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class ContentTypeMapper method serializeDefaultValue.

private void serializeDefaultValue(final MapGenerator gen, final Input input) {
    if (input.getDefaultValue() != null) {
        try {
            final Value defaultValue = InputTypes.BUILTIN.resolve(input.getInputType()).createDefaultValue(input);
            if (defaultValue != null) {
                gen.map("default");
                gen.value("value", defaultValue.getObject());
                gen.value("type", defaultValue.getType().getName());
                gen.end();
            }
        } catch (IllegalArgumentException ex) {
        // DO NOTHING
        }
    }
}
Also used : Value(com.enonic.xp.data.Value)

Example 2 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class JsonToPropertyTreeTranslator method mapValue.

private void mapValue(final PropertySet parent, final String key, final JsonNode value) {
    final Property parentProperty = parent.getProperty();
    final Input input = getInput(parentProperty, key);
    if (input == null) {
        if (this.strictMode) {
            throw new IllegalArgumentException("No mapping defined for property " + key + " with value " + resolveStringValue(value));
        }
        parent.addProperty(key, resolveCoreValue(value));
    } else {
        final InputType type = this.inputTypeResolver.resolve(input.getInputType());
        final Value mappedPropertyValue = type.createValue(resolveCoreValue(value), input.getInputTypeConfig());
        parent.addProperty(key, mappedPropertyValue);
    }
}
Also used : Input(com.enonic.xp.form.Input) InputType(com.enonic.xp.inputtype.InputType) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Example 3 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class ContentMappingConstraint method matches.

public boolean matches(final Content content) {
    final String val = trimQuotes(this.value);
    if (ID_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getId().toString());
    } else if (NAME_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getName().toString());
    } else if (PATH_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getPath().toString());
    } else if (TYPE_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getType().toString());
    } else if (DISPLAY_NAME_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getDisplayName());
    } else if (HAS_CHILDREN_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.hasChildren());
    } else if (LANGUAGE_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getLanguage() == null ? "" : content.getLanguage().toLanguageTag());
    } else if (VALID_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.isValid());
    } else if (this.id.startsWith(DATA_PROPERTY_PREFIX)) {
        final String dataPath = id.substring(DATA_PROPERTY_PREFIX.length());
        final Property prop = content.getData().getProperty(dataPath);
        if (prop == null || prop.getValue() == null) {
            return false;
        }
        final Value propertyValue = convert(val, prop.getValue().getType());
        return propertyValue != null && valueMatches(propertyValue.asString(), prop.getValue().asString());
    } else if (this.id.startsWith(XDATA_PROPERTY_PREFIX)) {
        final String dataPath = id.substring(XDATA_PROPERTY_PREFIX.length());
        final String appPrefix;
        final String mixinName;
        final String propertyName;
        final int firstIndex = dataPath.indexOf(".");
        if (firstIndex == -1) {
            appPrefix = dataPath;
            mixinName = "";
            propertyName = "";
        } else {
            appPrefix = dataPath.substring(0, firstIndex);
            final int secondIndex = dataPath.indexOf(".", firstIndex + 1);
            mixinName = secondIndex == -1 ? dataPath.substring(firstIndex + 1) : dataPath.substring(firstIndex + 1, secondIndex);
            propertyName = secondIndex == -1 ? "" : dataPath.substring(secondIndex + 1);
        }
        final PropertyTree xData = getXData(content.getAllExtraData(), appPrefix, mixinName);
        if (xData == null) {
            return false;
        }
        final Property prop = xData.getProperty(propertyName);
        if (prop == null || prop.getValue() == null) {
            return false;
        }
        final Value propertyValue = convert(val, prop.getValue().getType());
        return propertyValue != null && valueMatches(propertyValue.asString(), prop.getValue().asString());
    }
    return false;
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Example 4 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class HtmlStripperTest method processEscapedCharacters.

@Test
void processEscapedCharacters() {
    Value valueToProcess = ValueFactory.newString("<tag value=\"æøå\"/>");
    assertEquals(ValueFactory.newString("<tag value=\"æøå\"/>"), this.htmlStripper.process(valueToProcess));
    valueToProcess = ValueFactory.newXml("&lt;tag value=\"&aelig;&oslash;&aring;\"/&gt;");
    assertEquals(ValueFactory.newXml("<tag value=\"æøå\"/>"), this.htmlStripper.process(valueToProcess));
}
Also used : Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 5 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class DateTypeTest method testRelativeDefaultValue.

@Test
public void testRelativeDefaultValue() {
    final Input input = getDefaultInputBuilder(InputTypeName.DATE, "+1year -5months -36d").build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertSame(ValueTypes.LOCAL_DATE, value.getType());
    assertEquals(value.getObject(), LocalDate.now().plusYears(1).plusMonths(-5).plusDays(-36));
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Aggregations

Value (com.enonic.xp.data.Value)62 Test (org.junit.jupiter.api.Test)48 Input (com.enonic.xp.form.Input)24 Property (com.enonic.xp.data.Property)4 PropertySet (com.enonic.xp.data.PropertySet)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 InputType (com.enonic.xp.inputtype.InputType)2 Instant (java.time.Instant)2 PropertyPath (com.enonic.xp.data.PropertyPath)1 FieldSet (com.enonic.xp.form.FieldSet)1 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)1 IndexConfig (com.enonic.xp.index.IndexConfig)1 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1