本文整理汇总了Java中org.apache.commons.lang.StringEscapeUtils类的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils类的具体用法?Java StringEscapeUtils怎么用?Java StringEscapeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringEscapeUtils类属于org.apache.commons.lang包,在下文中一共展示了StringEscapeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNameSearch
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
private void buildNameSearch(String searchString, StringBuilder sqlBuilder) {
if (!StringUtils.isBlank(searchString)) {
String[] tokens = searchString.trim().split("\\s+");
for (String token : tokens) {
String escToken = StringEscapeUtils.escapeSql(token);
sqlBuilder.append(" WHERE (user.first_name LIKE '%").append(escToken)
.append("%' OR user.last_name LIKE '%").append(escToken).append("%' OR user.login_name LIKE '%")
.append(escToken).append("%') ");
}
}
}
示例2: insertRowIntoDB
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
private static String insertRowIntoDB(String rowLine) {
List<String> rowFields =
new ArrayList<String>(Arrays.asList(rowLine.split("\t")));
Gene gene = Gene.valueOf(rowFields.remove(0));
DrugClass drugClass = DrugClass.valueOf(rowFields.remove(0));
int pos = Integer.parseInt(rowFields.remove(0));
int rank = Integer.parseInt(rowFields.remove(0));
String aas = rowFields.remove(0);
MutType mutType = MutType.valueOf(rowFields.remove(0));
String comment = rowFields.remove(0);
StringBuilder statements = new StringBuilder();
statements.append("INSERT INTO `tblCommentsWithVersions` ");
statements.append(
"(Gene, DrugClass, Pos, AAs, Type, " +
"Display, Version, Date, Comment) VALUES ");
statements.append(String.format(
"('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
gene, drugClass, pos, aas, mutType,
rank, VERSION, VERSION.versionDate,
StringEscapeUtils.escapeSql(comment.trim())));
statements.append(';');
return statements.toString();
}
示例3: getPlaintextFromEditor
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
/**
* Returns plain text from the editor.
*
* @param editor
* the editor from which to take the text.
* @param onlySelected
* if {@code true} will only return the selected text
* @return the text of the editor converted to plain text
* @throws BadLocationException
* @throws IOException
*/
public static String getPlaintextFromEditor(final JEditorPane editor, final boolean onlySelected) throws IOException,
BadLocationException {
if (editor == null) {
throw new IllegalArgumentException("editor must not be null!");
}
HTMLDocument document = (HTMLDocument) editor.getDocument();
StringWriter writer = new StringWriter();
int start = 0;
int length = document.getLength();
if (onlySelected) {
start = editor.getSelectionStart();
length = editor.getSelectionEnd() - start;
}
editor.getEditorKit().write(writer, document, start, length);
String text = writer.toString();
text = AnnotationDrawUtils.removeStyleFromComment(text);
// switch <br> and <br/> to actual newline (current system)
text = text.replaceAll("<br.*?>", System.lineSeparator());
// kill all other html tags
text = text.replaceAll("\\<.*?>", "");
text = StringEscapeUtils.unescapeHtml(text);
return text;
}
示例4: generate
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
public static void generate(final long hashCode, final StringBuilder content, final CharSequence[] successors, boolean notescurl) {
content.append("<html>\n<head></head>\n<body>\n");
// This helps in making the page text different even for the same number
// of URLs, but not always.
content.append("<h1>").append((char)((hashCode & 0xF) + 'A')).append((char)((hashCode >>> 4 & 0xF) + 'A')).append((char)((hashCode >>> 8 & 0xF) + 'A')).append((char)((hashCode >>> 12 & 0xF) + 'A')).append("</h1>\n");
for (final CharSequence s : successors) {
String ref = s.toString();
if (!notescurl) ref = StringEscapeUtils.escapeHtml(s.toString());
content.append("<p>Lorem ipsum dolor sit amet <a href=\""
+ ref
+ "\">"
+ ref
+ "</a>, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n");
}
content.append("</body>\n</html>\n");
}
示例5: getItemSb
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
private StringBuilder getItemSb(MaterialCatalogService mcs, DomainConfig dc, IDemandItem item)
throws ServiceException {
StringBuilder itemSb = new StringBuilder();
IMaterial m = mcs.getMaterial(item.getMaterialId());
itemSb.append(m.getMaterialId() != null ? m.getMaterialId() : CharacterConstants.EMPTY)
.append(CharacterConstants.COMMA)
.append(m.getCustomId() != null ? StringEscapeUtils.escapeCsv(m.getCustomId())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(StringEscapeUtils.escapeCsv(m.getName())).append(CharacterConstants.COMMA)
.append(item.getReason() != null ? StringEscapeUtils.escapeCsv(item.getReason())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(BigUtil.getFormattedValue(item.getQuantity()));
if (!dc.isDisableOrdersPricing()) {
itemSb.append(CharacterConstants.COMMA)
.append(item.getCurrency() != null ? StringEscapeUtils.escapeCsv(item.getCurrency())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(item.getFormattedPrice()).append(CharacterConstants.COMMA)
.append(item.getDiscount()).append(CharacterConstants.COMMA)
.append(item.computeTotalPrice(true));
}
return itemSb;
}
示例6: getLocationSb
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
StringBuilder getLocationSb(DomainConfig dc, IKiosk c, Locale locale) {
StringBuilder locationSb = new StringBuilder();
locationSb.append(c.getCountry() != null ? StringEscapeUtils.escapeCsv(c.getCountry())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getState() != null ? StringEscapeUtils.escapeCsv(c.getState())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getDistrict() != null ? StringEscapeUtils.escapeCsv(c.getDistrict())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getTaluk() != null ? StringEscapeUtils.escapeCsv(c.getTaluk())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getCity() != null ? StringEscapeUtils.escapeCsv(c.getCity())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getStreet() != null ? StringEscapeUtils.escapeCsv(c.getStreet())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(c.getPinCode() != null ? StringEscapeUtils.escapeCsv(c.getPinCode())
: CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(order.getLatitude() != null ? order.getLatitude() : CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(order.getLongitude() != null ? order.getLongitude() : CharacterConstants.EMPTY).append(CharacterConstants.COMMA)
.append(order.getGeoAccuracy() != null ? NumberUtil.getDoubleValue(order.getGeoAccuracy()) : CharacterConstants.EMPTY)
.append(CharacterConstants.COMMA)
.append(order.getGeoErrorCode() != null ? StringEscapeUtils.escapeCsv(GeoUtil.getGeoErrorMessage(order.getGeoErrorCode(), locale))
: CharacterConstants.EMPTY);
return locationSb;
}
示例7: buildCondtion
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
/**
* 创建检索条件
*
* @param searchBean
* 检索条件
* @param hql
* hql
* @param params
* 参数
*/
private void buildCondtion(ReviewSearchBean searchBean, StringBuffer hql, List<Object> params) {
if (Utils.isDefined(searchBean.getArticleno())) {
hql.append(" AND articleno = ? ");
params.add(searchBean.getArticleno());
}
if (Utils.isDefined(searchBean.getArticlename())) {
hql.append(" AND articlename like ? ");
params.add("%" + StringEscapeUtils.escapeSql(searchBean.getArticlename()) + "%");
}
if (Utils.isDefined(searchBean.getLoginid())) {
hql.append(" AND loginid like ?");
params.add("%" + StringEscapeUtils.escapeSql(searchBean.getLoginid()) + "%");
}
if (Utils.isDefined(searchBean.getChaptername())) {
hql.append(" AND chaptername like ? ");
params.add("%" + StringEscapeUtils.escapeSql(searchBean.getChaptername()) + "%");
}
}
示例8: getLessonStatusStr
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
/**
* Returns the lesson status string which is a reference to an image
*
* @param learnerProgress
* @return
*/
private String getLessonStatusStr(LearnerProgress learnerProgress) {
String status = "-";
final String IMAGES_DIR = Configuration.get(ConfigurationKeys.SERVER_URL) + "images";
if (learnerProgress != null) {
if (learnerProgress.isComplete()) {
status = "<i class='fa fa-check text-success'></i>";
} else if ((learnerProgress.getAttemptedActivities() != null)
&& (learnerProgress.getAttemptedActivities().size() > 0)) {
String currentActivityTitle = learnerProgress.getCurrentActivity() == null ? ""
: StringEscapeUtils.escapeHtml(learnerProgress.getCurrentActivity().getTitle());
status = "<i class='fa fa-cog' title='" + currentActivityTitle + "'></i>";
}
}
return status;
}
示例9: getUsersRatingsCommentsByCriteriaIdDTO
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
@Override
public StyledCriteriaRatingDTO getUsersRatingsCommentsByCriteriaIdDTO(Long toolContentId, Long toolSessionId,
RatingCriteria criteria, Long currentUserId, boolean skipRatings, int sorting, String searchString,
boolean getAllUsers, boolean getByUser) {
if (skipRatings) {
return ratingService.convertToStyledDTO(criteria, currentUserId, getAllUsers, null);
}
List<Object[]> rawData = peerreviewUserDao.getRatingsComments(toolContentId, toolSessionId, criteria,
currentUserId, null, null, sorting, searchString, getByUser, ratingService,
userManagementService);
for (Object[] raw : rawData) {
raw[raw.length - 2] = (Object) StringEscapeUtils.escapeCsv((String)raw[raw.length - 2]);
}
// if !getByUser -> is get current user's ratings from other users ->
// convertToStyledJSON.getAllUsers needs to be true otherwise current user (the only one in the set!) is dropped
return ratingService.convertToStyledDTO(criteria, currentUserId, !getByUser || getAllUsers, rawData);
}
示例10: buildReplaceResult
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
String dataXml = "";
if (resultData != null) {
String format = isUrl ? resultDataUrl : resultDataText;
dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
}
//*LAMS* the following line was added by LAMS and also messageIdentifier was added to the line after it
String messageIdentifier = UUID.randomUUID().toString();
String xml = String.format(replaceResultMessage, messageIdentifier, StringEscapeUtils.escapeXml(sourcedid),
StringEscapeUtils.escapeXml(score), dataXml);
HttpParameters parameters = new HttpParameters();
String hash = getBodyHash(xml);
parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/xml");
request.setEntity(new StringEntity(xml, "UTF-8"));
signer.setAdditionalParameters(parameters);
signer.sign(request);
return request;
}
示例11: propagateOptionsToJob
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
@Override
protected void propagateOptionsToJob(Job job) {
Configuration conf = job.getConfiguration();
String nullValue = options.getInNullStringValue();
if (nullValue != null) {
conf.set(DirectNetezzaManager.NETEZZA_NULL_VALUE,
StringEscapeUtils.unescapeJava(nullValue));
}
conf.setInt(DelimiterSet.INPUT_FIELD_DELIM_KEY,
options.getInputFieldDelim());
conf.setInt(DelimiterSet.INPUT_RECORD_DELIM_KEY,
options.getInputRecordDelim());
conf.setInt(DelimiterSet.INPUT_ENCLOSED_BY_KEY,
options.getInputEnclosedBy());
// Netezza uses \ as the escape character. Force the use of it
int escapeChar = options.getInputEscapedBy();
if (escapeChar > 0) {
if (escapeChar != '\\') {
LOG.info(
"Setting escaped char to \\ for Netezza external table export");
}
conf.setInt(DelimiterSet.INPUT_ESCAPED_BY_KEY, '\\');
}
conf.setBoolean(DelimiterSet.INPUT_ENCLOSE_REQUIRED_KEY,
options.isOutputEncloseRequired());
}
示例12: getLearnersByLesson
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<User> getLearnersByLesson(Long lessonId, String searchPhrase, Integer limit, Integer offset,
boolean orderAscending) {
StringBuilder queryTextBuilder = new StringBuilder("SELECT users ").append(LessonDAO.LOAD_LEARNERS_BY_LESSON);
if (!StringUtils.isBlank(searchPhrase)) {
String[] tokens = searchPhrase.trim().split("\\s+");
for (String token : tokens) {
token = StringEscapeUtils.escapeSql(token).replace("\\", "\\\\");
queryTextBuilder.append(" AND (users.firstName LIKE '%").append(token)
.append("%' OR users.lastName LIKE '%").append(token).append("%' OR users.login LIKE '%")
.append(token).append("%')");
}
}
String order = orderAscending ? "ASC" : "DESC";
queryTextBuilder.append(" ORDER BY users.firstName ").append(order).append(", users.lastName ").append(order)
.append(", users.login ").append(order);
Query query = getSession().createQuery(queryTextBuilder.toString()).setLong("lessonId", lessonId);
if (limit != null) {
query.setMaxResults(limit);
}
if (offset != null) {
query.setFirstResult(offset);
}
return query.list();
}
示例13: getCountLearnersByLesson
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
@Override
public Integer getCountLearnersByLesson(long lessonId, String searchPhrase) {
StringBuilder queryTextBuilder = new StringBuilder("SELECT COUNT(*) ")
.append(LessonDAO.LOAD_LEARNERS_BY_LESSON);
if (!StringUtils.isBlank(searchPhrase)) {
String[] tokens = searchPhrase.trim().split("\\s+");
for (String token : tokens) {
token = StringEscapeUtils.escapeSql(token).replace("\\", "\\\\");
queryTextBuilder.append(" AND (users.firstName LIKE '%").append(token)
.append("%' OR users.lastName LIKE '%").append(token).append("%' OR users.login LIKE '%")
.append(token).append("%')");
}
}
Query query = getSession().createQuery(queryTextBuilder.toString()).setLong("lessonId", lessonId);
Object value = query.uniqueResult();
return ((Number) value).intValue();
}
示例14: getParameterValues
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
@Override
public String[] getParameterValues(String name) {
String[] values = super.getParameterValues(name);
if(values != null) {
int length = values.length;
String[] escapseValues = new String[length];
for(int i = 0; i < length; i++){
escapseValues[i] = StringEscapeUtils.escapeHtml(values[i]);
}
return escapseValues;
}
return super.getParameterValues(name);
}
示例15: wrapSafeString
import org.apache.commons.lang.StringEscapeUtils; //导入依赖的package包/类
private static String wrapSafeString(String label) {
if (label.indexOf(',') >= 0) {
if (label.length()>14) {
label = label.replaceAll(",", ",\n");
}
}
label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
return label;
}