thymeleaf 0.1.0-beta.1

A framework-neutral Thymeleaf-compatible dynamic template engine for Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
//! 内嵌 Thymeleaf 官方版本化 DTD 文件集,构建 MemoryResolver。
//!
//! 文件来源:Thymeleaf 2.1.6.RELEASE jar 内 `org/thymeleaf/dtd/`(Java 实现
//! 唯一官方捆绑的版本化 DTD 约束集),以 `include_str!` 逐字节内嵌。
//! 覆盖三组注册:
//! 1. Thymeleaf 命名空间 16 个 SYSTEM ID(4 族 × 4 个历史版本,
//!    与 `StandardTranslationDocTypeProcessor` 翻译表一一对应)——
//!    自包含单体 DTD(方言标签内联,无外部引用)
//! 2. transitional 族历史拼写别名(文件头自引用 `transitonal`,
//!    Thymeleaf 2 时代模板可能照抄进 DOCTYPE)
//! 3. W3C 命名空间 4 个标准 URL + 全部裸文件名(.mod/.ent)——
//!    `standard/` 下亦为自包含单体副本
//!
//! 零网络访问,零文件系统依赖。

#[cfg(feature = "dtd-validation")]
use oxixml_dtd::MemoryResolver;

/// DTD 文件内嵌:`dtd-files/thymeleaf-2.1.6/org/thymeleaf/dtd/` 相对路径。
#[cfg(feature = "dtd-validation")]
macro_rules! dtd_entry {
    ($path:literal) => {
        include_str!(concat!(
            "../../../dtd-files/thymeleaf-2.1.6/org/thymeleaf/dtd/",
            $path
        ))
    };
}

