57 */ |
57 */ |
58 public abstract class HtmlDocWriter extends HtmlWriter { |
58 public abstract class HtmlDocWriter extends HtmlWriter { |
59 |
59 |
60 public static final String CONTENT_TYPE = "text/html"; |
60 public static final String CONTENT_TYPE = "text/html"; |
61 |
61 |
62 DocPath pathToRoot; |
62 private final HtmlConfiguration configuration; |
|
63 private final DocPath pathToRoot; |
63 |
64 |
64 /** |
65 /** |
65 * Constructor. Initializes the destination file name through the super |
66 * Constructor. Initializes the destination file name through the super |
66 * class HtmlWriter. |
67 * class HtmlWriter. |
67 * |
68 * |
68 * @param configuration the configuration for this doclet |
69 * @param configuration the configuration for this doclet |
69 * @param filename String file name. |
70 * @param filename String file name. |
70 */ |
71 */ |
71 public HtmlDocWriter(BaseConfiguration configuration, DocPath filename) { |
72 public HtmlDocWriter(HtmlConfiguration configuration, DocPath filename) { |
72 super(configuration, filename); |
73 super(configuration, filename); |
|
74 this.configuration = configuration; |
73 this.pathToRoot = filename.parent().invert(); |
75 this.pathToRoot = filename.parent().invert(); |
74 Messages messages = configuration.getMessages(); |
76 Messages messages = configuration.getMessages(); |
75 messages.notice("doclet.Generating_0", |
77 messages.notice("doclet.Generating_0", |
76 DocFile.createFileForOutput(configuration, filename).getPath()); |
78 DocFile.createFileForOutput(configuration, filename).getPath()); |
77 } |
79 } |
78 |
80 |
79 /** |
81 /** |
80 * Accessor for configuration. |
82 * Accessor for configuration. |
81 * @return the configuration for this doclet |
83 * @return the configuration for this doclet |
82 */ |
84 */ |
83 public abstract BaseConfiguration configuration(); |
85 public BaseConfiguration configuration() { |
|
86 return configuration; |
|
87 } |
84 |
88 |
85 public Content getHyperLink(DocPath link, String label) { |
89 public Content getHyperLink(DocPath link, String label) { |
86 return getHyperLink(link, new StringContent(label), false, "", "", ""); |
90 return getHyperLink(link, new StringContent(label), false, "", "", ""); |
87 } |
91 } |
88 |
92 |
164 * |
168 * |
165 * @param name the name that needs to be converted to valid HTML name. |
169 * @param name the name that needs to be converted to valid HTML name. |
166 * @return a valid HTML name string. |
170 * @return a valid HTML name string. |
167 */ |
171 */ |
168 public String getName(String name) { |
172 public String getName(String name) { |
169 StringBuilder sb = new StringBuilder(); |
|
170 char ch; |
|
171 /* The HTML 4 spec at http://www.w3.org/TR/html4/types.html#h-6.2 mentions |
173 /* The HTML 4 spec at http://www.w3.org/TR/html4/types.html#h-6.2 mentions |
172 * that the name/id should begin with a letter followed by other valid characters. |
174 * that the name/id should begin with a letter followed by other valid characters. |
173 * The HTML 5 spec (draft) is more permissive on names/ids where the only restriction |
175 * The HTML 5 spec (draft) is more permissive on names/ids where the only restriction |
174 * is that it should be at least one character long and should not contain spaces. |
176 * is that it should be at least one character long and should not contain spaces. |
175 * The spec draft is @ http://www.w3.org/html/wg/drafts/html/master/dom.html#the-id-attribute. |
177 * The spec draft is @ http://www.w3.org/html/wg/drafts/html/master/dom.html#the-id-attribute. |
176 * |
178 * |
177 * For HTML 4, we need to check for non-characters at the beginning of the name and |
179 * For HTML 4, we need to check for non-characters at the beginning of the name and |
178 * substitute it accordingly, "_" and "$" can appear at the beginning of a member name. |
180 * substitute it accordingly, "_" and "$" can appear at the beginning of a member name. |
179 * The method substitutes "$" with "Z:Z:D" and will prefix "_" with "Z:Z". |
181 * The method substitutes "$" with "Z:Z:D" and will prefix "_" with "Z:Z". |
180 */ |
182 */ |
|
183 |
|
184 if (configuration.isOutputHtml5()) { |
|
185 return name.replaceAll(" +", ""); |
|
186 } |
|
187 |
|
188 StringBuilder sb = new StringBuilder(); |
181 for (int i = 0; i < name.length(); i++) { |
189 for (int i = 0; i < name.length(); i++) { |
182 ch = name.charAt(i); |
190 char ch = name.charAt(i); |
183 switch (ch) { |
191 switch (ch) { |
184 case '(': |
192 case '(': |
185 case ')': |
193 case ')': |
186 case '<': |
194 case '<': |
187 case '>': |
195 case '>': |