package org.madore.damlengine; import org.w3c.dom.*; public final class TodoSmileyElement extends TodoDefaultElement { public enum Type { // Originally :-) SMILE("smile", "\u263A\uFE0F", "Smile", "Sourire"), // Originally ;-) WINK("wink", new String(Character.toChars(0x1F609)), "Wink", "Clin d'\u0153il"), // Originally :-o SURPRISED("surprised", new String(Character.toChars(0x1F632)), "Surprised", "Surpris"), // Originally :-( SAD("sad", "\u2639\uFE0F", "Sad", "Triste"), // Originally 8-) COOL("cool", new String(Character.toChars(0x1F60E)), "Cool", "Cool"), // Originally :-D BIGGRIN("biggrin", new String(Character.toChars(0x1F601)), "Big grin", "Grand sourire"), // Originally :-S CONFUSED("confused", new String(Character.toChars(0x1F615)), "Confused", "Embrouill\u00e9"), // Originally %-) CRAZY("crazy", new String(Character.toChars(0x1F92A)), "Crazy", "Fou"), // Originally :-| NEUTRAL("neutral", new String(Character.toChars(0x1F610)), "Non-grin", "Sans sourire"), // Formerly "twisted", originally 8-> now thought of as >:-) EVILGRIN("evilgrin", new String(Character.toChars(0x1F608)), "Evil grin", "Sourire mauvais"), // Originally \u00A6-( CRY("cry", new String(Character.toChars(0x1F622)), "Crying", "Pleure"), // Originally >:-( EVIL("evil", new String(Character.toChars(0x1F47F)), "Evil", "Mauvais"); final String emotion; final String altText; final String enName; final String frName; Type(String emotion, String altText, String enName, String frName) { this.emotion = emotion; this.altText = altText; this.enName = enName; this.frName = frName; } } public static class Factory extends TodoElement.Factory { final Type t; public Factory(Type t) { super(); this.t = t; } @Override public TodoSmileyElement newItem(Element node, Context ctx, TodoItem caller) { return new TodoSmileyElement(t, node, ctx, caller); } } final Type t; public TodoSmileyElement(Type t, Element node, Context ctx, TodoItem caller) { super(node, ctx, caller); this.t = t; } @Override public void handleNodeOnly() { String lang = LangHelper.getLangRec(node); Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img"); img.setAttributeNS(null, "src", "data:image/png;base64," + Base64.encode(DamlEngine.class.getResourceAsStream("images/smileys/"+t.emotion+".png"))); img.setAttributeNS(null, "class", "smiley"); img.setAttributeNS(null, "alt", t.altText); img.setAttributeNS(null, "height", "15"); img.setAttributeNS(null, "width", "15"); if ( lang != null && lang.equals("en") ) img.setAttributeNS(null, "title", t.enName); else if ( lang != null && lang.equals("fr") ) img.setAttributeNS(null, "title", t.frName); node.getParentNode().replaceChild(img, node); } }