import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
+import jalview.analytics.GoogleAnalytics4;
import jalview.datamodel.PDBEntry;
import jalview.gui.Preferences;
import jalview.gui.UserDefinedColours;
// in-memory only storage of proxy password, safer to use char array
public static char[] proxyAuthPassword = null;
+ /**
+ * Session properties, set by command line, try not to affect stored
+ * properties!
+ */
+ private static Map<String, String> sessionProperties = new HashMap<>();
+
+ private static boolean bypassSessionProperties = false;
+
+ public static void enableSessionProperties()
+ {
+ bypassSessionProperties = false;
+ }
+
+ public static void disableSessionProperties()
+ {
+ bypassSessionProperties = true;
+ }
+
/** Jalview Properties */
public static Properties applicationProperties = new Properties()
{
{
// props file provided as URL
fis = new URL(propertiesFile).openStream();
- System.out.println(
- "Loading jalview properties from : " + propertiesFile);
- System.out.println(
- "Disabling Jalview writing to user's local properties file.");
+ if (!Jalview.quiet())
+ {
+ System.out.println(
+ "Loading jalview properties from : " + propertiesFile);
+ System.out.println(
+ "Disabling Jalview writing to user's local properties file.");
+ }
propsAreReadOnly = true;
} catch (Exception ex)
{
fis.close();
} catch (Exception ex)
{
- System.out.println("Error reading properties file: " + ex);
+ if (!Jalview.quiet())
+ System.out.println("Error reading properties file: " + ex);
}
}
}
} catch (Exception ex)
{
- System.out.println("Error reading author details: " + ex);
+ if (!Jalview.quiet())
+ System.out.println("Error reading author details: " + ex);
authorDetails = null;
}
if (authorDetails == null)
remoteVersion = remoteBuildProperties.getProperty("VERSION");
} catch (Exception ex)
{
- System.out.println(
- "Non-fatal exception when checking version at "
- + remoteBuildPropertiesUrl + ":");
- System.out.println(ex);
+ if (!Jalview.quiet())
+ {
+ System.out.println(
+ "Non-fatal exception when checking version at "
+ + remoteBuildPropertiesUrl + ":");
+ System.out.println(ex);
+ }
remoteVersion = getProperty("VERSION");
}
}
}
} catch (Exception ex)
{
- System.out.println("Error reading build details: " + ex);
+ if (!Jalview.quiet())
+ System.out.println("Error reading build details: " + ex);
applicationProperties.remove("VERSION");
}
String codeVersion = getProperty("VERSION");
if (printVersion && reportVersion)
{
System.out.println(ChannelProperties.getProperty("app_name")
- + " Version: " + codeVersion + codeInstallation);
+ + " version: " + codeVersion + codeInstallation);
}
}
*/
public static String getProperty(String key)
{
- String prop = applicationProperties.getProperty(key);
+ return getProperty(key, false);
+ }
+
+ public static String getProperty(String key,
+ boolean skipSessionProperties)
+ {
+ String prop = null;
+ if (!(skipSessionProperties || bypassSessionProperties))
+ {
+ prop = getSessionProperty(key);
+ }
+ if (prop == null)
+ {
+ prop = applicationProperties.getProperty(key);
+ }
if (prop == null && Platform.isJS())
{
prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
def = Integer.parseInt(string);
} catch (NumberFormatException e)
{
- System.out.println("Error parsing int property '" + property
- + "' with value '" + string + "'");
+ if (!Jalview.quiet())
+ System.out.println("Error parsing int property '" + property
+ + "' with value '" + string + "'");
}
}
try
{
oldValue = applicationProperties.setProperty(key, obj);
- if (propertiesFile != null && !propsAreReadOnly)
+ if (propertiesFile != null && !propsAreReadOnly
+ // don't rewrite if new value is same as old value
+ && !((obj == null && oldValue == null)
+ || (obj != null && obj.equals(oldValue))))
{
+ // reset the session property too
+ if (sessionProperties.containsKey(key))
+ {
+ sessionProperties.remove(key);
+ }
FileOutputStream out = new FileOutputStream(propertiesFile);
applicationProperties.store(out, "---JalviewX Properties File---");
out.close();
}
} catch (Exception ex)
{
- System.out.println(
- "Error setting property: " + key + " " + obj + "\n" + ex);
+ if (!Jalview.quiet())
+ System.out.println(
+ "Error setting property: " + key + " " + obj + "\n" + ex);
}
return oldValue;
}
out.close();
} catch (Exception ex)
{
- System.out.println("Error saving properties: " + ex);
+ if (!Jalview.quiet())
+ System.out.println("Error saving properties: " + ex);
}
}
}
protected static Class jgoogleanalyticstracker = null;
+ private static boolean useGA4 = true;
+
/**
* Initialise the google tracker if it is not done already.
*/
public static void initGoogleTracker()
{
- if (tracker == null)
+ if (useGA4)
{
- if (jgoogleanalyticstracker == null)
- {
- // try to get the tracker class
- try
- {
- jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
- "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
- trackerfocus = Cache.class.getClassLoader()
- .loadClass("com.boxysystems.jgoogleanalytics.FocusPoint");
- } catch (Exception e)
- {
- Console.debug(
- "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
- tracker = null;
- jgoogleanalyticstracker = null;
- trackerfocus = null;
- return;
- }
- }
- // now initialise tracker
- Exception re = null, ex = null;
- Error err = null;
- String vrs = "No Version Accessible";
+ GoogleAnalytics4.setEnabled(true);
+
+ String appName = ChannelProperties.getProperty("app_name")
+ + " Desktop";
+ String version = Cache.getProperty("VERSION") + "_"
+ + Cache.getDefault("BUILD_DATE", "unknown");
+ String path;
+ /* we don't want to encode ':' as "%3A" for backward compatibility with the UA setup
try
{
- // Google analytics tracking code for Library Finder
- tracker = jgoogleanalyticstracker
- .getConstructor(new Class[]
- { String.class, String.class, String.class })
- .newInstance(new Object[]
- { ChannelProperties.getProperty("app_name") + " Desktop",
- (vrs = Cache.getProperty("VERSION") + "_"
- + Cache.getDefault("BUILD_DATE", "unknown")),
- "UA-9060947-1" });
- jgoogleanalyticstracker
- .getMethod("trackAsynchronously", new Class[]
- { trackerfocus })
- .invoke(tracker, new Object[]
- { trackerfocus.getConstructor(new Class[] { String.class })
- .newInstance(new Object[]
- { "Application Started." }) });
- } catch (RuntimeException e)
- {
- re = e;
- } catch (Exception e)
+ path = "/" + String.join("/", URLEncoder.encode(appName, "UTF-8"),
+ URLEncoder.encode(version, "UTF-8"),
+ URLEncoder.encode(APPLICATION_STARTED, "UTF-8"));
+ } catch (UnsupportedEncodingException e)
{
- ex = e;
- } catch (Error e)
- {
- err = e;
+ */
+ path = ("/" + String.join("/", appName, version, APPLICATION_STARTED))
+ .replace(' ', '+');
+ /*
}
- if (re != null || ex != null || err != null)
+ */
+ GoogleAnalytics4 ga4 = GoogleAnalytics4.getInstance();
+
+ // This will add a page_view similar to the old UA analytics.
+ // We probably want to get rid of this once the application_launch event
+ // is being processed properly.
+ ga4.sendAnalytics("page_view", "page_location", path, "page_title",
+ APPLICATION_STARTED);
+
+ // This will send a new "application_launch" event with parameters
+ // including the old-style "path", the channel name and version
+ ga4.sendAnalytics("application_launch", true, "page_location", path);
+ }
+ else
+ {
+ if (tracker == null)
{
- if (re != null)
+ if (jgoogleanalyticstracker == null)
{
- Console.debug("Caught runtime exception in googletracker init:",
- re);
+ // try to get the tracker class
+ try
+ {
+ jgoogleanalyticstracker = Cache.class.getClassLoader()
+ .loadClass(
+ "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
+ trackerfocus = Cache.class.getClassLoader().loadClass(
+ "com.boxysystems.jgoogleanalytics.FocusPoint");
+ } catch (Exception e)
+ {
+ Console.debug(
+ "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
+ tracker = null;
+ jgoogleanalyticstracker = null;
+ trackerfocus = null;
+ return;
+ }
}
- if (ex != null)
+ // now initialise tracker
+ Exception re = null, ex = null;
+ Error err = null;
+ String vrs = "No Version Accessible";
+ try
{
- Console.warn(
- "Failed to initialise GoogleTracker for Jalview Desktop with version "
- + vrs,
- ex);
+ // Google analytics tracking code for Library Finder
+ tracker = jgoogleanalyticstracker
+ .getConstructor(new Class[]
+ { String.class, String.class, String.class })
+ .newInstance(new Object[]
+ { ChannelProperties.getProperty("app_name") + " Desktop",
+ (vrs = Cache.getProperty("VERSION") + "_"
+ + Cache.getDefault("BUILD_DATE", "unknown")),
+ "UA-9060947-1" });
+ jgoogleanalyticstracker
+ .getMethod("trackAsynchronously", new Class[]
+ { trackerfocus })
+ .invoke(tracker, new Object[]
+ { trackerfocus
+ .getConstructor(new Class[]
+ { String.class })
+ .newInstance(new Object[]
+ { APPLICATION_STARTED }) });
+ } catch (RuntimeException e)
+ {
+ re = e;
+ } catch (Exception e)
+ {
+ ex = e;
+ } catch (Error e)
+ {
+ err = e;
}
- if (err != null)
+ if (re != null || ex != null || err != null)
{
- Console.error(
- "Whilst initing GoogleTracker for Jalview Desktop version "
- + vrs,
- err);
+ if (re != null)
+ {
+ Console.debug("Caught runtime exception in googletracker init:",
+ re);
+ }
+ if (ex != null)
+ {
+ Console.warn(
+ "Failed to initialise GoogleTracker for Jalview Desktop with version "
+ + vrs,
+ ex);
+ }
+ if (err != null)
+ {
+ Console.error(
+ "Whilst initing GoogleTracker for Jalview Desktop version "
+ + vrs,
+ err);
+ }
+ }
+ else
+ {
+ Console.debug("Successfully initialised tracker.");
}
- }
- else
- {
- Console.debug("Successfully initialised tracker.");
}
}
}
+ private static final String APPLICATION_STARTED = "Application Started.";
+
/**
* get the user's default colour if available
*
}
} catch (Exception ex)
{
- System.out.println("Error loading User ColourFile\n" + ex);
+ if (!Jalview.quiet())
+ System.out.println("Error loading User ColourFile\n" + ex);
}
}
if (!files.equals(coloursFound.toString()))
}
return bootstrapProps;
}
+
+ public static void setSessionProperty(String key, String val)
+ {
+ if (key != null)
+ {
+ sessionProperties.put(key, val);
+ }
+ }
+
+ public static String getSessionProperty(String key)
+ {
+ return key == null ? null : sessionProperties.get(key);
+ }
}