|
30 | 30 | import org.apache.http.client.methods.HttpGet;
|
31 | 31 | import org.apache.http.impl.client.HttpClientBuilder;
|
32 | 32 | import org.apache.http.util.EntityUtils;
|
33 |
| - |
| 33 | +import com.vaadin.flow.component.Component; |
34 | 34 | import com.vaadin.flow.component.HasSize;
|
35 | 35 | import com.vaadin.flow.component.HasStyle;
|
36 | 36 | import com.vaadin.flow.component.Tag;
|
37 | 37 | import com.vaadin.flow.component.dependency.JsModule;
|
38 | 38 | import com.vaadin.flow.component.dependency.NpmPackage;
|
39 |
| -import com.vaadin.flow.component.polymertemplate.PolymerTemplate; |
40 | 39 |
|
41 | 40 | /**
|
42 | 41 | * Simple RSS Reader component based on https://github.com/TherapyChat/rss-items
|
|
49 | 48 | @NpmPackage(value="x2js",version="3.4.0")
|
50 | 49 | @JsModule("./rss-items.js")
|
51 | 50 | @SuppressWarnings("serial")
|
52 |
| -public class RssItems extends PolymerTemplate<RssItemsModel> implements HasSize, HasStyle { |
| 51 | +public class RssItems extends Component implements HasSize, HasStyle { |
53 | 52 |
|
54 | 53 | private String url;
|
55 | 54 |
|
@@ -96,13 +95,13 @@ public RssItems(String url, int max, int maxTitleLength, int maxExcerptLength, b
|
96 | 95 | this.getElement().executeJs(IMAGE_METHOD.replaceAll("%%ATTRIBUTE_NAME%%", attributeName), this);
|
97 | 96 | }
|
98 | 97 |
|
99 |
| - getModel().setAuto(true); |
100 |
| - getModel().setMax(max); |
101 |
| - getModel().setMaxExcerptLength(maxExcerptLength); |
102 |
| - getModel().setMaxTitleLength(maxTitleLength); |
| 98 | + this.setUrl(url); |
| 99 | + this.setAuto(true); |
| 100 | + this.setMax(max); |
| 101 | + this.setMaxExcerptLength(maxExcerptLength); |
| 102 | + this.setMaxTitleLength(maxTitleLength); |
103 | 103 | addClassName("x-scope");
|
104 |
| - addClassName("rss-items-0"); |
105 |
| - this.url = url; |
| 104 | + addClassName("rss-items-0"); |
106 | 105 | refreshUrl();
|
107 | 106 | }
|
108 | 107 |
|
@@ -142,37 +141,53 @@ private String obtainRss(String url) throws ClientProtocolException, IOException
|
142 | 141 | return result;
|
143 | 142 | }
|
144 | 143 |
|
| 144 | + /** |
| 145 | + * Sets the auto property to init the RSS request |
| 146 | + * @param auto |
| 147 | + */ |
| 148 | + public void setAuto(boolean auto) { |
| 149 | + this.getElement().setProperty("auto", auto); |
| 150 | + } |
| 151 | + |
145 | 152 | /**
|
146 | 153 | * Sets the max title length
|
147 | 154 | * @param length
|
148 | 155 | */
|
149 |
| - public void setMaxTitleLength(int length) { |
150 |
| - getModel().setMaxTitleLength(length); |
151 |
| - refreshUrl(); |
152 |
| - } |
| 156 | + public void setMaxTitleLength(int length) { |
| 157 | + this.getElement().setProperty("maxTitleLength", length); |
| 158 | + refreshUrl(); |
| 159 | + } |
153 | 160 |
|
154 | 161 | /**
|
155 | 162 | * Sets the max title excerpt length
|
156 | 163 | * @param length
|
157 | 164 | */
|
158 |
| - public void setMaxExcerptLength(int length) { |
159 |
| - getModel().setMaxExcerptLength(length); |
160 |
| - refreshUrl(); |
161 |
| - } |
| 165 | + public void setMaxExcerptLength(int length) { |
| 166 | + this.getElement().setProperty("maxExcerptLength", length); |
| 167 | + refreshUrl(); |
| 168 | + } |
162 | 169 |
|
163 | 170 | /**
|
164 | 171 | * Sets the maximun number of items to be shown
|
165 | 172 | * @param max
|
166 | 173 | */
|
167 |
| - public void setMax(int max) { |
168 |
| - getModel().setMax(max); |
169 |
| - refreshUrl(); |
170 |
| - } |
171 |
| - |
172 |
| - public void setExtractImageFromDescription(boolean extractImageFromDescription) { |
173 |
| - this.extractImageFromDescription = extractImageFromDescription; |
174 |
| - refreshUrl(); |
175 |
| - } |
| 174 | + public void setMax(int max) { |
| 175 | + this.getElement().setProperty("max", max); |
| 176 | + refreshUrl(); |
| 177 | + } |
| 178 | + |
| 179 | + public void setExtractImageFromDescription(boolean extractImageFromDescription) { |
| 180 | + this.extractImageFromDescription = extractImageFromDescription; |
| 181 | + refreshUrl(); |
| 182 | + } |
176 | 183 |
|
| 184 | + /** |
| 185 | + * Sets the url of the RSS |
| 186 | + * @param url |
| 187 | + */ |
| 188 | + public void setUrl(String url) { |
| 189 | + this.getElement().setProperty("url", url); |
| 190 | + this.url = url; |
| 191 | + } |
177 | 192 |
|
178 | 193 | }
|
0 commit comments