Package org.structr.web.entity

Examples of org.structr.web.entity.Image


  }

  private Image createImageNode(final String uuid, final String name, final String contentType, final long size, final long checksum) throws FrameworkException {

    String relativeFilePath = Image.getDirectoryPath(uuid) + "/" + uuid;
    Image imageNode = app.create(Image.class,
      new NodeAttribute(GraphObject.id, uuid),
      new NodeAttribute(AbstractNode.name, name),
      new NodeAttribute(File.relativeFilePath, relativeFilePath),
      new NodeAttribute(File.contentType, contentType),
      new NodeAttribute(File.size, size),
View Full Code Here


    props.put(AbstractNode.type, imageType == null ? Image.class.getSimpleName() : imageType.getSimpleName());
    props.put(Image.isThumbnail, markAsThumbnail);
    props.put(AbstractNode.name, name);

    Image newImage = StructrApp.getInstance(securityContext).create(imageType, props);

    if (imageData != null && imageData.length > 0) {

      setFileData(newImage, imageData, contentType);
View Full Code Here

      return false;
    }

    try {

      Image img = null;

      try {
        if (source instanceof byte[]) {

          byte[] data      = (byte[]) source;
          MagicMatch match = Magic.getMagicMatch(data);
          String mimeType  = match.getMimeType();

          if (keyAndClass != null) {

            img = (Image) ImageHelper.createFile(securityContext, data, mimeType, keyAndClass.getCls());

          } else {

            ImageHelper.setImageData((Image) currentObject, data, mimeType);

          }

        } else if (source instanceof String) {

          String sourceString = (String) source;

          if (StringUtils.isNotBlank(sourceString)) {

            if (keyAndClass != null) {

              // UUID?
              if (sourceString.length() == 32) {

                img = (Image) ImageHelper.transformFile(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);
              }

              if (img == null) {

                img = (Image) ImageHelper.createFileBase64(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);

              }

            } else {

              ImageHelper.decodeAndSetFileData((Image) currentObject, sourceString);

            }
          }

        }

      } catch (Throwable t) {
        logger.log(Level.WARNING, "Cannot create image node from given data", t);
      }

      if (img != null) {

        // manual indexing of UUID needed here to avoid a 404 in the following setProperty call
        img.updateInIndex();
        currentObject.setProperty(keyAndClass.getPropertyKey(), img);
      }


    } catch (Throwable t) {
View Full Code Here

      img.setProperty(AbstractNode.name, "test-image.png");
     
      assertNotNull(img);
      assertTrue(img instanceof TestImage);

      Image tn = img.getProperty(TestImage.thumbnail);

      assertNotNull(tn);
      assertEquals(new Integer(200), tn.getWidth());
      assertEquals(new Integer(48), tn.getHeight())// cropToFit = false
      assertEquals("image/" + Thumbnail.FORMAT, tn.getContentType());
     
      tx.success();

    } catch (Exception ex) {
View Full Code Here

      Logger.getLogger(FilesTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    try (final Tx tx = app.tx()) {

      Image image1 = (Image) app.create(Image.class, "image1");
      assertNotNull(image1);
      assertEquals(FileHelper.getFolderPath(image1), "/image1");

      image1.setProperty(File.parent, folder1);
      assertEquals(FileHelper.getFolderPath(image1), "/folder1/image1");

      tx.success();

    } catch (FrameworkException ex) {
View Full Code Here

TOP

Related Classes of org.structr.web.entity.Image

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.