use of org.structr.core.property.PropertyMap in project structr by structr.
the class FileHelper method transformFile.
/**
* Transform an existing file into the target class.
*
* @param <T>
* @param securityContext
* @param uuid
* @param fileType
* @return transformed file
* @throws FrameworkException
* @throws IOException
*/
public static <T extends File> T transformFile(final SecurityContext securityContext, final String uuid, final Class<T> fileType) throws FrameworkException, IOException {
AbstractFile existingFile = getFileByUuid(securityContext, uuid);
if (existingFile != null) {
existingFile.unlockSystemPropertiesOnce();
existingFile.setProperties(securityContext, new PropertyMap(AbstractNode.type, fileType == null ? File.class.getSimpleName() : fileType.getSimpleName()));
existingFile = getFileByUuid(securityContext, uuid);
return (T) (fileType != null ? fileType.cast(existingFile) : (File) existingFile);
}
return null;
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class FileHelper method setFileProperties.
/**
* Set the contentType, checksum, size and version properties of the given fileNode
*
* @param file
* @param contentType if null, try to auto-detect content type
* @throws FrameworkException
* @throws IOException
*/
public static void setFileProperties(final File file, final String contentType) throws IOException, FrameworkException {
final java.io.File fileOnDisk = file.getFileOnDisk(false);
final PropertyMap map = new PropertyMap();
map.put(StructrApp.key(File.class, "contentType"), contentType != null ? contentType : FileHelper.getContentMimeType(fileOnDisk, file.getProperty(File.name)));
map.put(StructrApp.key(File.class, "size"), FileHelper.getSize(fileOnDisk));
map.put(StructrApp.key(File.class, "version"), 1);
map.putAll(getChecksums(file, fileOnDisk));
file.setProperties(file.getSecurityContext(), map);
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class ImageHelper method createImageNode.
/**
* Create a new image node from the given image data
*
* @param securityContext
* @param imageData
* @param contentType
* @param imageType defaults to Image.class if null
* @param name
* @param markAsThumbnail
* @return image
* @throws FrameworkException
* @throws IOException
*/
public static Image createImageNode(final SecurityContext securityContext, final byte[] imageData, final String contentType, final Class<? extends Image> imageType, final String name, final boolean markAsThumbnail) throws FrameworkException, IOException {
final PropertyMap props = new PropertyMap();
props.put(AbstractNode.type, imageType == null ? Image.class.getSimpleName() : imageType.getSimpleName());
props.put(StructrApp.key(Image.class, "isThumbnail"), markAsThumbnail);
props.put(AbstractNode.name, name);
final Image newImage = StructrApp.getInstance(securityContext).create(imageType, props);
if (imageData != null && imageData.length > 0) {
setFileData(newImage, imageData, contentType);
}
return newImage;
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class ImageHelper method updateMetadata.
/**
* Update width and height
*
* @param image the image
* @param fis file input stream
* @throws FrameworkException
*/
public static void updateMetadata(final File image, final InputStream fis) throws FrameworkException {
try (final InputStream is = fis) {
final BufferedImage source = ImageIO.read(is);
if (source != null) {
final int sourceWidth = source.getWidth();
final int sourceHeight = source.getHeight();
final PropertyMap map = new PropertyMap();
map.put(StructrApp.key(Image.class, "width"), sourceWidth);
map.put(StructrApp.key(Image.class, "height"), sourceHeight);
map.put(StructrApp.key(Image.class, "orientation"), ImageHelper.getOrientation(image));
image.setProperties(image.getSecurityContext(), map);
}
} catch (IOException ex) {
logger.warn("Unable to read image data", ex);
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class ImageHelper method createImage.
/**
* Create a new image node from the given image data
*
* @param securityContext
* @param imageStream
* @param contentType
* @param imageType defaults to Image.class if null
* @param name
* @param markAsThumbnail
* @return image
* @throws FrameworkException
* @throws IOException
*/
public static Image createImage(final SecurityContext securityContext, final InputStream imageStream, final String contentType, final Class<? extends Image> imageType, final String name, final boolean markAsThumbnail) throws FrameworkException, IOException {
final PropertyMap props = new PropertyMap();
props.put(AbstractNode.type, imageType == null ? Image.class.getSimpleName() : imageType.getSimpleName());
props.put(StructrApp.key(Image.class, "isThumbnail"), markAsThumbnail);
props.put(AbstractNode.name, name);
final Image newImage = StructrApp.getInstance(securityContext).create(imageType, props);
setFileData(newImage, imageStream, contentType);
return newImage;
}
Aggregations