The assumption is that the DTD is valid.
We need to pull out 4 elements of data:
We can do this all with a well-structured regular expression, which is actually simpler than trying to fish out all the components ourselves....
| Modifier and Type | Field and Description |
|---|---|
| private static final String | metapattern
This is the meta-pattern. |
| private static final Pattern | pattern
The following Pattern is the final result after parsing/tokenizing/substituting the meta-pattern. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static final Pattern | Returns: The substituted patternThe map containing substitution tokens/patterns map, String The meta-pattern to do the substitutions on. input)This method substitutes the simple tokens in the meta-pattern with the declared values in the map. |
| private static String | Returns: the formatted input.the input DocType declaration as found in a StAX Reader. internal)Reformat an internal subset.... |
| private static final String | |
| private static final boolean | Returns: true if it is a space, tab, newline, or carriage-return.The char to check ch)return true if the input character is one of the types recognized in the DTD spec. |
| public static DocType | Returns: The input string as a DocType.the input DOCTYPE string to parse. Must be valid. input, final JDOMFactory The JDOM factory to use to build the JDOM DocType. factory)Parse out a DOCTYPE declaration as supplied by the standard StAX readers. |
| private static final HashMap | Returns: The populated map.This builds a substitution map containing the raw patterns for certain types of content we expect. |
| metapattern | back to summary |
|---|---|
| private static final String metapattern This is the meta-pattern.
Space (' ') was chosen for the token delimiter because it makes the meta-pattern easy to read. There are a couple of places in this expression where there are two ' ' together, and it is critical that it does not change because there will be missed token matches then. | |
| pattern | back to summary |
|---|---|
| private static final Pattern pattern The following Pattern is the final result after parsing/tokenizing/substituting the meta-pattern. | |
| DTDParser | back to summary |
|---|---|
| private DTDParser() Make instances 'impossible'. Everything is static. | |
| buildPattern | back to summary |
|---|---|
| private static final Pattern buildPattern(HashMap<String, String> map, String input) This method substitutes the simple tokens in the meta-pattern with the declared values in the map. | |
| formatInternal | back to summary |
|---|---|
| private static String formatInternal(String internal) Reformat an internal subset.... Each declaration starts on an indented newline. | |
| getGroup | back to summary |
|---|---|
| private static final String getGroup(final Matcher mat, final int... groups) Looks in any number of matched groups for a value. Returns the first set value. The assumption is that, depending on the pattern matches, the value could be in a few different locations. | |
| isWhite | back to summary |
|---|---|
| private static final boolean isWhite(char ch) return true if the input character is one of the types recognized in the DTD spec.
| |
| parse | back to summary |
|---|---|
| public static DocType parse(final String input, final JDOMFactory factory) throws JDOMException Parse out a DOCTYPE declaration as supplied by the standard StAX readers. Using 'XML' terminology, this method assumes that the input is both 'well-formed' and 'valid'. The assumptions that this class makes ensure that the 'right thing' is done for valid content, but invalid content may or may not fail with a JDOMException. The behaviour of this method with invalid input is 'undefined'.
| |
| populatePatterns | back to summary |
|---|---|
| private static final HashMap This builds a substitution map containing the raw patterns for certain types of content we expect. | |