/// 构建包含全部内嵌 DTD 的 MemoryResolver(SYSTEM key 精确匹配)。
///
/// # 返回
/// 覆盖 Thymeleaf 16 + 拼写别名 4 + W3C 4 + 裸模块文件名 42 的 resolver。
///
/// 对应 Java 语义:Thymeleaf 2.1.6 以 classpath 资源
/// `org/thymeleaf/dtd/{thymeleaf,standard}/` 提供同一文件集离线解析;
/// Rust 侧以 `include_str!` 内嵌等价内容,零运行时 IO。
#[cfg(feature = "dtd-validation")]
pub fn build_xhtml_resolver() -> MemoryResolver {
    let mut resolver = MemoryResolver::new();
    // Thymeleaf 命名空间:4 族 × 4 版本(与 StandardTranslationDocTypeProcessor 对应)
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-1.dtd",
        dtd_entry!("thymeleaf/xhtml1-strict-thymeleaf-1.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-2.dtd",
        dtd_entry!("thymeleaf/xhtml1-strict-thymeleaf-2.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-3.dtd",
        dtd_entry!("thymeleaf/xhtml1-strict-thymeleaf-3.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd",
        dtd_entry!("thymeleaf/xhtml1-strict-thymeleaf-4.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitional-thymeleaf-1.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-1.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitional-thymeleaf-2.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-2.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitional-thymeleaf-3.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-3.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitional-thymeleaf-4.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-4.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-frameset-thymeleaf-1.dtd",
        dtd_entry!("thymeleaf/xhtml1-frameset-thymeleaf-1.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-frameset-thymeleaf-2.dtd",
        dtd_entry!("thymeleaf/xhtml1-frameset-thymeleaf-2.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-frameset-thymeleaf-3.dtd",
        dtd_entry!("thymeleaf/xhtml1-frameset-thymeleaf-3.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-frameset-thymeleaf-4.dtd",
        dtd_entry!("thymeleaf/xhtml1-frameset-thymeleaf-4.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml11-thymeleaf-1.dtd",
        dtd_entry!("thymeleaf/xhtml11-thymeleaf-1.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml11-thymeleaf-2.dtd",
        dtd_entry!("thymeleaf/xhtml11-thymeleaf-2.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml11-thymeleaf-3.dtd",
        dtd_entry!("thymeleaf/xhtml11-thymeleaf-3.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml11-thymeleaf-4.dtd",
        dtd_entry!("thymeleaf/xhtml11-thymeleaf-4.dtd"),
    );
    // transitional 族历史拼写别名(`transitonal`,文件头自引用拼写)
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitonal-thymeleaf-1.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-1.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitonal-thymeleaf-2.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-2.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitonal-thymeleaf-3.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-3.dtd"),
    );
    resolver.insert(
        "http://www.thymeleaf.org/dtd/xhtml1-transitonal-thymeleaf-4.dtd",
        dtd_entry!("thymeleaf/xhtml1-transitional-thymeleaf-4.dtd"),
    );
    // W3C 命名空间:标准 SYSTEM URL → standard/ 自包含单体副本
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
        dtd_entry!("standard/xhtml1-strict.dtd"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
        dtd_entry!("standard/xhtml1-transitional.dtd"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd",
        dtd_entry!("standard/xhtml1-frameset.dtd"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd",
        dtd_entry!("standard/xhtml11.dtd"),
    );
    // xhtml11 命名空间:模型模块 URL(xhtml11-thymeleaf-1/2/3 引用)
    resolver.insert(
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11-model-1.mod",
        dtd_entry!("standard/xhtml11-model-1.mod"),
    );
    // 字符实体 URL → 本地 .ent:thymeleaf 族单体以 W3C URL 引用字符实体集
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent",
        dtd_entry!("standard/xhtml-lat1.ent"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent",
        dtd_entry!("standard/xhtml-symbol.ent"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent",
        dtd_entry!("standard/xhtml-special.ent"),
    );
    // 模块 URL → 本地模块:xhtml11.dtd 等模块化 DTD 以绝对 URL 引用模块,
    // jar 已捆绑同名本地副本,注册映射实现完全离线解析。
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod",
        dtd_entry!("standard/xhtml-attribs-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod",
        dtd_entry!("standard/xhtml-base-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod",
        dtd_entry!("standard/xhtml-bdo-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod",
        dtd_entry!("standard/xhtml-blkphras-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod",
        dtd_entry!("standard/xhtml-blkpres-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod",
        dtd_entry!("standard/xhtml-blkstruct-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod",
        dtd_entry!("standard/xhtml-charent-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod",
        dtd_entry!("standard/xhtml-csismap-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod",
        dtd_entry!("standard/xhtml-datatypes-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod",
        dtd_entry!("standard/xhtml-edit-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod",
        dtd_entry!("standard/xhtml-events-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod",
        dtd_entry!("standard/xhtml-form-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod",
        dtd_entry!("standard/xhtml-framework-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod",
        dtd_entry!("standard/xhtml-hypertext-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod",
        dtd_entry!("standard/xhtml-image-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod",
        dtd_entry!("standard/xhtml-inlphras-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod",
        dtd_entry!("standard/xhtml-inlpres-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod",
        dtd_entry!("standard/xhtml-inlstruct-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod",
        dtd_entry!("standard/xhtml-inlstyle-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod",
        dtd_entry!("standard/xhtml-link-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod",
        dtd_entry!("standard/xhtml-list-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod",
        dtd_entry!("standard/xhtml-meta-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod",
        dtd_entry!("standard/xhtml-object-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod",
        dtd_entry!("standard/xhtml-param-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod",
        dtd_entry!("standard/xhtml-pres-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod",
        dtd_entry!("standard/xhtml-qname-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-ruby-1.mod",
        dtd_entry!("standard/xhtml-ruby-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod",
        dtd_entry!("standard/xhtml-script-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod",
        dtd_entry!("standard/xhtml-ssismap-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod",
        dtd_entry!("standard/xhtml-struct-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod",
        dtd_entry!("standard/xhtml-style-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod",
        dtd_entry!("standard/xhtml-table-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod",
        dtd_entry!("standard/xhtml-text-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod",
        dtd_entry!("standard/xhtml11-model-1.mod"),
    );
    resolver.insert(
        "http://www.w3.org/TR/ruby/xhtml-ruby-1.mod",
        dtd_entry!("standard/xhtml-ruby-1.mod"),
    );
    // 裸文件名(模块化 DTD 的相对引用):standard/ 全集
    resolver.insert(
        "xhtml-attribs-1.mod",
        dtd_entry!("standard/xhtml-attribs-1.mod"),
    );
    resolver.insert("xhtml-base-1.mod", dtd_entry!("standard/xhtml-base-1.mod"));
    resolver.insert("xhtml-bdo-1.mod", dtd_entry!("standard/xhtml-bdo-1.mod"));
    resolver.insert(
        "xhtml-blkphras-1.mod",
        dtd_entry!("standard/xhtml-blkphras-1.mod"),
    );
    resolver.insert(
        "xhtml-blkpres-1.mod",
        dtd_entry!("standard/xhtml-blkpres-1.mod"),
    );
    resolver.insert(
        "xhtml-blkstruct-1.mod",
        dtd_entry!("standard/xhtml-blkstruct-1.mod"),
    );
    resolver.insert(
        "xhtml-charent-1.mod",
        dtd_entry!("standard/xhtml-charent-1.mod"),
    );
    resolver.insert(
        "xhtml-csismap-1.mod",
        dtd_entry!("standard/xhtml-csismap-1.mod"),
    );
    resolver.insert(
        "xhtml-datatypes-1.mod",
        dtd_entry!("standard/xhtml-datatypes-1.mod"),
    );
    resolver.insert("xhtml-edit-1.mod", dtd_entry!("standard/xhtml-edit-1.mod"));
    resolver.insert(
        "xhtml-events-1.mod",
        dtd_entry!("standard/xhtml-events-1.mod"),
    );
    resolver.insert("xhtml-form-1.mod", dtd_entry!("standard/xhtml-form-1.mod"));
    resolver.insert(
        "xhtml-framework-1.mod",
        dtd_entry!("standard/xhtml-framework-1.mod"),
    );
    resolver.insert(
        "xhtml-hypertext-1.mod",
        dtd_entry!("standard/xhtml-hypertext-1.mod"),
    );
    resolver.insert(
        "xhtml-image-1.mod",
        dtd_entry!("standard/xhtml-image-1.mod"),
    );
    resolver.insert(
        "xhtml-inlphras-1.mod",
        dtd_entry!("standard/xhtml-inlphras-1.mod"),
    );
    resolver.insert(
        "xhtml-inlpres-1.mod",
        dtd_entry!("standard/xhtml-inlpres-1.mod"),
    );
    resolver.insert(
        "xhtml-inlstruct-1.mod",
        dtd_entry!("standard/xhtml-inlstruct-1.mod"),
    );
    resolver.insert(
        "xhtml-inlstyle-1.mod",
        dtd_entry!("standard/xhtml-inlstyle-1.mod"),
    );
    resolver.insert("xhtml-lat1.ent", dtd_entry!("standard/xhtml-lat1.ent"));
    resolver.insert("xhtml-link-1.mod", dtd_entry!("standard/xhtml-link-1.mod"));
    resolver.insert("xhtml-list-1.mod", dtd_entry!("standard/xhtml-list-1.mod"));
    resolver.insert("xhtml-meta-1.mod", dtd_entry!("standard/xhtml-meta-1.mod"));
    resolver.insert(
        "xhtml-object-1.mod",
        dtd_entry!("standard/xhtml-object-1.mod"),
    );
    resolver.insert(
        "xhtml-param-1.mod",
        dtd_entry!("standard/xhtml-param-1.mod"),
    );
    resolver.insert("xhtml-pres-1.mod", dtd_entry!("standard/xhtml-pres-1.mod"));
    resolver.insert(
        "xhtml-qname-1.mod",
        dtd_entry!("standard/xhtml-qname-1.mod"),
    );
    resolver.insert("xhtml-ruby-1.mod", dtd_entry!("standard/xhtml-ruby-1.mod"));
    resolver.insert(
        "xhtml-script-1.mod",
        dtd_entry!("standard/xhtml-script-1.mod"),
    );
    resolver.insert(
        "xhtml-special.ent",
        dtd_entry!("standard/xhtml-special.ent"),
    );
    resolver.insert(
        "xhtml-ssismap-1.mod",
        dtd_entry!("standard/xhtml-ssismap-1.mod"),
    );
    resolver.insert(
        "xhtml-struct-1.mod",
        dtd_entry!("standard/xhtml-struct-1.mod"),
    );
    resolver.insert(
        "xhtml-style-1.mod",
        dtd_entry!("standard/xhtml-style-1.mod"),
    );
    resolver.insert("xhtml-symbol.ent", dtd_entry!("standard/xhtml-symbol.ent"));
    resolver.insert(
        "xhtml-table-1.mod",
        dtd_entry!("standard/xhtml-table-1.mod"),
    );
    resolver.insert("xhtml-text-1.mod", dtd_entry!("standard/xhtml-text-1.mod"));
    resolver.insert(
        "xhtml1-frameset.dtd",
        dtd_entry!("standard/xhtml1-frameset.dtd"),
    );
    resolver.insert(
        "xhtml1-strict.dtd",
        dtd_entry!("standard/xhtml1-strict.dtd"),
    );
    resolver.insert(
        "xhtml1-transitional.dtd",
        dtd_entry!("standard/xhtml1-transitional.dtd"),
    );
    resolver.insert(
        "xhtml11-model-1.mod",
        dtd_entry!("standard/xhtml11-model-1.mod"),
    );
    resolver.insert("xhtml11.dtd", dtd_entry!("standard/xhtml11.dtd"));
    resolver.insert(
        "xhtml5-legacy-wildcard.dtd",
        dtd_entry!("standard/xhtml5-legacy-wildcard.dtd"),
    );
    resolver
}