@Override public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException { switch (def) { case ENVAR: final String e = System.getenv(Token.string(checkEStr(expr[0], ctx))); return e != null ? Str.get(e) : null; default: return super.item(ctx, ii); } }
@Override public Iter iter(final QueryContext ctx) throws QueryException { switch (def) { case ERROR: final int al = expr.length; if (al == 0) FUNERR1.thrw(input); String code = FUNERR1.code(); String msg = FUNERR1.desc; final Item it = expr[0].item(ctx, input); if (it == null) { if (al == 1) XPEMPTY.thrw(input, desc()); } else { code = Token.string(((QNm) checkType(it, AtomType.QNM)).ln()); } if (al > 1) msg = Token.string(checkEStr(expr[1], ctx)); final Value val = al > 2 ? expr[2].value(ctx) : null; final QueryException ex = new QueryException(input, code, val, msg); throw ex; case TRACE: return new Iter() { final Iter ir = expr[0].iter(ctx); final byte[] s = checkEStr(expr[1], ctx); @Override public Item next() throws QueryException { final Item i = ir.next(); if (i != null) { final TokenBuilder tb = new TokenBuilder(s); if (s.length != 0) tb.add(": "); tb.add(i.toString()); // if GUI is used, or if user is no admin, trace info is cached if (Prop.gui || !ctx.context.user.perm(User.ADMIN)) { ctx.evalInfo(tb.finish()); } else { Util.errln(tb); } } return i; } }; case ENVARS: final ItemCache ic = new ItemCache(); for (final Object k : System.getenv().keySet().toArray()) { ic.add(Str.get(k)); } return ic; default: return super.iter(ctx); } }