| java.lang.Object javax.swing.text.html.parser.ContentModel
ContentModel | final public class ContentModel implements Serializable(Code) | | Element s content representation. That's unary or binary expression.
Operands can be null (matched with null object), instance of
Element ,
instance of
ContentModel .
Valid operations can be unary operations (types):
- '+' - (e+) - e must occur one or more times;
- '*' - (e*) - e must occur zero or more times;
- '?' - (e?) - e must occur zero or one time;
- (0) - (e) - e must occur one time only
and binary operations (types):
- '|' - (e1|e2) means either e1 or e2 must occur, but not both;
- ',' - (e1,e2) means both A and B must occur, in that order;
- '&' - (e1 & e2) means both e1 and e2 must occur, in any order;
(Operation interpretation corresponds to HTML 4.01 Specification (3.3.3))
As content model is using for dtd presentation here is some ambiguity what
null object can be matched with. So null shouldn't be passed to constructor.
No recursion is allowed.
Content, next, type fields has the following limitation:
- if type is one from {'+', '*', '?'} content hasn't to be null and next
can be not null, if a binary operation is applyed to them;
- if type is one from {'|', ',', '&'} content hasn't to be null and next
must be null;
- content can be null, instance of Element or instance of ContentModel;
- type can be one from the following '*', '+', '?', '|', '&', ','.
The structure of a
ContentModel is represented by a relation through
its
ContentModel.content and
ContentModel.next fields. Using
these fields and the information stored in the
ContentModel.type field a
ContentModel can be represented as a binary tree.
From now on, in the examples that will follow, we will consider the left
branch and the one belonging to the
ContentModel.content field and
the right branch the
ContentModel.next field.
Depending on the
ContentModel.type of a
ContentModel , the
following cases may arise:
CASE 1: A binary relation over some
ContentModel s:
B
/ \
C1 NULL
/ \
C2
/ \
...
/ \
Cn
/ \
NULL
Where the binary operation B is applyed to all the
ContentModel s C1, C2, ..., Cn (that is a sequence of
ContentModel related by the
ContentModel.next field,
finishing in a null value). This means that this
ContentModel represents the content model:
(C1 B C2 B ... B Cn)
Here, obviously the B operator can be one of:
CASE 2: A unary relation applied to one
ContentModel
U
/ \
C1 NULL
Where the unary operator U is only applyed to the
ContentModel C1. This means that this
ContentModel represents
the content model:
C1 U
Here, obviously the U operator can be one of:
CASE 3: An element
ELEM
Where this is only an instance of a
Element class and obviosly
denotes a
Element of the
ContentModel . An important fact to
remark is that a
ContentModel may not be just an
Element , it
must be applyed to at least one unary operator, usually the 0 operator.
This means that if we want to represent the body
ContentModel , the
ContentModel will be denoted by:
0
+-----+-----+
| |
BODY NULL
CASE 4: A null value
NULL
The empty or null
ContentModel is denoted by this value. It is also
used to denote the end of a sequence of
ContentModel (as seen in the
CASE 1).
As an example, if we want to represent the content model denoted by the
expression:
((E1? , E2)* & E3)+
The
ContentModel will be denoted by:
'+'
+---------+---------+
| |
'&' NULL
+---------+---------+
| |
'*' NULL
+---------+---------+
| |
'|' '0'
+------+------+ +------+------+
| | | |
'?' NULL E4 NULL
+---------+---------+
| |
'0' '0'
+------+------+ +------+------+
| | | |
E1 NULL E2 '+'
+------+------+
| |
'0' NULL
+-----+-----+
| |
E3 NULL
|
Field Summary | |
public Object | content The content of the ContentModel. | public ContentModel | next The next ContentModel in the ContentModel structure. | final static long | serialVersionUID The serialization UID value. | public int | type The type of the content model. |
content | public Object content(Code) | | The content of the ContentModel.
|
serialVersionUID | final static long serialVersionUID(Code) | | The serialization UID value.
|
type | public int type(Code) | | The type of the content model. It should be '*', '+', '?', '|', '&', ','
or 0.
|
ContentModel | public ContentModel(Element content)(Code) | | That content model will be mathed with exactly one element. Type will be
0.
Element can be equals to null. In such case
ContentModel will be matched with an empty input stream.
|
empty | public boolean empty()(Code) | | Checks if the
ContentModel can match an empty expression.
true if and only if some of the conditions is true:- type equals to '*' or '?';
- type equals to '|' and one of the ContentModelsrelated by the binary operator can be empty.
- type equals to '&' or ',' and all the ContentModelsrelated by the binary operation can be empty.
If the type equals '+', then it returns true if theContentModel applied to this operator can be empty; If the type equals '0' then it returns false. |
first | public boolean first(Object token)(Code) | | Returns if a given token can occur as first elements in a
ContentModel Parameters: token - the element we are interested in determining whether it canoccur as the first element of a ContentModel- if type equals to 0, returns true if and only if token equals tocontent.
- if type is one from the unary types returns true if and only if oneof the following conditions is true:
- content is instance of Element, token is instance ofElement and token equals to content
- content is instance of ContentModel, token is instance ofElement and content.first(token) returns true;
- if type is one from binary types then:
- if content instance of Element and content equals to tokenreturns true;
- if content instance of ContentModel and content.first(token)equals to true, then returns true;
- if type equals to ',' returns true if and only if content isinstance of ContentModel and:
- for at least one of the ContentModel related by the ',',first(token) is true and,
- for all the ContentModels that preceded it, empty() istrue.
- if type equals to '| or '&', it returns true if and only if at leastone of ContentModels related by the '|' or '&' operatorsatisfies that first(token) is true.
|
getElements | public void getElements(Vector<Element> elemVec)(Code) | | Adds all elements of this contentModel to elemVec ignoring operations
between elements. For instance, for ((a+)| ((b*),(c?))) elements a,b,c
will be added to the elemVec. The argument elemVec should not be null.
If content is null, nothing will be added to elemVec.
Parameters: elemVec - the vector where the Elements of theContentModel will be added to. |
implication | List<Pair<Element, Boolean>> implication(Element e, List<Element> parsed, boolean many, int depth, LinkedList<Pair<Element, Boolean>> path)(Code) | | Determines the sequence of
Element needed to be implied to
insert an
Element .
Parameters: e - the Element found in the document are for which theimplication is needed. Parameters: parsed - the ArrayList of Elements found previosly tothe Element e. Parameters: many - a value specifyng whether the given Element may appearmore than once in the ContentModel Parameters: depth - the depth level been searched in the ContentModel Parameters: path - a possible path of implied Elements that may leed tothe Element e. - null, if an implication path to the element e could not be found.
- an empty List if the element may be insertedin the actual position, with no implication of other elements needed.
- a non empty List if some Elements need to be implied.In such case, the List is formed by a pair. The firstcomponent defines the Element needed to be implied. Thesecond component defines if the Element must be opened andclosed (if true) or just opened (false).
|
|
|