当前位置: 首页>>代码示例>>Java>>正文


Java StringEscapeUtils类代码示例

本文整理汇总了Java中org.apache.commons.text.StringEscapeUtils的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils类的具体用法?Java StringEscapeUtils怎么用?Java StringEscapeUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringEscapeUtils类属于org.apache.commons.text包,在下文中一共展示了StringEscapeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
/**
 * Prints the.
 *
 * @param displayValue the display value
 * @param out the out
 * @throws JspException the jsp exception
 */
private void print(String displayValue, JspWriter out) throws JspException {
  try {
    if (maxLength != -1 && displayValue.length() > maxLength) {
      String newValue;
      if (ellipsisRight) {
        newValue = displayValue.substring(0, maxLength - 3) + "...";
      } else {
        newValue = "..." + displayValue.substring(displayValue.length() - maxLength + 3);
      }
      String title = StringEscapeUtils.escapeHtml4(displayValue);
      out.print("<span title=\"" + title + "\">" + newValue + "</span>");
    } else {
      out.print(displayValue);
    }
  } catch (IOException e) {
    throw new JspException(e);
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:26,代码来源:OutTag.java

示例2: createMessage

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
private static String createMessage(boolean stackTraceInWiki, String message) {
    String result = message;
    if (!stackTraceInWiki) {
        // Until https://github.com/unclebob/fitnesse/issues/731 is fixed
        if (message.contains("\n")) {
            if (!message.startsWith("<") || !message.endsWith(">")) {
                // it is not yet HTML, make it HTML so we can use <br/>
                message = StringEscapeUtils.escapeHtml4(message);
                message = String.format("<div>%s</div>", message);
            }
            message = message.replaceAll("(\\r)?\\n", "<br/>");
        }
        result = String.format("message:<<%s>>", message);
    }
    return result;
}
 
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:17,代码来源:SlimFixtureException.java

示例3: taskList

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
@RequestMapping(value = "/task_list.html", method = RequestMethod.GET)
public String taskList(HttpServletRequest request, @RequestParam(required = false, defaultValue = "false")boolean showRunning) {
	ResultList<Task> list;
	if(!showRunning)
		list = service.findAll(true);
	else
		list = service.findTasksByState(State.RUNNING, true);
	try {
		request.setAttribute("result", list);
		request.setAttribute("count", service.countByState(State.RUNNING).getResult());
		request.setAttribute("infoList", list.getRes().stream().map(task -> 
		        StringEscapeUtils.escapeHtml4(gson.toJson(task.getExtraInfoByKey("spiderInfo"))
		)).collect(Collectors.toList()));
	} catch(Exception e) {
		request.setAttribute("result", null);
	}
	return "pages/task/task_list";
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:19,代码来源:AsyncGatherController.java

示例4: getResponse

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
@SneakyThrows
private Map<String, String> getResponse(String uri, HttpEntity entity) {
	HttpPost post = new HttpPost(uri);
	post.setHeader("User-Agent", "ArmorvoxClient");
	post.setEntity(entity);
	final HttpClient client = clientBuilder.build();
	final HttpResponse serverResponse = client.execute(post);

	Map<String, String> response = new HashMap<>();
	IOUtils.readLines(serverResponse.getEntity().getContent(), "UTF-8").stream().forEach(line -> {
		if (StringUtils.contains(line, "<var name=\"")) {
			String key = StringUtils.substringBetween(line, "name=\"", "\"");
			String value = StringUtils.substringBetween(line, "expr=\"'", "'\"");
			if (key != null && value != null) {
				response.computeIfAbsent(key.toLowerCase(), k -> StringEscapeUtils.unescapeXml(value));
			}
		}
	});
	return response;
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:21,代码来源:VxmlClient.java

示例5: searchResponseFields

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
private String searchResponseFields(List<String> lines, String field) {
	Pattern fieldPattern = Pattern.compile("name\\s*=\\s*['\"]" + Pattern.quote(field) + "['\"]");
	StringBuilder sb = new StringBuilder();

	lines.stream().filter(line -> (fieldPattern.matcher(line).find())).forEach(line -> {
		// System.out.println(line);
		for (int i = 0; i < startStrings.length; i++) {
			String startString = startStrings[i];
			String endString = endStrings[i];
			String subString = StringUtils.substringBetween(line, startString, endString);
			if (subString != null) {
				sb.append(StringEscapeUtils.unescapeXml(subString));
			}
		}
	});

	String result = sb.toString();
	if (StringUtils.equals(field, "Condition")) {
		conditionMap.computeIfAbsent(result, k -> new LongAdder()).increment();
	}

	return result;
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:24,代码来源:ClientHandlerV5.java

示例6: writeTag

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
public static Iterator<Object> writeTag(String tagName, Map<String,Object> attributes, boolean selfClose) {
	final ArrayList<Object> t = new ArrayList<>((attributes.size() * 5) + 2);
	t.add("<" + tagName);
	for(final Map.Entry<String,Object> e: attributes.entrySet()) {
		t.add(" ");
		t.add(e.getKey());
		final Object val = e.getValue();
		if(val != null) {
			t.add("=\"");
			t.add(StringEscapeUtils.escapeHtml4(val.toString()));
			t.add("\"");
		}
	}
	t.add(selfClose ? "/>" : ">");
	return t.iterator();
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:17,代码来源:Tag.java

示例7: makeMethod

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
public static int makeMethod(final PrintWriter writer,
		final SQLMethod m,
		final Statement qe,
		final int level,
		final int[] gensym,
		final int[] braces,
		final boolean retValue) {
	final int stmt = gensym[0];
	gensym[0]++;
	writer.println("\t\t\ttry (final java.sql.PreparedStatement _" + stmt
		+ " = _0.prepareStatement(\"" + StringEscapeUtils.escapeJava(qe.sql.trim()) + "\")) {");
	braces[0] = braces[0] + 1;
	for(final SQLSetter s: qe.setters) {
		int i=0;
		for(int j=0;j < m.pList.length; j++) {
			if(s.name.equals(m.pList[j])) {
				i = j + 1;
				break;
			}
		}
		writer.println("\t\t\t" + s.setStatic("_" + stmt, "_" + i) + ";");
	}
	writer.println("\t\t\t_" + stmt + ".execute();");
	return -1;
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:26,代码来源:SQLC.java

示例8: lexString

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
private Lexeme lexString(final Reader in) throws IOException {
	final StringBuilder sb = new StringBuilder();
	boolean escape = false;
	while(true) {
		final int c = in.read();
		if(c == -1) { throw new ParserException("Expected a character instead of end of stream"); }
		final String cbuf = new String(Character.toChars(c));
		if(("\"".equals(cbuf)) && !escape) {
			return new Lexeme(Token.STRING, StringEscapeUtils.unescapeJson(sb.toString()));
		} else if ("\\".equals(cbuf)) {
			escape = true;
			sb.append(cbuf);
		} else {
			escape = false;
			sb.append(cbuf);
		}
	}
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:19,代码来源:StreamingParser.java

示例9: lexString

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
private static Lexeme lexString(final String cs, final int[] position) {
	final StringBuilder sb = new StringBuilder();
	boolean escape = false;
	while(true) {
		final int c = read(cs, position);
		if(c == -1) { throw new IllegalArgumentException("unexpected end of expression in string"); }
		final String cbuf = new String(Character.toChars(c));
		if(("\'".equals(cbuf)) && !escape) {
			return new Lexeme(Token.STRING, StringEscapeUtils.unescapeJson(sb.toString()));
		} else if ("\\".equals(cbuf)) {
			escape = true;
			sb.append(cbuf);
		} else {
			escape = false;
			sb.append(cbuf);
		}
	}
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:19,代码来源:JsonPath.java

示例10: addUser

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
@Override public Object addUser(final long tenantId, final UserToken uid, final String username) throws Exception {
	final String instancePrefix = getInstancePrefix(tenantId);
	final UserManagement um = mt.getInstance(instancePrefix).lookupInterface(UserManagement.class);
	logger.debug("Tenant: {} add user {}", tenantId, username);
	final ArrayList<String> accts = new ArrayList<>();
	accts.add(username);
	if(um.addAccounts(accts).size() == 0) {
		try (final Connection conn = adminDS.getConnection()) {
			tenantQueries.logEvent(conn, tenantId, uid.getID(), AuthUtils.lookupUsername(pw, uid),
				"{ \"action\": \"addUser\", \"data\": { \"users\": [ \""
					+ StringEscapeUtils.escapeJson(username) + "\" ] }}");
		} catch (final Exception ex) {
			logger.error("{}", ex);
		}
		return SUCCESS;
	} else {
		throw new RuntimeException();
	}
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:20,代码来源:Manager.java

示例11: startImport

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
@Override public TenantExport.Status startImport(final long tenantId,
		final UserToken uid,
		final SecureString password,
		final long exportId) throws Exception {
	checkAuth(pw, uid, password);
	final String instancePrefix = getInstancePrefix(tenantId);
	final TenantExport te = mt.getInstance(instancePrefix).lookupInterface(TenantExport.class);
	mailer.restoreInstanceFromExport(AuthUtils.lookupUsername(pw, uid), instancePrefix);
	try (final Connection conn = adminDS.getConnection()) {
		final long ownerId = tenantQueries.getOwner(conn, tenantId);
		if(ownerId != uid.getID()) {
			mailer.restoreInstanceFromExport(tenantQueries.getOwnerEmail(conn, ownerId), instancePrefix);
		}
		try {
			final TenantExport.Entry e = findFile(te, exportId);
			tenantQueries.logEvent(conn, tenantId, uid.getID(), AuthUtils.lookupUsername(pw, uid),
				"{ \"action\": \"importInstance\", \"data\": { \"exportId\": " + Long.toString(exportId)
					+ ", \"exportFile\": \""+ StringEscapeUtils.escapeJson(e.filename) + "\""
					+ ", \"exportDesc\": \"" + StringEscapeUtils.escapeJson(e.description) + "\" }}");
		} catch (final Exception ex) {
			logger.error("{}", ex);
		}
	}
	return te.initiateImport(exportId);
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:26,代码来源:Manager.java

示例12: getAttributeValues

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
/**
 * Get all values for the specified attribute
 * @param search the search query
 * @param path the path
 * @param attribute the name of the attribute
 * @param response the http response
 */
private void getAttributeValues(String search, String path, String attribute,
    HttpServerResponse response) {
  final Boolean[] first = {true};
  response.setChunked(true);
  response.write("[");

  store.rxGetAttributeValues(search, path, attribute)
    .flatMapObservable(x -> new RxAsyncCursor<>(x).toObservable())
    .subscribe(
      x -> {
        if (first[0]) {
          first[0] = false;
        } else {
          response.write(",");
        }
        response.write("\"" + StringEscapeUtils.escapeJson(x) + "\"");
      },
      err -> fail(response, err),
      () -> response
        .write("]")
        .setStatusCode(200)
        .end());
}
 
开发者ID:georocket,项目名称:georocket,代码行数:31,代码来源:StoreEndpoint.java

示例13: getPropertyValues

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
/**
 * Get all values for the specified property
 * @param search the search query
 * @param path the path
 * @param property the name of the property
 * @param response the http response
 */
private void getPropertyValues(String search, String path, String property,
    HttpServerResponse response) {
  final Boolean[] first = {true};
  response.setChunked(true);
  response.write("[");

  store.rxGetPropertyValues(search, path, property)
    .flatMapObservable(x -> new RxAsyncCursor<>(x).toObservable())
    .subscribe(
      x -> {
        if (first[0]) {
          first[0] = false;
        } else {
          response.write(",");
        }
        response.write("\"" + StringEscapeUtils.escapeJson(x) + "\"");
      },
      err -> fail(response, err),
      () -> response
        .write("]")
        .setStatusCode(200)
        .end());
}
 
开发者ID:georocket,项目名称:georocket,代码行数:31,代码来源:StoreEndpoint.java

示例14: parseProperties

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
/**
 * Parse list of properties in the form key:value
 * @param updates the list of properties
 * @return a json object with the property keys as object keys and the property
 * values as corresponding object values
 * @throws ServerAPIException if the syntax is not valid
 */
private static Map<String, String> parseProperties(List<String> updates)
  throws ServerAPIException {
  Map<String, String> props = new HashMap<>();
  String regex = "(?<!" + Pattern.quote("\\") + ")" + Pattern.quote(":");

  for (String part : updates) {
    part = part.trim();
    String[] property = part.split(regex);
    if (property.length != 2) {
      throw new ServerAPIException(
        ServerAPIException.INVALID_PROPERTY_SYNTAX_ERROR,
        "Invalid property syntax: " + part);
    }
    String key = StringEscapeUtils.unescapeJava(property[0].trim());
    String value = StringEscapeUtils.unescapeJava(property[1].trim());
    props.put(key, value);
  }

  return props;
}
 
开发者ID:georocket,项目名称:georocket,代码行数:28,代码来源:StoreEndpoint.java

示例15: getParameters

import org.apache.commons.text.StringEscapeUtils; //导入依赖的package包/类
private Map<String, Object> getParameters(String type) {
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("id", this.id);
	params.put("name", this.name);
	params.put("maxlength", String.valueOf(this.maxlength));
	params.put("placeHolder", StringEscapeUtils.escapeEcmaScript(this.placeHolder) );
	params.put("width", String.valueOf(this.width));
	params.put("value", this.value);
	Object valueStackObj = null;
	if (!StringUtils.isBlank(this.value)) {
		valueStackObj = ActionContext.getContext().getValueStack().findValue(this.value);
	}				
	if (valueStackObj != null) { // 存在 action 中的變數的話就使用這個變術的值		
		this.fillValueByValueStackObj(params, valueStackObj);
	}
	params.put("readonly", this.readonly);
	return params;
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:19,代码来源:TextBox.java


注:本文中的org.apache.commons.text.StringEscapeUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。