Java Code Examples for org.springframework.web.util.JavaScriptUtils#javaScriptEscape()

The following examples show how to use org.springframework.web.util.JavaScriptUtils#javaScriptEscape() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagUtils.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
/**
 * リンクとして出力するURLを生成します。
 * @param url パス
 * @param params パスに付与するパラメータ
 * @param pageContext ページコンテキスト
 * @param isHtmlEscape HTMLの特殊文字をエスケープするかどうか
 * @param isJavaScriptEscape JavaScriptの特殊文字をエスケープするかどうか
 * @return パス
 * @throws JspException 予期しない例外
 */
public static String createUrl(String url, Map<String, String[]> params, PageContext pageContext, boolean isHtmlEscape, boolean isJavaScriptEscape) throws JspException {
    HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();

    StringBuilder buffer = new StringBuilder();
    UrlType urlType = getUrlType(url);
    if (urlType == UrlType.CONTEXT_RELATIVE) {
        buffer.append(request.getContextPath());
        if (!url.startsWith("/")) {
            buffer.append("/");
        }
    }
    buffer.append(replaceUriTemplateParams(url, params, pageContext));
    buffer.append(createQueryString(params, (url.indexOf("?") == -1), pageContext));

    String urlStr = buffer.toString();
    if (urlType != UrlType.ABSOLUTE) {
        urlStr = response.encodeURL(urlStr);
    }

    urlStr = isHtmlEscape ? HtmlUtils.htmlEscape(urlStr) : urlStr;
    urlStr = isJavaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr;

    return urlStr;
}
 
Example 2
Source File: UrlTag.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Build the URL for the tag from the tag attributes and parameters.
 * @return the URL value as a String
 */
String createUrl() throws JspException {
	Assert.state(this.value != null, "No value set");
	HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
	HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse();

	StringBuilder url = new StringBuilder();
	if (this.type == UrlType.CONTEXT_RELATIVE) {
		// add application context to url
		if (this.context == null) {
			url.append(request.getContextPath());
		}
		else {
			if (this.context.endsWith("/")) {
				url.append(this.context.substring(0, this.context.length() - 1));
			}
			else {
				url.append(this.context);
			}
		}
	}
	if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
		url.append("/");
	}
	url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams));
	url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1)));

	String urlStr = url.toString();
	if (this.type != UrlType.ABSOLUTE) {
		// Add the session identifier if needed
		// (Do not embed the session identifier in a remote link!)
		urlStr = response.encodeURL(urlStr);
	}

	// HTML and/or JavaScript escape, if demanded.
	urlStr = htmlEscape(urlStr);
	urlStr = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr);

	return urlStr;
}
 
Example 3
Source File: EscapeBodyTag.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public int doAfterBody() throws JspException {
	try {
		String content = readBodyContent();
		// HTML and/or JavaScript escape, if demanded
		content = htmlEscape(content);
		content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
		writeBodyContent(content);
	}
	catch (IOException ex) {
		throw new JspException("Could not write escaped body", ex);
	}
	return (SKIP_BODY);
}
 
Example 4
Source File: HtmlFileTransportHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
	return new DefaultSockJsFrameFormat("<script>\np(\"%s\");\n</script>\r\n") {
		@Override
		protected String preProcessContent(String content) {
			return JavaScriptUtils.javaScriptEscape(content);
		}
	};
}
 
Example 5
Source File: UrlTag.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Build the URL for the tag from the tag attributes and parameters.
 * @return the URL value as a String
 */
String createUrl() throws JspException {
	Assert.state(this.value != null, "No value set");
	HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
	HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse();

	StringBuilder url = new StringBuilder();
	if (this.type == UrlType.CONTEXT_RELATIVE) {
		// add application context to url
		if (this.context == null) {
			url.append(request.getContextPath());
		}
		else {
			if (this.context.endsWith("/")) {
				url.append(this.context.substring(0, this.context.length() - 1));
			}
			else {
				url.append(this.context);
			}
		}
	}
	if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
		url.append("/");
	}
	url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams));
	url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1)));

	String urlStr = url.toString();
	if (this.type != UrlType.ABSOLUTE) {
		// Add the session identifier if needed
		// (Do not embed the session identifier in a remote link!)
		urlStr = response.encodeURL(urlStr);
	}

	// HTML and/or JavaScript escape, if demanded.
	urlStr = htmlEscape(urlStr);
	urlStr = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr);

	return urlStr;
}
 
