Get favicon url from injected properties
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index 3d575f9..197931b 100644 (file)
@@ -40,6 +40,8 @@ import com.google.gwt.core.client.JsArrayString;
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.core.client.Scheduler.RepeatingCommand;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.dom.client.*;
+import com.google.gwt.dom.client.Element;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.logical.shared.ResizeEvent;
@@ -81,6 +83,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     private static final boolean IsLOGEnabled = false;
     public static final boolean IsDetailedHTTPLOGEnabled = true;
     public static final boolean IsFullResponseBodyLOGEnabled = true;
+    private static final boolean EnableScheduledRefresh = true; // Make false only for debugging purposes.
 
     public static final Set<String> HTTPHeadersToIgnoreInLOG = new HashSet<String>();
     static {
@@ -99,16 +102,27 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     public static final Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
-    public static String getFromOtherPropertiesOrNull(String key) {
+    public static String getFromOtherPropertiesOrDefault(String key, String def) {
         try {
-            return otherProperties.get(key);
+            final String value = otherProperties.get(key);
+            return value == null ? def : value;
         }
         catch(Exception e) {
-            LOGError(e);
-            return null;
+            return def;
         }
     }
 
+    public static String getFromOtherPropertiesOrNull(String key) {
+        return getFromOtherPropertiesOrDefault(key, null);
+    }
+
+    private static final boolean SHOW_COPYRIGHT;
+    static {
+        final String valueStr = getFromOtherPropertiesOrDefault("SHOW_COPYRIGHT", "true").trim().toLowerCase();
+        SHOW_COPYRIGHT = "true".equals(valueStr);
+        LOG("SHOW_COPYRIGHT = '", valueStr, "' ==> ", SHOW_COPYRIGHT);
+    }
+
     public static final String OTHERPROPS_STORAGE_API_URL = getFromOtherPropertiesOrNull("STORAGE_API_URL");
     public static final String OTHERPROPS_USER_CATALOGS_API_URL = getFromOtherPropertiesOrNull("USER_CATALOGS_API_URL");
     static {
@@ -130,6 +144,22 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
         LOG("Computed STORAGE_API_URL = ", STORAGE_API_URL);
     }
+
+    public static final String STORAGE_VIEW_URL;
+    static {
+        final String viewURL = getFromOtherPropertiesOrNull("STORAGE_VIEW_URL");
+        if(viewURL != null) {
+            STORAGE_VIEW_URL = viewURL;
+        }
+        else {
+            STORAGE_VIEW_URL = STORAGE_API_URL;
+        }
+
+        LOG("Computed STORAGE_VIEW_URL = ", STORAGE_VIEW_URL);
+    }
+
+    public static final String PUBLIC_LINK_VIEW_PREFIX = getFromOtherPropertiesOrDefault("PUBLIC_LINK_VIEW_PREFIX", "");
+
     public static final String USER_CATALOGS_API_URL;
     static {
         if(OTHERPROPS_USER_CATALOGS_API_URL != null) {
@@ -152,6 +182,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
         }
     }
 
+    public static String FAVICON_URL = getFromOtherPropertiesOrNull("FAVICON_URL");
+
     public interface Style extends CssResource {
         String commandAnchor();
 
@@ -465,6 +497,16 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     private void initialize() {
+        // Inject the dynamically provided favicon
+        if(FAVICON_URL != null) {
+            final Document document = Document.get();
+            final Element head = document.getElementsByTagName("head").getItem(0);
+            final LinkElement link = document.createLinkElement();
+            link.setRel("icon");
+            link.setHref(FAVICON_URL);
+            head.appendChild(link);
+        }
+
         userCatalogs.updateWithIDAndName("*", "All Pithos users");
 
         lastModified = new Date(); //Initialize if-modified-since value with now.
@@ -664,7 +706,9 @@ public class Pithos implements EntryPoint, ResizeHandler {
         });
     }
 
-    public void scheduleResfresh() {
+    public void scheduleRefresh() {
+        if(!Pithos.EnableScheduledRefresh) { return; }
+
         Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
 
             @Override
@@ -684,7 +728,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                                 @Override
                                 public void execute() {
-                                    scheduleResfresh();
+                                    scheduleRefresh();
                                 }
 
                             }, false);
@@ -694,19 +738,19 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                                 @Override
                                 public void execute() {
-                                    scheduleResfresh();
+                                    scheduleRefresh();
                                 }
                             });
                         }
                         else {
-                            scheduleResfresh();
+                            scheduleRefresh();
                         }
                     }
 
                     @Override
                     public void onError(Throwable t) {
                         if(t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
-                            scheduleResfresh();
+                            scheduleRefresh();
                         }
                         else if(retries >= MAX_RETRIES) {
                             LOG("Error heading folder. ", t);
@@ -812,11 +856,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
         this.userID = authSplit[0];
         this.userToken = authSplit[1];
 
-        String gotoUrl = Window.Location.getParameter("goto");
-        if(gotoUrl != null && gotoUrl.length() > 0) {
-            Window.Location.assign(gotoUrl);
-            return false;
-        }
         return true;
     }
 
@@ -1083,10 +1122,26 @@ public class Pithos implements EntryPoint, ResizeHandler {
         return STORAGE_API_URL;
     }
 
+    public static String getStorageViewURL() {
+        return STORAGE_VIEW_URL;
+    }
+
+    public static boolean isShowCopyrightMessage() {
+        return SHOW_COPYRIGHT;
+    }
+
     public static String getUserCatalogsURL() {
         return USER_CATALOGS_API_URL;
     }
 
+    public static String getFileViewURL(File file) {
+        return Pithos.getStorageViewURL() + file.getOwnerID() + file.getUri();
+    }
+
+    public static String getVersionedFileViewURL(File file, int version) {
+        return getFileViewURL(file) + "?version=" + version;
+    }
+
     /**
      * History support for folder navigation
      * adds a new browser history entry
@@ -1372,7 +1427,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel, false);
                 trees.insert(otherSharedTreeView, 1);
                 treeViews.add(otherSharedTreeView);
-                scheduleResfresh();
+                scheduleRefresh();
             }
         });
     }