Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add root path to velocity context #1220

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/ViewAssets.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;

import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -89,16 +89,6 @@ public class StreamingBaseHtmlProvider implements MessageBodyWriter<RdfNamespace
*/
public static final String templatesLocation = "/views";

/**
* Location in the classpath where the common css file is to be found.
*/
public static final String commonCssLocation = "/views/common.css";

/**
* Location in the classpath where the common javascript file is to be found.
*/
public static final String commonJsLocation = "/views/common.js";

/**
* A map from String names for primary node types to the Velocity templates
* that should be used for those node types.
Expand All @@ -117,7 +107,6 @@ public class StreamingBaseHtmlProvider implements MessageBodyWriter<RdfNamespace

@PostConstruct
void init() throws IOException {

LOGGER.trace("Velocity engine initializing...");
final Properties properties = new Properties();
final String fcrepoHome = getProperty("fcrepo.home");
Expand Down Expand Up @@ -165,7 +154,6 @@ public void writeTo(final RdfNamespacedStream nsStream, final Class<?> type,
final OutputStream entityStream) throws IOException {

final Node subject = ViewHelpers.getContentNode(nsStream.stream.topic());

final Model model = nsStream.stream.collect(toModel());
model.setNsPrefixes(nsStream.namespaces);

Expand All @@ -184,6 +172,14 @@ protected Context getContext(final Model model, final Node subject) {
final FieldTool fieldTool = new FieldTool();

final Context context = new VelocityContext();
final String[] baseUrl = uriInfo.getBaseUri().getPath().split("/");
if (baseUrl.length > 0) {
final String staticBaseUrl =
Arrays.asList(Arrays.copyOf(baseUrl, baseUrl.length - 1)).stream().collect(Collectors.joining("/"));
context.put("staticBaseUrl", staticBaseUrl);
} else {
context.put("staticBaseUrl", "/");
}
context.put("rdfLexicon", fieldTool.in(RdfLexicon.class));
context.put("helpers", VIEW_HELPERS);
context.put("esc", escapeTool);
Expand Down
12 changes: 6 additions & 6 deletions fcrepo-http-api/src/main/resources/views/common-head.vsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<link rel="icon" type="image/png" href="$uriInfo.baseUriBuilder.build()../static/images/fcrepo-favicon.png">
<script src="$uriInfo.baseUriBuilder.build()../static/js/jquery-1.9.1.min.js" ></script>
<script src="$uriInfo.baseUriBuilder.build()../static/js/bootstrap-3.0.0.min.js"></script>
<link href="$uriInfo.baseUriBuilder.build()../static/css/bootstrap-3.0.0.min.css" rel="stylesheet">
<script type="text/javascript" src="$uriInfo.baseUriBuilder.build()fcr:assets/common.js"></script>
<link rel="stylesheet" type="text/css" href="$uriInfo.baseUriBuilder.build()fcr:assets/common.css">
<link rel="icon" type="image/png" href="$staticBaseUrl/static/images/fcrepo-favicon.png">
<script src="$staticBaseUrl/static/js/jquery-1.9.1.min.js" ></script>
<script src="$staticBaseUrl/static/js/bootstrap-3.0.0.min.js"></script>
<link href="$staticBaseUrl/static/css/bootstrap-3.0.0.min.css" rel="stylesheet">
<script type="text/javascript" src="$staticBaseUrl/static/js/common.js"></script>
<link rel="stylesheet" type="text/css" href="$staticBaseUrl/static/css/common.css">
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.stream.Stream;

import javax.jcr.NamespaceRegistry;
Expand Down Expand Up @@ -112,6 +113,9 @@ public void setup() throws RepositoryException {

testData2 = new RdfNamespacedStream(stream2, getNamespaces(mockSession));
final UriInfo info = Mockito.mock(UriInfo.class);
final URI baseUri = URI.create("http://localhost:8080/rest/");
when(info.getBaseUri()).thenReturn(baseUri);

setField(testProvider, "uriInfo", info);
}

Expand Down