[overlord-commits] Overlord SVN: r931 - in bpm-console/trunk: gui/war/src/main/java/org/jboss/bpm/console/client/util and 3 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Mon Jan 25 08:03:42 EST 2010
Author: heiko.braun at jboss.com
Date: 2010-01-25 08:03:41 -0500 (Mon, 25 Jan 2010)
New Revision: 931
Added:
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Authentication.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Preferences.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java
Removed:
bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Authentication.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Preferences.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/UIConstants.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java
bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/regex/
Log:
Further strip down workspace API
Added: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Authentication.java
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Authentication.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Authentication.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,334 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client;
+
+import com.google.gwt.http.client.*;
+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.JSONValue;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
+import org.gwt.mosaic.ui.client.MessageBox;
+import org.jboss.bpm.console.client.util.ConsoleLog;
+import org.jboss.bpm.console.client.util.JSONWalk;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class Authentication
+{
+ private AuthCallback callback;
+
+ private List<String> rolesAssigned = new ArrayList<String>();
+
+ private String sid;
+ private String username;
+ private String password;
+
+ private ConsoleConfig config;
+ private String rolesUrl;
+ private Date loggedInSince;
+
+ public Authentication(ConsoleConfig config, String sessionID, String rolesUrl)
+ {
+ this.config = config;
+ this.sid = sessionID;
+ this.rolesUrl = rolesUrl;
+ this.loggedInSince = new Date();
+ }
+
+ public String getSid()
+ {
+ return sid;
+ }
+
+ public void login(String user, String pass)
+ {
+ this.username = user;
+ this.password = pass;
+
+ String formAction = config.getConsoleServerUrl() + "/rs/identity/secure/j_security_check";
+ RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, formAction);
+ rb.setHeader("Content-Type", "application/x-www-form-urlencoded");
+
+ try
+ {
+ rb.sendRequest("j_username="+user+"&j_password="+pass,
+ new RequestCallback()
+ {
+
+ public void onResponseReceived(Request request, Response response)
+ {
+ ConsoleLog.debug("postLoginCredentials() HTTP "+response.getStatusCode());
+
+ if(response.getText().indexOf("HTTP 401")!=-1) // HACK
+ {
+ if (callback != null)
+ callback.onLoginFailed(request, new Exception("Authentication failed"));
+ else
+ throw new RuntimeException("Unknown exception upon login attempt");
+ }
+ else if(response.getStatusCode()==200) // it's always 200, even when the authentication fails
+ {
+ DeferredCommand.addCommand(
+ new Command()
+ {
+
+ public void execute()
+ {
+ requestAssignedRoles();
+ }
+ }
+ );
+ }
+ }
+
+ public void onError(Request request, Throwable t)
+ {
+ if (callback != null)
+ callback.onLoginFailed(request, new Exception("Authentication failed"));
+ else
+ throw new RuntimeException("Unknown exception upon login attempt");
+ }
+ }
+ );
+ }
+ catch (RequestException e)
+ {
+ ConsoleLog.error("Request error", e);
+ }
+ }
+
+ public Date getLoggedInSince()
+ {
+ return loggedInSince;
+ }
+
+ /**
+ * Login using specific credentials.
+ * This delegates to {@link com.google.gwt.http.client.RequestBuilder#setUser(String)}
+ * and {@link com.google.gwt.http.client.RequestBuilder#setPassword(String)}
+ */
+ private void requestAssignedRoles()
+ {
+ RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, rolesUrl );
+
+ ConsoleLog.debug("Request roles: " + rb.getUrl());
+
+ /*if (user != null && pass != null)
+ {
+ rb.setUser(user);
+ rb.setPassword(pass);
+
+ if (!GWT.isScript()) // hosted mode only
+ {
+ rb.setHeader("xtest-user", user);
+ rb.setHeader("xtest-pass", pass); // NOTE: This is plaintext, use for testing only
+ }
+ }*/
+
+ try
+ {
+ rb.sendRequest(null,
+ new RequestCallback()
+ {
+
+ public void onResponseReceived(Request request, Response response)
+ {
+ ConsoleLog.debug("requestAssignedRoles() HTTP "+response.getStatusCode());
+
+ // parse roles
+ if (200 == response.getStatusCode())
+ {
+ rolesAssigned = Authentication.parseRolesAssigned(response.getText());
+ if (callback != null) callback.onLoginSuccess(request, response);
+ }
+ else
+ {
+ onError(request, new Exception(response.getText()));
+ }
+ }
+
+ public void onError(Request request, Throwable t)
+ {
+ // auth failed
+ // Couldn't connect to server (could be timeout, SOP violation, etc.)
+ if (callback != null)
+ callback.onLoginFailed(request, t);
+ else
+ throw new RuntimeException("Unknown exception upon login attempt", t);
+ }
+ });
+ }
+
+ catch (RequestException e1)
+ {
+ // Couldn't connect to server
+ throw new RuntimeException("Unknown error upon login attempt", e1);
+ }
+ }
+
+
+ public void setCallback(AuthCallback callback)
+ {
+ this.callback = callback;
+ }
+
+ private native void reload() /*-{
+ $wnd.location.reload();
+ }-*/;
+
+ public static void logout(final ConsoleConfig conf)
+ {
+ RequestBuilder rb = new RequestBuilder(
+ RequestBuilder.POST,
+ conf.getConsoleServerUrl()+"/rs/identity/sid/invalidate"
+ );
+
+ try
+ {
+ rb.sendRequest(null, new RequestCallback()
+ {
+ public void onResponseReceived(Request request, Response response)
+ {
+ ConsoleLog.debug("logout() HTTP "+response.getStatusCode());
+
+ if(response.getStatusCode()!=200)
+ {
+ ConsoleLog.error(response.getText());
+ }
+ }
+
+ public void onError(Request request, Throwable t)
+ {
+ ConsoleLog.error("Failed to invalidate session", t);
+ }
+ });
+ }
+ catch (RequestException e)
+ {
+ ConsoleLog.error("Request error", e);
+ }
+ }
+
+ public void logoutAndReload()
+ {
+ RequestBuilder rb = new RequestBuilder(
+ RequestBuilder.POST,
+ config.getConsoleServerUrl()+"/rs/identity/sid/invalidate"
+ );
+
+ try
+ {
+ rb.sendRequest(null, new RequestCallback()
+ {
+ public void onResponseReceived(Request request, Response response)
+ {
+ ConsoleLog.debug("logoutAndReload() HTTP "+response.getStatusCode());
+ resetState();
+ reload();
+ }
+
+ public void onError(Request request, Throwable t)
+ {
+ ConsoleLog.error("Failed to invalidate session", t);
+ }
+ });
+ }
+ catch (RequestException e)
+ {
+ ConsoleLog.error("Request error", e);
+ }
+ }
+
+ private void resetState()
+ {
+ sid = null;
+ username = null;
+ password = null;
+ rolesAssigned = new ArrayList<String>();
+ loggedInSince = null;
+ }
+
+ public void handleSessionTimeout()
+ {
+ MessageBox.confirm("Session expired", "Please login again",
+ new MessageBox.ConfirmationCallback()
+ {
+ public void onResult(boolean b)
+ {
+ // regardless of the choice, force login
+ logoutAndReload();
+ }
+ }
+ );
+ }
+
+
+ public interface AuthCallback
+ {
+ void onLoginSuccess(Request request, Response response);
+
+ void onLoginFailed(Request request, Throwable t);
+ }
+
+
+ public List<String> getRolesAssigned()
+ {
+ return rolesAssigned;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public static List<String> parseRolesAssigned(String json)
+ {
+ // parse roles
+ List<String> roles = new ArrayList<String>();
+
+ JSONValue root = JSONParser.parse(json);
+ JSONArray array = JSONWalk.on(root).next("roles").asArray();
+
+ for (int i = 0; i < array.size(); ++i)
+ {
+ JSONObject item = array.get(i).isObject();
+ boolean assigned = JSONWalk.on(item).next("assigned").asBool();
+ String roleName = JSONWalk.on(item).next("role").asString();
+
+ if (assigned)
+ {
+ roles.add(roleName);
+ }
+ }
+
+ return roles;
+ }
+}
Added: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.Dictionary;
+
+/**
+ * Initialize console config from host page (<code>Application.html</code>) variable:
+ * <pre>
+ * var consoleConfig = {
+ * consoleServerUrl: "http://localhost:8080/gwt-console-server",
+ * reportServerUrl: "http://localhost:8080/report",
+ * [...]
+ * };
+ * </pre>
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ * @see com.google.gwt.i18n.client.Dictionary
+ */
+public class ConsoleConfig
+{
+ private String serverWebContext;
+
+ private String overallReportFile;
+ private String processSummaryReportFile;
+ private String instanceSummaryReportFile;
+
+ private String profileName;
+ private String logo;
+
+ private String consoleServerUrl;
+
+ private String defaultEditor;
+
+ public ConsoleConfig(String proxyUrl)
+ {
+ Dictionary theme = Dictionary.getDictionary("consoleConfig");
+ profileName = theme.get("profileName");
+ logo = theme.get("logo");
+
+ serverWebContext = theme.get("serverWebContext");
+
+ overallReportFile = theme.get("overallReportFile");
+ processSummaryReportFile = theme.get("processSummaryReportFile");
+ instanceSummaryReportFile = theme.get("instanceSummaryReportFile");
+
+ defaultEditor = theme.get("defaultEditor");
+
+ if(null==proxyUrl)
+ {
+ // extract host
+ String base = GWT.getHostPageBaseURL();
+ String protocol = base.substring(0, base.indexOf("//")+2);
+ String noProtocol = base.substring(base.indexOf(protocol)+protocol.length(), base.length());
+ String host = noProtocol.substring(0, noProtocol.indexOf("/"));
+
+ // default url
+ consoleServerUrl = protocol + host + serverWebContext;
+ }
+ else
+ {
+ consoleServerUrl = proxyUrl;
+ }
+
+ // features
+
+ }
+
+ public String getHost()
+ {
+ String host = null;
+ if(!GWT.isScript()) // development with proxy
+ {
+ host = consoleServerUrl;
+ }
+ else
+ {
+ String baseUrl = GWT.getModuleBaseURL();
+ host = baseUrl.substring(
+ 0, baseUrl.indexOf("app")
+ );
+ }
+
+ return host;
+ }
+
+ public String getProfileName()
+ {
+ return profileName;
+ }
+
+ public String getLogo()
+ {
+ return logo;
+ }
+
+ public String getDefaultEditor()
+ {
+ return defaultEditor;
+ }
+
+ public String getConsoleServerUrl()
+ {
+ if(consoleServerUrl ==null)
+ throw new RuntimeException("Config not properly setup: console server URL is null");
+ return consoleServerUrl;
+ }
+
+ public void setConsoleServerUrl(String consoleServerUrl)
+ {
+ this.consoleServerUrl = consoleServerUrl;
+ }
+
+ public String getServerWebContext()
+ {
+ return serverWebContext;
+ }
+
+ public void setServerWebContext(String serverWebContext)
+ {
+ this.serverWebContext = serverWebContext;
+ }
+
+ public String getOverallReportFile()
+ {
+ return overallReportFile;
+ }
+
+ public void setOverallReportFile(String overallReportFile)
+ {
+ this.overallReportFile = overallReportFile;
+ }
+
+ public String getProcessSummaryReportFile()
+ {
+ return processSummaryReportFile;
+ }
+
+ public void setProcessSummaryReportFile(String processSummaryReportFile)
+ {
+ this.processSummaryReportFile = processSummaryReportFile;
+ }
+
+ public String getInstanceSummaryReportFile()
+ {
+ return instanceSummaryReportFile;
+ }
+
+ public void setInstanceSummaryReportFile(String instanceSummaryReportFile)
+ {
+ this.instanceSummaryReportFile = instanceSummaryReportFile;
+ }
+}
Added: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Preferences.java
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Preferences.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/Preferences.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client;
+
+import com.google.gwt.user.client.Cookies;
+
+import java.util.Date;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class Preferences
+{
+ // Editor that should be launched at startup
+ public static final String BPM_DEFAULT_TOOL = "bpm.default.tool";
+
+ public static boolean has(String key)
+ {
+ return Preferences.get(key)!=null;
+ }
+
+ public static String get(String key)
+ {
+ return Cookies.getCookie(key);
+ }
+
+ public static void set(String key, String value)
+ {
+ Date twoWeeks = new Date(System.currentTimeMillis()+(2*604800*1000));
+ Cookies.setCookie(key, value, twoWeeks);
+ }
+
+ public static void clear(String key)
+ {
+ Cookies.removeCookie(key);
+ }
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java (from rev 899, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.util;
+
+/**
+ * The maven gwt:test mojo treats any output to stderr as
+ * a test failure. gwt-log does dump some information there,
+ * hence we need to proxy log invocation and be able to disable them at all.
+ * <p/>
+ * If you want to test the application, make sure to lauch it using
+ * {@link org.jboss.bpm.console.client.Application#onModuleLoad2()}.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class ConsoleLog
+{
+ private static boolean enabled = true; // see javadoc comments
+
+ public static void warn(String msg)
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.warn(msg);
+ }
+
+ public static void info(String msg)
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.info(msg);
+ }
+
+ public static void debug(String msg)
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.debug(msg);
+ }
+
+ public static void error(String msg)
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.error(msg);
+ }
+
+ public static void error(String msg, Throwable t)
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.error(msg, t);
+ }
+
+ public static void setUncaughtExceptionHandler()
+ {
+ if (enabled)
+ com.allen_sauer.gwt.log.client.Log.setUncaughtExceptionHandler();
+ }
+
+ public static boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ public static void setEnabled(boolean enabled)
+ {
+ ConsoleLog.enabled = enabled;
+ }
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java (from rev 899, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.bpm.console.client.util;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Date locale support for the {@link SimpleDateParser}. You are encouraged to
+ * extend this class and provide implementations for other locales.
+ * @author <a href="mailto:g.georgovassilis at gmail.com">George Georgovassilis</a>
+ *
+ */
+public class DateLocale {
+ public final static String TOKEN_DAY_OF_WEEK = "E";
+
+ public final static String TOKEN_DAY_OF_MONTH = "d";
+
+ public final static String TOKEN_MONTH = "M";
+
+ public final static String TOKEN_YEAR = "y";
+
+ public final static String TOKEN_HOUR_12 = "h";
+
+ public final static String TOKEN_HOUR_24 = "H";
+
+ public final static String TOKEN_MINUTE = "m";
+
+ public final static String TOKEN_SECOND = "s";
+
+ public final static String TOKEN_MILLISECOND = "S";
+
+ public final static String TOKEN_AM_PM = "a";
+
+ public final static String AM = "AM";
+
+ public final static String PM = "PM";
+
+ public final static List SUPPORTED_DF_TOKENS = Arrays.asList(new String[] {
+ TOKEN_DAY_OF_WEEK, TOKEN_DAY_OF_MONTH, TOKEN_MONTH, TOKEN_YEAR,
+ TOKEN_HOUR_12, TOKEN_HOUR_24, TOKEN_MINUTE, TOKEN_SECOND,
+ TOKEN_AM_PM });
+
+ public String[] MONTH_LONG = { "January", "February", "March", "April",
+ "May", "June", "July", "August", "September", "October",
+ "November", "December" };
+
+ public String[] MONTH_SHORT = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
+
+ public String[] WEEKDAY_LONG = { "Sunday", "Monday", "Tuesday",
+ "Wednesday", "Thursday", "Friday", "Saturday" };
+
+ public String[] WEEKDAY_SHORT = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
+ "Sat" };
+
+ public static String getAM() {
+ return AM;
+ }
+
+ public static String getPM() {
+ return PM;
+ }
+
+ public String[] getWEEKDAY_LONG() {
+ return WEEKDAY_LONG;
+ }
+
+ public String[] getWEEKDAY_SHORT() {
+ return WEEKDAY_SHORT;
+ }
+
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java (from rev 927, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.util;
+
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONException;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONValue;
+
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class JSONWalk
+{
+ private JSONValue root;
+
+
+ private JSONWalk(JSONValue root)
+ {
+ this.root = root;
+ }
+
+ public static JSONWalk on(JSONValue root)
+ {
+ return new JSONWalk(root);
+ }
+
+ public JSONWrapper next(String name)
+ {
+ if (null == root || root.isObject() == null) return null;
+ JSONObject rootObject = root.isObject();
+
+ JSONWrapper match = null;
+ Set<String> keySet = rootObject.keySet();
+
+ Iterator it = keySet.iterator();
+ while (it.hasNext())
+ {
+ String s = (String) it.next();
+ JSONValue child = rootObject.get(s);
+ if (name.equals(s))
+ {
+ match = new JSONWrapper(child);
+ break;
+ }
+ else
+ {
+ match = JSONWalk.on(child).next(name);
+ }
+ }
+
+ return match;
+ }
+
+ public class JSONWrapper
+ {
+
+ private JSONValue value;
+
+ public JSONWrapper(JSONValue value)
+ {
+ this.value = value;
+ }
+
+ public int asInt()
+ {
+ if (value.isNumber() != null)
+ {
+ return new Double(value.isNumber().getValue()).intValue();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a number: " + value);
+ }
+ }
+
+ public long asLong()
+ {
+ if (value.isNumber() != null)
+ {
+ return new Double(value.isNumber().getValue()).longValue();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a number: " + value);
+ }
+ }
+
+ public double asDouble()
+ {
+ if (value.isNumber() != null)
+ {
+ return value.isNumber().getValue();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a number: " + value);
+ }
+ }
+
+ public String asString()
+ {
+ if (value.isString() != null)
+ {
+ return value.isString().stringValue();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a string: " + value);
+ }
+ }
+
+ public boolean asBool()
+ {
+ if (value.isBoolean() != null)
+ {
+ return value.isBoolean().booleanValue();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a boolean: " + value);
+ }
+ }
+
+ public Date asDate()
+ {
+ if (value.isString() != null)
+ {
+ SimpleDateFormat df = new SimpleDateFormat();
+ return df.parse(value.isString().stringValue());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a date string: " + value);
+ }
+ }
+
+
+ public JSONArray asArray()
+ {
+ if (value.isArray() != null)
+ {
+ return value.isArray();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not a number: " + value);
+ }
+ }
+
+ public JSONObject asObject()
+ {
+ if (value.isObject() != null)
+ {
+ return value.isObject();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Not an object: " + value);
+ }
+ }
+
+
+ public String toString() throws JSONException
+ {
+ return value.toString();
+ }
+ }
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java (from rev 899, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.util;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class MapEntry
+{
+ String name;
+ Object value;
+
+ public MapEntry(String name, Object value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java (from rev 927, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.bpm.console.client.util;
+
+import java.util.Date;
+
+ at SuppressWarnings("deprecation")
+public class SimpleDateFormat {
+ private String format;
+ private DateLocale locale = new DateLocale();
+ public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+
+ /**
+ * Gets the support locale for formatting and parsing dates
+ * @return
+ */
+ public DateLocale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(DateLocale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Use {@link #DEFAULT_FORMAT}
+ */
+ public SimpleDateFormat()
+ {
+ format = DEFAULT_FORMAT;
+ }
+
+ /**
+ * Use a custom format
+ */
+ public SimpleDateFormat(String pattern) {
+ format = pattern;
+ }
+
+ public String format(Date date) {
+ String f = "";
+ if (format != null && format.length() > 0) {
+ String lastTokenType = null;
+ String currentToken = "";
+ for (int i = 0; i < format.length(); i++) {
+ String thisChar = format.substring(i, i + 1);
+ String currentTokenType = DateLocale.SUPPORTED_DF_TOKENS
+ .contains(thisChar) ? thisChar : "";
+ if (currentTokenType.equals(lastTokenType) || i == 0) {
+ currentToken += thisChar;
+ lastTokenType = currentTokenType;
+ } else {
+ if ("".equals(lastTokenType))
+ f += currentToken;
+ else
+ f += handleToken(currentToken, date);
+ currentToken = thisChar;
+ lastTokenType = currentTokenType;
+ }
+ }
+ if ("".equals(lastTokenType))
+ f += currentToken;
+ else
+ f += handleToken(currentToken, date);
+ }
+ return f;
+ }
+
+ /**
+ * takes a date format string and returns the formatted portion of the date.
+ * For instance if the token is MMMM then the full month name is returned.
+ *
+ * @param token
+ * date format token
+ * @param date
+ * date to format
+ * @return formatted portion of the date
+ */
+ private String handleToken(String token, Date date) {
+ String response = token;
+ String tc = token.substring(0, 1);
+ if (DateLocale.TOKEN_DAY_OF_WEEK.equals(tc)) {
+ if (token.length() > 3)
+ response = locale.getWEEKDAY_LONG()[date.getDay()];
+ else
+ response = locale.getWEEKDAY_SHORT()[date.getDay()];
+ } else if (DateLocale.TOKEN_DAY_OF_MONTH.equals(tc)) {
+ if (token.length() == 1)
+ response = Integer.toString(date.getDate());
+ else
+ response = twoCharDateField(date.getDate());
+ } else if (DateLocale.TOKEN_MONTH.equals(tc)) {
+ switch (token.length()) {
+ case 1:
+ response = Integer.toString(date.getMonth() + 1);
+ break;
+ case 2:
+ response = twoCharDateField(date.getMonth() + 1);
+ break;
+ case 3:
+ response = locale.MONTH_SHORT[date.getMonth()];
+ break;
+ default:
+ response = locale.MONTH_LONG[date.getMonth()];
+ break;
+ }
+ } else if (DateLocale.TOKEN_YEAR.equals(tc)) {
+ if (token.length() > 2)
+ response = Integer.toString(date.getYear() + 1900);
+ else
+ response = twoCharDateField(date.getYear());
+ } else if (DateLocale.TOKEN_HOUR_12.equals(tc)) {
+ int h = date.getHours();
+ if (h == 0)
+ h = 12;
+ else if (h > 12)
+ h -= 12;
+ if (token.length() > 1)
+ response = twoCharDateField(h);
+ else
+ response = Integer.toString(h);
+ } else if (DateLocale.TOKEN_HOUR_24.equals(tc)) {
+ if (token.length() > 1)
+ response = twoCharDateField(date.getHours());
+ else
+ response = Integer.toString(date.getHours());
+ } else if (DateLocale.TOKEN_MINUTE.equals(tc)) {
+ if (token.length() > 1)
+ response = twoCharDateField(date.getMinutes());
+ else
+ response = Integer.toString(date.getMinutes());
+ } else if (DateLocale.TOKEN_SECOND.equals(tc)) {
+ if (token.length() > 1)
+ response = twoCharDateField(date.getSeconds());
+ else
+ response = Integer.toString(date.getSeconds());
+ } else if (DateLocale.TOKEN_AM_PM.equals(tc)) {
+ int hour = date.getHours();
+ if (hour > 11)
+ response = DateLocale.getPM();
+ else
+ response = DateLocale.getAM();
+ }
+ return response;
+ }
+
+ /**
+ * This is basically just a sneaky way to guarantee that our 1 or 2 digit
+ * numbers come out as a 2 character string. we add an arbitrary number
+ * larger than 100, convert this new number to a string, then take the right
+ * most 2 characters.
+ *
+ * @param num
+ * @return
+ */
+ private String twoCharDateField(int num) {
+ String res = Integer.toString(num + 1900);
+ res = res.substring(res.length() - 2);
+ return res;
+ }
+
+ private static Date newDate(long time) {
+ return new Date(time);
+ }
+
+ /**
+ * Parses text and returns the corresponding date object.
+ *
+ * @param source
+ * @return java.util.Date
+ */
+ public Date parse(String source){
+ return SimpleDateParser.parse(source, format);
+ };
+
+}
\ No newline at end of file
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java (from rev 899, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.bpm.console.client.util;
+
+import org.jboss.bpm.console.client.util.regex.Pattern;
+
+import java.util.Date;
+
+
+/**
+ * This is a simple regular expression based parser for date notations.
+ * While our aim is to fully support in the future the JDK date parser, currently
+ * only numeric notations and literals are supported such as <code>dd/MM/yyyy HH:mm:ss.SSSS</code>.
+ * Each entity is parsed with the same number of digits, i.e. for <code>dd</code> two digits will be
+ * parsed while for <code>d</code> only one will be parsed.
+ * @author <a href="mailto:g.georgovassilis at gmail.com">George Georgovassilis</a>
+ *
+ */
+
+ at SuppressWarnings("deprecation")
+public class SimpleDateParser {
+
+
+ private final static String DAY_IN_MONTH = "d";
+
+ private final static String MONTH = "M";
+
+ private final static String YEAR = "y";
+
+ private final static String LITERAL = "\\";
+
+ private final static int DATE_PATTERN = 0;
+
+ private final static int REGEX_PATTERN = 1;
+
+ private final static int COMPONENT = 2;
+
+ private final static int REGEX = 0;
+
+ private final static int INSTRUCTION = 1;
+
+ private final static String[] TOKENS[] = {
+ { "SSSS", "(\\d\\d\\d\\d)",DateLocale.TOKEN_MILLISECOND },
+ { "SSS", "(\\d\\d\\d)", DateLocale.TOKEN_MILLISECOND },
+ { "SS", "(\\d\\d)", DateLocale.TOKEN_MILLISECOND },
+ { "S", "(\\d)", DateLocale.TOKEN_MILLISECOND },
+ { "ss", "(\\d\\d)", DateLocale.TOKEN_SECOND },
+ { "s", "(\\d)", DateLocale.TOKEN_SECOND },
+ { "mm", "(\\d\\d)", DateLocale.TOKEN_MINUTE },
+ { "m", "(\\d)", DateLocale.TOKEN_MINUTE},
+ { "HH", "(\\d\\d)", DateLocale.TOKEN_HOUR_24},
+ { "H", "(\\d)", DateLocale.TOKEN_HOUR_24 },
+ { "dd", "(\\d\\d)", DateLocale.TOKEN_DAY_OF_MONTH },
+ { "d", "(\\d)", DateLocale.TOKEN_DAY_OF_MONTH },
+ { "MM", "(\\d\\d)", DateLocale.TOKEN_MONTH },
+ { "M", "(\\d)", DateLocale.TOKEN_MONTH },
+ { "yyyy", "(\\d\\d\\d\\d)", DateLocale.TOKEN_YEAR },
+ { "yyy", "(\\d\\d\\d)", DateLocale.TOKEN_YEAR },
+ { "yy", "(\\d\\d)", DateLocale.TOKEN_YEAR },
+ { "y", "(\\d)", DateLocale.TOKEN_YEAR }
+ };
+
+ private Pattern regularExpression;
+
+ private String instructions = "";
+
+ private static void _parse(String format, String[] args) {
+ if (format.length() == 0)
+ return;
+ if (format.startsWith("'")){
+ format = format.substring(1);
+ int end = format.indexOf("'");
+ if (end == -1)
+ throw new IllegalArgumentException("Unmatched single quotes.");
+ args[REGEX]+=Pattern.quote(format.substring(0,end));
+ format = format.substring(end+1);
+ }
+ for (int i = 0; i < TOKENS.length; i++) {
+ String[] row = TOKENS[i];
+ String datePattern = row[DATE_PATTERN];
+ if (!format.startsWith(datePattern))
+ continue;
+ format = format.substring(datePattern.length());
+ args[REGEX] += row[REGEX_PATTERN];
+ args[INSTRUCTION] += row[COMPONENT];
+ _parse(format, args);
+ return;
+ }
+ args[REGEX] += Pattern.quote(""+format.charAt(0));
+ format = format.substring(1);
+ _parse(format, args);
+ }
+
+ private static void load(Date date, String text, String component) {
+ if (component.equals(DateLocale.TOKEN_MILLISECOND)) {
+ //TODO: implement
+ }
+
+ if (component.equals(DateLocale.TOKEN_SECOND)) {
+ date.setSeconds(Integer.parseInt(text));
+ }
+
+ if (component.equals(DateLocale.TOKEN_MINUTE)) {
+ date.setMinutes(Integer.parseInt(text));
+ }
+
+ if (component.equals(DateLocale.TOKEN_HOUR_24)) {
+ date.setHours(Integer.parseInt(text));
+ }
+
+ if (component.equals(DateLocale.TOKEN_DAY_OF_MONTH)) {
+ date.setDate(Integer.parseInt(text));
+ }
+ if (component.equals(DateLocale.TOKEN_MONTH)) {
+ date.setMonth(Integer.parseInt(text)-1);
+ }
+ if (component.equals(DateLocale.TOKEN_YEAR)) {
+ //TODO: fix for short patterns
+ date.setYear(Integer.parseInt(text)-1900);
+ }
+
+ }
+
+ public SimpleDateParser(String format) {
+ String[] args = new String[] { "", "" };
+ _parse(format, args);
+ regularExpression = new Pattern(args[REGEX]);
+ instructions = args[INSTRUCTION];
+ }
+
+ public Date parse(String input) {
+ Date date = new Date(0, 0, 1, 0, 0, 0);
+ String matches[] = regularExpression.match(input);
+ if (matches == null)
+ throw new IllegalArgumentException(input+" does not match "+regularExpression.pattern());
+ if (matches.length-1!=instructions.length())
+ throw new IllegalArgumentException("Different group count - "+input+" does not match "+regularExpression.pattern());
+ for (int group = 0; group < instructions.length(); group++) {
+ String match = matches[group + 1];
+ load(date, match, ""+instructions.charAt(group));
+ }
+ return date;
+ }
+
+ public static Date parse(String input, String pattern){
+ return new SimpleDateParser(pattern).parse(input);
+ }
+}
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex (from rev 899, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/regex)
Deleted: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java 2009-12-10 13:53:53 UTC (rev 899)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,186 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client.util.regex;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-/**
- * <p>
- * Implementation of the {@link java.util.regex.Pattern} class with a
- * wrapper aroung the Javascript <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Regular_Expressions">RegExp</a> object.
- * As most of the methods delegate to the JavaScript RegExp object, certain differences in the
- * declaration and behaviour of regular expressions must be expected.
- * </p>
- * <p>
- * Please note that neither the {@link java.util.regex.Pattern#compile(String)} method nor
- * {@link Matcher} instances are supported. For the later, consider using {@link Pattern#match(String)}.
- * </p>
- *
- * @author George Georgovassilis
- *
- */
-public class Pattern {
-
- /**
- * Declares that regular expressions should be matched across line borders.
- */
- public final static int MULTILINE = 1;
-
- /**
- * Declares that characters are matched reglardless of case.
- */
- public final static int CASE_INSENSITIVE = 2;
-
- private JavaScriptObject regExp;
-
- private static JavaScriptObject createExpression(String pattern, int flags) {
- String sFlags = "";
- if ((flags & MULTILINE) != 0)
- sFlags += "m";
- if ((flags & CASE_INSENSITIVE) != 0)
- sFlags += "i";
- return _createExpression(pattern, sFlags);
- }
-
- private static native JavaScriptObject _createExpression(String pattern,
- String flags)/*-{
- return new RegExp(pattern, flags);
- }-*/;
-
- private native void _match(String text, List matches)/*-{
- var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
- var result = text.match(regExp);
- if (result == null) return;
- for (var i=0;i<result.length;i++)
- matches. at java.util.ArrayList::add(Ljava/lang/Object;)(result[i]);
- }-*/;
-
- /**
- * Determines wether the specified regular expression is validated by the
- * provided input.
- * @param regex Regular expression
- * @param input String to validate
- * @return <code>true</code> if matched.
- */
- public static boolean matches(String regex, String input) {
- return new Pattern(regex).matches(input);
- }
-
- /**
- * Escape a provided string so that it will be interpreted as a literal
- * in regular expressions.
- * The current implementation does escape each character even if not neccessary,
- * generating verbose literals.
- * @param input
- * @return
- */
- public static String quote(String input) {
- String output = "";
- for (int i = 0; i < input.length(); i++) {
- output += "\\" + input.charAt(i);
- }
- return output;
- }
-
- /**
- * Class constructor
- * @param pattern Regular expression
- */
- public Pattern(String pattern) {
- this(pattern, 0);
- }
-
- /**
- * Class constructor
- * @param pattern Regular expression
- * @param flags
- */
- public Pattern(String pattern, int flags) {
- regExp = createExpression(pattern, flags);
- }
-
- /**
- * This method is borrowed from the JavaScript RegExp object.
- * It parses a string and returns as an array any assignments to parenthesis groups
- * in the pattern's regular expression
- * @param text
- * @return Array of strings following java's Pattern convention for groups:
- * Group 0 is the entire input string and the remaining groups are the matched parenthesis.
- * In case nothing was matched an empty array is returned.
- */
- public String[] match(String text) {
- List matches = new ArrayList();
- _match(text, matches);
- String arr[] = new String[matches.size()];
- for (int i = 0; i < matches.size(); i++)
- arr[i] = matches.get(i).toString();
- return arr;
- }
-
- /**
- * Determines wether a provided text matches the regular expression
- * @param text
- * @return
- */
- public native boolean matches(String text)/*-{
- var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
- return regExp.test(text);
- }-*/;
-
- /**
- * Returns the regular expression for this pattern
- * @return
- */
- public native String pattern()/*-{
- var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
- return regExp.source;
- }-*/;
-
- private native void _split(String input, List results)/*-{
- var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
- var parts = input.split(regExp);
- for (var i=0;i<parts.length;i++)
- results. at java.util.ArrayList::add(Ljava/lang/Object;)(parts[i] );
- }-*/;
-
- /**
- * Split an input string by the pattern's regular expression
- * @param input
- * @return Array of strings
- */
- public String[] split(String input){
- List results = new ArrayList();
- _split(input, results);
- String[] parts = new String[results.size()];
- for (int i=0;i<results.size();i++)
- parts[i] = (String)results.get(i);
- return parts;
- }
-
- public String toString() {
- return regExp.toString();
- }
-}
-
Copied: bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java (from rev 927, bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java)
===================================================================
--- bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java (rev 0)
+++ bpm-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/util/regex/Pattern.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.util.regex;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>
+ * Implementation of the {@link java.util.regex.Pattern} class with a
+ * wrapper aroung the Javascript <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Regular_Expressions">RegExp</a> object.
+ * As most of the methods delegate to the JavaScript RegExp object, certain differences in the
+ * declaration and behaviour of regular expressions must be expected.
+ * </p>
+ * <p>
+ * Please note that neither the {@link java.util.regex.Pattern#compile(String)} method nor
+ * {@link Matcher} instances are supported. For the later, consider using {@link Pattern#match(String)}.
+ * </p>
+ *
+ * @author George Georgovassilis
+ *
+ */
+public class Pattern {
+
+ /**
+ * Declares that regular expressions should be matched across line borders.
+ */
+ public final static int MULTILINE = 1;
+
+ /**
+ * Declares that characters are matched reglardless of case.
+ */
+ public final static int CASE_INSENSITIVE = 2;
+
+ private JavaScriptObject regExp;
+
+ private static JavaScriptObject createExpression(String pattern, int flags) {
+ String sFlags = "";
+ if ((flags & MULTILINE) != 0)
+ sFlags += "m";
+ if ((flags & CASE_INSENSITIVE) != 0)
+ sFlags += "i";
+ return _createExpression(pattern, sFlags);
+ }
+
+ private static native JavaScriptObject _createExpression(String pattern,
+ String flags)/*-{
+ return new RegExp(pattern, flags);
+ }-*/;
+
+ private native void _match(String text, List matches)/*-{
+ var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
+ var result = text.match(regExp);
+ if (result == null) return;
+ for (var i=0;i<result.length;i++)
+ matches. at java.util.ArrayList::add(Ljava/lang/Object;)(result[i]);
+ }-*/;
+
+ /**
+ * Determines wether the specified regular expression is validated by the
+ * provided input.
+ * @param regex Regular expression
+ * @param input String to validate
+ * @return <code>true</code> if matched.
+ */
+ public static boolean matches(String regex, String input) {
+ return new Pattern(regex).matches(input);
+ }
+
+ /**
+ * Escape a provided string so that it will be interpreted as a literal
+ * in regular expressions.
+ * The current implementation does escape each character even if not neccessary,
+ * generating verbose literals.
+ * @param input
+ * @return
+ */
+ public static String quote(String input) {
+ String output = "";
+ for (int i = 0; i < input.length(); i++) {
+ output += "\\" + input.charAt(i);
+ }
+ return output;
+ }
+
+ /**
+ * Class constructor
+ * @param pattern Regular expression
+ */
+ public Pattern(String pattern) {
+ this(pattern, 0);
+ }
+
+ /**
+ * Class constructor
+ * @param pattern Regular expression
+ * @param flags
+ */
+ public Pattern(String pattern, int flags) {
+ regExp = createExpression(pattern, flags);
+ }
+
+ /**
+ * This method is borrowed from the JavaScript RegExp object.
+ * It parses a string and returns as an array any assignments to parenthesis groups
+ * in the pattern's regular expression
+ * @param text
+ * @return Array of strings following java's Pattern convention for groups:
+ * Group 0 is the entire input string and the remaining groups are the matched parenthesis.
+ * In case nothing was matched an empty array is returned.
+ */
+ public String[] match(String text) {
+ List matches = new ArrayList();
+ _match(text, matches);
+ String arr[] = new String[matches.size()];
+ for (int i = 0; i < matches.size(); i++)
+ arr[i] = matches.get(i).toString();
+ return arr;
+ }
+
+ /**
+ * Determines wether a provided text matches the regular expression
+ * @param text
+ * @return
+ */
+ public native boolean matches(String text)/*-{
+ var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
+ return regExp.test(text);
+ }-*/;
+
+ /**
+ * Returns the regular expression for this pattern
+ * @return
+ */
+ public native String pattern()/*-{
+ var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
+ return regExp.source;
+ }-*/;
+
+ private native void _split(String input, List results)/*-{
+ var regExp = this. at org.jboss.bpm.console.client.util.regex.Pattern::regExp;
+ var parts = input.split(regExp);
+ for (var i=0;i<parts.length;i++)
+ results. at java.util.ArrayList::add(Ljava/lang/Object;)(parts[i] );
+ }-*/;
+
+ /**
+ * Split an input string by the pattern's regular expression
+ * @param input
+ * @return Array of strings
+ */
+ public String[] split(String input){
+ List results = new ArrayList();
+ _split(input, results);
+ String[] parts = new String[results.size()];
+ for (int i=0;i<results.size();i++)
+ parts[i] = (String)results.get(i);
+ return parts;
+ }
+
+ public String toString() {
+ return regExp.toString();
+ }
+}
+
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Authentication.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Authentication.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Authentication.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,334 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client;
-
-import com.google.gwt.http.client.*;
-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.JSONValue;
-import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.DeferredCommand;
-import org.gwt.mosaic.ui.client.MessageBox;
-import org.jboss.bpm.console.client.util.ConsoleLog;
-import org.jboss.bpm.console.client.util.JSONWalk;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-public class Authentication
-{
- private AuthCallback callback;
-
- private List<String> rolesAssigned = new ArrayList<String>();
-
- private String sid;
- private String username;
- private String password;
-
- private ConsoleConfig config;
- private String rolesUrl;
- private Date loggedInSince;
-
- public Authentication(ConsoleConfig config, String sessionID, String rolesUrl)
- {
- this.config = config;
- this.sid = sessionID;
- this.rolesUrl = rolesUrl;
- this.loggedInSince = new Date();
- }
-
- public String getSid()
- {
- return sid;
- }
-
- public void login(String user, String pass)
- {
- this.username = user;
- this.password = pass;
-
- String formAction = config.getConsoleServerUrl() + "/rs/identity/secure/j_security_check";
- RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, formAction);
- rb.setHeader("Content-Type", "application/x-www-form-urlencoded");
-
- try
- {
- rb.sendRequest("j_username="+user+"&j_password="+pass,
- new RequestCallback()
- {
-
- public void onResponseReceived(Request request, Response response)
- {
- ConsoleLog.debug("postLoginCredentials() HTTP "+response.getStatusCode());
-
- if(response.getText().indexOf("HTTP 401")!=-1) // HACK
- {
- if (callback != null)
- callback.onLoginFailed(request, new Exception("Authentication failed"));
- else
- throw new RuntimeException("Unknown exception upon login attempt");
- }
- else if(response.getStatusCode()==200) // it's always 200, even when the authentication fails
- {
- DeferredCommand.addCommand(
- new Command()
- {
-
- public void execute()
- {
- requestAssignedRoles();
- }
- }
- );
- }
- }
-
- public void onError(Request request, Throwable t)
- {
- if (callback != null)
- callback.onLoginFailed(request, new Exception("Authentication failed"));
- else
- throw new RuntimeException("Unknown exception upon login attempt");
- }
- }
- );
- }
- catch (RequestException e)
- {
- ConsoleLog.error("Request error", e);
- }
- }
-
- public Date getLoggedInSince()
- {
- return loggedInSince;
- }
-
- /**
- * Login using specific credentials.
- * This delegates to {@link com.google.gwt.http.client.RequestBuilder#setUser(String)}
- * and {@link com.google.gwt.http.client.RequestBuilder#setPassword(String)}
- */
- private void requestAssignedRoles()
- {
- RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, rolesUrl );
-
- ConsoleLog.debug("Request roles: " + rb.getUrl());
-
- /*if (user != null && pass != null)
- {
- rb.setUser(user);
- rb.setPassword(pass);
-
- if (!GWT.isScript()) // hosted mode only
- {
- rb.setHeader("xtest-user", user);
- rb.setHeader("xtest-pass", pass); // NOTE: This is plaintext, use for testing only
- }
- }*/
-
- try
- {
- rb.sendRequest(null,
- new RequestCallback()
- {
-
- public void onResponseReceived(Request request, Response response)
- {
- ConsoleLog.debug("requestAssignedRoles() HTTP "+response.getStatusCode());
-
- // parse roles
- if (200 == response.getStatusCode())
- {
- rolesAssigned = Authentication.parseRolesAssigned(response.getText());
- if (callback != null) callback.onLoginSuccess(request, response);
- }
- else
- {
- onError(request, new Exception(response.getText()));
- }
- }
-
- public void onError(Request request, Throwable t)
- {
- // auth failed
- // Couldn't connect to server (could be timeout, SOP violation, etc.)
- if (callback != null)
- callback.onLoginFailed(request, t);
- else
- throw new RuntimeException("Unknown exception upon login attempt", t);
- }
- });
- }
-
- catch (RequestException e1)
- {
- // Couldn't connect to server
- throw new RuntimeException("Unknown error upon login attempt", e1);
- }
- }
-
-
- public void setCallback(AuthCallback callback)
- {
- this.callback = callback;
- }
-
- private native void reload() /*-{
- $wnd.location.reload();
- }-*/;
-
- public static void logout(final ConsoleConfig conf)
- {
- RequestBuilder rb = new RequestBuilder(
- RequestBuilder.POST,
- conf.getConsoleServerUrl()+"/rs/identity/sid/invalidate"
- );
-
- try
- {
- rb.sendRequest(null, new RequestCallback()
- {
- public void onResponseReceived(Request request, Response response)
- {
- ConsoleLog.debug("logout() HTTP "+response.getStatusCode());
-
- if(response.getStatusCode()!=200)
- {
- ConsoleLog.error(response.getText());
- }
- }
-
- public void onError(Request request, Throwable t)
- {
- ConsoleLog.error("Failed to invalidate session", t);
- }
- });
- }
- catch (RequestException e)
- {
- ConsoleLog.error("Request error", e);
- }
- }
-
- public void logoutAndReload()
- {
- RequestBuilder rb = new RequestBuilder(
- RequestBuilder.POST,
- config.getConsoleServerUrl()+"/rs/identity/sid/invalidate"
- );
-
- try
- {
- rb.sendRequest(null, new RequestCallback()
- {
- public void onResponseReceived(Request request, Response response)
- {
- ConsoleLog.debug("logoutAndReload() HTTP "+response.getStatusCode());
- resetState();
- reload();
- }
-
- public void onError(Request request, Throwable t)
- {
- ConsoleLog.error("Failed to invalidate session", t);
- }
- });
- }
- catch (RequestException e)
- {
- ConsoleLog.error("Request error", e);
- }
- }
-
- private void resetState()
- {
- sid = null;
- username = null;
- password = null;
- rolesAssigned = new ArrayList<String>();
- loggedInSince = null;
- }
-
- public void handleSessionTimeout()
- {
- MessageBox.confirm("Session expired", "Please login again",
- new MessageBox.ConfirmationCallback()
- {
- public void onResult(boolean b)
- {
- // regardless of the choice, force login
- logoutAndReload();
- }
- }
- );
- }
-
-
- public interface AuthCallback
- {
- void onLoginSuccess(Request request, Response response);
-
- void onLoginFailed(Request request, Throwable t);
- }
-
-
- public List<String> getRolesAssigned()
- {
- return rolesAssigned;
- }
-
- public String getUsername()
- {
- return username;
- }
-
- public String getPassword()
- {
- return password;
- }
-
- public static List<String> parseRolesAssigned(String json)
- {
- // parse roles
- List<String> roles = new ArrayList<String>();
-
- JSONValue root = JSONParser.parse(json);
- JSONArray array = JSONWalk.on(root).next("roles").asArray();
-
- for (int i = 0; i < array.size(); ++i)
- {
- JSONObject item = array.get(i).isObject();
- boolean assigned = JSONWalk.on(item).next("assigned").asBool();
- String roleName = JSONWalk.on(item).next("role").asString();
-
- if (assigned)
- {
- roles.add(roleName);
- }
- }
-
- return roles;
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/ConsoleConfig.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,173 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.i18n.client.Dictionary;
-
-/**
- * Initialize console config from host page (<code>Application.html</code>) variable:
- * <pre>
- * var consoleConfig = {
- * consoleServerUrl: "http://localhost:8080/gwt-console-server",
- * reportServerUrl: "http://localhost:8080/report",
- * [...]
- * };
- * </pre>
- *
- * @author Heiko.Braun <heiko.braun at jboss.com>
- * @see com.google.gwt.i18n.client.Dictionary
- */
-public class ConsoleConfig
-{
- private String serverWebContext;
-
- private String overallReportFile;
- private String processSummaryReportFile;
- private String instanceSummaryReportFile;
-
- private String profileName;
- private String logo;
-
- private String consoleServerUrl;
-
- private String defaultEditor;
-
- public ConsoleConfig(String proxyUrl)
- {
- Dictionary theme = Dictionary.getDictionary("consoleConfig");
- profileName = theme.get("profileName");
- logo = theme.get("logo");
-
- serverWebContext = theme.get("serverWebContext");
-
- overallReportFile = theme.get("overallReportFile");
- processSummaryReportFile = theme.get("processSummaryReportFile");
- instanceSummaryReportFile = theme.get("instanceSummaryReportFile");
-
- defaultEditor = theme.get("defaultEditor");
-
- if(null==proxyUrl)
- {
- // extract host
- String base = GWT.getHostPageBaseURL();
- String protocol = base.substring(0, base.indexOf("//")+2);
- String noProtocol = base.substring(base.indexOf(protocol)+protocol.length(), base.length());
- String host = noProtocol.substring(0, noProtocol.indexOf("/"));
-
- // default url
- consoleServerUrl = protocol + host + serverWebContext;
- }
- else
- {
- consoleServerUrl = proxyUrl;
- }
-
- // features
-
- }
-
- public String getHost()
- {
- String host = null;
- if(!GWT.isScript()) // development with proxy
- {
- host = consoleServerUrl;
- }
- else
- {
- String baseUrl = GWT.getModuleBaseURL();
- host = baseUrl.substring(
- 0, baseUrl.indexOf("app")
- );
- }
-
- return host;
- }
-
- public String getProfileName()
- {
- return profileName;
- }
-
- public String getLogo()
- {
- return logo;
- }
-
- public String getDefaultEditor()
- {
- return defaultEditor;
- }
-
- public String getConsoleServerUrl()
- {
- if(consoleServerUrl ==null)
- throw new RuntimeException("Config not properly setup: console server URL is null");
- return consoleServerUrl;
- }
-
- public void setConsoleServerUrl(String consoleServerUrl)
- {
- this.consoleServerUrl = consoleServerUrl;
- }
-
- public String getServerWebContext()
- {
- return serverWebContext;
- }
-
- public void setServerWebContext(String serverWebContext)
- {
- this.serverWebContext = serverWebContext;
- }
-
- public String getOverallReportFile()
- {
- return overallReportFile;
- }
-
- public void setOverallReportFile(String overallReportFile)
- {
- this.overallReportFile = overallReportFile;
- }
-
- public String getProcessSummaryReportFile()
- {
- return processSummaryReportFile;
- }
-
- public void setProcessSummaryReportFile(String processSummaryReportFile)
- {
- this.processSummaryReportFile = processSummaryReportFile;
- }
-
- public String getInstanceSummaryReportFile()
- {
- return instanceSummaryReportFile;
- }
-
- public void setInstanceSummaryReportFile(String instanceSummaryReportFile)
- {
- this.instanceSummaryReportFile = instanceSummaryReportFile;
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Preferences.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Preferences.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/Preferences.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client;
-
-import com.google.gwt.user.client.Cookies;
-
-import java.util.Date;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class Preferences
-{
- // Editor that should be launched at startup
- public static final String BPM_DEFAULT_TOOL = "bpm.default.tool";
-
- public static boolean has(String key)
- {
- return Preferences.get(key)!=null;
- }
-
- public static String get(String key)
- {
- return Cookies.getCookie(key);
- }
-
- public static void set(String key, String value)
- {
- Date twoWeeks = new Date(System.currentTimeMillis()+(2*604800*1000));
- Cookies.setCookie(key, value, twoWeeks);
- }
-
- public static void clear(String key)
- {
- Cookies.removeCookie(key);
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/UIConstants.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/UIConstants.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/UIConstants.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class UIConstants
-{
- public static final int OVERALL_WIDTH = 1024;
- public static final int OVERALL_HEIGHT = 768;
- public static final int MAIN_MENU_MIN = 175;
- public static final int MAIN_MENU_MAX = 400;
- public static final int EDITOR_WIDTH = 680;
- public static final int TEASER_PANEL_WIDTH = 200;
- public static final int EDITOR_PANEL_WIDTH = 450;
-
- public static final String DEFAULT_TRANSITION = "default transition";
- public static final String DATE_FORMAT = "yyyy-m-j H:i:s"; //08-10-02 13:51:27
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/ConsoleLog.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client.util;
-
-/**
- * The maven gwt:test mojo treats any output to stderr as
- * a test failure. gwt-log does dump some information there,
- * hence we need to proxy log invocation and be able to disable them at all.
- * <p/>
- * If you want to test the application, make sure to lauch it using
- * {@link org.jboss.bpm.console.client.Application#onModuleLoad2()}.
- *
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class ConsoleLog
-{
- private static boolean enabled = true; // see javadoc comments
-
- public static void warn(String msg)
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.warn(msg);
- }
-
- public static void info(String msg)
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.info(msg);
- }
-
- public static void debug(String msg)
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.debug(msg);
- }
-
- public static void error(String msg)
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.error(msg);
- }
-
- public static void error(String msg, Throwable t)
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.error(msg, t);
- }
-
- public static void setUncaughtExceptionHandler()
- {
- if (enabled)
- com.allen_sauer.gwt.log.client.Log.setUncaughtExceptionHandler();
- }
-
- public static boolean isEnabled()
- {
- return enabled;
- }
-
- public static void setEnabled(boolean enabled)
- {
- ConsoleLog.enabled = enabled;
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/DateLocale.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,86 +0,0 @@
-/*
- * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.bpm.console.client.util;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Date locale support for the {@link SimpleDateParser}. You are encouraged to
- * extend this class and provide implementations for other locales.
- * @author <a href="mailto:g.georgovassilis at gmail.com">George Georgovassilis</a>
- *
- */
-public class DateLocale {
- public final static String TOKEN_DAY_OF_WEEK = "E";
-
- public final static String TOKEN_DAY_OF_MONTH = "d";
-
- public final static String TOKEN_MONTH = "M";
-
- public final static String TOKEN_YEAR = "y";
-
- public final static String TOKEN_HOUR_12 = "h";
-
- public final static String TOKEN_HOUR_24 = "H";
-
- public final static String TOKEN_MINUTE = "m";
-
- public final static String TOKEN_SECOND = "s";
-
- public final static String TOKEN_MILLISECOND = "S";
-
- public final static String TOKEN_AM_PM = "a";
-
- public final static String AM = "AM";
-
- public final static String PM = "PM";
-
- public final static List SUPPORTED_DF_TOKENS = Arrays.asList(new String[] {
- TOKEN_DAY_OF_WEEK, TOKEN_DAY_OF_MONTH, TOKEN_MONTH, TOKEN_YEAR,
- TOKEN_HOUR_12, TOKEN_HOUR_24, TOKEN_MINUTE, TOKEN_SECOND,
- TOKEN_AM_PM });
-
- public String[] MONTH_LONG = { "January", "February", "March", "April",
- "May", "June", "July", "August", "September", "October",
- "November", "December" };
-
- public String[] MONTH_SHORT = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
-
- public String[] WEEKDAY_LONG = { "Sunday", "Monday", "Tuesday",
- "Wednesday", "Thursday", "Friday", "Saturday" };
-
- public String[] WEEKDAY_SHORT = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
- "Sat" };
-
- public static String getAM() {
- return AM;
- }
-
- public static String getPM() {
- return PM;
- }
-
- public String[] getWEEKDAY_LONG() {
- return WEEKDAY_LONG;
- }
-
- public String[] getWEEKDAY_SHORT() {
- return WEEKDAY_SHORT;
- }
-
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/JSONWalk.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,192 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client.util;
-
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONException;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
-
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class JSONWalk
-{
- private JSONValue root;
-
-
- private JSONWalk(JSONValue root)
- {
- this.root = root;
- }
-
- public static JSONWalk on(JSONValue root)
- {
- return new JSONWalk(root);
- }
-
- public JSONWrapper next(String name)
- {
- if (null == root || root.isObject() == null) return null;
- JSONObject rootObject = root.isObject();
-
- JSONWrapper match = null;
- Set<String> keySet = rootObject.keySet();
-
- Iterator it = keySet.iterator();
- while (it.hasNext())
- {
- String s = (String) it.next();
- JSONValue child = rootObject.get(s);
- if (name.equals(s))
- {
- match = new JSONWrapper(child);
- break;
- }
- else
- {
- match = JSONWalk.on(child).next(name);
- }
- }
-
- return match;
- }
-
- public class JSONWrapper
- {
-
- private JSONValue value;
-
- public JSONWrapper(JSONValue value)
- {
- this.value = value;
- }
-
- public int asInt()
- {
- if (value.isNumber() != null)
- {
- return new Double(value.isNumber().getValue()).intValue();
- }
- else
- {
- throw new IllegalArgumentException("Not a number: " + value);
- }
- }
-
- public long asLong()
- {
- if (value.isNumber() != null)
- {
- return new Double(value.isNumber().getValue()).longValue();
- }
- else
- {
- throw new IllegalArgumentException("Not a number: " + value);
- }
- }
-
- public double asDouble()
- {
- if (value.isNumber() != null)
- {
- return value.isNumber().getValue();
- }
- else
- {
- throw new IllegalArgumentException("Not a number: " + value);
- }
- }
-
- public String asString()
- {
- if (value.isString() != null)
- {
- return value.isString().stringValue();
- }
- else
- {
- throw new IllegalArgumentException("Not a string: " + value);
- }
- }
-
- public boolean asBool()
- {
- if (value.isBoolean() != null)
- {
- return value.isBoolean().booleanValue();
- }
- else
- {
- throw new IllegalArgumentException("Not a boolean: " + value);
- }
- }
-
- public Date asDate()
- {
- if (value.isString() != null)
- {
- SimpleDateFormat df = new SimpleDateFormat();
- return df.parse(value.isString().stringValue());
- }
- else
- {
- throw new IllegalArgumentException("Not a date string: " + value);
- }
- }
-
-
- public JSONArray asArray()
- {
- if (value.isArray() != null)
- {
- return value.isArray();
- }
- else
- {
- throw new IllegalArgumentException("Not a number: " + value);
- }
- }
-
- public JSONObject asObject()
- {
- if (value.isObject() != null)
- {
- return value.isObject();
- }
- else
- {
- throw new IllegalArgumentException("Not an object: " + value);
- }
- }
-
-
- public String toString() throws JSONException
- {
- return value.toString();
- }
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/MapEntry.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.console.client.util;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class MapEntry
-{
- String name;
- Object value;
-
- public MapEntry(String name, Object value)
- {
- this.name = name;
- this.value = value;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Object getValue()
- {
- return value;
- }
-}
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateFormat.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,190 +0,0 @@
-/*
- * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.bpm.console.client.util;
-
-import java.util.Date;
-
- at SuppressWarnings("deprecation")
-public class SimpleDateFormat {
- private String format;
- private DateLocale locale = new DateLocale();
- public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
-
-
- /**
- * Gets the support locale for formatting and parsing dates
- * @return
- */
- public DateLocale getLocale() {
- return locale;
- }
-
- public void setLocale(DateLocale locale) {
- this.locale = locale;
- }
-
- /**
- * Use {@link #DEFAULT_FORMAT}
- */
- public SimpleDateFormat()
- {
- format = DEFAULT_FORMAT;
- }
-
- /**
- * Use a custom format
- */
- public SimpleDateFormat(String pattern) {
- format = pattern;
- }
-
- public String format(Date date) {
- String f = "";
- if (format != null && format.length() > 0) {
- String lastTokenType = null;
- String currentToken = "";
- for (int i = 0; i < format.length(); i++) {
- String thisChar = format.substring(i, i + 1);
- String currentTokenType = DateLocale.SUPPORTED_DF_TOKENS
- .contains(thisChar) ? thisChar : "";
- if (currentTokenType.equals(lastTokenType) || i == 0) {
- currentToken += thisChar;
- lastTokenType = currentTokenType;
- } else {
- if ("".equals(lastTokenType))
- f += currentToken;
- else
- f += handleToken(currentToken, date);
- currentToken = thisChar;
- lastTokenType = currentTokenType;
- }
- }
- if ("".equals(lastTokenType))
- f += currentToken;
- else
- f += handleToken(currentToken, date);
- }
- return f;
- }
-
- /**
- * takes a date format string and returns the formatted portion of the date.
- * For instance if the token is MMMM then the full month name is returned.
- *
- * @param token
- * date format token
- * @param date
- * date to format
- * @return formatted portion of the date
- */
- private String handleToken(String token, Date date) {
- String response = token;
- String tc = token.substring(0, 1);
- if (DateLocale.TOKEN_DAY_OF_WEEK.equals(tc)) {
- if (token.length() > 3)
- response = locale.getWEEKDAY_LONG()[date.getDay()];
- else
- response = locale.getWEEKDAY_SHORT()[date.getDay()];
- } else if (DateLocale.TOKEN_DAY_OF_MONTH.equals(tc)) {
- if (token.length() == 1)
- response = Integer.toString(date.getDate());
- else
- response = twoCharDateField(date.getDate());
- } else if (DateLocale.TOKEN_MONTH.equals(tc)) {
- switch (token.length()) {
- case 1:
- response = Integer.toString(date.getMonth() + 1);
- break;
- case 2:
- response = twoCharDateField(date.getMonth() + 1);
- break;
- case 3:
- response = locale.MONTH_SHORT[date.getMonth()];
- break;
- default:
- response = locale.MONTH_LONG[date.getMonth()];
- break;
- }
- } else if (DateLocale.TOKEN_YEAR.equals(tc)) {
- if (token.length() > 2)
- response = Integer.toString(date.getYear() + 1900);
- else
- response = twoCharDateField(date.getYear());
- } else if (DateLocale.TOKEN_HOUR_12.equals(tc)) {
- int h = date.getHours();
- if (h == 0)
- h = 12;
- else if (h > 12)
- h -= 12;
- if (token.length() > 1)
- response = twoCharDateField(h);
- else
- response = Integer.toString(h);
- } else if (DateLocale.TOKEN_HOUR_24.equals(tc)) {
- if (token.length() > 1)
- response = twoCharDateField(date.getHours());
- else
- response = Integer.toString(date.getHours());
- } else if (DateLocale.TOKEN_MINUTE.equals(tc)) {
- if (token.length() > 1)
- response = twoCharDateField(date.getMinutes());
- else
- response = Integer.toString(date.getMinutes());
- } else if (DateLocale.TOKEN_SECOND.equals(tc)) {
- if (token.length() > 1)
- response = twoCharDateField(date.getSeconds());
- else
- response = Integer.toString(date.getSeconds());
- } else if (DateLocale.TOKEN_AM_PM.equals(tc)) {
- int hour = date.getHours();
- if (hour > 11)
- response = DateLocale.getPM();
- else
- response = DateLocale.getAM();
- }
- return response;
- }
-
- /**
- * This is basically just a sneaky way to guarantee that our 1 or 2 digit
- * numbers come out as a 2 character string. we add an arbitrary number
- * larger than 100, convert this new number to a string, then take the right
- * most 2 characters.
- *
- * @param num
- * @return
- */
- private String twoCharDateField(int num) {
- String res = Integer.toString(num + 1900);
- res = res.substring(res.length() - 2);
- return res;
- }
-
- private static Date newDate(long time) {
- return new Date(time);
- }
-
- /**
- * Parses text and returns the corresponding date object.
- *
- * @param source
- * @return java.util.Date
- */
- public Date parse(String source){
- return SimpleDateParser.parse(source, format);
- };
-
-}
\ No newline at end of file
Deleted: bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java
===================================================================
--- bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java 2010-01-25 12:55:27 UTC (rev 930)
+++ bpm-console/trunk/workspace/workspace-api/src/main/java/org/jboss/bpm/console/client/util/SimpleDateParser.java 2010-01-25 13:03:41 UTC (rev 931)
@@ -1,161 +0,0 @@
-/*
- * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.bpm.console.client.util;
-
-import org.jboss.bpm.console.client.util.regex.Pattern;
-
-import java.util.Date;
-
-
-/**
- * This is a simple regular expression based parser for date notations.
- * While our aim is to fully support in the future the JDK date parser, currently
- * only numeric notations and literals are supported such as <code>dd/MM/yyyy HH:mm:ss.SSSS</code>.
- * Each entity is parsed with the same number of digits, i.e. for <code>dd</code> two digits will be
- * parsed while for <code>d</code> only one will be parsed.
- * @author <a href="mailto:g.georgovassilis at gmail.com">George Georgovassilis</a>
- *
- */
-
- at SuppressWarnings("deprecation")
-public class SimpleDateParser {
-
-
- private final static String DAY_IN_MONTH = "d";
-
- private final static String MONTH = "M";
-
- private final static String YEAR = "y";
-
- private final static String LITERAL = "\\";
-
- private final static int DATE_PATTERN = 0;
-
- private final static int REGEX_PATTERN = 1;
-
- private final static int COMPONENT = 2;
-
- private final static int REGEX = 0;
-
- private final static int INSTRUCTION = 1;
-
- private final static String[] TOKENS[] = {
- { "SSSS", "(\\d\\d\\d\\d)",DateLocale.TOKEN_MILLISECOND },
- { "SSS", "(\\d\\d\\d)", DateLocale.TOKEN_MILLISECOND },
- { "SS", "(\\d\\d)", DateLocale.TOKEN_MILLISECOND },
- { "S", "(\\d)", DateLocale.TOKEN_MILLISECOND },
- { "ss", "(\\d\\d)", DateLocale.TOKEN_SECOND },
- { "s", "(\\d)", DateLocale.TOKEN_SECOND },
- { "mm", "(\\d\\d)", DateLocale.TOKEN_MINUTE },
- { "m", "(\\d)", DateLocale.TOKEN_MINUTE},
- { "HH", "(\\d\\d)", DateLocale.TOKEN_HOUR_24},
- { "H", "(\\d)", DateLocale.TOKEN_HOUR_24 },
- { "dd", "(\\d\\d)", DateLocale.TOKEN_DAY_OF_MONTH },
- { "d", "(\\d)", DateLocale.TOKEN_DAY_OF_MONTH },
- { "MM", "(\\d\\d)", DateLocale.TOKEN_MONTH },
- { "M", "(\\d)", DateLocale.TOKEN_MONTH },
- { "yyyy", "(\\d\\d\\d\\d)", DateLocale.TOKEN_YEAR },
- { "yyy", "(\\d\\d\\d)", DateLocale.TOKEN_YEAR },
- { "yy", "(\\d\\d)", DateLocale.TOKEN_YEAR },
- { "y", "(\\d)", DateLocale.TOKEN_YEAR }
- };
-
- private Pattern regularExpression;
-
- private String instructions = "";
-
- private static void _parse(String format, String[] args) {
- if (format.length() == 0)
- return;
- if (format.startsWith("'")){
- format = format.substring(1);
- int end = format.indexOf("'");
- if (end == -1)
- throw new IllegalArgumentException("Unmatched single quotes.");
- args[REGEX]+=Pattern.quote(format.substring(0,end));
- format = format.substring(end+1);
- }
- for (int i = 0; i < TOKENS.length; i++) {
- String[] row = TOKENS[i];
- String datePattern = row[DATE_PATTERN];
- if (!format.startsWith(datePattern))
- continue;
- format = format.substring(datePattern.length());
- args[REGEX] += row[REGEX_PATTERN];
- args[INSTRUCTION] += row[COMPONENT];
- _parse(format, args);
- return;
- }
- args[REGEX] += Pattern.quote(""+format.charAt(0));
- format = format.substring(1);
- _parse(format, args);
- }
-
- private static void load(Date date, String text, String component) {
- if (component.equals(DateLocale.TOKEN_MILLISECOND)) {
- //TODO: implement
- }
-
- if (component.equals(DateLocale.TOKEN_SECOND)) {
- date.setSeconds(Integer.parseInt(text));
- }
-
- if (component.equals(DateLocale.TOKEN_MINUTE)) {
- date.setMinutes(Integer.parseInt(text));
- }
-
- if (component.equals(DateLocale.TOKEN_HOUR_24)) {
- date.setHours(Integer.parseInt(text));
- }
-
- if (component.equals(DateLocale.TOKEN_DAY_OF_MONTH)) {
- date.setDate(Integer.parseInt(text));
- }
- if (component.equals(DateLocale.TOKEN_MONTH)) {
- date.setMonth(Integer.parseInt(text)-1);
- }
- if (component.equals(DateLocale.TOKEN_YEAR)) {
- //TODO: fix for short patterns
- date.setYear(Integer.parseInt(text)-1900);
- }
-
- }
-
- public SimpleDateParser(String format) {
- String[] args = new String[] { "", "" };
- _parse(format, args);
- regularExpression = new Pattern(args[REGEX]);
- instructions = args[INSTRUCTION];
- }
-
- public Date parse(String input) {
- Date date = new Date(0, 0, 1, 0, 0, 0);
- String matches[] = regularExpression.match(input);
- if (matches == null)
- throw new IllegalArgumentException(input+" does not match "+regularExpression.pattern());
- if (matches.length-1!=instructions.length())
- throw new IllegalArgumentException("Different group count - "+input+" does not match "+regularExpression.pattern());
- for (int group = 0; group < instructions.length(); group++) {
- String match = matches[group + 1];
- load(date, match, ""+instructions.charAt(group));
- }
- return date;
- }
-
- public static Date parse(String input, String pattern){
- return new SimpleDateParser(pattern).parse(input);
- }
-}
More information about the overlord-commits
mailing list