<stylesheet src="component-themes/collection.css"/>
<!-- Specify the app entry point class. -->
- <entry-point class="com.itmill.toolkit.terminal.gwt.client.Client"/>
+ <entry-point class="com.itmill.toolkit.terminal.gwt.client.ApplicationConnection"/>
</module>
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.json.client.JSONString;
+import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.user.client.ui.FocusWidget;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.ui.IContextMenu;
+
+/**
+ * Entry point classes define <code>onModuleLoad()</code>.
+ *
+ * TODO IDEA: Should be extend Widget here !?!?!
+ */
+public class ApplicationConnection implements EntryPoint {
+
+ private String appUri;
+
+ private HashMap resourcesMap = new HashMap();
+
+ // TODO remove repaintAll until things start to pile up
+ private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri
+ + "/UIDL/?repaintAll=1&");
+
+ public Console console;
+
+ private Vector pendingVariables = new Vector();
+
+ private HashMap paintables = new HashMap();
+
+ private WidgetFactory widgetFactory = new DefaultWidgetFactory();
+
+ private LocaleService locale;
+
+ private IContextMenu contextMenu = null;
+
+ /**
+ * This is the entry point method.
+ */
+ public void onModuleLoad() {
+
+ appUri = getAppUri();
+
+ console = new Console(RootPanel.get("itmtk-loki"));
+
+ console.log("Makin fake UIDL Request to fool servlet of an app init");
+ RequestBuilder rb2 = new RequestBuilder(RequestBuilder.GET, appUri);
+ try {
+ rb2.sendRequest("", new RequestCallback() {
+
+ public void onResponseReceived(Request request,
+ Response response) {
+ console
+ .log("Got fake response... sending initial UIDL request");
+ makeUidlRequest("repaintAll=1");
+ }
+
+ public void onError(Request request, Throwable exception) {
+ // TODO Auto-generated method stub
+
+ }
+
+ });
+ } catch (RequestException e1) {
+ e1.printStackTrace();
+ }
+
+ }
+
+ private native String getAppUri()/*-{
+ return $wnd.itmtk.appUri;
+ }-*/;
+
+ private void makeUidlRequest(String requestData) {
+ console.log("Making UIDL Request with params: " + requestData);
+ rb = new RequestBuilder(RequestBuilder.POST, appUri
+ + "/UIDL/?requestId=" + (Math.random()) + "&" + requestData);
+ try {
+ rb.sendRequest(requestData, new RequestCallback() {
+ public void onError(Request request, Throwable exception) {
+ console.error("Got error");
+ }
+
+ public void onResponseReceived(Request request,
+ Response response) {
+ handleReceivedJSONMessage(response);
+ }
+
+ });
+
+ } catch (RequestException e) {
+ console.error(e.getMessage());
+ }
+ }
+
+ private void handleReceivedJSONMessage(Response response) {
+ Date start = new Date();
+ String jsonText = response.getText().substring(3) + "}";
+ System.out.println(jsonText);
+ JSONValue json;
+ try {
+ json = JSONParser.parse(jsonText);
+ } catch (com.google.gwt.json.client.JSONException e) {
+ console.log(e.getMessage() + " - Original JSON-text:");
+ console.log(jsonText);
+ return;
+ }
+ // Store resources
+ JSONObject resources = (JSONObject) ((JSONObject) json)
+ .get("resources");
+ for (Iterator i = resources.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ resourcesMap.put(key, ((JSONString)resources.get(key)).stringValue());
+ }
+
+ // Store locale data
+ if(((JSONObject)json).containsKey("locales")) {
+ JSONArray l = (JSONArray) ((JSONObject) json).get("locales");
+ for(int i=0; i < l.size(); i++)
+ LocaleService.addLocale((JSONObject) l.get(i));
+ }
+
+ // Process changes
+ JSONArray changes = (JSONArray) ((JSONObject) json).get("changes");
+ for (int i = 0; i < changes.size(); i++) {
+ try {
+ UIDL change = new UIDL((JSONArray) changes.get(i));
+ try {
+ console.dirUIDL(change);
+ } catch (Exception e) {
+ console.log(e.getMessage());
+ // TODO: dir doesn't work in any browser although it should
+ // work (works in hosted mode)
+ // it partially did at some part but now broken.
+ }
+ UIDL uidl = change.getChildUIDL(0);
+ Paintable paintable = getPaintable(uidl.getId());
+ if (paintable != null)
+ paintable.updateFromUIDL(uidl, this);
+ else {
+ if (!uidl.getTag().equals("window"))
+ throw new IllegalStateException("Received update for "
+ + uidl.getTag()
+ + ", but there is no such paintable ("
+ + uidl.getId() + ") registered yet.");
+ Widget window = widgetFactory.createWidget(uidl);
+ registerPaintable(uidl.getId(), (Paintable) window);
+ ((Paintable) window).updateFromUIDL(uidl, this);
+
+ // TODO We should also handle other windows
+ RootPanel.get("itmtk-ajax-window").add(window);
+ }
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+
+ }
+ long prosessingTime = (new Date().getTime()) - start.getTime();
+ console.log(" Processing time was " + String.valueOf(prosessingTime)
+ + "ms for " + jsonText.length() + " characters of JSON");
+
+ }
+
+ public void registerPaintable(String id, Paintable paintable) {
+ paintables.put(id, paintable);
+ }
+
+ public Paintable getPaintable(String id) {
+ return (Paintable) paintables.get(id);
+ }
+
+ private void addVariableToQueue(String paintableId, String variableName,
+ String encodedValue, boolean immediate) {
+ String id = paintableId + "_" + variableName;
+ for (int i = 0; i < pendingVariables.size(); i += 2)
+ if ((pendingVariables.get(i)).equals(id)) {
+ pendingVariables.remove(i);
+ pendingVariables.remove(i);
+ break;
+ }
+ pendingVariables.add(id);
+ pendingVariables.add(encodedValue);
+ if (immediate)
+ sendPendingVariableChanges();
+ }
+
+ public void sendPendingVariableChanges() {
+ StringBuffer req = new StringBuffer();
+
+ for (int i = 0; i < pendingVariables.size(); i++) {
+ req.append(pendingVariables.get(i++));
+ req.append("=");
+ req.append(pendingVariables.get(i));
+ req.append("&");
+ }
+
+ pendingVariables.clear();
+ makeUidlRequest(req.toString());
+ }
+
+ private String escapeString(String value) {
+ // TODO
+ return value;
+ }
+
+ public void updateVariable(String paintableId, String variableName,
+ String newValue, boolean immediate) {
+ addVariableToQueue(paintableId, variableName, escapeString(newValue),
+ immediate);
+ }
+
+ public void updateVariable(String paintableId, String variableName,
+ int newValue, boolean immediate) {
+ addVariableToQueue(paintableId, variableName, "" + newValue, immediate);
+ }
+
+ public void updateVariable(String paintableId, String variableName,
+ boolean newValue, boolean immediate) {
+ addVariableToQueue(paintableId, variableName, newValue ? "true"
+ : "false", immediate);
+ }
+
+ public void updateVariable(String paintableId, String variableName,
+ Object[] values, boolean immediate) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < values.length; i++) {
+ if (i > 0)
+ buf.append(",");
+ buf.append(escapeString(values[i].toString()));
+ }
+ addVariableToQueue("array:" + paintableId, variableName,
+ buf.toString(), immediate);
+ }
+
+ public WidgetFactory getWidgetFactory() {
+ return widgetFactory;
+ }
+
+ public void setWidgetFactory(WidgetFactory widgetFactory) {
+ this.widgetFactory = widgetFactory;
+ }
+
+ public static Layout getParentLayout(Widget component) {
+ Widget parent = component.getParent();
+ while (parent != null && !(parent instanceof Layout))
+ parent = parent.getParent();
+ if (parent != null && ((Layout) parent).hasChildComponent(component))
+ return (Layout) parent;
+ return null;
+ }
+
+ /**
+ * Update generic component features.
+ *
+ * <h2>Selecting correct implementation</h2>
+ *
+ * <p>
+ * The implementation of a component depends on many properties, including
+ * styles, component features, etc. Sometimes the user changes those
+ * properties after the component has been created. Calling this method in
+ * the beginning of your updateFromUIDL -method automatically replaces your
+ * component with more appropriate if the requested implementation changes.
+ * </p>
+ *
+ * <h2>Caption, icon, error messages and description</h2>
+ *
+ * <p>
+ * Component can delegate management of caption, icon, error messages and
+ * description to parent layout. This is optional an should be decided by
+ * component author
+ * </p>
+ *
+ * <h2>Component visibility and disabling</h2>
+ *
+ * This method will manage component visibility automatically and if
+ * component is an instanceof FocusWidget, also handle component disabling
+ * when needed.
+ *
+ * @param currentWidget
+ * Current widget that might need replacement
+ * @param uidl
+ * UIDL to be painted
+ * @param manageCaption
+ * True if you want to delegate caption, icon, description and
+ * error message management to parent.
+ *
+ * @return Returns true iff no further painting is needed by caller
+ */
+ public boolean updateComponent(Widget component, UIDL uidl,
+ boolean manageCaption) {
+
+ // Switch to correct implementation if neede
+ if (!widgetFactory.isCorrectImplementation(component, uidl)) {
+ Layout parent = getParentLayout(component);
+ if (parent != null) {
+ Widget w = widgetFactory.createWidget(uidl);
+ registerPaintable(uidl.getId(), (Paintable) w);
+ parent.replaceChildComponent(component, w);
+ ((Paintable) w).updateFromUIDL(uidl, this);
+ return true;
+ }
+ }
+
+ // Set captions
+ // TODO Manage Error messages
+ if (manageCaption) {
+ Layout parent = getParentLayout(component);
+ if (parent != null)
+ parent.updateCaption(component, uidl);
+ }
+
+ // Visibility, Disabling and read-only status
+ if (component instanceof FocusWidget) {
+ boolean enabled = true;
+ if (uidl.hasAttribute("disabled"))
+ enabled = !uidl.getBooleanAttribute("disabled");
+ else if (uidl.hasAttribute("readonly"))
+ enabled = !uidl.getBooleanAttribute("readonly");
+ ((FocusWidget) component).setEnabled(enabled);
+ } else {
+ boolean enabled = true;
+ if (uidl.hasAttribute("disabled"))
+ enabled = !uidl.getBooleanAttribute("disabled");
+ if(!enabled)
+ component.addStyleName("i-disabled");
+ else
+ component.removeStyleName("i-disabled");
+ }
+ boolean visible = !uidl.getBooleanAttribute("invisible");
+ component.setVisible(visible);
+ if (!visible)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Get either existing or new widget for given UIDL.
+ *
+ * If corresponding paintable has been previously painted, return it.
+ * Otherwise create and register a new widget from UIDL. Caller must update
+ * the returned widget from UIDL after it has been connected to parent.
+ *
+ * @param uidl
+ * UIDL to create widget from.
+ * @return Either existing or new widget corresponding to UIDL.
+ */
+ public Widget getWidget(UIDL uidl) {
+ String id = uidl.getId();
+ Widget w = (Widget) getPaintable(id);
+ if (w != null)
+ return w;
+ w = widgetFactory.createWidget(uidl);
+ registerPaintable(id, (Paintable) w);
+ return w;
+ }
+
+ public String getResource(String name) {
+ return (String) resourcesMap.get(name);
+ }
+
+ /**
+ * Singleton method to get instance of app's context menu.
+ *
+ * @return IContextMenu object
+ */
+ public IContextMenu getContextMenu() {
+ if(contextMenu == null) {
+ contextMenu = new IContextMenu();
+ }
+ return contextMenu;
+ }
+}
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Vector;
-
-import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONParser;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
-import com.google.gwt.user.client.ui.FocusWidget;
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.ui.IContextMenu;
-
-/**
- * Entry point classes define <code>onModuleLoad()</code>.
- *
- * TODO IDEA: Should be extend Widget here !?!?!
- */
-public class Client implements EntryPoint {
-
- private String appUri;
-
- private HashMap resourcesMap = new HashMap();
-
- // TODO remove repaintAll until things start to pile up
- private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri
- + "/UIDL/?repaintAll=1&");
-
- public Console console;
-
- private Vector pendingVariables = new Vector();
-
- private HashMap paintables = new HashMap();
-
- private WidgetFactory widgetFactory = new DefaultWidgetFactory();
-
- private LocaleService locale;
-
- private IContextMenu contextMenu = null;
-
- /**
- * This is the entry point method.
- */
- public void onModuleLoad() {
-
- appUri = getAppUri();
-
- console = new Console(RootPanel.get("itmtk-loki"));
-
- console.log("Makin fake UIDL Request to fool servlet of an app init");
- RequestBuilder rb2 = new RequestBuilder(RequestBuilder.GET, appUri);
- try {
- rb2.sendRequest("", new RequestCallback() {
-
- public void onResponseReceived(Request request,
- Response response) {
- console
- .log("Got fake response... sending initial UIDL request");
- makeUidlRequest("repaintAll=1");
- }
-
- public void onError(Request request, Throwable exception) {
- // TODO Auto-generated method stub
-
- }
-
- });
- } catch (RequestException e1) {
- e1.printStackTrace();
- }
-
- }
-
- private native String getAppUri()/*-{
- return $wnd.itmtk.appUri;
- }-*/;
-
- private void makeUidlRequest(String requestData) {
- console.log("Making UIDL Request with params: " + requestData);
- rb = new RequestBuilder(RequestBuilder.POST, appUri
- + "/UIDL/?requestId=" + (Math.random()) + "&" + requestData);
- try {
- rb.sendRequest(requestData, new RequestCallback() {
- public void onError(Request request, Throwable exception) {
- console.error("Got error");
- }
-
- public void onResponseReceived(Request request,
- Response response) {
- handleReceivedJSONMessage(response);
- }
-
- });
-
- } catch (RequestException e) {
- console.error(e.getMessage());
- }
- }
-
- private void handleReceivedJSONMessage(Response response) {
- Date start = new Date();
- String jsonText = response.getText().substring(3) + "}";
- System.out.println(jsonText);
- JSONValue json;
- try {
- json = JSONParser.parse(jsonText);
- } catch (com.google.gwt.json.client.JSONException e) {
- console.log(e.getMessage() + " - Original JSON-text:");
- console.log(jsonText);
- return;
- }
- // Store resources
- JSONObject resources = (JSONObject) ((JSONObject) json)
- .get("resources");
- for (Iterator i = resources.keySet().iterator(); i.hasNext();) {
- String key = (String) i.next();
- resourcesMap.put(key, ((JSONString)resources.get(key)).stringValue());
- }
-
- // Store locale data
- if(((JSONObject)json).containsKey("locales")) {
- JSONArray l = (JSONArray) ((JSONObject) json).get("locales");
- for(int i=0; i < l.size(); i++)
- LocaleService.addLocale((JSONObject) l.get(i));
- }
-
- // Process changes
- JSONArray changes = (JSONArray) ((JSONObject) json).get("changes");
- for (int i = 0; i < changes.size(); i++) {
- try {
- UIDL change = new UIDL((JSONArray) changes.get(i));
- try {
- console.dirUIDL(change);
- } catch (Exception e) {
- console.log(e.getMessage());
- // TODO: dir doesn't work in any browser although it should
- // work (works in hosted mode)
- // it partially did at some part but now broken.
- }
- UIDL uidl = change.getChildUIDL(0);
- Paintable paintable = getPaintable(uidl.getId());
- if (paintable != null)
- paintable.updateFromUIDL(uidl, this);
- else {
- if (!uidl.getTag().equals("window"))
- throw new IllegalStateException("Received update for "
- + uidl.getTag()
- + ", but there is no such paintable ("
- + uidl.getId() + ") registered yet.");
- Widget window = widgetFactory.createWidget(uidl);
- registerPaintable(uidl.getId(), (Paintable) window);
- ((Paintable) window).updateFromUIDL(uidl, this);
-
- // TODO We should also handle other windows
- RootPanel.get("itmtk-ajax-window").add(window);
- }
-
- } catch (Throwable e) {
- e.printStackTrace();
- }
-
- }
- long prosessingTime = (new Date().getTime()) - start.getTime();
- console.log(" Processing time was " + String.valueOf(prosessingTime)
- + "ms for " + jsonText.length() + " characters of JSON");
-
- }
-
- public void registerPaintable(String id, Paintable paintable) {
- paintables.put(id, paintable);
- }
-
- public Paintable getPaintable(String id) {
- return (Paintable) paintables.get(id);
- }
-
- private void addVariableToQueue(String paintableId, String variableName,
- String encodedValue, boolean immediate) {
- String id = paintableId + "_" + variableName;
- for (int i = 0; i < pendingVariables.size(); i += 2)
- if ((pendingVariables.get(i)).equals(id)) {
- pendingVariables.remove(i);
- pendingVariables.remove(i);
- break;
- }
- pendingVariables.add(id);
- pendingVariables.add(encodedValue);
- if (immediate)
- sendPendingVariableChanges();
- }
-
- public void sendPendingVariableChanges() {
- StringBuffer req = new StringBuffer();
-
- for (int i = 0; i < pendingVariables.size(); i++) {
- req.append(pendingVariables.get(i++));
- req.append("=");
- req.append(pendingVariables.get(i));
- req.append("&");
- }
-
- pendingVariables.clear();
- makeUidlRequest(req.toString());
- }
-
- private String escapeString(String value) {
- // TODO
- return value;
- }
-
- public void updateVariable(String paintableId, String variableName,
- String newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, escapeString(newValue),
- immediate);
- }
-
- public void updateVariable(String paintableId, String variableName,
- int newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, "" + newValue, immediate);
- }
-
- public void updateVariable(String paintableId, String variableName,
- boolean newValue, boolean immediate) {
- addVariableToQueue(paintableId, variableName, newValue ? "true"
- : "false", immediate);
- }
-
- public void updateVariable(String paintableId, String variableName,
- Object[] values, boolean immediate) {
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- if (i > 0)
- buf.append(",");
- buf.append(escapeString(values[i].toString()));
- }
- addVariableToQueue("array:" + paintableId, variableName,
- buf.toString(), immediate);
- }
-
- public WidgetFactory getWidgetFactory() {
- return widgetFactory;
- }
-
- public void setWidgetFactory(WidgetFactory widgetFactory) {
- this.widgetFactory = widgetFactory;
- }
-
- public static Layout getParentLayout(Widget component) {
- Widget parent = component.getParent();
- while (parent != null && !(parent instanceof Layout))
- parent = parent.getParent();
- if (parent != null && ((Layout) parent).hasChildComponent(component))
- return (Layout) parent;
- return null;
- }
-
- /**
- * Update generic component features.
- *
- * <h2>Selecting correct implementation</h2>
- *
- * <p>
- * The implementation of a component depends on many properties, including
- * styles, component features, etc. Sometimes the user changes those
- * properties after the component has been created. Calling this method in
- * the beginning of your updateFromUIDL -method automatically replaces your
- * component with more appropriate if the requested implementation changes.
- * </p>
- *
- * <h2>Caption, icon, error messages and description</h2>
- *
- * <p>
- * Component can delegate management of caption, icon, error messages and
- * description to parent layout. This is optional an should be decided by
- * component author
- * </p>
- *
- * <h2>Component visibility and disabling</h2>
- *
- * This method will manage component visibility automatically and if
- * component is an instanceof FocusWidget, also handle component disabling
- * when needed.
- *
- * @param currentWidget
- * Current widget that might need replacement
- * @param uidl
- * UIDL to be painted
- * @param manageCaption
- * True if you want to delegate caption, icon, description and
- * error message management to parent.
- *
- * @return Returns true iff no further painting is needed by caller
- */
- public boolean updateComponent(Widget component, UIDL uidl,
- boolean manageCaption) {
-
- // Switch to correct implementation if neede
- if (!widgetFactory.isCorrectImplementation(component, uidl)) {
- Layout parent = getParentLayout(component);
- if (parent != null) {
- Widget w = widgetFactory.createWidget(uidl);
- registerPaintable(uidl.getId(), (Paintable) w);
- parent.replaceChildComponent(component, w);
- ((Paintable) w).updateFromUIDL(uidl, this);
- return true;
- }
- }
-
- // Set captions
- // TODO Manage Error messages
- if (manageCaption) {
- Layout parent = getParentLayout(component);
- if (parent != null)
- parent.updateCaption(component, uidl);
- }
-
- // Visibility, Disabling and read-only status
- if (component instanceof FocusWidget) {
- boolean enabled = true;
- if (uidl.hasAttribute("disabled"))
- enabled = !uidl.getBooleanAttribute("disabled");
- else if (uidl.hasAttribute("readonly"))
- enabled = !uidl.getBooleanAttribute("readonly");
- ((FocusWidget) component).setEnabled(enabled);
- } else {
- boolean enabled = true;
- if (uidl.hasAttribute("disabled"))
- enabled = !uidl.getBooleanAttribute("disabled");
- if(!enabled)
- component.addStyleName("i-disabled");
- else
- component.removeStyleName("i-disabled");
- }
- boolean visible = !uidl.getBooleanAttribute("invisible");
- component.setVisible(visible);
- if (!visible)
- return true;
-
- return false;
- }
-
- /**
- * Get either existing or new widget for given UIDL.
- *
- * If corresponding paintable has been previously painted, return it.
- * Otherwise create and register a new widget from UIDL. Caller must update
- * the returned widget from UIDL after it has been connected to parent.
- *
- * @param uidl
- * UIDL to create widget from.
- * @return Either existing or new widget corresponding to UIDL.
- */
- public Widget getWidget(UIDL uidl) {
- String id = uidl.getId();
- Widget w = (Widget) getPaintable(id);
- if (w != null)
- return w;
- w = widgetFactory.createWidget(uidl);
- registerPaintable(id, (Paintable) w);
- return w;
- }
-
- public String getResource(String name) {
- return (String) resourcesMap.get(name);
- }
-
- /**
- * Singleton method to get instance of app's context menu.
- *
- * @return IContextMenu object
- */
- public IContextMenu getContextMenu() {
- if(contextMenu == null) {
- contextMenu = new IContextMenu();
- }
- return contextMenu;
- }
-}
public interface Paintable {
- public void updateFromUIDL(UIDL uidl, Client client);
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client);
}
package com.itmill.toolkit.terminal.gwt.client.ui;
import com.google.gwt.user.client.Command;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
/**
*
*/
public IAction[] getActions();
- public Client getClient();
+ public ApplicationConnection getClient();
public String getPaintableId();
}
\ No newline at end of file
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Button;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
String id;
- Client client;
+ ApplicationConnection client;
public IButton() {
setStyleName(CLASSNAME);
});
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation,
// but don't let container manage caption etc.
package com.itmill.toolkit.terminal.gwt.client.ui;\r
\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
public class ICalendar extends IDateField {\r
add(date);\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
super.updateFromUIDL(uidl, client);\r
date.updateCalendar();\r
}\r
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
boolean immediate;
- Client client;
+ ApplicationConnection client;
public ICheckBox() {
addClickListener(new ClickListener() {
});
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation
if (client.updateComponent(this, uidl, false))
package com.itmill.toolkit.terminal.gwt.client.ui;\r
\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
public class IComponent extends IPanel {\r
setStyleName("i-component");\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
super.updateFromUIDL(uidl, client);\r
setStyleName("i-component");\r
}\r
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
}
/** Update the layout from UIDL */
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Client manages general cases
if (client.updateComponent(this, uidl, false))
}
/** Update implementing HTML-layout if needed. */
- private void updateHTML(UIDL uidl, Client client) {
+ private void updateHTML(UIDL uidl, ApplicationConnection client) {
// Update only if style has changed
String newStyle = uidl.getStringAttribute("style");
import java.util.Date;\r
\r
import com.google.gwt.user.client.ui.FlowPanel;\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.DateTimeService;\r
import com.itmill.toolkit.terminal.gwt.client.LocaleNotLoadedException;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
\r
String id;\r
\r
- Client client;\r
+ ApplicationConnection client;\r
\r
protected boolean immediate;\r
\r
dts = new DateTimeService();\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
// Ensure correct implementation and let layout manage caption\r
if (client.updateComponent(this, uidl, true))\r
return;\r
package com.itmill.toolkit.terminal.gwt.client.ui;
import com.google.gwt.user.client.ui.HTML;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public class IEmbedded extends HTML implements Paintable {
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if(uidl.hasAttribute("type") && uidl.getStringAttribute("type").equals("image")) {
setHTML("<img src=\""+ uidl.getStringAttribute("src") +"\"/>");
} else {
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public class IGridLayout extends FlexTable implements Paintable {
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
clear();
if (uidl.hasAttribute("caption"))
setTitle(uidl.getStringAttribute("caption"));
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
private HashMap componentToWrapper = new HashMap();
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation
if (client.updateComponent(this, uidl, false))
package com.itmill.toolkit.terminal.gwt.client.ui;
import com.google.gwt.user.client.ui.HTML;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
setStyleName(CLASSNAME);
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true))
return;
import com.google.gwt.user.client.ui.KeyboardListener;\r
import com.google.gwt.user.client.ui.Panel;\r
import com.google.gwt.user.client.ui.Widget;\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
\r
public static final String CLASSNAME_OPTION = "i-select-option";\r
\r
- Client client;\r
+ ApplicationConnection client;\r
\r
String id;\r
\r
container.add(optionsContainer);\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
this.client = client;\r
this.id = uidl.getId();\r
\r
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public static final String CLASSNAME = "i-panel";
- Client client;
+ ApplicationConnection client;
String id;
content.setStyleName(CLASSNAME+"-content");
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation
if (client.updateComponent(this, uidl, false))
return;
import com.google.gwt.user.client.ui.PopupListener;\r
import com.google.gwt.user.client.ui.PopupPanel;\r
import com.google.gwt.user.client.ui.Widget;\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
popup.addPopupListener(this);\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
super.updateFromUIDL(uidl, client);\r
calendar.updateCalendar();\r
calendarToggle.setEnabled(enabled);\r
import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.IScrollTableRow;
private String[] columnOrder;
- private Client client;
+ private ApplicationConnection client;
private String paintableId;
private boolean immediate;
initWidget(panel);
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true))
return;
return availableCells.size();
}
- public Client getClient() {
+ public ApplicationConnection getClient() {
return client;
}
return actions;
}
- public Client getClient() {
+ public ApplicationConnection getClient() {
return client;
}
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
private Map columnOrder = new HashMap();
- private Client client;
+ private ApplicationConnection client;
private String id;
private boolean immediate = false;
initWidget(panel);
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true))
return;
import com.google.gwt.user.client.ui.TabListener;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
String id;
- Client client;
+ ApplicationConnection client;
ArrayList tabKeys = new ArrayList();
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
id = uidl.getId();
package com.itmill.toolkit.terminal.gwt.client.ui;\r
\r
import com.google.gwt.user.client.DOM;\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
/**\r
super(DOM.createTextArea());\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
// Call parent renderer explicitly\r
super.updateFromUIDL(uidl, client);\r
\r
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
protected String id;
- protected Client client;
+ protected ApplicationConnection client;
private boolean immediate = false;
addFocusListener(this);
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
id = uidl.getId();
import com.google.gwt.user.client.Timer;\r
import com.google.gwt.user.client.ui.ChangeListener;\r
import com.google.gwt.user.client.ui.Widget;\r
-import com.itmill.toolkit.terminal.gwt.client.Client;\r
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
import com.itmill.toolkit.terminal.gwt.client.DateLocale;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
add(text);\r
}\r
\r
- public void updateFromUIDL(UIDL uidl, Client client) {\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
super.updateFromUIDL(uidl, client);\r
buildTime();\r
}\r
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.TreeListener;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public static final String CLASSNAME = "i-tree";
Set selectedIds = new HashSet();
- Client client;
+ ApplicationConnection client;
String id;
private boolean selectable;
private boolean multiselect;
setStyleName(CLASSNAME);
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation and let container manage caption
if (client.updateComponent(this, uidl, true))
return;
String key;
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.setText(uidl.getStringAttribute("caption"));
key = uidl.getStringAttribute("key");
for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.VerticalPanel;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
caption.setStyleName("itmtk-unknown-caption");
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
setCaption("Client faced an unknown component type. Unrendered UIDL:");
uidlTree.addItem(uidl.dir());
}
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
private HashMap componentToWrapper = new HashMap();
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Ensure correct implementation
if (client.updateComponent(this, uidl, false))
package com.itmill.toolkit.terminal.gwt.client.ui;
-import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
return theme;
}
- public void updateFromUIDL(UIDL uidl, Client client) {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
theme = uidl.getStringAttribute("theme");
super.updateFromUIDL( uidl, client);
com.google.gwt.user.client.Window.setTitle(uidl.getStringAttribute("caption"));
HttpServletResponse response) throws ServletException, IOException {
// Transformer and output stream for the result
- HttpVariableMap variableMap = null;
OutputStream out = response.getOutputStream();
Application application = null;
try {
return;
}
- // Gets the variable map
- variableMap = getVariableMap(application, request);
- if (variableMap == null)
- return;
-
- // Change all variables based on request parameters
- Map unhandledParameters = variableMap.handleVariables(request,
- application);
-
- // Check/handle client side feature checks
- WebBrowserProbe
- .handleProbeRequest(request, unhandledParameters);
-
- // If rendering mode is not defined or detecting requested
- // try to detect it
- WebBrowser wb = WebBrowserProbe.getTerminalType(request
- .getSession());
-
- boolean detect = false;
- if (unhandledParameters.get("renderingMode") != null) {
- detect = ((String) ((Object[]) unhandledParameters
- .get("renderingMode"))[0]).equals("detect");
- }
- if (detect) {
- String themeName = application.getTheme();
- if (themeName == null)
- themeName = DEFAULT_THEME;
- if (unhandledParameters.get("theme") != null) {
- themeName = (String) ((Object[]) unhandledParameters
- .get("theme"))[0];
- }
- }
-
+
// Handles the URI if the application is still running
if (application.isRunning())
download = handleURI(application, request, response);
// Finds the window within the application
Window window = null;
if (application.isRunning())
- window = getApplicationWindow(request, application,
- unhandledParameters);
-
- // Handles the unhandled parameters if the application is
- // still running
- if (window != null && unhandledParameters != null
- && !unhandledParameters.isEmpty()) {
- try {
- window.handleParameters(unhandledParameters);
- } catch (Throwable t) {
- application
- .terminalError(new ParameterHandlerErrorImpl(
- window, t));
- }
- }
+ window = getApplicationWindow(request, application);
// Removes application if it has stopped
if (!application.isRunning()) {
// Sets terminal type for the window, if not already set
if (window.getTerminal() == null) {
- window.setTerminal(wb);
+ // TODO !!!!
+ window.setTerminal(new WebBrowser());
}
// Finds theme
String themeName = window.getTheme() != null ? window
.getTheme() : DEFAULT_THEME;
- if (unhandledParameters.get("theme") != null) {
- themeName = (String) ((Object[]) unhandledParameters
- .get("theme"))[0];
+ if (request.getParameter("theme") != null) {
+ themeName = request.getParameter("theme");
}
- // Handles resource requests
+ // Handles resource requests
if (handleResourceRequest(request, response, themeName))
return;
-
writeAjaxPage(request, response, out,
- unhandledParameters, window, wb, themeName);
+ window, themeName);
}
}
*/
private void writeAjaxPage(HttpServletRequest request,
HttpServletResponse response, OutputStream out,
- Map unhandledParameters, Window window, WebBrowser terminalType, String themeName) throws IOException, MalformedURLException {
+ Window window, String themeName) throws IOException, MalformedURLException {
response.setContentType("text/html");
BufferedWriter page = new BufferedWriter(new OutputStreamWriter(out));
" <div style=\"position: absolute; right: 5px; top: 5px; color: gray;\"><strong>IT Mill Toolkit 5 Prototype</strong></div>\n" +
" </body>\n" +
"</html>\n");
-
-
-
-// Theme t = theme;
-// Vector themes = new Vector();
-// themes.add(t);
-// while (t.getParent() != null) {
-// String parentName = t.getParent();
-// t = themeSource.getThemeByName(parentName);
-// themes.add(t);
-// }
-// for (int k = themes.size() - 1; k >= 0; k--) {
-// t = (Theme) themes.get(k);
-// Collection files = t.getFileNames(terminalType, Theme.MODE_AJAX);
-// for (Iterator i = files.iterator(); i.hasNext();) {
-// String file = (String) i.next();
-// if (file.endsWith(".css"))
-// page.write("<link rel=\"stylesheet\" href=\""
-// + getResourceLocation(t.getName(),
-// new ThemeResource(file))
-// + "\" type=\"text/css\" />\n");
-// else if (file.endsWith(".js")) {
-// page.write("<script src=\"");
-//
-// // TODO remove this and implement behaviour in themes
-// // description.xml files
-// if (file.endsWith("firebug.js")
-// && !isDebugMode(unhandledParameters)) {
-// file = file.replaceFirst("bug.js", "bugx.js");
-// }
-// page.write(getResourceLocation(t.getName(),
-// new ThemeResource(file)));
-// page.write("\" type=\"text/javascript\"></script>\n");
-// }
-// }
-//
-// }
-
-
-// page.write("itmill.tmp = new itmill.Client("
-// + "document.getElementById('ajax-window')," + "\"" + appUrl
-// + "/UIDL/" + "\",\"" + resourcePath
-// + ((Theme) themes.get(themes.size() - 1)).getName() + "/"
-//
-// + "client/\",document.getElementById('ajax-wait'));\n");
-
- // TODO Only current theme is registered to the client
- // for (int k = themes.size() - 1; k >= 0; k--) {
- // t = (Theme) themes.get(k);
-// t = theme;
-// String themeObjName = "itmill.themes."
-// + t.getName().substring(0, 1).toUpperCase()
-// + t.getName().substring(1);
-// page.write(" (new " + themeObjName + "(\"" + resourcePath + t.getName()
-// + "/\")).registerTo(itmill.tmp);\n");
- // }
+
page.close();
}
return true;
}
- /**
- * Gets the variable map for the session.
- *
- * @param application
- * @param request
- * the HTTP request.
- * @return the variable map.
- *
- */
- private static synchronized HttpVariableMap getVariableMap(
- Application application, HttpServletRequest request) {
-
- HttpSession session = request.getSession();
-
- // Gets the application to variablemap map
- Map varMapMap = (Map) session.getAttribute(SESSION_ATTR_VARMAP);
- if (varMapMap == null) {
- varMapMap = new WeakHashMap();
- session.setAttribute(SESSION_ATTR_VARMAP, varMapMap);
- }
-
- // Creates a variable map, if it does not exists.
- HttpVariableMap variableMap = (HttpVariableMap) varMapMap
- .get(application);
- if (variableMap == null) {
- variableMap = new HttpVariableMap();
- varMapMap.put(application, variableMap);
- }
-
- return variableMap;
- }
/**
* Gets the current application URL from request.
* servlet's normal operation.
*/
private Window getApplicationWindow(HttpServletRequest request,
- Application application, Map params) throws ServletException {
+ Application application) throws ServletException {
Window window = null;
+++ /dev/null
-/* *************************************************************************
-
- IT Mill Toolkit
-
- Development of Browser User Interfaces Made Easy
-
- Copyright (C) 2000-2006 IT Mill Ltd
-
- *************************************************************************
-
- This product is distributed under commercial license that can be found
- from the product package on license.pdf. Use of this product might
- require purchasing a commercial license from IT Mill Ltd. For guidelines
- on usage, see licensing-guidelines.html
-
- *************************************************************************
-
- For more information, contact:
-
- IT Mill Ltd phone: +358 2 4802 7180
- Ruukinkatu 2-4 fax: +358 2 4802 7181
- 20540, Turku email: info@itmill.com
- Finland company www: www.itmill.com
-
- Primary source for information and releases: www.itmill.com
-
- ********************************************************************** */
-
-package com.itmill.toolkit.terminal.gwt.server;
-
-import java.io.InputStream;
-
-/**
- * WebAdapter implementation of the UploadStream interface.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public class HttpUploadStream implements
- com.itmill.toolkit.terminal.UploadStream {
-
- /**
- * Holds value of property variableName.
- */
- private String streamName;
-
- private String contentName;
-
- private String contentType;
-
- /**
- * Holds value of property variableValue.
- */
- private InputStream stream;
-
- /**
- * Creates a new instance of UploadStreamImpl
- *
- * @param name
- * the name of the stream.
- * @param stream
- * the input stream.
- * @param contentName
- * the name of the content.
- * @param contentType
- * the type of the content.
- */
- public HttpUploadStream(String name, InputStream stream,
- String contentName, String contentType) {
- this.streamName = name;
- this.stream = stream;
- this.contentName = contentName;
- this.contentType = contentType;
- }
-
- /**
- * Gets the name of the stream.
- *
- * @return the name of the stream.
- */
- public String getStreamName() {
- return this.streamName;
- }
-
- /**
- * Gets the input stream.
- *
- * @return the Input stream.
- */
- public InputStream getStream() {
- return this.stream;
- }
-
- /**
- * Gets the input stream content type.
- *
- * @return the content type of the input stream.
- */
- public String getContentType() {
- return this.contentType;
- }
-
- /**
- * Gets the stream content name. Stream content name usually differs from
- * the actual stream name. It is used to identify the content of the stream.
- *
- * @return the Name of the stream content.
- */
- public String getContentName() {
- return this.contentName;
- }
-}
+++ /dev/null
-/* *************************************************************************
-
- IT Mill Toolkit
-
- Development of Browser User Interfaces Made Easy
-
- Copyright (C) 2000-2006 IT Mill Ltd
-
- *************************************************************************
-
- This product is distributed under commercial license that can be found
- from the product package on license.pdf. Use of this product might
- require purchasing a commercial license from IT Mill Ltd. For guidelines
- on usage, see licensing-guidelines.html
-
- *************************************************************************
-
- For more information, contact:
-
- IT Mill Ltd phone: +358 2 4802 7180
- Ruukinkatu 2-4 fax: +358 2 4802 7181
- 20540, Turku email: info@itmill.com
- Finland company www: www.itmill.com
-
- Primary source for information and releases: www.itmill.com
-
- ********************************************************************** */
-
-package com.itmill.toolkit.terminal.gwt.server;
-
-import com.itmill.toolkit.terminal.SystemError;
-import com.itmill.toolkit.terminal.Terminal;
-import com.itmill.toolkit.terminal.UploadStream;
-import com.itmill.toolkit.terminal.VariableOwner;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Enumeration;
-import java.util.WeakHashMap;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.LinkedList;
-import java.util.Iterator;
-
-/**
- * Class implementing the variable mappings.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public class HttpVariableMap {
-
- // Id <-> (Owner,Name) mapping
- private Map idToNameMap = new HashMap();
-
- private Map idToTypeMap = new HashMap();
-
- private Map idToOwnerMap = new HashMap();
-
- private Map idToValueMap = new HashMap();
-
- private Map ownerToNameToIdMap = new WeakHashMap();
-
- private Object mapLock = new Object();
-
- // Id generator
- private long lastId = 0;
-
- /**
- * Converts the string to a supported class.
- *
- * @param type
- * @param value
- * @throws java.lang.ClassCastException
- */
- private static Object convert(Class type, String value)
- throws java.lang.ClassCastException {
- try {
-
- // Boolean typed variables
- if (type.equals(Boolean.class))
- return new Boolean(!(value.equals("") || value.equals("false")));
-
- // Integer typed variables
- if (type.equals(Integer.class))
- return new Integer(value.trim());
-
- // String typed variables
- if (type.equals(String.class))
- return value;
-
- throw new ClassCastException("Unsupported type: " + type.getName());
- } catch (NumberFormatException e) {
- return null;
- }
- }
-
- /**
- * Registers a new variable.
- *
- * @param name
- * the name of the variable.
- * @param type
- * @param value
- * @param owner
- * the Listener for variable changes.
- *
- * @return id to assigned for this variable.
- */
- public String registerVariable(String name, Class type, Object value,
- VariableOwner owner) {
-
- // Checks that the type of the class is supported
- if (!(type.equals(Boolean.class) || type.equals(Integer.class)
- || type.equals(String.class) || type.equals(String[].class) || type
- .equals(UploadStream.class)))
- throw new SystemError("Unsupported variable type: "
- + type.getClass());
-
- synchronized (mapLock) {
-
- // Checks if the variable is already mapped
- HashMap nameToIdMap = (HashMap) ownerToNameToIdMap.get(owner);
- if (nameToIdMap == null) {
- nameToIdMap = new HashMap();
- ownerToNameToIdMap.put(owner, nameToIdMap);
- }
- String id = (String) nameToIdMap.get(name);
-
- if (id == null) {
- // Generates new id and register it
- id = "v" + String.valueOf(++lastId);
- nameToIdMap.put(name, id);
- idToOwnerMap.put(id, new WeakReference(owner));
- idToNameMap.put(id, name);
- idToTypeMap.put(id, type);
- }
-
- idToValueMap.put(id, value);
-
- return id;
- }
- }
-
- /**
- * Unregisters the variable.
- *
- * @param name
- * the name of the variable.
- * @param owner
- * the Listener for variable changes.
- */
- public void unregisterVariable(String name, VariableOwner owner) {
-
- synchronized (mapLock) {
-
- // Gets the id
- HashMap nameToIdMap = (HashMap) ownerToNameToIdMap.get(owner);
- if (nameToIdMap == null)
- return;
- String id = (String) nameToIdMap.get(name);
- if (id != null)
- return;
-
- // Removes all the mappings
- nameToIdMap.remove(name);
- if (nameToIdMap.isEmpty())
- ownerToNameToIdMap.remove(owner);
- idToNameMap.remove(id);
- idToTypeMap.remove(id);
- idToValueMap.remove(id);
- idToOwnerMap.remove(id);
-
- }
- }
-
- /**
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class ParameterContainer {
-
- /**
- * Constructs the mapping: listener to set of listened parameter names.
- */
- private HashMap parameters = new HashMap();
-
- /**
- * Parameter values.
- */
- private HashMap values = new HashMap();
-
- /**
- * Multipart parser used for parsing the request.
- */
- private ServletMultipartRequest parser = null;
-
- /**
- * Name - Value mapping of parameters that are not variables.
- */
- private HashMap nonVariables = new HashMap();
-
- /**
- * Creates a new parameter container and parse the parameters from the
- * request using GET, POST and POST/MULTIPART parsing.
- *
- * @param req
- * the HTTP request.
- * @throws IOException
- * if the writing failed due to input/output error.
- */
- public ParameterContainer(HttpServletRequest req) throws IOException {
- // Parse GET / POST parameters
- for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
- String paramName = (String) e.nextElement();
- String[] paramValues = req.getParameterValues(paramName);
- addParam(paramName, paramValues);
- }
-
- // Parse multipart variables
- try {
- parser = new ServletMultipartRequest(req,
- MultipartRequest.MAX_READ_BYTES);
- } catch (IllegalArgumentException ignored) {
- parser = null;
- }
-
- if (parser != null) {
- for (Enumeration e = parser.getFileParameterNames(); e
- .hasMoreElements();) {
- String paramName = (String) e.nextElement();
- addParam(paramName, null);
- }
- for (Enumeration e = parser.getParameterNames(); e
- .hasMoreElements();) {
- String paramName = (String) e.nextElement();
- Enumeration val = parser.getURLParameters(paramName);
-
- // Create a linked list from enumeration to calculate
- // elements
- LinkedList l = new LinkedList();
- while (val.hasMoreElements())
- l.addLast(val.nextElement());
-
- // String array event constructor
- String[] s = new String[l.size()];
- Iterator i = l.iterator();
- for (int j = 0; j < s.length; j++)
- s[j] = (String) i.next();
-
- addParam(paramName, s);
- }
- }
-
- }
-
- /**
- * Adds the parameter to container.
- *
- * @param name
- * the name of the parameter.
- * @param value
- */
- private void addParam(String name, String[] value) {
-
- // Support name="set:name=value" value="ignored" notation
- if (name.startsWith("set:")) {
- int equalsIndex = name.indexOf('=');
- value[0] = name.substring(equalsIndex + 1, name.length());
- name = name.substring(4, equalsIndex);
- String[] curVal = (String[]) values.get(name);
- if (curVal != null) {
- String[] newVal = new String[1 + curVal.length];
- newVal[curVal.length] = value[0];
- for (int i = 0; i < curVal.length; i++)
- newVal[i] = curVal[i];
- value = newVal;
-
- // Special case - if the set:-method is used for
- // declaring array of length 2, where either of the
- // following conditions are true:
- // - the both items are the same
- // - the both items have the same length and
- // - the items only differ on last character
- // - second last character is '.'
- // - last char of one string is 'x' and other is 'y'
- // Browser is unporposely modifying the name.
- if (value.length == 2
- && value[0].length() == value[1].length()) {
- boolean same = true;
- for (int i = 0; i < value[0].length() - 1 && same; i++)
- if (value[0].charAt(i) != value[1].charAt(i))
- same = false;
- if (same
- && ((value[0].charAt(value[0].length() - 1) == 'x' && value[1]
- .charAt(value[1].length() - 1) == 'y') || (value[0]
- .charAt(value[0].length() - 1) == 'y' && value[1]
- .charAt(value[1].length() - 1) == 'x'))) {
- value = new String[] { value[0].substring(0,
- value[1].length() - 2) };
- } else if (same && value[0].equals(value[1]))
- value = new String[] { value[0] };
- }
-
- // Special case - if the set:-method is used for
- // declaring array of length 3, where all of the
- // following conditions are true:
- // - two last items have the same length
- // - the first item is 2 chars shorter
- // - the longer items only differ on last character
- // - the shortest item is a prefix of the longer ones
- // - second last character of longer ones is '.'
- // - last char of one long string is 'x' and other is 'y'
- // Browser is unporposely modifying the name. (Mozilla,
- // Firefox, ..)
- if (value.length == 3
- && value[1].length() == value[2].length()
- && value[0].length() + 2 == value[1].length()) {
- boolean same = true;
- for (int i = 0; i < value[1].length() - 1 && same; i++)
- if (value[2].charAt(i) != value[1].charAt(i))
- same = false;
- for (int i = 0; i < value[0].length() && same; i++)
- if (value[0].charAt(i) != value[1].charAt(i))
- same = false;
- if (same
- && (value[2].charAt(value[2].length() - 1) == 'x' && value[1]
- .charAt(value[1].length() - 1) == 'y')
- || (value[2].charAt(value[2].length() - 1) == 'y' && value[1]
- .charAt(value[1].length() - 1) == 'x')) {
- value = new String[] { value[0] };
- }
- }
-
- }
- }
-
- // Support for setting arrays in format
- // set-array:name=value1,value2,value3,...
- else if (name.startsWith("set-array:")) {
- int equalsIndex = name.indexOf('=');
- if (equalsIndex < 0)
- return;
-
- StringTokenizer commalist = new StringTokenizer(name
- .substring(equalsIndex + 1), ",");
- name = name.substring(10, equalsIndex);
- String[] curVal = (String[]) values.get(name);
- ArrayList elems = new ArrayList();
-
- // Adds old values if present.
- if (curVal != null) {
- for (int i = 0; i < curVal.length; i++)
- elems.add(curVal[i]);
- }
- while (commalist.hasMoreTokens()) {
- String token = commalist.nextToken();
- if (token != null && token.length() > 0)
- elems.add(token);
- }
- value = new String[elems.size()];
- for (int i = 0; i < value.length; i++)
- value[i] = (String) elems.get(i);
-
- }
-
- // Support name="array:name" value="val1,val2,val3" notation
- // All the empty elements are ignored
- else if (name.startsWith("array:")) {
-
- name = name.substring(6);
- StringTokenizer commalist = new StringTokenizer(value[0], ",");
- String[] curVal = (String[]) values.get(name);
- ArrayList elems = new ArrayList();
-
- // Adds old values if present.
- if (curVal != null) {
- for (int i = 0; i < curVal.length; i++)
- elems.add(curVal[i]);
- }
- while (commalist.hasMoreTokens()) {
- String token = commalist.nextToken();
- if (token != null && token.length() > 0)
- elems.add(token);
- }
- value = new String[elems.size()];
- for (int i = 0; i < value.length; i++)
- value[i] = (String) elems.get(i);
- }
-
- // Support declaring variables with name="declare:name"
- else if (name.startsWith("declare:")) {
- name = name.substring(8);
- value = (String[]) values.get(name);
- if (value == null)
- value = new String[0];
- }
-
- // Gets the owner
- WeakReference ref = (WeakReference) idToOwnerMap.get(name);
- VariableOwner owner = null;
- if (ref != null)
- owner = (VariableOwner) ref.get();
-
- // Adds the parameter to mapping only if they have owners
- if (owner != null) {
- Set p = (Set) parameters.get(owner);
- if (p == null)
- parameters.put(owner, p = new HashSet());
- p.add(name);
- if (value != null)
- values.put(name, value);
- }
-
- // If the owner can not be found
- else {
-
- // If parameter has been mapped before, remove the old owner
- // mapping
- if (ref != null) {
-
- // The owner has been destroyed, so we remove the mappings
- idToNameMap.remove(name);
- idToOwnerMap.remove(name);
- idToTypeMap.remove(name);
- idToValueMap.remove(name);
- }
-
- // Adds the parameter to set of non-variables
- nonVariables.put(name, value);
- }
-
- }
-
- /**
- * Gets the set of all parameters connected to given variable owner.
- *
- * @param owner
- * the Listener for variable changes.
- * @return the set of all parameters connected to variable owner.
- */
- public Set getParameters(VariableOwner owner) {
- if (owner == null)
- return null;
- return (Set) parameters.get(owner);
- }
-
- /**
- * Gets the set of all variable owners owning parameters in this
- * request.
- *
- * @return
- */
- public Set getOwners() {
- return parameters.keySet();
- }
-
- /**
- * Gets the value of a parameter.
- *
- * @param parameterName
- * the name of the parameter.
- * @return the value of the parameter.
- */
- public String[] getValue(String parameterName) {
- return (String[]) values.get(parameterName);
- }
-
- /**
- * Gets the servlet multipart parser.
- *
- * @return the parser.
- */
- public ServletMultipartRequest getParser() {
- return parser;
- }
-
- /**
- * Gets the name - value[] mapping of non variable paramteres.
- *
- * @return
- */
- public Map getNonVariables() {
- return nonVariables;
- }
- }
-
- /**
- * Handles all variable changes in this request.
- *
- * @param req
- * the Http request to handle.
- * @param errorListener
- * If the list is non null, only the listed listeners are served.
- * Otherwise all the listeners are served.
- * @return Name to Value[] mapping of unhandled variables.
- * @throws IOException
- * if the writing failed due to input/output error.
- */
- public Map handleVariables(HttpServletRequest req,
- Terminal.ErrorListener errorListener) throws IOException {
-
- // Gets the parameters
- ParameterContainer parcon = new ParameterContainer(req);
-
- // Sorts listeners to dependency order
- List listeners = getDependencySortedListenerList(parcon.getOwners());
-
- // Handles all parameters for all listeners
- while (!listeners.isEmpty()) {
- VariableOwner listener = (VariableOwner) listeners.remove(0);
- boolean changed = false; // Has any of this owners variabes
- // changed
- // Handle all parameters for listener
- Set params = parcon.getParameters(listener);
- if (params != null) { // Name value mapping
- Map variables = new HashMap();
- for (Iterator pi = params.iterator(); pi.hasNext();) {
- // Gets the name of the parameter
- String param = (String) pi.next();
- // Extracts more information about the parameter
- String varName = (String) idToNameMap.get(param);
- Class varType = (Class) idToTypeMap.get(param);
- Object varOldValue = idToValueMap.get(param);
- if (varName == null || varType == null)
- Log
- .warn("VariableMap: No variable found for parameter "
- + param
- + " ("
- + varName
- + ","
- + listener + ")");
- else {
-
- ServletMultipartRequest parser = parcon.getParser();
-
- // Upload events
- if (varType.equals(UploadStream.class)) {
- if (parser != null
- && parser.getFileParameter(param,
- MultipartRequest.FILENAME) != null) {
- String filename = (String) parser
- .getFileParameter(param,
- MultipartRequest.FILENAME);
- String contentType = (String) parser
- .getFileParameter(param,
- MultipartRequest.CONTENT_TYPE);
- UploadStream upload = new HttpUploadStream(
- varName, parser.getFileContents(param),
- filename, contentType);
- variables.put(varName, upload);
- changed = true;
- }
- }
-
- // Normal variable change events
- else {
- // First try to parse the event without multipart
- String[] values = parcon.getValue(param);
- if (values != null) {
-
- if (varType.equals(String[].class)) {
- variables.put(varName, values);
- changed |= (!Arrays.equals(values,
- (String[]) varOldValue));
- } else {
- try {
- if (values.length == 1) {
- Object val = convert(varType,
- values[0]);
- variables.put(varName, val);
- changed |= ((val == null && varOldValue != null) || (val != null && !val
- .equals(varOldValue)));
- } else if (values.length == 0
- && varType
- .equals(Boolean.class)) {
- Object val = new Boolean(false);
- variables.put(varName, val);
- changed |= (!val
- .equals(varOldValue));
- } else {
- Log.warn("Empty variable '"
- + varName + "' of type "
- + varType.toString());
- }
-
- } catch (java.lang.ClassCastException e) {
- Log
- .except(
- "WebVariableMap conversion exception",
- e);
- errorListener
- .terminalError(new TerminalErrorImpl(
- e));
- }
- }
- }
- }
- }
- }
-
- // Do the valuechange if the listener is enabled
- if (listener.isEnabled() && changed) {
- try {
- listener.changeVariables(req, variables);
- } catch (Throwable t) {
- // Notify the error listener
- errorListener.terminalError(new VariableOwnerErrorImpl(
- listener, t));
- }
- }
- }
- }
-
- return parcon.getNonVariables();
- }
-
- /**
- * Implementation of VariableOwner.Error interface.
- */
- public class TerminalErrorImpl implements Terminal.ErrorEvent {
- private Throwable throwable;
-
- /**
- *
- * @param throwable
- */
- private TerminalErrorImpl(Throwable throwable) {
- this.throwable = throwable;
- }
-
- /**
- * Gets the contained throwable.
- *
- * @see com.itmill.toolkit.terminal.Terminal.ErrorEvent#getThrowable()
- */
- public Throwable getThrowable() {
- return this.throwable;
- }
-
- }
-
- /**
- * Implementation of VariableOwner.Error interface.
- */
- public class VariableOwnerErrorImpl extends TerminalErrorImpl implements
- VariableOwner.ErrorEvent {
-
- private VariableOwner owner;
-
- /**
- *
- * @param owner
- * the Listener for variable changes.
- * @param throwable
- */
- private VariableOwnerErrorImpl(VariableOwner owner, Throwable throwable) {
- super(throwable);
- this.owner = owner;
- }
-
- /**
- * Gets the source VariableOwner.
- *
- * @see com.itmill.toolkit.terminal.VariableOwner.ErrorEvent#getVariableOwner()
- */
- public VariableOwner getVariableOwner() {
- return this.owner;
- }
-
- }
-
- /**
- * Resolves the VariableOwners needed from the request and sort them to
- * assure that the dependencies are met (as well as possible).
- *
- * @param listeners
- * @return List of variable list changers, that are needed for handling all
- * the variables in the request
- */
- private List getDependencySortedListenerList(Set listeners) {
-
- LinkedList resultNormal = new LinkedList();
- LinkedList resultImmediate = new LinkedList();
-
- // Go trough the listeners and either add them to result or resolve
- // their dependencies
- HashMap deepdeps = new HashMap();
- LinkedList unresolved = new LinkedList();
- for (Iterator li = listeners.iterator(); li.hasNext();) {
-
- VariableOwner listener = (VariableOwner) li.next();
- if (listener != null) {
- Set dependencies = listener.getDirectDependencies();
-
- // The listeners with no dependencies are added to the front of
- // the
- // list directly
- if (dependencies == null || dependencies.isEmpty()) {
- if (listener.isImmediate())
- resultImmediate.addFirst(listener);
- else
- resultNormal.addFirst(listener);
- }
-
- // Resolve deep dependencies for the listeners with dependencies
- // (the listeners will be added to the end of results in correct
- // dependency order later). Also the dependencies of all the
- // depended listeners are resolved.
- else if (deepdeps.get(listener) == null) {
-
- // Set the fifo for unresolved parents to contain only the
- // listener to be resolved
- unresolved.clear();
- unresolved.add(listener);
-
- // Resolve dependencies
- HashSet tmpdeepdeps = new HashSet();
- while (!unresolved.isEmpty()) {
-
- VariableOwner l = (VariableOwner) unresolved
- .removeFirst();
- if (!tmpdeepdeps.contains(l)) {
- tmpdeepdeps.add(l);
- if (deepdeps.containsKey(l)) {
- tmpdeepdeps.addAll((Set) deepdeps.get(l));
- } else {
- Set deps = l.getDirectDependencies();
- if (deps != null && !deps.isEmpty())
- for (Iterator di = deps.iterator(); di
- .hasNext();) {
- Object d = di.next();
- if (d != null
- && !tmpdeepdeps.contains(d))
- unresolved.addLast(d);
- }
- }
- }
- }
-
- tmpdeepdeps.remove(listener);
- deepdeps.put(listener, tmpdeepdeps);
- }
- }
- }
-
- // Adds the listeners with dependencies in sane order to the result
- for (Iterator li = deepdeps.keySet().iterator(); li.hasNext();) {
- VariableOwner l = (VariableOwner) li.next();
- boolean immediate = l.isImmediate();
-
- // Adds each listener after the last depended listener already in
- // the list
- int index = -1;
- for (Iterator di = ((Set) deepdeps.get(l)).iterator(); di.hasNext();) {
- int k;
- Object depended = di.next();
- if (immediate) {
- k = resultImmediate.lastIndexOf(depended);
- } else {
- k = resultNormal.lastIndexOf(depended);
- }
- if (k > index)
- index = k;
- }
- if (immediate) {
- resultImmediate.add(index + 1, l);
- } else {
- resultNormal.add(index + 1, l);
- }
- }
-
- // Appends immediate listeners to normal listeners
- // This way the normal handlers are always called before
- // immediate ones
- resultNormal.addAll(resultImmediate);
- return resultNormal;
- }
-}
+++ /dev/null
-/* *************************************************************************
-
- IT Mill Toolkit
-
- Development of Browser User Interfaces Made Easy
-
- Copyright (C) 2000-2006 IT Mill Ltd
-
- *************************************************************************
-
- This product is distributed under commercial license that can be found
- from the product package on license.pdf. Use of this product might
- require purchasing a commercial license from IT Mill Ltd. For guidelines
- on usage, see licensing-guidelines.html
-
- *************************************************************************
-
- For more information, contact:
-
- IT Mill Ltd phone: +358 2 4802 7180
- Ruukinkatu 2-4 fax: +358 2 4802 7181
- 20540, Turku email: info@itmill.com
- Finland company www: www.itmill.com
-
- Primary source for information and releases: www.itmill.com
-
- ********************************************************************** */
-
-package com.itmill.toolkit.terminal.gwt.server;
-
-import com.itmill.toolkit.terminal.Terminal;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Locale;
-
-/**
- * Web browser terminal type.
- *
- * This class implements web browser properties, which declare the features of
- * the web browser.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public class WebBrowser implements Terminal {
-
- private static WebBrowser DEFAULT = new WebBrowser();
-
- /**
- * Content type.
- */
- private String contentType = "text/html; charset=utf-8";
-
- /**
- * Holds the collection of accepted locales.
- */
- private Collection locales = new ArrayList();
-
- /**
- * Holds value of property browserApplication.
- */
- private String browserApplication = null;
-
- /**
- * Should the client side checkking be done.
- */
- private boolean performClientCheck = true;
-
- /**
- * Holds value for property isClientSideChecked.
- */
- private boolean clientSideChecked = false;
-
- /**
- * Holds value of property javaScriptVersion.
- */
- private JavaScriptVersion javaScriptVersion = JAVASCRIPT_UNCHECKED;
-
- /**
- * Holds value of property javaEnabled.
- */
- private boolean javaEnabled = false;
-
- /**
- * Holds value of property frameSupport.
- */
- private boolean frameSupport = false;
-
- /**
- * Holds value of property markup version.
- */
- private MarkupVersion markupVersion = MARKUP_HTML_3_2;
-
- /**
- * Pixel width of the terminal screen.
- */
- private int screenWidth = -1;
-
- /**
- * Pixel height of the terminal screen.
- */
- private int screenHeight = -1;
-
- /**
- * Constuctor with some autorecognition capabilities Retrieves all
- * capability information reported in http request headers:
- * <ul>
- * <li>User web browser (User-Agent)</li>
- * <li>Supported locale(s)</li>
- * </ul>
- */
-
- /**
- * Constructor WebBrowserType. Creates a default WebBrowserType instance.
- */
- public WebBrowser() {
- }
-
- /**
- * Gets the name of the default theme.
- *
- * @return the Name of the terminal window.
- */
- public String getDefaultTheme() {
- return ApplicationServlet.DEFAULT_THEME;
- }
-
- /**
- * Gets the name and version of the web browser application. This is the
- * version string reported by the web-browser in http headers.
- *
- * @return the Web browser application.
- */
- public String getBrowserApplication() {
- return this.browserApplication;
- }
-
- /**
- * Gets the version of the supported Java Script by the browser.
- *
- * <code>Null</code> if the Java Script is not supported.
- *
- * @return the Version of the supported Java Script.
- */
- public JavaScriptVersion getJavaScriptVersion() {
- return this.javaScriptVersion;
- }
-
- /**
- * Does the browser support frames ?
- *
- * @return <code>true</code> if the browser supports frames, otherwise
- * <code>false</code>.
- */
- public boolean isFrameSupport() {
- return this.frameSupport;
- }
-
- /**
- * Sets the browser frame support.
- *
- * @param frameSupport
- * True if the browser supports frames, False if not.
- */
- public void setFrameSupport(boolean frameSupport) {
- this.frameSupport = frameSupport;
- }
-
- /**
- * Gets the supported markup language.
- *
- * @return the Supported markup language
- */
- public MarkupVersion getMarkupVersion() {
- return this.markupVersion;
- }
-
- /**
- * Gets the height of the terminal window in pixels.
- *
- * @return the Height of the terminal window.
- */
- public int getScreenHeight() {
- return this.screenHeight;
- }
-
- /**
- * Gets the width of the terminal window in pixels.
- *
- * @return the Width of the terminal window.
- */
- public int getScreenWidth() {
- return this.screenWidth;
- }
-
- /**
- * Gets the default locale requested by the browser.
- *
- * @return the Default locale.
- */
- public Locale getDefaultLocale() {
- if (this.locales.isEmpty())
- return null;
- return (Locale) this.locales.iterator().next();
- }
-
- /**
- * Hash code composed of the properties of the web browser type.
- *
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return toString().hashCode();
- }
-
- /**
- * Tests the equality of the properties for two web browser types.
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (obj != null && obj instanceof WebBrowser) {
- return toString().equals(obj.toString());
- }
- return false;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
-
- String localeString = "[";
- for (Iterator i = this.locales.iterator(); i.hasNext(); localeString += ",") {
- localeString += ((Locale) i.next()).toString();
- }
- localeString += "]";
-
- // Returns catenation of the properties
- return "Browser:" + this.browserApplication + ", " + "Locales:"
- + localeString + ", " + "Frames:" + this.frameSupport + ", "
- + "JavaScript:" + this.javaScriptVersion + ", " + "Java: "
- + this.javaEnabled + ", " + "Markup:" + this.markupVersion
- + ", " + "Height:" + this.screenHeight + ", " + "Width:"
- + this.screenWidth + ", ClientCheck:" + this.performClientCheck
- + ", ClientCheckDone:" + this.clientSideChecked;
- }
-
- /**
- * Gets the preferred content type.
- *
- * @return the content type.
- */
- public String getContentType() {
- return contentType;
- }
-
- /**
- * Checks if this type supports also given browser.
- *
- * @param browser
- * the browser type.
- * @return true if this type matches the given browser.
- */
- public boolean supports(String browser) {
- return this.getBrowserApplication().indexOf(browser) >= 0;
- }
-
- /**
- * Checks if this type supports given markup language version.
- *
- * @param html
- * the markup language version.
- * @return <code>true</ocde> if this type supports the given markup version,otherwise <code>false</code>.
- */
- public boolean supports(MarkupVersion html) {
- return this.getMarkupVersion().supports(html);
- }
-
- /**
- * Checks if this type supports given javascript version.
- *
- * @param js
- * the javascript version to check for.
- * @return true if this type supports the given javascript version.
- */
- public boolean supports(JavaScriptVersion js) {
- return this.getJavaScriptVersion().supports(js);
- }
-
- /**
- * Parses HTML version from string.
- *
- * @param html
- * @return HTMLVersion instance.
- */
- private MarkupVersion doParseHTMLVersion(String html) {
- for (int i = 0; i < MARKUP_VERSIONS.length; i++) {
- if (MARKUP_VERSIONS[i].name.equals(html))
- return MARKUP_VERSIONS[i];
- }
- return MARKUP_UNKNOWN;
- }
-
- /**
- * Parses JavaScript version from string.
- *
- * @param js
- * the javascript version to check for.
- * @return HTMLVersion instance.
- */
- private JavaScriptVersion doParseJavaScriptVersion(String js) {
- for (int i = 0; i < JAVASCRIPT_VERSIONS.length; i++) {
- if (JAVASCRIPT_VERSIONS[i].name.toLowerCase().startsWith(
- js.toLowerCase()))
- return JAVASCRIPT_VERSIONS[i];
- }
- return JAVASCRIPT_NONE;
- }
-
- /**
- * Parses HTML version from string.
- *
- * @param html
- * @return the HTMLVersion instance.
- */
- public static MarkupVersion parseHTMLVersion(String html) {
- return DEFAULT.doParseHTMLVersion(html);
- }
-
- /**
- * Parse JavaScript version from string.
- *
- * @param js
- * the javascript version to check for.
- * @return the HTMLVersion instance.
- */
- public static JavaScriptVersion parseJavaScriptVersion(String js) {
- return DEFAULT.doParseJavaScriptVersion(js);
- }
-
- /**
- * Gets the client side cheked property. Certain terminal features can only
- * be detected at client side. This property indicates if the client side
- * detections have been performed for this type.
- *
- * @return <code>true</code> if client has sent information about its
- * properties. Default is <code>false</code>.
- */
- public boolean isClientSideChecked() {
- return this.clientSideChecked;
- }
-
- /**
- * Sets the client side checked property. Certain terminal features can only
- * be detected at client side. This property indicates if the client side
- * detections have been performed for this type.
- *
- * @param value
- * true if client has sent information about its properties,
- * false otherweise.
- */
- public void setClientSideChecked(boolean value) {
- this.clientSideChecked = value;
- }
-
- /**
- * Should the client features be checked using remote scripts. Should the
- * client side terminal feature check be performed.
- *
- * @return <code>true</code> if client side checking should be performed
- * for this terminal type. Default is <code>false</code>.
- */
- public boolean performClientCheck() {
- return this.performClientCheck;
- }
-
- /**
- * Should the client features be checked using remote scripts.
- *
- * @param value
- * @return <code>true</code> if client side checking should be performed
- * for this terminal type. Default <code>false</code>.
- */
- public void performClientCheck(boolean value) {
- this.performClientCheck = value;
- }
-
- /**
- * Checks if web browser supports Java.
- *
- * @return <code>true<code> if the browser supports java otherwise <code>false</code>.
- */
- public boolean isJavaEnabled() {
- return javaEnabled;
- }
-
- /**
- * Returns the locales supported by the web browser.
- *
- * @return the Collection.
- */
- public Collection getLocales() {
- return locales;
- }
-
- /**
- * Sets the browser application. This corresponds to User-Agent HTTP header.
- *
- * @param browserApplication
- * the browserApplication to set.
- */
- public void setBrowserApplication(String browserApplication) {
- this.browserApplication = browserApplication;
- }
-
- /**
- * Sets the default content type. Default is <code>text/html</code>
- *
- * @param contentType
- * the contentType to set.
- */
- public void setContentType(String contentType) {
- this.contentType = contentType;
- }
-
- /**
- * Sets the java enabled property.
- *
- * @param javaEnabled
- * the javaEnabled to set.
- */
- public void setJavaEnabled(boolean javaEnabled) {
- this.javaEnabled = javaEnabled;
- }
-
- /**
- * Sets the JavaScript version.
- *
- * @param javaScriptVersion
- * the JavaScript version to set.
- */
- public void setJavaScriptVersion(JavaScriptVersion javaScriptVersion) {
- this.javaScriptVersion = javaScriptVersion;
- }
-
- /**
- * Sets the markup language version.
- *
- * @param markupVersion
- * the markup language version to set.
- */
- public void setMarkupVersion(MarkupVersion markupVersion) {
- this.markupVersion = markupVersion;
- }
-
- /**
- * Sets the screen height.
- *
- * @param screenHeight
- * the screen height to set in pixels.
- */
- public void setScreenHeight(int screenHeight) {
- this.screenHeight = screenHeight;
- }
-
- /**
- * Sets the screen width.
- *
- * @param screenWidth
- * the screenWidth to set in pixels.
- */
- public void setScreenWidth(int screenWidth) {
- this.screenWidth = screenWidth;
- }
-
- /*
- * Consts defining the supported markup language versions @author IT Mill
- * Ltd.
- *
- * @version @VERSION@
- * @since 3.0
- */
- public class MarkupVersion {
- private String name;
-
- private int order;
-
- /**
- * Returns <code>true</code> if and only if the argument is not
- * <code>null</code> and is a Boolean object that represents the same
- * boolean value as this object.
- *
- * @param obj
- * the object to compare with.
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object obj) {
- if (obj != null && obj instanceof MarkupVersion)
- return name.equals(((MarkupVersion) obj).name);
- return false;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return name;
- }
-
- /**
- *
- * @param name
- * @param order
- */
- private MarkupVersion(String name, int order) {
- this.name = name;
- this.order = order;
- }
-
- /**
- * Checks the compability with other HTML version.
- *
- * @param other
- * the HTML version.
- * @return <code>true</code> if this is compatible with the other,
- * otherwise <code>false</code>.
- */
- public boolean supports(MarkupVersion other) {
- return (this.order >= other.order);
- }
-
- }
-
- public static final MarkupVersion MARKUP_UNKNOWN = DEFAULT.new MarkupVersion(
- "HTML unknown", 0);
-
- public static final MarkupVersion MARKUP_HTML_2_0 = DEFAULT.new MarkupVersion(
- "HTML 2.0", 20);
-
- public static final MarkupVersion MARKUP_HTML_3_2 = DEFAULT.new MarkupVersion(
- "HTML 3.2", 32);
-
- public static final MarkupVersion MARKUP_HTML_4_0 = DEFAULT.new MarkupVersion(
- "HTML 4.0", 40);
-
- public static final MarkupVersion MARKUP_XHTML_1_0 = DEFAULT.new MarkupVersion(
- "XHTML 1.0", 110);
-
- public static final MarkupVersion MARKUP_XHTML_2_0 = DEFAULT.new MarkupVersion(
- "XHTML 2.0", 120);
-
- public static final MarkupVersion MARKUP_WML_1_0 = DEFAULT.new MarkupVersion(
- "WML 1.0", 10);
-
- public static final MarkupVersion MARKUP_WML_1_1 = DEFAULT.new MarkupVersion(
- "WML 1.1", 11);
-
- public static final MarkupVersion MARKUP_WML_1_2 = DEFAULT.new MarkupVersion(
- "WML 1.2", 12);
-
- public static final MarkupVersion[] MARKUP_VERSIONS = new MarkupVersion[] {
- MARKUP_UNKNOWN, MARKUP_HTML_2_0, MARKUP_HTML_3_2, MARKUP_HTML_4_0,
- MARKUP_XHTML_1_0, MARKUP_XHTML_2_0, MARKUP_WML_1_0, MARKUP_WML_1_1,
- MARKUP_WML_1_2 };
-
- /*
- * Consts defining the supported JavaScript versions @author IT Mill Ltd.
- *
- * @version @VERSION@
- * @since 3.0
- */
- public class JavaScriptVersion {
- private String name;
-
- private int order;
-
- /**
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object obj) {
- if (obj != null && obj instanceof JavaScriptVersion)
- return name.equals(((JavaScriptVersion) obj).name);
- return false;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return name;
- }
-
- /**
- *
- * @param name
- * @param order
- */
- private JavaScriptVersion(String name, int order) {
- this.name = name;
- this.order = order;
- }
-
- /**
- * Checks the compability with other JavaScript version. Use this like:
- * <code>boolean isEcma = someVersion.supports(ECMA_262);</code>
- *
- * @param other
- * the java script version.
- * @return <code>true</code> if this supports the other, otherwise
- * <code>false</code>.
- */
- public boolean supports(JavaScriptVersion other) {
-
- // ECMA-262 support compare
- if (other.equals(ECMA_262)) {
-
- // JScript over 5.0 support ECMA-262
- if (this.order >= 100) {
- return (this.order >= JSCRIPT_5_0.order);
- } else {
- return (this.order >= JAVASCRIPT_1_3.order);
- }
- }
-
- // JavaScript version compare
- else if (this.order < 100 && other.order < 100) {
- return (this.order >= other.order);
- }
-
- // JScript version compare
- else if (this.order >= 100 && other.order >= 100) {
- return (this.order >= other.order);
- }
-
- return false;
-
- }
-
- }
-
- public static final JavaScriptVersion JAVASCRIPT_UNCHECKED = DEFAULT.new JavaScriptVersion(
- "JavaScript unchecked", -1);
-
- public static final JavaScriptVersion JAVASCRIPT_NONE = DEFAULT.new JavaScriptVersion(
- "JavaScript none", -1);
-
- public static final JavaScriptVersion JAVASCRIPT_1_0 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.0", 10);
-
- public static final JavaScriptVersion JAVASCRIPT_1_1 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.1", 11);
-
- public static final JavaScriptVersion JAVASCRIPT_1_2 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.2", 12);
-
- public static final JavaScriptVersion JAVASCRIPT_1_3 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.3", 13);
-
- public static final JavaScriptVersion JAVASCRIPT_1_4 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.4", 14);
-
- public static final JavaScriptVersion JAVASCRIPT_1_5 = DEFAULT.new JavaScriptVersion(
- "JavaScript 1.5", 15);
-
- public static final JavaScriptVersion JSCRIPT_1_0 = DEFAULT.new JavaScriptVersion(
- "JScript 1.0", 110);
-
- public static final JavaScriptVersion JSCRIPT_3_0 = DEFAULT.new JavaScriptVersion(
- "JScript 3.0", 130);
-
- public static final JavaScriptVersion JSCRIPT_4_0 = DEFAULT.new JavaScriptVersion(
- "JScript 4.0", 140);
-
- public static final JavaScriptVersion JSCRIPT_5_0 = DEFAULT.new JavaScriptVersion(
- "JScript 5.0", 150);
-
- public static final JavaScriptVersion JSCRIPT_5_1 = DEFAULT.new JavaScriptVersion(
- "JScript 5.1", 151);
-
- public static final JavaScriptVersion JSCRIPT_5_5 = DEFAULT.new JavaScriptVersion(
- "JScript 5.5", 155);
-
- public static final JavaScriptVersion JSCRIPT_5_6 = DEFAULT.new JavaScriptVersion(
- "JScript 5.6", 156);
-
- public static final JavaScriptVersion JSCRIPT_5_7 = DEFAULT.new JavaScriptVersion(
- "JScript 5.7", 157);
-
- public static final JavaScriptVersion ECMA_262 = DEFAULT.new JavaScriptVersion(
- "ECMA-262", 262);
-
- public static final JavaScriptVersion[] JAVASCRIPT_VERSIONS = new JavaScriptVersion[] {
- JAVASCRIPT_UNCHECKED, JAVASCRIPT_NONE, JAVASCRIPT_1_0,
- JAVASCRIPT_1_1, JAVASCRIPT_1_2, JAVASCRIPT_1_3, JAVASCRIPT_1_4,
- JAVASCRIPT_1_5, JSCRIPT_1_0, JSCRIPT_3_0, JSCRIPT_4_0, JSCRIPT_5_0,
- JSCRIPT_5_1, JSCRIPT_5_5, JSCRIPT_5_6, JSCRIPT_5_7, ECMA_262 };
-
-}
+++ /dev/null
-/* *************************************************************************
-
- IT Mill Toolkit
-
- Development of Browser User Interfaces Made Easy
-
- Copyright (C) 2000-2006 IT Mill Ltd
-
- *************************************************************************
-
- This product is distributed under commercial license that can be found
- from the product package on license.pdf. Use of this product might
- require purchasing a commercial license from IT Mill Ltd. For guidelines
- on usage, see licensing-guidelines.html
-
- *************************************************************************
-
- For more information, contact:
-
- IT Mill Ltd phone: +358 2 4802 7180
- Ruukinkatu 2-4 fax: +358 2 4802 7181
- 20540, Turku email: info@itmill.com
- Finland company www: www.itmill.com
-
- Primary source for information and releases: www.itmill.com
-
- ********************************************************************** */
-
-package com.itmill.toolkit.terminal.gwt.server;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-/**
- * The <code>WebBrowserProbe</code> uses JavaScript to determine the
- * capabilities of the client browser.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public class WebBrowserProbe {
-
- private static final String WA_NOSCRIPT = "WA_NOSCRIPT";
-
- private static final String CLIENT_TYPE = "wa_browser";
-
- /**
- * Returns the terminal type from the given session.
- *
- * @param session
- * the HTTP session.
- * @return WebBrowser instance for the given session.
- */
- public static WebBrowser getTerminalType(HttpSession session) {
- if (session != null)
- return (WebBrowser) session.getAttribute(CLIENT_TYPE);
- return null;
- }
-
- /**
- * Sets the terminal type for the given session.
- *
- * @param session
- * the HTTP session.
- * @param terminal
- * the web browser.
- * @return WebBrowser instance for the given session.
- */
- public static void setTerminalType(HttpSession session, WebBrowser terminal) {
- if (session != null)
- session.setAttribute(CLIENT_TYPE, terminal);
- }
-
- /**
- * Handles the client checking.
- *
- * @param request
- * the HTTP request to process.
- * @param parameters
- * the Parameters to be used as defaults.
- * @return <code>true</code> if response should include a probe
- * script,otherwise <code>false</code>.
- * @throws ServletException
- * if an exception has occurred that interferes with the
- * servlet's normal operation.
- */
- public static boolean handleProbeRequest(HttpServletRequest request,
- Map parameters) throws ServletException {
-
- HttpSession s = request.getSession();
- WebBrowser browser = getTerminalType(s);
- if (browser != null) {
-
- // Check if no-script was requested
- if (parameters.containsKey(WA_NOSCRIPT)) {
- String val = ((String[]) parameters.get(WA_NOSCRIPT))[0];
- if (val != null && "1".equals(val)) {
- browser.setJavaScriptVersion(WebBrowser.JAVASCRIPT_NONE);
- browser.setClientSideChecked(true);
- } else {
- // Recheck
- browser.setClientSideChecked(false);
- }
- }
-
- // If client is alredy checked disable further checking
- if (browser.isClientSideChecked())
- return false;
-
- }
-
- // Creates new type based on client parameters
- browser = probe(browser, request, parameters);
- setTerminalType(s, browser);
-
- // Sets client as checked if parameters were found
- if (parameters.containsKey("wa_clientprobe")) {
- String val = ((String[]) parameters.get("wa_clientprobe"))[0];
- browser.setClientSideChecked(val != null && "1".equals(val));
- }
-
- // Include probe script if requested and not alredy probed
- return browser.performClientCheck() && !browser.isClientSideChecked();
-
- }
-
- /**
- * Determines versions based on user agent string.
- *
- * @param agent
- * the HTTP User-Agent request header.
- * @return new WebBrowser instance initialized based on agent features.
- */
- public static WebBrowser probe(String agent) {
- WebBrowser res = new WebBrowser();
- if (agent == null)
- return res;
-
- // Set the agent string
- res.setBrowserApplication(agent);
-
- // Konqueror
- if (agent.indexOf("Konqueror") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_5_6);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- }
-
- // Opera
- else if (agent.indexOf("Opera 3.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_3);
- res.setJavaEnabled(false);
- res.setFrameSupport(true);
- } else if (agent.indexOf("Opera") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_3);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- if (agent.indexOf("Opera/9") >= 0)
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_5);
- }
-
- // OmniWeb
- else if (agent.indexOf("OmniWeb") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_3);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- }
-
- // Mosaic
- else if (agent.indexOf("Mosaic") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_3);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_2_0);
- }
-
- // Lynx
- else if (agent.indexOf("Lynx") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_NONE);
- res.setJavaEnabled(false);
- res.setFrameSupport(true);
- }
-
- // Microsoft Browsers
- // See Microsoft documentation for details:
- // http://msdn.microsoft.com/library/default.asp?url=/library/
- // en-us/script56/html/js56jsoriversioninformation.asp
- else if (agent.indexOf("MSIE 7.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_5_7);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("MSIE 6.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_5_6);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("MSIE 5.5") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_5_5);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("MSIE 5.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_5_0);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("MSIE 4.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_3_0);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("MSIE 3.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JSCRIPT_3_0);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- } else if (agent.indexOf("MSIE 2.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_NONE);
- res.setJavaEnabled(false);
- if (agent.indexOf("Mac") >= 0) {
- res.setFrameSupport(true);
- } else {
- res.setFrameSupport(false);
- }
- }
-
- // Netscape browsers
- else if (agent.indexOf("Netscape6") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_5);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if ((agent.indexOf("Mozilla/4.06") >= 0)
- || (agent.indexOf("Mozilla/4.7") >= 0)) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_3);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- } else if (agent.indexOf("Mozilla/4.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_2);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- } else if (agent.indexOf("Mozilla/3.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_1);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- } else if (agent.indexOf("Mozilla/2.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_0);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- }
-
- // Mozilla Open-Source Browsers
- else if (agent.indexOf("Mozilla/5.") >= 0) {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_1_5);
- res.setJavaEnabled(true);
- res.setFrameSupport(true);
- res.setMarkupVersion(WebBrowser.MARKUP_HTML_4_0);
- }
-
- // Unknown browser
- else {
- res.setJavaScriptVersion(WebBrowser.JAVASCRIPT_UNCHECKED);
- res.setJavaEnabled(false);
- res.setMarkupVersion(WebBrowser.MARKUP_UNKNOWN);
- res.setFrameSupport(false);
- }
-
- return res;
- }
-
- /**
- * Creates new instance of WebBrowser by initializing the values based on
- * user request.
- *
- * @param browser
- * the browser to be updated. If null a new instance is created.
- * @param request
- * the Request to be used as defaults.
- * @param params
- * the Parameters to be used as defaults.
- * @return new WebBrowser instance initialized based on request parameters.
- */
- public static WebBrowser probe(WebBrowser browser,
- HttpServletRequest request, Map params) {
-
- // Initialize defaults based on client features
- WebBrowser res = browser;
- if (res == null) {
- res = probe(request.getHeader("User-Agent"));
- }
-
- // Client locales
- Collection locales = res.getLocales();
- locales.clear();
- for (Enumeration e = request.getLocales(); e.hasMoreElements();) {
- locales.add(e.nextElement());
- }
-
- // Javascript version
- if (params.containsKey("wa_jsversion")) {
- String val = ((String[]) params.get("wa_jsversion"))[0];
- if (val != null) {
- res
- .setJavaScriptVersion(WebBrowser
- .parseJavaScriptVersion(val));
- }
- }
- // Java support
- if (params.containsKey("wa_javaenabled")) {
- String val = ((String[]) params.get("wa_javaenabled"))[0];
- if (val != null) {
- res.setJavaEnabled(Boolean.valueOf(val).booleanValue());
- }
- }
- // Screen width
- if (params.containsKey("wa_screenwidth")) {
- String val = ((String[]) params.get("wa_screenwidth"))[0];
- if (val != null) {
- try {
- res.setScreenWidth(Integer.parseInt(val));
- } catch (NumberFormatException e) {
- res.setScreenWidth(-1);
- }
- }
- }
- // Screen height
- if (params.containsKey("wa_screenheight")) {
- String val = ((String[]) params.get("wa_screenheight"))[0];
- if (val != null) {
- try {
- res.setScreenHeight(Integer.parseInt(val));
- } catch (NumberFormatException e) {
- res.setScreenHeight(-1);
- }
- }
- }
-
- return res;
- }
-}
\ No newline at end of file