private static boolean propsAreReadOnly = Platform.isJS();/// ** @j2sNative
/// true || */false;
+ private final static String JS_PROPERTY_PREFIX = "jalview_";
+
public static void initLogger()
{
if (log != null)
public static void loadProperties(String propsFile)
{
propertiesFile = propsFile;
- if (propsFile == null)
+ if (propsFile == null && !propsAreReadOnly)
{
propertiesFile = System.getProperty("user.home") + File.separatorChar
+ ".jalview_properties";
propsAreReadOnly = true;
}
- try
+ if (propertiesFile == null)
+ { // BH 2019
+ Platform.readInfoProperties(JS_PROPERTY_PREFIX,
+ applicationProperties);
+ }
+ else
{
- InputStream fis;
try
{
- fis = new java.net.URL(propertiesFile).openStream();
- System.out.println(
- "Loading jalview properties from : " + propertiesFile);
- System.out.println(
- "Disabling Jalview writing to user's local properties file.");
- propsAreReadOnly = true;
+ InputStream fis;
+ try
+ {
+ fis = new java.net.URL(propertiesFile).openStream();
+ 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 = null;
+ }
+ if (fis == null)
+ {
+ fis = new FileInputStream(propertiesFile);
+ }
+ applicationProperties.clear();
+ applicationProperties.load(fis);
+
+ // remove any old build properties
+ deleteBuildProperties();
+ fis.close();
} catch (Exception ex)
{
- fis = null;
+ System.out.println("Error reading properties file: " + ex);
}
- if (fis == null)
- {
- fis = new FileInputStream(propertiesFile);
- }
- applicationProperties.clear();
- applicationProperties.load(fis);
-
- // remove any old build properties
-
- deleteBuildProperties();
- fis.close();
- } catch (Exception ex)
- {
- System.out.println("Error reading properties file: " + ex);
}
-
if (getDefault("USE_PROXY", false))
{
String proxyServer = getDefault("PROXY_SERVER", ""),
}
// LOAD THE AUTHORS FROM THE authors.props file
- boolean ignore = Platform.isJS();
- if (!ignore)
- /**
- * @j2sNative
- */
+ String authorDetails = (Platform.isJS() ? null
+ : "jar:".concat(Cache.class.getProtectionDomain()
+ .getCodeSource().getLocation().toString()
+ .concat("!/authors.props")));
+
+ try
{
- try
+ if (authorDetails != null)
{
- String authorDetails = "jar:"
- .concat(Cache.class.getProtectionDomain().getCodeSource()
- .getLocation().toString().concat("!/authors.props"));
-
java.net.URL localJarFileURL = new java.net.URL(authorDetails);
-
InputStream in = localJarFileURL.openStream();
applicationProperties.load(in);
in.close();
-
- } catch (Exception ex)
- {
- System.out.println("Error reading author details: " + ex);
- ignore = true;
}
+ } catch (Exception ex)
+ {
+ System.out.println("Error reading author details: " + ex);
+ authorDetails = null;
}
-
- if (ignore) {
+ if (authorDetails == null)
+ {
applicationProperties.remove("AUTHORS");
applicationProperties.remove("AUTHORFNAMES");
applicationProperties.remove("YEAR");
}
-
+
// FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
// MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
// VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
- // BH 2019.01.25 switching to Platform.isJS()
- ignore = Platform.isJS();
- if (!ignore)
- /**
- * @j2sNative
- */
+ String buildDetails = (Platform.isJS() ? null
+ : "jar:".concat(Cache.class.getProtectionDomain()
+ .getCodeSource().getLocation().toString()
+ .concat("!/.build_properties")));
+ if (buildDetails != null)
{
try
{
- String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
- .getCodeSource().getLocation().toString()
- .concat("!/.build_properties"));
-
java.net.URL localJarFileURL = new java.net.URL(buildDetails);
-
InputStream in = localJarFileURL.openStream();
applicationProperties.load(in);
in.close();
} catch (Exception ex)
{
System.out.println("Error reading build details: " + ex);
- ignore = true;
+ buildDetails = null;
}
}
-
- if (ignore) {
+ if (buildDetails == null)
+ {
applicationProperties.remove("VERSION");
}
-
String jnlpVersion = System.getProperty("jalview.version");
String codeVersion = getProperty("VERSION");
String codeInstallation = getProperty("INSTALLATION");
false);
}
+
private static void deleteBuildProperties()
{
applicationProperties.remove("LATEST_VERSION");
import jalview.ext.jmol.JalviewJmolBinding;
import jalview.io.DataSourceType;
import jalview.structure.StructureSelectionManager;
+import jalview.util.Platform;
import java.awt.Container;
+import java.io.File;
+import java.util.List;
import java.util.Map;
import org.jmol.api.JmolAppConsoleInterface;
+
import javajs.util.BS;
-import org.openscience.jmol.app.jmolpanel.console.AppConsole;
public class AppJmolBinding extends JalviewJmolBinding
{
- private AppJmol appJmolWindow;
+ protected AppJmol appJmolWindow;
public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
return null;
}
+
+ @SuppressWarnings("unused")
+ public void cacheFiles(List<File> files)
+ {
+ if (files == null)
+ {
+ return;
+ }
+ for (File f : files)
+ {
+ String path = f.getAbsolutePath();
+ byte[] data = Platform.getFileBytes(f);
+ if (data != null)
+ {
+ Platform.cacheFileData(path, data);
+ }
+ }
+ }
}
import jalview.schemes.ColourSchemeI;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import jalview.ws.utils.UrlDownloadClient;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Vector;
@SuppressWarnings("unused")
public static BufferedReader getBuffereReader(Object file) throws FileNotFoundException {
if (file instanceof String)
+ {
return new BufferedReader(new FileReader((String) file));
-
- byte[] bytes = /** @j2sNative file._bytes || */ null;
+ }
+ byte[] bytes = Platform.getFileBytes((File) file);
if (bytes != null)
+ {
return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
+ }
return new BufferedReader(new FileReader((File) file));
}
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsModelI;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
private void parse(File file, String fileStr, DataSourceType sourceType,
boolean isFileObject) throws MalformedURLException, IOException
{
- /**
- * @j2sNative
- *
- * this.bytes = file && file._bytes;
- *
- */
- this.dataSourceType = sourceType;
+ bytes = Platform.getFileBytes(file);
+ dataSourceType = sourceType;
error = false;
if (sourceType == DataSourceType.FILE)
}
else if (sourceType == DataSourceType.RELATIVE_URL)
{
- /**
- * BH 2018 hack for no support for access-origin
- *
- * @j2sNative
- *
- * this.bytes = swingjs.JSUtil.getFileAsBytes$O(fileStr);
- *
- */
-
+ // BH 2018 hack for no support for access-origin
+ bytes = Platform.getFileAsBytes(fileStr);
dataIn = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes)));
dataName = fileStr;
import com.sun.jersey.api.client.config.ClientConfig;
+/**
+ * A JavaScript-only proxy for com.sun.jersey.api.client.Client
+ *
+ * @author hansonr
+ *
+ */
public class Client
{
package jalview.javascript.web;
+import jalview.util.Platform;
+
import java.net.URI;
import java.net.URISyntaxException;
-/* this class is a proxy for
+/*
+ * A JavaScript-only proxy for com.sun.jersey.api.client.WebResource
*
*/
public class WebResource
{
private String endpoint, params = "";
-
- public WebResource(String endpoint) {
+
+ public WebResource(String endpoint)
+ {
this.endpoint = endpoint;
}
-
public WebResource queryParam(String key, String value)
{
- params += (params == "" ? "?" : "&") + key + "=";
- /**
- * @j2sNative
- * value = encodeURIComponent(value);
- */
- params += value;
+ params += (params == "" ? "?" : "&") + key + "="
+ + Platform.encodeURI(value);
return this;
}
public Builder accept(String... encoding)
{
- return new Builder(getURI(), encoding);
+ return new Builder(getURI(), encoding);
}
-
-
- public static class Builder {
- private URI uri;
- private String[] encoding;
- public Builder(URI uri, String... encoding)
+ public static class Builder
+ {
+ private URI uri;
+
+ private String[] encoding;
+
+ public Builder(URI uri, String... encoding)
{
- this.uri = uri;
- this.encoding = encoding; // application/json
-
- // TODO Auto-generated constructor stub
+ this.uri = uri;
+ this.encoding = encoding; // application/json
}
- public ClientResponse get(Class<?> c) {
- String data = uri.toString();
- // c will be ClientResponse
- data = /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null;
- return new ClientResponse(data, encoding);
- }
+ /**
+ * Get the response
+ *
+ * @param c
+ * must be ClientResponse
+ * @return
+ */
+ public ClientResponse get(Class<?> c)
+ {
+ return new ClientResponse(Platform.getFileAsString(uri.toString()),
+ encoding);
+ }
}
-
-
-
}
// BH 2018 we add the .jvp binary extension to J2S so that
// it will declare that binary when we do the file save from the browser
- private static void addJ2SBinaryType(String ext)
- {
- ext = "." + ext + "?";
-
- /**
- * @j2sNative
- *
- * J2S._binaryTypes.push(ext);
- *
- */
- }
-
static
{
- addJ2SBinaryType(".jvp?");
+ Platform.addJ2SBinaryType(".jvp?");
}
private static final String VIEWER_PREFIX = "viewer_";
// BH 2018 allow for bytes already attached to File object
try {
String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
- byte[] bytes = /** @j2sNative ofile._bytes || */
- null;
+ byte[] bytes = Platform.getFileBytes((File) ofile);
URL url = null;
errorMessage = null;
uniqueSetSuffix = null;
public static void openURL(String url) throws IOException
{
+ if (Platform.openURL(url))
+ {
+ return;
+ }
/**
- * @j2sNative
- *
- * window.open(url);
- *
+ * Java only
*
+ * @j2sNative
*/
-
{
if (!loadedWithoutErrors)
*/
}
+ /**
+ * Encode the URI using JavaScript encodeURIComponent
+ *
+ * @param value
+ * @return encoded value
+ */
public static String encodeURI(String value)
{
/**
- * @j2sNative return encodeURIComponent(value);
+ * @j2sNative value = encodeURIComponent(value);
*/
return value;
}
+ /**
+ * Open the URL using a simple window call if this is JavaScript
+ *
+ * @param url
+ * @return true if window has been opened
+ */
public static boolean openURL(String url)
{
if (!isJS())
import jalview.util.Platform;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public static void download(String urlstring, File tempFile) throws IOException
{
- // BH 2019.01.25 this said "...getFileAsBytes(..." which cannot work.
- // maybe we cannot get here?
- if (Platform.isJS()) {
- /** @j2sNative
- * tempFile._bytes = swingjs.JSUtil.getFileAsBytes$O(urlstring);
- */
- } else {
+ if (!Platform.setFileBytes(tempFile, urlstring))
+ {
download(urlstring, tempFile.toString());
}
}