Merge branch 'issue_3575' into develop
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index b29b248..2baeaf6 100644 (file)
@@ -78,6 +78,16 @@ import java.util.*;
  * Entry point classes define <code>onModuleLoad()</code>.
  */
 public class Pithos implements EntryPoint, ResizeHandler {
+    private static final boolean IsLOGEnabled = true;
+    public static final boolean IsDetailedHTTPLOGEnabled = true;
+    public static final Set<String> HTTPHeadersToIgnoreInLOG = new HashSet<String>();
+    static {
+        HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_CONNECTION);
+        HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_DATE);
+        HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_KEEP_ALIVE);
+        HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_SERVER);
+        HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_VARY);
+    }
 
     public static final Configuration config = GWT.create(Configuration.class);
 
@@ -336,53 +346,73 @@ public class Pithos implements EntryPoint, ResizeHandler {
       }
     }-*/;
 
-    public static void LOG(Object ...args) {
-        if(false) {
-            final StringBuilder sb = new StringBuilder();
-            for(Object arg : args) {
-                if(arg instanceof Throwable) {
-                    final Throwable error = (Throwable) arg;
-                    sb.append("\nException: [" + error.toString().replace("\n", "\n  ") + "]");
-                    Throwable cause = error.getCause();
-                    if(cause != null) {
-                        sb.append("\nCauses:\n");
-                        while(cause != null) {
-                            sb.append("  ");
-                            sb.append("[" + cause.toString().replace("\n", "\n  ")  + "]");
-                            sb.append("\n");
-                            cause = cause.getCause();
-                        }
-                    }
-                    else {
-                        sb.append("\n");
-                    }
-
-                    StackTraceElement[] stackTrace = error.getStackTrace();
-                    sb.append("Stack trace (" + stackTrace.length + " elements):\n");
-                    for(int i = 0; i < stackTrace.length; i++) {
-                        StackTraceElement errorElem = stackTrace[i];
-                        sb.append("  [" + i + "] ");
-                        sb.append(errorElem.toString());
-                        sb.append("\n");
-                    }
-                }
-                else {
-                    sb.append(arg);
-                }
+    public static void LOGError(Throwable error, StringBuilder sb) {
+        if(!IsLOGEnabled) { return; }
+
+        sb.append("\nException: [" + error.toString().replace("\n", "\n  ") + "]");
+        Throwable cause = error.getCause();
+        if(cause != null) {
+            sb.append("\nCauses:\n");
+            while(cause != null) {
+                sb.append("  ");
+                sb.append("[" + cause.toString().replace("\n", "\n  ")  + "]");
+                sb.append("\n");
+                cause = cause.getCause();
             }
+        }
+        else {
+            sb.append("\n");
+        }
 
+        StackTraceElement[] stackTrace = error.getStackTrace();
+        sb.append("Stack trace (" + stackTrace.length + " elements):\n");
+        for(int i = 0; i < stackTrace.length; i++) {
+            StackTraceElement errorElem = stackTrace[i];
+            sb.append("  [" + i + "] ");
+            sb.append(errorElem.toString());
+            sb.append("\n");
+        }
+    }
 
-            if(sb.length() > 0) {
-                __ConsoleLog(sb.toString());
+    public static void LOGError(Throwable error) {
+        if(!IsLOGEnabled) { return; }
+
+        final StringBuilder sb = new StringBuilder();
+        LOGError(error, sb);
+        if(sb.length() > 0) {
+            __ConsoleLog(sb.toString());
+        }
+    }
+
+    public static boolean isLogEnabled() {
+        return IsLOGEnabled;
+    }
+
+    public static void LOG(Object ...args) {
+        if(!IsLOGEnabled) { return; }
+
+        final StringBuilder sb = new StringBuilder();
+        for(Object arg : args) {
+            if(arg instanceof Throwable) {
+                LOGError((Throwable) arg, sb);
+            }
+            else {
+                sb.append(arg);
             }
         }
+
+        if(sb.length() > 0) {
+            __ConsoleLog(sb.toString());
+        }
     }
 
     private void initialize() {
+        userCatalogs.updateWithIDAndName("*", "All Pithos users");
+
         lastModified = new Date(); //Initialize if-modified-since value with now.
         resources.pithosCss().ensureInjected();
         boolean bareContent = Window.Location.getParameter("noframe") != null;
-        String contentWidth = bareContent ? Const.PERCENT_100 : "75%";
+        String contentWidth = bareContent ? Const.PERCENT_100 : Const.PERCENT_75;
 
         VerticalPanel outer = new VerticalPanel();
         outer.setWidth(Const.PERCENT_100);
@@ -1312,6 +1342,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     public void setError(Throwable t) {
         error = t;
+        LOG(t);
     }
 
     public void showRelevantToolbarButtons() {
@@ -1364,7 +1395,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                                 @Override
                                 public void onError(Throwable _t) {
-                                    LOG(_t);
                                     setError(_t);
                                     if(_t instanceof RestException) {
                                         displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());