MAP | PageMixer Documents > Tutorial > Mixing with PageMixer > Inset data into sequence | << | >> |
This section explains
how to inset your data instead of part of HTML page
in PageMixer framework.
Explanation uses
the filter which insets user-name string
between "<span>
" and
corresponding "</span>
" in HTML page.
<span class="Auth-UserName"></span>
<span class="Auth-UserName">foozy</span>
Class diagram in this section is shown below:
Classes which you must define are colored, and other are already defined.
Object diagram in this section is shown below:
Sequence diagram in this section is shown below:
In this tutorial, abbreviated class names are used. Complete names are shown below.
Notation | Full name |
---|---|
ConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext |
HTMLSymbolSet | jp.ne.dti.lares.foozy.pagemixer.HTMLSymbolSet |
SequenceDataInsetFilter | jp.ne.dti.lares.foozy.pagemixer.mixer.SequenceDataInsetFilter |
SequenceWatcher | jp.ne.dti.lares.foozy.pagemixer.mixer.SequenceWatcher |
TokenDataInsetFilter | jp.ne.dti.lares.foozy.pagemixer.mixer.TokenDataInsetFilter |
TokenWatcher | jp.ne.dti.lares.foozy.pagemixer.mixer.TokenWatcher |
Notation | Full name |
---|---|
Bootstrap | pagemixer.filter.Bootstrap |
UsernameTextInsetFilter | pagemixer.filter.UsernameTextInsetFilter |
SequenceWatcher
As described above,
this section let the filter
inset user-name string
between "<span>
" and
corresponding "</span>
" in HTML page.
But, it is not good idea to inset it into all parts
between them in given HTML page.
Then, condition of target sub-sequence are:
span
"
class
" attribute, and
Auth-UserName
"
In this case,
"SequenceWatcher.NameAttr
" is used
as "SequenceWatcher
".
It is "Sequence Watcher watching at Name and Attribute of first token".
new SequenceWatcher.NameAttr(HTMLSymbolSet.SET.SPAN, HTMLSymbolSet.SET.CLASS, "Auth-UserName")
SequenceDataInsetFilter
PageMixer framework provides the utility classes
which provide the template to inset data instead of sub-sequence
found by SequenceWatcher
given on construction,
and these are SequenceDataInsetFilter
and its derived classes.
In the situation of this section,
you must inset data as "HTML-Safe" TextToken
, because:
and, "SequenceDataInsetFilter.HTMLSafeTextInside
"
is good for this purpose.
public class UsernameTextInsetFilter
extends SequenceDataInsetFilter.HTMLSafeTextInside
{
final static
private HTMLSymbolSet SET = HTMLSymbolSet.SET;
final static
private String ATTR_VALUE = "Auth-UserName";
////////////////////////////////////////
public UsernameTextInsetFilter(Object key){
super(new SequenceWatcher.NameAttr(SET.SPAN,
SET.CLASS,
ATTR_VALUE),
key);
}
/////////////////////////////////////////////
// Concretization of class HTMLSafeTextInside
protected String getText(Object data){
return (null != data ? data.toString() : "");
}
}
Differences between samples of "Inset data into token" and this section are:
TokenDataInsetFilter
or SequenceDataInsetFilter
TokenWatcher
or SequenceWatcher
Now, everything needed are ready to use. Execution code is as below (see UsernameTextInsetFilter for detail).
try{ // key to set/get user name final Object key = "Auth.Login"; // user name final String name = "foozy"; Bootstrap bootstrap = new Bootstrap.Default(filename) { protected void prepare(ConsumerContext context) { // put user name into context context.setValue(key, name); } }; // apply the filter bootstrap.execute(new UsernameTextInsetFilter(key)); } catch(Exception e){ e.printStackTrace(System.err); }
Sample HTML file as input is "auth.en.html
"
(or "index.en.html
")
under "src/demo/servlet/war/WEB-INF/page/demosite
"
in distribution.
MAP | PageMixer Documents > Tutorial > Mixing with PageMixer > Inset data into sequence | << | >> |