@Override public LoggingAdvisingAppendable append(CharSequence csq, int start, int end) throws IOException { buffer.append(csq, start, end); commandBuffer.append(csq, start, end); return this; }
@Override public String toString() { if (commands != null) { // NOTE: this ignores all the logging statements which is as it should be since they don't // affect output StringBuilder builder = new StringBuilder(); appendCommandsToBuilder(commands, builder); builder.append(delegate); return builder.toString(); } else { return delegate.toString(); } }
private static void appendCommandsToBuilder(List<Object> commands, StringBuilder builder) { for (Object o : commands) { if (o instanceof String) { builder.append((String) o); } else if (o instanceof LoggingFunctionCommand) { LoggingFunctionCommand command = (LoggingFunctionCommand) o; builder.append(escapePlaceholder(command.fn().placeholderValue(), command.escapers())); } } }
@Override public RenderResult renderAndResolve(LoggingAdvisingAppendable appendable, boolean isLast) throws IOException { if (isDone()) { buffer.replayOn(appendable); return RenderResult.done(); } if (isLast) { RenderResult result = doRender(appendable); if (result.isDone()) { resolvedValue = TombstoneValue.INSTANCE; } return result; } TeeAdvisingAppendable currentBuilder = (TeeAdvisingAppendable) builder; if (currentBuilder == null) { builder = currentBuilder = new TeeAdvisingAppendable(appendable); } RenderResult result = doRender(currentBuilder); if (result.isDone()) { buffer = currentBuilder.buffer; builder = null; } return result; }
@Override public RenderResult renderAndResolve(LoggingAdvisingAppendable appendable, boolean isLast) throws IOException { if (isDone()) { if (buffer == null && resolvedValue == TombstoneValue.INSTANCE) { throw new IllegalStateException( "calling renderAndResolve after setting isLast = true is not supported"); } buffer.replayOn(appendable); return RenderResult.done(); } if (isLast) { RenderResult result = doRender(appendable); if (result.isDone()) { resolvedValue = TombstoneValue.INSTANCE; } return result; } TeeAdvisingAppendable currentBuilder = (TeeAdvisingAppendable) builder; if (currentBuilder == null) { builder = currentBuilder = new TeeAdvisingAppendable(appendable); } RenderResult result = doRender(currentBuilder); if (result.isDone()) { buffer = currentBuilder.buffer; builder = null; } return result; }
public void replayOn(LoggingAdvisingAppendable appendable) throws IOException { if (commands != null) { for (Object o : getCommandsAndAddPendingStringData()) { if (o instanceof String) { appendable.append((String) o); } else if (o instanceof LoggingFunctionCommand) { ((LoggingFunctionCommand) o).replayOn(appendable); } else if (o == EXIT_LOG_STATEMENT_MARKER) { appendable.exitLoggableElement(); } else if (o instanceof LogStatement) { appendable.enterLoggableElement((LogStatement) o); } else if (o instanceof ContentKind) { appendable.setSanitizedContentKind((ContentKind) o); } else if (o instanceof Dir) { appendable.setSanitizedContentDirectionality((Dir) o); } else if (o == SET_SANITIZED_CONTENT_DIRECTIONALITY_NULL_MARKER) { appendable.setSanitizedContentDirectionality(null); } else { throw new AssertionError("unexpected command object: " + o); } } } else { appendable.append(delegate); } }
@Override public void close() throws IOException { BidiFormatter formatter = BidiFormatter.getInstance(globalDir.toDir()); BidiWrappingText wrappingText; switch (wrapType) { case SPAN: wrappingText = formatter.spanWrappingText( getSanitizedContentDirectionality(), buffer.toString(), true /* isHtml */); break; case UNICODE: wrappingText = formatter.unicodeWrappingText( getSanitizedContentDirectionality(), buffer.toString(), getSantizedContentKind() == ContentKind.HTML); break; default: throw new IllegalArgumentException("invalid wrap type: " + wrapType); } delegate.append(wrappingText.beforeText()); commandBuffer.replayOn(delegate); delegate.append(wrappingText.afterText()); } }
public void replayOn(LoggingAdvisingAppendable appendable) throws IOException { if (commands != null) { for (Object o : getCommandsAndAddPendingStringData()) { if (o instanceof String) { appendable.append((String) o); } else if (o instanceof LoggingFunctionCommand) { ((LoggingFunctionCommand) o).replayOn(appendable); } else if (o == EXIT_LOG_STATEMENT_MARKER) { appendable.exitLoggableElement(); } else if (o instanceof LogStatement) { appendable.enterLoggableElement((LogStatement) o); } else if (o instanceof ContentKind) { appendable.setSanitizedContentKind((ContentKind) o); } else if (o instanceof Dir) { appendable.setSanitizedContentDirectionality((Dir) o); } else if (o == SET_SANITIZED_CONTENT_DIRECTIONALITY_NULL_MARKER) { appendable.setSanitizedContentDirectionality(null); } else { throw new AssertionError("unexpected command object: " + o); } } } else { appendable.append(delegate); } }
@Override public void close() throws IOException { BidiFormatter formatter = BidiFormatter.getInstance(globalDir.toDir()); BidiWrappingText wrappingText; switch (wrapType) { case SPAN: wrappingText = formatter.spanWrappingText( getSanitizedContentDirectionality(), buffer.toString(), /* isHtml= */ true); break; case UNICODE: wrappingText = formatter.unicodeWrappingText( getSanitizedContentDirectionality(), buffer.toString(), getSantizedContentKind() == ContentKind.HTML); break; default: throw new IllegalArgumentException("invalid wrap type: " + wrapType); } delegate.append(wrappingText.beforeText()); commandBuffer.replayOn(delegate); delegate.append(wrappingText.afterText()); } }
@Override protected void notifyContentKind(ContentKind kind) throws IOException { getCommandsAndAddPendingStringData().add(kind); }
@Override protected void doAppendLoggingFunctionInvocation( LoggingFunctionInvocation funCall, ImmutableList<Function<String, String>> escapers) throws IOException { getCommandsAndAddPendingStringData().add(LoggingFunctionCommand.create(funCall, escapers)); }
/** Called whenever a loggable element is exited. */ @Override protected final void doExitLoggableElement() { getCommandsAndAddPendingStringData().add(EXIT_LOG_STATEMENT_MARKER); }
/** Called whenever a loggable element is entered. */ @Override protected final void doEnterLoggableElement(LogStatement statement) { getCommandsAndAddPendingStringData().add(statement); }
@Override public LoggingAdvisingAppendable exitLoggableElement() { delegate.exitLoggableElement(); buffer.exitLoggableElement(); return this; }
@Override public TeeAdvisingAppendable append(CharSequence csq) throws IOException { delegate.append(csq); buffer.append(csq); return this; }
@Override protected void notifyContentDirectionality(@Nullable Dir contentDir) throws IOException { delegate.setSanitizedContentDirectionality(contentDir); buffer.setSanitizedContentDirectionality(contentDir); }
/** Called whenever a loggable element is entered. */ @Override protected final void doEnterLoggableElement(LogStatement statement) { getCommandsAndAddPendingStringData().add(statement); }
@Override public LoggingAdvisingAppendable exitLoggableElement() { commandBuffer.exitLoggableElement(); return this; }
private static void appendCommandsToBuilder(List<Object> commands, StringBuilder builder) { for (Object o : commands) { if (o instanceof String) { builder.append((String) o); } else if (o instanceof LoggingFunctionCommand) { LoggingFunctionCommand command = (LoggingFunctionCommand) o; builder.append(escapePlaceholder(command.fn().placeholderValue(), command.escapers())); } } }
@Override public TeeAdvisingAppendable append(char c) throws IOException { delegate.append(c); buffer.append(c); return this; }