本文整理汇总了Java中org.springframework.web.util.JavaScriptUtils类的典型用法代码示例。如果您正苦于以下问题:Java JavaScriptUtils类的具体用法?Java JavaScriptUtils怎么用?Java JavaScriptUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaScriptUtils类属于org.springframework.web.util包,在下文中一共展示了JavaScriptUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doEndTagInternal
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* @see MessageTag#doStartTagInternal()
* @should evaluate specified message resolvable
* @should resolve message by code
* @should resolve message in locale that different from default
* @should return code if no message resolved
* @should use body content as fallback if no message resolved
* @should use text attribute as fallback if no message resolved
* @should use body content in prior to text attribute as fallback if no message resolved
* @should ignore fallbacks if tag locale differs from context locale
*/
@Override
protected int doEndTagInternal() throws JspException, IOException {
try {
// Resolve the unescaped message.
String msg = resolveMessage();
// HTML and/or JavaScript escape, if demanded.
msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg;
msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg;
// Expose as variable, if demanded, else write to the page.
String resolvedVar = this.var;
if (resolvedVar != null) {
pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(this.scope));
} else {
writeMessage(msg);
}
return EVAL_PAGE;
}
catch (NoSuchMessageException ex) {
throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
}
}
示例2: setAsText
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* override setAsText method , then register
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (!StringUtils.hasText(text)) {
return;
}else {
String value = text;
if (escapeHTML) {
value = HtmlUtils.htmlEscape(value);
}
if (escapeJavaScript) {
value = JavaScriptUtils.javaScriptEscape(value);
}
super.setValue(value);
}
}
示例3: createUrl
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* リンクとして出力する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;
}
示例4: createUrl
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* 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;
}
示例5: doAfterBody
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
@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);
}
示例6: getFrameFormat
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
@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);
}
};
}
示例7: getFrameFormat
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
@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);
}
};
}
示例8: escapeJavascriptParam
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* 对javascript变量进行转义.
*
* @param str
* js变量
* @return 转义后的字符串
*/
public static String escapeJavascriptParam(String str) {
if (str == null) {
return null;
}
if (str.indexOf('"') != -1) {
Exception e = new Exception("invalid js param:" + str);
logger.error(e.getMessage(), e);
str = str.replace("\"", "");
}
return JavaScriptUtils.javaScriptEscape(str);
}
示例9: setAsText
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (text == null) {
setValue(null);
} else {
String value = text;
if (escapeHTML) {
value = HtmlUtils.htmlEscape(value);
}
if (escapeJavaScript) {
value = JavaScriptUtils.javaScriptEscape(value);
}
setValue(value);
}
}
示例10: doStartTagInternal
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* Resolves the message, escapes it if demanded,
* and writes it to the page (or exposes it as variable).
* @see #resolveMessage()
* @see org.springframework.web.util.HtmlUtils#htmlEscape(String)
* @see org.springframework.web.util.JavaScriptUtils#javaScriptEscape(String)
* @see #writeMessage(String)
*/
@Override
protected final int doStartTagInternal() throws JspException, IOException {
try {
// Resolve the unescaped message.
String msg = resolveMessage();
// HTML and/or JavaScript escape, if demanded.
msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg;
msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg;
// Expose as variable, if demanded, else write to the page.
String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext);
if (resolvedVar != null) {
String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext);
pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope));
}
else {
writeMessage(msg);
}
return EVAL_BODY_INCLUDE;
}
catch (NoSuchMessageException ex) {
throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
}
}
示例11: createUrl
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
/**
* 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 {
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 = isHtmlEscape() ? HtmlUtils.htmlEscape(urlStr) : urlStr;
urlStr = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr;
return urlStr;
}
示例12: doAfterBody
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
@Override
public int doAfterBody() throws JspException {
try {
String content = readBodyContent();
// HTML and/or JavaScript escape, if demanded
content = isHtmlEscape() ? HtmlUtils.htmlEscape(content) : 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);
}
示例13: convertExceptionToJson
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
private void convertExceptionToJson(Throwable ex, WebScriptServletResponse wsr, final HttpServletResponse sr, LocalHttpServletResponse mockHttpServletResponse) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ResponseMapBuilder builder = ResponseMapBuilder.createFailResponseMap().withEntry("event", "exception").withEntry("exception", ex.getClass()).withEntry("message",
JavaScriptUtils.javaScriptEscape(ex.getMessage()));
int status = mockHttpServletResponse.getStatus();
if (HttpServletResponse.SC_OK == status) {
status = HttpServletResponse.SC_BAD_REQUEST;
}
// String errorMessage = ex.getLocalizedMessage();
if (ex instanceof NestedServletException) {
NestedServletException nestedServletException = (NestedServletException) ex;
if (nestedServletException.getCause() != null) {
builder.withEntry("cause", nestedServletException.getCause().getClass());
builder.withEntry("causeMessage", nestedServletException.getCause().getMessage());
if (nestedServletException.getCause() instanceof DataAccessException) {
if (HttpServletResponse.SC_OK == mockHttpServletResponse.getStatus()) {
status = HttpServletResponse.SC_NOT_ACCEPTABLE;
}
}
}
}
// mockHttpServletResponse.sendError(status, errorMessage);
mockHttpServletResponse.setStatus(status);
mockHttpServletResponse.setContentType("application/json");
objectMapper.writeValue(mockHttpServletResponse.getOutputStream(), builder.build());
writeResponseToWebscript(wsr, mockHttpServletResponse);
}
示例14: testCaseExecutionToJSONObject
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
private JSONObject testCaseExecutionToJSONObject(
TestCaseExecution testCaseExecution) throws JSONException {
JSONObject result = new JSONObject();
result.put("ID", String.valueOf(testCaseExecution.getId()));
result.put("Test", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTest()));
result.put("TestCase", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCase()));
result.put("Environment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getEnvironment()));
result.put("Start", testCaseExecution.getStart());
result.put("End", testCaseExecution.getEnd());
result.put("Country", JavaScriptUtils.javaScriptEscape(testCaseExecution.getCountry()));
result.put("Browser", JavaScriptUtils.javaScriptEscape(testCaseExecution.getBrowser()));
result.put("ControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlStatus()));
result.put("ControlMessage", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlMessage()));
result.put("Status", JavaScriptUtils.javaScriptEscape(testCaseExecution.getStatus()));
String bugId;
if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null
&& !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugID() != null) {
bugId = testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID());
bugId = new StringBuffer("<a href='")
.append(bugId)
.append("' target='reportBugID'>")
.append(testCaseExecution.getTestCaseObj().getBugID())
.append("</a>")
.toString();
} else {
bugId = testCaseExecution.getTestCaseObj().getBugID();
}
result.put("BugID", bugId);
result.put("Comment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getComment()));
result.put("Priority", JavaScriptUtils.javaScriptEscape(String.valueOf(testCaseExecution.getTestCaseObj().getPriority())));
result.put("Function", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getFunction()));
result.put("Application", JavaScriptUtils.javaScriptEscape(testCaseExecution.getApplication()));
result.put("ShortDescription", testCaseExecution.getTestCaseObj().getDescription());
return result;
}
示例15: escape
import org.springframework.web.util.JavaScriptUtils; //导入依赖的package包/类
public static String escape(String content){
return HtmlUtils.htmlEscape(JavaScriptUtils.javaScriptEscape(content));
}