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