| It implements ASN.1 codification tools for
javax.swing.text.html.parser.ContentModel . Given a
ContentModel , its values are codified in ASN.1 according to
the following rule:
HTMLContentModel ::= SEQUENCE OF SEQUENCE {
Type INTEGER,
Index INTEGER
}
The structure used to store the ContentModel is a sort of
binary tree that imitate the internal structure of a
ContentModel .
As you may know, a ContentModel can be represented by a binary
tree where each node denotes one of the following possible values:
- A binary relation between its children.
- A unary relation applied only to its left child.
- An element.
- A null value.
So, depending on each of those possible values, a different node is created
to summarize that information. We will denote each node as a pair of (type,
index). Therefore, according to the representation of a ContentModel,we have
the following conversions:
CASE 1: A binary relation between its children
B
/ => [B,-1]
C1
\
C2
\
...
\
Cn
CASE 2: A unary relation applied inly to its left child
U
/ => [U,-1]
C1
CASE 3: An element
ELEM => [-2, ELEM.getIndex()]
CASE 4: A null value
NULL => [-1,-1]
For example, lets take the ContentModel 's tree for the HEAD
Element. The ContentModel is defined as:
TITLE & ISINDEX? & BASE?
And the ContentModel tree for this case is then:
&
|
+-----------------+-----------------+
| |
0 NULL
+---------+---------+
| |
TITLE ?
+---------+---------+
| |
0 ?
+----+----+ +----+----+
| | | |
ISINDEX NULL 0 NULL
+-----+-----+
| |
BASE NULL
Then, this representation translated into our tree representation looks like:
['&',-1]
|
+-----------------+-----------------+
| |
[0,-1] [-1,-1]
+---------+---------+
| |
[-2,TITLE] ['?',-1]
+---------+---------+
| |
[0,-1] ['?',-1]
+----+----+ +----+----+
| | | |
[-2,ISINDEX][-1,-1] [0,-1] [-1,-1]
+-----+-----+
| |
[-2,BASE] [-1,-1]
So then, this simpler tree can be stored as a sequence of pairs (type,index),
and reconstructing it again is straightforward if both, the storage and
recovery of information, are made is BSF mode.
Then, this tree will be represented by the sequence:
['&',-1] , [0,-1], [-1,-1], [-2,TITLE], ['?',-1], [0,-1], ['?',-1],
[-2,ISINDEX], [-1,-1], [0,-1], [-1,-1], [-2,BASE], [-1,-1]
And the relation among nodes can be restored if we consider that if the
sequence is numerated from 0, we maintain the number of processed
relation nodes (rn) and we read the stored nodes in order, for any
relational node, its sons are stored ad positions 2*rn+1 and 2*rn+2.
The class can be used to obtain a byte array representing the codification of
a ContentModel , as well as a ContentModel from
a byte array (previously obtained codifying a ContentModel ).
In fact, it serves as a wrapper for the codification and the
ContentModel itself.
|