Cleaning the version mess a bit classloader
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 26 Jun 2013 19:29:54 +0200
branchclassloader
changeset 1228462dd9238173
parent 1227 5a907f38608d
child 1229 592cb4e0f363
Cleaning the version mess a bit
ko/archetype-test/pom.xml
ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java
ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java
ko/archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java
ko/archetype-test/src/test/java/org/apidesign/html/archetype/test/VerifyArchetypeTest.java
ko/archetype/pom.xml
ko/archetype/src/main/java/org/apidesign/bck2brwsr/ko/archetype/package-info.java
ko/archetype/src/main/java/org/apidesign/html/archetype/package-info.java
ko/bck2brwsr/pom.xml
ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxImpl.java
ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxPrvdr.java
ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/ConvertTypes.java
ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/Knockout.java
ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/BrwsrCtxImpl.java
ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/BrwsrCtxPrvdr.java
ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/ConvertTypes.java
ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/Knockout.java
ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java
ko/bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java
pom.xml
     1.1 --- a/ko/archetype-test/pom.xml	Wed Jun 26 18:44:21 2013 +0200
     1.2 +++ b/ko/archetype-test/pom.xml	Wed Jun 26 19:29:54 2013 +0200
     1.3 @@ -2,14 +2,14 @@
     1.4  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     1.5      <modelVersion>4.0.0</modelVersion>
     1.6      <parent>
     1.7 -        <groupId>org.apidesign</groupId>
     1.8 -        <artifactId>html</artifactId>
     1.9 -        <version>0.4-SNAPSHOT</version>
    1.10 +        <groupId>org.apidesign.bck2brwsr</groupId>
    1.11 +        <artifactId>ko</artifactId>
    1.12 +        <version>0.8-SNAPSHOT</version>
    1.13      </parent>
    1.14 -    <groupId>org.apidesign.html</groupId>
    1.15 +    <groupId>org.apidesign.bck2brwsr</groupId>
    1.16      <artifactId>ko-archetype-test</artifactId>
    1.17 -    <version>0.4-SNAPSHOT</version>
    1.18 -    <name>Knockout 4 Java Archetype Test</name>
    1.19 +    <version>0.8-SNAPSHOT</version>
    1.20 +    <name>Knockout Bck2Brwsr Archetype Test</name>
    1.21      <url>http://maven.apache.org</url>
    1.22      <description>Verifies the Knockout &amp; net.java.html.json archetype behaves properly.</description>
    1.23      <properties>
    1.24 @@ -19,7 +19,7 @@
    1.25          <dependency>
    1.26              <groupId>${project.groupId}</groupId>
    1.27              <artifactId>knockout4j-archetype</artifactId>
    1.28 -            <version>0.4-SNAPSHOT</version>
    1.29 +            <version>${project.version}</version>
    1.30          </dependency>
    1.31          <dependency>
    1.32              <groupId>org.testng</groupId>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java	Wed Jun 26 19:29:54 2013 +0200
     2.3 @@ -0,0 +1,136 @@
     2.4 +/**
     2.5 + * Back 2 Browser Bytecode Translator
     2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, version 2 of the License.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program. Look for COPYING file in the top folder.
    2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 + */
    2.21 +package org.apidesign.bck2brwsr.ko.archetype.test;
    2.22 +
    2.23 +import java.io.IOException;
    2.24 +import java.net.URL;
    2.25 +import javax.xml.XMLConstants;
    2.26 +import javax.xml.parsers.DocumentBuilderFactory;
    2.27 +import javax.xml.parsers.ParserConfigurationException;
    2.28 +import javax.xml.xpath.XPathConstants;
    2.29 +import javax.xml.xpath.XPathExpression;
    2.30 +import javax.xml.xpath.XPathExpressionException;
    2.31 +import javax.xml.xpath.XPathFactory;
    2.32 +import javax.xml.xpath.XPathFactoryConfigurationException;
    2.33 +import org.testng.annotations.Test;
    2.34 +import static org.testng.Assert.*;
    2.35 +import org.testng.annotations.BeforeClass;
    2.36 +import org.w3c.dom.Document;
    2.37 +import org.w3c.dom.NodeList;
    2.38 +import org.xml.sax.SAXException;
    2.39 +
    2.40 +/**
    2.41 + *
    2.42 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.43 + */
    2.44 +public class ArchetypeVersionTest {
    2.45 +    private String version;
    2.46 +    
    2.47 +    public ArchetypeVersionTest() {
    2.48 +    }
    2.49 +    
    2.50 +    @BeforeClass public void readCurrentVersion() throws Exception {
    2.51 +        version = findCurrentVersion();
    2.52 +        assertFalse(version.isEmpty(), "There should be some version string");
    2.53 +    }
    2.54 +    
    2.55 +
    2.56 +    @Test public void testComparePomDepsVersions() throws Exception {
    2.57 +        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    2.58 +        URL r = l.getResource("archetype-resources/pom.xml");
    2.59 +        assertNotNull(r, "Archetype pom found");
    2.60 +        
    2.61 +        final XPathFactory fact = XPathFactory.newInstance();
    2.62 +        XPathExpression xp2 = fact.newXPath().compile(
    2.63 +            "//properties/net.java.html.version/text()"
    2.64 +        );
    2.65 +        
    2.66 +        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    2.67 +        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    2.68 +
    2.69 +        assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
    2.70 +    }
    2.71 +    
    2.72 +    @Test public void testCheckLauncher() throws Exception {
    2.73 +        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    2.74 +        URL r = l.getResource("archetype-resources/pom.xml");
    2.75 +        assertNotNull(r, "Archetype pom found");
    2.76 +        
    2.77 +        final XPathFactory fact = XPathFactory.newInstance();
    2.78 +        XPathExpression xp2 = fact.newXPath().compile(
    2.79 +            "//properties/bck2brwsr.launcher.version/text()"
    2.80 +        );
    2.81 +        
    2.82 +        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    2.83 +        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    2.84 +
    2.85 +        
    2.86 +        assertTrue(arch.matches("[0-9\\.]+"), "launcher version seems valid: " + arch);
    2.87 +    }
    2.88 +    
    2.89 +    @Test public void testCheckBck2Brwsr() throws Exception {
    2.90 +        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    2.91 +        URL r = l.getResource("archetype-resources/pom.xml");
    2.92 +        assertNotNull(r, "Archetype pom found");
    2.93 +        
    2.94 +        final XPathFactory fact = XPathFactory.newInstance();
    2.95 +        XPathExpression xp2 = fact.newXPath().compile(
    2.96 +            "//properties/bck2brwsr.version/text()"
    2.97 +        );
    2.98 +        
    2.99 +        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   2.100 +        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
   2.101 +        
   2.102 +        assertTrue(arch.matches("[0-9\\.]+"), "bck2brwsr version seems valid: " + arch);
   2.103 +    }
   2.104 +    
   2.105 +    @Test public void testNbActions() throws Exception {
   2.106 +        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   2.107 +        URL r = l.getResource("archetype-resources/nbactions.xml");
   2.108 +        assertNotNull(r, "Archetype nb file found");
   2.109 +        
   2.110 +        final XPathFactory fact = XPathFactory.newInstance();
   2.111 +        XPathExpression xp2 = fact.newXPath().compile(
   2.112 +            "//goal/text()"
   2.113 +        );
   2.114 +        
   2.115 +        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   2.116 +        NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
   2.117 +        
   2.118 +        for (int i = 0; i < goals.getLength(); i++) {
   2.119 +            String s = goals.item(i).getTextContent();
   2.120 +            if (s.contains("apidesign")) {
   2.121 +                assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
   2.122 +            }
   2.123 +        }
   2.124 +    }
   2.125 +
   2.126 +    static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
   2.127 +        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   2.128 +        URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
   2.129 +        assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
   2.130 +
   2.131 +        final XPathFactory fact = XPathFactory.newInstance();
   2.132 +        fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
   2.133 +
   2.134 +        XPathExpression xp = fact.newXPath().compile("project/version/text()");
   2.135 +        
   2.136 +        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
   2.137 +        return xp.evaluate(dom);
   2.138 +    }
   2.139 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java	Wed Jun 26 19:29:54 2013 +0200
     3.3 @@ -0,0 +1,116 @@
     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.ko.archetype.test;
    3.22 +
    3.23 +import java.io.File;
    3.24 +import java.util.Properties;
    3.25 +import java.util.zip.ZipFile;
    3.26 +import org.apache.maven.it.Verifier;
    3.27 +import org.testng.annotations.Test;
    3.28 +import static org.testng.Assert.*;
    3.29 +
    3.30 +/**
    3.31 + *
    3.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.33 + */
    3.34 +public class VerifyArchetypeTest {
    3.35 +    @Test public void fxBrwsrCompiles() throws Exception {
    3.36 +        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
    3.37 +        generateFromArchetype(dir);
    3.38 +        
    3.39 +        File created = new File(dir, "o-a-test");
    3.40 +        assertTrue(created.isDirectory(), "Project created");
    3.41 +        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    3.42 +        
    3.43 +        Verifier v = new Verifier(created.getAbsolutePath());
    3.44 +        v.executeGoal("verify");
    3.45 +        
    3.46 +        v.verifyErrorFreeLog();
    3.47 +        
    3.48 +        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    3.49 +            if (l.contains("j2js")) {
    3.50 +                fail("No pre-compilaton:\n" + l);
    3.51 +            }
    3.52 +        }
    3.53 +        
    3.54 +        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
    3.55 +        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
    3.56 +    }
    3.57 +    
    3.58 +    @Test public void bck2BrwsrCompiles() throws Exception {
    3.59 +        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
    3.60 +        generateFromArchetype(dir);
    3.61 +        
    3.62 +        File created = new File(dir, "o-a-test");
    3.63 +        assertTrue(created.isDirectory(), "Project created");
    3.64 +        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    3.65 +        
    3.66 +        Verifier v = new Verifier(created.getAbsolutePath());
    3.67 +        Properties sysProp = v.getSystemProperties();
    3.68 +        if (Boolean.getBoolean("java.awt.headless")) {
    3.69 +            sysProp.put("java.awt.headless", "true");
    3.70 +        }
    3.71 +        v.addCliOption("-Pbck2brwsr");
    3.72 +        v.executeGoal("verify");
    3.73 +        
    3.74 +        v.verifyErrorFreeLog();
    3.75 +        
    3.76 +        // does pre-compilation to JavaScript
    3.77 +        v.verifyTextInLog("j2js");
    3.78 +        // uses Bck2BrwsrLauncher
    3.79 +        v.verifyTextInLog("BaseHTTPLauncher stopServerAndBrwsr");
    3.80 +        // building zip:
    3.81 +        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    3.82 +        
    3.83 +        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    3.84 +            if (l.contains("fxbrwsr")) {
    3.85 +                fail("No fxbrwsr:\n" + l);
    3.86 +            }
    3.87 +        }
    3.88 +
    3.89 +        File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    3.90 +        assertTrue(zip.isFile(), "Zip file with website was created");
    3.91 +        
    3.92 +        ZipFile zf = new ZipFile(zip);
    3.93 +        assertNotNull(zf.getEntry("public_html/index.html"), "index.html found");
    3.94 +        assertNotNull(zf.getEntry("public_html/twitterExample.css"), "css file found");
    3.95 +        
    3.96 +    }
    3.97 +
    3.98 +    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
    3.99 +        Verifier v = new Verifier(dir.getAbsolutePath());
   3.100 +        v.setAutoclean(false);
   3.101 +        v.setLogFileName("generate.log");
   3.102 +        v.deleteDirectory("");
   3.103 +        dir.mkdirs();
   3.104 +        Properties sysProp = v.getSystemProperties();
   3.105 +        sysProp.put("groupId", "org.apidesign.test");
   3.106 +        sysProp.put("artifactId", "o-a-test");
   3.107 +        sysProp.put("package", "org.apidesign.test.oat");
   3.108 +        sysProp.put("archetypeGroupId", "org.apidesign.html");
   3.109 +        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
   3.110 +        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
   3.111 +        
   3.112 +        for (String p : params) {
   3.113 +            v.addCliOption(p);
   3.114 +        }
   3.115 +        v.executeGoal("archetype:generate");
   3.116 +        v.verifyErrorFreeLog();
   3.117 +        return v;
   3.118 +    }
   3.119 +}
     4.1 --- a/ko/archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java	Wed Jun 26 18:44:21 2013 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,136 +0,0 @@
     4.4 -/**
     4.5 - * Back 2 Browser Bytecode Translator
     4.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 - *
     4.8 - * This program is free software: you can redistribute it and/or modify
     4.9 - * it under the terms of the GNU General Public License as published by
    4.10 - * the Free Software Foundation, version 2 of the License.
    4.11 - *
    4.12 - * This program is distributed in the hope that it will be useful,
    4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 - * GNU General Public License for more details.
    4.16 - *
    4.17 - * You should have received a copy of the GNU General Public License
    4.18 - * along with this program. Look for COPYING file in the top folder.
    4.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    4.20 - */
    4.21 -package org.apidesign.html.archetype.test;
    4.22 -
    4.23 -import java.io.IOException;
    4.24 -import java.net.URL;
    4.25 -import javax.xml.XMLConstants;
    4.26 -import javax.xml.parsers.DocumentBuilderFactory;
    4.27 -import javax.xml.parsers.ParserConfigurationException;
    4.28 -import javax.xml.xpath.XPathConstants;
    4.29 -import javax.xml.xpath.XPathExpression;
    4.30 -import javax.xml.xpath.XPathExpressionException;
    4.31 -import javax.xml.xpath.XPathFactory;
    4.32 -import javax.xml.xpath.XPathFactoryConfigurationException;
    4.33 -import org.testng.annotations.Test;
    4.34 -import static org.testng.Assert.*;
    4.35 -import org.testng.annotations.BeforeClass;
    4.36 -import org.w3c.dom.Document;
    4.37 -import org.w3c.dom.NodeList;
    4.38 -import org.xml.sax.SAXException;
    4.39 -
    4.40 -/**
    4.41 - *
    4.42 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    4.43 - */
    4.44 -public class ArchetypeVersionTest {
    4.45 -    private String version;
    4.46 -    
    4.47 -    public ArchetypeVersionTest() {
    4.48 -    }
    4.49 -    
    4.50 -    @BeforeClass public void readCurrentVersion() throws Exception {
    4.51 -        version = findCurrentVersion();
    4.52 -        assertFalse(version.isEmpty(), "There should be some version string");
    4.53 -    }
    4.54 -    
    4.55 -
    4.56 -    @Test public void testComparePomDepsVersions() throws Exception {
    4.57 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    4.58 -        URL r = l.getResource("archetype-resources/pom.xml");
    4.59 -        assertNotNull(r, "Archetype pom found");
    4.60 -        
    4.61 -        final XPathFactory fact = XPathFactory.newInstance();
    4.62 -        XPathExpression xp2 = fact.newXPath().compile(
    4.63 -            "//properties/net.java.html.version/text()"
    4.64 -        );
    4.65 -        
    4.66 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    4.67 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    4.68 -
    4.69 -        assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
    4.70 -    }
    4.71 -    
    4.72 -    @Test public void testCheckLauncher() throws Exception {
    4.73 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    4.74 -        URL r = l.getResource("archetype-resources/pom.xml");
    4.75 -        assertNotNull(r, "Archetype pom found");
    4.76 -        
    4.77 -        final XPathFactory fact = XPathFactory.newInstance();
    4.78 -        XPathExpression xp2 = fact.newXPath().compile(
    4.79 -            "//properties/bck2brwsr.launcher.version/text()"
    4.80 -        );
    4.81 -        
    4.82 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    4.83 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    4.84 -
    4.85 -        
    4.86 -        assertTrue(arch.matches("[0-9\\.]+"), "launcher version seems valid: " + arch);
    4.87 -    }
    4.88 -    
    4.89 -    @Test public void testCheckBck2Brwsr() throws Exception {
    4.90 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    4.91 -        URL r = l.getResource("archetype-resources/pom.xml");
    4.92 -        assertNotNull(r, "Archetype pom found");
    4.93 -        
    4.94 -        final XPathFactory fact = XPathFactory.newInstance();
    4.95 -        XPathExpression xp2 = fact.newXPath().compile(
    4.96 -            "//properties/bck2brwsr.version/text()"
    4.97 -        );
    4.98 -        
    4.99 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   4.100 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
   4.101 -        
   4.102 -        assertTrue(arch.matches("[0-9\\.]+"), "bck2brwsr version seems valid: " + arch);
   4.103 -    }
   4.104 -    
   4.105 -    @Test public void testNbActions() throws Exception {
   4.106 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   4.107 -        URL r = l.getResource("archetype-resources/nbactions.xml");
   4.108 -        assertNotNull(r, "Archetype nb file found");
   4.109 -        
   4.110 -        final XPathFactory fact = XPathFactory.newInstance();
   4.111 -        XPathExpression xp2 = fact.newXPath().compile(
   4.112 -            "//goal/text()"
   4.113 -        );
   4.114 -        
   4.115 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   4.116 -        NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
   4.117 -        
   4.118 -        for (int i = 0; i < goals.getLength(); i++) {
   4.119 -            String s = goals.item(i).getTextContent();
   4.120 -            if (s.contains("apidesign")) {
   4.121 -                assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
   4.122 -            }
   4.123 -        }
   4.124 -    }
   4.125 -
   4.126 -    static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
   4.127 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   4.128 -        URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
   4.129 -        assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
   4.130 -
   4.131 -        final XPathFactory fact = XPathFactory.newInstance();
   4.132 -        fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
   4.133 -
   4.134 -        XPathExpression xp = fact.newXPath().compile("project/version/text()");
   4.135 -        
   4.136 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
   4.137 -        return xp.evaluate(dom);
   4.138 -    }
   4.139 -}
     5.1 --- a/ko/archetype-test/src/test/java/org/apidesign/html/archetype/test/VerifyArchetypeTest.java	Wed Jun 26 18:44:21 2013 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,116 +0,0 @@
     5.4 -/**
     5.5 - * Back 2 Browser Bytecode Translator
     5.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License as published by
    5.10 - * the Free Software Foundation, version 2 of the License.
    5.11 - *
    5.12 - * This program is distributed in the hope that it will be useful,
    5.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 - * GNU General Public License for more details.
    5.16 - *
    5.17 - * You should have received a copy of the GNU General Public License
    5.18 - * along with this program. Look for COPYING file in the top folder.
    5.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 - */
    5.21 -package org.apidesign.html.archetype.test;
    5.22 -
    5.23 -import java.io.File;
    5.24 -import java.util.Properties;
    5.25 -import java.util.zip.ZipFile;
    5.26 -import org.apache.maven.it.Verifier;
    5.27 -import org.testng.annotations.Test;
    5.28 -import static org.testng.Assert.*;
    5.29 -
    5.30 -/**
    5.31 - *
    5.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    5.33 - */
    5.34 -public class VerifyArchetypeTest {
    5.35 -    @Test public void fxBrwsrCompiles() throws Exception {
    5.36 -        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
    5.37 -        generateFromArchetype(dir);
    5.38 -        
    5.39 -        File created = new File(dir, "o-a-test");
    5.40 -        assertTrue(created.isDirectory(), "Project created");
    5.41 -        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    5.42 -        
    5.43 -        Verifier v = new Verifier(created.getAbsolutePath());
    5.44 -        v.executeGoal("verify");
    5.45 -        
    5.46 -        v.verifyErrorFreeLog();
    5.47 -        
    5.48 -        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    5.49 -            if (l.contains("j2js")) {
    5.50 -                fail("No pre-compilaton:\n" + l);
    5.51 -            }
    5.52 -        }
    5.53 -        
    5.54 -        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
    5.55 -        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
    5.56 -    }
    5.57 -    
    5.58 -    @Test public void bck2BrwsrCompiles() throws Exception {
    5.59 -        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
    5.60 -        generateFromArchetype(dir);
    5.61 -        
    5.62 -        File created = new File(dir, "o-a-test");
    5.63 -        assertTrue(created.isDirectory(), "Project created");
    5.64 -        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    5.65 -        
    5.66 -        Verifier v = new Verifier(created.getAbsolutePath());
    5.67 -        Properties sysProp = v.getSystemProperties();
    5.68 -        if (Boolean.getBoolean("java.awt.headless")) {
    5.69 -            sysProp.put("java.awt.headless", "true");
    5.70 -        }
    5.71 -        v.addCliOption("-Pbck2brwsr");
    5.72 -        v.executeGoal("verify");
    5.73 -        
    5.74 -        v.verifyErrorFreeLog();
    5.75 -        
    5.76 -        // does pre-compilation to JavaScript
    5.77 -        v.verifyTextInLog("j2js");
    5.78 -        // uses Bck2BrwsrLauncher
    5.79 -        v.verifyTextInLog("BaseHTTPLauncher stopServerAndBrwsr");
    5.80 -        // building zip:
    5.81 -        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    5.82 -        
    5.83 -        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    5.84 -            if (l.contains("fxbrwsr")) {
    5.85 -                fail("No fxbrwsr:\n" + l);
    5.86 -            }
    5.87 -        }
    5.88 -
    5.89 -        File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    5.90 -        assertTrue(zip.isFile(), "Zip file with website was created");
    5.91 -        
    5.92 -        ZipFile zf = new ZipFile(zip);
    5.93 -        assertNotNull(zf.getEntry("public_html/index.html"), "index.html found");
    5.94 -        assertNotNull(zf.getEntry("public_html/twitterExample.css"), "css file found");
    5.95 -        
    5.96 -    }
    5.97 -
    5.98 -    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
    5.99 -        Verifier v = new Verifier(dir.getAbsolutePath());
   5.100 -        v.setAutoclean(false);
   5.101 -        v.setLogFileName("generate.log");
   5.102 -        v.deleteDirectory("");
   5.103 -        dir.mkdirs();
   5.104 -        Properties sysProp = v.getSystemProperties();
   5.105 -        sysProp.put("groupId", "org.apidesign.test");
   5.106 -        sysProp.put("artifactId", "o-a-test");
   5.107 -        sysProp.put("package", "org.apidesign.test.oat");
   5.108 -        sysProp.put("archetypeGroupId", "org.apidesign.html");
   5.109 -        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
   5.110 -        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
   5.111 -        
   5.112 -        for (String p : params) {
   5.113 -            v.addCliOption(p);
   5.114 -        }
   5.115 -        v.executeGoal("archetype:generate");
   5.116 -        v.verifyErrorFreeLog();
   5.117 -        return v;
   5.118 -    }
   5.119 -}
     6.1 --- a/ko/archetype/pom.xml	Wed Jun 26 18:44:21 2013 +0200
     6.2 +++ b/ko/archetype/pom.xml	Wed Jun 26 19:29:54 2013 +0200
     6.3 @@ -2,15 +2,15 @@
     6.4  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     6.5    <modelVersion>4.0.0</modelVersion>
     6.6    <parent>
     6.7 -    <artifactId>html</artifactId>
     6.8 -    <groupId>org.apidesign</groupId>
     6.9 -    <version>0.4-SNAPSHOT</version>
    6.10 +    <artifactId>ko</artifactId>
    6.11 +    <groupId>org.apidesign.bck2brwsr</groupId>
    6.12 +    <version>0.8-SNAPSHOT</version>
    6.13    </parent>
    6.14 -  <groupId>org.apidesign.html</groupId>
    6.15 +  <groupId>org.apidesign.bck2brwsr</groupId>
    6.16    <artifactId>knockout4j-archetype</artifactId>
    6.17 -  <version>0.4-SNAPSHOT</version>
    6.18 +  <version>0.8-SNAPSHOT</version>
    6.19    <packaging>jar</packaging>
    6.20 -  <name>Knockout 4 Java Maven Archetype</name>
    6.21 +  <name>Knockout Bck2Brwsr Maven Archetype</name>
    6.22    <description>
    6.23        HTML page with Knockout.js bindings driven by application model
    6.24        written in Java. Use your favorite language to code. Use
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/ko/archetype/src/main/java/org/apidesign/bck2brwsr/ko/archetype/package-info.java	Wed Jun 26 19:29:54 2013 +0200
     7.3 @@ -0,0 +1,18 @@
     7.4 +/**
     7.5 + * Back 2 Browser Bytecode Translator
     7.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     7.7 + *
     7.8 + * This program is free software: you can redistribute it and/or modify
     7.9 + * it under the terms of the GNU General Public License as published by
    7.10 + * the Free Software Foundation, version 2 of the License.
    7.11 + *
    7.12 + * This program is distributed in the hope that it will be useful,
    7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 + * GNU General Public License for more details.
    7.16 + *
    7.17 + * You should have received a copy of the GNU General Public License
    7.18 + * along with this program. Look for COPYING file in the top folder.
    7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    7.20 + */
    7.21 +package org.apidesign.bck2brwsr.ko.archetype;
     8.1 --- a/ko/archetype/src/main/java/org/apidesign/html/archetype/package-info.java	Wed Jun 26 18:44:21 2013 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,18 +0,0 @@
     8.4 -/**
     8.5 - * Back 2 Browser Bytecode Translator
     8.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 - *
     8.8 - * This program is free software: you can redistribute it and/or modify
     8.9 - * it under the terms of the GNU General Public License as published by
    8.10 - * the Free Software Foundation, version 2 of the License.
    8.11 - *
    8.12 - * This program is distributed in the hope that it will be useful,
    8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 - * GNU General Public License for more details.
    8.16 - *
    8.17 - * You should have received a copy of the GNU General Public License
    8.18 - * along with this program. Look for COPYING file in the top folder.
    8.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    8.20 - */
    8.21 -package org.apidesign.html.archetype;
     9.1 --- a/ko/bck2brwsr/pom.xml	Wed Jun 26 18:44:21 2013 +0200
     9.2 +++ b/ko/bck2brwsr/pom.xml	Wed Jun 26 19:29:54 2013 +0200
     9.3 @@ -2,13 +2,13 @@
     9.4  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     9.5    <modelVersion>4.0.0</modelVersion>
     9.6    <parent>
     9.7 -    <groupId>org.apidesign</groupId>
     9.8 -    <artifactId>html</artifactId>
     9.9 -    <version>0.4-SNAPSHOT</version>
    9.10 +    <groupId>org.apidesign.bck2brwsr</groupId>
    9.11 +    <artifactId>ko</artifactId>
    9.12 +    <version>0.8-SNAPSHOT</version>
    9.13    </parent>
    9.14 -  <groupId>org.apidesign.html</groupId>
    9.15 +  <groupId>org.apidesign.bck2brwsr</groupId>
    9.16    <artifactId>ko-bck2brwsr</artifactId>
    9.17 -  <version>0.4-SNAPSHOT</version>
    9.18 +  <version>0.8-SNAPSHOT</version>
    9.19    <name>Knockout.b2b</name>
    9.20    <url>http://maven.apache.org</url>
    9.21    <build>
    9.22 @@ -51,7 +51,7 @@
    9.23      <dependency>
    9.24        <groupId>org.apidesign.bck2brwsr</groupId>
    9.25        <artifactId>emul</artifactId>
    9.26 -      <version>${bck2brwsr.version}</version>
    9.27 +      <version>${project.version}</version>
    9.28        <classifier>rt</classifier>
    9.29        <type>jar</type>
    9.30        <scope>compile</scope>
    9.31 @@ -59,20 +59,20 @@
    9.32      <dependency>
    9.33        <groupId>org.apidesign.bck2brwsr</groupId>
    9.34        <artifactId>vm4brwsr</artifactId>
    9.35 -      <version>${bck2brwsr.version}</version>
    9.36 +      <version>${project.version}</version>
    9.37        <type>jar</type>
    9.38        <scope>test</scope>
    9.39      </dependency>
    9.40      <dependency>
    9.41        <groupId>org.apidesign.bck2brwsr</groupId>
    9.42        <artifactId>vmtest</artifactId>
    9.43 -      <version>${bck2brwsr.version}</version>
    9.44 +      <version>${project.version}</version>
    9.45        <scope>test</scope>
    9.46      </dependency>
    9.47      <dependency>
    9.48        <groupId>org.apidesign.bck2brwsr</groupId>
    9.49        <artifactId>launcher.http</artifactId>
    9.50 -      <version>${bck2brwsr.launcher.version}</version>
    9.51 +      <version>${project.version}</version>
    9.52        <scope>test</scope>
    9.53      </dependency>
    9.54      <dependency>
    9.55 @@ -89,7 +89,7 @@
    9.56      <dependency>
    9.57        <groupId>org.apidesign.bck2brwsr</groupId>
    9.58        <artifactId>core</artifactId>
    9.59 -      <version>${bck2brwsr.version}</version>
    9.60 +      <version>${project.version}</version>
    9.61        <type>jar</type>
    9.62      </dependency>
    9.63    </dependencies>
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxImpl.java	Wed Jun 26 19:29:54 2013 +0200
    10.3 @@ -0,0 +1,126 @@
    10.4 +/**
    10.5 + * Back 2 Browser Bytecode Translator
    10.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    10.7 + *
    10.8 + * This program is free software: you can redistribute it and/or modify
    10.9 + * it under the terms of the GNU General Public License as published by
   10.10 + * the Free Software Foundation, version 2 of the License.
   10.11 + *
   10.12 + * This program is distributed in the hope that it will be useful,
   10.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 + * GNU General Public License for more details.
   10.16 + *
   10.17 + * You should have received a copy of the GNU General Public License
   10.18 + * along with this program. Look for COPYING file in the top folder.
   10.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   10.20 + */
   10.21 +package org.apidesign.bck2brwsr.ko2brwsr;
   10.22 +
   10.23 +import java.io.ByteArrayOutputStream;
   10.24 +import java.io.IOException;
   10.25 +import java.io.InputStream;
   10.26 +import java.io.InputStreamReader;
   10.27 +import net.java.html.BrwsrCtx;
   10.28 +import org.apidesign.html.context.spi.Contexts;
   10.29 +import org.apidesign.html.json.spi.FunctionBinding;
   10.30 +import org.apidesign.html.json.spi.JSONCall;
   10.31 +import org.apidesign.html.json.spi.PropertyBinding;
   10.32 +import org.apidesign.html.json.spi.Technology;
   10.33 +import org.apidesign.html.json.spi.Transfer;
   10.34 +
   10.35 +/**
   10.36 + *
   10.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   10.38 + */
   10.39 +final class BrwsrCtxImpl implements Technology<Object>, Transfer {
   10.40 +    private BrwsrCtxImpl() {}
   10.41 +    
   10.42 +    public static final BrwsrCtxImpl DEFAULT = new BrwsrCtxImpl();
   10.43 +    
   10.44 +    @Override
   10.45 +    public void extract(Object obj, String[] props, Object[] values) {
   10.46 +        ConvertTypes.extractJSON(obj, props, values);
   10.47 +    }
   10.48 +
   10.49 +    @Override
   10.50 +    public void loadJSON(final JSONCall call) {
   10.51 +        class R implements Runnable {
   10.52 +            Object[] arr = { null };
   10.53 +            @Override
   10.54 +            public void run() {
   10.55 +                call.notifySuccess(arr[0]);
   10.56 +            }
   10.57 +        }
   10.58 +        R r = new R();
   10.59 +        if (call.isJSONP()) {
   10.60 +            String me = ConvertTypes.createJSONP(r.arr, r);
   10.61 +            ConvertTypes.loadJSONP(call.composeURL(me), me);
   10.62 +        } else {
   10.63 +            String data = null;
   10.64 +            if (call.isDoOutput()) {
   10.65 +                try {
   10.66 +                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
   10.67 +                    call.writeData(bos);
   10.68 +                    data = new String(bos.toByteArray(), "UTF-8");
   10.69 +                } catch (IOException ex) {
   10.70 +                    call.notifyError(ex);
   10.71 +                }
   10.72 +            }
   10.73 +            ConvertTypes.loadJSON(call.composeURL(null), r.arr, r, call.getMethod(), data);
   10.74 +        }
   10.75 +    }
   10.76 +
   10.77 +    @Override
   10.78 +    public Object wrapModel(Object model) {
   10.79 +        return model;
   10.80 +    }
   10.81 +
   10.82 +    @Override
   10.83 +    public void bind(PropertyBinding b, Object model, Object data) {
   10.84 +        Knockout.bind(data, b, b.getPropertyName(), 
   10.85 +            "getValue__Ljava_lang_Object_2", 
   10.86 +            b.isReadOnly() ? null : "setValue__VLjava_lang_Object_2", 
   10.87 +            false, false
   10.88 +        );
   10.89 +    }
   10.90 +
   10.91 +    @Override
   10.92 +    public void valueHasMutated(Object data, String propertyName) {
   10.93 +        Knockout.valueHasMutated(data, propertyName);
   10.94 +    }
   10.95 +
   10.96 +    @Override
   10.97 +    public void expose(FunctionBinding fb, Object model, Object d) {
   10.98 +        Knockout.expose(d, fb, fb.getFunctionName(), "call__VLjava_lang_Object_2Ljava_lang_Object_2");
   10.99 +    }
  10.100 +
  10.101 +    @Override
  10.102 +    public void applyBindings(Object data) {
  10.103 +        Knockout.applyBindings(data);
  10.104 +    }
  10.105 +
  10.106 +    @Override
  10.107 +    public Object wrapArray(Object[] arr) {
  10.108 +        return arr;
  10.109 +    }
  10.110 +
  10.111 +    @Override
  10.112 +    public <M> M toModel(Class<M> modelClass, Object data) {
  10.113 +        return modelClass.cast(data);
  10.114 +    }
  10.115 +
  10.116 +    @Override
  10.117 +    public Object toJSON(InputStream is) throws IOException {
  10.118 +        StringBuilder sb = new StringBuilder();
  10.119 +        InputStreamReader r = new InputStreamReader(is);
  10.120 +        for (;;) {
  10.121 +            int ch = r.read();
  10.122 +            if (ch == -1) {
  10.123 +                break;
  10.124 +            }
  10.125 +            sb.append((char)ch);
  10.126 +        }
  10.127 +        return ConvertTypes.parse(sb.toString());
  10.128 +    }
  10.129 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxPrvdr.java	Wed Jun 26 19:29:54 2013 +0200
    11.3 @@ -0,0 +1,51 @@
    11.4 +/**
    11.5 + * Back 2 Browser Bytecode Translator
    11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    11.7 + *
    11.8 + * This program is free software: you can redistribute it and/or modify
    11.9 + * it under the terms of the GNU General Public License as published by
   11.10 + * the Free Software Foundation, version 2 of the License.
   11.11 + *
   11.12 + * This program is distributed in the hope that it will be useful,
   11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 + * GNU General Public License for more details.
   11.16 + *
   11.17 + * You should have received a copy of the GNU General Public License
   11.18 + * along with this program. Look for COPYING file in the top folder.
   11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   11.20 + */
   11.21 +package org.apidesign.bck2brwsr.ko2brwsr;
   11.22 +
   11.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   11.24 +import org.apidesign.html.context.spi.Contexts;
   11.25 +import org.apidesign.html.json.spi.Technology;
   11.26 +import org.apidesign.html.json.spi.Transfer;
   11.27 +import org.openide.util.lookup.ServiceProvider;
   11.28 +
   11.29 +/** This is an implementation package - just
   11.30 + * include its JAR on classpath and use official {@link Context} API
   11.31 + * to access the functionality.
   11.32 + * <p>
   11.33 + * Provides binding between models and <a href="http://bck2brwsr.apidesign.org">
   11.34 + * Bck2Brwsr</a> VM.
   11.35 + * Registers {@link ContextProvider}, so {@link ServiceLoader} can find it.
   11.36 + *
   11.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.38 + */
   11.39 +@ServiceProvider(service = Contexts.Provider.class)
   11.40 +public final class BrwsrCtxPrvdr implements Contexts.Provider {
   11.41 +
   11.42 +    @Override
   11.43 +    public void fillContext(Contexts.Builder context, Class<?> requestor) {
   11.44 +        if (bck2BrwsrVM()) {
   11.45 +            context.register(Technology.class, BrwsrCtxImpl.DEFAULT, 50).
   11.46 +            register(Transfer.class, BrwsrCtxImpl.DEFAULT, 50);
   11.47 +        }
   11.48 +    }
   11.49 +    
   11.50 +    @JavaScriptBody(args = {  }, body = "return true;")
   11.51 +    private static boolean bck2BrwsrVM() {
   11.52 +        return false;
   11.53 +    }
   11.54 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/ConvertTypes.java	Wed Jun 26 19:29:54 2013 +0200
    12.3 @@ -0,0 +1,152 @@
    12.4 +/**
    12.5 + * Back 2 Browser Bytecode Translator
    12.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    12.7 + *
    12.8 + * This program is free software: you can redistribute it and/or modify
    12.9 + * it under the terms of the GNU General Public License as published by
   12.10 + * the Free Software Foundation, version 2 of the License.
   12.11 + *
   12.12 + * This program is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU General Public License
   12.18 + * along with this program. Look for COPYING file in the top folder.
   12.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   12.20 + */
   12.21 +package org.apidesign.bck2brwsr.ko2brwsr;
   12.22 +
   12.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   12.24 +
   12.25 +/**
   12.26 + *
   12.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   12.28 + */
   12.29 +final class ConvertTypes {
   12.30 +    ConvertTypes() {
   12.31 +    }
   12.32 +    
   12.33 +    public static String toString(Object object, String property) {
   12.34 +        Object ret = getProperty(object, property);
   12.35 +        return ret == null ? null : ret.toString();
   12.36 +    }
   12.37 +
   12.38 +    public static double toDouble(Object object, String property) {
   12.39 +        Object ret = getProperty(object, property);
   12.40 +        return ret instanceof Number ? ((Number)ret).doubleValue() : Double.NaN;
   12.41 +    }
   12.42 +
   12.43 +    public static int toInt(Object object, String property) {
   12.44 +        Object ret = getProperty(object, property);
   12.45 +        return ret instanceof Number ? ((Number)ret).intValue() : Integer.MIN_VALUE;
   12.46 +    }
   12.47 +
   12.48 +    public static <T> T toModel(Class<T> modelClass, Object object, String property) {
   12.49 +        Object ret = getProperty(object, property);
   12.50 +        if (ret == null || modelClass.isInstance(ret)) {
   12.51 +            return modelClass.cast(ret);
   12.52 +        }
   12.53 +        throw new IllegalStateException("Value " + ret + " is not of type " + modelClass);
   12.54 +    }
   12.55 +    
   12.56 +    public static String toJSON(Object value) {
   12.57 +        if (value == null) {
   12.58 +            return "null";
   12.59 +        }
   12.60 +        if (value instanceof Enum) {
   12.61 +            value = value.toString();
   12.62 +        }
   12.63 +        if (value instanceof String) {
   12.64 +            return '"' + 
   12.65 +                ((String)value).
   12.66 +                    replace("\"", "\\\"").
   12.67 +                    replace("\n", "\\n").
   12.68 +                    replace("\r", "\\r").
   12.69 +                    replace("\t", "\\t")
   12.70 +                + '"';
   12.71 +        }
   12.72 +        return value.toString();
   12.73 +    }
   12.74 +    
   12.75 +    @JavaScriptBody(args = { "object", "property" },
   12.76 +        body = "if (property === null) return object;\n"
   12.77 +        + "var p = object[property]; return p ? p : null;"
   12.78 +    )
   12.79 +    private static Object getProperty(Object object, String property) {
   12.80 +        return null;
   12.81 +    }
   12.82 +    
   12.83 +    public static String createJSONP(Object[] jsonResult, Runnable whenDone) {
   12.84 +        int h = whenDone.hashCode();
   12.85 +        String name;
   12.86 +        for (;;) {
   12.87 +            name = "jsonp" + Integer.toHexString(h);
   12.88 +            if (defineIfUnused(name, jsonResult, whenDone)) {
   12.89 +                return name;
   12.90 +            }
   12.91 +            h++;
   12.92 +        }
   12.93 +    }
   12.94 +
   12.95 +    @JavaScriptBody(args = { "name", "arr", "run" }, body = 
   12.96 +        "if (window[name]) return false;\n "
   12.97 +      + "window[name] = function(data) {\n "
   12.98 +      + "  delete window[name];\n"
   12.99 +      + "  var el = window.document.getElementById(name);\n"
  12.100 +      + "  el.parentNode.removeChild(el);\n"
  12.101 +      + "  arr[0] = data;\n"
  12.102 +      + "  run.run__V();\n"
  12.103 +      + "};\n"
  12.104 +      + "return true;\n"
  12.105 +    )
  12.106 +    private static boolean defineIfUnused(String name, Object[] arr, Runnable run) {
  12.107 +        return true;
  12.108 +    }
  12.109 +    
  12.110 +    @JavaScriptBody(args = { "s" }, body = "return eval('(' + s + ')');")
  12.111 +    static Object parse(String s) {
  12.112 +        return s;
  12.113 +    }
  12.114 +    
  12.115 +    @JavaScriptBody(args = { "url", "arr", "callback", "method", "data" }, body = ""
  12.116 +        + "var request = new XMLHttpRequest();\n"
  12.117 +        + "if (!method) method = 'GET';\n"
  12.118 +        + "request.open(method, url, true);\n"
  12.119 +        + "request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');\n"
  12.120 +        + "request.onreadystatechange = function() {\n"
  12.121 +        + "  if (this.readyState!==4) return;\n"
  12.122 +        + "  try {\n"
  12.123 +        + "    arr[0] = eval('(' + this.response + ')');\n"
  12.124 +        + "  } catch (error) {;\n"
  12.125 +        + "    arr[0] = this.response;\n"
  12.126 +        + "  }\n"
  12.127 +        + "  callback.run__V();\n"
  12.128 +        + "};"
  12.129 +        + "if (data) request.send(data);"
  12.130 +        + "else request.send();"
  12.131 +    )
  12.132 +    static void loadJSON(
  12.133 +        String url, Object[] jsonResult, Runnable whenDone, String method, String data
  12.134 +    ) {
  12.135 +    }
  12.136 +    
  12.137 +    @JavaScriptBody(args = { "url", "jsonp" }, body = 
  12.138 +        "var scrpt = window.document.createElement('script');\n "
  12.139 +        + "scrpt.setAttribute('src', url);\n "
  12.140 +        + "scrpt.setAttribute('id', jsonp);\n "
  12.141 +        + "scrpt.setAttribute('type', 'text/javascript');\n "
  12.142 +        + "var body = document.getElementsByTagName('body')[0];\n "
  12.143 +        + "body.appendChild(scrpt);\n"
  12.144 +    )
  12.145 +    static void loadJSONP(String url, String jsonp) {
  12.146 +        
  12.147 +    }
  12.148 +    
  12.149 +    public static void extractJSON(Object jsonObject, String[] props, Object[] values) {
  12.150 +        for (int i = 0; i < props.length; i++) {
  12.151 +            values[i] = getProperty(jsonObject, props[i]);
  12.152 +        }
  12.153 +    }
  12.154 +    
  12.155 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/Knockout.java	Wed Jun 26 19:29:54 2013 +0200
    13.3 @@ -0,0 +1,131 @@
    13.4 +/**
    13.5 + * Back 2 Browser Bytecode Translator
    13.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    13.7 + *
    13.8 + * This program is free software: you can redistribute it and/or modify
    13.9 + * it under the terms of the GNU General Public License as published by
   13.10 + * the Free Software Foundation, version 2 of the License.
   13.11 + *
   13.12 + * This program is distributed in the hope that it will be useful,
   13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 + * GNU General Public License for more details.
   13.16 + *
   13.17 + * You should have received a copy of the GNU General Public License
   13.18 + * along with this program. Look for COPYING file in the top folder.
   13.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   13.20 + */
   13.21 +package org.apidesign.bck2brwsr.ko2brwsr;
   13.22 +
   13.23 +import java.lang.reflect.Method;
   13.24 +import java.util.List;
   13.25 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
   13.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   13.27 +
   13.28 +/** Provides binding between models and bck2brwsr VM.
   13.29 + *
   13.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   13.31 + */
   13.32 +@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js")
   13.33 +final class Knockout {
   13.34 +    /** used by tests */
   13.35 +    static Knockout next;
   13.36 +    private final Object model;
   13.37 +
   13.38 +    Knockout(Object model) {
   13.39 +        this.model = model == null ? this : model;
   13.40 +    }
   13.41 +    
   13.42 +    public static <M> Knockout applyBindings(
   13.43 +        Object model, String[] propsGettersAndSetters,
   13.44 +        String[] methodsAndSignatures
   13.45 +    ) {
   13.46 +        applyImpl(propsGettersAndSetters, model.getClass(), model, model, methodsAndSignatures);
   13.47 +        return new Knockout(model);
   13.48 +    }
   13.49 +    public static <M> Knockout applyBindings(
   13.50 +        Class<M> modelClass, M model, String[] propsGettersAndSetters,
   13.51 +        String[] methodsAndSignatures
   13.52 +    ) {
   13.53 +        Knockout bindings = next;
   13.54 +        next = null;
   13.55 +        if (bindings == null) {
   13.56 +            bindings = new Knockout(null);
   13.57 +        }
   13.58 +        applyImpl(propsGettersAndSetters, modelClass, bindings, model, methodsAndSignatures);
   13.59 +        applyBindings(bindings);
   13.60 +        return bindings;
   13.61 +    }
   13.62 +
   13.63 +    public void valueHasMutated(String prop) {
   13.64 +        valueHasMutated(model, prop);
   13.65 +    }
   13.66 +    @JavaScriptBody(args = { "self", "prop" }, body =
   13.67 +        "var p = self[prop]; if (p) p.valueHasMutated();"
   13.68 +    )
   13.69 +    public static void valueHasMutated(Object self, String prop) {
   13.70 +    }
   13.71 +    
   13.72 +
   13.73 +    @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));")
   13.74 +    public static void triggerEvent(String id, String ev) {
   13.75 +    }
   13.76 +    
   13.77 +    @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive", "array" }, body =
   13.78 +          "var bnd = {\n"
   13.79 +        + "  'read': function() {\n"
   13.80 +        + "    var v = model[getter]();\n"
   13.81 +        + "    if (array) v = v.koArray(); else if (v !== null) v = v.valueOf();\n"
   13.82 +        + "    return v;\n"
   13.83 +        + "  },\n"
   13.84 +        + "  'owner': bindings\n"
   13.85 +        + "};\n"
   13.86 +        + "if (setter != null) {\n"
   13.87 +        + "  bnd['write'] = function(val) {\n"
   13.88 +        + "    var v = val === null ? null : val.valueOf();"
   13.89 +        + "    model[setter](v);\n"
   13.90 +        + "  };\n"
   13.91 +        + "}\n"
   13.92 +        + "bindings[prop] = ko['computed'](bnd);"
   13.93 +    )
   13.94 +    static void bind(
   13.95 +        Object bindings, Object model, String prop, String getter, String setter, boolean primitive, boolean array
   13.96 +    ) {
   13.97 +    }
   13.98 +
   13.99 +    @JavaScriptBody(args = { "bindings", "model", "prop", "sig" }, body = 
  13.100 +        "bindings[prop] = function(data, ev) { model[sig](data, ev); };"
  13.101 +    )
  13.102 +    static void expose(
  13.103 +        Object bindings, Object model, String prop, String sig
  13.104 +    ) {
  13.105 +    }
  13.106 +    
  13.107 +    @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);")
  13.108 +    static void applyBindings(Object bindings) {}
  13.109 +    
  13.110 +    private static void applyImpl(
  13.111 +        String[] propsGettersAndSetters,
  13.112 +        Class<?> modelClass,
  13.113 +        Object bindings,
  13.114 +        Object model,
  13.115 +        String[] methodsAndSignatures
  13.116 +    ) throws IllegalStateException, SecurityException {
  13.117 +        for (int i = 0; i < propsGettersAndSetters.length; i += 4) {
  13.118 +            try {
  13.119 +                Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]);
  13.120 +                bind(bindings, model, propsGettersAndSetters[i],
  13.121 +                    propsGettersAndSetters[i + 1],
  13.122 +                    propsGettersAndSetters[i + 2],
  13.123 +                    getter.getReturnType().isPrimitive(),
  13.124 +                    List.class.isAssignableFrom(getter.getReturnType()));
  13.125 +            } catch (NoSuchMethodException ex) {
  13.126 +                throw new IllegalStateException(ex.getMessage());
  13.127 +            }
  13.128 +        }
  13.129 +        for (int i = 0; i < methodsAndSignatures.length; i += 2) {
  13.130 +            expose(
  13.131 +                bindings, model, methodsAndSignatures[i], methodsAndSignatures[i + 1]);
  13.132 +        }
  13.133 +    }
  13.134 +}
    14.1 --- a/ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/BrwsrCtxImpl.java	Wed Jun 26 18:44:21 2013 +0200
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,126 +0,0 @@
    14.4 -/**
    14.5 - * Back 2 Browser Bytecode Translator
    14.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    14.7 - *
    14.8 - * This program is free software: you can redistribute it and/or modify
    14.9 - * it under the terms of the GNU General Public License as published by
   14.10 - * the Free Software Foundation, version 2 of the License.
   14.11 - *
   14.12 - * This program is distributed in the hope that it will be useful,
   14.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.15 - * GNU General Public License for more details.
   14.16 - *
   14.17 - * You should have received a copy of the GNU General Public License
   14.18 - * along with this program. Look for COPYING file in the top folder.
   14.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   14.20 - */
   14.21 -package org.apidesign.html.ko2brwsr;
   14.22 -
   14.23 -import java.io.ByteArrayOutputStream;
   14.24 -import java.io.IOException;
   14.25 -import java.io.InputStream;
   14.26 -import java.io.InputStreamReader;
   14.27 -import net.java.html.BrwsrCtx;
   14.28 -import org.apidesign.html.context.spi.Contexts;
   14.29 -import org.apidesign.html.json.spi.FunctionBinding;
   14.30 -import org.apidesign.html.json.spi.JSONCall;
   14.31 -import org.apidesign.html.json.spi.PropertyBinding;
   14.32 -import org.apidesign.html.json.spi.Technology;
   14.33 -import org.apidesign.html.json.spi.Transfer;
   14.34 -
   14.35 -/**
   14.36 - *
   14.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   14.38 - */
   14.39 -final class BrwsrCtxImpl implements Technology<Object>, Transfer {
   14.40 -    private BrwsrCtxImpl() {}
   14.41 -    
   14.42 -    public static final BrwsrCtxImpl DEFAULT = new BrwsrCtxImpl();
   14.43 -    
   14.44 -    @Override
   14.45 -    public void extract(Object obj, String[] props, Object[] values) {
   14.46 -        ConvertTypes.extractJSON(obj, props, values);
   14.47 -    }
   14.48 -
   14.49 -    @Override
   14.50 -    public void loadJSON(final JSONCall call) {
   14.51 -        class R implements Runnable {
   14.52 -            Object[] arr = { null };
   14.53 -            @Override
   14.54 -            public void run() {
   14.55 -                call.notifySuccess(arr[0]);
   14.56 -            }
   14.57 -        }
   14.58 -        R r = new R();
   14.59 -        if (call.isJSONP()) {
   14.60 -            String me = ConvertTypes.createJSONP(r.arr, r);
   14.61 -            ConvertTypes.loadJSONP(call.composeURL(me), me);
   14.62 -        } else {
   14.63 -            String data = null;
   14.64 -            if (call.isDoOutput()) {
   14.65 -                try {
   14.66 -                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
   14.67 -                    call.writeData(bos);
   14.68 -                    data = new String(bos.toByteArray(), "UTF-8");
   14.69 -                } catch (IOException ex) {
   14.70 -                    call.notifyError(ex);
   14.71 -                }
   14.72 -            }
   14.73 -            ConvertTypes.loadJSON(call.composeURL(null), r.arr, r, call.getMethod(), data);
   14.74 -        }
   14.75 -    }
   14.76 -
   14.77 -    @Override
   14.78 -    public Object wrapModel(Object model) {
   14.79 -        return model;
   14.80 -    }
   14.81 -
   14.82 -    @Override
   14.83 -    public void bind(PropertyBinding b, Object model, Object data) {
   14.84 -        Knockout.bind(data, b, b.getPropertyName(), 
   14.85 -            "getValue__Ljava_lang_Object_2", 
   14.86 -            b.isReadOnly() ? null : "setValue__VLjava_lang_Object_2", 
   14.87 -            false, false
   14.88 -        );
   14.89 -    }
   14.90 -
   14.91 -    @Override
   14.92 -    public void valueHasMutated(Object data, String propertyName) {
   14.93 -        Knockout.valueHasMutated(data, propertyName);
   14.94 -    }
   14.95 -
   14.96 -    @Override
   14.97 -    public void expose(FunctionBinding fb, Object model, Object d) {
   14.98 -        Knockout.expose(d, fb, fb.getFunctionName(), "call__VLjava_lang_Object_2Ljava_lang_Object_2");
   14.99 -    }
  14.100 -
  14.101 -    @Override
  14.102 -    public void applyBindings(Object data) {
  14.103 -        Knockout.applyBindings(data);
  14.104 -    }
  14.105 -
  14.106 -    @Override
  14.107 -    public Object wrapArray(Object[] arr) {
  14.108 -        return arr;
  14.109 -    }
  14.110 -
  14.111 -    @Override
  14.112 -    public <M> M toModel(Class<M> modelClass, Object data) {
  14.113 -        return modelClass.cast(data);
  14.114 -    }
  14.115 -
  14.116 -    @Override
  14.117 -    public Object toJSON(InputStream is) throws IOException {
  14.118 -        StringBuilder sb = new StringBuilder();
  14.119 -        InputStreamReader r = new InputStreamReader(is);
  14.120 -        for (;;) {
  14.121 -            int ch = r.read();
  14.122 -            if (ch == -1) {
  14.123 -                break;
  14.124 -            }
  14.125 -            sb.append((char)ch);
  14.126 -        }
  14.127 -        return ConvertTypes.parse(sb.toString());
  14.128 -    }
  14.129 -}
    15.1 --- a/ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/BrwsrCtxPrvdr.java	Wed Jun 26 18:44:21 2013 +0200
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,51 +0,0 @@
    15.4 -/**
    15.5 - * Back 2 Browser Bytecode Translator
    15.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    15.7 - *
    15.8 - * This program is free software: you can redistribute it and/or modify
    15.9 - * it under the terms of the GNU General Public License as published by
   15.10 - * the Free Software Foundation, version 2 of the License.
   15.11 - *
   15.12 - * This program is distributed in the hope that it will be useful,
   15.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 - * GNU General Public License for more details.
   15.16 - *
   15.17 - * You should have received a copy of the GNU General Public License
   15.18 - * along with this program. Look for COPYING file in the top folder.
   15.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   15.20 - */
   15.21 -package org.apidesign.html.ko2brwsr;
   15.22 -
   15.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
   15.24 -import org.apidesign.html.context.spi.Contexts;
   15.25 -import org.apidesign.html.json.spi.Technology;
   15.26 -import org.apidesign.html.json.spi.Transfer;
   15.27 -import org.openide.util.lookup.ServiceProvider;
   15.28 -
   15.29 -/** This is an implementation package - just
   15.30 - * include its JAR on classpath and use official {@link Context} API
   15.31 - * to access the functionality.
   15.32 - * <p>
   15.33 - * Provides binding between models and <a href="http://bck2brwsr.apidesign.org">
   15.34 - * Bck2Brwsr</a> VM.
   15.35 - * Registers {@link ContextProvider}, so {@link ServiceLoader} can find it.
   15.36 - *
   15.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   15.38 - */
   15.39 -@ServiceProvider(service = Contexts.Provider.class)
   15.40 -public final class BrwsrCtxPrvdr implements Contexts.Provider {
   15.41 -
   15.42 -    @Override
   15.43 -    public void fillContext(Contexts.Builder context, Class<?> requestor) {
   15.44 -        if (bck2BrwsrVM()) {
   15.45 -            context.register(Technology.class, BrwsrCtxImpl.DEFAULT, 50).
   15.46 -            register(Transfer.class, BrwsrCtxImpl.DEFAULT, 50);
   15.47 -        }
   15.48 -    }
   15.49 -    
   15.50 -    @JavaScriptBody(args = {  }, body = "return true;")
   15.51 -    private static boolean bck2BrwsrVM() {
   15.52 -        return false;
   15.53 -    }
   15.54 -}
    16.1 --- a/ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/ConvertTypes.java	Wed Jun 26 18:44:21 2013 +0200
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,152 +0,0 @@
    16.4 -/**
    16.5 - * Back 2 Browser Bytecode Translator
    16.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    16.7 - *
    16.8 - * This program is free software: you can redistribute it and/or modify
    16.9 - * it under the terms of the GNU General Public License as published by
   16.10 - * the Free Software Foundation, version 2 of the License.
   16.11 - *
   16.12 - * This program is distributed in the hope that it will be useful,
   16.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.15 - * GNU General Public License for more details.
   16.16 - *
   16.17 - * You should have received a copy of the GNU General Public License
   16.18 - * along with this program. Look for COPYING file in the top folder.
   16.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   16.20 - */
   16.21 -package org.apidesign.html.ko2brwsr;
   16.22 -
   16.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
   16.24 -
   16.25 -/**
   16.26 - *
   16.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   16.28 - */
   16.29 -final class ConvertTypes {
   16.30 -    ConvertTypes() {
   16.31 -    }
   16.32 -    
   16.33 -    public static String toString(Object object, String property) {
   16.34 -        Object ret = getProperty(object, property);
   16.35 -        return ret == null ? null : ret.toString();
   16.36 -    }
   16.37 -
   16.38 -    public static double toDouble(Object object, String property) {
   16.39 -        Object ret = getProperty(object, property);
   16.40 -        return ret instanceof Number ? ((Number)ret).doubleValue() : Double.NaN;
   16.41 -    }
   16.42 -
   16.43 -    public static int toInt(Object object, String property) {
   16.44 -        Object ret = getProperty(object, property);
   16.45 -        return ret instanceof Number ? ((Number)ret).intValue() : Integer.MIN_VALUE;
   16.46 -    }
   16.47 -
   16.48 -    public static <T> T toModel(Class<T> modelClass, Object object, String property) {
   16.49 -        Object ret = getProperty(object, property);
   16.50 -        if (ret == null || modelClass.isInstance(ret)) {
   16.51 -            return modelClass.cast(ret);
   16.52 -        }
   16.53 -        throw new IllegalStateException("Value " + ret + " is not of type " + modelClass);
   16.54 -    }
   16.55 -    
   16.56 -    public static String toJSON(Object value) {
   16.57 -        if (value == null) {
   16.58 -            return "null";
   16.59 -        }
   16.60 -        if (value instanceof Enum) {
   16.61 -            value = value.toString();
   16.62 -        }
   16.63 -        if (value instanceof String) {
   16.64 -            return '"' + 
   16.65 -                ((String)value).
   16.66 -                    replace("\"", "\\\"").
   16.67 -                    replace("\n", "\\n").
   16.68 -                    replace("\r", "\\r").
   16.69 -                    replace("\t", "\\t")
   16.70 -                + '"';
   16.71 -        }
   16.72 -        return value.toString();
   16.73 -    }
   16.74 -    
   16.75 -    @JavaScriptBody(args = { "object", "property" },
   16.76 -        body = "if (property === null) return object;\n"
   16.77 -        + "var p = object[property]; return p ? p : null;"
   16.78 -    )
   16.79 -    private static Object getProperty(Object object, String property) {
   16.80 -        return null;
   16.81 -    }
   16.82 -    
   16.83 -    public static String createJSONP(Object[] jsonResult, Runnable whenDone) {
   16.84 -        int h = whenDone.hashCode();
   16.85 -        String name;
   16.86 -        for (;;) {
   16.87 -            name = "jsonp" + Integer.toHexString(h);
   16.88 -            if (defineIfUnused(name, jsonResult, whenDone)) {
   16.89 -                return name;
   16.90 -            }
   16.91 -            h++;
   16.92 -        }
   16.93 -    }
   16.94 -
   16.95 -    @JavaScriptBody(args = { "name", "arr", "run" }, body = 
   16.96 -        "if (window[name]) return false;\n "
   16.97 -      + "window[name] = function(data) {\n "
   16.98 -      + "  delete window[name];\n"
   16.99 -      + "  var el = window.document.getElementById(name);\n"
  16.100 -      + "  el.parentNode.removeChild(el);\n"
  16.101 -      + "  arr[0] = data;\n"
  16.102 -      + "  run.run__V();\n"
  16.103 -      + "};\n"
  16.104 -      + "return true;\n"
  16.105 -    )
  16.106 -    private static boolean defineIfUnused(String name, Object[] arr, Runnable run) {
  16.107 -        return true;
  16.108 -    }
  16.109 -    
  16.110 -    @JavaScriptBody(args = { "s" }, body = "return eval('(' + s + ')');")
  16.111 -    static Object parse(String s) {
  16.112 -        return s;
  16.113 -    }
  16.114 -    
  16.115 -    @JavaScriptBody(args = { "url", "arr", "callback", "method", "data" }, body = ""
  16.116 -        + "var request = new XMLHttpRequest();\n"
  16.117 -        + "if (!method) method = 'GET';\n"
  16.118 -        + "request.open(method, url, true);\n"
  16.119 -        + "request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');\n"
  16.120 -        + "request.onreadystatechange = function() {\n"
  16.121 -        + "  if (this.readyState!==4) return;\n"
  16.122 -        + "  try {\n"
  16.123 -        + "    arr[0] = eval('(' + this.response + ')');\n"
  16.124 -        + "  } catch (error) {;\n"
  16.125 -        + "    arr[0] = this.response;\n"
  16.126 -        + "  }\n"
  16.127 -        + "  callback.run__V();\n"
  16.128 -        + "};"
  16.129 -        + "if (data) request.send(data);"
  16.130 -        + "else request.send();"
  16.131 -    )
  16.132 -    static void loadJSON(
  16.133 -        String url, Object[] jsonResult, Runnable whenDone, String method, String data
  16.134 -    ) {
  16.135 -    }
  16.136 -    
  16.137 -    @JavaScriptBody(args = { "url", "jsonp" }, body = 
  16.138 -        "var scrpt = window.document.createElement('script');\n "
  16.139 -        + "scrpt.setAttribute('src', url);\n "
  16.140 -        + "scrpt.setAttribute('id', jsonp);\n "
  16.141 -        + "scrpt.setAttribute('type', 'text/javascript');\n "
  16.142 -        + "var body = document.getElementsByTagName('body')[0];\n "
  16.143 -        + "body.appendChild(scrpt);\n"
  16.144 -    )
  16.145 -    static void loadJSONP(String url, String jsonp) {
  16.146 -        
  16.147 -    }
  16.148 -    
  16.149 -    public static void extractJSON(Object jsonObject, String[] props, Object[] values) {
  16.150 -        for (int i = 0; i < props.length; i++) {
  16.151 -            values[i] = getProperty(jsonObject, props[i]);
  16.152 -        }
  16.153 -    }
  16.154 -    
  16.155 -}
    17.1 --- a/ko/bck2brwsr/src/main/java/org/apidesign/html/ko2brwsr/Knockout.java	Wed Jun 26 18:44:21 2013 +0200
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,131 +0,0 @@
    17.4 -/**
    17.5 - * Back 2 Browser Bytecode Translator
    17.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    17.7 - *
    17.8 - * This program is free software: you can redistribute it and/or modify
    17.9 - * it under the terms of the GNU General Public License as published by
   17.10 - * the Free Software Foundation, version 2 of the License.
   17.11 - *
   17.12 - * This program is distributed in the hope that it will be useful,
   17.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.15 - * GNU General Public License for more details.
   17.16 - *
   17.17 - * You should have received a copy of the GNU General Public License
   17.18 - * along with this program. Look for COPYING file in the top folder.
   17.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   17.20 - */
   17.21 -package org.apidesign.html.ko2brwsr;
   17.22 -
   17.23 -import java.lang.reflect.Method;
   17.24 -import java.util.List;
   17.25 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
   17.26 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
   17.27 -
   17.28 -/** Provides binding between models and bck2brwsr VM.
   17.29 - *
   17.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   17.31 - */
   17.32 -@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js")
   17.33 -final class Knockout {
   17.34 -    /** used by tests */
   17.35 -    static Knockout next;
   17.36 -    private final Object model;
   17.37 -
   17.38 -    Knockout(Object model) {
   17.39 -        this.model = model == null ? this : model;
   17.40 -    }
   17.41 -    
   17.42 -    public static <M> Knockout applyBindings(
   17.43 -        Object model, String[] propsGettersAndSetters,
   17.44 -        String[] methodsAndSignatures
   17.45 -    ) {
   17.46 -        applyImpl(propsGettersAndSetters, model.getClass(), model, model, methodsAndSignatures);
   17.47 -        return new Knockout(model);
   17.48 -    }
   17.49 -    public static <M> Knockout applyBindings(
   17.50 -        Class<M> modelClass, M model, String[] propsGettersAndSetters,
   17.51 -        String[] methodsAndSignatures
   17.52 -    ) {
   17.53 -        Knockout bindings = next;
   17.54 -        next = null;
   17.55 -        if (bindings == null) {
   17.56 -            bindings = new Knockout(null);
   17.57 -        }
   17.58 -        applyImpl(propsGettersAndSetters, modelClass, bindings, model, methodsAndSignatures);
   17.59 -        applyBindings(bindings);
   17.60 -        return bindings;
   17.61 -    }
   17.62 -
   17.63 -    public void valueHasMutated(String prop) {
   17.64 -        valueHasMutated(model, prop);
   17.65 -    }
   17.66 -    @JavaScriptBody(args = { "self", "prop" }, body =
   17.67 -        "var p = self[prop]; if (p) p.valueHasMutated();"
   17.68 -    )
   17.69 -    public static void valueHasMutated(Object self, String prop) {
   17.70 -    }
   17.71 -    
   17.72 -
   17.73 -    @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));")
   17.74 -    public static void triggerEvent(String id, String ev) {
   17.75 -    }
   17.76 -    
   17.77 -    @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive", "array" }, body =
   17.78 -          "var bnd = {\n"
   17.79 -        + "  'read': function() {\n"
   17.80 -        + "    var v = model[getter]();\n"
   17.81 -        + "    if (array) v = v.koArray(); else if (v !== null) v = v.valueOf();\n"
   17.82 -        + "    return v;\n"
   17.83 -        + "  },\n"
   17.84 -        + "  'owner': bindings\n"
   17.85 -        + "};\n"
   17.86 -        + "if (setter != null) {\n"
   17.87 -        + "  bnd['write'] = function(val) {\n"
   17.88 -        + "    var v = val === null ? null : val.valueOf();"
   17.89 -        + "    model[setter](v);\n"
   17.90 -        + "  };\n"
   17.91 -        + "}\n"
   17.92 -        + "bindings[prop] = ko['computed'](bnd);"
   17.93 -    )
   17.94 -    static void bind(
   17.95 -        Object bindings, Object model, String prop, String getter, String setter, boolean primitive, boolean array
   17.96 -    ) {
   17.97 -    }
   17.98 -
   17.99 -    @JavaScriptBody(args = { "bindings", "model", "prop", "sig" }, body = 
  17.100 -        "bindings[prop] = function(data, ev) { model[sig](data, ev); };"
  17.101 -    )
  17.102 -    static void expose(
  17.103 -        Object bindings, Object model, String prop, String sig
  17.104 -    ) {
  17.105 -    }
  17.106 -    
  17.107 -    @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);")
  17.108 -    static void applyBindings(Object bindings) {}
  17.109 -    
  17.110 -    private static void applyImpl(
  17.111 -        String[] propsGettersAndSetters,
  17.112 -        Class<?> modelClass,
  17.113 -        Object bindings,
  17.114 -        Object model,
  17.115 -        String[] methodsAndSignatures
  17.116 -    ) throws IllegalStateException, SecurityException {
  17.117 -        for (int i = 0; i < propsGettersAndSetters.length; i += 4) {
  17.118 -            try {
  17.119 -                Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]);
  17.120 -                bind(bindings, model, propsGettersAndSetters[i],
  17.121 -                    propsGettersAndSetters[i + 1],
  17.122 -                    propsGettersAndSetters[i + 2],
  17.123 -                    getter.getReturnType().isPrimitive(),
  17.124 -                    List.class.isAssignableFrom(getter.getReturnType()));
  17.125 -            } catch (NoSuchMethodException ex) {
  17.126 -                throw new IllegalStateException(ex.getMessage());
  17.127 -            }
  17.128 -        }
  17.129 -        for (int i = 0; i < methodsAndSignatures.length; i += 2) {
  17.130 -            expose(
  17.131 -                bindings, model, methodsAndSignatures[i], methodsAndSignatures[i + 1]);
  17.132 -        }
  17.133 -    }
  17.134 -}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java	Wed Jun 26 19:29:54 2013 +0200
    18.3 @@ -0,0 +1,122 @@
    18.4 +/**
    18.5 + * Back 2 Browser Bytecode Translator
    18.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    18.7 + *
    18.8 + * This program is free software: you can redistribute it and/or modify
    18.9 + * it under the terms of the GNU General Public License as published by
   18.10 + * the Free Software Foundation, version 2 of the License.
   18.11 + *
   18.12 + * This program is distributed in the hope that it will be useful,
   18.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.15 + * GNU General Public License for more details.
   18.16 + *
   18.17 + * You should have received a copy of the GNU General Public License
   18.18 + * along with this program. Look for COPYING file in the top folder.
   18.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   18.20 + */
   18.21 +package org.apidesign.bck2brwsr.ko2brwsr;
   18.22 +
   18.23 +import org.apidesign.bck2brwsr.ko2brwsr.BrwsrCtxImpl;
   18.24 +import java.io.BufferedReader;
   18.25 +import java.io.IOException;
   18.26 +import java.io.InputStreamReader;
   18.27 +import java.net.URI;
   18.28 +import java.net.URISyntaxException;
   18.29 +import java.net.URL;
   18.30 +import java.net.URLConnection;
   18.31 +import java.util.Map;
   18.32 +import net.java.html.BrwsrCtx;
   18.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   18.34 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   18.35 +import org.apidesign.html.context.spi.Contexts;
   18.36 +import org.apidesign.html.json.spi.Technology;
   18.37 +import org.apidesign.html.json.spi.Transfer;
   18.38 +import org.apidesign.html.json.tck.KOTest;
   18.39 +import org.apidesign.html.json.tck.KnockoutTCK;
   18.40 +import org.openide.util.lookup.ServiceProvider;
   18.41 +import org.testng.annotations.Factory;
   18.42 +
   18.43 +/**
   18.44 + *
   18.45 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   18.46 + */
   18.47 +@ServiceProvider(service = KnockoutTCK.class)
   18.48 +public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
   18.49 +    @Factory public static Object[] create() {
   18.50 +        return VMTest.newTests().
   18.51 +            withClasses(testClasses()).
   18.52 +            withLaunchers("bck2brwsr").
   18.53 +            withTestAnnotation(KOTest.class).
   18.54 +            build();
   18.55 +    }
   18.56 +    
   18.57 +    @Override
   18.58 +    public BrwsrCtx createContext() {
   18.59 +        return Contexts.newBuilder().
   18.60 +            register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9).
   18.61 +            register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build();
   18.62 +    }
   18.63 +
   18.64 +
   18.65 +    
   18.66 +    @Override
   18.67 +    public Object createJSON(Map<String, Object> values) {
   18.68 +        Object json = createJSON();
   18.69 +        
   18.70 +        for (Map.Entry<String, Object> entry : values.entrySet()) {
   18.71 +            putValue(json, entry.getKey(), entry.getValue());
   18.72 +        }
   18.73 +        return json;
   18.74 +    }
   18.75 +
   18.76 +    @JavaScriptBody(args = {}, body = "return new Object();")
   18.77 +    private static native Object createJSON();
   18.78 +
   18.79 +    @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
   18.80 +    private static native void putValue(Object json, String key, Object value);
   18.81 +
   18.82 +    @Override
   18.83 +    public Object executeScript(String script, Object[] arguments) {
   18.84 +        return execScript(script, arguments);
   18.85 +    }
   18.86 +    
   18.87 +    @JavaScriptBody(args = { "s", "args" }, body = 
   18.88 +        "var f = new Function(s); return f.apply(null, args);"
   18.89 +    )
   18.90 +    private static native Object execScript(String s, Object[] arguments);
   18.91 +    
   18.92 +    @JavaScriptBody(args = {  }, body = 
   18.93 +          "var h;"
   18.94 +        + "if (!!window && !!window.location && !!window.location.href)\n"
   18.95 +        + "  h = window.location.href;\n"
   18.96 +        + "else "
   18.97 +        + "  h = null;"
   18.98 +        + "return h;\n"
   18.99 +    )
  18.100 +    private static native String findBaseURL();
  18.101 +    
  18.102 +    @Override
  18.103 +    public URI prepareURL(String content, String mimeType, String[] parameters) {
  18.104 +        try {
  18.105 +            final URL baseURL = new URL(findBaseURL());
  18.106 +            StringBuilder sb = new StringBuilder();
  18.107 +            sb.append("/dynamic?mimeType=").append(mimeType);
  18.108 +            for (int i = 0; i < parameters.length; i++) {
  18.109 +                sb.append("&param" + i).append("=").append(parameters[i]);
  18.110 +            }
  18.111 +            String mangle = content.replace("\n", "%0a")
  18.112 +                .replace("\"", "\\\"").replace(" ", "%20");
  18.113 +            sb.append("&content=").append(mangle);
  18.114 +
  18.115 +            URL query = new URL(baseURL, sb.toString());
  18.116 +            String uri = (String) query.getContent(new Class[] { String.class });
  18.117 +            URI connectTo = new URI(uri.trim());
  18.118 +            return connectTo;
  18.119 +        } catch (IOException ex) {
  18.120 +            throw new IllegalStateException(ex);
  18.121 +        } catch (URISyntaxException ex) {
  18.122 +            throw new IllegalStateException(ex);
  18.123 +        }
  18.124 +    }    
  18.125 +}
    19.1 --- a/ko/bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java	Wed Jun 26 18:44:21 2013 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,121 +0,0 @@
    19.4 -/**
    19.5 - * Back 2 Browser Bytecode Translator
    19.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    19.7 - *
    19.8 - * This program is free software: you can redistribute it and/or modify
    19.9 - * it under the terms of the GNU General Public License as published by
   19.10 - * the Free Software Foundation, version 2 of the License.
   19.11 - *
   19.12 - * This program is distributed in the hope that it will be useful,
   19.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.15 - * GNU General Public License for more details.
   19.16 - *
   19.17 - * You should have received a copy of the GNU General Public License
   19.18 - * along with this program. Look for COPYING file in the top folder.
   19.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   19.20 - */
   19.21 -package org.apidesign.html.ko2brwsr;
   19.22 -
   19.23 -import java.io.BufferedReader;
   19.24 -import java.io.IOException;
   19.25 -import java.io.InputStreamReader;
   19.26 -import java.net.URI;
   19.27 -import java.net.URISyntaxException;
   19.28 -import java.net.URL;
   19.29 -import java.net.URLConnection;
   19.30 -import java.util.Map;
   19.31 -import net.java.html.BrwsrCtx;
   19.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
   19.33 -import org.apidesign.bck2brwsr.vmtest.VMTest;
   19.34 -import org.apidesign.html.context.spi.Contexts;
   19.35 -import org.apidesign.html.json.spi.Technology;
   19.36 -import org.apidesign.html.json.spi.Transfer;
   19.37 -import org.apidesign.html.json.tck.KOTest;
   19.38 -import org.apidesign.html.json.tck.KnockoutTCK;
   19.39 -import org.openide.util.lookup.ServiceProvider;
   19.40 -import org.testng.annotations.Factory;
   19.41 -
   19.42 -/**
   19.43 - *
   19.44 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   19.45 - */
   19.46 -@ServiceProvider(service = KnockoutTCK.class)
   19.47 -public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
   19.48 -    @Factory public static Object[] create() {
   19.49 -        return VMTest.newTests().
   19.50 -            withClasses(testClasses()).
   19.51 -            withLaunchers("bck2brwsr").
   19.52 -            withTestAnnotation(KOTest.class).
   19.53 -            build();
   19.54 -    }
   19.55 -    
   19.56 -    @Override
   19.57 -    public BrwsrCtx createContext() {
   19.58 -        return Contexts.newBuilder().
   19.59 -            register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9).
   19.60 -            register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build();
   19.61 -    }
   19.62 -
   19.63 -
   19.64 -    
   19.65 -    @Override
   19.66 -    public Object createJSON(Map<String, Object> values) {
   19.67 -        Object json = createJSON();
   19.68 -        
   19.69 -        for (Map.Entry<String, Object> entry : values.entrySet()) {
   19.70 -            putValue(json, entry.getKey(), entry.getValue());
   19.71 -        }
   19.72 -        return json;
   19.73 -    }
   19.74 -
   19.75 -    @JavaScriptBody(args = {}, body = "return new Object();")
   19.76 -    private static native Object createJSON();
   19.77 -
   19.78 -    @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
   19.79 -    private static native void putValue(Object json, String key, Object value);
   19.80 -
   19.81 -    @Override
   19.82 -    public Object executeScript(String script, Object[] arguments) {
   19.83 -        return execScript(script, arguments);
   19.84 -    }
   19.85 -    
   19.86 -    @JavaScriptBody(args = { "s", "args" }, body = 
   19.87 -        "var f = new Function(s); return f.apply(null, args);"
   19.88 -    )
   19.89 -    private static native Object execScript(String s, Object[] arguments);
   19.90 -    
   19.91 -    @JavaScriptBody(args = {  }, body = 
   19.92 -          "var h;"
   19.93 -        + "if (!!window && !!window.location && !!window.location.href)\n"
   19.94 -        + "  h = window.location.href;\n"
   19.95 -        + "else "
   19.96 -        + "  h = null;"
   19.97 -        + "return h;\n"
   19.98 -    )
   19.99 -    private static native String findBaseURL();
  19.100 -    
  19.101 -    @Override
  19.102 -    public URI prepareURL(String content, String mimeType, String[] parameters) {
  19.103 -        try {
  19.104 -            final URL baseURL = new URL(findBaseURL());
  19.105 -            StringBuilder sb = new StringBuilder();
  19.106 -            sb.append("/dynamic?mimeType=").append(mimeType);
  19.107 -            for (int i = 0; i < parameters.length; i++) {
  19.108 -                sb.append("&param" + i).append("=").append(parameters[i]);
  19.109 -            }
  19.110 -            String mangle = content.replace("\n", "%0a")
  19.111 -                .replace("\"", "\\\"").replace(" ", "%20");
  19.112 -            sb.append("&content=").append(mangle);
  19.113 -
  19.114 -            URL query = new URL(baseURL, sb.toString());
  19.115 -            String uri = (String) query.getContent(new Class[] { String.class });
  19.116 -            URI connectTo = new URI(uri.trim());
  19.117 -            return connectTo;
  19.118 -        } catch (IOException ex) {
  19.119 -            throw new IllegalStateException(ex);
  19.120 -        } catch (URISyntaxException ex) {
  19.121 -            throw new IllegalStateException(ex);
  19.122 -        }
  19.123 -    }    
  19.124 -}
    20.1 --- a/pom.xml	Wed Jun 26 18:44:21 2013 +0200
    20.2 +++ b/pom.xml	Wed Jun 26 19:29:54 2013 +0200
    20.3 @@ -21,6 +21,7 @@
    20.4      <module>javaquery</module>
    20.5      <module>benchmarks</module>
    20.6      <module>ide</module>
    20.7 +    <module>ko</module>
    20.8      <module>launcher</module>
    20.9      <module>rt</module>
   20.10    </modules>