/** * Append the JavaScript part to end of the this JavaScript * * @param sourceCodeToAppend JavaScript source code to append on the end of this JavaScript * @return this JavaScript with javaScriptPartToAppend appended */ public JavaScript append(String sourceCodeToAppend) { return fromString(this.source + sourceCodeToAppend); }
@Override public String toString() { return getSourceCode(); }
/** * The factory method for JavaScript object * * @param source the JavaScript source code * @return the new JavaScript object with predefined JavaScript code */ public static JavaScript fromString(String source) { return new JavaScript(source); }
@Override public JavaScript getExtensionScript() { return JavaScript.fromResource("com/jquery/jquery-1.7.2.min.js").append("window.Graphene = window.Graphene || {}; window.Graphene.jQuery = jQuery.noConflict(true);"); }
/** * Loads the JavaScript from file. * * @param sourceFile the source file * @return the JavaScript object loaded from file * @throws RuntimeException when failed to load a script */ public static JavaScript fromFile(File sourceFile) { String sourceCode; try { sourceCode = inputStreamToString(new FileInputStream(sourceFile)); } catch (FileNotFoundException e) { throw new IllegalStateException("Unable to find JavaScript source file '" + sourceFile + "'", e); } catch (IOException e) { throw new RuntimeException("Unable to load JavaScript from file '" + sourceFile + "'", e); } return fromString(sourceCode); }
for (String source: dependency.sources()) { if (dependencyScript == null) { dependencyScript = JavaScript.fromResource(source); } else { dependencyScript = dependencyScript.join(JavaScript.fromResource(source)); JSMethod installMethod = target.getJSMethod(InstallableJavaScript.INSTALL_METHOD); String functionCall = target.getName() + "." + installMethod.getName() + "();"; dependencyScript = dependencyScript.join(JavaScript.fromString(functionCall)); for (String object: target.getName().split("\\.")) { if (jsInstallationDetection == null) { jsInstallationDetection = JavaScript.fromString("return (typeof " + object + " != 'undefined')"); } else { jsInstallationDetection = jsInstallationDetection.append(" && (typeof " + builder.toString() + object + " != 'undefined')"); this.installationDetectionScript = JavaScript.fromString("return true;"); this.extensionScript = JavaScript.fromString("return true;"); this.required = Collections.unmodifiableCollection(Collections.EMPTY_LIST);
/** * Loads the JavaScript from file. * * @param sourceFile the source file * @return the JavaScript object loaded from file * @throws RuntimeException when failed to load a script */ public static JavaScript fromFile(File sourceFile) { String sourceCode; try { sourceCode = inputStreamToString(new FileInputStream(sourceFile)); } catch (FileNotFoundException e) { throw new IllegalStateException("Unable to find JavaScript source file '" + sourceFile + "'", e); } catch (IOException e) { throw new RuntimeException("Unable to load JavaScript from file '" + sourceFile + "'", e); } return fromString(sourceCode); }
for (String source: dependency.sources()) { if (dependencyScript == null) { dependencyScript = JavaScript.fromResource(source); } else { dependencyScript = dependencyScript.join(JavaScript.fromResource(source)); JSMethod installMethod = target.getJSMethod(InstallableJavaScript.INSTALL_METHOD); String functionCall = target.getName() + "." + installMethod.getName() + "();"; dependencyScript = dependencyScript.join(JavaScript.fromString(functionCall)); for (String object: target.getName().split("\\.")) { if (jsInstallationDetection == null) { jsInstallationDetection = JavaScript.fromString("return (typeof " + object + " != 'undefined')"); } else { jsInstallationDetection = jsInstallationDetection.append(" && (typeof " + builder.toString() + object + " != 'undefined')"); this.installationDetectionScript = JavaScript.fromString("return true;"); this.extensionScript = JavaScript.fromString("return true;"); this.required = Collections.unmodifiableCollection(Collections.EMPTY_LIST);
@Override public JavaScript getExtensionScript() { return JavaScript.fromResource("com/jquery/jquery-1.7.2.min.js").append("window.Graphene = window.Graphene || {}; window.Graphene.jQuery = jQuery.noConflict(true);"); }
/** * Joins this JavaScript object with another JavaScript object to single JavaScript. * * @param javaScriptToJoin the JavaScript object we want to join with * @return the joined JavaScript object */ public JavaScript join(JavaScript javaScriptToJoin) { return fromString(this.source + '\n' + javaScriptToJoin.source); }
/** * Loads the JavaScript from classpath resource. * * @param resourceName the resource name, e.g. "org/jboss/test/..." * @return the JavaScript object loaded from classpath resource * @throws RuntimeException when failed to load a script */ public static JavaScript fromResource(String resourceName) { InputStream inputStream = JavaScript.class.getResourceAsStream("/" + resourceName); if (inputStream == null) { throw new IllegalStateException("Can't open the '" + resourceName + "' resource."); } String sourceCode; try { sourceCode = inputStreamToString(inputStream); } catch (IOException e) { throw new RuntimeException("Unable to load JavaScript from resource with name '" + resourceName + "'", e); } return fromString(sourceCode); }
@Override public String toString() { return getSourceCode(); }
/** * The factory method for JavaScript object * * @param source the JavaScript source code * @return the new JavaScript object with predefined JavaScript code */ public static JavaScript fromString(String source) { return new JavaScript(source); }
/** * Joins this JavaScript object with another JavaScript object to single JavaScript. * * @param javaScriptToJoin the JavaScript object we want to join with * @return the joined JavaScript object */ public JavaScript join(JavaScript javaScriptToJoin) { return fromString(this.source + '\n' + javaScriptToJoin.source); }
/** * Loads the JavaScript from classpath resource. * * @param resourceName the resource name, e.g. "org/jboss/test/..." * @return the JavaScript object loaded from classpath resource * @throws RuntimeException when failed to load a script */ public static JavaScript fromResource(String resourceName) { InputStream inputStream = JavaScript.class.getResourceAsStream("/" + resourceName); if (inputStream == null) { throw new IllegalStateException("Can't open the '" + resourceName + "' resource."); } String sourceCode; try { sourceCode = inputStreamToString(inputStream); } catch (IOException e) { throw new RuntimeException("Unable to load JavaScript from resource with name '" + resourceName + "'", e); } return fromString(sourceCode); }
public static Object execute(JavascriptExecutor executor, org.jboss.arquillian.graphene.spi.javascript.JavaScript javaScript, Object... args) { return execute(executor, javaScript.getSourceCode(), args); }
@Override public JavaScript getInstallationDetectionScript() { return JavaScript.fromString("return ((typeof window.Graphene != 'undefined') && (typeof window.Graphene.jQuery != 'undefined') && " + "(typeof window.Graphene.jQuery == 'function') && (typeof window.Graphene.jQuery != null))"); }
public static Object execute(JavascriptExecutor executor, org.jboss.arquillian.graphene.spi.javascript.JavaScript javaScript, Object... args) { return execute(executor, javaScript.getSourceCode(), args); }
/** * Append the JavaScript part to end of the this JavaScript * * @param sourceCodeToAppend JavaScript source code to append on the end of this JavaScript * @return this JavaScript with javaScriptPartToAppend appended */ public JavaScript append(String sourceCodeToAppend) { return fromString(this.source + sourceCodeToAppend); }
@Override public JavaScript getInstallationDetectionScript() { return JavaScript.fromString("return ((typeof window.Graphene != 'undefined') && (typeof window.Graphene.jQuery != 'undefined') && " + "(typeof window.Graphene.jQuery == 'function') && (typeof window.Graphene.jQuery != null))"); }