@Test public void buildsHyperlinkUriWithAlreadyUrlEncodedTarget() { final URI alreadyEncodedTargetUri = WidgetWorker.buildHyperlinkUri( "&#47;projectmgr&#47;control&#47;EditTaskContents&#63;workEffortId&#61;10003", "plain", new HashMap<>(), null, false, true, true, null, null); assertThat(alreadyEncodedTargetUri, hasProperty("path", equalTo("/projectmgr/control/EditTaskContents"))); assertThat(alreadyEncodedTargetUri, hasProperty("query", equalTo("workEffortId=10003"))); }
public static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response) { String localRequestName = Parser.unescapeEntities(target, true); localRequestName = UtilHttp.encodeBlanks(localRequestName); final URIBuilder uriBuilder; final Map<String, String> additionalParameters = new HashMap<>(); final String uriString; if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); uriString = rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode); } else if (prefix != null) { uriString = prefix + localRequestName; } else { uriString = localRequestName; } } else if ("inter-app".equals(targetType)) { uriString = localRequestName; String externalLoginKey = (String) request.getAttribute("externalLoginKey"); additionalParameters.put("externalLoginKey", externalLoginKey); } else if ("content".equals(targetType)) { uriString = getContentUrl(localRequestName, request); } else { uriString = localRequestName; } try { uriBuilder = new URIBuilder(uriString); } catch (URISyntaxException e) { final String msg = "Syntax error when parsing URI: " + uriString; Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } final String tokenValue = CsrfUtil.generateTokenForNonAjax(request, target); if (isNotEmpty(tokenValue)) { additionalParameters.put(CsrfUtil.getTokenNameNonAjax(), tokenValue); } if (UtilValidate.isNotEmpty(parameterMap)) { parameterMap.forEach(uriBuilder::addParameter); } additionalParameters.forEach(uriBuilder::addParameter); try { return uriBuilder.build(); } catch (URISyntaxException e) { final String msg = "Syntax error when building URI: " + uriBuilder.toString(); Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } }
WidgetWorker { public static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response) { String localRequestName = Parser.unescapeEntities(target, true); localRequestName = UtilHttp.encodeBlanks(localRequestName); final URIBuilder uriBuilder; final Map<String, String> additionalParameters = new HashMap<>(); final String uriString; if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); uriString = rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode); } else if (prefix != null) { uriString = prefix + localRequestName; } else { uriString = localRequestName; } } else if ("inter-app".equals(targetType)) { uriString = localRequestName; String externalLoginKey = (String) request.getAttribute("externalLoginKey"); additionalParameters.put("externalLoginKey", externalLoginKey); } else if ("content".equals(targetType)) { uriString = getContentUrl(localRequestName, request); } else { uriString = localRequestName; } try { uriBuilder = new URIBuilder(uriString); } catch (URISyntaxException e) { final String msg = "Syntax error when parsing URI: " + uriString; Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } final String tokenValue = CsrfUtil.generateTokenForNonAjax(request, target); if (isNotEmpty(tokenValue)) { additionalParameters.put(CsrfUtil.getTokenNameNonAjax(), tokenValue); } if (UtilValidate.isNotEmpty(parameterMap)) { parameterMap.forEach(uriBuilder::addParameter); } additionalParameters.forEach(uriBuilder::addParameter); try { return uriBuilder.build(); } catch (URISyntaxException e) { final String msg = "Syntax error when building URI: " + uriBuilder.toString(); Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } } }
WidgetWorker { public static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response) { String localRequestName = Parser.unescapeEntities(target, true); localRequestName = UtilHttp.encodeBlanks(localRequestName); final URIBuilder uriBuilder; final Map<String, String> additionalParameters = new HashMap<>(); final String uriString; if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); uriString = rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode); } else if (prefix != null) { uriString = prefix + localRequestName; } else { uriString = localRequestName; } } else if ("inter-app".equals(targetType)) { uriString = localRequestName; String externalLoginKey = (String) request.getAttribute("externalLoginKey"); additionalParameters.put("externalLoginKey", externalLoginKey); } else if ("content".equals(targetType)) { uriString = getContentUrl(localRequestName, request); } else { uriString = localRequestName; } try { uriBuilder = new URIBuilder(uriString); } catch (URISyntaxException e) { final String msg = "Syntax error when parsing URI: " + uriString; Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } final String tokenValue = CsrfUtil.generateTokenForNonAjax(request, target); if (isNotEmpty(tokenValue)) { additionalParameters.put(CsrfUtil.getTokenNameNonAjax(), tokenValue); } if (UtilValidate.isNotEmpty(parameterMap)) { parameterMap.forEach(uriBuilder::addParameter); } additionalParameters.forEach(uriBuilder::addParameter); try { return uriBuilder.build(); } catch (URISyntaxException e) { final String msg = "Syntax error when building URI: " + uriBuilder.toString(); Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } } private  WidgetWorker(); }
WidgetWorker { public static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response) { String localRequestName = Parser.unescapeEntities(target, true); localRequestName = UtilHttp.encodeBlanks(localRequestName); final URIBuilder uriBuilder; final Map<String, String> additionalParameters = new HashMap<>(); final String uriString; if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); uriString = rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode); } else if (prefix != null) { uriString = prefix + localRequestName; } else { uriString = localRequestName; } } else if ("inter-app".equals(targetType)) { uriString = localRequestName; String externalLoginKey = (String) request.getAttribute("externalLoginKey"); additionalParameters.put("externalLoginKey", externalLoginKey); } else if ("content".equals(targetType)) { uriString = getContentUrl(localRequestName, request); } else { uriString = localRequestName; } try { uriBuilder = new URIBuilder(uriString); } catch (URISyntaxException e) { final String msg = "Syntax error when parsing URI: " + uriString; Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } final String tokenValue = CsrfUtil.generateTokenForNonAjax(request, target); if (isNotEmpty(tokenValue)) { additionalParameters.put(CsrfUtil.getTokenNameNonAjax(), tokenValue); } if (UtilValidate.isNotEmpty(parameterMap)) { parameterMap.forEach(uriBuilder::addParameter); } additionalParameters.forEach(uriBuilder::addParameter); try { return uriBuilder.build(); } catch (URISyntaxException e) { final String msg = "Syntax error when building URI: " + uriBuilder.toString(); Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } } private  WidgetWorker(); static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap,
                                        String prefix, boolean fullPath, boolean secure, boolean encode,
                                        HttpServletRequest request, HttpServletResponse response); static String getContentUrl(final String location, final HttpServletRequest request); static Element makeHiddenFormLinkAnchorElement(String linkStyle, String description, String confirmation,
                                                          ModelFormField modelFormField, HttpServletRequest request,
                                                          Map<String, Object> context); static Element makeHiddenFormLinkFormElement(String target, String targetType,
                                              String targetWindow, Map<String, String> parameterMap,
                                              ModelFormField modelFormField, HttpServletRequest request,
                                              HttpServletResponse response, Map<String, Object> context); static String makeLinkHiddenFormName(Map<String, Object> context, ModelFormField modelFormField); static String determineAutoLinkType(String linkType, String target, String targetType, HttpServletRequest request); static String getScriptLocation(String combinedName); static String getScriptMethodName(String combinedName); static int getPaginatorNumber(Map<String, Object> context); static void incrementPaginatorNumber(Map<String, Object> context); static LocalDispatcher getDispatcher(Map<String, Object> context); static Delegator getDelegator(Map<String, Object> context); }
