OSGI-INF/dataServletContext.xml,\
OSGI-INF/filesServletContext.xml,\
OSGI-INF/filesServlet.xml,\
-OSGI-INF/jcrContentProvider.xml
import org.argeo.api.acr.spi.ContentProvider;
import org.argeo.api.acr.spi.ProvidedContent;
import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.api.cms.CmsConstants;
import org.argeo.cms.acr.ContentUtils;
import org.argeo.cms.jcr.CmsJcrUtils;
import org.argeo.jcr.JcrException;
/** A JCR workspace accessed as an {@link ContentProvider}. */
public class JcrContentProvider implements ContentProvider, NamespaceContext {
- public final static String ACR_MOUNT_PATH_PROPERTY = "acr.mount.path";
private Repository jcrRepository;
private Session adminSession;
private Map<ProvidedSession, JcrSessionAdapter> sessionAdapters = Collections.synchronizedMap(new HashMap<>());
public void start(Map<String, String> properties) {
- mountPath = properties.get(ACR_MOUNT_PATH_PROPERTY);
+ mountPath = properties.get(CmsConstants.ACR_MOUNT_PATH);
if ("/".equals(mountPath))
throw new IllegalArgumentException("JCR content provider cannot be root /");
Objects.requireNonNull(mountPath);
String CONTEXT_PATH = "context.path";
String CONTEXT_PUBLIC = "context.public";
String EVENT_TOPICS = "event.topics";
+ String ACR_MOUNT_PATH = "acr.mount.path";
+
/*
* FILE SYSTEM
server.start();
//
+ // Addresses
+ String httpHost = getDeployProperty(CmsDeployProperty.HOST);
+ String fallBackHostname = cmsState != null ? cmsState.getHostname() : "::1";
+ if (httpConnector != null)
+ httpAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname,
+ httpConnector.getLocalPort());
+ if (httpsConnector != null)
+ httpsAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname,
+ httpsConnector.getLocalPort());
+
+ // Clean up
Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(), "Jetty shutdown"));
log.info(httpPortsMsg());
if (httpPortStr != null || httpsPortStr != null) {
// TODO deal with hostname resolving taking too much time
// String fallBackHostname = InetAddress.getLocalHost().getHostName();
- String fallBackHostname = cmsState != null ? cmsState.getHostname() : "::1";
boolean httpEnabled = httpPortStr != null;
// props.put(JettyHttpConstants.HTTP_ENABLED, httpEnabled);
httpConnector.setHost(httpHost);
httpConnector.setIdleTimeout(DEFAULT_IDLE_TIMEOUT);
- httpAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname, httpPort);
}
if (httpsEnabled) {
int httpsPort = Integer.parseInt(httpsPortStr);
httpsConnector.setPort(httpsPort);
httpsConnector.setHost(httpHost);
-
- httpsAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname, httpsPort);
}
}
private final FsContentProvider provider;
private final Path path;
- private final boolean isRoot;
+ private final boolean isMountBase;
private final QName name;
protected FsContent(ProvidedSession session, FsContentProvider contentProvider, Path path) {
super(session);
this.provider = contentProvider;
this.path = path;
- this.isRoot = contentProvider.isMountRoot(path);
+ this.isMountBase = contentProvider.isMountBase(path);
// TODO check file names with ':' ?
- if (isRoot) {
+ if (isMountBase) {
String mountPath = provider.getMountPath();
if (mountPath != null && !mountPath.equals("/")) {
Content mountPoint = session.getMountPoint(mountPath);
@Override
public Content getParent() {
- if (isRoot) {
+ if (isMountBase) {
String mountPath = provider.getMountPath();
if (mountPath == null || mountPath.equals("/"))
return null;
public class FsContentProvider implements ContentProvider {
final static String XMLNS_ = "xmlns:";
- private final String mountPath;
- private final Path rootPath;
-// private final boolean isRoot;
+ protected String mountPath;
+ protected Path rootPath;
private NavigableMap<String, String> prefixes = new TreeMap<>();
initNamespaces();
}
-// @Deprecated
-// public FsContentProvider(String mountPath, Path rootPath, boolean isRoot) {
-// this.mountPath = mountPath;
-// this.rootPath = rootPath;
-//// this.isRoot = isRoot;
-//// initNamespaces();
-// }
+ protected FsContentProvider() {
- private void initNamespaces() {
+ }
+
+ protected void initNamespaces() {
try {
UserDefinedFileAttributeView udfav = Files.getFileAttributeView(rootPath,
UserDefinedFileAttributeView.class);
return mountPath;
}
- boolean isMountRoot(Path path) {
+ boolean isMountBase(Path path) {
try {
return Files.isSameFile(rootPath, path);
} catch (IOException e) {
--- /dev/null
+package org.argeo.cms.acr.fs;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Map;
+import java.util.Objects;
+
+import org.argeo.api.cms.CmsConstants;
+import org.argeo.api.cms.CmsState;
+
+public class FsContentProviderService extends FsContentProvider {
+ private CmsState cmsState;
+
+ public void start(Map<String, String> properties) {
+ mountPath = properties.get(CmsConstants.ACR_MOUNT_PATH);
+ Objects.requireNonNull(mountPath);
+ if (!mountPath.startsWith("/"))
+ throw new IllegalArgumentException("Mount path must start with /");
+
+ String relPath = mountPath.substring(1);
+ rootPath = cmsState.getDataPath(relPath);
+ try {
+ Files.createDirectories(rootPath);
+ } catch (IOException e) {
+ throw new IllegalStateException(
+ "Cannot initialize FS content provider " + mountPath + " with base" + rootPath, e);
+ }
+
+ initNamespaces();
+ }
+
+ public void stop() {
+ }
+
+ public void setCmsState(CmsState cmsState) {
+ this.cmsState = cmsState;
+ }
+
+}