protected String href(String link) { final RequestInfo pg = RequestInfo.get(); link += ".html"; // encode as relative or absolute depending on the link type if (link.startsWith("/")) { // absolute, encode from "root" return pg.servletURI(link); } else { // encode as relative return pg.pageURI(link); } } }
@Override public boolean preHandle( HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { RequestInfo.set(new RequestInfo(request)); return true; } }
public String pageURI(String path) { return buildURI(pagePath, path); }
protected static String href(String path) { return ResponseUtils.buildURL( RequestInfo.get().servletURI("resource/"), ResponseUtils.urlEncode(path, '/'), null, URLMangler.URLType.RESOURCE); }
if (template == null) template = tryLoadTemplate(configuration, templateName + ".ftl"); final RequestInfo requestInfo = RequestInfo.get(); String pagePath = requestInfo.getPagePath(); String r = pagePath.substring(pagePath.lastIndexOf('/') + 1);
/** * Gets the base URL of the server, this value is retrieved from the current HTTP request. If no * HTTP request is in progress NULL is returned. Only the use cases where an OWS service or a * REST end-point was target are handled. */ private static String baseUrl() { // let's see if a OWS service was targeted Request owsRequest = Dispatcher.REQUEST.get(); if (owsRequest != null) { // retrieve the base URL from the dispatcher request return RequestUtils.baseURL(Dispatcher.REQUEST.get().getHttpRequest()); } // let's see if a REST end-point was targeted RequestInfo restRequest = RequestInfo.get(); if (restRequest != null) { // retrieve the base URL from REST request return restRequest.getBaseURL(); } // no HTTP request is in progress return null; } }
/** * Add {@link RequestInfo} to the freemarker model * * @param model * @throws TemplateModelException */ protected void setRequestInfo(SimpleHash model) throws TemplateModelException { final RequestInfo requestInfo = RequestInfo.get(); if (model.get("page") == null) { if (requestInfo != null) { model.put("page", requestInfo); } } }
/** * Constructs a {@link RequestInfo} object, generating content based on the passed request. * * @param request */ public RequestInfo(HttpServletRequest request) { // http://host:port/appName baseURL = request.getRequestURL() .toString() .replace(request.getRequestURI(), request.getContextPath()); servletPath = request.getServletPath(); pagePath = request.getServletPath() + request.getPathInfo(); setQueryMap(request.getParameterMap()); // strip off the extension extension = ResponseUtils.getExtension(pagePath); if (extension != null) { pagePath = pagePath.substring(0, pagePath.length() - extension.length() - 1); } // trim leading slash if (pagePath.endsWith("/")) { pagePath = pagePath.substring(0, pagePath.length() - 1); } }
public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { String ref; // Special case for layer list, to handle the non-workspace-specific // endpoint for layers if (clazz.equals(LayerInfo.class) && OwsUtils.getter(clazz, "prefixedName", String.class) != null && RequestInfo.get() != null && !RequestInfo.get().getPagePath().contains("/workspaces/")) { ref = (String) OwsUtils.get(source, "prefixedName"); } else if (OwsUtils.getter(clazz, "name", String.class) != null) { ref = (String) OwsUtils.get(source, "name"); } else if (OwsUtils.getter(clazz, "id", String.class) != null) { ref = (String) OwsUtils.get(source, "id"); } else if (OwsUtils.getter(clazz, "id", Long.class) != null) { // For some reason Importer objects have Long ids so this catches that // case ref = OwsUtils.get(source, "id").toString(); } else { throw new RuntimeException( "Could not determine identifier for: " + clazz.getName()); } writer.startNode("name"); writer.setValue(ref); writer.endNode(); encodeLink(encode(ref), writer); }
@GetMapping( value = {"", "index"}, produces = {MediaType.TEXT_HTML_VALUE} ) public RestWrapper get() { SimpleHash model = new SimpleHash(); model.put("links", getLinks()); model.put("page", RequestInfo.get()); return wrapObject(model, SimpleHash.class); }
protected String href(String link) { final RequestInfo pg = RequestInfo.get(); String ext = getExtension(); if (ext != null && ext.length() > 0) link = link + "." + ext; // encode as relative or absolute depending on the link type if (link.startsWith("/")) { // absolute, encode from "root" return pg.servletURI(link); } else { // encode as relative return pg.pageURI(link); } }
public String servletURI(String path) { return buildURI(servletPath, path); }