|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectMessageDecoder
This message decoder class is designed to work along side the main jYMSG classes, accepting raw message strings from Yahoo, and translating them into something a bit more Java-friendly.
Currently the decoder can translate messages into basic HTML and plain text (formatting stripped). It can also append styled text onto the end of a Swing Document object, complete with smiley icons if desired.
Please note: this class is new and experimental.
String a[] =
{ "\u001b[#000000m<font face=\"Verdana\" size=\"10\">No, and it's not that common anyway now, Facs.",
"\u001b[31m<font face=\"Verdana\" size=\"13\">can any1 help me?",
"\u001b[31mRFred, I got it, hold on.",
"<FADE #00002b,#4848ff,#4848ff,#00002b,#4848ff,#4848ff><font face=\"Comic Sans MS\" size=\"16\">any programmerz who make yahoo programz:-?</FADE>",
"\u001b[30m<font face=\"times\" size=\"14\">\u001b[1m\u001b[2manyone here using gyach enhanced?",
"can you make such a monster?",
"<font face=\"Arial\" size=\"10\">\u001b[#000000m<FADE #000000,#FF0000,#000000>whassup mah fellow programma's?!</FADE><font YmLite 41>",
"<font face=\"Symbol\" size=\"12\">\u001b[#a0a0ffm\u001b[1m\u001b[4m$\u001b[x1m\u001b[x4m</font></font><font face=\"Arial\" size=\"10\"> \u001b[#000000m.9 times 10 <> 9.9</font><font YHLT ~></font>",
"Happy :-) :) Sad :( Wink ;) Grin :D Eyes ;;) Confused :/ Love :X Blush :\"> Tongue :p Kiss :*",
"Shock :O Anger X-( Smug :> Cool B) Worried :s Devil >:) Cry :(( Laugh :)) Straight :| Eyebrow /:)",
"Angel O:) Nerd :-B Hand =; Sleep I-) Rolling 8-| Sick :-& Shhh :-$ Not talk [-( Clown :o) Silly 8-}",
"Tired (:| Drool =P~ Think :-? D'oh #-o Applause =D>"
};
// Build window
JFrame frame = new JFrame();
JTextPane tp = new JTextPane();
tp.setEditable(false);
frame.getContentPane().add(tp); frame.setSize(400,350);
frame.setVisible(true);
// Get the document
Document doc = tp.getDocument();
// Decode the message content. Note: because we are making several
// versions of the same message, we've taken a multi-step process,
// although this class has static methods to do an all-in-one conversion.
for(int i=0;i<a.length;i++)
{ // Create decoder, and set the emoticon (smiley) option on
MessageDecoderSettings mds = new MessageDecoderSettings();
mds.setEmoticonsDecoded(true);
MessageDecoder md = new MessageDecoder(mds);
// Decode the message into an element tree, returns root node.
// Note: we don't actually have to create a brand new MessageDecoder
// object for each decode - we could just re-use an existing one.
MessageElement sc=md.decode(a[i]);
// Dump to stdout the HTML and plain text versions
System.out.println(sc.toHTML());
System.out.println(sc.toText());
// Append to the message to Swing Document
sc.appendToDocument(doc);
}
| Constructor Summary | |
MessageDecoder()
Create a new instance of a decoder. |
|
MessageDecoder(MessageDecoderSettings md)
Create a new instance of a decoder, using settings. |
|
| Method Summary | |
void |
appendToDocument(String m,
javax.swing.text.Document doc)
Convenience method to convert Yahoo message to styled Swing text. |
MessageElement |
decode(String m)
Decodes a Yahoo message to an element tree. |
String |
decodeToHTML(String m)
Convenience method to convert Yahoo message to HTML. |
String |
decodeToText(String m)
Convenience method to convert Yahoo message to plain text. |
MessageDecoderSettings |
getDecoderSettings()
Return the current settings object used by this decoder, if set. |
void |
setDecoderSettings(MessageDecoderSettings md)
Provide a settings object for this decoder to work with. |
| Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public MessageDecoder()
Note: it is actually possible to re-use decoder objects for multiple decodes, even across different threads.
public MessageDecoder(MessageDecoderSettings md)
MessageDecoderSettings for details.
Note: it is actually possible to re-use decoder objects for multiple decodes, even across different threads.
md - decoders settings| Method Detail |
public void setDecoderSettings(MessageDecoderSettings md)
md - decoders settingspublic MessageDecoderSettings getDecoderSettings()
public MessageElement decode(String m)
Note: it is actually possible to re-use decoder objects for multiple decodes, even across different threads.
m - Yahoo message text, possibly containing Utf8.
public String decodeToHTML(String m)
MessageDecoder, decodes the message and returns
the output from the appropriate translator method, all in one.
m - Yahoo message text, possibly containing Utf8.
public String decodeToText(String m)
MessageDecoder, decodes the message and returns
the output from the appropriate translator method, all in one.
m - Yahoo message text, possibly containing Utf8.
public void appendToDocument(String m,
javax.swing.text.Document doc)
MessageDecoder, decodes the message and
appends the output from the appropriate translator method to the
provided Swing Document object, all in one.
m - Yahoo message text, possibly containing Utf8.doc - Swing Document object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||