List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:com.surevine.alfresco.audit.NodeRefResolverImpl.java
/** * There are two types of Strings that may be input and processed similarly. Those strings that represent a path * that comes from the requested URI (i.e. doc library) and those that are namespace aware, as introduced during * Managed Deletion.// ww w . j a va 2 s . c o m * * @return * @throws UnsupportedEncodingException */ public static List<String> serializePathString(final String path) throws UnsupportedEncodingException { final String companyHome = "/app:company_home"; // First decide which type of string it is, if it begins with "/app:company_home" then it is the type of path // used for managed delete webscripts, otherwise assume it is the URI type used for doclib. String[] revisedPathArr; String revisedPath; if (path.startsWith(companyHome)) { // Now we need to dispense with company home and then lose each of the namespace qualifiers. revisedPath = path.substring(path.indexOf(companyHome) + companyHome.length(), path.length()); Pattern p = Pattern.compile("/[a-z]+:"); Matcher m = p.matcher(revisedPath); revisedPath = m.replaceAll("/"); revisedPathArr = StringUtils.split(revisedPath, '/'); // The last element will be ISO9075 encoded, and will need de-encoding if (revisedPathArr.length > 0) { revisedPathArr[revisedPathArr.length - 1] = ISO9075 .decode(revisedPathArr[revisedPathArr.length - 1]); } } else { // Need to do a minor bit of fiddling assuming the path has come from a URI. revisedPath = STRING_TO_INSERT + path.substring(path.lastIndexOf(STRING_TO_REMOVE) + STRING_TO_REMOVE.length()); revisedPath = URLDecoder.decode(revisedPath, "UTF-8"); revisedPathArr = StringUtils.split(revisedPath, '/'); } return Arrays.asList(revisedPathArr); }
From source file:de.iteratec.iteraplan.presentation.tags.TagUtils.java
/** * Every File-Link will be decorated with a javascript alert message. * /* w w w . java 2 s. c om*/ * @param original * @return string that contains decorated file links */ public static String decorateFileLinks(String original) { Matcher matcherFile = FILE_PATTERN_REGEX.matcher(original); String message = MessageAccess.getString(WIKI_LINKS_WARNING_KEY, UserContext.getCurrentLocale()); return matcherFile.replaceAll( "<a onclick=\"javascript:return alert('" + message + "');\" href=\"$1\">$2</a>"); }
From source file:com.email.ReceiveEmail.java
/** * Strip out the emojis and symbols from the email so we can actually save * it in the database// w w w. j a v a2 s . c om * * @param content String * @return String */ private static String removeEmojiAndSymbolFromString(String content) { String utf8tweet = ""; if (content != null) { try { byte[] utf8Bytes = content.getBytes("UTF-8"); utf8tweet = new String(utf8Bytes, "UTF-8"); } catch (UnsupportedEncodingException ex) { ExceptionHandler.Handle(ex); } Pattern unicodeOutliers = Pattern.compile( "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CANON_EQ | Pattern.CASE_INSENSITIVE); Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet); utf8tweet = unicodeOutlierMatcher.replaceAll(" "); } return utf8tweet; }
From source file:it.cilea.osd.jdyna.web.tag.JDynATagLibraryFunctions.java
public static String nl2br(String stringa) { String strigaRisultato = new String(stringa); Pattern CRLF = Pattern.compile("(\r\n|\r|\n|\n\r)"); Matcher m = CRLF.matcher(stringa); if (m.find()) { strigaRisultato = m.replaceAll("<br/>"); }/*from ww w. ja v a2 s. com*/ return strigaRisultato; }
From source file:com.bitplan.w3ccheck.W3CValidator.java
/** * create a W3CValidator result for the given url with the given html * //from w w w. j av a 2 s . com * @param url - the url of the validator e.g. "http://validator.w3.org/check" * @param html - the html code to be checked * @return - a W3CValidator response according to the SOAP response format or null if the * http response status of the Validation service is other than 200 * explained at response http://validator.w3.org/docs/api.html#requestformat * @throws JAXBException if there is something wrong with the response message so that it * can not be unmarshalled */ public static W3CValidator check(String url, String html) throws JAXBException { // initialize the return value W3CValidator result = null; // create a WebResource to access the given url WebResource resource = Client.create().resource(url); // prepare form data for posting FormDataMultiPart form = new FormDataMultiPart(); // set the output format to soap12 // triggers the various outputs formats of the validator. If unset, the usual Web format will be sent. // If set to soap12, // the SOAP1.2 interface will be triggered. See the SOAP 1.2 response format description at // http://validator.w3.org/docs/api.html#requestformat form.field("output", "soap12"); // make sure Unicode 0x0 chars are removed from html (if any) // see https://github.com/WolfgangFahl/w3cValidator/issues/1 Pattern pattern = Pattern.compile("[\\000]*"); Matcher matcher = pattern.matcher(html); if (matcher.find()) { html = matcher.replaceAll(""); } // The document to validate, POSTed as multipart/form-data FormDataBodyPart fdp = new FormDataBodyPart("uploaded_file", IOUtils.toInputStream(html), // new FileInputStream(tmpHtml), MediaType.APPLICATION_OCTET_STREAM_TYPE); // attach the inputstream as upload info to the form form.bodyPart(fdp); // now post the form via the Internet/Intranet ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); // in debug mode show the response status if (debug) LOGGER.log(Level.INFO, "response status for '" + url + "'=" + response.getStatus()); // if the http Status is ok if (response.getStatus() == 200) { // get the XML encoded SOAP 1.2 response format String responseXml = response.getEntity(String.class); // in debug mode show the full xml if (debug) LOGGER.log(Level.INFO, responseXml); // unmarshal the xml message to the format to a W3CValidator Java object JAXBContext context = JAXBContext.newInstance(W3CValidator.class); Unmarshaller u = context.createUnmarshaller(); StringReader xmlReader = new StringReader(responseXml); // this step will convert from xml text to Java Object result = (W3CValidator) u.unmarshal(xmlReader); } // return the result which might be null if the response status was other than 200 return result; }
From source file:org.eclipse.php.internal.core.typeinference.evaluators.PHPEvaluationUtils.java
public static MultiTypeType getArrayType(String type, IType currentNamespace, int offset) { int beginIndex = type.indexOf("[") + 1; //$NON-NLS-1$ int endIndex = type.lastIndexOf("]"); //$NON-NLS-1$ if (endIndex != -1) { type = type.substring(beginIndex, endIndex); }/* w w w . java 2 s . co m*/ MultiTypeType arrayType = new MultiTypeType(); Matcher m = ARRAY_TYPE_PATTERN.matcher(type); if (m.find()) { arrayType.addType(getArrayType(m.group(), currentNamespace, offset)); type = m.replaceAll(""); //$NON-NLS-1$ } else if (type.endsWith(BRACKETS) && type.length() > 2) { arrayType.addType(getArrayType(type.substring(0, type.length() - 2), currentNamespace, offset)); type = type.replaceAll(Pattern.quote(BRACKETS), ""); //$NON-NLS-1$ } String[] typeNames = type.split(","); //$NON-NLS-1$ for (String name : typeNames) { if (!"".equals(name)) { //$NON-NLS-1$ int nsSeparatorIndex = name.indexOf(NamespaceReference.NAMESPACE_SEPARATOR); if (currentNamespace != null && (nsSeparatorIndex < 0 || nsSeparatorIndex > 0)) { // check if the first part is an alias, then get the full // name // NB: do as in method // PDTModelUtils#collectParameterTypes(IMethod method) ModuleDeclaration moduleDeclaration = SourceParserUtil .getModuleDeclaration(currentNamespace.getSourceModule()); String prefix = name; if (nsSeparatorIndex > 0) { prefix = name.substring(0, nsSeparatorIndex); } final Map<String, UsePart> result = PHPModelUtils.getAliasToNSMap(prefix, moduleDeclaration, offset, currentNamespace, true); if (result.containsKey(prefix)) { String fullName = result.get(prefix).getNamespace().getFullyQualifiedName(); name = name.replace(prefix, fullName); if (name.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) { name = NamespaceReference.NAMESPACE_SEPARATOR + name; } } } arrayType.addType(getEvaluatedType(name, currentNamespace)); } } return arrayType; }
From source file:org.apache.ibatis.plugin.Plugin.java
public static String getStringNoBlank(String str) { if (str != null && !"".equals(str)) { Pattern p = Pattern.compile("\t|\r|\n"); Matcher m = p.matcher(str); String strNoBlank = m.replaceAll(" "); p = Pattern.compile("\\s+"); m = p.matcher(str);/* w w w .j a v a 2 s . c o m*/ strNoBlank = m.replaceAll(" "); return strNoBlank; } else { return str; } }
From source file:org.elasticsearch.river.email.EmailToJson.java
public static String delHTMLTag(String htmlStr) { Matcher m_script = p_script.matcher(htmlStr); htmlStr = m_script.replaceAll(""); Matcher m_style = p_style.matcher(htmlStr); htmlStr = m_style.replaceAll(""); Matcher m_html = p_html.matcher(htmlStr); htmlStr = m_html.replaceAll(""); return htmlStr.trim(); }
From source file:com.android.email.core.internet.MimeUtility.java
/** * Replace sequences of CRLF+WSP with WSP. Tries to preserve original string * object whenever possible./* ww w .ja v a 2 s.c o m*/ */ public static String unfold(String s) { if (s == null) { return null; } Matcher patternMatcher = PATTERN_CR_OR_LF.matcher(s); if (patternMatcher.find()) { patternMatcher.reset(); s = patternMatcher.replaceAll(""); } return s; }
From source file:ambit.data.qmrf.QMRFConverter.java
public static String replaceNewLine(String text) { if (text == null) return text; String newText = text;/*from ww w . j ava 2 s . c om*/ Matcher m = CRLF.matcher(newText); if (m.find()) { newText = m.replaceAll(""); } return newText; }