Search in sources :

Example 46 with PropertyMap

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;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) PropertyMap(org.structr.core.property.PropertyMap) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Example 47 with PropertyMap

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);
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Example 48 with PropertyMap

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image)

Example 49 with PropertyMap

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);
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image) BufferedImage(java.awt.image.BufferedImage)

Example 50 with PropertyMap

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15