17 package com.nokia.carbide.internal.discovery.ui.extension; |
17 package com.nokia.carbide.internal.discovery.ui.extension; |
18 |
18 |
19 import java.net.URL; |
19 import java.net.URL; |
20 import java.text.DateFormat; |
20 import java.text.DateFormat; |
21 import java.text.MessageFormat; |
21 import java.text.MessageFormat; |
|
22 import java.util.ArrayList; |
22 import java.util.Date; |
23 import java.util.Date; |
23 import java.util.LinkedHashSet; |
24 import java.util.LinkedHashSet; |
|
25 import java.util.List; |
24 import java.util.Set; |
26 import java.util.Set; |
25 import java.util.regex.Pattern; |
27 import java.util.regex.Pattern; |
26 |
28 |
27 import org.eclipse.jface.action.Action; |
29 import org.eclipse.jface.action.Action; |
28 import org.eclipse.jface.action.IAction; |
30 import org.eclipse.jface.action.IAction; |
33 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Channel; |
35 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Channel; |
34 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Item; |
36 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Item; |
35 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Rss; |
37 import com.nokia.carbide.internal.discovery.ui.editor.SimpleRSSReader.Rss; |
36 |
38 |
37 public abstract class AbstractRSSPortalPageLayer extends AbstractBrowserPortalPageLayer { |
39 public abstract class AbstractRSSPortalPageLayer extends AbstractBrowserPortalPageLayer { |
|
40 |
|
41 private static final List<Pattern> EXCLUDE_TAG_PATTERNS = new ArrayList<Pattern>(); |
38 |
42 |
39 private static final String[] EXCLUDE_TAGS = { |
43 private static final String[] EXCLUDE_TAGS = { |
40 "object", //$NON-NLS-1$ |
44 "object", //$NON-NLS-1$ |
41 "param", //$NON-NLS-1$ |
45 "param", //$NON-NLS-1$ |
42 "embed", //$NON-NLS-1$ |
46 "embed", //$NON-NLS-1$ |
43 "script", //$NON-NLS-1$ |
47 "script", //$NON-NLS-1$ |
44 "img" //$NON-NLS-1$ |
48 "img" //$NON-NLS-1$ |
45 }; |
49 }; |
46 |
50 |
47 private static final Pattern[] EXCLUDE_TAG_PATTERNS = new Pattern[EXCLUDE_TAGS.length * 2]; |
51 private static final String[] EXCLUDE_FORMAT_TAGS = { |
|
52 "b", //$NON-NLS-1$ |
|
53 "i", //$NON-NLS-1$ |
|
54 "em", //$NON-NLS-1$ |
|
55 "strong", //$NON-NLS-1$ |
|
56 "tt", //$NON-NLS-1$ |
|
57 "s", //$NON-NLS-1$ |
|
58 "strike", //$NON-NLS-1$ |
|
59 "p" //$NON-NLS-1$ |
|
60 }; |
48 |
61 |
49 static { |
62 static { |
50 int i = 0; |
|
51 for (String tagString : EXCLUDE_TAGS) { |
63 for (String tagString : EXCLUDE_TAGS) { |
52 StringBuilder sb = new StringBuilder(); |
64 StringBuilder sb = new StringBuilder(); |
53 sb.append('<'); |
65 sb.append('<'); |
54 sb.append(tagString); |
66 sb.append(tagString); |
55 sb.append(" .*</"); //$NON-NLS-1$ |
67 sb.append(" .*</"); //$NON-NLS-1$ |
56 sb.append(tagString); |
68 sb.append(tagString); |
57 sb.append('>'); |
69 sb.append('>'); |
58 EXCLUDE_TAG_PATTERNS[i++] = |
70 EXCLUDE_TAG_PATTERNS.add(Pattern.compile(sb.toString(), |
59 Pattern.compile(sb.toString(), |
71 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)); |
60 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); |
|
61 } |
72 } |
62 for (String tagString : EXCLUDE_TAGS) { |
73 for (String tagString : EXCLUDE_TAGS) { |
63 StringBuilder sb = new StringBuilder(); |
74 StringBuilder sb = new StringBuilder(); |
64 sb.append('<'); |
75 sb.append('<'); |
65 sb.append(tagString); |
76 sb.append(tagString); |
66 sb.append(" .*/>"); //$NON-NLS-1$ |
77 sb.append(" .*/>"); //$NON-NLS-1$ |
67 EXCLUDE_TAG_PATTERNS[i++] = |
78 EXCLUDE_TAG_PATTERNS.add(Pattern.compile(sb.toString(), |
68 Pattern.compile(sb.toString(), |
79 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)); |
69 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); |
80 } |
|
81 for (String formatTag : EXCLUDE_FORMAT_TAGS) { |
|
82 StringBuilder sb = new StringBuilder(); |
|
83 sb.append("</?"); //$NON-NLS-1$ |
|
84 sb.append(formatTag); |
|
85 sb.append('>'); |
|
86 EXCLUDE_TAG_PATTERNS.add(Pattern.compile(sb.toString(), |
|
87 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)); |
|
88 |
70 } |
89 } |
71 } |
90 } |
72 |
91 |
73 private static final String HTML_BODY_HEADER = "<html><head><title></title><style type=\"text/css\">div.item {font-family : sans-serif; font-size : 12px; margin-bottom : 16px;} div.itemBody {padding-top : 3px; padding-bottom : 3px;} div.itemInfo {background-color : #EEEEEE; color : #333333;} div.feedflare {display: none;} a.itemTitle {font-size : 12px; font-weight : bold;} a.markItemRead {font-size : 10px; color : #333333;}</style></head><body>"; //$NON-NLS-1$ |
92 private static final String HTML_BODY_HEADER = "<html><head><title></title><style type=\"text/css\">div.item {font-family : sans-serif; font-size : 12px; margin-bottom : 16px;} div.itemBody {padding-top : 3px; padding-bottom : 3px;} div.itemInfo {background-color : #EEEEEE; color : #333333;} div.feedflare {display: none;} a.itemTitle {font-size : 12px; font-weight : bold;} a.markItemRead {font-size : 10px; color : #333333;}</style></head><body>"; //$NON-NLS-1$ |
74 private static final String HTML_BODY_FOOTER = "</body></html>"; //$NON-NLS-1$ |
93 private static final String HTML_BODY_FOOTER = "</body></html>"; //$NON-NLS-1$ |
115 buf.append("\">"); //$NON-NLS-1$ |
134 buf.append("\">"); //$NON-NLS-1$ |
116 buf.append(clean(item.getTitle())); |
135 buf.append(clean(item.getTitle())); |
117 buf.append("</a>"); //$NON-NLS-1$ |
136 buf.append("</a>"); //$NON-NLS-1$ |
118 buf.append("<div class=\"itemBody\">"); //$NON-NLS-1$ |
137 buf.append("<div class=\"itemBody\">"); //$NON-NLS-1$ |
119 Date date = item.getPubDate(); |
138 Date date = item.getPubDate(); |
120 if (date != null) |
139 if (date != null) { |
121 buf.append(DateFormat.getInstance().format(date)); |
140 String dateString = DateFormat.getDateTimeInstance().format(date); |
|
141 buf.append(dateString); |
|
142 buf.append("<br>"); |
|
143 } |
122 buf.append(clean(item.getDescription())); |
144 buf.append(clean(item.getDescription())); |
123 buf.append("</div></li>"); //$NON-NLS-1$ |
145 buf.append("</div></li>"); //$NON-NLS-1$ |
124 } |
146 } |
125 buf.append("</ul>"); //$NON-NLS-1$ |
147 buf.append("</ul>"); //$NON-NLS-1$ |
126 } |
148 } |
127 buf.append(HTML_BODY_FOOTER); |
149 buf.append(HTML_BODY_FOOTER); |
128 browser.setText(buf.toString()); |
150 browser.setText(buf.toString()); |
129 } |
151 } |
130 |
152 |
131 private String clean(String s) { |
153 private String clean(String s) { |
|
154 String output = s; |
132 for (Pattern pattern : EXCLUDE_TAG_PATTERNS) { |
155 for (Pattern pattern : EXCLUDE_TAG_PATTERNS) { |
133 s = pattern.matcher(s).replaceAll(""); //$NON-NLS-1$ |
156 output = pattern.matcher(output).replaceAll(""); //$NON-NLS-1$ |
134 } |
157 } |
135 return s.length() > MAX_ELEM_LEN ? s.substring(0, MAX_ELEM_LEN) : s; |
158 output = output.length() > MAX_ELEM_LEN ? output.substring(0, MAX_ELEM_LEN) : output; |
|
159 return output; |
136 } |
160 } |
137 |
161 |
138 @Override |
162 @Override |
139 public void dispose() { |
163 public void dispose() { |
140 } |
164 } |