import org.osgi.service.event.EventAdmin;
/** The {@link CmsView} for a {@link CmsWebApp}. */
+@SuppressWarnings("restriction")
public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationListener {
private static final long serialVersionUID = 7733510691684570402L;
private final static Log log = LogFactory.getLog(CmsWebEntryPoint.class);
return loginContext.getSubject();
}
+ public <T> T doAs(PrivilegedAction<T> action) {
+ return Subject.doAs(getSubject(), action);
+ }
+
@Override
public boolean isAnonymous() {
return CurrentUser.isAnonymous(getSubject());
package org.argeo.cms.ui;
+import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
properties.put(param, value);
sendEvent(topic, properties);
}
-
+
default void applyStyles(Object widget) {
-
+
+ }
+
+ default <T> T doAs(PrivilegedAction<T> action) {
+ throw new UnsupportedOperationException();
}
static CmsView getCmsView(Control parent) {
* FORM LAYOUT
*/
- public static FormData coversAll() {
+ public static FormData coverAll() {
FormData fdLabel = new FormData();
fdLabel.top = new FormAttachment(0, 0);
fdLabel.left = new FormAttachment(0, 0);
}
currentUiProvider = uiProvider;
section.setNode(context);
- section.setLayoutData(CmsUiUtils.coversAll());
+ section.setLayoutData(CmsUiUtils.coverAll());
build(section, uiProvider, context);
if (sections.size() == 0)
sections.add(section);
int currentIndex = sections.indexOf(currentSection);
Section previousSection = new Section(body, SWT.NONE, context);
build(previousSection, previousUiProvider, previousNode);
- previousSection.setLayoutData(CmsUiUtils.coversAll());
+ previousSection.setLayoutData(CmsUiUtils.coverAll());
// sections.remove(currentSection);
sections.add(currentIndex + 1, previousSection);
// sections.add(currentSection);
--- /dev/null
+package org.argeo.cms.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.FileSystem;
+import java.nio.file.Path;
+import java.nio.file.spi.FileSystemProvider;
+
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+
+import org.argeo.api.NodeConstants;
+import org.argeo.jcr.Jcr;
+
+/** Utilities around documents. */
+public class CmsFsUtils {
+ // TODO make it more robust and configurable
+ private static String baseWorkspaceName = NodeConstants.SYS_WORKSPACE;
+
+ public static Node getNode(Repository repository, Path path) {
+ String workspaceName = path.getNameCount() == 0 ? baseWorkspaceName : path.getName(0).toString();
+ String jcrPath = '/' + path.subpath(1, path.getNameCount()).toString();
+ try {
+ Session newSession;
+ try {
+ newSession = repository.login(workspaceName);
+ } catch (NoSuchWorkspaceException e) {
+ // base workspace
+ newSession = repository.login(baseWorkspaceName);
+ jcrPath = path.toString();
+ }
+ return newSession.getNode(jcrPath);
+ } catch (RepositoryException e) {
+ throw new IllegalStateException("Cannot get node from path " + path, e);
+ }
+ }
+
+ public static NodeIterator getLastUpdatedDocuments(Session session) {
+ try {
+ String qStr = "//element(*, nt:file)";
+ qStr += " order by @jcr:lastModified descending";
+ QueryManager queryManager = session.getWorkspace().getQueryManager();
+ @SuppressWarnings("deprecation")
+ Query xpathQuery = queryManager.createQuery(qStr, Query.XPATH);
+ xpathQuery.setLimit(8);
+ NodeIterator nit = xpathQuery.execute().getNodes();
+ return nit;
+ } catch (RepositoryException e) {
+ throw new IllegalStateException("Unable to retrieve last updated documents", e);
+ }
+ }
+
+ public static Path getPath(FileSystemProvider nodeFileSystemProvider, URI uri) {
+ try {
+ FileSystem fileSystem = nodeFileSystemProvider.getFileSystem(uri);
+ if (fileSystem == null)
+ fileSystem = nodeFileSystemProvider.newFileSystem(uri, null);
+ String path = uri.getPath();
+ return fileSystem.getPath(path);
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to initialise file system for " + uri, e);
+ }
+ }
+
+ public static Path getPath(FileSystemProvider nodeFileSystemProvider, Node node) {
+ String workspaceName = Jcr.getWorkspaceName(node);
+ String fullPath = baseWorkspaceName.equals(workspaceName) ? Jcr.getPath(node)
+ : '/' + workspaceName + Jcr.getPath(node);
+ URI uri;
+ try {
+ uri = new URI(NodeConstants.SCHEME_NODE, null, fullPath, null);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Cannot interpret " + fullPath + " as an URI", e);
+ }
+ return getPath(nodeFileSystemProvider, uri);
+ }
+
+ /** Singleton. */
+ private CmsFsUtils() {
+ }
+}
import java.nio.file.FileSystem;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.Path;
+import java.nio.file.spi.FileSystemProvider;
import java.util.HashMap;
import java.util.Map;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
+/** Implementation of an {@link FileSystemProvider} based on Jackrabbit. */
public class CmsFsProvider extends AbstractJackrabbitFsProvider {
private Map<String, CmsFileSystem> fileSystems = new HashMap<>();
import org.apache.commons.logging.LogFactory;
import org.argeo.api.NodeConstants;
import org.argeo.api.NodeState;
-import org.argeo.cms.CmsException;
import org.argeo.cms.LocaleUtils;
import org.argeo.transaction.simple.SimpleTransactionManager;
import org.argeo.util.LangUtils;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.cm.ManagedServiceFactory;
+/**
+ * Implementation of a {@link NodeState}, initialising the required services.
+ */
public class CmsState implements NodeState {
private final static Log log = LogFactory.getLog(CmsState.class);
private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
throw new UnsupportedOperationException(
"Bitronix is not supported anymore, but could be again if there is enough interest.");
} else {
- throw new CmsException("Usupported transaction manager type " + tmType);
+ throw new IllegalArgumentException("Usupported transaction manager type " + tmType);
}
// POI
RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
stopHooks.add(() -> repositoryServiceFactory.shutdown());
bc.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
- LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
+ LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
NodeRepositoryFactory repositoryFactory = new NodeRepositoryFactory();
bc.registerService(RepositoryFactory.class, repositoryFactory, null);
NodeUserAdmin userAdmin = new NodeUserAdmin(NodeConstants.ROLES_BASEDN, NodeConstants.TOKENS_BASEDN);
stopHooks.add(() -> userAdmin.destroy());
bc.registerService(ManagedServiceFactory.class, userAdmin,
- LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_USER_ADMIN_PID));
+ LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_USER_ADMIN_PID));
// File System
CmsFsProvider cmsFsProvider = new CmsFsProvider();
// log.debug("Installed FileSystemProvider " + fsp);
// }
bc.registerService(FileSystemProvider.class, cmsFsProvider,
- LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_FS_PROVIDER_PID));
+ LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_FS_PROVIDER_PID));
}
private void initSimpleTransactionManager() {