List of usage examples for java.util.regex Pattern CASE_INSENSITIVE
int CASE_INSENSITIVE
To view the source code for java.util.regex Pattern CASE_INSENSITIVE.
Click Source Link
From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java
private String replaceLinks(final String linkPattern, final int linkIndex, final String newLinkPrefix, final String remoteBasePath, final String content) { log.debug("Rewriting links to basePath " + remoteBasePath); final boolean isUrlEncodingNeeded = newLinkPrefix.indexOf('?') >= 0; final Pattern pattern = Pattern.compile(linkPattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); final Matcher m = pattern.matcher(content); // determines if the link is absolute final StringBuffer buffer = new StringBuffer(); int lastEnd = 0; while (m.find()) { final String link = m.group(linkIndex).trim(); if (link.startsWith("data")) { continue; }// ww w. j av a 2s . co m if (!isFullLinkWithProtocol(link)) { String newURI = getRelativeLink(newLinkPrefix, remoteBasePath, isUrlEncodingNeeded, link); buffer.append(getSubstringBetweenLinks(linkIndex, content, m, lastEnd)); buffer.append(newURI.trim()); lastEnd = m.end(linkIndex); } } buffer.append(content.substring(lastEnd)); return buffer.toString(); }
From source file:de.thm.arsnova.service.UserServiceImpl.java
private void parseMailAddressPattern() { /* TODO: Add Unicode support */ List<String> domainList = Arrays.asList(allowedEmailDomains.split(",")); if (!domainList.isEmpty()) { List<String> patterns = new ArrayList<>(); if (domainList.contains("*")) { patterns.add("([a-z0-9-]+\\.)+[a-z0-9-]+"); } else {/*from w w w .ja v a2 s . co m*/ Pattern patternPattern = Pattern.compile("[a-z0-9.*-]+", Pattern.CASE_INSENSITIVE); for (String patternStr : domainList) { if (patternPattern.matcher(patternStr).matches()) { patterns.add(patternStr.replaceAll("[.]", "[.]").replaceAll("[*]", "[a-z0-9-]+?")); } } } mailPattern = Pattern.compile("[a-z0-9._-]+?@(" + StringUtils.join(patterns, "|") + ")", Pattern.CASE_INSENSITIVE); logger.info("Allowed e-mail addresses (pattern) for registration: '{}'.", mailPattern.pattern()); } }
From source file:eu.dety.burp.joseph.attacks.key_confusion.KeyConfusionInfo.java
@Override public HashMap<String, String> updateValuesByPayload(Enum payloadTypeId, String header, String payload, String signature) throws AttackPreparationFailedException { String publicKeyValue = publicKey.getText(); int publicKeyFormat = publicKeySelection.getSelectedIndex(); String modifiedKey;/*from w w w .ja v a 2 s.c o m*/ switch (publicKeyFormat) { // JWK (JSON) case 1: loggerInstance.log(getClass(), "Key format is JWK: " + publicKeyValue, Logger.LogLevel.DEBUG); HashMap<String, PublicKey> publicKeys; PublicKey selectedPublicKey; try { Object publickKeyValueJson = new JSONParser().parse(publicKeyValue); publicKeys = Converter.getRsaPublicKeysByJwkWithId(publickKeyValueJson); } catch (Exception e) { loggerInstance.log(getClass(), "Error in updateValuesByPayload (JWK): " + e.getMessage(), Logger.LogLevel.ERROR); throw new AttackPreparationFailedException(bundle.getString("NOT_VALID_JWK")); } switch (publicKeys.size()) { // No suitable JWK in JWK Set found case 0: loggerInstance.log(getClass(), "Error in updateValuesByPayload (JWK): No suitable JWK", Logger.LogLevel.ERROR); throw new AttackPreparationFailedException(bundle.getString("NO_SUITABLE_JWK")); // Exactly one suitable JWK found case 1: selectedPublicKey = publicKeys.entrySet().iterator().next().getValue(); break; // More than one suitable JWK found. Provide dialog to select one. default: selectedPublicKey = Converter.getRsaPublicKeyByJwkSelectionPanel(publicKeys); } try { modifiedKey = transformKeyByPayload(payloadTypeId, selectedPublicKey); } catch (Exception e) { loggerInstance.log(getClass(), "Error in updateValuesByPayload (JWK): " + e.getMessage(), Logger.LogLevel.ERROR); throw new AttackPreparationFailedException(bundle.getString("ATTACK_PREPARATION_FAILED")); } break; // PEM (String) default: loggerInstance.log(getClass(), "Key format is PEM: " + publicKeyValue, Logger.LogLevel.DEBUG); // Simple check if String has valid format if (!publicKeyValue.trim().startsWith("-----BEGIN") && !publicKeyValue.trim().startsWith("MI")) { throw new AttackPreparationFailedException(bundle.getString("NOT_VALID_PEM")); } try { modifiedKey = transformKeyByPayload(payloadTypeId, publicKeyValue); } catch (Exception e) { loggerInstance.log(getClass(), "Error in updateValuesByPayload (PEM): " + e.getMessage(), Logger.LogLevel.ERROR); throw new AttackPreparationFailedException(bundle.getString("NOT_VALID_PEM")); } } Pattern jwsPattern = Pattern.compile("\"alg\":\"(.+?)\"", Pattern.CASE_INSENSITIVE); Matcher jwsMatcher = jwsPattern.matcher(header); String algorithm = (jwsMatcher.find()) ? jwsMatcher.group(1) : "HS256"; String macAlg = Crypto.getMacAlgorithmByJoseAlgorithm(algorithm, "HmacSHA256"); if (!Crypto.JWS_HMAC_ALGS.contains(algorithm)) algorithm = "HS256"; header = header.replaceFirst("\"alg\":\"(.+?)\"", "\"alg\":\"" + algorithm + "\""); HashMap<String, String> result = new HashMap<>(); result.put("header", header); result.put("payload", payload); result.put( "signature", Decoder .getEncoded( Crypto.generateMac(macAlg, helpers.stringToBytes(modifiedKey), helpers.stringToBytes(Decoder.concatComponents(new String[] { Decoder.base64UrlEncode(helpers.stringToBytes(header)), Decoder.base64UrlEncode(helpers.stringToBytes(payload)) }))))); if (publicKeyValue.isEmpty()) { return result; } return result; }
From source file:com.stimulus.archiva.extraction.MessageExtraction.java
private String prepareHTMLMessage(String baseURL, Hashtable<String, String> inl, Hashtable<String, String> imgs, Hashtable<String, String> nonImgs, Hashtable<String, String> ready, ArrayList<String> mimeTypes) { String str = (String) inl.get("text/html"); boolean alternative = false; for (int i = 0; i < mimeTypes.size(); i++) { if (((String) mimeTypes.get(i)).toLowerCase(Locale.ENGLISH).indexOf("multipart/alternative") > -1) { alternative = true;/* w ww.ja v a2s. c o m*/ break; } } if (!alternative && inl.containsKey("text/plain")) { String plain = activateURLs((String) inl.get("text/plain")).replaceAll("\r", "").replaceAll("\n", "<br>" + System.getProperty("line.separator")) + "<br><br>" + System.getProperty("line.separator") + "<hr><br>"; int bestStart = 0; int next = str.toLowerCase(Locale.ENGLISH).indexOf("<body"); if (next > 0) next = str.indexOf(">", next) + 1; if (next > 0 && next < str.length()) bestStart = next; if (bestStart > 0) str = str.substring(0, bestStart) + plain + str.substring(bestStart); else str = plain + str; } HashSet<String> alreadyUsed = new HashSet<String>(); Enumeration enuma = imgs.keys(); while (enuma.hasMoreElements()) { String repl = (String) enuma.nextElement(); String cidTag = (String) imgs.get(repl); if (cidTag.startsWith("<") && cidTag.endsWith(">")) { cidTag = cidTag.substring(1, cidTag.length() - 1); } if (str.indexOf("cid:" + cidTag) > -1) { alreadyUsed.add(repl); } String st = (String) ready.get(repl); str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str) .replaceAll(ready.get(repl)); } enuma = nonImgs.keys(); while (enuma.hasMoreElements()) { String repl = (String) enuma.nextElement(); String cidTag = (String) nonImgs.get(repl); if (cidTag.startsWith("<") && cidTag.endsWith(">")) cidTag = cidTag.substring(1, cidTag.length() - 1); if (str.indexOf("cid:" + cidTag) > -1) alreadyUsed.add(repl); String st = (String) ready.get(repl); str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str) .replaceAll(ready.get(repl)); } StringBuffer buff = new StringBuffer(); enuma = imgs.keys(); while (enuma.hasMoreElements()) { String fl = (String) enuma.nextElement(); if (!alreadyUsed.contains(fl)) { fl = (String) ready.get(fl); if (fl.endsWith(".tif") || fl.endsWith(".tiff")) { buff.append(System.getProperty("line.separator") + "<BR><BR><EMBED SRC=\"" + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\" TYPE=\"image/tiff\">"); } else { buff.append(System.getProperty("line.separator") + "<BR><BR><IMG SRC=\"" + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\">"); } } } String output = ""; int bestStart = 0; int next = str.toLowerCase(Locale.ENGLISH).indexOf("</body>"); if (next > 0 && next < str.length()) bestStart = next; if (bestStart > 0) output = str.substring(0, bestStart) + buff.toString() + str.substring(bestStart); else output = str + buff.toString(); if (output.indexOf("charset=") < 0) { next = output.toLowerCase(Locale.ENGLISH).indexOf("</head>"); if (next > 0) output = output.substring(0, next) + "<META http-equiv=Content-Type content=\"text/html; charset=" + serverEncoding + "\">" + output.substring(next); } else output = output.replaceFirst("charset=.*\"", "charset=" + serverEncoding + "\""); output = output.replaceAll("FONT SIZE=\\d", "FONT"); output = output.replaceAll("font size=\\d", "font"); return writeTempMessage(output, ".html"); }
From source file:com.salas.bb.utils.StringUtils.java
/** * Scans for tags definitions in micro-format. The text should contain A-links to * tag categories with "rel" attribute equal to "tag". The last section of URL is * taken as tag.//w w w .j ava 2s. c o m * * @param aText text to parse. * * @return list of tags detected. */ public static String[] collectTags(String aText) { List<String> tagsList = null; if (aText != null) { Pattern pat = Pattern.compile("<a\\s+[^>]*rel\\s*=\\s*['\"]tag['\"][^>]*>", Pattern.CASE_INSENSITIVE); Matcher matcher = pat.matcher(aText); Pattern patTag = null; while (matcher.find()) { if (tagsList == null) { tagsList = new ArrayList<String>(); patTag = Pattern.compile("href\\s*=\\s*['\"]([^'\"/]+/+)+([\\+a-zA-Z0-9]+)['\"]"); } Matcher m2 = patTag.matcher(matcher.group()); if (m2.find()) tagsList.add(m2.group(2).replaceAll("\\+", " ")); } } return tagsList == null ? Constants.EMPTY_STRING_LIST : tagsList.toArray(new String[tagsList.size()]); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java
public static boolean isValidName(String name) { boolean validName = false; if (!StringUtils.isEmpty(name)) { Pattern validNamePattern = Pattern.compile("^[a-zA-Z][\\w\\d]*$", Pattern.CASE_INSENSITIVE); validName = validNamePattern.matcher(name).matches(); }//from w w w. j a va 2s .co m return validName; }
From source file:net.longfalcon.newsj.CategoryService.java
private boolean matchRegex(String regex, String value, int categoryType) { Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(value); if (matcher.find()) { tmpCat = categoryType;// w ww . j a va 2 s.co m return true; } return false; }