static String format(String pattern, Object... args) { String result = pattern; for (Object arg : args) { result = StringUtils.replaceOnce(result, "{}", Objects.toString(arg)); } return result; } }
String tmp = StringUtils.replaceOnce(duration, " 0 days", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", ""); duration = tmp; if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 seconds", ""); String tmp = StringUtils.replaceOnce(duration, " 0 seconds", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", ""); if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 days", ""); duration = StringUtils.replaceOnce(duration, " 1 seconds", " 1 second"); duration = StringUtils.replaceOnce(duration, " 1 minutes", " 1 minute"); duration = StringUtils.replaceOnce(duration, " 1 hours", " 1 hour"); duration = StringUtils.replaceOnce(duration, " 1 days", " 1 day"); return duration.trim();
static String format(String pattern, Object... args) { String result = pattern; for (Object arg : args) { result = StringUtils.replaceOnce(result, "{}", Objects.toString(arg)); } return result; } }
private static String getResolvedAttributeName(String attributeValue) { Matcher matcher = numericPattern.matcher(attributeValue); while (matcher.find()) { String arrayPattern = matcher.group(); attributeValue = StringUtils.replaceOnce(attributeValue, arrayPattern, NUMERIC_IDENTIFIER); } return attributeValue; }
/** * Converts a {@link RyaURI} to the contained data string. * @param namespace the namespace. * @param the {@link RyaURI} to convert. * @return the data value without the namespace. */ public static String convertRyaUriToString(final String namespace, final RyaURI ryaUri) { return StringUtils.replaceOnce(ryaUri.getData(), namespace, ""); }
protected String abbreviatePackageUsingMappings(String clazz, SortedMap<String, String> abbreviations) { for (String s : abbreviations.keySet()) { if (StringUtils.startsWith(clazz,s)) { return StringUtils.replaceOnce(clazz, s, abbreviations.get(s)); } } return clazz; }
/** * @param path a path string that was generated by {@link #pathRelativeToRootDirectory(String)} * @return an absolute path, including the root directory */ public static String resolvePathToAbsolutePath(String path) { for (File rootDirectory : retrieveBatchFileLookupRootDirectories()) { if (path.startsWith(rootDirectory.getName())) { return new File(StringUtils.replaceOnce(path, rootDirectory.getName(), rootDirectory.getAbsolutePath())).getAbsolutePath(); } } throw new RuntimeException("Cannot resolve to absolute path"); }
/** * Converts a {@link RyaIRI} to the contained data string. * @param namespace the namespace. * @param ryaIri the {@link RyaIRI} to convert. * @return the data value without the namespace. */ public static String convertRyaIriToString(final String namespace, final RyaIRI ryaIri) { return StringUtils.replaceOnce(ryaIri.getData(), namespace, ""); }
protected boolean isValidAuthority(String authority) { if (authority == null) { return false; } String authority_ = authority; String [] split = authority.split("\\."); if (split.length > 1 && split[0].contains(OFFENDING_CHAR)) { authority_ = StringUtils.replaceOnce(authority,OFFENDING_CHAR, ""); } if (!authority_.equals(authority)) { logger.debug("replacing '{}' with '{}'", authority, authority_); } return super.isValidAuthority(authority_); }
protected int dumpFileContents(Writer outputWriter, File file, int currentPageNumber) { try { BufferedReader reader = new BufferedReader(new FileReader(file)); while (reader.ready()) { String line = reader.readLine(); while (line.contains(KFSConstants.REPORT_WRITER_SERVICE_PAGE_NUMBER_PLACEHOLDER)) { line = StringUtils.replaceOnce(line, KFSConstants.REPORT_WRITER_SERVICE_PAGE_NUMBER_PLACEHOLDER, String.valueOf(currentPageNumber)); currentPageNumber++; } outputWriter.write(line); outputWriter.write(newLineCharacter); } reader.close(); return currentPageNumber; } catch (IOException e) { throw new RuntimeException("Error reading or writing file", e); } }
private String suppressUrlPassword(final String val) { try { final URI uri = URI.create(val); if (uri.getUserInfo() != null && uri.getUserInfo().contains(":")) { final String password = uri.getUserInfo().split(":", 2)[1]; return StringUtils.replaceOnce(val, password, "(password)"); } else { return val; // No user info / user info doesn't contain a password } } catch (Throwable t) { return val; // Error parsing, just return the value } }
/** * returns a path relative to the appropriate lookup root directory, while including the name of the root directory for example, * if the parameter is "c:\opt\staging\gl\somefile.txt" and the roots are "c:\opt\reports;c:\opt\staging", it will return * "staging\gl\somefile.txt" (the system-specific path separator will be used). If there are multiple matching roots, then the * first one to be matched will take precedence * * @param absolutePath an absolute path for a file/directory */ public static String pathRelativeToRootDirectory(String absolutePath) { for (File rootDirectory : retrieveBatchFileLookupRootDirectories()) { if (absolutePath.startsWith(rootDirectory.getAbsolutePath())) { return StringUtils.replaceOnce(absolutePath, rootDirectory.getAbsolutePath(), rootDirectory.getName()); } } throw new RuntimeException("Unable to find appropriate root directory)"); }
/** * Creates a message with optional var injection. * Message format: "A String with any number of {} placeholders that will have the vars injected in order" * @param message the message string with the injection placeholders ({}) * @param vars the vars to inject into the the message template; some type conversion will occur for common data * types */ public void message(String message, final Object... vars) { if (ArrayUtils.isEmpty(vars)) { pw.println(message); } else { for (final Object var : vars) { try { message = StringUtils.replaceOnce(message, "{}", TypeUtil.toString(var)); } catch (Exception e) { log.error("Could not derive a valid String representation for {} using TypeUtil.toString(..)", var, e); message = StringUtils.replaceOnce(message, "{}", "???"); } } pw.println(message); } }
/** * Creates a message with optional var injection. * Message format: "A String with any number of {} placeholders that will have the vars injected in order" * @param message the message string with the injection placeholders ({}) * @param vars the vars to inject into the the message template; some type conversion will occur for common data * types */ public void message(String message, final Object... vars) { if (ArrayUtils.isEmpty(vars)) { pw.println(message); } else { for (final Object var : vars) { try { message = StringUtils.replaceOnce(message, "{}", TypeUtil.toString(var)); } catch (Exception e) { log.error("Could not derive a valid String representation for {} using TypeUtil.toString(..)", var, e); message = StringUtils.replaceOnce(message, "{}", "???"); } } pw.println(message); } }
public static String getPathWithNameServiceID(String path) { if (LOG.isDebugEnabled()) { LOG.debug("==> HdfsNameServiceResolver.getPathWithNameServiceID({})", path); } String ret = path; // Only handle URLs that begin with hdfs:// if (path != null && path.indexOf(HDFS_SCHEME) == 0) { URI uri = new Path(path).toUri(); String nsId; if (uri.getPort() != -1) { nsId = hostToNameServiceMap.get(uri.getAuthority()); } else { nsId = hostToNameServiceMap.get(uri.getHost() + ":" + DEFAULT_PORT); } if (nsId != null) { ret = StringUtils.replaceOnce(path, uri.getAuthority(), nsId); } } if (LOG.isDebugEnabled()) { LOG.debug("<== HdfsNameServiceResolver.getPathWithNameServiceID({}) = {}", path, ret); } return ret; }
public static String getPathWithNameServiceID(String path) { if (LOG.isDebugEnabled()) { LOG.debug("==> HdfsNameServiceResolver.getPathWithNameServiceID({})", path); } String ret = path; // Only handle URLs that begin with hdfs:// if (path != null && path.indexOf(HDFS_SCHEME) == 0) { URI uri = new Path(path).toUri(); String nsId; if (uri.getPort() != -1) { nsId = hostToNameServiceMap.get(uri.getAuthority()); } else { nsId = hostToNameServiceMap.get(uri.getHost() + ":" + DEFAULT_PORT); } if (nsId != null) { ret = StringUtils.replaceOnce(path, uri.getAuthority(), nsId); } } if (LOG.isDebugEnabled()) { LOG.debug("<== HdfsNameServiceResolver.getPathWithNameServiceID({}) = {}", path, ret); } return ret; }
public void registerService(URL url, Class serviceType, Object impl) { String contextPath = url.getParameter(RestfulConstants.CONTEXT_PATH,"/"); String path =StringUtils.replaceOnce(url.getPath(),contextPath,""); if(StringUtils.startsWith(path,"/")){ path = StringUtils.replaceOnce(path,"/",""); } SERVICE_MAPPING.putIfAbsent(path, new ServiceHandler(url.getParameter(Constants.GROUP_KEY), url.getParameter(Constants.VERSION_KEY), serviceType,path,impl)); }
private void updateExtendsOfDefinition(Session session, Node definition, String searchString, String replacement) throws RepositoryException { if(definition.hasProperty("extends")){ reportSystem("Updating extends on "+definition.getPath()); String extendsProp = PropertyUtil.getString(definition, "extends"); String newExtendsProp = StringUtils.replaceOnce(extendsProp, searchString, replacement); String extendsPropAbsolute = MigrationUtil.getAbsolutePath(newExtendsProp, definition); if(extendsPropAbsolute != null) { definition.setProperty("extends",newExtendsProp); //original replaced newExtendsProp (not newExtendsPropAbsolute) reportDebug("Property 'extends' of "+definition.getPath()+" updated with "+newExtendsProp); defUpdated+=1; } else{ reportRequestUserAction("!!! Unable to update property 'extends' of "+definition.getPath()+". New expected path was not found -> "+newExtendsProp+". Please check."); defNotUpdated+=1; } } }
/** * Description: <br> * * @author yang.zhipeng <br> * @taskId <br> * @param statement <br> * @return <br> */ private String getExcuteSql(StatementProxy statement) { String sqlStr = statement.getBatchSql(); if (statement instanceof PreparedStatementProxy) for (JdbcParameter parameter : statement.getParameters().values()) { int sqlType = parameter.getSqlType(); Object value = parameter.getValue(); String tempValue = Types.NULL == sqlType ? "NULL" : String.valueOf(value); sqlStr = StringUtils.replaceOnce(sqlStr, "?", tempValue); } return sqlStr; }
public void insertText(String text, String marker, XWikiContext context) throws XWikiException { setContent(StringUtils.replaceOnce(getContent(), marker, text + marker)); context.getWiki().saveDocument(this, context); }