Search in sources :

Example 1 with ValueType

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);
}
Also used : FocalPoint(com.enonic.xp.image.FocalPoint) ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 2 with ValueType

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();
}
Also used : ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 3 with ValueType

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);
}
Also used : ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 4 with ValueType

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);
}
Also used : ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 5 with ValueType

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 + "]");
    }
}
Also used : ValueType(com.enonic.xp.data.ValueType)

Aggregations

ValueType (com.enonic.xp.data.ValueType)5 Property (com.enonic.xp.data.Property)4 PropertySet (com.enonic.xp.data.PropertySet)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 FocalPoint (com.enonic.xp.image.FocalPoint)1