You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/08/02 18:38:07 UTC
svn commit: r1368594 - in /pivot/trunk: ./
tests/src/org/apache/pivot/tests/issues/pivot859/
Author: smartini
Date: Thu Aug 2 16:38:07 2012
New Revision: 1368594
URL: http://svn.apache.org/viewvc?rev=1368594&view=rev
Log:
merge fixes from 2.0.x
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/README.txt
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml
Modified:
pivot/trunk/ (props changed)
Propchange: pivot/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Aug 2 16:38:07 2012
@@ -8,3 +8,4 @@ install
lib
maven
noel
+temp
Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java?rev=1368594&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java Thu Aug 2 16:38:07 2012
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests.issues.pivot859;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.pivot.beans.BXMLSerializer;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.serialization.Serializer;
+import org.apache.pivot.serialization.StringSerializer;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.TextArea;
+import org.apache.pivot.wtk.TextInput;
+import org.apache.pivot.wtk.Window;
+
+/**
+ * Test application , to be run in multiple instances in the same HTML page.
+ */
+public class Pivot859 extends Application.Adapter {
+
+ private Window window = null;
+ private TextInput urlInput = null;
+ private PushButton goButton = null;
+ private TextArea contentArea = null;
+ private PushButton clearButton = null;
+ private Label statusLabel = null;
+
+ private String appletName = null;
+ private String defaultURL = null;
+
+
+ public void startup(final Display display, Map<String, String> properties) throws Exception {
+ System.out.println("startup(...)");
+
+ initializeProperties(properties);
+
+ BXMLSerializer bxmlSerializer = new BXMLSerializer();
+ window = (Window) bxmlSerializer.readObject(Pivot859.class, "pivot_859.bxml");
+ initializeFields(bxmlSerializer);
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean b) throws Exception {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ /**
+ * Set the Applet name.
+ * <p>
+ * Called by JavaScript from the Browser.
+ * @param name the name
+ */
+ public void setAppletName(String name) {
+ appletName = name;
+ System.out.println("set appletName to \"" + appletName + "\"");
+ }
+
+ /**
+ * Get the Applet name.
+ * <p>
+ * Called by JavaScript from the Browser.
+ * @return the name
+ */
+ public String getAppletName() {
+ return appletName;
+ }
+
+
+ private void initializeProperties(Map<String, String> properties) {
+ defaultURL = properties.get("default_url");
+ if (defaultURL == null){
+ defaultURL = "";
+ }
+ if (defaultURL.length() > 0){
+ System.out.println("got default URL from startup properties, to \"" + defaultURL + "\"");
+ }
+ }
+
+ private void initializeFields(BXMLSerializer serializer) {
+ System.out.println("initializeFields: start");
+
+ urlInput = (TextInput)serializer.getNamespace().get("textInput");
+ if (defaultURL.length() > 0){
+ urlInput.setText(defaultURL);
+ }
+
+ goButton = (PushButton)serializer.getNamespace().get("goButton");
+ goButton.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ clearContent();
+ retrieveURLContentSync();
+ }
+ });
+
+ contentArea = (TextArea)serializer.getNamespace().get("textArea");
+ clearButton = (PushButton)serializer.getNamespace().get("clearButton");
+ clearButton.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ clearContent();
+ }
+ });
+
+ statusLabel = (Label)serializer.getNamespace().get("textStatus");
+
+ System.out.println("initializeFields: end");
+ }
+
+ private String getAppletNameForLog() {
+ return ( (getAppletName() != null) ? getAppletName() + ": " : "" );
+ }
+
+ private void updateStatus(String status) {
+ System.out.println(getAppletNameForLog() + status);
+ statusLabel.setText(status);
+ }
+
+ private void clearContent() {
+ updateStatus("Clearing text area content ...");
+ // contentArea.clear();
+ contentArea.setText("");
+ }
+
+ private URL buildURL() {
+ URL url = null;
+ String urlTyped = urlInput.getText();
+
+ try {
+ url = new URL(urlTyped);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+
+ return url;
+ }
+
+ /**
+ * Retrieve content from the given URL (in applet GUI), but in a synchronous way.
+ */
+ private void retrieveURLContentSync() {
+ URL url = buildURL();
+ if (url == null) {
+ updateStatus("Unable to retrieve content from a bad URL");
+ return ;
+ }
+
+ try {
+ updateStatus("Retrieving Content from URL \"" + url + "\" ...");
+
+ long start = System.currentTimeMillis();
+ Serializer<String> serializer = new StringSerializer();
+ InputStream inputStream = url.openStream();
+ String result = serializer.readObject(inputStream);
+ if (result == null){
+ result = "";
+ }
+ long end = System.currentTimeMillis();
+
+ contentArea.setText(result);
+ updateStatus("retrieved " + result.length() + " chars in " + (end - start) + " msec.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+// TODO: retrieve content in the usual asynchronous way, but maybe in another method ...
+
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(Pivot859.class, args);
+ }
+
+}
Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/README.txt
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/README.txt?rev=1368594&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/README.txt (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/README.txt Thu Aug 2 16:38:07 2012
@@ -0,0 +1,18 @@
+//
+// README for Pivot859
+//
+
+This test must be run from a real browser, so before running the test you must generate Pivot jars, with the usual ant commands:
+
+ant package-tests
+ant deploy
+
+Note that this is required because in this test, to give grants to make queries outside the Plugin sandbox,
+we must use the signed version of jars.
+
+Then copy the html page from this package to a temporary folder (for example one folder up, relative to generated jar files),
+edit it to set the Pivot Version and the relative path of jars to load,
+and finally open the html page here in a real browser.
+
+Note that this test put multiple Applet instance inside the same HTML page,
+and any Applet instance does an HTTP Query via GET.
Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html?rev=1368594&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html Thu Aug 2 16:38:07 2012
@@ -0,0 +1,133 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <title>Pivot-859 - Test</title>
+
+ <style type="text/css">
+ applet {
+ border: 1px solid #999999;
+ }
+ </style>
+
+</head>
+<body>
+
+ <script type="text/javascript" src="http://java.com/js/deployJava.js"></script>
+ <script type="text/javascript">
+ // global variables to edit
+ var local_path_to_lib_jars = // "../../../../../../../../lib/"; // sample relative path, good from this package
+ "./lib/"; // edit to put the relative path between the html page and Pivot jars
+ var pivot_version = ""; // edit to put Pivot version in the string value
+ var pivot_signed = ".signed"; // name suffix for use signed version of jars
+
+ // Applet definition sample
+ var attributes = {
+ // id:"", // set later (if necessary)
+ // name:"", // set later (if necessary)
+ code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+ width:"640",
+ height:"240"
+ };
+
+ var libraries = [];
+ libraries.push(local_path_to_lib_jars + "pivot-tests-" + pivot_version + pivot_signed + ".jar");
+ libraries.push(local_path_to_lib_jars + "pivot-core-" + pivot_version + pivot_signed + ".jar");
+ libraries.push(local_path_to_lib_jars + "pivot-wtk-" + pivot_version + pivot_signed + ".jar");
+ libraries.push(local_path_to_lib_jars + "pivot-wtk-terra-" + pivot_version + pivot_signed + ".jar");
+ libraries.push(local_path_to_lib_jars + "pivot-tutorials-" + pivot_version + pivot_signed + ".jar");
+ libraries.push(local_path_to_lib_jars + "svgSalamander-tiny" + pivot_signed + ".jar");
+
+ attributes.archive = libraries.join(",");
+
+ var parameters = {
+ codebase_lookup:false,
+ application_class_name:"org.apache.pivot.tests.issues.pivot859.Pivot859",
+ separate_jvm:false
+ };
+
+ var javaArguments = ["-Dsun.awt.noerasebackground=true",
+ "-Dsun.awt.erasebackgroundonresize=true"];
+ parameters.java_arguments = javaArguments.join(" ");
+
+ var startupProperties = [];
+ </script>
+
+<div class="content">
+
+<div class="applet">
+ <p>Test Applet, first instance</p>
+ <script type="text/javascript">
+ // set some values, before running the applet
+ attributes.id = "applet1";
+ attributes.name = "applet, first instance";
+ startupProperties.push("default_url=http://pivot.apache.org/");
+ parameters.startup_properties = startupProperties.join("&");
+
+ // run the applet
+ deployJava.runApplet(attributes, parameters, "1.6");
+
+ // call Applet methods from JavaScript
+ var applet1 = document.getElementById("applet1");
+ // alert("applet1 = " + applet1);
+ var appletReference = applet1.getApplication(); // the reference to Pivot Applet instance
+ appletReference.setAppletName(applet1.name); // read the name from applet tag attribute in HTML page
+ // put some debug info in page
+ // alert(
+ document.write( // less intrusive
+ "<br/>" +
+ "applet has name = \"" + appletReference.getAppletName() + "\""
+ );
+ </script>
+ <br/>
+</div>
+<hr/>
+
+<div class="applet">
+ <p>Test Applet, second instance</p>
+ <script type="text/javascript">
+ // set some values, before running the applet
+ attributes.id = "applet2";
+ attributes.name = "applet, second instance";
+ startupProperties.push("default_url=http://www.google.com/");
+ parameters.startup_properties = startupProperties.join("&");
+
+ // run the applet
+ deployJava.runApplet(attributes, parameters, "1.6");
+
+ // call Applet methods from JavaScript
+ var applet2 = document.getElementById("applet2");
+ // alert("applet2 = " + applet2);
+ var appletReference = applet2.getApplication(); // the reference to Pivot Applet instance
+ appletReference.setAppletName(applet2.name); // read the name from applet tag attribute in HTML page
+ // put some debug info in page
+ // alert(
+ document.write( // less intrusive
+ "<br/>" +
+ "applet has name = \"" + appletReference.getAppletName() + "\""
+ );
+ </script>
+ <br/>
+</div>
+<hr/>
+
+</div>
+
+</body>
+</html>
Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml?rev=1368594&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml Thu Aug 2 16:38:07 2012
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Pivot-859" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:app="org.apache.pivot.tests.issues"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+>
+
+ <TablePane styles="{padding:6, horizontalSpacing:6, verticalSpacing:8}">
+ <columns>
+ <TablePane.Column width="100"/>
+ <TablePane.Column width="1*"/>
+ <TablePane.Column width="50"/>
+ </columns>
+
+ <TablePane.Row height="-1">
+ <Label styles="{horizontalAlignment:'right', verticalAlignment:'center'}" text="URL:"/>
+ <TextInput bxml:id="textInput" text="http://pivot.apache.org" textSize="30"/>
+ <PushButton bxml:id="goButton" buttonData="Go"/>
+ </TablePane.Row>
+ <TablePane.Row height="1*">
+ <Label styles="{horizontalAlignment:'right', verticalAlignment:'center'}" text="Content:"/>
+ <Border>
+ <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill_to_capacity"
+ preferredHeight="200"
+ >
+ <TextArea bxml:id="textArea"
+ styles="{wrapText:true}"
+ editable="false"
+ text=""
+ >
+ <textAreaContentListeners>
+ function textChanged(textArea) {
+ // java.lang.System.out.println("length = " + textArea.characterCount);
+ }
+ </textAreaContentListeners>
+ </TextArea>
+ </ScrollPane>
+ </Border>
+ <PushButton bxml:id="clearButton" buttonData="Clear" preferredHeight="40" preferredWidth="50">
+ <!--
+ <buttonPressListeners>
+ function buttonPressed(button) {
+ textArea.text = "";
+ }
+ </buttonPressListeners>
+ //-->
+ </PushButton>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <Label styles="{horizontalAlignment:'right', verticalAlignment:'center'}" text="Status:"/>
+ <Label bxml:id="textStatus" styles="{horizontalAlignment:'left', verticalAlignment:'center'}" text=""/>
+ </TablePane.Row>
+ </TablePane>
+
+</Window>