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
}
}
}
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);
}
}
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;
}
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("<tag value=\"æøå\"/>");
assertEquals(ValueFactory.newXml("<tag value=\"æøå\"/>"), this.htmlStripper.process(valueToProcess));
}
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));
}
Aggregations