static String[] resolveVars(VarResolver vr, String[] in) { String[] out = new String[in.length]; for (int i = 0; i < in.length; i++) out[i] = vr.resolve(in[i]); return out; }
/** * Resolve variables in the specified string. * * <p> * This is a shortcut for calling <code>createSession(<jk>null</jk>).resolve(s);</code>. * <br>This method can only be used if the string doesn't contain variables that rely on the existence of session * variables. * * @param s The input string. * @return The string with variables resolved, or the same string if it doesn't contain any variables to resolve. */ public String resolve(String s) { return createSession(null).resolve(s); }
return new VarResolver() .addVars( SystemPropertiesVar.class, EnvVariablesVar.class,
/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
/** * Create a new var resolver using the settings in this builder. * * @return A new var resolver. */ public VarResolver build() { return new VarResolver(vars.toArray(new Class[vars.size()]), contextObjects); }
child.init(servletConfig); varResolver.addVars( LocalizationVar.class, RequestVar.class,
/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps, true); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
/** * Create a new var resolver using the settings in this builder. * * @return A new var resolver. */ public VarResolver build() { return new VarResolver(vars.toArray(new Class[vars.size()]), contextObjects); }
private static String[] resolveVars(VarResolver vr, String[] in) { String[] out = new String[in.length]; for (int i = 0; i < in.length; i++) out[i] = vr.resolve(in[i]); return out; }
/** * Resolve variables in the specified string. * * <p> * This is a shortcut for calling <code>createSession(<jk>null</jk>).resolve(s);</code>. * <br>This method can only be used if the string doesn't contain variables that rely on the existence of session * variables. * * @param s The input string. * @return The string with variables resolved, or the same string if it doesn't contain any variables to resolve. */ public String resolve(String s) { return createSession(null).resolve(s); }
/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps, true); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
/** * Create a new var resolver using the settings in this builder. * * @return A new var resolver. */ public VarResolver build() { return new VarResolver(vars.toArray(new Class[vars.size()]), contextObjects); }
static String[] resolveVars(VarResolver vr, String[] in) { String[] out = new String[in.length]; for (int i = 0; i < in.length; i++) out[i] = vr.resolve(in[i]); return out; }
/** * Resolve variables in the specified string. * * <p> * This is a shortcut for calling <code>createSession(<jk>null</jk>).resolve(s);</code>. * <br>This method can only be used if the string doesn't contain variables that rely on the existence of session * variables. * * @param s The input string. * @return The string with variables resolved, or the same string if it doesn't contain any variables to resolve. */ public String resolve(String s) { return createSession(null).resolve(s); }
@Test public void testResolvingWithOverride() throws Exception { Config cf = init(); cf.set("a", "$A{X}"); cf.set("b", "$B{X}"); cf.set("c", "$A{$B{X}}"); cf.set("d", "$B{$A{X}}"); cf.set("e", "$D{X}"); VarResolver vr = new VarResolverBuilder().defaultVars().vars(ALVar.class, BLVar.class).build(); cf = cf.resolving(vr.createSession()); assertEquals("aXa", cf.getString("a")); assertEquals("bXb", cf.getString("b")); assertEquals("abXba", cf.getString("c")); assertEquals("baXab", cf.getString("d")); assertEquals("$D{X}", cf.getString("e")); // Create new resolver that addx $C and overrides $A VarResolver vr2 = vr.builder().vars(AUVar.class, DUVar.class).build(); // true == augment by adding existing as parent to the new resolver cf = cf.resolving(vr2.createSession()); assertEquals("AXA", cf.getString("a")); assertEquals("bXb", cf.getString("b")); assertEquals("AbXbA", cf.getString("c")); assertEquals("bAXAb", cf.getString("d")); assertEquals("DXD", cf.getString("e")); }
private static String[] resolveVars(VarResolver vr, String[] in) { String[] out = new String[in.length]; for (int i = 0; i < in.length; i++) out[i] = vr.resolve(in[i]); return out; }
/** * Resolve variables in the specified string and sends the results to the specified writer. * * <p> * This is a shortcut for calling <code>createSession(<jk>null</jk>).resolveTo(s, w);</code>. * <br>This method can only be used if the string doesn't contain variables that rely on the existence of session * variables. * * @param s The input string. * @param w The writer to send the result to. * @throws IOException */ public void resolveTo(String s, Writer w) throws IOException { createSession(null).resolveTo(s, w); } }
private static String[] resolveVars(VarResolver vr, String[] in) { String[] out = new String[in.length]; for (int i = 0; i < in.length; i++) out[i] = vr.resolve(in[i]); return out; }
/** * Resolve variables in the specified string and sends the results to the specified writer. * * <p> * This is a shortcut for calling <code>createSession(<jk>null</jk>).resolveTo(s, w);</code>. * <br>This method can only be used if the string doesn't contain variables that rely on the existence of session * variables. * * @param s The input string. * @param w The writer to send the result to. * @throws IOException */ public void resolveTo(String s, Writer w) throws IOException { createSession(null).resolveTo(s, w); } }