public static String getProcessedUrl(StringBuilder url, HttpServletRequest request, HttpServletResponse response) { return getProcessedUrl(url.toString(), request, response); }
private String reportAsConsoleError(String responseAsString, HttpServletRequest request) { StringBuilder alertMessage = new StringBuilder(BASE_MSG_CONSOLE); alertMessage.append(UrlUtils.getCurrentUri(request)); alertMessage.append("?ddl-debug&ddl-debug-page=alerts"); StringBuilder console = new StringBuilder(); console.append("<script type=\"text/javascript\">"); console.append("throw new Error('").append(alertMessage).append("');"); console.append("</script>"); console.append('\n'); console.append(CLOSING_HEAD_TAG); responseAsString = responseAsString.replace(CLOSING_HEAD_TAG, console); return responseAsString; } }
public static boolean doesNotContainParamater(HttpServletRequest request, String parameterName) { return !containsParameter(request, parameterName); }
public static String getContentFromUrl(HttpServletRequest request, String url, boolean neverFail) { try { if (UrlUtils.isProtocolRelative(url)) { url = request.isSecure() ? "https:" : "http:" + url; } if (UrlUtils.isContextRelative(url, request)) { url = UrlUtils.getBaseUrl(request, false) + url; } URL urlLocation = new URL(url); return ResourceUtils.getContentFromInputStream(urlLocation.openStream()); } catch (IOException e) { if (neverFail) { return ""; } StringBuilder sb = new StringBuilder("The content pointed by the url "); sb.append(url); sb.append(" can't be read."); throw new DandelionException(sb.toString(), e); } }
StringBuilder exportUrl = UrlUtils.getCurrentUri(tableConfiguration.getRequest()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f"); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, enabledFormat); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, tableConfiguration.getTableId()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y"); UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false); exportConf = new ExportConf(enabledFormat, UrlUtils.getProcessedUrl(exportUrl, tableConfiguration.getRequest(), tableConfiguration.getResponse()));
private Map<String, Object> getCommonPageContext() { Map<String, Object> commonCtx = new HashMap<String, Object>(); StringBuilder currentUrlWithParams = UrlUtils.getCurrentUrl(context.getRequest(), true); commonCtx.put("currentContextPath", UrlUtils.getContext(context.getRequest()).toString()); String currentUri = UrlUtils.getCurrentUri(context.getRequest()).toString(); String appUri = currentUri.substring(0, currentUri.indexOf(WebConstants.DANDELION_DEBUGGER) - 1); commonCtx.put("currentUri", appUri); StringBuilder debuggerUrl = new StringBuilder(UrlUtils.getContext(context.getRequest())); UrlUtils.addParameter(debuggerUrl, WebConstants.DANDELION_DEBUGGER); commonCtx.put("debuggerUrl", debuggerUrl); UrlUtils.addParameter(debuggerUrlWithParam, WebConstants.DANDELION_DEBUGGER); commonCtx.put("debuggerUrlWithParam", debuggerUrlWithParam); UrlUtils.addParameter(clearStorageUrl, WebConstants.DANDELION_CLEAR_STORAGE); commonCtx.put("clearStorageUrl", clearStorageUrl); UrlUtils.addParameter(clearCacheUrl, WebConstants.DANDELION_CLEAR_CACHE); commonCtx.put("clearCacheUrl", clearCacheUrl); UrlUtils.addParameter(reloadBundleUrl, WebConstants.DANDELION_RELOAD_BUNDLES); commonCtx.put("reloadBundleUrl", reloadBundleUrl); UrlUtils.addParameter(alertReportingUrl, "ddl-debug-page", "alerts"); commonCtx.put("alertReportingUrl", alertReportingUrl);
private String getPage(DebugPage page, HandlerContext context) throws IOException { page.initWith(context); // Get the template String template = page.getTemplate(context); // Inject Mustache context template = template.replace("%CONTEXT%", UrlUtils.getContext(context.getRequest()).toString()); Map<String, String> variables = page.getExtraParams(); if (variables != null) { for (Entry<String, String> variable : variables.entrySet()) { template = template.replace(variable.getKey(), variable.getValue()); } } template = template.replace("%MUSTACHE_CTX%", page.getContext()); return template; } }
/** * <p> * Returns the base URL, with the context path included by default. * * <p> * For Example, for an URL like * {@code http://domain.com:port/context/foo/bar}, this function returns * {@code http://domain.com:port/context}. * * @param request * The {@link HttpServletRequest} from which to extract the base * URL. * @return the base URL of the current request. */ public static String getBaseUrl(HttpServletRequest request) { return getBaseUrl(request, true); }
StringBuilder exportUrl = UrlUtils.getCurrentUri(tableConfiguration.getRequest()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f"); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, enabledFormat); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, tableConfiguration.getTableId()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y"); UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false); exportConf = new ExportConf(enabledFormat, UrlUtils.getProcessedUrl(exportUrl, tableConfiguration.getRequest(), tableConfiguration.getResponse()));
private Map<String, Object> getCommonPageContext() { Map<String, Object> commonCtx = new HashMap<String, Object>(); StringBuilder currentUrlWithParams = UrlUtils.getCurrentUrl(context.getRequest(), true); commonCtx.put("currentContextPath", UrlUtils.getContext(context.getRequest()).toString()); String currentUri = UrlUtils.getCurrentUri(context.getRequest()).toString(); String appUri = currentUri.substring(0, currentUri.indexOf(WebConstants.DANDELION_DEBUGGER) - 1); commonCtx.put("currentUri", appUri); StringBuilder debuggerUrl = new StringBuilder(UrlUtils.getContext(context.getRequest())); UrlUtils.addParameter(debuggerUrl, WebConstants.DANDELION_DEBUGGER); commonCtx.put("debuggerUrl", debuggerUrl); UrlUtils.addParameter(debuggerUrlWithParam, WebConstants.DANDELION_DEBUGGER); commonCtx.put("debuggerUrlWithParam", debuggerUrlWithParam); UrlUtils.addParameter(clearStorageUrl, WebConstants.DANDELION_CLEAR_STORAGE); commonCtx.put("clearStorageUrl", clearStorageUrl); UrlUtils.addParameter(clearCacheUrl, WebConstants.DANDELION_CLEAR_CACHE); commonCtx.put("clearCacheUrl", clearCacheUrl); UrlUtils.addParameter(reloadBundleUrl, WebConstants.DANDELION_RELOAD_BUNDLES); commonCtx.put("reloadBundleUrl", reloadBundleUrl); UrlUtils.addParameter(alertReportingUrl, "ddl-debug-page", "alerts"); commonCtx.put("alertReportingUrl", alertReportingUrl);
public static String getContentFromUrl(HttpServletRequest request, String url, boolean neverFail) { try { if (UrlUtils.isProtocolRelative(url)) { url = request.isSecure() ? "https:" : "http:" + url; } if (UrlUtils.isContextRelative(url, request)) { url = UrlUtils.getBaseUrl(request, false) + url; } URL urlLocation = new URL(url); return ResourceUtils.getContentFromInputStream(urlLocation.openStream()); } catch (IOException e) { if (neverFail) { return ""; } StringBuilder sb = new StringBuilder("The content pointed by the url "); sb.append(url); sb.append(" can't be read."); throw new DandelionException(sb.toString(), e); } }
private String getPage(DebugPage page, HandlerContext context) throws IOException { page.initWith(context); // Get the template String template = page.getTemplate(context); // Inject Mustache context template = template.replace("%CONTEXT%", UrlUtils.getContext(context.getRequest()).toString()); Map<String, String> variables = page.getExtraParams(); if (variables != null) { for (Entry<String, String> variable : variables.entrySet()) { template = template.replace(variable.getKey(), variable.getValue()); } } template = template.replace("%MUSTACHE_CTX%", page.getContext()); return template; } }
/** * <p> * Returns the base URL, with the context path included by default. * * <p> * For Example, for an URL like * {@code http://domain.com:port/context/foo/bar}, this function returns * {@code http://domain.com:port/context}. * * @param request * The {@link HttpServletRequest} from which to extract the base * URL. * @return the base URL of the current request. */ public static String getBaseUrl(HttpServletRequest request) { return getBaseUrl(request, true); }
exportUrl = UrlUtils.getCurrentUri(request); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f"); conf.setHasCustomUrl(false); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "c"); conf.setHasCustomUrl(true); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_NAME, this.fileName); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_EXTENSION, this.fileExtension); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ORIENTATION, orientation); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_MIME_TYPE, mimeType.trim()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_HEADER, includeHeader); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_AUTOSIZE, autoSize); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, parent.getTable().getId()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, format); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y"); UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false); conf.setUrl(UrlUtils.getProcessedUrl(exportUrl, request, response));
public static String getProcessedUrl(StringBuilder url, HttpServletRequest request, HttpServletResponse response) { return getProcessedUrl(url.toString(), request, response); }
private String reportAsConsoleError(String responseAsString, HttpServletRequest request) { StringBuilder alertMessage = new StringBuilder(BASE_MSG_CONSOLE); alertMessage.append(UrlUtils.getCurrentUri(request)); alertMessage.append("?ddl-debug&ddl-debug-page=alerts"); StringBuilder console = new StringBuilder(); console.append("<script type=\"text/javascript\">"); console.append("throw new Error('").append(alertMessage).append("');"); console.append("</script>"); console.append('\n'); console.append(CLOSING_HEAD_TAG); responseAsString = responseAsString.replace(CLOSING_HEAD_TAG, console); return responseAsString; } }
public static boolean doesNotContainParamater(HttpServletRequest request, String parameterName) { return !containsParameter(request, parameterName); }
exportUrl = UrlUtils.getCurrentUri(request); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f"); conf.setHasCustomUrl(false); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "c"); conf.setHasCustomUrl(true); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_NAME, this.fileName); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_EXTENSION, this.fileExtension); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ORIENTATION, orientation); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_MIME_TYPE, mimeType.trim()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_HEADER, includeHeader); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_AUTOSIZE, autoSize); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, parent.getTable().getId()); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, format); UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y"); UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false); conf.setUrl(UrlUtils.getProcessedUrl(exportUrl, request, response));
/** * <p> * May be a runtime expression. * </p> * * @param url */ public void setUrl(String url) { String processedUrl = UrlUtils.getProcessedUrl(url, (HttpServletRequest) this.pageContext.getRequest(), (HttpServletResponse) this.pageContext.getResponse()); this.stagingOptions.put(DatatableOptions.AJAX_SOURCE, processedUrl); this.dataSourceType = SOURCE_AJAX; }
public String generateRequestCacheKey(HttpServletRequest request) { StringBuilder cacheKey = new StringBuilder(UrlUtils.getCurrentUri(request)); return DigestUtils.md5Digest(cacheKey.toString()); }