Search in sources :

Example 86 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TestBinary method testMimeDetection3.

@Test
// Ignore until we find a proper fix for this problem...
@Ignore
public void testMimeDetection3() throws IOException {
    // File-based test - no sandbox mode
    NavajoFactory.getInstance().setSandboxMode(false);
    URL url = this.getClass().getResource("doc2.odt");
    Binary binaryx = new Binary(new File(url.getFile()));
    Assert.assertEquals("application/vnd.oasis.opendocument.text", binaryx.guessContentType());
}
Also used : Binary(com.dexels.navajo.document.types.Binary) File(java.io.File) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 87 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TestBinary method testLazyFileBinary.

@Test
public void testLazyFileBinary() throws IOException {
    Binary b1 = new Binary(getClass().getResourceAsStream("binary1.txt"));
    File temp = File.createTempFile("junit", "binary");
    temp.deleteOnExit();
    FileOutputStream fos = new FileOutputStream(temp);
    b1.write(fos);
    fos.close();
    Binary b2 = new Binary(temp, true);
    Assert.assertEquals(7, b2.getData().length);
}
Also used : FileOutputStream(java.io.FileOutputStream) Binary(com.dexels.navajo.document.types.Binary) File(java.io.File) Test(org.junit.Test)

Example 88 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class GetLogoImage method createTextImage.

private final Binary createTextImage(String text) {
    Binary result = new Binary();
    int fontsize = 8;
    int string_width = 0;
    Font f = null;
    Rectangle2D stringbounds = new Rectangle2D.Double(0.0, 0.0, 0.0, 0.0);
    JComponent c = new JLabel();
    while (string_width < width - 10 && stringbounds.getHeight() < (0.66 * height)) {
        fontsize++;
        f = new Font("Dialog", Font.BOLD, fontsize);
        FontMetrics fm = c.getFontMetrics(f);
        string_width = fm.stringWidth(text);
        stringbounds = fm.getStringBounds(text, null);
    }
    BufferedImage text_target = new BufferedImage(width, (int) stringbounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D text_targetGraphics = text_target.createGraphics();
    text_targetGraphics.setFont(f);
    text_targetGraphics.setColor(Color.black);
    text_targetGraphics.drawString(text, width / 2 - (int) (stringbounds.getWidth() / 2), (int) (-stringbounds.getY() + 1));
    text_target = getBlurFilter(2, 0).filter(text_target, null);
    text_target = getBlurFilter(0, 2).filter(text_target, null);
    BufferedImage target = new BufferedImage(width, (int) stringbounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D targetGraphics = target.createGraphics();
    targetGraphics.setColor(Color.white);
    targetGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    targetGraphics.setFont(f);
    targetGraphics.drawImage(text_target, 0, 0, text_target.getWidth(), text_target.getHeight(), null);
    targetGraphics.drawString(text, width / 2 - (int) (stringbounds.getWidth() / 2), (int) (-stringbounds.getY() + 1));
    BufferedImage reflection = createReflection(target);
    OutputStream out = result.getOutputStream();
    try {
        ImageIO.write(reflection, "png", out);
        out.close();
    } catch (Exception e) {
    }
    result.setMimeType(result.guessContentType());
    return result;
}
Also used : FontMetrics(java.awt.FontMetrics) OutputStream(java.io.OutputStream) Rectangle2D(java.awt.geom.Rectangle2D) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Binary(com.dexels.navajo.document.types.Binary) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Graphics2D(java.awt.Graphics2D)

Example 89 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class EncryptBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String result = null;
    String key = (String) getOperand(0);
    Binary image = (Binary) getOperand(1);
    try {
        Security s = new Security(key);
        result = s.encrypt(image).replace("\n", "");
    } catch (Exception e) {
        throw new TMLExpressionException(e.getMessage());
    }
    return result;
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Security(com.dexels.navajo.functions.security.Security) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 90 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class EncryptBinary method main.

public static void main(String[] args) throws Exception {
    EncryptBinary e = new EncryptBinary();
    e.reset();
    e.insertStringOperand("BBFW06E");
    e.insertBinaryOperand(new Binary("Apenoot".getBytes()));
    String result = (String) e.evaluate();
    System.err.println("result: " + result);
}
Also used : Binary(com.dexels.navajo.document.types.Binary)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6