001/*license*\ 002 Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com) 003 004 This software is dual-licensed under the: 005 - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version; 006 - Apache Software License (ASL) version 2.0. 007 008 Either license may be applied at your discretion. More information may be found at 009 - http://en.wikipedia.org/wiki/Multi-licensing. 010 011 The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at: 012 - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt 013 - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt 014\*license*/ 015package com.github.aliteralmind.codelet.type; 016 import com.github.xbn.text.StringUtil; 017 import com.github.aliteralmind.codelet.simplesig.SimpleMethodSignature; 018 import com.github.aliteralmind.codelet.CodeletInstance; 019 import com.github.aliteralmind.codelet.CodeletType; 020 import com.github.aliteralmind.codelet.CustomizationInstructions; 021 import com.github.aliteralmind.codelet.TagletOfTypeProcessor; 022 import java.nio.file.AccessDeniedException; 023 import java.nio.file.NoSuchFileException; 024 import java.util.Iterator; 025 import static com.github.aliteralmind.codelet.CodeletBaseConfig.*; 026/** 027 <p>Reads a {@link com.github.aliteralmind.codelet.CodeletType#CONSOLE_OUT {@.codelet.out}} taglet and outputs its replacement text.</p> 028 029 * @since 0.1.0 030 * @author Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a> 031 **/ 032public class ConsoleOutProcessor extends TagletOfTypeProcessor<ConsoleOutTemplate> { 033 /** 034 <p>Create a new instance from an {@code CodeletInstance}.</p> 035 036 * <p>Equal to <code>{@link com.github.aliteralmind.codelet.TagletOfTypeProcessor#TagletOfTypeProcessor(CodeletType, CodeletInstance) super}(CodeletType.CONSOLE_OUT, instance)</code> 037 038 039 <p>This<ol> 040 <li>Gets the {@linkplain #getExampleCodeStringSig() example code's string signature} from the instance.</li> 041 <li>Gets the {@linkplain com.github.aliteralmind.codelet.simplesig.SimpleMethodSignature#getForMainFromStringSig(Object, Appendable) simple signature} from that</li> 042 <li>{@linkplain com.github.aliteralmind.codelet.simplesig.SimpleMethodSignature#invokeGetMainOutputNoExtraParams(String) Invokes and captures} the output from its <a href="http://docs.oracle.com/javase/tutorial/getStarted/application/index.html#MAIN">{@code main} function</a></li> 043 <li>Returns a {@linkplain com.github.xbn.text.StringUtil#getLineIterator(Object) line iterator} for it.</li> 044 </ol></p> 045 046 */ 047 public ConsoleOutProcessor(CodeletInstance instance) throws ClassNotFoundException, NoSuchMethodException, NoSuchFileException, AccessDeniedException { 048 super(CodeletType.CONSOLE_OUT, instance); 049 050 String output = SimpleMethodSignature.getForMainFromStringSig( 051 getExampleCodeStringSig(), 052 getDebugApblIfOn(null, 053 "zzConsoleOutProcessor.consoleoutputfromexamplecodestringsig")). 054 invokeGetMainOutputNoExtraParams("Executing example code"); 055 Iterator<String> sysDotOutLineItr = StringUtil.getLineIterator(output); 056 057 CustomizationInstructions<ConsoleOutTemplate> instructions = 058 getCustomizationInstructions(CodeletType.CONSOLE_OUT); 059 060 String sysDotOutCustomized = instructions.getCustomizedBody(instance, sysDotOutLineItr); 061 062 ConsoleOutTemplate template = getTemplateFromInstructionsOverrideOrDefault( 063 instructions); 064 065 String finalOutput = template.fillBody(sysDotOutCustomized).getRendered(instance); 066 setFullyProcessedOutput(finalOutput); 067 } 068}