/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
*
* Created on April 20, 2007, 11:59 AM
* Updated for V3 on March 4, 2008
*/
/**
* Here is the contract:
* You give me a Map<String,String> object.
* resolve(Map<String,String>)
* I will find and replace the tokens, e.g., ${foo} with the value of "foo" in the properties.
* If the token has no such property -- then I leave the token as is.
* It purposely does not handle nested tokens. E.g. if the "foo" property has another
* token embedded in the value -- it will not be further resolved.
* This is the KISS principle in action...
* @author bnevins
*/
public class TokenResolver {
/**
* Empty constructor means use System Properties
*
*/
public TokenResolver() {
}
}
/**
* Replace $[variables} in map with a matching property from the map that this
* instance was constructed with. Both names and values are replaced.
* @param map Map of Strings to be token-replaced
*/
// we may be concurrently changing the map so we have to be careful!
// can't add to "map" arg while we are in the loop -- add all new
// entries AFTER the loop.
// usual case -- the RHS has a token
// will not get a concurrent mod exception -- it is just the value
// that changes...
}
// less usual case -- the LHS has a token. Need to remove the entry
// from the map and replace.
// We have to worry about ConcurrentModification here!
}
}
}
/**
* Replace $[variables} in list with a matching property from the map
* @param list List of Strings to be token-replaced
*/
if (hasToken(s)) {
}
}
}
///////////////////////////////////////////////////////////////////////////
/**
* Replace $[variables} with a matching property in the map
* @param s String to be token-replaced
* @return the replaced String
*/
{
return s;
if (hasWindowsToken(s)) {
s = windowsToUnixTokens(s);
}
}
return resolved;
}
/**
*
* @param s A String that may contain %token%
* @return the UNIX-ified format ${token}
*/
while (true) {
break;
}
}
return s;
}
else {
return replaced;
}
}
// Need at least 2 "%"
return false;
}
}
///////////////////////////////////////////////////////////////////////////
int index = 0;
while (true) {
break;
}
}
return tokens;
}
///////////////////////////////////////////////////////////////////////////
return null;
}
return null;
}
// if the token exists, but it's value is null -- then set the value
// back to the token.
}
return token;
}
///////////////////////////////////////////////////////////////////////////
if (s == null) {
return false;
}
return true;
}
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////
private static class Token {
int start;
int end;
}
}
}