Example 6
Source File: EscapeBodyTag.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public int doAfterBody() throws JspException {
	try {
		String content = readBodyContent();
		// HTML and/or JavaScript escape, if demanded
		content = htmlEscape(content);
		content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
		writeBodyContent(content);
	}
	catch (IOException ex) {
		throw new JspException("Could not write escaped body", ex);
	}
	return (SKIP_BODY);
}
 
Example 7
Source File: HtmlFileTransportHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
	return new DefaultSockJsFrameFormat("<script>\np(\"%s\");\n</script>\r\n") {
		@Override
		protected String preProcessContent(String content) {
			return JavaScriptUtils.javaScriptEscape(content);
		}
	};
}
 
Example 8
Source File: UrlTag.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build the URL for the tag from the tag attributes and parameters.
 * @return the URL value as a String
 */
String createUrl() throws JspException {
	HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
	HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

	StringBuilder url = new StringBuilder();
	if (this.type == UrlType.CONTEXT_RELATIVE) {
		// add application context to url
		if (this.context == null) {
			url.append(request.getContextPath());
		}
		else {
			if (this.context.endsWith("/")) {
				url.append(this.context.substring(0, this.context.length() - 1));
			}
			else {
				url.append(this.context);
			}
		}
	}
	if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
		url.append("/");
	}
	url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams));
	url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1)));

	String urlStr = url.toString();
	if (this.type != UrlType.ABSOLUTE) {
		// Add the session identifier if needed
		// (Do not embed the session identifier in a remote link!)
		urlStr = response.encodeURL(urlStr);
	}

	// HTML and/or JavaScript escape, if demanded.
	urlStr = htmlEscape(urlStr);
	urlStr = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr);

	return urlStr;
}
 
Example 9
Source File: EscapeBodyTag.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int doAfterBody() throws JspException {
	try {
		String content = readBodyContent();
		// HTML and/or JavaScript escape, if demanded
		content = htmlEscape(content);
		content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
		writeBodyContent(content);
	}
	catch (IOException ex) {
		throw new JspException("Could not write escaped body", ex);
	}
	return (SKIP_BODY);
}
 
Example 10
Source File: UrlTag.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Build the URL for the tag from the tag attributes and parameters.
 * @return the URL value as a String
 * @throws JspException
 */
private String createUrl() throws JspException {
	HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
	HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
	StringBuilder url = new StringBuilder();
	if (this.type == UrlType.CONTEXT_RELATIVE) {
		// add application context to url
		if (this.context == null) {
			url.append(request.getContextPath());
		}
		else {
			if (this.context.endsWith("/")) {
				url.append(this.context.substring(0, this.context.length() - 1));
			}
			else {
				url.append(this.context);
			}
		}
	}
	if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
		url.append("/");
	}
	url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams));
	url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1)));

	String urlStr = url.toString();
	if (this.type != UrlType.ABSOLUTE) {
		// Add the session identifier if needed
		// (Do not embed the session identifier in a remote link!)
		urlStr = response.encodeURL(urlStr);
	}

	// HTML and/or JavaScript escape, if demanded.
	urlStr = htmlEscape(urlStr);
	urlStr = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr;

	return urlStr;
}
 
Example 11
Source File: EscapeBodyTag.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public int doAfterBody() throws JspException {
	try {
		String content = readBodyContent();
		// HTML and/or JavaScript escape, if demanded
		content = htmlEscape(content);
		content = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content;
		writeBodyContent(content);
	}
	catch (IOException ex) {
		throw new JspException("Could not write escaped body", ex);
	}
	return (SKIP_BODY);
}
 
Example 12
Source File: HtmlFileTransportHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
	return new DefaultSockJsFrameFormat("<script>\np(\"%s\");\n</script>\r\n") {
		@Override
		protected String preProcessContent(String content) {
			return JavaScriptUtils.javaScriptEscape(content);
		}
	};
}
 
Example 13
Source File: JsonpPollingTransportHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
	// We already validated the parameter above...
	String callback = getCallbackParam(request);

	return new DefaultSockJsFrameFormat("/**/" + callback + "(\"%s\");\r\n") {
		@Override
		protected String preProcessContent(String content) {
			return JavaScriptUtils.javaScriptEscape(content);
		}
	};
}
 
Example 14
Source File: UtilsFunctionPackage.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * 对值进行JavaScript转义
 *
 * @param input
 *            输入文本
 * @return 转义文本
 */
public String javaScript(String input) {
	return JavaScriptUtils.javaScriptEscape(input);
}