http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java ---------------------------------------------------------------------- diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java b/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java new file mode 100644 index 0000000..0e9a8f3 --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java @@ -0,0 +1,132 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko4j; + +import java.io.Closeable; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.application.Platform; +import org.netbeans.html.boot.spi.Fn; +import org.testng.ITest; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public final class KOFx implements ITest, Runnable { + private final Fn.Presenter p; + private final Method m; + private Object result; + private Object inst; + private int count; + + KOFx(Fn.Presenter p, Method m) { + this.p = p; + this.m = m; + } + + @Override + public String getTestName() { + return m.getName(); + } + + @Test + public synchronized void executeTest() throws Exception { + if (result == null) { + Platform.runLater(this); + wait(); + } + if (result instanceof Exception) { + throw (Exception)result; + } + if (result instanceof Error) { + throw (Error)result; + } + } + + @Override + public synchronized void run() { + boolean notify = true; + Closeable a = Fn.activate(p); + try { + if (inst == null) { + inst = m.getDeclaringClass().newInstance(); + } + result = m.invoke(inst); + if (result == null) { + result = this; + } + } catch (InvocationTargetException ex) { + Throwable r = ex.getTargetException(); + if (r instanceof InterruptedException) { + if (count++ < 10000) { + notify = false; + try { + Thread.sleep(100); + } catch (Exception ex1) { + // ignore and continue + } + Platform.runLater(this); + return; + } + } + result = r; + } catch (Exception ex) { + result = ex; + } finally { + if (notify) { + notifyAll(); + } + try { + a.close(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java ---------------------------------------------------------------------- diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java new file mode 100644 index 0000000..306ac1e --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java @@ -0,0 +1,235 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko4j; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; +import net.java.html.BrwsrCtx; +import net.java.html.boot.BrowserBuilder; +import net.java.html.js.JavaScriptBody; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; +import org.openide.util.lookup.ServiceProvider; +import org.testng.Assert; +import static org.testng.Assert.*; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +@ServiceProvider(service = KnockoutTCK.class) +public final class KnockoutFXTest extends KnockoutTCK { + private static Class<?> browserClass; + private static Fn.Presenter browserContext; + + public KnockoutFXTest() { + } + + @Factory public static Object[] compatibilityTests() throws Exception { + Class[] arr = testClasses(); + for (int i = 0; i < arr.length; i++) { + assertEquals( + arr[i].getClassLoader(), + KnockoutFXTest.class.getClassLoader(), + "All classes loaded by the same classloader" + ); + } + + URI uri = DynamicHTTP.initServer(); + + final BrowserBuilder bb = BrowserBuilder.newBrowser().loadClass(KnockoutFXTest.class). + loadPage(uri.toString()). + invoke("initialized"); + + Executors.newSingleThreadExecutor().submit(new Runnable() { + @Override + public void run() { + bb.showAndWait(); + } + }); + + ClassLoader l = getClassLoader(); + List<Object> res = new ArrayList<Object>(); + for (int i = 0; i < arr.length; i++) { + Class<?> c = Class.forName(arr[i].getName(), true, l); + seekKOTests(c, res); + } + Class<?> c = Class.forName(LessCallbacksCheck.class.getName(), true, l); + seekKOTests(c, res); + return res.toArray(); + } + + private static void seekKOTests(Class<?> c, List<Object> res) throws SecurityException, ClassNotFoundException { + Class<? extends Annotation> koTest = + c.getClassLoader().loadClass(KOTest.class.getName()). + asSubclass(Annotation.class); + for (Method m : c.getMethods()) { + if (m.getAnnotation(koTest) != null) { + res.add(new KOFx(browserContext, m)); + } + } + } + + static synchronized ClassLoader getClassLoader() throws InterruptedException { + while (browserClass == null) { + KnockoutFXTest.class.wait(); + } + return browserClass.getClassLoader(); + } + + public static synchronized void initialized(Class<?> browserCls) throws Exception { + browserClass = browserCls; + browserContext = Fn.activePresenter(); + KnockoutFXTest.class.notifyAll(); + } + + public static void initialized() throws Exception { + Assert.assertSame( + KnockoutFXTest.class.getClassLoader(), + ClassLoader.getSystemClassLoader(), + "No special classloaders" + ); + KnockoutFXTest.initialized(KnockoutFXTest.class); + browserContext = Fn.activePresenter(); + } + + @Override + public BrwsrCtx createContext() { + KO4J ko4j = new KO4J(); + Contexts.Builder cb = Contexts.newBuilder(). + register(Technology.class, ko4j.knockout(), 10). + register(Transfer.class, ko4j.transfer(), 10); + if (ko4j.websockets() != null) { + cb.register(WSTransfer.class, ko4j.websockets(), 10); + } + cb.register(Executor.class, (Executor)browserContext, 10); + cb.register(Fn.Presenter.class, browserContext, 10); + BrwsrCtx ctx = cb.build(); + return ctx; + } + + @Override + public Object createJSON(Map<String, Object> values) { + Object json = createJSON(); + for (Map.Entry<String, Object> entry : values.entrySet()) { + setProperty(json, entry.getKey(), entry.getValue()); + } + return json; + } + + @JavaScriptBody(args = {}, body = "return new Object();") + private static native Object createJSON(); + @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;") + private static native void setProperty(Object json, String key, Object value); + + @Override + @JavaScriptBody(args = { "s", "args" }, body = "" + + "var f = new Function(s); " + + "return f.apply(null, args);" + ) + public native Object executeScript(String script, Object[] arguments); + + @JavaScriptBody(args = { }, body = + "var h;" + + "if (!!window && !!window.location && !!window.location.href)\n" + + " h = window.location.href;\n" + + "else " + + " h = null;" + + "return h;\n" + ) + private static native String findBaseURL(); + + @Override + public URI prepareURL(String content, String mimeType, String[] parameters) { + try { + final URL baseURL = new URL(findBaseURL()); + StringBuilder sb = new StringBuilder(); + sb.append("/dynamic?mimeType=").append(mimeType); + for (int i = 0; i < parameters.length; i++) { + sb.append("¶m" + i).append("=").append(parameters[i]); + } + String mangle = content.replace("\n", "%0a") + .replace("\"", "\\\"").replace(" ", "%20"); + sb.append("&content=").append(mangle); + + URL query = new URL(baseURL, sb.toString()); + URLConnection c = query.openConnection(); + BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream())); + URI connectTo = new URI(br.readLine()); + return connectTo; + } catch (IOException ex) { + throw new IllegalStateException(ex); + } catch (URISyntaxException ex) { + throw new IllegalStateException(ex); + } + } + + @Override + public boolean canFailWebSocketTest() { + try { + Class.forName("java.util.function.Function"); + return false; + } catch (ClassNotFoundException ex) { + // running on JDK7, FX WebView WebSocket impl does not work + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java ---------------------------------------------------------------------- diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java b/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java new file mode 100644 index 0000000..81d643a --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java @@ -0,0 +1,97 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko4j; + +import java.io.PrintWriter; +import java.io.StringWriter; +import net.java.html.json.ComputedProperty; +import net.java.html.json.Model; +import net.java.html.json.Property; +import org.netbeans.html.json.tck.KOTest; + +/** + * + * @author Jaroslav Tulach + */ +@Model(className = "LessCalls", targetId = "", properties = { + @Property(name = "value", type = int.class) +}) +public class LessCallbacksCheck { + private static StringWriter sw; + + @ComputedProperty static int plusOne(int value) { + if (sw == null) { + sw = new StringWriter(); + } + new Exception("Who calls me?").printStackTrace( + new PrintWriter(sw) + ); + return value + 1; + } + + @KOTest public void dontCallForInitialValueBackToJavaVM() { + sw = null; + LessCalls m = new LessCalls(10).applyBindings(); + assert m.getPlusOne() == 11 : "Expecting 11: " + m.getPlusOne(); + + assert sw != null : "StringWriter should be initialized: " + sw; + + if (sw.toString().contains("$JsCallbacks$")) { + assert false : "Don't call for initial value via JsCallbacks:\n" + sw; + } + } + + @KOTest public void dontCallForChangeValueBackToJavaVM() { + LessCalls m = new LessCalls(10).applyBindings(); + assert m.getPlusOne() == 11 : "Expecting 11: " + m.getPlusOne(); + + sw = null; + m.setValue(5); + assert m.getPlusOne() == 6: "Expecting 6: " + m.getPlusOne(); + assert sw != null : "StringWriter should be initialized: " + sw; + + if (sw.toString().contains("$JsCallbacks$")) { + assert false : "Don't call for initial value via JsCallbacks:\n" + sw; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/java/org/netbeans/html/ko4j/OffThreadInitializationTest.java ---------------------------------------------------------------------- diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/OffThreadInitializationTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/OffThreadInitializationTest.java new file mode 100644 index 0000000..71bbd65 --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/OffThreadInitializationTest.java @@ -0,0 +1,166 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko4j; + +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import net.java.html.BrwsrCtx; +import net.java.html.json.Model; +import net.java.html.json.Models; +import net.java.html.json.Property; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; +import org.testng.Assert; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +@Model(className = "Background", properties = { + @Property(name = "identityHashCode", type = int.class), +}) +public class OffThreadInitializationTest { + private ScheduledExecutorService executor; + + @BeforeMethod + public void initExecutor() { + executor = Executors.newSingleThreadScheduledExecutor(); + } + + @Test + public void backgroundInitializationOfAModel() throws Exception { + BrwsrCtx ctx = Contexts.newBuilder().register(Technology.class, new DummyTechnology(), 1).build(); + DummyTechnology.assertEquals(1, "One technology, created explicitly"); + final Background prototype = new Background(); + DummyTechnology.assertEquals(0, "No more technology on rebind"); + final Background b = Models.bind(prototype, ctx); + Models.applyBindings(b); + DummyTechnology.assertEquals(0, "Technology is shared!"); + + + Background b2 = executor.submit(new Callable<Background>() { + @Override + public Background call() throws Exception { + return b.clone(); + } + }).get(); + + assertSameTech(b, b2); + DummyTechnology.assertEquals(0, "Technology is still shared!"); + } + + private void assertSameTech(Background b, Background b2) { + assertEquals(b.getIdentityHashCode(), b2.getIdentityHashCode(), "The hashcodes of the tech has to be the same"); + } + + private static final class DummyTechnology implements Technology<Object> { + static int cnt; + + static void assertAtMax(int i, String msg) { + if (cnt <= i) { + cnt = 0; + } else { + fail(msg + " was: " + cnt); + } + } + + static void assertEquals(int i, String msg) { + Assert.assertEquals(cnt, i, msg); + cnt = 0; + } + + DummyTechnology() { + cnt++; + } + + @Override + public Object wrapModel(Object model) { + return model; + } + + @Override + public <M> M toModel(Class<M> modelClass, Object data) { + return modelClass.cast(data); + } + + @Override + public void bind(PropertyBinding b, Object model, Object data) { + if (b.getPropertyName().equals("identityHashCode")) { + ((Background)model).setIdentityHashCode(System.identityHashCode(this)); + } + } + + @Override + public void valueHasMutated(Object data, String propertyName) { + } + + @Override + public void expose(FunctionBinding fb, Object model, Object d) { + } + + @Override + public void applyBindings(Object data) { + } + + @Override + public Object wrapArray(Object[] arr) { + return arr; + } + + @Override + public void runSafe(Runnable r) { + r.run(); + } + } + + public static final class DummyProvider implements Contexts.Provider { + @Override + public void fillContext(Contexts.Builder context, Class<?> requestor) { + context.register(Technology.class, new DummyTechnology(), 0); + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/java/org/netbeans/html/ko4j/ReferenceKnockoutTest.java ---------------------------------------------------------------------- diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/ReferenceKnockoutTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/ReferenceKnockoutTest.java new file mode 100644 index 0000000..a730904 --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/ReferenceKnockoutTest.java @@ -0,0 +1,63 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko4j; + +import static org.testng.Assert.assertNull; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class ReferenceKnockoutTest { + @Test public void canLoadKnockout() { + Object ret = null; + try { + ret = Knockout.toModel(null); + } catch (IllegalStateException ex) { + // ISE is OK as we don't have any + // context for the + } + assertNull(ret, "Either null"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/ko4j/src/test/resources/org/netbeans/html/ko4j/test.html ---------------------------------------------------------------------- diff --git a/ko4j/src/test/resources/org/netbeans/html/ko4j/test.html b/ko4j/src/test/resources/org/netbeans/html/ko4j/test.html new file mode 100644 index 0000000..d4399a0 --- /dev/null +++ b/ko4j/src/test/resources/org/netbeans/html/ko4j/test.html @@ -0,0 +1,56 @@ +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + + Oracle and Java are registered trademarks of Oracle and/or its affiliates. + Other names may be trademarks of their respective owners. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common + Development and Distribution License("CDDL") (collectively, the + "License"). You may not use this file except in compliance with the + License. You can obtain a copy of the License at + http://www.netbeans.org/cddl-gplv2.html + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + specific language governing permissions and limitations under the + License. When distributing the software, include this License Header + Notice in each file and include the License file at + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + particular file as subject to the "Classpath" exception as provided + by Oracle in the GPL Version 2 section of the License file that + accompanied this code. If applicable, add the following below the + License Header, with the fields enclosed by brackets [] replaced by + your own identifying information: + "Portions Copyrighted [year] [name of copyright owner]" + + Contributor(s): + + The Original Software is NetBeans. The Initial Developer of the Original + Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + + If you wish your version of this file to be governed by only the CDDL + or only the GPL Version 2, indicate your decision by adding + "[Contributor] elects to include this software in this distribution + under the [CDDL or GPL Version 2] license." If you do not indicate a + single choice of license, a recipient has the option to distribute + your version of this file under either the CDDL, the GPL Version 2 or + to extend the choice of license to its licensees as provided above. + However, if you add GPL Version 2 code and therefore, elected the GPL + Version 2 license, then the option applies only if the new code is + made subject to such option by the copyright holder. + +--> +<!DOCTYPE html> +<html> + <head> + <title>Knockout.fx Execution Harness</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <meta name="viewport" content="width=device-width"> + </head> + <body> + <h1>Knockout.fx Execution Harness</h1> + </body> + <script></script> +</html> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a19bfcb --- /dev/null +++ b/pom.xml @@ -0,0 +1,475 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2013-2016 Oracle and/or its affiliates. All rights reserved. + + Oracle and Java are registered trademarks of Oracle and/or its affiliates. + Other names may be trademarks of their respective owners. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common + Development and Distribution License("CDDL") (collectively, the + "License"). You may not use this file except in compliance with the + License. You can obtain a copy of the License at + http://www.netbeans.org/cddl-gplv2.html + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + specific language governing permissions and limitations under the + License. When distributing the software, include this License Header + Notice in each file and include the License file at + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + particular file as subject to the "Classpath" exception as provided + by Oracle in the GPL Version 2 section of the License file that + accompanied this code. If applicable, add the following below the + License Header, with the fields enclosed by brackets [] replaced by + your own identifying information: + "Portions Copyrighted [year] [name of copyright owner]" + + Contributor(s): + + The Original Software is NetBeans. The Initial Developer of the Original + Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + + If you wish your version of this file to be governed by only the CDDL + or only the GPL Version 2, indicate your decision by adding + "[Contributor] elects to include this software in this distribution + under the [CDDL or GPL Version 2] license." If you do not indicate a + single choice of license, a recipient has the option to distribute + your version of this file under either the CDDL, the GPL Version 2 or + to extend the choice of license to its licensees as provided above. + However, if you add GPL Version 2 code and therefore, elected the GPL + Version 2 license, then the option applies only if the new code is + made subject to such option by the copyright holder. + +--> +<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"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.netbeans.html</groupId> + <artifactId>pom</artifactId> + <version>2.0-SNAPSHOT</version> + <packaging>pom</packaging> + <name>HTML APIs via Java</name> + <parent> + <groupId>net.java</groupId> + <artifactId>jvnet-parent</artifactId> + <version>3</version> + </parent> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <netbeans.version>RELEASE80</netbeans.version> + <grizzly.version>2.3.8</grizzly.version> + <license>COPYING</license> + <publicPackages /> + <bundleSymbolicName>${project.artifactId}</bundleSymbolicName> + <netbeans.compile.on.save>none</netbeans.compile.on.save> + </properties> + <modules> + <module>json</module> + <module>json-tck</module> + <module>ko4j</module> + <module>sound</module> + <module>context</module> + <module>boot</module> + <module>boot-fx</module> + <module>geo</module> + <module>ko-ws-tyrus</module> + <module>html4j-maven-plugin</module> + <module>ko-felix-test</module> + <module>ko-osgi-test</module> + <module>equinox-agentclass-hook</module> + <module>boot-script</module> + <module>boot-truffle</module> + <module>boot-agent-test</module> + <module>xhr4j</module> + </modules> + <licenses> + <license> + <name>GPL-2.0wCPexc+CDDL</name> + <url>http://www.netbeans.org/cddl-gplv2.html</url> + <distribution>repo</distribution> + </license> + </licenses> + <organization> + <name>NetBeans</name> + <url>http://netbeans.org</url> + </organization> + <scm> + <connection>scm:hg:https://hg.netbeans.org/html4j</connection> + <developerConnection>scm:hg:https://hg.netbeans.org/html4j</developerConnection> + <url>https://hg.netbeans.org/html4j</url> + <tag>default</tag> + </scm> + <repositories> + <repository> + <id>netbeans</id> + <name>NetBeans</name> + <url>http://bits.netbeans.org/maven2/</url> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>mc-release</id> + <name>Local Maven repository of releases</name> + <url>http://mc-repo.googlecode.com/svn/maven2/releases</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + </releases> + </pluginRepository> + </pluginRepositories> + <build> + <plugins> + <plugin> + <inherited>false</inherited> + <groupId>com.mycila.maven-license-plugin</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>1.9.0</version> + <executions> + <execution> + <id>blah</id> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + <configuration> + <aggregate>true</aggregate> + <basedir>${basedir}</basedir> + <header>COPYING</header> + <strictCheck>true</strictCheck> + <excludes> + <exclude>*</exclude> + <exclude>.*/**</exclude> + <exclude>*/nb-configuration.xml</exclude> + </excludes> + </configuration> + </plugin> + <plugin> + <artifactId>maven-release-plugin</artifactId> + <version>2.4</version> + <configuration> + <mavenExecutorId>forked-path</mavenExecutorId> + <useReleaseProfile>false</useReleaseProfile> + <arguments>-Pjvnet-release -Pgpg</arguments> + <tag>release-${releaseVersion}</tag> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9</version> + <configuration> + <docfilessubdirs>true</docfilessubdirs> + <subpackages>${publicPackages}</subpackages> + <skip>false</skip> + <excludePackageNames> +org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.impl:org.netbeans.html.equinox.*:org.netbeans.html.geo.impl:org.netbeans.html.json.impl:org.netbeans.html.sound.impl:org.netbeans.html.ko.*:org.netbeans.html.ko4j:org.netbeans.html.mojo:org.netbeans.html.wstyrus:net.java.html.js.tests:net.java.html.json.tests:org.netbeans.html.xhr4j + </excludePackageNames> + <groups> + <group> + <title>JSON for Java</title> + <packages>net.java.html.json</packages> + </group> + <group> + <title>Core Client APIs</title> + <packages>net.java.html.boot*:net.java.html.js:net.java.html</packages> + </group> + <group> + <title>Geolocation API</title> + <packages>net.java.html.geo</packages> + </group> + <group> + <title>Sound API</title> + <packages>net.java.html.sound</packages> + </group> + <group> + <title>Testing and Headless API</title> + <packages>net.java.html.boot.script:net.java.html.boot.truffle</packages> + </group> + <group> + <title>Service Provider APIs (not commonly interesting)</title> + <packages>org.netbeans.html.*</packages> + </group> + </groups> + <links> + <link>http://testng.org/javadocs/</link> + <link>http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/</link> + <link>http://docs.oracle.com/javase/8/javafx/api/</link> + </links> + </configuration> + </plugin> + <plugin> + <groupId>org.netbeans.tools</groupId> + <artifactId>sigtest-maven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + <goal>check</goal> + </goals> + </execution> + </executions> + <configuration> + <packages>${publicPackages}</packages> + <releaseVersion>1.3</releaseVersion> + </configuration> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.13</version> + <configuration> + <systemPropertyVariables> + <fxpresenter.headless>true</fxpresenter.headless> + </systemPropertyVariables> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.18.1</version> + <configuration> + <systemPropertyVariables> + <fxpresenter.headless>true</fxpresenter.headless> + </systemPropertyVariables> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9</version> + <configuration> + <subpackages>${publicPackages}</subpackages> + <skip>false</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>2.4.0</version> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>${publicPackages},META-INF.services.*;-noimport:=true;-split-package:=first</Export-Package> + <Bundle-SymbolicName>${bundleSymbolicName}</Bundle-SymbolicName> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.netbeans.html</groupId> + <artifactId>html4j-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>classes</id> + <goals> + <goal>process-js-annotations</goal> + </goals> + </execution> + <execution> + <id>test-classes</id> + <phase>process-test-classes</phase> + <goals> + <goal>process-js-annotations</goal> + </goals> + <configuration> + <classes>${project.build.directory}/test-classes</classes> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.7</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>junit</artifactId> + <groupId>junit</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>de.twentyeleven.skysail</groupId> + <artifactId>org.json-osgi</artifactId> + <version>20080701</version> + </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + <version>5.0</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-classfile</artifactId> + <version>${netbeans.version}</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-openide-util-lookup</artifactId> + <version>${netbeans.version}</version> + <scope>compile</scope> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-api-annotations-common</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-java-source</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-libs-javacapi</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-spi-java-hints</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-parsing-api</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-spi-editor-hints</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-openide-util</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-java-lexer</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-lexer</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-modules-java-hints-test</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-netbeans-libs-junit4</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.netbeans.modules</groupId> + <artifactId>org-netbeans-lib-nbjavac</artifactId> + <version>${netbeans.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>4.2.1</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.1.0</version> + </dependency> + <dependency> + <groupId>org.netbeans.modules</groupId> + <artifactId>org-netbeans-modules-web-browser-api</artifactId> + <version>${netbeans.version}</version> + <exclusions> + <exclusion> + <artifactId>org-netbeans-core</artifactId> + <groupId>org.netbeans.modules</groupId> + </exclusion> + <exclusion> + <artifactId>org-netbeans-core-multiview</artifactId> + <groupId>org.netbeans.api</groupId> + </exclusion> + <exclusion> + <artifactId>org-netbeans-libs-lucene</artifactId> + <groupId>org.netbeans.api</groupId> + </exclusion> + <exclusion> + <artifactId>org-netbeans-modules-diff</artifactId> + <groupId>org.netbeans.api</groupId> + </exclusion> + <exclusion> + <artifactId>org-netbeans-modules-editor-fold</artifactId> + <groupId>org.netbeans.api</groupId> + </exclusion> + <exclusion> + <artifactId>org-netbeans-modules-editor-guards</artifactId> + <groupId>org.netbeans.api</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <artifactId>org-netbeans-modules-projectapi</artifactId> + <groupId>org.netbeans.api</groupId> + <type>jar</type> + <version>${netbeans.version}</version> + </dependency> + </dependencies> + </dependencyManagement> + <profiles> + <profile> + <id>jdk8</id> + <activation> + <file> + <exists>${java.home}/lib/ext/jfxrt.jar</exists> + </file> + </activation> + <properties> + <jfxrt.jar>${java.home}/lib/ext/jfxrt.jar</jfxrt.jar> + </properties> + </profile> + <profile> + <id>jdk7</id> + <activation> + <file> + <exists>${java.home}/lib/jfxrt.jar</exists> + </file> + </activation> + <properties> + <jfxrt.jar>${java.home}/lib/jfxrt.jar</jfxrt.jar> + </properties> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/pom.xml ---------------------------------------------------------------------- diff --git a/sound/pom.xml b/sound/pom.xml new file mode 100644 index 0000000..62fce4b --- /dev/null +++ b/sound/pom.xml @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2013-2016 Oracle and/or its affiliates. All rights reserved. + + Oracle and Java are registered trademarks of Oracle and/or its affiliates. + Other names may be trademarks of their respective owners. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common + Development and Distribution License("CDDL") (collectively, the + "License"). You may not use this file except in compliance with the + License. You can obtain a copy of the License at + http://www.netbeans.org/cddl-gplv2.html + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + specific language governing permissions and limitations under the + License. When distributing the software, include this License Header + Notice in each file and include the License file at + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + particular file as subject to the "Classpath" exception as provided + by Oracle in the GPL Version 2 section of the License file that + accompanied this code. If applicable, add the following below the + License Header, with the fields enclosed by brackets [] replaced by + your own identifying information: + "Portions Copyrighted [year] [name of copyright owner]" + + Contributor(s): + + The Original Software is NetBeans. The Initial Developer of the Original + Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + + If you wish your version of this file to be governed by only the CDDL + or only the GPL Version 2, indicate your decision by adding + "[Contributor] elects to include this software in this distribution + under the [CDDL or GPL Version 2] license." If you do not indicate a + single choice of license, a recipient has the option to distribute + your version of this file under either the CDDL, the GPL Version 2 or + to extend the choice of license to its licensees as provided above. + However, if you add GPL Version 2 code and therefore, elected the GPL + Version 2 license, then the option applies only if the new code is + made subject to such option by the copyright holder. + +--> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.netbeans.html</groupId> + <artifactId>pom</artifactId> + <version>2.0-SNAPSHOT</version> + </parent> + <groupId>org.netbeans.html</groupId> + <artifactId>net.java.html.sound</artifactId> + <version>2.0-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>Sound API via HTML</name> + <url>http://maven.apache.org</url> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <publicPackages>net.java.html.sound</publicPackages> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.netbeans.html</groupId> + <artifactId>html4j-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.netbeans.html</groupId> + <artifactId>net.java.html.boot</artifactId> + <version>2.0-SNAPSHOT</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.netbeans.api</groupId> + <artifactId>org-openide-util-lookup</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/src/main/java/net/java/html/sound/AudioClip.java ---------------------------------------------------------------------- diff --git a/sound/src/main/java/net/java/html/sound/AudioClip.java b/sound/src/main/java/net/java/html/sound/AudioClip.java new file mode 100644 index 0000000..d502077 --- /dev/null +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java @@ -0,0 +1,200 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package net.java.html.sound; + +import java.util.ServiceLoader; +import net.java.html.BrwsrCtx; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.sound.spi.AudioEnvironment; +import org.netbeans.html.sound.impl.BrowserAudioEnv; + +/** Handle to an audio clip which can be {@link #play() played}, {@link #pause() paused} + * and etc. Obtain new instance via {@link #create(java.lang.String) create} factory + * method and then use it when necessary. + * + * @author antonepple + */ +public abstract class AudioClip { + private AudioClip() { + } + + /** Creates new instance of an audio clip based on the provided URL. + * If no suitable audio environment provider is found, the method + * returns a dummy instance that does nothing and only returns + * false from its {@link #isSupported()} method. + * <p> + * The <code>src</code> can be absolute URL or it can be relative + * to current {@link BrwsrCtx browser context} - e.g. usually to the + * page that is just being displayed. + * + * @param src the URL where to find the audio clip + * @return the audio clip handle + * @throws NullPointerException if src is <code>null</code> + */ + public static AudioClip create(String src) { + src.getClass(); + BrwsrCtx brwsrCtx = BrwsrCtx.findDefault(AudioClip.class); + AudioEnvironment brwsrAE = Contexts.find(brwsrCtx, AudioEnvironment.class); + if (brwsrAE != null) { + Impl handle = create(brwsrAE, src); + if (handle != null) { + return handle; + } + } + for (AudioEnvironment<?> ae : ServiceLoader.load(AudioEnvironment.class)) { + Impl handle = create(ae, src); + if (handle != null) { + return handle; + } + } + Impl handle = create(BrowserAudioEnv.DEFAULT, src); + return handle != null ? handle : DummyClip.INSTANCE; + } + + /** Plays the clip from begining to the end. + */ + public abstract void play(); + + /** Pauses playback of the clip + */ + public abstract void pause(); + + /** + * Specifies the volume of the audio. Must be a number between 0.0 and 1.0: + * <ul> + * <li>1.0 - highest volume</li> + * <li>0.5 - 50% volume</li> + * <li>0.0 - silent</li> + * </ul> + * + * @param volume for the playback + */ + public abstract void setVolume(double volume); + + /** Check whether the audio clip is supported and can be played. + * @return true if it is likely that after calling {@link #play()} + * a sound will be produced + */ + public abstract boolean isSupported(); + +// public abstract void playFrom(int seconds); + + // + // Implementation + // + + private static <Audio> Impl<Audio> create(AudioEnvironment<Audio> env, String src) { + Audio a = env.create(src); + if (a != null) { + return new Impl<Audio>(env, src, a); + } else { + return null; + } + } + + private static final class Impl<Audio> extends AudioClip { + private final String src; + private final Audio clip; + private final AudioEnvironment<Audio> env; + + public Impl(AudioEnvironment<Audio> env, String src, Audio clip) { + this.clip = clip; + this.env = env; + this.src = src; + } + + @Override + public void play() { + env.play(clip); + } + + @Override + public void pause() { + env.pause(clip); + } + + @Override + public void setVolume(double volume) { + env.setVolume(clip, volume); + } + + @Override + public boolean isSupported() { + return env.isSupported(clip); + } + + @Override + public int hashCode() { + return 59 * src.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Impl) { + return src.equals(((Impl)obj).src); + } + return false; + } + } // end of Impl + + private static final class DummyClip extends AudioClip { + static AudioClip INSTANCE = new DummyClip(); + + @Override + public void play() { + } + + @Override + public void pause() { + } + + @Override + public void setVolume(double volume) { + } + + @Override + public boolean isSupported() { + return false; + } + } // end of DummyClip +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/src/main/java/net/java/html/sound/package.html ---------------------------------------------------------------------- diff --git a/sound/src/main/java/net/java/html/sound/package.html b/sound/src/main/java/net/java/html/sound/package.html new file mode 100644 index 0000000..c41bf01 --- /dev/null +++ b/sound/src/main/java/net/java/html/sound/package.html @@ -0,0 +1,50 @@ +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + + Oracle and Java are registered trademarks of Oracle and/or its affiliates. + Other names may be trademarks of their respective owners. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common + Development and Distribution License("CDDL") (collectively, the + "License"). You may not use this file except in compliance with the + License. You can obtain a copy of the License at + http://www.netbeans.org/cddl-gplv2.html + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + specific language governing permissions and limitations under the + License. When distributing the software, include this License Header + Notice in each file and include the License file at + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + particular file as subject to the "Classpath" exception as provided + by Oracle in the GPL Version 2 section of the License file that + accompanied this code. If applicable, add the following below the + License Header, with the fields enclosed by brackets [] replaced by + your own identifying information: + "Portions Copyrighted [year] [name of copyright owner]" + + Contributor(s): + + The Original Software is NetBeans. The Initial Developer of the Original + Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + + If you wish your version of this file to be governed by only the CDDL + or only the GPL Version 2, indicate your decision by adding + "[Contributor] elects to include this software in this distribution + under the [CDDL or GPL Version 2] license." If you do not indicate a + single choice of license, a recipient has the option to distribute + your version of this file under either the CDDL, the GPL Version 2 or + to extend the choice of license to its licensees as provided above. + However, if you add GPL Version 2 code and therefore, elected the GPL + Version 2 license, then the option applies only if the new code is + made subject to such option by the copyright holder. + +--> +<body> + <p> + Control {@link net.java.html.sound.AudioClip sound} in your HTML for + Java applications. + </p> +</body> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java ---------------------------------------------------------------------- diff --git a/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java b/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java new file mode 100644 index 0000000..4d084bc --- /dev/null +++ b/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java @@ -0,0 +1,85 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.sound.impl; + +import net.java.html.js.JavaScriptBody; +import org.netbeans.html.sound.spi.AudioEnvironment; + +/** The default audio provider that delegates to HTML5 Audio tag + * it is used if no other {@link AudioEnvironment} is found. + * + * @author Jaroslav Tulach + */ +public final class BrowserAudioEnv implements AudioEnvironment<Object> { + public static final AudioEnvironment<?> DEFAULT = new BrowserAudioEnv(); + + private BrowserAudioEnv() { + } + + @Override + @JavaScriptBody(args = { "src" }, body = "" + + "if (!Audio) return null;" + + "return new Audio(src);") + public Object create(String src) { + // null if not running in browser + return null; + } + + @Override @JavaScriptBody(args = { "a" }, body = "a.play();") + public void play(Object a) { + } + + @Override @JavaScriptBody(args = { "a" }, body = "a.pause();") + public void pause(Object a) { + } + + @Override @JavaScriptBody(args = { "a", "volume" }, body = "a.setVolume(volume);") + public void setVolume(Object a, double volume) { + } + + @Override + @JavaScriptBody(args = "a", body = "return true;") + public boolean isSupported(Object a) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/src/main/java/org/netbeans/html/sound/spi/AudioEnvironment.java ---------------------------------------------------------------------- diff --git a/sound/src/main/java/org/netbeans/html/sound/spi/AudioEnvironment.java b/sound/src/main/java/org/netbeans/html/sound/spi/AudioEnvironment.java new file mode 100644 index 0000000..e8e6b82 --- /dev/null +++ b/sound/src/main/java/org/netbeans/html/sound/spi/AudioEnvironment.java @@ -0,0 +1,94 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.sound.spi; + +import net.java.html.BrwsrCtx; +import org.netbeans.html.context.spi.Contexts; + +/** Basic interface for sound playback providers. Register your implementation + * in a way {@link java.util.ServiceLoader} can find it - e.g. use + * {@link org.openide.util.lookup.ServiceProvider} annotation. Possibly + * one can register the provider into {@link Contexts#newBuilder()}, in + * case the implementation is somehow associated + * with the actual {@link BrwsrCtx} (works since version 0.8.3). + * + * @author antonepple + * @param <Audio> custom type representing the internal audio state + */ +public interface AudioEnvironment<Audio> { + /** Checks if the provided URL can be a supported audio stream + * and if so, it create an object to represent it. The created object + * will be used in future callbacks to other methods of this interface + * (like {@link #play(java.lang.Object)}). + * @param src the URL pointing to the media stream + * @return an internal representation object or <code>null</code> if this + * environment does not know how to handle such stream + */ + public Audio create(String src); + + /** Starts playback of the audio. + * + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method. + */ + public void play(Audio a); + + /** Pauses playback of the audio. + * + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method. + */ + public void pause(Audio a); + + /** Changes volume for the playback of the audio. + * + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method. + * @param volume value between 0.0 and 1.0 + */ + public void setVolume(Audio a, double volume); + + /** Checks whether given audio is supported + * + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method. + * @return <code>true</code> or <code>false</code> + */ + public boolean isSupported(Audio a); +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/226089a5/sound/src/main/java/org/netbeans/html/sound/spi/package.html ---------------------------------------------------------------------- diff --git a/sound/src/main/java/org/netbeans/html/sound/spi/package.html b/sound/src/main/java/org/netbeans/html/sound/spi/package.html new file mode 100644 index 0000000..b0e71cd --- /dev/null +++ b/sound/src/main/java/org/netbeans/html/sound/spi/package.html @@ -0,0 +1,49 @@ +<!-- + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + + Oracle and Java are registered trademarks of Oracle and/or its affiliates. + Other names may be trademarks of their respective owners. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common + Development and Distribution License("CDDL") (collectively, the + "License"). You may not use this file except in compliance with the + License. You can obtain a copy of the License at + http://www.netbeans.org/cddl-gplv2.html + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + specific language governing permissions and limitations under the + License. When distributing the software, include this License Header + Notice in each file and include the License file at + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + particular file as subject to the "Classpath" exception as provided + by Oracle in the GPL Version 2 section of the License file that + accompanied this code. If applicable, add the following below the + License Header, with the fields enclosed by brackets [] replaced by + your own identifying information: + "Portions Copyrighted [year] [name of copyright owner]" + + Contributor(s): + + The Original Software is NetBeans. The Initial Developer of the Original + Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved. + + If you wish your version of this file to be governed by only the CDDL + or only the GPL Version 2, indicate your decision by adding + "[Contributor] elects to include this software in this distribution + under the [CDDL or GPL Version 2] license." If you do not indicate a + single choice of license, a recipient has the option to distribute + your version of this file under either the CDDL, the GPL Version 2 or + to extend the choice of license to its licensees as provided above. + However, if you add GPL Version 2 code and therefore, elected the GPL + Version 2 license, then the option applies only if the new code is + made subject to such option by the copyright holder. + +--> +<body> + <p> + Give your {@link net.java.html.sound.AudioClip} real behavior! + </p> +</body>
