001 /* 002 * Copyright 2006 Stephen J. McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.util; 020 021 import java.net.URI; 022 import java.net.URISyntaxException; 023 024 /** 025 * Build-time value resolver. 026 */ 027 public class SimpleResolver implements Resolver 028 { 029 /** 030 * Utility function supporting resolution of uris containing 'resource' or 031 * 'alias' schemes. If the supplied uri scheme is 'resource' or 'alias' the 032 * reference is resolved to a artifact type, group and name from which a 033 * resource is resolved and the uri returned. If the scheme is resource 034 * the usi of the resource is returned. If the scheme is 'alias' a 035 * link alias is returned. If the scheme is not 'resource' or 'alias' 036 * the argument will be evaluated as a normal transit artifact uri 037 * specification. 038 * 039 * @param ref the uri argument 040 * @return the uri value 041 * @exception URISyntaxException if an error occurs during uri creation 042 */ 043 public URI toURI( String ref ) throws URISyntaxException 044 { 045 String value = resolve( ref ); 046 return new URI( value ); 047 } 048 049 /** 050 * Return a property value. 051 * @param key the property key 052 * @return the property value 053 */ 054 public String getProperty( String key ) 055 { 056 return System.getProperty( key ); 057 } 058 059 /** 060 * Return a property value. 061 * @param key the property key 062 * @param value the default value 063 * @return the property value 064 */ 065 public String getProperty( String key, String value ) 066 { 067 return System.getProperty( key, value ); 068 } 069 070 /** 071 * Symbolic expansion of a supplied value. 072 * Replace any occurances of ${[key]} with the value of the property 073 * assigned to the [key] in system properties. 074 * @param value a string containing possibly multiple ${[value]} sequences 075 * @return the expanded string 076 */ 077 public String resolve( String value ) 078 { 079 return PropertyResolver.resolve( value ); 080 } 081 }