/*
- * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
*/
public class Pithos implements EntryPoint, ResizeHandler {
+ private static final boolean IsLOGEnabled = true;
+
public static final Configuration config = GWT.create(Configuration.class);
public interface Style extends CssResource {
}
}-*/;
+ 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");
+ }
+ }
+
+ 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(false) {
- final StringBuilder sb = new StringBuilder();
- for(Object arg : args) {
- sb.append(arg);
+ if(!IsLOGEnabled) { return; }
+
+ final StringBuilder sb = new StringBuilder();
+ for(Object arg : args) {
+ if(arg instanceof Throwable) {
+ LOGError((Throwable) arg, sb);
}
- if(sb.length() > 0) {
- __ConsoleLog(sb.toString());
+ else {
+ sb.append(arg);
}
}
+
+ if(sb.length() > 0) {
+ __ConsoleLog(sb.toString());
+ }
}
private void initialize() {
scheduleResfresh();
}
else if(retries >= MAX_RETRIES) {
- GWT.log("Error heading folder", t);
+ LOG("Error heading folder. ", t);
setError(t);
if(t instanceof RestException) {
displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
}
}
else {//retry
- GWT.log("Retry " + retries);
+ LOG("Retry ", retries);
Scheduler.get().scheduleDeferred(this);
}
}
@Override
public void onError(Throwable t) {
- GWT.log("Error getting account", t);
+ LOG("Error getting account", t);
setError(t);
if(t instanceof RestException) {
displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
@Override
public void onError(Throwable t) {
- GWT.log("Error getting account", t);
+ LOG("Error getting account", t);
setError(t);
if(t instanceof RestException) {
displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
@Override
public void onError(Throwable t) {
- GWT.log("Error creating pithos", t);
+ LOG("Error creating pithos", t);
setError(t);
if(t instanceof RestException) {
displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
@Override
public void onError(Throwable t) {
- GWT.log("Error creating pithos", t);
+ LOG("Error creating pithos", t);
setError(t);
if(t instanceof RestException) {
displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
@Override
public void onError(Throwable t) {
- GWT.log("", t);
+ LOG(t);
setError(t);
if(t instanceof RestException) {
if(((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) {
@Override
public void onError(Throwable t) {
- GWT.log("", t);
+ LOG(t);
setError(t);
if(t instanceof RestException) {
displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
@Override
public void onError(Throwable t) {
- GWT.log("", t);
+ LOG(t);
setError(t);
if(t instanceof RestException) {
displayError("Unable to copy folder: " + ((RestException) t).getHttpStatusText());
public void setError(Throwable t) {
error = t;
+ LOG(t);
}
public void showRelevantToolbarButtons() {
@Override
public void onError(Throwable _t) {
- GWT.log("", _t);
setError(_t);
if(_t instanceof RestException) {
displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
displayError("System error heading folder: " + t.getMessage());
}
- GWT.log("Error heading folder", t);
+ LOG("Error heading folder", t);
setError(t);
}
@Override
public void onError(Throwable t) {
- GWT.log("Error heading file", t);
+ LOG("Error heading file", t);
setError(t);
if(t instanceof RestException) {
displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
fileList.selectByUrl(selectedUrls);
}
- public void emptyContainer(final Folder container) {
+ public void purgeContainer(final Folder container) {
String path = "/" + container.getName() + "?delimiter=/";
DeleteRequest delete = new DeleteRequest(getApiPath(), getUserID(), path) {
@Override
public void onError(Throwable t) {
- GWT.log("Error deleting trash", t);
+ LOG("Error deleting trash", t);
setError(t);
if(t instanceof RestException) {
displayError("Error deleting trash: " + ((RestException) t).getHttpStatusText());