# HG changeset patch # User Jaroslav Tulach # Date 1367644865 -7200 # Node ID f0a52c72ef74596fb9400028dfe5f762e95f23cc # Parent a707111432df03e26ffe6a45b7116f09c36c7ab0 Skeleton of client part of the chat application diff -r a707111432df -r f0a52c72ef74 pom.xml --- a/pom.xml Thu May 02 14:41:10 2013 +0200 +++ b/pom.xml Sat May 04 07:21:05 2013 +0200 @@ -18,6 +18,7 @@ twitter + serverside diff -r a707111432df -r f0a52c72ef74 serverside/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/nbactions.xml Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,45 @@ + + + + + run + + process-classes + bck2brwsr:brwsr + + + + debug + + process-classes + bck2brwsr:brwsr + + + maven + + + diff -r a707111432df -r f0a52c72ef74 serverside/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/pom.xml Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.apidesign.html + demo + 1.0-SNAPSHOT + + org.apidesign.bck2brwsr + demo-serverside + 1.0-SNAPSHOT + Bck2Brwsr and Bck2Server + http://maven.apache.org + + UTF-8 + 0.2 + 0.7 + MINIMAL + org/apidesign/bck2brwsr/demo/serverside/chat.html + + + + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + ${bck2brwsr.version} + + + + brwsr + + + + + ${brwsr.startpage} + bck2brwsr + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + + + org.apidesign.html + net.java.html.json + ${net.java.html.version} + jar + + + org.apidesign.html + ko-bck2brwsr + ${net.java.html.version} + runtime + + + ${project.groupId} + launcher.http + ${bck2brwsr.version} + runtime + + + ${project.groupId} + emul + ${bck2brwsr.version} + rt + runtime + + + org.testng + testng + 6.5.2 + test + + + diff -r a707111432df -r f0a52c72ef74 serverside/src/main/java/org/apidesign/bck2brwsr/demo/serverside/ChatClient.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/src/main/java/org/apidesign/bck2brwsr/demo/serverside/ChatClient.java Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,73 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.bck2brwsr.demo.serverside; + +import net.java.html.json.ComputedProperty; +import net.java.html.json.Context; +import net.java.html.json.Function; +import net.java.html.json.Model; +import net.java.html.json.Property; + +/** + * + * @author Jaroslav Tulach + */ +@Model(className = "ChatModel", properties = { + @Property(name = "user", type = String.class), + @Property(name = "text", type = String.class), + @Property(name = "msgs", type = Message.class, array = true) +}) +class ChatClient { + @ComputedProperty + static boolean sendEnabled(String user, String text) { + boolean res = user != null && text != null && !user.isEmpty() && !text.isEmpty(); + try { + if (true) throw new IllegalStateException("Query for msg '" + text + "' by user " + user + " res: " + res); + } catch (Exception ex) { + + } + return res; + } + + @Function + static void submit(ChatModel m) { + if (!sendEnabled(m.getUser(), m.getText())) { + return; + } + Message msg = new Message(CNTX); + msg.setComment(m.getText()); + msg.setUser(m.getUser()); + m.getMsgs().add(msg); + } + + static final Context CNTX = Context.findDefault(ChatClient.class); + static { + ChatModel chm = new ChatModel(CNTX); + Message m = new Message(CNTX); + m.setComment("Hello World!"); + m.setUser("Jarda"); + chm.getMsgs().add(m); + chm.applyBindings(); + } +} diff -r a707111432df -r f0a52c72ef74 serverside/src/main/java/org/apidesign/bck2brwsr/demo/serverside/MessageImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/src/main/java/org/apidesign/bck2brwsr/demo/serverside/MessageImpl.java Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,49 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.bck2brwsr.demo.serverside; + +import net.java.html.json.ComputedProperty; +import net.java.html.json.Model; +import net.java.html.json.Property; + +/** + * + * @author Jaroslav Tulach + */ +@Model(className = "Message", properties = { + @Property(name = "user", type = String.class), + @Property(name = "comment", type = String.class), +// @Property(name = "when", type = long.class) +}) +class MessageImpl { + @ComputedProperty static String at() { + return "nekdy"; + } + + @Model(className = "Query", properties = { + @Property(name = "messages", type = Message.class, array = true) + }) + class QryMsgs { + } +} diff -r a707111432df -r f0a52c72ef74 serverside/src/main/resources/org/apidesign/bck2brwsr/demo/serverside/chat.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/src/main/resources/org/apidesign/bck2brwsr/demo/serverside/chat.html Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,54 @@ + + + + + Chat via Jersey Server + + + +
Username:
+ +
Message:
+ + + +
    +
  • + @ + : + +
  • +
+ + + + + + diff -r a707111432df -r f0a52c72ef74 serverside/src/test/java/org/apidesign/bck2brwsr/demo/serverside/ChatClientTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serverside/src/test/java/org/apidesign/bck2brwsr/demo/serverside/ChatClientTest.java Sat May 04 07:21:05 2013 +0200 @@ -0,0 +1,55 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.bck2brwsr.demo.serverside; + +import net.java.html.json.Context; +import static org.testng.Assert.*; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class ChatClientTest { + public ChatClientTest() { + } + + @Test public void hasSendEnabled() { + ChatModel m = new ChatModel(Context.EMPTY); + assertFalse(m.isSendEnabled(), "By default disabled"); + m.setText("some msg"); + m.setUser("by me"); + assertTrue(m.isSendEnabled(), "Now it is enabled"); + m.setUser(null); + assertFalse(m.isSendEnabled(), "No user means disabled"); + m.setUser("by him"); + assertTrue(m.isSendEnabled(), "Again enabled"); + m.setText(""); + assertFalse(m.isSendEnabled(), "Empty text means disabled"); + } +}