@Override /* Object */ public String toString() { if (varSession != null) return varSession.resolve(contents); return contents; } }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, true); return req.getHeader(key); } }
@Override /* Writeable */ public void writeTo(Writer w) throws IOException { if (varSession != null) varSession.resolveTo(contents, w); else w.write(contents); }
if (isSimpleVar(s)) { String var = s.substring(1, s.indexOf('{')); String val = s.substring(s.indexOf('{')+1, s.length()-1); Var v = getVar(var); if (v != null) { try { if (s == null) s = ""; return (v.allowRecurse() ? resolve(s) : s); } catch (VarResolverException e) { throw e; return resolveTo(s, new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); // Never happens.
return null; if (o instanceof CharSequence) return (T)resolve(o.toString()); if (o.getClass().isArray()) { if (! containsVars(o)) return o; Object o2 = Array.newInstance(o.getClass().getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) Array.set(o2, i, resolve(Array.get(o, i))); return (T)o2; try { Collection c = (Collection)o; if (! containsVars(c)) return o; Collection c2 = c.getClass().newInstance(); for (Object o2 : c) c2.add(resolve(o2)); return (T)c2; } catch (VarResolverException e) { try { Map m = (Map)o; if (! containsVars(m)) return o; Map m2 = m.getClass().newInstance(); for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) m2.put(e.getKey(), resolve(e.getValue())); return (T)m2;
/** * Same as {@link #createSession()} except allows you to specify session objects as a map. * * @param sessionObjects The session objects to associate with the session. * @return A new resolver session. */ public VarResolverSession createSession(Map<String,Object> sessionObjects) { return new VarResolverSession(ctx, sessionObjects); }
if (isSimpleVar(s)) { String var = s.substring(1, s.indexOf('{')); String val = s.substring(s.indexOf('{')+1, s.length()-1); Var v = getVar(var); if (v != null) { try { if (s == null) s = ""; return (v.allowRecurse() ? resolve(s) : s); } catch (VarResolverException e) { throw e; return resolveTo(s, new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); // Never happens.
return null; if (o instanceof CharSequence) return (T)resolve(o.toString()); if (o.getClass().isArray()) { if (! containsVars(o)) return o; Object o2 = Array.newInstance(o.getClass().getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) Array.set(o2, i, resolve(Array.get(o, i))); return (T)o2; try { Collection c = (Collection)o; if (! containsVars(c)) return o; Collection c2 = c.getClass().newInstance(); for (Object o2 : c) c2.add(resolve(o2)); return (T)c2; } catch (VarResolverException e) { try { Map m = (Map)o; if (! containsVars(m)) return o; Map m2 = m.getClass().newInstance(); for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) m2.put(e.getKey(), resolve(e.getValue())); return (T)m2;
/** * Creates a new resolver session with no session objects. * * <p> * Session objects can be associated with the specified session using the {@link VarResolverSession#sessionObject(String, Object)} * method. * * @return A new resolver session. */ public VarResolverSession createSession() { return new VarResolverSession(ctx, null); }
private String resolve(String s) { if (s == null) return null; return vr.resolve(s.trim()); }
@Override /* Parameter */ public String resolve(VarResolverSession session, String[] args) { if (args.length > 0) { String key = args[0]; String[] a = (args.length > 1) ? Arrays.copyOfRange(args, 1, args.length) : new String[0]; return session.getSessionObject(RestRequest.class, RequestVar.SESSION_req, true).getMessage(key, (Object[])a); } return ""; } }
if (isSimpleVar(s)) { String var = s.substring(1, s.indexOf('{')); String val = s.substring(s.indexOf('{')+1, s.length()-1); Var v = getVar(var); if (v != null) { try { if (s == null) s = ""; return (v.allowRecurse() ? resolve(s) : s); } catch (VarResolverException e) { throw e; return resolveTo(s, new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); // Never happens.
return null; if (o instanceof CharSequence) return (T)resolve(o.toString()); if (o.getClass().isArray()) { if (! containsVars(o)) return o; Object o2 = Array.newInstance(o.getClass().getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) Array.set(o2, i, resolve(Array.get(o, i))); return (T)o2; try { Collection c = (Collection)o; if (! containsVars(c)) return o; Collection c2 = c.getClass().newInstance(); for (Object o2 : c) c2.add(resolve(o2)); return (T)c2; } catch (VarResolverException e) { try { Map m = (Map)o; if (! containsVars(m)) return o; Map m2 = m.getClass().newInstance(); for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) m2.put(e.getKey(), resolve(e.getValue())); return (T)m2;
/** * 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); } }
/** * Same as {@link #createSession()} except allows you to specify session objects as a map. * * @param sessionObjects The session objects to associate with the session. * @return A new resolver session. */ public VarResolverSession createSession(Map<String,Object> sessionObjects) { return new VarResolverSession(ctx, sessionObjects); }
private String resolve(String s) { if (s == null) return null; return vr.resolve(s.trim()); }
@Override /* Parameter */ public String resolve(VarResolverSession session, String[] args) { if (args.length > 0) { String key = args[0]; String[] a = (args.length > 1) ? Arrays.copyOfRange(args, 1, args.length) : new String[0]; return session.getSessionObject(RestRequest.class, RequestVar.SESSION_req).getMessage(key, (Object[])a); } return ""; } }