1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Sun Apr 07 22:30:45 2013 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Sun Apr 07 22:32:41 2013 +0200
1.3 @@ -210,9 +210,15 @@
1.4 w.append(" }\n");
1.5 w.append("}\n");
1.6 } else {
1.7 - w.append(" this.prop_").append(pn);
1.8 - w.append(" = (").append(type).append(')');
1.9 - w.append("ret[" + cnt + "];\n");
1.10 + if (isPrimitive(type)) {
1.11 + w.append(" this.prop_").append(pn);
1.12 + w.append(" = ((Number)").append("ret[" + cnt + "]).");
1.13 + w.append(type).append("Value();\n");
1.14 + } else {
1.15 + w.append(" this.prop_").append(pn);
1.16 + w.append(" = (").append(type).append(')');
1.17 + w.append("ret[" + cnt + "];\n");
1.18 + }
1.19 }
1.20 cnt++;
1.21 }
2.1 --- a/javaquery/demo-twitter/src/main/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClient.java Sun Apr 07 22:30:45 2013 +0200
2.2 +++ b/javaquery/demo-twitter/src/main/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClient.java Sun Apr 07 22:32:41 2013 +0200
2.3 @@ -33,7 +33,7 @@
2.4 @Property(name="activeTweetersName", type=String.class),
2.5 @Property(name="modifiedList", type=TwitterClient.Twttrs.class),
2.6 @Property(name="userNameToAdd", type=String.class),
2.7 - @Property(name="currentTweets", type=String.class, array = true)
2.8 + @Property(name="currentTweets", type=TwitterClient.Twt.class, array = true)
2.9 })
2.10 public class TwitterClient {
2.11 @Model(className = "Tweeters", properties = {
2.12 @@ -42,6 +42,41 @@
2.13 })
2.14 static class Twttrs {
2.15 }
2.16 + @Model(className = "Tweet", properties = {
2.17 + @Property(name = "from_user", type = String.class),
2.18 + @Property(name = "from_user_id", type = int.class),
2.19 + @Property(name = "profile_image_url", type = String.class),
2.20 + @Property(name = "text", type = String.class),
2.21 +
2.22 + })
2.23 + static final class Twt {
2.24 + }
2.25 + @Model(className = "TwitterQuery", properties = {
2.26 + @Property(array = true, name = "results", type = Twt.class)
2.27 + })
2.28 + public static final class TwttrQr {
2.29 + }
2.30 +
2.31 + @OnReceive(url="{url}")
2.32 + static void queryTweets(TwitterModel page, TwitterQuery q) {
2.33 + page.getCurrentTweets().clear();
2.34 + page.getCurrentTweets().addAll(q.getResults());
2.35 + }
2.36 +
2.37 + @OnFunction
2.38 + static void refreshTweets(TwitterModel model) {
2.39 + Tweeters people = model.getActiveTweeters();
2.40 + StringBuilder sb = new StringBuilder();
2.41 + sb.append("http://search.twitter.com/search.json?callback=?&rpp=25&q=");
2.42 + String sep = "";
2.43 + for (String p : people.getUserNames()) {
2.44 + sb.append(sep);
2.45 + sb.append("from:");
2.46 + sb.append(p);
2.47 + sep = " OR ";
2.48 + }
2.49 + model.queryTweets(sb.toString());
2.50 + }
2.51
2.52 private static Tweeters tweeters(String listName, String... userNames) {
2.53 Tweeters t = new Tweeters();
2.54 @@ -60,7 +95,7 @@
2.55 svdLst.add(tweeters("Tech pundits", "Scobleizer", "LeoLaporte", "techcrunch", "BoingBoing", "timoreilly", "codinghorror"));
2.56
2.57 model.setActiveTweetersName("NetBeans");
2.58 -
2.59 +
2.60 model.applyBindings();
2.61 }
2.62
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterProtocolTest.java Sun Apr 07 22:32:41 2013 +0200
3.3 @@ -0,0 +1,90 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator
3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License
3.18 + * along with this program. Look for COPYING file in the top folder.
3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 +package org.apidesign.bck2brwsr.demo.twitter;
3.22 +
3.23 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
3.24 +import org.apidesign.bck2brwsr.vmtest.Http;
3.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
3.26 +import org.testng.annotations.Factory;
3.27 +
3.28 +/**
3.29 + *
3.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.31 + */
3.32 +public class TwitterProtocolTest {
3.33 + private TwitterModel page;
3.34 + @Http(@Http.Resource(
3.35 + path = "/test.tweet",
3.36 + mimeType = "application/json",
3.37 + content = "{\"completed_in\":0.04,\"max_id\":320055706885689344,\"max_id_str\""
3.38 + + ":\"320055706885689344\",\"page\":1,\"query\":\"from%3AJaroslavTulach\",\"refresh_url\":"
3.39 + + "\"?since_id=320055706885689344&q=from%3AJaroslavTulach\","
3.40 + + "\"results\":[{\"created_at\":\"Fri, 05 Apr 2013 06:10:01 +0000\","
3.41 + + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
3.42 + + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":320055706885689344,"
3.43 + + "\"id_str\":\"320055706885689344\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
3.44 + + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.45 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.46 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
3.47 + + "\"@tom_enebo Amzng! Not that I would like #ruby, but I am really glad you guys stabilized the plugin + "
3.48 + + "made it work in #netbeans 7.3! Gd wrk.\",\"to_user\":\"tom_enebo\",\"to_user_id\":14498747,"
3.49 + + "\"to_user_id_str\":\"14498747\",\"to_user_name\":\"tom_enebo\",\"in_reply_to_status_id\":319832359509839872,"
3.50 + + "\"in_reply_to_status_id_str\":\"319832359509839872\"},{\"created_at\":\"Thu, 04 Apr 2013 07:33:06 +0000\","
3.51 + + "\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,\"from_user_id_str\":"
3.52 + + "\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,\"id\":319714227088678913,"
3.53 + + "\"id_str\":\"319714227088678913\",\"iso_language_code\":\"en\",\"metadata\":{\"result_type\":"
3.54 + + "\"recent\"},\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.55 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.56 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
3.57 + + "\"RT @drkrab: At #erlangfactory @joerl: Frameworks grow in complexity until nobody can use them.\"},"
3.58 + + "{\"created_at\":\"Tue, 02 Apr 2013 07:44:34 +0000\",\"from_user\":\"JaroslavTulach\","
3.59 + + "\"from_user_id\":420944648,\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\","
3.60 + + "\"geo\":null,\"id\":318992336145248256,\"id_str\":\"318992336145248256\",\"iso_language_code\":\"en\","
3.61 + + "\"metadata\":{\"result_type\":\"recent\"},\"profile_image_url\":"
3.62 + + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.63 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.64 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
3.65 + + "\"Twitter renamed to twttr http:\\/\\/t.co\\/tqaN4T1xlZ - good, I don't have to rename #bck2brwsr!\"},"
3.66 + + "{\"created_at\":\"Sun, 31 Mar 2013 03:52:04 +0000\",\"from_user\":\"JaroslavTulach\",\"from_user_id\":420944648,"
3.67 + + "\"from_user_id_str\":\"420944648\",\"from_user_name\":\"Jaroslav Tulach\",\"geo\":null,"
3.68 + + "\"id\":318209051223789568,\"id_str\":\"318209051223789568\",\"iso_language_code\":\"en\",\"metadata\":"
3.69 + + "{\"result_type\":\"recent\"},\"profile_image_url\":"
3.70 + + "\"http:\\/\\/a0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.71 + + "\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1656828312\\/jst_normal.gif\","
3.72 + + "\"source\":\"<a href="http:\\/\\/twitter.com\\/">web<\\/a>\",\"text\":"
3.73 + + "\"Math proofs without words. Ingenious: http:\\/\\/t.co\\/sz7yVbfpGw\"}],\"results_per_page\":100,"
3.74 + + "\"since_id\":0,\"since_id_str\":\"0\"}"
3.75 + ))
3.76 + @BrwsrTest public void readFromTwttr() throws InterruptedException {
3.77 + if (page == null) {
3.78 + page = new TwitterModel();
3.79 + page.applyBindings();
3.80 + page.queryTweets("/test.tweet");
3.81 + }
3.82 +
3.83 + if (page.getCurrentTweets().isEmpty()) {
3.84 + throw new InterruptedException();
3.85 + }
3.86 +
3.87 + assert 4 == page.getCurrentTweets().size() : "Four tweets: " + page.getCurrentTweets();
3.88 + }
3.89 +
3.90 + @Factory public static Object[] create() {
3.91 + return VMTest.create(TwitterProtocolTest.class);
3.92 + }
3.93 +}