VarResolverBuilder b = new VarResolverBuilder() .defaultVars() .vars(ConfigVar.class, SwitchVar.class, IfVar.class); if (cf != null) b.contextObject(ConfigVar.SESSION_config, cf); return b;
/** * Returns a new builder object using the settings in this resolver as a base. * * @return A new var resolver builder. */ public VarResolverBuilder builder() { return new VarResolverBuilder() .vars(ctx.getVars()) .contextObjects(ctx.getContextObjects()); }
@Test public void test() throws Exception { VarResolver vr = new VarResolverBuilder().vars(LowerCaseVar.class, SystemPropertiesVar.class).build(); System.setProperty("LowerCaseVar.test", "fooBAR"); assertEquals("foobar", vr.resolve("$LC{$S{LowerCaseVar.test}}")); } }
/** * 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); }
/** * Augments the set of variables defined in the configuration and var resolver. * * <p> * This calls {@link VarResolverBuilder#vars(Class[])} on the var resolver used to construct the configuration * object returned by {@link Microservice#getConfig()} and the var resolver returned by {@link Microservice#getVarResolver()}. * * @param vars The set of variables to append to the var resolver builder. * @return This object (for method chaining). */ @SuppressWarnings("unchecked") public MicroserviceBuilder vars(Class<? extends Var>...vars) { varResolverBuilder.vars(vars); return this; }
ConfigBuilder configBuilder = builder.configBuilder.varResolver(builder.varResolverBuilder.build()).store(ConfigMemoryStore.DEFAULT); if (config == null) { ConfigStore store = builder.configStore; this.varResolver = varResolverBuilder.contextObject(ConfigVar.SESSION_config, config).build();
cf = cfb.name(cfPath).varResolver(createVarResolver().defaultVars().build()).build(); cf = cfb.build(); } else { cf = cfb.name(cfPath).varResolver(createVarResolver().build()).build(); vr = createVarResolver().build();
/** * Adds a var resolver context object for vars defined in the configuration and var resolver. * * <p> * This calls {@link VarResolverBuilder#contextObject(String,Object)} on the var resolver used to construct the configuration * object returned by {@link Microservice#getConfig()} and the var resolver returned by {@link Microservice#getVarResolver()}. * * @param name The context object name. * @param object The context object. * @return This object (for method chaining). */ public MicroserviceBuilder varContext(String name, Object object) { varResolverBuilder.contextObject(name, object); return this; }
/** * Instantiates a new clean-slate {@link VarResolverBuilder} object. * * <p> * This is equivalent to simply calling <code><jk>new</jk> VarResolverBuilder()</code>. * * @return A new {@link VarResolverBuilder} object. */ public static VarResolverBuilder create() { return new VarResolverBuilder(); }
@Test public void test() throws Exception { VarResolver vr = new VarResolverBuilder().vars(UpperCaseVar.class, SystemPropertiesVar.class).build(); System.setProperty("UpperCaseVar.test", "fooBAR"); assertEquals("FOOBAR", vr.resolve("$UC{$S{UpperCaseVar.test}}")); } }
/** * 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); }
/** * Adds the specified {@link Var} classes to this config. * * <p> * These variables affect the variable resolver returned by {@link RestRequest#getVarResolverSession()} which is * used to resolve string variables of the form <js>"$X{...}"</js>. * * <p> * See {@link RestContext#getVarResolver()} for a list of predefined variables. * * @param vars The {@link Var} classes to add to this config. * @return This object (for method chaining). */ public RestContextBuilder vars(Class<?>...vars) { this.varResolverBuilder.vars(vars); return this; }
/** * Adds a var context object to this config. * * <p> * Var context objects are read-only objects associated with the variable resolver for vars that require external * information. * * <p> * For example, the {@link ConfigVar} needs access to this resource's {@link Config} through the * {@link ConfigVar#SESSION_config} object that can be specified as either a session object (temporary) or * context object (permanent). * In this case, we call the following code to add it to the context map: * <p class='bcode w800'> * config.addVarContextObject(<jsf>SESSION_config</jsf>, configFile); * </p> * * @param name The context object key (i.e. the name that the Var class looks for). * @param object The context object. * @return This object (for method chaining). */ public RestContextBuilder varContextObject(String name, Object object) { this.varResolverBuilder.contextObject(name, object); return this; }
/** * Instantiates a new clean-slate {@link VarResolverBuilder} object. * * <p> * This is equivalent to simply calling <code><jk>new</jk> VarResolverBuilder()</code>. * * @return A new {@link VarResolverBuilder} object. */ public static VarResolverBuilder create() { return new VarResolverBuilder(); }
@Test public void testParent() throws Exception { VarResolver vr = new VarResolverBuilder().defaultVars().vars(XMultipartVar.class).build(); String t; System.setProperty("a", "a1"); System.setProperty("b", "b1"); t = "$X{$S{a},$S{b}}"; assertEquals("a1+b1", vr.resolve(t)); t = "$X{$S{a}}"; assertEquals("a1", vr.resolve(t)); }
@Test public void testNoNest() throws Exception { VarResolver vr = new VarResolverBuilder().vars(NoNestVar.class).build(); test(vr, "$NoNest{foo}", "foo"); test(vr, "$NoNest{$NoNest{foo}}", "$NoNest{foo}"); test(vr, "$NoNest{foo $NoNest{foo} bar}", "foo $NoNest{foo} bar"); }
/** * 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); }
/** * Returns a new builder object using the settings in this resolver as a base. * * @return A new var resolver builder. */ public VarResolverBuilder builder() { return new VarResolverBuilder() .vars(ctx.getVars()) .contextObjects(ctx.getContextObjects()); }
/** * Adds the specified {@link Var} classes to this config. * * <p> * These variables affect the variable resolver returned by {@link RestRequest#getVarResolverSession()} which is * used to resolve string variables of the form <js>"$X{...}"</js>. * * <p> * See {@link RestContext#getVarResolver()} for a list of predefined variables. * * @param vars The {@link Var} classes to add to this config. * @return This object (for method chaining). */ public RestContextBuilder vars(Class<?>...vars) { this.varResolverBuilder.vars(vars); return this; }
/** * Adds a var context object to this config. * * <p> * Var context objects are read-only objects associated with the variable resolver for vars that require external * information. * * <p> * For example, the {@link ConfigVar} needs access to this resource's {@link Config} through the * {@link ConfigVar#SESSION_config} object that can be specified as either a session object (temporary) or * context object (permanent). * In this case, we call the following code to add it to the context map: * <p class='bcode w800'> * config.addVarContextObject(<jsf>SESSION_config</jsf>, configFile); * </p> * * @param name The context object key (i.e. the name that the Var class looks for). * @param object The context object. * @return This object (for method chaining). */ public RestContextBuilder varContextObject(String name, Object object) { this.varResolverBuilder.contextObject(name, object); return this; }