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.aliteralmind.codelet.CodeletType;
017   import  com.github.aliteralmind.codelet.UserExtraGapGetter;
018   import  com.github.aliteralmind.codelet.CodeletGap;
019   import  com.github.aliteralmind.codelet.CodeletBaseConfig;
020   import  com.github.aliteralmind.codelet.CodeletInstance;
021   import  com.github.aliteralmind.codelet.TagletTextUtil;
022   import  com.github.aliteralmind.templatefeather.FeatherTemplate;
023   import  java.util.Map;
024   import  java.util.Set;
025   import  java.util.TreeMap;
026   import  static com.github.xbn.lang.XbnConstants.*;
027/**
028   <p>The text into which {@code {@.file.textlet}} output (the example-code's console output) is placed.</p>
029
030   <A NAME="gaps"></a><h2><a href="{@docRoot}/com/github/aliteralmind/codelet/CodeletTemplateBase.html"><IMG SRC="{@docRoot}/resources/up_arrow.gif"/></a> &nbsp; Codelet: {@code {@.file.textlet}}: Template: <u>Gap names</u></h2>
031
032   <p>The only required gap is &quot;{@link com.github.aliteralmind.codelet.type.OnlyOneBodyGapTemplateBase#BODY_GAP_NAME body}&quot;, which is where the fully-processed source-code is placed.</p>
033
034   <p>In addition to any {@linkplain com.github.aliteralmind.codelet.UserExtraGapGetter#getForFileTextlet() user-extra} gaps, the {@code {@.codelet}} template also provides for the following &quot;default&quot; optional gaps:</p>
035
036   <A NAME="gaps"></a><p><a href="SourceCodeTemplate.html"><IMG SRC="{@docRoot}/resources/up_arrow.gif"/></a> &nbsp; <b>Url-related:</b></p>
037
038   <p><TABLE ALIGN="center" BORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="#EEEEEE"><TR ALIGN="center" VALIGN="middle">
039      <TD><b><u>Name</u></b></TD>
040      <TD><b><u>Description</u></b></TD>
041   </TR><TR>
042      <TD>{@link #GAP_REL_PATH_AS_URL rel_path_url}</TD>
043      <TD>The file's relative url-path, as it exists in the base url.</TD>
044   </TR><TR>
045      <TD>{@link #GAP_URL javadoc_path_url}</TD>
046      <TD>The absolute url to the example code's source file, as exists somewhere in the JavaDoc output directory ({@code {@docRoot}}).</TD>
047   </TR><TR>
048      <TD>{@link #GAP_REL_DIR_AS_URL relative_dir_as_url}</TD>
049      <TD>The example code's relative_dir, with file-separators replaced by url-slashes ({@code '/'}).</TD>
050   </TR></TABLE></p>
051
052   <A NAME="gaps"></a><p><a href="SourceCodeTemplate.html"><IMG SRC="{@docRoot}/resources/up_arrow.gif"/></a> &nbsp; <b>Non-url related:</b></p>
053
054   <p><TABLE ALIGN="center" BORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="#EEEEEE"><TR ALIGN="center" VALIGN="middle">
055      <TD><b><u>Name</u></b></TD>
056      <TD><b><u>Description</u></b></TD>
057   </TR><TR>
058      <TD>{@link #GAP_PATH path}</TD>
059      <TD>The absolute on-disk path to the file.</TD>
060   </TR><TR>
061      <TD>{@link #GAP_BASE_DIR base_dir}</TD>
062      <TD>The on-disk path that is prepended to the file's relative path.</TD>
063   </TR><TR>
064      <TD>{@link #GAP_FILE_NAME_NO_EXT file_name_no_ext}</TD>
065      <TD>The name of the file, without its dot-extension (such as .txt"}).</TD>
066   </TR><TR>
067      <TD>{@link #GAP_FILE_NAME_WITH_EXT file_name}</TD>
068      <TD>The name of the file, including its dot-extension (such as .txt"}).</TD>
069   </TR><TR>
070      <TD>{@link #GAP_RELATIVE_PATH file_name_dir}</TD>
071      <TD>The example's path as it exists in the base directory.</TD>
072   </TR><TR>
073      <TD>{@link #GAP_RELATIVE_DIR relative_dir}</TD>
074      <TD>The example code's relative directory, as it exists in the absolute path.</TD>
075   </TR></TABLE></p>
076
077 * @since  0.1.0
078 * @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>
079 **/
080public class FileTextTemplate extends OnlyOneBodyGapTemplateBase  {
081   /**
082      <p>The absolute on-disk path to the file--Gap name is {@code "path"}.</p>
083
084      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
085
086      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getFilePath(CodeletInstance) getFilePath}(<i>[the-instance]</i>)</code></p>
087
088    * @see  #GAP_BASE_DIR
089    * @see  #GAP_RELATIVE_PATH
090    */
091   public static final CodeletGap GAP_PATH = new FilePathGap();
092   /**
093      <p>The on-disk path that is prepended to the file's relative path--Gap name is {@code "base_dir"}.</p>
094
095      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
096
097      <p><code>{@link com.github.aliteralmind.codelet.CodeletBaseConfig CodeletBaseConfig}.{@link com.github.aliteralmind.codelet.CodeletBaseConfig#INSTANCE INSTANCE}.{@link com.github.aliteralmind.codelet.CodeletBaseConfig#getExampleSourceBaseDir() getExampleSourceBaseDir}()</code></p>
098
099    * @see  #GAP_PATH
100    */
101   public static final CodeletGap GAP_BASE_DIR = new FileBaseDirGap();
102   /**
103      <p>The name of the file, without its dot-extension (such as {@code ".txt"})--Gap name is {@code "file_name_no_ext"}.</p>
104
105      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
106
107      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getFileNameWithoutExtension(CodeletInstance) getFileNameWithoutExtension}(<i>[the-instance]</i>)</code></p>
108
109    * @see  #GAP_FILE_NAME_WITH_EXT
110    * @see  #GAP_RELATIVE_PATH
111    */
112   public static final CodeletGap GAP_FILE_NAME_NO_EXT = new FileNameNoExtGap();
113   /**
114      <p>The name of the file, including its dot-extension (such as {@code ".txt"})--Gap name is {@code "file_name"}.</p>
115
116      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
117
118      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getFileNameWithExtension(CodeletInstance) getFileNameWithExtension}(<i>[the-instance]</i>)</code></p>
119
120    * @see  #GAP_RELATIVE_PATH
121    * @see  #GAP_REL_PATH_AS_URL
122    * @see  #GAP_FILE_NAME_NO_EXT
123    */
124   public static final CodeletGap GAP_FILE_NAME_WITH_EXT = new FileNameWithExtGap();
125   /**
126      <p>The file's relative url-path, as it exists in the base url--Gap name is {@code "rel_path_url"}..</p>
127
128      <p>Example input:<ol>
129         <li>Example code's {@linkplain com.github.aliteralmind.codelet.TagletTextUtil#getExampleClassFQName(CodeletInstance) fully-qualified class name}: {@code "fully.qualified.examples.AnExample"}</li>
130      </ol></p>
131
132      <p>{@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) Output}:</p>
133
134      <p>{@code "fully/qualified/examples/AnExample"}</p>
135
136      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
137
138      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getExampleClassFQName(CodeletInstance) getExampleClassFQName}(<i>[the-instance]</i>).{@link java.lang.String#replace(CharSequence, CharSequence) replace}(&quot;.&quot;, &quot;/&quot;)</code></p>
139
140    * @see  #GAP_URL
141    */
142   public static final CodeletGap GAP_REL_PATH_AS_URL = new RelPathAsUrlGap();
143   /**
144      <p>The example's path as it exists in the base directory--Gap name is {@code "file_name_dir"}.</p>
145
146      <p>Example input:<ol>
147         <li>Example code's {@linkplain com.github.aliteralmind.codelet.TagletTextUtil#getExampleClassFQName(CodeletInstance) fully-qualified class name}: {@code "fully.qualified.examples.AnExample"}</li>
148      </ol></p>
149
150      <p>{@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) Output} (assuming Microsoft Windows):</p>
151
152      <p>{@code "fully\qualified\examples\AnExample"}</p>
153
154      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
155
156      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getExampleClassFQName(CodeletInstance) getExampleClassFQName}(<i>[the-instance]</i>).{@link java.lang.String#replace(CharSequence, CharSequence) replace}(&quot;.&quot;, {@link com.github.xbn.lang.XbnConstants#FILE_SEP FILE_SEP}*)</code></p>
157
158    * @see  #GAP_PATH
159    * @see  #GAP_REL_PATH_AS_URL
160    * @see  #GAP_FILE_NAME_WITH_EXT
161    */
162   public static final CodeletGap GAP_RELATIVE_PATH = new RelativeDirGap();
163   /**
164      <p>The absolute url to the example code's source file, as exists somewhere in the JavaDoc output directory ({@code {@docRoot}})--Gap name is {@code "javadoc_path_url"}.</p>
165
166      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
167
168      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getJavaDocSourceUrl(CodeletInstance) getJavaDocSourceUrl}(<i>[the-instance]</i>)</code></p>
169    */
170   public static final CodeletGap GAP_URL = new JavaDocFileUrlGap();
171   /**
172      <p>The example code's relative directory, as it exists in the absolute path--Gap name is {@code "relative_dir"}.</p>
173
174      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
175
176      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getFilePath(CodeletInstance) getFilePath}(<i>[the-instance]</i>)</code></p>
177
178    * @see  #GAP_PATH
179    * @see  #GAP_REL_DIR_AS_URL
180    */
181   public static final CodeletGap GAP_RELATIVE_DIR = new RelDirGap();
182   /**
183      <p>The example code's relative_dir, with file-separators replaced by url-slashes ({@code '/'})--Gap name is {@code "relative_dir_as_url"}.</p>
184
185      <p>Gap is {@linkplain com.github.aliteralmind.codelet.CodeletGap#getFillText(CodeletInstance) filled} with</p>
186
187      <p><code>{@link com.github.aliteralmind.codelet.TagletTextUtil TagletTextUtil}.{@link com.github.aliteralmind.codelet.TagletTextUtil#getFilePath(CodeletInstance) getFilePath}(<i>[the-instance]</i>).{@link java.lang.String#replace(CharSequence, CharSequence) replace}(&quot;.&quot;, &quot;/&quot;)</code></p>
188
189    * @see  #GAP_RELATIVE_DIR
190    */
191   public static final CodeletGap GAP_REL_DIR_AS_URL = new RelDirAsUrlGap();
192
193   /**
194      <p>Create the first instance.</p>
195
196    * <p>Equal to</p>
197
198<blockquote><pre>
199{@link com.github.aliteralmind.codelet.type.OnlyOneBodyGapTemplateBase#OnlyOneBodyGapTemplateBase(CodeletType, FeatherTemplate, String, CodeletGap[], UserExtraGapGetter) super}({@link com.github.aliteralmind.codelet.CodeletType CodeletType}.{@link com.github.aliteralmind.codelet.CodeletType#FILE_TEXT FILE_TEXT}, template, tmpl_path,
200   new CodeletGap[] {
201      {@link #GAP_PATH},
202      {@link #GAP_BASE_DIR},
203      {@link #GAP_FILE_NAME_NO_EXT},
204      {@link #GAP_FILE_NAME_WITH_EXT},
205      {@link #GAP_REL_PATH_AS_URL},
206      {@link #GAP_RELATIVE_PATH},
207      {@link #GAP_URL},
208      {@link #GAP_RELATIVE_DIR},
209      {@link #GAP_REL_DIR_AS_URL}},
210   userExtra_getter)
211</pre></blockquote>
212
213    * @see  #FileTextTemplate(FileTextTemplate, FeatherTemplate, String)
214    */
215   public FileTextTemplate(FeatherTemplate template, String tmpl_path, UserExtraGapGetter userExtra_getter)  {
216      super(CodeletType.SOURCE_CODE, template, tmpl_path,
217         new CodeletGap[] {
218            GAP_PATH,
219            GAP_BASE_DIR,
220            GAP_FILE_NAME_NO_EXT,
221            GAP_FILE_NAME_WITH_EXT,
222            GAP_REL_PATH_AS_URL,
223            GAP_RELATIVE_PATH,
224            GAP_URL,
225            GAP_RELATIVE_DIR,
226            GAP_REL_DIR_AS_URL},
227         userExtra_getter);
228   }
229   /**
230      <p>Create the second or subsequent instance.</p>
231
232    * <p>Equal to</p>
233
234<blockquote><pre>{@link com.github.aliteralmind.codelet.type.OnlyOneBodyGapTemplateBase#OnlyOneBodyGapTemplateBase(OnlyOneBodyGapTemplateBase, FeatherTemplate, String) super}(to_copy, template, tmpl_path)</pre></blockquote>
235
236    * @see  #FileTextTemplate(FeatherTemplate, String, UserExtraGapGetter)
237    */
238   public FileTextTemplate(FileTextTemplate to_copy, FeatherTemplate template, String tmpl_path)  {
239      super(to_copy, template, tmpl_path);
240   }
241   public FileTextTemplate(FileTextTemplate to_copy, Appendable debugDest_ifNonNull)  {
242      super(to_copy, debugDest_ifNonNull);
243   }
244   public FileTextTemplate fillBody(String fully_processed)  {
245      fillBodyGap(fully_processed);
246      return  this;
247   }
248   /**
249      <p>Duplicate this template.</p>
250
251    * @return  <code>(new {@link #FileTextTemplate(FileTextTemplate, Appendable) FileTextTemplate}(this, debugDest_ifNonNull))</code>
252    */
253   public FileTextTemplate getObjectCopy(Appendable debugDest_ifNonNull)  {
254      return  (new FileTextTemplate(this, debugDest_ifNonNull));
255   }
256   public static final FileTextTemplate newFromPathAndUserExtraGaps(String path, String path_name, UserExtraGapGetter userExtra_getter)  {
257      return  (new FileTextTemplate(newTemplateFromPath(path, path_name), path, userExtra_getter));
258   }
259}
260class FilePathGap extends CodeletGap  {
261   public FilePathGap()  {
262      super("path");
263   }
264   public String getFillText(CodeletInstance instance)  {
265      return  TagletTextUtil.getFilePath(instance);
266   }
267}
268class FileBaseDirGap extends CodeletGap  {
269   public FileBaseDirGap()  {
270      super("base_dir");
271   }
272   public String getFillText(CodeletInstance ignored)  {
273      return  CodeletBaseConfig.getExampleSourceBaseDir();
274   }
275}
276class FileNameNoExtGap extends CodeletGap  {
277   public FileNameNoExtGap()  {
278      super("file_name_no_ext");
279   }
280   public String getFillText(CodeletInstance instance)  {
281      return  TagletTextUtil.getFileNameWithoutExtension(instance);
282   }
283}
284class FileNameWithExtGap extends CodeletGap  {
285   public FileNameWithExtGap()  {
286      super("file_name");
287   }
288   public String getFillText(CodeletInstance instance)  {
289      return  TagletTextUtil.getFileNameWithExtension(instance);
290   }
291}
292class RelPathAsUrlGap extends CodeletGap  {
293   public RelPathAsUrlGap()  {
294      super("rel_path_url");
295   }
296   public String getFillText(CodeletInstance instance)  {
297      return  TagletTextUtil.getExampleClassFQName(instance).replace(".", "/");
298   }
299}
300class RelativeDirGap extends CodeletGap  {
301   public RelativeDirGap()  {
302      super("file_name_dir");
303   }
304   public String getFillText(CodeletInstance instance)  {
305      return  TagletTextUtil.getExampleClassFQName(instance).replace(".", FILE_SEP);
306   }
307}
308class JavaDocFileUrlGap extends CodeletGap  {
309   public JavaDocFileUrlGap()  {
310      super("javadoc_path_url");
311   }
312   public String getFillText(CodeletInstance instance)  {
313      return  TagletTextUtil.getJavaDocSourceUrl(instance);
314   }
315}
316class RelDirGap extends CodeletGap  {
317   public RelDirGap()  {
318      super("relative_dir");
319   }
320   public String getFillText(CodeletInstance instance)  {
321      return  TagletTextUtil.getFilePath(instance);
322   }
323}
324class RelDirAsUrlGap extends CodeletGap  {
325   public RelDirAsUrlGap()  {
326      super("relative_dir_as_url");
327   }
328   public String getFillText(CodeletInstance instance)  {
329      return  TagletTextUtil.getFilePath(instance).replace(".", "/");
330   }
331}