1 Clazz.declarePackage ("jalview.util");
\r
2 Clazz.load (["java.lang.StringBuffer", "java.util.ArrayList", "java.util.regex.Pattern"], "jalview.util.ParseHtmlBodyAndLinks", ["java.util.StringTokenizer"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
5 this.htmlContent = true;
\r
8 Clazz.instantialize (this, arguments);
\r
9 }, jalview.util, "ParseHtmlBodyAndLinks");
\r
10 Clazz.prepareFields (c$, function () {
\r
11 this.links = new java.util.ArrayList ();
\r
12 this.sb = new StringBuffer ();
\r
14 Clazz.defineMethod (c$, "getOrig",
\r
18 Clazz.defineMethod (c$, "isHtmlContent",
\r
20 return this.htmlContent;
\r
22 Clazz.defineMethod (c$, "getContent",
\r
24 return this.sb.toString ();
\r
26 Clazz.defineMethod (c$, "getLinks",
\r
30 Clazz.makeConstructor (c$,
\r
31 function (description, removeHTML, newline) {
\r
32 if (description == null || description.length == 0) {
\r
33 this.htmlContent = false;
\r
35 }if (description.toUpperCase ().indexOf ("<HTML>") == -1) {
\r
36 this.htmlContent = false;
\r
37 }this.orig = description;
\r
38 var st = new java.util.StringTokenizer (description, "<");
\r
43 while (st.hasMoreElements ()) {
\r
44 token = st.nextToken ("&>");
\r
45 if (token.equalsIgnoreCase ("html") || token.startsWith ("/")) {
\r
48 startTag = token.indexOf ("<");
\r
49 if (startTag > -1) {
\r
50 tag = token.substring (startTag + 1);
\r
51 token = token.substring (0, startTag);
\r
52 }if (tag != null && tag.toUpperCase ().startsWith ("A HREF=")) {
\r
53 if (token.length > 0) {
\r
54 this.sb.append (token);
\r
55 }link = tag.substring (tag.indexOf ("\"") + 1, tag.length - 1);
\r
56 var label = st.nextToken ("<>");
\r
57 this.links.add (label + "|" + link);
\r
58 this.sb.append (label + "%LINK%");
\r
59 } else if (tag != null && tag.equalsIgnoreCase ("br")) {
\r
60 this.sb.append (newline);
\r
61 } else if (token.startsWith ("lt;")) {
\r
62 this.sb.append ("<" + token.substring (3));
\r
63 } else if (token.startsWith ("gt;")) {
\r
64 this.sb.append (">" + token.substring (3));
\r
65 } else if (token.startsWith ("amp;")) {
\r
66 this.sb.append ("&" + token.substring (4));
\r
68 this.sb.append (token);
\r
70 if (removeHTML && !this.htmlContent) {
\r
71 this.sb = new StringBuffer (jalview.util.ParseHtmlBodyAndLinks.LEFT_ANGLE_BRACKET_PATTERN.matcher (description).replaceAll ("<"));
\r
73 Clazz.defineMethod (c$, "getNonHtmlContent",
\r
75 return this.isHtmlContent () ? this.sb.toString () : this.orig;
\r
77 c$.LEFT_ANGLE_BRACKET_PATTERN = c$.prototype.LEFT_ANGLE_BRACKET_PATTERN = java.util.regex.Pattern.compile ("<");
\r