下面列出了org.apache.commons.lang3.StringUtils#indexOfIgnoreCase ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String cookie(String cookieStringIn, String name) {
String cookieString = cookieStringIn;
if(cookieString==null) {
return null;
}
String cookieParamName=name+"=";
// Fix Java: rfc2965 want cookie to be separated by comma.
// SOmehow i am receiving some semicolon separated cookies.
// Quick Fix: First strip the preceeding cookies if not the first.
if(!StringUtils.startsWithIgnoreCase(cookieString, cookieParamName)) {
int indexOfIgnoreCase = StringUtils.indexOfIgnoreCase(cookieString, cookieParamName);
cookieString = cookieString.substring(indexOfIgnoreCase);
}
// The proce
List<HttpCookie> cookies = HttpCookie.parse(cookieString);
for (HttpCookie httpCookie : cookies) {
if(StringUtils.equalsIgnoreCase(httpCookie.getName(), name)){
return httpCookie.getValue();
}
}
return null;
}
private static String combingToolTipTextWithKeyBinding(String toolTipText,
String keyBindingText) {
StringBuilder buffy = new StringBuilder(toolTipText);
if (StringUtilities.startsWithIgnoreCase(toolTipText, "<HTML>")) {
String endHTMLTag = "</HTML>";
int closeTagIndex = StringUtils.indexOfIgnoreCase(toolTipText, endHTMLTag);
if (closeTagIndex < 0) {
// no closing tag, which is acceptable
buffy.append(START_KEYBINDING_TEXT)
.append(keyBindingText)
.append(END_KEYBINDNIG_TEXT);
}
else {
// remove the closing tag, put on our text, and then put the tag back on
buffy.delete(closeTagIndex, closeTagIndex + endHTMLTag.length() + 1);
buffy.append(START_KEYBINDING_TEXT)
.append(keyBindingText)
.append(END_KEYBINDNIG_TEXT)
.append(endHTMLTag);
}
return buffy.toString();
}
// plain text (not HTML)
return toolTipText + " (" + keyBindingText + ")";
}
/**
* Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
* the DN is in an unrecognized format, the entire DN is returned.
*
* @param dn the dn to extract the username from
* @return the exatracted username
*/
public static String extractUsername(String dn) {
String username = dn;
// ensure the dn is specified
if (StringUtils.isNotBlank(dn)) {
// determine the separate
final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";
// attempt to locate the cd
final String cnPattern = "cn=";
final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
if (cnIndex >= 0) {
int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
if (separatorIndex > 0) {
username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
} else {
username = StringUtils.substring(dn, cnIndex + cnPattern.length());
}
}
}
return username;
}
/**
* Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
* the DN is in an unrecognized format, the entire DN is returned.
*
* @param dn the dn to extract the username from
* @return the exatracted username
*/
public static String extractUsername(String dn) {
String username = dn;
// ensure the dn is specified
if (StringUtils.isNotBlank(dn)) {
// determine the separate
final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";
// attempt to locate the cd
final String cnPattern = "cn=";
final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
if (cnIndex >= 0) {
int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
if (separatorIndex > 0) {
username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
} else {
username = StringUtils.substring(dn, cnIndex + cnPattern.length());
}
}
}
return username;
}
/**
* Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
* the DN is in an unrecognized format, the entire DN is returned.
*
* @param dn the dn to extract the username from
* @return the exatracted username
*/
public static String extractUsername(String dn) {
String username = dn;
// ensure the dn is specified
if (StringUtils.isNotBlank(dn)) {
// determine the separate
final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";
// attempt to locate the cd
final String cnPattern = "cn=";
final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
if (cnIndex >= 0) {
int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
if (separatorIndex > 0) {
username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
} else {
username = StringUtils.substring(dn, cnIndex + cnPattern.length());
}
}
}
return username;
}
private int searchNext(FlowableEmitter<CodeNode> emitter, String text, JavaNode javaClass, String code,
int startPos, boolean ignoreCase) {
int pos;
if (ignoreCase) {
pos = StringUtils.indexOfIgnoreCase(code, text, startPos);
} else {
pos = code.indexOf(text, startPos);
}
if (pos == -1) {
return -1;
}
int lineStart = 1 + code.lastIndexOf(CodeWriter.NL, pos);
int lineEnd = code.indexOf(CodeWriter.NL, pos + text.length());
StringRef line = StringRef.subString(code, lineStart, lineEnd == -1 ? code.length() : lineEnd);
emitter.onNext(new CodeNode(nodeCache.makeFrom(javaClass), -pos, line.trim()));
return lineEnd;
}
public static Optional<String> extractTokenFromBearer(FullHttpRequest req) {
String header = req.headers().get(HttpHeaders.AUTHORIZATION);
if(StringUtils.isBlank(header) || !StringUtils.containsIgnoreCase(header, OAuthUtil.AUTH_BEARER)) {
return Optional.empty();
}
int idx = StringUtils.indexOfIgnoreCase(header, OAuthUtil.AUTH_BEARER);
return Optional.of(header.substring(idx + OAuthUtil.AUTH_BEARER.length()).trim());
}
@Override
protected void doCheck(
SSPHandler sspHandler,
Elements elements,
TestSolutionHandler testSolutionHandler) {
SSP ssp = sspHandler.getSSP();
// if the page doesn't have any doctype declaration, the test is
// not applicable
if (StringUtils.isBlank(ssp.getDoctype())) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
String sourcePage = ssp.getAdaptedContent();
int indexOfDoctype = StringUtils.indexOfIgnoreCase(sourcePage,DOCTYPE_KEY);
int indexOfHtmlTag = StringUtils.indexOfIgnoreCase(sourcePage,HTML_ELEMENT_KEY);
if (indexOfHtmlTag < indexOfDoctype ||
StringUtils.indexOfIgnoreCase(sourcePage,DOCTYPE_KEY, indexOfHtmlTag) != -1) {
testSolutionHandler.addTestSolution(getFailureSolution());
addProcessRemark(getFailureSolution(), BAD_DOCTYPE_LOCATION_MSG);
} else {
testSolutionHandler.addTestSolution(getSuccessSolution());
}
}
/**
* Check if the value contains terms used for XML External Entity Injection
*
* @param strValue
* The value
* @return true if
*/
public static boolean containsXmlExternalEntityInjectionTerms( String strValue )
{
for ( String strTerm : XXE_TERMS )
{
if ( StringUtils.indexOfIgnoreCase( strValue, strTerm ) >= 0 )
{
Logger logger = Logger.getLogger( LOGGER_NAME );
logger.warn( "SECURITY WARNING : XXE TERMS DETECTED : " + dumpRequest( LocalVariables.getRequest( ) ) );
return true;
}
}
return false;
}
private static int indexOf(String source, String search, int offset) {
return StringUtils.indexOfIgnoreCase(source, search, offset);
}
@Override
Highlight[] getHighlights(String text, Object object,
Class<? extends FieldFactory> fieldFactoryClass, Color highlightColor) {
Address currentAddress = getAddressForHighlightObject(object);
if (!isInAddresses(currentAddress)) {
return EMPTY_HIGHLIGHTS;
}
if (MnemonicFieldFactory.class.isAssignableFrom(fieldFactoryClass) &&
(object instanceof Data)) {
// Not sure if we should ever highlight the mnemonic. It would only be for data.
// But, we are always looking for the field of a type, then mnemonic will only hold
// the parent's name and not the field's name.
}
else if (LabelFieldFactory.class.isAssignableFrom(fieldFactoryClass)) {
// It would be nice to highlight the label that points into data structures.
// However, the label is on the parent address, which is not in our list of matches
// when we are offcut. Further, using the program to lookup each address that
// comes in to see if it is our paren't address seems too expensive, as highlighting
// code is called for every paint operation.
//
// We could add the parent match to the list of known addresses and then use that
// to lookup in real-time later. To do this we would need the current list of
// reference addresses and a new list of parent data addresses. That seems a bit
// involved just for highlighting a label.
}
else if (OperandFieldFactory.class.isAssignableFrom(fieldFactoryClass)) {
// Not sure how to get the correct part of the text. This is a hack for now.
int offset = StringUtils.indexOfIgnoreCase(text, typeAndFieldName, 0);
if (offset != -1) {
return new Highlight[] {
new Highlight(offset, offset + typeAndFieldName.length() - 1, highlightColor) };
}
}
else if (FieldNameFieldFactory.class.isAssignableFrom(fieldFactoryClass)) {
if (text.equalsIgnoreCase(fieldName)) {
return new Highlight[] { new Highlight(0, text.length(), highlightColor) };
}
String typeName = getDataTypeName();
if (text.equalsIgnoreCase(typeName)) {
return new Highlight[] { new Highlight(0, text.length(), highlightColor) };
}
}
return EMPTY_HIGHLIGHTS;
}
@Override
protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) {
return StringUtils.indexOfIgnoreCase(str, searchStr, startPos);
}
private void findAll(String text, String find, boolean selectActiveHit) {
findInfoLabel.setText(null);
if (find.isEmpty()) {
clearHits();
return;
}
boolean matchCase = matchCaseButton.isSelected();
boolean regex = regexButton.isSelected();
hits.clear();
// find
if (regex) {
String pattern = matchCase ? find : ("(?i)" + find);
try {
Matcher matcher = Pattern.compile(pattern).matcher(text);
while (matcher.find())
hits.add(new Range(matcher.start(), matcher.end()));
} catch (PatternSyntaxException ex) {
findInfoLabel.setText(Messages.get("FindReplacePane.infoLabel.regexError"));
}
} else {
int fromIndex = 0;
int hitIndex;
while ((hitIndex = matchCase
? text.indexOf(find, fromIndex)
: StringUtils.indexOfIgnoreCase(text, find, fromIndex)) >= 0)
{
hits.add(new Range(hitIndex, hitIndex + find.length()));
fromIndex = hitIndex + find.length();
}
}
if (hits.isEmpty()) {
setActiveHitIndex(-1, selectActiveHit);
updateOverviewRuler();
return;
}
// find active hit index after current selection
int anchor = textArea.getAnchor();
int index = Collections.binarySearch(hits, new Range(anchor, anchor), (r1, r2) -> {
return r1.end - r2.start;
});
if (index < 0) {
index = -index - 1;
if (index >= hits.size())
index = 0; // wrap
}
setActiveHitIndex(index, selectActiveHit);
updateOverviewRuler();
}
/**
* Attempts to find the HTML head and body in the document and return them back.
* @param responseStr The HTML to be parse
* @param debug If <code>true</code> then log where we found the head and body.
*
* @return <code>null</code> if we failed to parse the page or a PageParts object.
*/
PageParts parseHtmlParts(String responseStr, boolean debug) {
// We can't lowercase the string and search in it as then the offsets don't match when a character is a
// different length in upper and lower case
int headStart = StringUtils.indexOfIgnoreCase(responseStr, "<head");
headStart = findEndOfTag(responseStr, headStart);
int headEnd = StringUtils.indexOfIgnoreCase(responseStr, "</head");
int bodyStart = StringUtils.indexOfIgnoreCase(responseStr, "<body");
bodyStart = findEndOfTag(responseStr, bodyStart);
// Some tools (Blogger for example) have multiple
// head-body pairs - browsers seem to not care much about
// this so we will do the same - so that we can be
// somewhat clean - we search for the "last" end
// body tag - for the normal case there will only be one
int bodyEnd = StringUtils.indexOfIgnoreCase(responseStr, "</body");
// If there is no body end at all or it is before the body
// start tag we simply - take the rest of the response
if ( bodyEnd < bodyStart ) bodyEnd = responseStr.length() - 1;
if(debug)
log.info("Frameless HS="+headStart+" HE="+headEnd+" BS="+bodyStart+" BE="+bodyEnd);
if (bodyEnd > bodyStart && bodyStart > headEnd && headEnd > headStart
&& headStart > 1) {
PageParts pp = new PageParts();
pp.head = responseStr.substring(headStart + 1, headEnd);
// SAK-29908
// Titles come twice to view and tool title overwrites main title because
// it is printed before.
int titleStart = pp.head.indexOf("<title");
int titleEnd = pp.head.indexOf("</title");
titleEnd = findEndOfTag(pp.head, titleEnd);
pp.head = (titleStart != -1 && titleEnd != -1) ? pp.head.substring(0, titleStart) + pp.head.substring(titleEnd + 1) : pp.head;
// End SAK-29908
pp.body = responseStr.substring(bodyStart + 1, bodyEnd);
return pp;
}
return null;
}
/**
* Attempts to find the HTML head and body in the document and return them back.
* @param responseStr The HTML to be parse
* @param debug If <code>true</code> then log where we found the head and body.
*
* @return <code>null</code> if we failed to parse the page or a PageParts object.
*/
PageParts parseHtmlParts(String responseStr, boolean debug) {
// We can't lowercase the string and search in it as then the offsets don't match when a character is a
// different length in upper and lower case
int headStart = StringUtils.indexOfIgnoreCase(responseStr, "<head");
headStart = findEndOfTag(responseStr, headStart);
int headEnd = StringUtils.indexOfIgnoreCase(responseStr, "</head");
int bodyStart = StringUtils.indexOfIgnoreCase(responseStr, "<body");
bodyStart = findEndOfTag(responseStr, bodyStart);
// Some tools (Blogger for example) have multiple
// head-body pairs - browsers seem to not care much about
// this so we will do the same - so that we can be
// somewhat clean - we search for the "last" end
// body tag - for the normal case there will only be one
int bodyEnd = StringUtils.indexOfIgnoreCase(responseStr, "</body");
// If there is no body end at all or it is before the body
// start tag we simply - take the rest of the response
if ( bodyEnd < bodyStart ) bodyEnd = responseStr.length() - 1;
if(debug)
log.info("Frameless HS="+headStart+" HE="+headEnd+" BS="+bodyStart+" BE="+bodyEnd);
if (bodyEnd > bodyStart && bodyStart > headEnd && headEnd > headStart
&& headStart > 1) {
PageParts pp = new PageParts();
pp.head = responseStr.substring(headStart + 1, headEnd);
// SAK-29908
// Titles come twice to view and tool title overwrites main title because
// it is printed before.
int titleStart = pp.head.indexOf("<title");
int titleEnd = pp.head.indexOf("</title");
titleEnd = findEndOfTag(pp.head, titleEnd);
pp.head = (titleStart != -1 && titleEnd != -1) ? pp.head.substring(0, titleStart) + pp.head.substring(titleEnd + 1) : pp.head;
// End SAK-29908
pp.body = responseStr.substring(bodyStart + 1, bodyEnd);
return pp;
}
return null;
}