本文整理匯總了Java中org.springframework.web.util.HtmlUtils類的典型用法代碼示例。如果您正苦於以下問題:Java HtmlUtils類的具體用法?Java HtmlUtils怎麽用?Java HtmlUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HtmlUtils類屬於org.springframework.web.util包,在下文中一共展示了HtmlUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: escapeObjectError
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T extends ObjectError> T escapeObjectError(T source) {
if (source == null) {
return null;
}
if (source instanceof FieldError) {
FieldError fieldError = (FieldError) source;
Object value = fieldError.getRejectedValue();
if (value instanceof String) {
value = HtmlUtils.htmlEscape((String) value);
}
return (T) new FieldError(
fieldError.getObjectName(), fieldError.getField(), value,
fieldError.isBindingFailure(), fieldError.getCodes(),
fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
}
else {
return (T) new ObjectError(
source.getObjectName(), source.getCodes(), source.getArguments(),
HtmlUtils.htmlEscape(source.getDefaultMessage()));
}
}
示例2: execute
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
@Override
public GameOutput execute(GameOutput output, Entity entity, String command, String[] tokens, String raw) {
if (StringUtils.isEmpty(raw)) {
output.append("What would you like to shout?");
return output;
}
output.append(String.format("[dyellow]You shout '%s[dyellow]'", HtmlUtils.htmlEscape(raw)));
GameOutput toZone = new GameOutput(String.format("[dyellow]%s shouts '%s[dyellow]'", entity.getName(), HtmlUtils.htmlEscape(raw)));
List<Entity> contents = entityRepository.findByXBetweenAndYBetweenAndZBetween(
entity.getX() - SHOUT_DISTANCE, entity.getX() + SHOUT_DISTANCE,
entity.getY() - SHOUT_DISTANCE, entity.getY() + SHOUT_DISTANCE,
entity.getZ() - SHOUT_DISTANCE, entity.getZ() + SHOUT_DISTANCE
);
contents = contents.stream()
.filter(r -> roomService.isWithinDistance(entity, r.getX(), r.getY(), r.getZ(), SHOUT_DISTANCE))
.collect(Collectors.toList());
entityService.sendMessageToListeners(contents, entity, toZone);
return output;
}
示例3: buildNote
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
protected TableCell buildNote(PreferenceGroup prefGroup, boolean isEditable, UserContext user){
TableCell cell = null;
if (prefGroup instanceof Class_) {
Class_ c = (Class_) prefGroup;
if (c.getNotes() != null && !c.getNotes().trim().isEmpty()) {
if (CommonValues.NoteAsShortText.eq(user.getProperty(UserProperty.ManagerNoteDisplay))) {
String note = (c.getNotes().length() <= 20 ? c.getNotes() : c.getNotes().substring(0, 20) + "...");
cell = initNormalCell(note.replaceAll("\n","<br>"), isEditable);
cell.setAlign("left");
} else if (CommonValues.NoteAsFullText.eq(user.getProperty(UserProperty.ManagerNoteDisplay))) {
cell = initNormalCell(c.getNotes().replaceAll("\n","<br>"), isEditable);
cell.setAlign("left");
} else {
cell = initNormalCell("<IMG border='0' alt='" + MSG.altHasNoteToMgr() + "' title='" + HtmlUtils.htmlEscape(c.getNotes()) + "' align='absmiddle' src='images/note.png'>", isEditable);
cell.setAlign("center");
}
} else {
cell = this.initNormalCell(" " ,isEditable);
}
} else {
cell = this.initNormalCell(" " ,isEditable);
}
return(cell);
}
示例4: main
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
public static void main(String[] args) {
String specialStr = " #測試轉義:#<table id=\"testid\"><tr>test1;test2</tr></table>";
// ①轉換為HTML轉義字符表示
String str1 = HtmlUtils.htmlEscape(specialStr);
System.out.println(str1);
// ②轉換為數據轉義表示
String str2 = HtmlUtils.htmlEscapeDecimal(specialStr);
System.out.println(str2);
//③轉換為十六進製數據轉義表示
String str3 = HtmlUtils.htmlEscapeHex(specialStr);
System.out.println(str3);
// ④下麵對轉義後字符串進行反向操作
System.out.println(HtmlUtils.htmlUnescape(str1));
System.out.println(HtmlUtils.htmlUnescape(str2));
System.out.println(HtmlUtils.htmlUnescape(str3));
}
示例5: largeGrainedTagFilter
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
/**
* 大顆粒標簽過濾(含<>)
* @param value
* @return 返回轉義後的字符
*/
public String largeGrainedTagFilter(String value) {
//標準腳本和HTML<script>alert(999)</script>
//簡化腳本和HTML<script type="" src=""/>
//</script>
Pattern scriptPattern = Pattern.compile("(<(.*?)>(.*)</(.*?)>|<(.*?)/>|</(.*?)>)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
//value = scriptPattern.matcher(value).replaceAll("");
boolean boo = scriptPattern.matcher(value).find();
if(boo){
value = HtmlUtils.htmlEscape(value);
}
System.out.println("1:"+value);
//不規範的腳本<script>
scriptPattern = Pattern.compile("<(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
boo = scriptPattern.matcher(value).find();
if(boo){
value = HtmlUtils.htmlEscape(value);
}
System.out.println(value);
return value;
}
示例6: doEndTagInternal
import org.springframework.web.util.HtmlUtils; //導入依賴的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));
}
}
示例7: createSpeak
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
public static Article createSpeak(Zone zone,
String zoneAliasName,
FlakeId articleId,
Account author,
String title,
String content,
Instant now) {
Preconditions.checkArgument(isValidTitle(title));
Preconditions.checkArgument(isValidContent(content));
String safeTitle = HtmlUtils.htmlEscape(title);
return new Article(zone,
zoneAliasName,
articleId,
safeTitle,
null,
content,
ArticleContentType.MARK_DOWN,
now,
author.getAccountId(),
author.getUsername(),
false,
0,
0,
0);
}
示例8: createExternalLink
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
public static Article createExternalLink(Zone zone,
String zoneAliasName,
FlakeId articleId,
Account author,
String title,
String link,
Instant now) {
Preconditions.checkArgument(isValidTitle(title));
Preconditions.checkArgument(isValidLink(link));
String safeTitle = HtmlUtils.htmlEscape(title);
String safeLink = HtmlUtils.htmlEscape(link);
return new Article(zone,
zoneAliasName,
articleId,
safeTitle,
safeLink,
null,
ArticleContentType.NONE,
now,
author.getAccountId(),
author.getUsername(),
false,
0,
0,
0);
}
示例9: setAsText
import org.springframework.web.util.HtmlUtils; //導入依賴的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);
}
}
示例10: resolveException
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
LOGGER.error("Error when calling web action", exception);
// Compute error message to display
String errorTitle = exception.getClass().getSimpleName().replaceFirst("(Error|Exception)", " Error");
String errorMessage = HtmlUtils.htmlEscape(exception.getMessage()).replace("\n", "<br/>");
ModelAndView modelAndView = new ModelAndView(Constants.VIEW_ERROR);
modelAndView.addObject(Constants.ERROR_TITLE_KEY, errorTitle);
modelAndView.addObject(Constants.ERROR_MESSAGE_KEY, errorMessage);
if (exception instanceof AccessDeniedException || exception instanceof ConfigException) {
modelAndView.addObject(Constants.BLOCKING_ERROR_KEY, Boolean.TRUE);
}
return modelAndView;
}
示例11: add
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
@Override
public Item add(Integer tenantId, String itemId, String itemType, String itemDescription, String url,
String imageurl) {
try {
Object[] args = {tenantId, itemId, itemType, HtmlUtils.htmlEscape(itemDescription), Web.makeUrlSecure(url),
Web.makeUrlSecure(imageurl)};
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemplate().update(PS_ADD_ITEM.newPreparedStatementCreator(args), keyHolder);
return new Item(keyHolder.getKey().toString(), tenantId, itemId, itemType,
HtmlUtils.htmlEscape(itemDescription), Web.makeUrlSecure(url), Web.makeUrlSecure(imageurl),
null, true, new Date().toString());
} catch (Exception e) {
logger.error("An error occured adding an item!", e);
return null;
}
}
示例12: PricePlan
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
/**
* Creates a Price Plan from a raw price plan extracted from RDF
* @param rawPricePlan The raw price plan
* @param offering The offering that contains the price plan
* @throw ParseException When the raw price plan does is not valid
*/
public PricePlan(Map<String, List<Object>> rawPricePlan, Offering offering) throws ParseException {
List<Object> titles = rawPricePlan.get("title");
String title = (titles == null || titles.isEmpty()) ? "" : (String) titles.get(0);
if (title.isEmpty()) {
throw new ParseException("Offering " + offering.getDisplayName() +
" contains a price plan without title");
}
this.title = HtmlUtils.htmlEscape(title);
List<Object> ppDescriptions = rawPricePlan.get("description");
this.comment = (ppDescriptions != null && ppDescriptions.size() == 1) ?
HtmlUtils.htmlEscape((String) ppDescriptions.get(0)) : "";
this.offering = offering;
this.priceComponents = new HashSet<>();
}
示例13: createUrl
import org.springframework.web.util.HtmlUtils; //導入依賴的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;
}
示例14: normalizePseudo
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
public String normalizePseudo(final String pseudo) throws ExecutionException {
if (null == pseudo || pseudo.trim().isEmpty()) {
return new StringBuilder("Ann Onymous #").append(getAnonymousCounter().incrementAndGet()).toString();
} else {
String lpseudo = pseudo.trim();
final Matcher m = Service.PATTERN.matcher(lpseudo);
if (m.matches()) {
if(lpseudo.length() > 40) {
lpseudo = HtmlUtils.htmlEscape(new StringBuilder(lpseudo.substring(0, 40)).append("...").toString());
}
return lpseudo;
} else {
return new StringBuilder("Fucked up #").append(getFuckedupCounter().incrementAndGet()).toString();
}
}
}
示例15: addLink
import org.springframework.web.util.HtmlUtils; //導入依賴的package包/類
/** 글의 http 주소가 있으면 링크로 바꿔줌.
* @param plain
* @return
*/
public static String addLink(String text){
if (text == null) {
return text;
}
String escapedText = HtmlUtils.htmlEscape(text)
.replaceAll("(\\A|\\s)((http|https|ftp|mailto):\\S+)(\\s|\\z)","$1<a href=\"$2\">$2</a>$4");
return escapedText;
}