| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GenerateDTD |
|
| 0.0;0 |
| 1 | package no.sesat.mojo.modes; | |
| 2 | ||
| 3 | import java.util.Iterator; | |
| 4 | import java.util.List; | |
| 5 | import java.util.Set; | |
| 6 | import java.util.TreeSet; | |
| 7 | ||
| 8 | /** | |
| 9 | * Generator for DTD. | |
| 10 | * | |
| 11 | */ | |
| 12 | public class GenerateDTD extends GenerateSchemaFile { | |
| 13 | 0 | private final Set<String> written = new TreeSet<String>(); |
| 14 | ||
| 15 | /** | |
| 16 | * @param element | |
| 17 | * Root element. | |
| 18 | * @param name | |
| 19 | * File name. | |
| 20 | * @param idString | |
| 21 | * id. | |
| 22 | */ | |
| 23 | public GenerateDTD(final ConfigElement element, final String name, final String idString) { | |
| 24 | 0 | super(element, name, idString); |
| 25 | 0 | } |
| 26 | ||
| 27 | /** | |
| 28 | * Generate DTD. | |
| 29 | */ | |
| 30 | @Override | |
| 31 | public void runImpl() { | |
| 32 | 0 | println("<?xml version='1.0' encoding='UTF-8'?>\n"); |
| 33 | 0 | println("<!-- " + id + " -->"); |
| 34 | 0 | generate(root); |
| 35 | 0 | } |
| 36 | ||
| 37 | private void generate(final ConfigElement element) { | |
| 38 | 0 | if (written.add(element.name)) { |
| 39 | ||
| 40 | 0 | if (element.hasDoc()) { |
| 41 | 0 | println("<!-- " + element.doc + " -->"); |
| 42 | } | |
| 43 | ||
| 44 | 0 | print("<!ELEMENT " + element.name); |
| 45 | 0 | if (element.children.isEmpty()) { |
| 46 | 0 | print(" EMPTY"); |
| 47 | } else { | |
| 48 | 0 | print(" ("); |
| 49 | 0 | for (int i = 0; i < element.children.size(); i++) { |
| 50 | 0 | if (i > 0) { |
| 51 | 0 | print("|"); |
| 52 | } | |
| 53 | 0 | print(element.children.get(i).name); |
| 54 | } | |
| 55 | 0 | print(")*"); |
| 56 | } | |
| 57 | 0 | println(">"); |
| 58 | ||
| 59 | 0 | generate(element.attributes); |
| 60 | 0 | printlnI("<!ATTLIST " + element.name + " "); |
| 61 | 0 | for (final Iterator<ConfigAttribute> iterator = element.attributes.iterator(); iterator.hasNext();) { |
| 62 | 0 | final ConfigAttribute attrib = iterator.next(); |
| 63 | 0 | print(attrib.name + " "); |
| 64 | 0 | generate(attrib); |
| 65 | 0 | } |
| 66 | 0 | printlnU(">"); |
| 67 | ||
| 68 | 0 | for (ConfigElement child : element.children) { |
| 69 | 0 | if (!written.contains(child.name)) { |
| 70 | 0 | generate(child); |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | 0 | } |
| 75 | ||
| 76 | private void generate(final ConfigAttribute attrib) { | |
| 77 | 0 | println(attrib.type + " " + (attrib.required ? "#REQUIRED" : "#IMPLIED")); |
| 78 | 0 | } |
| 79 | ||
| 80 | private void generate(final List<ConfigAttribute> attributes) { | |
| 81 | 0 | println("<!--"); |
| 82 | 0 | for (final Iterator<ConfigAttribute> iterator = attributes.iterator(); iterator.hasNext();) { |
| 83 | 0 | final ConfigAttribute attrib = iterator.next(); |
| 84 | 0 | print(" @attr " + attrib.name); |
| 85 | 0 | if (attrib.hasDoc()) { |
| 86 | 0 | print(" " + attrib.doc); |
| 87 | } | |
| 88 | 0 | println(""); |
| 89 | 0 | } |
| 90 | 0 | println("-->"); |
| 91 | 0 | } |
| 92 | } |