use of com.enonic.xp.data.ValueType in project xp by enonic.
the class Media method getFocalPoint.
public FocalPoint getFocalPoint() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return FocalPoint.DEFAULT;
}
final ValueType mediaPropertyType = mediaProperty.getType();
if (!mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
return FocalPoint.DEFAULT;
}
final PropertySet mediaData = getData().getSet(ContentPropertyNames.MEDIA);
final PropertySet focalPointData = mediaData.getSet(ContentPropertyNames.MEDIA_FOCAL_POINT);
if (focalPointData == null) {
return FocalPoint.DEFAULT;
}
final Double focalX = focalPointData.getDouble(ContentPropertyNames.MEDIA_FOCAL_POINT_X);
final Double focalY = focalPointData.getDouble(ContentPropertyNames.MEDIA_FOCAL_POINT_Y);
if (focalX == null || focalY == null) {
return FocalPoint.DEFAULT;
}
return new FocalPoint(focalX, focalY);
}
use of com.enonic.xp.data.ValueType in project xp by enonic.
the class Media method getCropping.
public Cropping getCropping() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return null;
}
final ValueType mediaPropertyType = mediaProperty.getType();
if (!mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
return null;
}
final PropertySet mediaData = getData().getSet(ContentPropertyNames.MEDIA);
final PropertySet croppingData = mediaData.getSet(ContentPropertyNames.MEDIA_CROPPING);
if (croppingData == null) {
return null;
}
final Double top = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_TOP);
final Double left = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_LEFT);
final Double bottom = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_BOTTOM);
final Double right = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_RIGHT);
final Double zoom = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_ZOOM);
if (left == null || top == null || bottom == null || right == null) {
return null;
}
// TODO The values stored in top, left, bottom and right are not the correct values
final double fixedTop = top / zoom;
final double fixedLeft = left / zoom;
final double fixedBottom = bottom / zoom;
final double fixedRight = right / zoom;
return Cropping.create().zoom(zoom).top(fixedTop).left(fixedLeft).bottom(fixedBottom).right(fixedRight).build();
}
use of com.enonic.xp.data.ValueType in project xp by enonic.
the class Media method getMediaAttachment.
public Attachment getMediaAttachment() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return null;
}
final ValueType mediaPropertyType = mediaProperty.getType();
final String mediaAttachmentName;
if (mediaPropertyType.equals(ValueTypes.STRING)) {
// backwards compatibility
mediaAttachmentName = getData().getString(ContentPropertyNames.MEDIA);
} else if (mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
final PropertySet mediaData = getData().getSet(ContentPropertyNames.MEDIA);
mediaAttachmentName = mediaData.getString(ContentPropertyNames.MEDIA_ATTACHMENT);
} else {
return null;
}
if (mediaAttachmentName == null) {
return null;
}
return getAttachments().byName(mediaAttachmentName);
}
use of com.enonic.xp.data.ValueType in project xp by enonic.
the class Media method getOrientationFromPropertySet.
private ImageOrientation getOrientationFromPropertySet() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return null;
}
final ValueType mediaPropertyType = mediaProperty.getType();
if (!mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
return null;
}
final PropertySet mediaData = mediaProperty.getSet();
if (mediaData == null) {
return null;
}
if (!mediaData.hasProperty(ContentPropertyNames.ORIENTATION)) {
return null;
}
final String orientationValue = mediaData.getString(ContentPropertyNames.ORIENTATION);
if (!ImageOrientation.isValid(orientationValue)) {
return null;
}
return ImageOrientation.from(orientationValue);
}
use of com.enonic.xp.data.ValueType in project xp by enonic.
the class XmlNodeSerializer method serializeProperty.
private void serializeProperty(final Property value) {
final ValueType type = value.getType();
final String name = value.getName();
if (type.equals(ValueTypes.BOOLEAN)) {
serializeProperty("boolean", name, value.getBoolean());
} else if (type.equals(ValueTypes.STRING)) {
serializeProperty("string", name, value.getString());
} else if (type.equals(ValueTypes.DOUBLE)) {
serializeProperty("double", name, value.getDouble());
} else if (type.equals(ValueTypes.LONG)) {
serializeProperty("long", name, value.getLong());
} else if (type.equals(ValueTypes.XML)) {
serializeProperty("xml", name, value.getString());
} else if (type.equals(ValueTypes.GEO_POINT)) {
serializeProperty("geoPoint", name, value.getString());
} else if (type.equals(ValueTypes.DATE_TIME)) {
serializeProperty("dateTime", name, toStringValue(value.getInstant()));
} else if (type.equals(ValueTypes.LOCAL_DATE_TIME)) {
serializeProperty("localDateTime", name, toStringValue(value.getLocalDateTime()));
} else if (type.equals(ValueTypes.LOCAL_TIME)) {
serializeProperty("localTime", name, toStringValue(value.getLocalTime()));
} else if (type.equals(ValueTypes.LOCAL_DATE)) {
serializeProperty("localDate", name, toStringValue(value.getLocalDate()));
} else if (type.equals(ValueTypes.REFERENCE)) {
serializeProperty("reference", name, value.getReference());
} else if (type.equals(ValueTypes.LINK)) {
serializeProperty("link", name, value.getLink());
} else if (type.equals(ValueTypes.BINARY_REFERENCE)) {
serializeProperty("binaryReference", name, value.getBinaryReference());
} else if (type.equals(ValueTypes.PROPERTY_SET)) {
serializePropertySet(value);
} else {
throw new IllegalArgumentException("Unknown property type [" + type + "]");
}
}
Aggregations