本文整理汇总了Java中org.apache.commons.lang3.StringEscapeUtils类的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils类的具体用法?Java StringEscapeUtils怎么用?Java StringEscapeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringEscapeUtils类属于org.apache.commons.lang3包,在下文中一共展示了StringEscapeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeURIinUTF8
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
public static String encodeURIinUTF8(String uri) {
if (uri.startsWith("<http://dbpedia.org/resource/")) {
int splitPoint = uri.lastIndexOf("/")+1;
String infix = uri.substring(splitPoint, uri.length()-1);
if (infix.contains("%")) {
return uri;
}
try {
infix = infix.replace("\\\\", "\\");
infix = StringEscapeUtils.unescapeJava(infix);
infix = URLEncoder.encode(infix, "UTF-8");
} catch (UnsupportedEncodingException ex) {
System.err.println("Encoding exception: "+ex);
}
uri = uri.substring(0, splitPoint) + infix + ">";
}
return uri;
}
示例2: abbr
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* 缩略字符串(不区分中英文字符)
*
* @param str 目标字符串
* @param length 截取长度
* @return
*/
public static String abbr(String str, int length) {
if (str == null) {
return "";
}
try {
StringBuilder sb = new StringBuilder();
int currentLength = 0;
for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) {
currentLength += String.valueOf(c).getBytes("GBK").length;
if (currentLength <= length - 3) {
sb.append(c);
} else {
sb.append("...");
break;
}
}
return sb.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
示例3: doPost
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* doPost method to handle operations: like review, save hotel, check Expedia link.
*
* @param request
* @param response
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
List<String> types = getTypes();
String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
String id = StringEscapeUtils.escapeHtml4(request.getParameter("id"));
String username = getUsername(request);
PrintWriter out = response.getWriter();
if (username != null && types.contains(type)) {
try {
out.println(dbhandler.setLike(type, id, username));
}
catch (SQLException e) {
System.out.println(e);
}
}
}
示例4: prepareBugDescriptionForBugCreation
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* Prepares the description of bug body. By adding build url, a nice header, a note and
* excaptes html tags, json tags.
*
* @param description
* @return
*/
private String prepareBugDescriptionForBugCreation(String description)
{
description = "*[Automation failed tests]*\n" +
"||Testcase failing|| Parameters||\n" +
description + "\n" +
System.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS,
configuration.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS, "")) + "\n" +
"Build url: " + buildUrl;
description = description + "\n\n\n" + "Note: This bug is created automatically by DolphinNG." +
" Please do not edit summary line of the bug.";
description = StringEscapeUtils.escapeHtml3(description);
description = StringEscapeUtils.escapeHtml4(description);
description = JSONObject.escape(description);
return description;
}
示例5: apply
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
@Override
public void apply(ApiRequest request, ApiResponse response, WebSocketSession session) {
String msg = StringEscapeUtils.escapeHtml4(request.getMsg());
if (StringUtils.isBlank(msg)) {
return;
}
Map<String, Object> attributes = session.getAttributes();
String id = session.getId();
DrawPlayerInfo info = ((DrawPlayerInfo) attributes.get("info"));
DrawGuessContext ctx = (DrawGuessContext) attributes.get("ctx");
DrawGameStatus status = ctx.status();
ArrayList<String> msgs = new ArrayList<>(2);
if (status == DrawGameStatus.RUN) {
if (StringUtils.equals(id, ctx.getCurrentUser())) {
protectSecret(info, ctx, msg, msgs);
} else {
processGussPerson(info, ctx, msg, msgs);
}
} else {
msgs.add("<b>" + info.getName() + "</b>: " + msg);
}
response.setCode(DrawCode.DRAW_MSG.getCode()).setData(msgs);
}
示例6: createInstance
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* Creates a new chat instance.
*
* @return The unique id that identifies the created instance
*/
public String createInstance() {
final String query = this.mServiceUrl + CREATE_REQUEST;
try {
final List<String> content = getWebContent(query);
// If the answer is empty there was some error
if (content.isEmpty()) {
return null;
}
// The first line contains the id
final String firstLine = content.iterator().next();
if (firstLine.trim().isEmpty()) {
return null;
}
return StringEscapeUtils.unescapeHtml4(firstLine);
} catch (final IOException e) {
// Ignore the exception and return null
return null;
}
}
示例7: convertMessage
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
private String convertMessage(String message, Map<String, String> headers) {
String newMessage = message;
JsonElement msgRootElement = parser.parse(message);
if (msgRootElement instanceof JsonObject) {
JsonObject msgRoot = (JsonObject)msgRootElement;
JsonElement element = msgRoot.get(PAYLOAD_ELEMENT_KEY);
if (element != null) {
if (!element.isJsonObject()) {
//convert payLoad to a json object if it is not already
msgRoot.remove(PAYLOAD_ELEMENT_KEY);
String realPayload = element.getAsString();
String escapedPayload = StringEscapeUtils.unescapeJava(realPayload);
msgRoot.add(PAYLOAD_ELEMENT_KEY, parser.parse(escapedPayload));
}
}
JsonElement hdrElement = GSON.toJsonTree(headers);
msgRoot.add("msgHeaders", hdrElement);
newMessage = GSON.toJson(msgRoot);
if (logger.isDebugEnabled()) {
logger.debug("message to be indexed " + newMessage);
}
}
return newMessage;
}
示例8: annotationToJson
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
public static String annotationToJson(SpanAnnotation annotation) {
StringBuilder sb = new StringBuilder("{\n");
sb.append("name : '").append(annotation.getName()).append("',\n");
sb.append("startToken : sentence[").append(annotation.getStartTokenIndex()).append("],\n");
sb.append("endToken : sentence[").append(annotation.getEndTokenIndex()).append("]\n");
if (annotation.getFeatures().size() > 0) {
sb.append(",features:{");
for (Map.Entry<String, String> entry : annotation.getFeatures().entrySet()) {
sb.append("\"").append(StringEscapeUtils.escapeEcmaScript(entry.getKey())).append("\" : \"").append(StringEscapeUtils.escapeEcmaScript(entry.getValue())).append("\",\n");
}
sb.delete(sb.length() - 2, sb.length());
sb.append("}");
}
sb.append("}");
return sb.toString();
}
示例9: findCrumb
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
public String findCrumb(List<String> lines) {
String crumb = "";
String rtn = "";
for (String l : lines) {
if (l.indexOf("CrumbStore") > -1) {
rtn = l;
break;
}
}
// ,"CrumbStore":{"crumb":"OKSUqghoLs8"
if (rtn != null && !rtn.isEmpty()) {
String[] vals = rtn.split(":"); // get third item
crumb = vals[2].replace("\"", ""); // strip quotes
crumb = StringEscapeUtils.unescapeJava(crumb); // unescape escaped values (particularly, \u002f
}
return crumb;
}
示例10: doPost
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* doPost method to display "who liked this review" modal data.
*
* @param request
* @param response
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
String id = StringEscapeUtils.escapeHtml4(request.getParameter("id"));
PrintWriter out = response.getWriter();
if (getUsername(request) != null) {
try {
if (type.equals("review")) {
out.println(showReviewLikes(id));
}
}
catch (SQLException e){
System.out.println(e);
}
}
}
示例11: doGet
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* doGet method to display the body and footer of review modal.
*
* @param request
* @param response
* @throws IOException
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
String id = StringEscapeUtils.escapeHtml4(request.getParameter("id"));
StringBuilder sb = new StringBuilder();
PrintWriter out = response.getWriter();
if (getUsername(request) != null) {
try {
sb.append(body(id, type));
sb.append(footer(type));
out.println(sb.toString());
}
catch (SQLException e) {
System.out.println(e);
}
}
}
示例12: review
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
/**
* Displays a review apply.
*
* @param model
* @param id
* @return
* @throws ShepherException
*/
@RequestMapping(value = "reviews/{id}", method = RequestMethod.GET)
public String review(Model model, @PathVariable(value = "id") long id) throws ShepherException {
ReviewRequest reviewRequest = reviewService.get(id);
if (reviewRequest == null) {
throw ShepherException.createNoSuchReviewException();
}
reviewService.rejectIfExpired(reviewRequest);
model.addAttribute("clusters", ClusterUtil.getClusters());
model.addAttribute("cluster", reviewRequest.getCluster());
model.addAttribute("paths", reviewRequest.getPath().split("/"));
model.addAttribute("reviewRequest", reviewRequest);
model.addAttribute("content", StringEscapeUtils.escapeHtml4(reviewRequest.getSnapshotContent()));
model.addAttribute("newContent", StringEscapeUtils.escapeHtml4(reviewRequest.getNewSnapshotContent()));
String backPath = reviewRequest.getPath();
if (reviewRequest.getAction() == Action.DELETE.getValue()) {
backPath = ParentPathParser.getParent(backPath);
}
model.addAttribute("backPath", backPath);
model.addAttribute("canReview", permissionService.isPathMaster(userHolder.getUser().getName(),
reviewRequest.getCluster(), reviewRequest.getPath()));
return "review/review";
}
示例13: getTitle
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
public final String getTitle(String s) {
int start = s.indexOf(XML_START_TAG_TITLE);
int end = s.indexOf(XML_END_TAG_TITLE, start);
if (start < 0 || end < 0) {
return "";
}
return StringEscapeUtils.unescapeHtml4(s.substring(start + 7, end));
}
示例14: getClassInitBodyUnescaped
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
public String getClassInitBodyUnescaped(){
if(classInitBody==null)
return null;
Pattern pattern = Pattern.compile("\\t+");
Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeJava(this.classInitBody));
StringBuilder sb=new StringBuilder(StringEscapeUtils.unescapeJava(this.classInitBody));
while(matcher.find()){
sb.insert(matcher.start(), CodeStringBuilder.getTabString());
}
String tempString=sb.toString();
pattern=Pattern.compile("\\n+");
matcher=pattern.matcher(tempString);
while(matcher.find()){
sb.insert(matcher.end(), CodeStringBuilder.getTabString());
}
return sb.toString();
}
示例15: getLastPatchFile
import org.apache.commons.lang3.StringEscapeUtils; //导入依赖的package包/类
protected File getLastPatchFile(String baseApkVersion,
String productName,
File outPatchDir) throws IOException {
try {
String httpUrl = ((TpatchInput)input).LAST_PATCH_URL +
"baseVersion=" +
baseApkVersion +
"&productIdentifier=" +
productName;
String response = HttpClientUtils.getUrl(httpUrl);
if (StringUtils.isBlank(response) ||
response.equals("\"\"")) {
return null;
}
File downLoadFolder = new File(outPatchDir, "LastPatch");
downLoadFolder.mkdirs();
File downLoadFile = new File(downLoadFolder, "lastpatch.tpatch");
String downLoadUrl = StringEscapeUtils.unescapeJava(response);
downloadTPath(downLoadUrl.substring(1, downLoadUrl.length() - 1), downLoadFile);
return downLoadFile;
} catch (Exception e) {
return null;
}
}