Ejemplo n.º 1
0
  /**
   * Creates a ProductImage.
   *
   * @param bean the bean to retrieve the image for.
   */
  public ProductImage(final ProductBean bean) {
    if (bean != null) {
      description = bean.getShortTitle();
      String name = bean.getImage();

      if (name != null) {
        InputStream in =
            Thread.currentThread().getContextClassLoader().getResourceAsStream(IMAGE_PATH + name);

        if (in != null) {
          try {
            imageBytes = StreamUtil.getBytes(in);
            in.close();
          } catch (IOException ex) {
            log.error("Cannot load product image.", ex);
          }

          String type = name.substring(name.lastIndexOf('.') + 1).toLowerCase();

          if ("jpg".equals(type)) {
            mimeType = "image/jpeg";
          } else {
            mimeType = "image/" + type;
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testGetInputStream() throws IOException {
    WFileWidget widget = new WFileWidget();
    setActiveContext(createUIContext());

    Assert.assertNull("Stream data should be null by default", widget.getInputStream());

    // Set file on widget
    widget.setData(TEST_FILE_ITEM_WRAP);
    InputStream stream = widget.getInputStream();
    byte[] readBytes = StreamUtil.getBytes(stream);
    Assert.assertTrue("Incorrect stream data", Arrays.equals(TEST_FILE_ITEM.get(), readBytes));
  }