import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.RepositoryFactory;
return getUserHome(session, userID);
}
+ /** Whether this node is the home of the user of the underlying session. */
+ public static boolean isUserHome(Node node) {
+ try {
+ String userID = node.getSession().getUserID();
+ return node.hasProperty(Property.JCR_ID) && node.getProperty(Property.JCR_ID).getString().equals(userID);
+ } catch (RepositoryException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
/**
* Translate the path to this node into a path containing the name of the
* repository and the name of the workspace.
import org.argeo.cms.ui.CmsApp;
import org.argeo.cms.ui.CmsAppListener;
import org.argeo.cms.ui.CmsTheme;
+import org.argeo.cms.ui.CmsView;
import org.argeo.util.LangUtils;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.application.Application;
import org.eclipse.rap.rwt.application.ApplicationConfiguration;
+import org.eclipse.rap.rwt.application.ExceptionHandler;
import org.eclipse.rap.rwt.client.WebClient;
+import org.eclipse.swt.widgets.Display;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.EventAdmin;
/** An RWT web app integrating with a {@link CmsApp}. */
-public class CmsWebApp implements ApplicationConfiguration, CmsAppListener {
+public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, CmsAppListener {
private final static Log log = LogFactory.getLog(CmsWebApp.class);
private BundleContext bundleContext;
}
+ @Override
+ public void handleException(Throwable throwable) {
+ Display display = Display.getCurrent();
+ if (display != null && !display.isDisposed()) {
+ CmsView cmsView = CmsView.getCmsView(display.getActiveShell());
+ cmsView.exception(throwable);
+ } else {
+ log.error("Unexpected exception outside an UI thread", throwable);
+ }
+
+ }
+
protected void addEntryPoints(Application application, Map<String, String> commonProperties) {
for (String uiName : cmsApp.getUiNames()) {
Map<String, String> properties = new HashMap<>(commonProperties);
@Override
public void exception(final Throwable e) {
+ CmsFeedback.show("Unexpected exception in CMS", e).block();
exception = e;
- log.error("Unexpected exception in CMS", e);
+// log.error("Unexpected exception in CMS", e);
doRefresh();
}
log.error(message, e);
}
- public static void show(String message, Throwable e) {
+ public static CmsFeedback show(String message, Throwable e) {
// rethrow ThreaDeath in order to make sure that RAP will properly clean
// up the UI thread
if (e instanceof ThreadDeath)
CmsFeedback cmsFeedback = new CmsFeedback(null, message, e);
cmsFeedback.setBlockOnOpen(false);
cmsFeedback.open();
+ return cmsFeedback;
} catch (Throwable e1) {
log.error("Cannot open error feedback (" + e.getMessage() + "), original error below", e);
+ return null;
}
}
- public static void show(String message) {
- new CmsFeedback(null, message, null).open();
+ public static CmsFeedback show(String message) {
+ CmsFeedback cmsFeedback = new CmsFeedback(null, message, null);
+ cmsFeedback.open();
+ return cmsFeedback;
}
/** Tries to find a display */
return LocaleUtils.lead(local(locale).toString(), locale);
}
+ static class Untranslated implements Localized {
+ private String msg;
+
+ public Untranslated(String msg) {
+ super();
+ this.msg = msg;
+ }
+
+ @Override
+ public Object local(Locale locale) {
+ return msg;
+ }
+
+ }
}
});
if (block) {
- try {
- runEventLoop(foregoundShell);
- } catch (ThreadDeath t) {
- returnCode = CANCEL;
- if (log.isTraceEnabled())
- log.error("Thread death, canceling dialog", t);
- } catch (Throwable t) {
- returnCode = CANCEL;
- log.error("Cannot open blocking lightweight dialog", t);
- }
+ block();
}
if (returnCode == null)
returnCode = OK;
return returnCode;
}
+ public void block() {
+ try {
+ runEventLoop(foregoundShell);
+ } catch (ThreadDeath t) {
+ returnCode = CANCEL;
+ if (log.isTraceEnabled())
+ log.error("Thread death, canceling dialog", t);
+ } catch (Throwable t) {
+ returnCode = CANCEL;
+ log.error("Cannot open blocking lightweight dialog", t);
+ }
+ }
+
private boolean hasChildShells() {
if (foregoundShell == null)
return false;
}
}
- /** Retrieves the {@link Session} related to this node. */
+ /**
+ * Retrieves the {@link Session} related to this node.
+ *
+ * @deprecated Use {@link #getSession(Node)} instead.
+ */
+ @Deprecated
public static Session session(Node node) {
+ return getSession(node);
+ }
+
+ /** Retrieves the {@link Session} related to this node. */
+ public static Session getSession(Node node) {
try {
return node.getSession();
} catch (RepositoryException e) {
}
}
+ /** Safely and silently logs out the underlying session. */
+ public static void logout(Node node) {
+ Jcr.logout(session(node));
+ }
+
/*
* SECURITY
*/
return res;
}
+ /*
+ * MAP
+ */
+ /**
+ * Creates a new {@link Dictionary} with one key-value pair. Key should not be
+ * null, but if the value is null, it returns an empty {@link Dictionary}.
+ */
+ public static Map<String, Object> map(String key, Object value) {
+ assert key != null;
+ HashMap<String, Object> props = new HashMap<>();
+ if (value != null)
+ props.put(key, value);
+ return props;
+ }
+
/*
* DICTIONARY
*/