/** * <p>Replace all occurances of a char within another char.</p> * <p/> * <p>A <code>null</code> reference passed to this method is a no-op.</p> * * @param text text to search and replace in * @param repl char to search for * @param with char to replace with * @return the text with any replacements processed * @see #replace(String text, char repl, char with, int max) */ public static String replace( @Nullable String text, char repl, char with ) { return replace( text, repl, with, -1 ); }
/** * <p>Replace a char with another char inside a larger String, once.</p> * <p/> * <p>A <code>null</code> reference passed to this method is a no-op.</p> * * @param text text to search and replace in * @param repl char to search for * @param with char to replace with * @return the text with any replacements processed * @see #replace(String text, char repl, char with, int max) */ public static String replaceOnce( @Nullable String text, char repl, char with ) { return replace( text, repl, with, 1 ); }
/** * <p>Replace a String with another String inside a larger String, once.</p> * <p/> * <p>A <code>null</code> reference passed to this method is a no-op.</p> * * @param text text to search and replace in * @param repl String to search for * @param with String to replace with * @return the text with any replacements processed * @see #replace(String text, String repl, String with, int max) */ public static String replaceOnce( @Nullable String text, @Nullable String repl, @Nullable String with ) { return replace( text, repl, with, 1 ); }
/** * <p>Replace all occurances of a String within another String.</p> * <p/> * <p>A <code>null</code> reference passed to this method is a no-op.</p> * * @param text text to search and replace in * @param repl String to search for * @param with String to replace with * @return the text with any replacements processed * @see #replace(String text, String repl, String with, int max) */ public static String replace( @Nullable String text, @Nullable String repl, @Nullable String with ) { return replace( text, repl, with, -1 ); }
/** * <p>Replace a char with another char inside a larger String, * for the first <code>max</code> values of the search char.</p> * <p/> * <p>A <code>null</code> reference passed to this method is a no-op.</p> * * @param text text to search and replace in * @param repl char to search for * @param with char to replace with * @param max maximum number of values to replace, or <code>-1</code> if no maximum * @return the text with any replacements processed */ public static String replace( @Nullable String text, char repl, char with, int max ) { return replace( text, String.valueOf( repl ), String.valueOf( with ), max ); }
protected void buildConfiguration( Xpp3Dom configuration, org.apache.maven.model.v3_0_0.Model v3Model, Properties projectProperties ) throws ProjectConverterException { String warSourceDirectory = projectProperties.getProperty( "maven.war.src" ); addConfigurationChild( configuration, "warSourceDirectory", StringUtils.replace( warSourceDirectory, "${basedir}/", "" ) ); } }
/** * Fill all 'variables' in the given text with the values from the map. * Any text looking like '${key}' will get replaced by the value stored * in the namespace map under the 'key'. * * @param text The text where replacements will be searched for. * @param namespace The namespace which contains the replacements. * @return the interpolated text. */ public static String interpolate( String text, @Nonnull Map<?, ?> namespace ) { for ( Map.Entry<?, ?> entry : namespace.entrySet() ) { String key = entry.getKey().toString(); Object obj = entry.getValue(); if ( obj == null ) { throw new NullPointerException( "The value of the key '" + key + "' is null." ); } String value = obj.toString(); text = replace( text, "${" + key + "}", value ); if ( !key.contains( " " ) ) { text = replace( text, "$" + key, value ); } } return text; }
/** * Filters a text file by replacing some user-defined tokens. * * @param srcPath The path to the input file, relative to the base directory, must not be * <code>null</code>. * @param dstPath The path to the output file, relative to the base directory and possibly equal to the * input file, must not be <code>null</code>. * @param fileEncoding The file encoding to use, may be <code>null</code> or empty to use the platform's default * encoding. * @param filterProperties The mapping from tokens to replacement values, must not be <code>null</code>. * @return The path to the filtered output file, never <code>null</code>. * @throws IOException If the file could not be filtered. * @since 1.2 */ public File filterFile( String srcPath, String dstPath, String fileEncoding, Map<String, String> filterProperties ) throws IOException { File srcFile = new File( getBasedir(), srcPath ); String data = FileUtils.fileRead( srcFile, fileEncoding ); for ( String token : filterProperties.keySet() ) { String value = String.valueOf( filterProperties.get( token ) ); data = StringUtils.replace( data, token, value ); } File dstFile = new File( getBasedir(), dstPath ); //noinspection ResultOfMethodCallIgnored dstFile.getParentFile().mkdirs(); FileUtils.fileWrite( dstFile.getPath(), fileEncoding, data ); return dstFile; }
public void rewrite( Reader from, Writer to, boolean reportOnly, String groupId, String artifactId, String version, String packaging ) throws Exception { Model v4Model; if ( from != null ) { MavenXpp3Reader v3Reader = new MavenXpp3Reader(); StringWriter w = new StringWriter(); IOUtil.copy( from, w ); String content = StringUtils.replace( w.toString(), "${pom.currentVersion}", "${project.version}" ); org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( new StringReader( content ) ); v4Model = translator.translate( v3Model ); } else { v4Model = new Model(); } if ( v4Model != null ) { translator.validateV4Basics( v4Model, groupId, artifactId, version, packaging ); if ( !reportOnly ) { MavenXpp3Writer v4Writer = new MavenXpp3Writer(); v4Writer.write( to, v4Model ); } } }