/** * Add a screenshot to a context. * * @param file * @return */ private static int addSnapshot(Context context, File file) { List<SnapshotInfo> list = (List<SnapshotInfo>) context.getInternalObject(Keys.SNAPSHOTS, true); if (list == null) { list = new ArrayList<SnapshotInfo>(1); context.setInternalObject(Keys.SNAPSHOTS, list, true); } final SnapshotInfo si = new SnapshotInfo(); si.setFile(file); context.getStack().traverse(new IStackTraverser() { public boolean onItem(IEntity entity, ITag tag) { CallStack cs = new CallStack(); cs.setEntity(entity); cs.setTag(tag); si.getCallStack().add(cs); return true; } }); list.add(si); return list.size(); }
log.warn("Properties has no content loaded: " + context.getStack().getFirst());
@Override protected String convert(LoggingEvent event) { Context context = Context.getCurrentContext(); if (context == null) { return "*"; } else { Stack stack=context.getStack(); final StringBuilder sb = new StringBuilder(); if(!stack.isEmpty()){ sb.append(stack.getFirst().getTagName()); } stack.traverse(new IStackTraverser() { @Override public boolean onItem(IEntity entity, ITag tag) { String name = entity.getResource().getName(); if (StringUtils.isBlank(name)) { name = "?"; } sb.insert(0, " > ").insert(0, tag.getLineNumber()).insert(0, "@").insert(0, name); return fullStack; } }); // when it has no stack, it shows question mark. return sb.length() > 0 ? sb.toString() : "?"; } }
exceptionContext.getStack().traverse(new IStackTraverser() {
exceptionContext.getStack().traverse(new IStackTraverser() {
log.warn("Properties has no content loaded: " + context.getStack().getFirst());
/** * Add a screenshot to a context. * * @param file * @return */ private static int addSnapshot(Context context, File file) { List<SnapshotInfo> list = (List<SnapshotInfo>) context.getInternalObject(Keys.SNAPSHOTS, true); if (list == null) { list = new ArrayList<SnapshotInfo>(1); context.setInternalObject(Keys.SNAPSHOTS, list, true); } final SnapshotInfo si = new SnapshotInfo(); si.setFile(file); context.getStack().traverse(new IStackTraverser() { public boolean onItem(IEntity entity, ITag tag) { CallStack cs = new CallStack(); cs.setEntity(entity); cs.setTag(tag); si.getCallStack().add(cs); return true; } }); list.add(si); return list.size(); }
@Override protected String convert(LoggingEvent event) { Context context = Context.getCurrentContext(); if (context == null) { return "*"; } else { Stack stack=context.getStack(); final StringBuilder sb = new StringBuilder(); if(!stack.isEmpty()){ sb.append(stack.getFirst().getTagName()); } stack.traverse(new IStackTraverser() { @Override public boolean onItem(IEntity entity, ITag tag) { String name = entity.getResource().getName(); if (StringUtils.isBlank(name)) { name = "?"; } sb.insert(0, " > ").insert(0, tag.getLineNumber()).insert(0, "@").insert(0, name); return fullStack; } }); // when it has no stack, it shows question mark. return sb.length() > 0 ? sb.toString() : "?"; } }
/** * Call the execute() method of all children tags in order. * * @param context * the execution context. * @return the execution result. */ protected ChildrenResultList executeChildren(Context context) { int index = 0; Stack stack = context.getStack(); ChildrenResultList result = new ChildrenResultList(1); for (ITag tag : getChildren()) { if (stack.isDying()) { return null; } if (!stack.isEmpty() && context.getCurrentEntityContext().isReturning()) { break; } result.add(executeChild(tag, index++, context)); } return result; }
/** * Call the execute() method of all children tags in order. * * @param context * the execution context. * @return the execution result. */ protected ChildrenResultList executeChildren(Context context) { int index = 0; Stack stack = context.getStack(); ChildrenResultList result = new ChildrenResultList(1); for (ITag tag : getChildren()) { if (stack.isExiting()) { return null; } if (!stack.isEmpty() && context.getCurrentEntityContext().isReturning()) { break; } result.add(executeChild(tag, index++, context)); } return result; }
/** * Get the current execution stack from context. * * @return the current stack from the execution context, never null */ public Stack getStack() { Stack stack = (Stack) getInternalObject(PrivateKeys.STACK, true); if (stack == null) { stack = new Stack(); setInternalObject(PrivateKeys.STACK, stack, true); } return stack; }
/** * Get the current execution stack from context. * * @return the current stack from the execution context, never null */ public Stack getStack() { Stack stack = (Stack) getInternalObject(PrivateKeys.STACK, true); if (stack == null) { stack = new Stack(); setInternalObject(PrivateKeys.STACK, stack, true); } return stack; }
/** * Pop a tag from execution stack. * */ public void popStack() { getStack().pop(); }
/** * Push an tag into execution stack. * * @param tag * the tag */ public void pushStack(ITag tag) { getStack().push(tag); }
/** * Push an tag into execution stack. * * @param tag * the tag */ public void pushStack(ITag tag) { getStack().push(tag); }
/** * Pop a tag from execution stack. * */ public void popStack() { getStack().pop(); }