org.springframework.web.util.JavaScriptUtils Java Examples

The following examples show how to use org.springframework.web.util.JavaScriptUtils. 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 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 #3
Source File: ReadTestCaseExecution.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
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()));

        JSONArray bugs = new JSONArray();
        if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null
                && !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugs() != 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 {
            bugs = testCaseExecution.getTestCaseObj().getBugs();
        }
        result.put("bugs", bugs);

        result.put("Comment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getComment()));
        result.put("Priority", JavaScriptUtils.javaScriptEscape(String.valueOf(testCaseExecution.getTestCaseObj().getPriority())));
        result.put("Application", JavaScriptUtils.javaScriptEscape(testCaseExecution.getApplication()));
        result.put("ShortDescription", testCaseExecution.getTestCaseObj().getDescription());

        return result;
    }
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: XssUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static String escape(String content){
	return HtmlUtils.htmlEscape(JavaScriptUtils.javaScriptEscape(content));
}
 
Example #16
Source File: ReadTestCaseExecutionByTag.java    From cerberus-source with GNU General Public License v3.0 4 votes vote down vote up
private JSONObject testCaseExecutionToJSONObject(TestCaseExecution testCaseExecution) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("ID", String.valueOf(testCaseExecution.getId()));
    result.put("QueueID", String.valueOf(testCaseExecution.getQueueID()));
    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("RobotDecli", JavaScriptUtils.javaScriptEscape(testCaseExecution.getRobotDecli()));
    result.put("ManualExecution", JavaScriptUtils.javaScriptEscape(testCaseExecution.getManualExecution()));
    if (testCaseExecution.getExecutor() != null) {
        result.put("Executor", JavaScriptUtils.javaScriptEscape(testCaseExecution.getExecutor()));
    }
    result.put("ControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlStatus()));
    result.put("ControlMessage", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlMessage()));
    result.put("Status", JavaScriptUtils.javaScriptEscape(testCaseExecution.getStatus()));
    result.put("NbExecutions", String.valueOf(testCaseExecution.getNbExecutions()));
    result.put("previousExeId", testCaseExecution.getPreviousExeId());
    if (testCaseExecution.getPreviousExeStatus() != null) {
        result.put("previousExeControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getPreviousExeStatus()));
    }
    if (testCaseExecution.getQueueState() != null) {
        result.put("QueueState", JavaScriptUtils.javaScriptEscape(testCaseExecution.getQueueState()));
    }

    List<JSONObject> testCaseDep = new ArrayList<>();

    if (testCaseExecution.getTestCaseExecutionQueueDepList() != null) {
        for (TestCaseExecutionQueueDep tce : testCaseExecution.getTestCaseExecutionQueueDepList()) {
            JSONObject obj = new JSONObject();
            obj.put("test", tce.getDepTest());
            obj.put("testcase", tce.getDepTestCase());
            testCaseDep.add(obj);
        }
    }
    result.put("TestCaseDep", testCaseDep);

    return result;
}
 
Example #17
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);
}