WidgetWorker { public static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response) { String localRequestName = Parser.unescapeEntities(target, true); localRequestName = UtilHttp.encodeBlanks(localRequestName); final URIBuilder uriBuilder; final Map<String, String> additionalParameters = new HashMap<>(); final String uriString; if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); uriString = rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode); } else if (prefix != null) { uriString = prefix + localRequestName; } else { uriString = localRequestName; } } else if ("inter-app".equals(targetType)) { uriString = localRequestName; String externalLoginKey = (String) request.getAttribute("externalLoginKey"); additionalParameters.put("externalLoginKey", externalLoginKey); } else if ("content".equals(targetType)) { uriString = getContentUrl(localRequestName, request); } else { uriString = localRequestName; } try { uriBuilder = new URIBuilder(uriString); } catch (URISyntaxException e) { final String msg = "Syntax error when parsing URI: " + uriString; Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } final String tokenValue = CsrfUtil.generateTokenForNonAjax(request, target); if (isNotEmpty(tokenValue)) { additionalParameters.put(CsrfUtil.getTokenNameNonAjax(), tokenValue); } if (UtilValidate.isNotEmpty(parameterMap)) { parameterMap.forEach(uriBuilder::addParameter); } additionalParameters.forEach(uriBuilder::addParameter); try { return uriBuilder.build(); } catch (URISyntaxException e) { final String msg = "Syntax error when building URI: " + uriBuilder.toString(); Debug.logError(e, msg, MODULE); throw new RuntimeException(msg, e); } } private  WidgetWorker(); static URI buildHyperlinkUri(String target, String targetType, Map<String, String> parameterMap,
                                        String prefix, boolean fullPath, boolean secure, boolean encode,
                                        HttpServletRequest request, HttpServletResponse response); static String getContentUrl(final String location, final HttpServletRequest request); static Element makeHiddenFormLinkAnchorElement(String linkStyle, String description, String confirmation,
                                                          ModelFormField modelFormField, HttpServletRequest request,
                                                          Map<String, Object> context); static Element makeHiddenFormLinkFormElement(String target, String targetType,
                                              String targetWindow, Map<String, String> parameterMap,
                                              ModelFormField modelFormField, HttpServletRequest request,
                                              HttpServletResponse response, Map<String, Object> context); static String makeLinkHiddenFormName(Map<String, Object> context, ModelFormField modelFormField); static String determineAutoLinkType(String linkType, String target, String targetType, HttpServletRequest request); static String getScriptLocation(String combinedName); static String getScriptMethodName(String combinedName); static int getPaginatorNumber(Map<String, Object> context); static void incrementPaginatorNumber(Map<String, Object> context); static LocalDispatcher getDispatcher(Map<String, Object> context); static Delegator getDelegator(Map<String, Object> context);  }