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> Codelet: {@code {@.file.textlet}}: Template: <U>Gap names</U></H2> 031 032 <P>The only required gap is "{@link com.github.aliteralmind.codelet.type.OnlyOneBodyGapTemplateBase#BODY_GAP_NAME body}", 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 "default" optional gaps:</P> 035 036 <A NAME="gaps"></A><P><A HREF="SourceCodeTemplate.html"><IMG SRC="{@docRoot}/resources/up_arrow.gif"/></A> <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> <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}(".", "/")</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}(".", {@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}(".", "/")</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}