use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ImageContentProcessor method updateImageMetadata.
private ExtraDatas updateImageMetadata(final EditableContent editable) {
final Media media = (Media) editable.source;
final Attachment mediaAttachment = media.getMediaAttachment();
if (mediaAttachment == null) {
return editable.extraDatas;
}
final ByteSource binary = contentService.getBinary(editable.source.getId(), mediaAttachment.getBinaryReference());
if (binary == null) {
return editable.extraDatas;
}
final BufferedImage image = toBufferedImage(binary);
final Cropping cropping = media.getCropping();
final long byteSize = mediaAttachment.getSize();
final long imageWidth;
final long imageHeight;
final long imageSize;
if (cropping == null || cropping.isUnmodified()) {
imageWidth = image.getWidth();
imageHeight = image.getHeight();
imageSize = imageWidth * imageHeight;
} else {
final BufferedImage croppedImage = cropImage(image, cropping);
imageWidth = croppedImage.getWidth();
imageHeight = croppedImage.getHeight();
imageSize = imageWidth * imageHeight;
}
ExtraData extraData = editable.extraDatas.getMetadata(MediaInfo.IMAGE_INFO_METADATA_NAME);
if (extraData != null) {
final PropertyTree xData = extraData.getData();
setLongProperty(xData, IMAGE_INFO_PIXEL_SIZE, imageSize);
setLongProperty(xData, IMAGE_INFO_IMAGE_HEIGHT, imageHeight);
setLongProperty(xData, IMAGE_INFO_IMAGE_WIDTH, imageWidth);
setLongProperty(xData, MEDIA_INFO_BYTE_SIZE, byteSize);
}
return editable.extraDatas;
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ImageContentProcessor method fillComputedFormItems.
private void fillComputedFormItems(Collection<ExtraData> extraDataList, MediaInfo mediaInfo, final CreateAttachment sourceAttachment) {
for (ExtraData extraData : extraDataList) {
final PropertyTree xData = extraData.getData();
if (IMAGE_INFO.equals(extraData.getName().getLocalName())) {
final Collection<String> tiffImageLengths = mediaInfo.getMetadata().get("tiffImagelength");
final Collection<String> tiffImageWidths = mediaInfo.getMetadata().get("tiffImagewidth");
if (tiffImageLengths.size() > 0 && tiffImageWidths.size() > 0) {
final long tiffImageLength = Long.parseLong(tiffImageLengths.toArray()[0].toString());
final long tiffImageWidth = Long.parseLong(tiffImageWidths.toArray()[0].toString());
xData.setLong(IMAGE_INFO_PIXEL_SIZE, tiffImageLength * tiffImageWidth);
xData.setLong(IMAGE_INFO_IMAGE_HEIGHT, tiffImageLength);
xData.setLong(IMAGE_INFO_IMAGE_WIDTH, tiffImageWidth);
}
if (sourceAttachment != null) {
try {
long mediaInfoByteSize = sourceAttachment.getByteSource().size();
xData.setLong(MEDIA_INFO_BYTE_SIZE, mediaInfoByteSize);
} catch (IOException e) {
throw Exceptions.newRuntime("Failed to read BufferedImage from InputStream").withCause(e);
}
}
}
}
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class PageDefaultValuesProcessor method applyComponentDefaultValues.
private void applyComponentDefaultValues(final DescriptorBasedComponent cmp) {
if (cmp.getDescriptor() == null) {
return;
}
final Form cmpForm;
if (cmp instanceof PartComponent) {
final PartDescriptor partDescriptor = partDescriptorService.getByKey(cmp.getDescriptor());
cmpForm = partDescriptor.getConfig();
} else {
final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(cmp.getDescriptor());
cmpForm = layoutDescriptor.getConfig();
}
if (cmpForm != null) {
final PropertyTree cmpData = cmp.getConfig();
formDefaultValuesProcessor.setDefaultValues(cmpForm, cmpData);
}
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ContentDataSerializer method toUpdateNodeData.
public PropertyTree toUpdateNodeData(final UpdateContentTranslatorParams params) {
final PropertyTree newPropertyTree = new PropertyTree();
final PropertySet contentAsData = newPropertyTree.getRoot();
final Content content = params.getEditedContent();
addMetadata(contentAsData, content, params.getModifier());
contentAsData.addSet(DATA, content.getData().getRoot().copy(contentAsData.getTree()));
if (content.hasExtraData()) {
extraDataSerializer.toData(content.getAllExtraData(), contentAsData);
}
final Attachments attachments = mergeExistingAndUpdatedAttachments(content.getAttachments(), params);
applyAttachmentsAsData(attachments, contentAsData);
if (content.hasPage()) {
pageDataSerializer.toData(content.getPage(), contentAsData);
}
addProcessedReferences(contentAsData, content.getProcessedReferences());
return newPropertyTree;
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class FlattenedPageDataUpgraderTest method test.
private void test(final String oldJsonFile, final String newJsonFile) throws Exception {
final JsonNode oldPageComponents = loadJson(oldJsonFile);
final JsonNode newPageComponents = loadJson(newJsonFile);
final PropertyTree oldData = new JsonToPropertyTreeTranslator().translate(oldPageComponents);
final PropertyTree newData = new JsonToPropertyTreeTranslator().translate(newPageComponents);
final HashMap<String, String> templateControllerMap = new HashMap<>();
templateControllerMap.put("templateId", "com.enonic.app.features:main");
FlattenedPageDataUpgrader.create().templateControllerMap(templateControllerMap).build().upgrade(oldData);
// using string comparison because PropertyTree entries are same but might have different value type
assertEquals(newData.toString(), oldData.toString());
}
Aggregations