Search in sources :

Example 21 with Binary

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

the class ToSecureImage method generateImage.

private Binary generateImage() {
    try {
        BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) temp.getGraphics();
        char[] characters = str.toCharArray();
        int xpos = 0;
        int ypos = 0;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(Color.white);
        g.fillRect(0, 0, width, height);
        for (int i = 0; i < characters.length; i++) {
            String s = new String(new char[] { characters[i] });
            // Font f = new Font("Serif", Font.BOLD, 14 + rnd.nextInt(12));
            Font f = new Font("Serif", Font.BOLD, 20);
            double bi_width = f.getStringBounds(s, g.getFontRenderContext()).getWidth();
            double bi_height = f.getStringBounds(s, g.getFontRenderContext()).getHeight() / 1.6;
            // final_height = 30;
            BufferedImage bi = new BufferedImage(2 * (int) Math.ceil(bi_width), 2 * (int) Math.ceil(bi_height), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            // g2.setColor(new Color(rnd.nextInt(255), rnd.nextInt(180), rnd.nextInt(180)));
            g2.setColor(Color.black);
            boolean pos = rnd.nextBoolean();
            int sign = pos ? 1 : -1;
            AffineTransform rotate = AffineTransform.getRotateInstance(sign * rnd.nextDouble() / 2d, bi.getWidth() / 2, bi.getHeight() / 2);
            g2.transform(rotate);
            g2.setFont(f);
            g2.drawString(s, (int) Math.floor(bi_width / 2), (int) Math.ceil(bi_height * 1.5));
            g.drawImage(bi, xpos, ypos, observer);
            double xbounds = f.getStringBounds(s, g.getFontRenderContext()).getWidth() + 4;
            xpos += xbounds;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        for (int i = 0; i < 3; i++) {
            g.setColor(new Color(rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat() / 1.2f));
            g.drawLine(0, rnd.nextInt(500), width, -1 * rnd.nextInt(500));
            g.drawLine(width, -1 * rnd.nextInt(50), 0, rnd.nextInt(50));
        }
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        BufferedImage finalImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D fg = (Graphics2D) finalImg.getGraphics();
        fg.drawImage(temp, 0, 0, null);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ImageIO.write(finalImg, "png", bout);
        byte[] data = bout.toByteArray();
        bout.flush();
        bout.close();
        Binary b = new Binary(data);
        return b;
    } catch (Exception e) {
        logger.error("Error: ", e);
    }
    return null;
}
Also used : Color(java.awt.Color) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Graphics2D(java.awt.Graphics2D) AffineTransform(java.awt.geom.AffineTransform) Binary(com.dexels.navajo.document.types.Binary)

Example 22 with Binary

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

the class ToBinaryFromPath method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    Object o = getOperand(0);
    String s = (String) o;
    try {
        java.io.File u = new java.io.File(s);
        Binary b = new Binary(u);
        return b;
    } catch (MalformedURLException e) {
        throw new TMLExpressionException("Bad url in function ToBinaryFromPath: " + s, e);
    } catch (IOException e) {
        throw new TMLExpressionException("Error opening url in function ToBinaryFromPath: " + s, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 23 with Binary

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

the class XMLStreamMap method main.

public static void main(String[] args) throws UserException, MappableException, FileNotFoundException, IOException {
    XMLStreamMap map = new XMLStreamMap();
    map.load(null);
    map.setIndent(1);
    map.setStartElement("TOP");
    map.setNewline(true);
    for (int i = 0; i < 10000000; i++) {
        map.setStartElement("LEVEL_ONE");
        map.setAttribute("code", "" + i);
        map.setNewline(true);
        map.setStartElement("LEVEL_TWO");
        map.setNewline(true);
        map.setStartElement("LEVEL_THREE");
        map.setEndElement(true);
        map.setEndElement(true);
        map.setEndElement(true);
        if (i % 1000 == 0) {
            logger.info("at: " + i);
        }
    }
    map.setEndElement(true);
    Binary content = map.getContent();
    content.write(new FileOutputStream("c:/serial-xml.xml"));
    logger.info("done..");
}
Also used : FileOutputStream(java.io.FileOutputStream) Binary(com.dexels.navajo.document.types.Binary)

Example 24 with Binary

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

the class XMLStreamMap method load.

// @Override
@Override
public void load(Access access) throws MappableException, UserException {
    try {
        content = new Binary();
        OutputStream ob = content.getOutputStream();
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(ob, "UTF8");
        xtw = xof.createXMLStreamWriter(out);
        xtw.writeStartDocument("UTF-8", "1.0");
        xtw.setPrefix("", docSpecUrl);
        xtw.writeCharacters("\n");
    } catch (Exception e) {
        throw new UserException(450, e.getMessage());
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 25 with Binary

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

the class XMLMap method main.

public static void main(String[] args) throws Exception {
    XMLMap xml = new XMLMap();
    xml.setStart("xml");
    TagMap district = new TagMap();
    district.setName("district");
    xml.setChild(district);
    district.setName("DISTRIKTJE");
    district.setName("WERKT DIT NOG STEEDS");
    logger.info("child = {}", xml.getChildTag("district", 0));
    TagMap n = new TagMap();
    n.setName("apenoot");
    n.setText("Achterlijke");
    district.setChild(n);
    Binary b = xml.getContent();
    xml.setChildName("district");
    TagMap kind = xml.getChild();
    logger.info("kind = {}", kind.getName());
    StringWriter sw = new StringWriter();
    b.writeBase64(sw);
    logger.info("Result: {}", sw);
}
Also used : StringWriter(java.io.StringWriter) Binary(com.dexels.navajo.document.types.Binary) TagMap(com.dexels.navajo.adapter.xmlmap.TagMap)

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