package org.argeo.api.acr;
-import javax.xml.namespace.QName;
-
/** Standard names. */
-public enum CrName {
+public enum CrName implements QNamed {
/*
* TYPES
* ATTRIBUTES
*/
uuid, // the UUID of a content
- mount,
+ mount, // a mount point
cc, // content class
/*
public final static String ROLE_NAMESPACE_URI = "http://www.argeo.org/ns/role";
public final static String ROLE_DEFAULT_PREFIX = "role";
- private final ContentName value;
-
- CrName() {
- value = new ContentName(CR_NAMESPACE_URI, name(), RuntimeNamespaceContext.getNamespaceContext());
- }
-
- public QName qName() {
- return value;
- }
+// private final ContentName value;
-// @Override
-// public String getNamespaceURI() {
-// return CR_NAMESPACE_URI;
+// CrName() {
+// value = new ContentName(CR_NAMESPACE_URI, name(), RuntimeNamespaceContext.getNamespaceContext());
// }
//
-// @Override
-// public String getDefaultPrefix() {
-// return CR_DEFAULT_PREFIX;
+// public QName qName() {
+// return value;
// }
+ @Override
+ public String getNamespace() {
+ return CR_NAMESPACE_URI;
+ }
+
+ @Override
+ public String getDefaultPrefix() {
+ return CR_DEFAULT_PREFIX;
+ }
+
}
String PUBLIC_WORKSPACE = "public";
String SECURITY_WORKSPACE = "security";
String MIGRATION_WORKSPACE = "migration";
-
+
/*
* ACR CONVENTIONS
*/
String SRV_BASE = "/srv";
-
/*
* BASE DNs
String PATH_JCR = "/jcr";
String PATH_FILES = "/files";
// String PATH_JCR_PUB = "/pub";
+ String PATH_API_ACR = "/api/acr";
/*
* FILE SYSTEMS
<provide interface="com.sun.net.httpserver.HttpHandler"/>
</service>
<property name="context.path" type="String" value="/api/acr" />
+ <reference bind="setContentRepository" cardinality="1..1" interface="org.argeo.api.acr.spi.ProvidedRepository" name="ProvidedRepository" policy="static"/>
</scr:component>
@Override
public Content get(String path) {
+ if (!path.startsWith(ContentUtils.ROOT_SLASH))
+ throw new IllegalArgumentException(path + " is not an absolute path");
ContentProvider contentProvider = contentRepository.getMountManager().findContentProvider(path);
String mountPath = contentProvider.getMountPath();
String relativePath = extractRelativePath(mountPath, path);
package org.argeo.cms.internal.runtime;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+
+import org.argeo.api.acr.Content;
+import org.argeo.api.acr.ContentSession;
+import org.argeo.api.acr.CrName;
+import org.argeo.api.acr.spi.ProvidedRepository;
+import org.argeo.cms.acr.ContentUtils;
+import org.argeo.cms.auth.RemoteAuthUtils;
+import org.argeo.cms.internal.http.RemoteAuthHttpExchange;
+import org.argeo.util.StreamUtils;
import org.argeo.util.dav.DavServerHandler;
+import org.argeo.util.http.HttpResponseStatus;
+import org.argeo.util.http.HttpServerUtils;
+
+import com.sun.net.httpserver.HttpExchange;
+
+public class CmsAcrHttpHandler extends DavServerHandler {
+ private ProvidedRepository contentRepository;
+
+ @Override
+ protected void handleGET(HttpExchange exchange) {
+ ContentSession session = RemoteAuthUtils.doAs(() -> contentRepository.get(),
+ new RemoteAuthHttpExchange(exchange));
+ String relativePath = HttpServerUtils.relativize(exchange);
+ Content content = session.get(ContentUtils.ROOT_SLASH + relativePath);
+ Optional<Long> size = content.get(CrName.size, Long.class);
+ try (InputStream in = content.open(InputStream.class)) {
+ exchange.sendResponseHeaders(HttpResponseStatus.OK.getStatusCode(), size.orElse(0l));
+ StreamUtils.copy(in, exchange.getResponseBody());
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot process " + relativePath, e);
+ }
+ }
-public class CmsAcrHttpHandler extends DavServerHandler {
+ public void setContentRepository(ProvidedRepository contentRepository) {
+ this.contentRepository = contentRepository;
+ }
}
import javax.xml.namespace.QName;
public class DavResponse {
- final static String MODE_DAV_NAMESPACE = "http://apache.org/dav/props/";
+ final static String MOD_DAV_NAMESPACE = "http://apache.org/dav/props/";
private String href;
private boolean collection;
public void handle(HttpExchange exchange) throws IOException {
String method = exchange.getRequestMethod();
if (DavMethod.PROPFIND.name().equals(method)) {
- handle(exchange);
+ handlePROPFIND(exchange);
} else if (HttpMethod.GET.name().equals(method)) {
- exchange.getResponseBody().write("Hello Dav!".getBytes());
+ handleGET(exchange);
} else {
throw new IllegalArgumentException("Unsupported method " + method);
}
}
+ protected void handleGET(HttpExchange exchange) {
+ throw new UnsupportedOperationException();
+ }
+
protected DavResponse handlePROPFIND(HttpExchange exchange) {
- return null;
+ throw new UnsupportedOperationException();
}
}
value = reader.getText();
}
- if (name.getNamespaceURI().equals(DavResponse.MODE_DAV_NAMESPACE))
+ if (name.getNamespaceURI().equals(DavResponse.MOD_DAV_NAMESPACE))
continue elements; // skip mod_dav properties
assert currentResponse != null;
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
*/
public enum HttpResponseStatus {
+ // Successful responses (200–299)
+ OK(200), //
+ // Client error responses (400–499)
UNAUTHORIZED(401), //
FORBIDDEN(403), //
- NOT_FOUND(404),//
+ NOT_FOUND(404), //
;
private final int statusCode;
/** A path in the node repository */
protected String getDataPath(Content node) {
// TODO make it more configurable?
- StringBuilder buf = new StringBuilder(CmsConstants.PATH_DATA);
+ StringBuilder buf = new StringBuilder(CmsConstants.PATH_API_ACR);
buf.append(node.getPath());
return buf.toString();
}