|
1 | 1 | package org.fugerit.java.doc.freemarker.tool; |
2 | 2 |
|
| 3 | +import java.io.File; |
| 4 | +import java.io.FileInputStream; |
| 5 | +import java.io.InputStream; |
3 | 6 | import java.io.Writer; |
4 | 7 | import java.util.Properties; |
5 | 8 |
|
6 | 9 | import org.fugerit.java.core.io.StreamIO; |
| 10 | +import org.fugerit.java.core.lang.helpers.StringUtils; |
7 | 11 | import org.fugerit.java.doc.base.process.DocProcessContext; |
8 | 12 | import org.fugerit.java.doc.base.process.DocProcessData; |
9 | 13 | import org.fugerit.java.doc.freemarker.helper.FreeMarkerDocProcess; |
| 14 | +import org.fugerit.java.doc.freemarker.tool.model.ConfigModel; |
10 | 15 |
|
11 | | -public class GenerateStub { |
| 16 | +import lombok.extern.slf4j.Slf4j; |
12 | 17 |
|
| 18 | +@Slf4j |
| 19 | +public class GenerateStub { |
| 20 | + |
| 21 | + public static final String ATT_CONFIG_MODEL = "configModel"; |
| 22 | + |
13 | 23 | public static final String CONFIG_STUB_CHAIN_ID = "freemarker-doc-process-config-stub"; |
14 | 24 |
|
15 | 25 | public static final String ATT_STUB_PARAMS = "stubParams"; |
@@ -59,10 +69,30 @@ public class GenerateStub { |
59 | 69 | */ |
60 | 70 | public static final String PARAM_FM_TEMPLATE_PATH = "fm-template-path"; |
61 | 71 |
|
62 | | - public static void generate( Writer w, Properties params ) throws Exception { |
| 72 | + public static final String ARG_INPUT_FILE = "input"; |
| 73 | + |
| 74 | + public static void generate( Writer out, Properties params ) throws Exception { |
| 75 | + String input = params.getProperty(ARG_INPUT_FILE); |
| 76 | + if ( StringUtils.isNotEmpty( input ) ) { |
| 77 | + try ( InputStream is = new FileInputStream( new File( input ) ) ) { |
| 78 | + generate(out, params, is); |
| 79 | + } |
| 80 | + } else { |
| 81 | + generate(out, params, null); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public static void generate( Writer out, Properties params, InputStream is ) throws Exception { |
| 86 | + ConfigModel configModel = null; |
63 | 87 | DocProcessData data = new DocProcessData(); |
64 | | - FreeMarkerDocProcess.getInstance().process( CONFIG_STUB_CHAIN_ID, DocProcessContext.newContext( ATT_STUB_PARAMS, params ), data ); |
65 | | - StreamIO.pipeChar( data.getCurrentXmlReader() , w, StreamIO.MODE_CLOSE_IN_ONLY ); |
| 88 | + DocProcessContext context = DocProcessContext.newContext( ATT_STUB_PARAMS, params ); |
| 89 | + if ( is != null ) { |
| 90 | + log.info( "read legacy config model" ); |
| 91 | + configModel = LegacyConfigRead.readConfig(is); |
| 92 | + context = context.withAtt( ATT_CONFIG_MODEL , configModel ); |
| 93 | + } |
| 94 | + FreeMarkerDocProcess.getInstance().process( CONFIG_STUB_CHAIN_ID, context, data ); |
| 95 | + StreamIO.pipeChar( data.getCurrentXmlReader() , out, StreamIO.MODE_CLOSE_IN_ONLY ); |
66 | 96 | } |
67 | 97 |
|
68 | 98 | } |
0 commit comments