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());
}
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);
}
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;
}
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;
}
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);
}
Aggregations