Package org.slim3.repackaged.org.json

Examples of org.slim3.repackaged.org.json.JSONObject


        Assert.assertEquals("1", j.getString("value"));
    }

    @Test
    public void wrapperFloatValueTest() throws Exception {
        JSONObject j = new JSONObject("{value: 1.1}");
        Assert.assertEquals((Double) 1.1, j.get("value"));
        try {
            j.getBoolean("value");
            Assert.fail();
        } catch (JSONException e) {
        }
        Assert.assertEquals(1.1, j.getDouble("value"), 0.1);
        Assert.assertEquals(1, j.getInt("value"));
        Assert.assertEquals(1, j.getLong("value"));
        Assert.assertEquals("1.1", j.getString("value"));
    }
View Full Code Here


        Assert.assertEquals("1.1", j.getString("value"));
    }

    @Test
    public void wrapperListArrayTest() throws Exception {
        JSONObject j = new JSONObject("{\"values\":[1,2,3]}");
        JSONArray array = j.getJSONArray("values");
        Assert.assertEquals(3, array.length());
        Assert.assertEquals("1", array.getString(0));
        Assert.assertEquals("2", array.getString(1));
        Assert.assertEquals("3", array.getString(2));
    }
View Full Code Here

        Assert.assertEquals("3", array.getString(2));
    }

    @Test
    public void blobTest() throws Exception {
        JSONObject j = new JSONObject("{\"blobAttr\":\"aGVsbG8=\"}");
        Assert.assertArrayEquals(
            "hello".getBytes(),
            Base64.decode(j.getString("blobAttr")));
        try {
            Base64.decode("hello");
            Assert.fail();
        } catch (Base64DecoderException e) {
View Full Code Here

        }
    }

    @Test
    public void imHandle() throws Exception {
        JSONObject j =
            new JSONObject(
                "{"
                    + "\"imHandleAttr1\":{\"address\":\"handle\",\"protocol\":\"xmpp\"}"
                    + ",\"imHandleAttr2\":{\"address\":\"network\",\"protocol\":\"http://aim.com\"}"
                    + "}");
        JSONObject h = j.getJSONObject("imHandleAttr1");
        IMHandle i = null;
        IMHandle.Scheme s = null;
        URL u = null;
        try {
            s = IMHandle.Scheme.valueOf(h.getString("protocol"));
        } catch (IllegalArgumentException e) {
            try {
                u = new URL(h.getString("protocol"));
            } catch (MalformedURLException ex) {
            }
        }
        if (s != null) {
            i = new IMHandle(s, h.getString("address"));
        } else if (u != null) {
            i = new IMHandle(u, h.getString("address"));
        }
        Assert.assertEquals("handle", i.getAddress());
        Assert.assertEquals(IMHandle.Scheme.xmpp.name(), i.getProtocol());
    }
View Full Code Here

        Assert.assertEquals(IMHandle.Scheme.xmpp.name(), i.getProtocol());
    }

    @Test
    public void user() throws Exception {
        JSONObject j =
            new JSONObject(
                "{"
                    + "\"user1\":{\"authDomain\":\"authDomain\",\"email\":\"user@test.com\"}"
                    + "}");
        Assert.assertEquals("", j.optString("name"));
        Assert.assertNull(j.optString("name", null));
        JSONObject u = j.getJSONObject("user1");
        String domain = u.optString("authDomain", null);
        String email = u.optString("email", null);
        String uid = u.optString("userid", null);
        String fid = u.optString("federatedIdentity");
        if (domain != null && email != null) {
            if (uid == null) {
                new User(email, domain);
            } else if (fid == null) {
                new User(email, domain, uid);
View Full Code Here

    static {
        initialize();
    }

    private static void initialize() {
        Cleaner.add(new Cleanable() {
            public void clean() {
                modelMetaCache.clear();
                initialized = false;
            }
        });
View Full Code Here

    static {
        initialize();
    }

    private static void initialize() {
        Cleaner.add(new Cleanable() {
            public void clean() {
                modelMetaCache.clear();
                initialized = false;
            }
        });
View Full Code Here

    private TwitterService service = new TwitterService();
    private TweetMeta meta = TweetMeta.get();

    @Override
    public Navigation run() throws Exception {
        RequestMap requestMap = new RequestMap(request);
//        int index = Integer.parseInt(requestMap.get("index").toString());
//        String content = requestMap.get("content").toString();
//        List<Tweet> listTween = service.getTweetList();
//        int maxIndex = listTween.size();
//        if (index < maxIndex) {
//            service.updateTweet(listTween.get(index).getKey(), content);
//            listTween = service.getTweetList();
//            requestScope("tweetList", listTween);
//        }
        if (validate() && (!requestMap.get("content").toString().trim().equals(""))) {
            service.updateTweet(asKey(meta.key), asLong(meta.version), requestMap);
        } else {
            return forward ("edit.jsp");
        }
        return redirect(basePath);
View Full Code Here

    private TwitterService service = new TwitterService();
    private TweetMeta meta = TweetMeta.get();

    @Override
    public Navigation run() throws Exception {
        RequestMap requestMap = new RequestMap(request);
        if (validate() && (!requestMap.get("content").toString().trim().equals(""))) {
            service.tweet(requestMap);
        }
        return redirect(basePath);
    }
View Full Code Here

                encoding = "UTF-8";
            }
            try {
                return URLEncoder.encode(path, encoding);
            } catch (UnsupportedEncodingException e) {
                throw new WrapRuntimeException(e);
            }
        }
View Full Code Here

TOP

Related Classes of org.slim3.repackaged.org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.