List of usage examples for org.apache.commons.lang3 StringUtils removePattern
public static String removePattern(final String source, final String regex)
From source file:gov.nyc.doitt.gis.geoclient.parser.token.TextUtils.java
public static String sanitize(String s) { if (s == null || s.isEmpty()) { return s; }/* ww w. j av a2s. c o m*/ // Remove leading and trailing spaces or punctuation (except for trailing //period characters (eg, N.Y.) String clean = StringUtils.removePattern(s, "^(?:\\s|\\p{Punct})+|(?:\\s|[\\p{Punct}&&[^.]])+$"); // Make sure ampersand is surrounded by spaces but allow double ampersand clean = clean.replaceAll("([^\\s&])\\&", "$1 &"); clean = clean.replaceAll("\\&([^\\s&])", "& $1"); // Normalize whitespace clean = StringUtils.normalizeSpace(clean); return clean; }
From source file:io.knotx.knot.action.domain.FormEntity.java
private static String getFormIdentifier(Fragment fragment) { return fragment.knots().stream().filter(knot -> knot.startsWith(FRAGMENT_KNOT_PREFIX)) .map(knot -> StringUtils.removePattern(knot, FRAGMENT_KNOT_PATTERN)) .map(id -> StringUtils.isBlank(id) ? FORM_DEFAULT_IDENTIFIER : id).findFirst().orElseThrow(() -> { LOGGER.error("Could not find action adapter name in fragment [{}].", fragment); return new NoSuchElementException("Could not find action adapter name"); });/*from w w w .ja v a 2 s. c om*/ }
From source file:de.ks.standbein.sample.fieldbinding.activity.FieldBindingController.java
@Override public void duringLoad(FieldBindingExampleModel model) { super.duringLoad(model); //modify the model during loading, add a count to the name String name = model.getName(); name = StringUtils.removePattern(name, "\\d*"); if (!name.endsWith(" ")) { name += " "; }// ww w . ja v a 2s . c om model.setName(name + count++); }
From source file:ch.cyberduck.core.openstack.SwiftAttributesFeature.java
@Override public PathAttributes find(final Path file) throws BackgroundException { if (file.isRoot()) { return PathAttributes.EMPTY; }//from w w w .ja v a 2 s. c o m final Region region = regionService.lookup(file); try { if (containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final PathAttributes attributes = new PathAttributes(); final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if (file.isDirectory()) { if (!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if (file.isFile()) { if (StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } attributes.setSize(Long.valueOf(metadata.getContentLength())); try { attributes.setModificationDate(dateParser.parse(metadata.getLastModified()).getTime()); } catch (InvalidDateException e) { log.warn(String.format("%s is not RFC 1123 format %s", metadata.getLastModified(), e.getMessage())); } if (StringUtils.isNotBlank(metadata.getETag())) { final String etag = StringUtils.removePattern(metadata.getETag(), "\""); attributes.setETag(etag); if (metadata.getMetaData().containsKey(Constants.X_STATIC_LARGE_OBJECT)) { // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of // the concatenated string of ETags for each of the segments in the manifest. attributes.setChecksum(null); } else { attributes.setChecksum(Checksum.parse(etag)); } } return attributes; } catch (GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
From source file:ch.cyberduck.core.openstack.SwiftAttributesFinderFeature.java
@Override public PathAttributes find(final Path file) throws BackgroundException { if (file.isRoot()) { return PathAttributes.EMPTY; }/* w w w . ja v a 2 s . c om*/ final Region region = regionService.lookup(file); try { if (containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final PathAttributes attributes = new PathAttributes(); final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if (file.isDirectory()) { if (!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if (file.isFile()) { if (StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } attributes.setSize(Long.valueOf(metadata.getContentLength())); try { attributes.setModificationDate(dateParser.parse(metadata.getLastModified()).getTime()); } catch (InvalidDateException e) { log.warn(String.format("%s is not RFC 1123 format %s", metadata.getLastModified(), e.getMessage())); } if (StringUtils.isNotBlank(metadata.getETag())) { final String etag = StringUtils.removePattern(metadata.getETag(), "\""); attributes.setETag(etag); if (metadata.getMetaData().containsKey(Constants.X_STATIC_LARGE_OBJECT)) { // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of // the concatenated string of ETags for each of the segments in the manifest. attributes.setChecksum(Checksum.NONE); } else { attributes.setChecksum(Checksum.parse(etag)); } } return attributes; } catch (GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
From source file:com.qq.tars.service.monitor.TARSPropertyMonitorService.java
private String[] translate(double[] data) { if (null == data) { return new String[] { "--" }; }/*from w ww . ja v a 2 s . c o m*/ String[] result = new String[1]; result[0] = data[0] < 0 ? "--" : String.format("%.3f", data[0]); result[0] = StringUtils.removePattern(result[0], "[\\.]*[0]+$"); return result; }
From source file:me.adaptive.che.plugin.server.project.generator.GeneratorCommandBuilder.java
public String getAppId() { if (StringUtils.isEmpty(appId)) { appId = DEFAULTS.APP_ID_PREFIX + StringUtils.removePattern(getProjectName(), "[^A-Za-z0-9]"); }//from ww w . j a v a 2 s . c o m return appId; }
From source file:nl.imvertor.common.file.ZipFile.java
/** * Create an XML serialization in a folder that will hold * 1/ a single xml file content.xml/*from ww w . j a v a 2s. c o m*/ * 2/ for each binary object a folder holding the binary object * 3/ a workfolder for the original extraction * * @param xmlFile * @throws Exception */ public void serializeToXml(AnyFolder serializeFolder) throws Exception { // serialize folder must be new //if (serializeFolder.exists()) // throw new Exception("Temporary processing folder must not exist: " + serializeFolder.getAbsolutePath()); // create the serialize folder, and work folder. AnyFolder workFolder = new AnyFolder(serializeFolder, "work"); workFolder.mkdirs(); // unzip this file to the workfolder decompress(workFolder); // create a content file. XmlFile content = new XmlFile(serializeFolder, "__content.xml"); FileWriterWithEncoding contentWriter = content.getWriterWithEncoding("UTF-8", false); // create a pattern that matches <?xml ... ?> String xmlRegex = "<\\?(x|X)(m|M)(l|L).*?\\?>"; contentWriter.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><zip-content-wrapper:files xmlns:zip-content-wrapper=\"" + ZIP_CONTENT_WRAPPER_NAMESPACE + "\">"); // now go through all files in the workfolder. Based in the XML or binary type of the file, add to XML stream or save to a bin folder. Vector<String> files = workFolder.listFilesToVector(true); for (int i = 0; i < files.size(); i++) { AnyFile f = new AnyFile(files.get(i)); String relpath = f.getRelativePath(serializeFolder).substring(5); // i.e. skip the "work1/" part boolean done = false; if (f.isDirectory()) done = true; else if (f.isXml()) { XmlFile fx = new XmlFile(f); if (fx.isWellFormed()) { contentWriter.append("<zip-content-wrapper:file type=\"xml\" path=\"" + relpath + "\">"); int linesRead = 0; while (true) { String line = fx.getNextLine(); if (line == null) break; else if (linesRead > 0) contentWriter.append(line + linesep); else contentWriter.append(StringUtils.removePattern(line, xmlRegex) + linesep); linesRead += 1; } contentWriter.append("</zip-content-wrapper:file>"); done = true; } } if (!done) { AnyFile fb = new AnyFile(serializeFolder, relpath); AnyFolder fbf = new AnyFolder(fb.getParentFile()); fbf.mkdirs(); f.copyFile(fb); // and record in XML for informational purpose contentWriter.append("<zip-content-wrapper:file type=\"bin\" path=\"" + relpath + "\"/>"); } } contentWriter.append("</zip-content-wrapper:files>"); contentWriter.close(); // and remove the work folder workFolder.deleteDirectory(); }
From source file:org.finra.herd.core.HerdStringUtils.java
/** * Strips HTML tags from a given input String, allows some tags to be retained via a whitelist * * @param fragment the specified String//from w ww . ja v a2 s . co m * @param whitelistTags the specified whitelist tags * * @return cleaned String with allowed tags */ public static String stripHtml(String fragment, String... whitelistTags) { // Parse out html tags except those from a given list of whitelist tags Document dirty = Jsoup.parseBodyFragment(fragment); Whitelist whitelist = new Whitelist(); for (String whitelistTag : whitelistTags) { // Get the actual tag name from the whitelist tag // this is vulnerable in general to complex tags but will suffice for our simple needs whitelistTag = StringUtils.removePattern(whitelistTag, "[^\\{IsAlphabetic}]"); // Add all specified tags to the whitelist while preserving inline css whitelist.addTags(whitelistTag).addAttributes(whitelistTag, "class"); } Cleaner cleaner = new Cleaner(whitelist); Document clean = cleaner.clean(dirty); // Set character encoding to UTF-8 and make sure no line-breaks are added clean.outputSettings().escapeMode(Entities.EscapeMode.base).charset(StandardCharsets.UTF_8) .prettyPrint(false); // return 'cleaned' html body return clean.body().html(); }
From source file:org.kuali.coeus.propdev.impl.custom.AuditProposalCustomDataEvent.java
@Override public void reportError(CustomAttribute customAttribute, String propertyName, String errorKey, String... errorParams) {/* ww w. j a v a 2 s . c o m*/ String key = SUPPLEMENTAL_PAGE_NAME + "." + customAttribute.getGroupName(); AuditCluster auditCluster = GlobalVariables.getAuditErrorMap().get(key); if (auditCluster == null) { List<AuditError> auditErrors = new ArrayList<AuditError>(); auditCluster = new AuditCluster(key, auditErrors, AUDIT_ERRORS); GlobalVariables.getAuditErrorMap().put(key, auditCluster); } List<AuditError> auditErrors = auditCluster.getAuditErrorList(); auditErrors.add(new AuditError( StringUtils.removePattern(customAttribute.getGroupName() + "_" + customAttribute.getLabel(), "([^0-9a-zA-Z\\-_])"), errorKey, SUPPLEMENTAL_PAGE_ID + "." + customAttribute.getGroupName().replace(" ", "_"), errorParams)); }