p2006
05-13-2006, 07:39 PM
I had a dream since 1999 - a JSP page with Java and HTML, but without ... JSP. Did someone try "Hybrid Server Pages"? It is on downloads.com now. The modest thing has only four pages of description, so I'll paste it here (cut a bit) FYA.
My point is - does it really work?
Hybrid Server Pages
This proposal is a follow up to authors’ experience with JSP. We felt a clear need for a better than JSP language for dynamic web pages programming. Our aims were to:
get rid of redundant syntax;
provide more rigid syntax check;
hinder generation of wrong-HTML pages;
support code reuse;
keep everything simple.
The language was finally named “Hybrid Java” where “Hybrid” stands for “Hybrid with HTML”. The HJ grammar was received by a merge of slightly modified formal grammars of Java and HTML.
Compilation Units and files
HJ reads files “*.hsp” (Hybrid Server Page) and files “*.hsw” (Hybrid Server Widget) defining reusable HJ code fragments.
Using XML syntax
In general HJ code is presented as an XML document containing both Java code and HTML document content. It may use all possible tags - those that correspond to HTML tags present HTML elements. Other tags (except for few reserved) present widget calls and their slots calls. Each opening tag must be closed by an appropriate closing tag (<p> … </p>). Single tag HTML elements must be presented in XML style too (<br/>);
Hybrid code
Reserved word “Hybrid” met in the attribute list of an element means that the text between tags is Hybrid code (Java code mixed with more elements). Otherwise the text is interpreted as page content. The following HTML elements my not have content inside and thus are “Hybrid” by default: COLGROUP, DIR, DL, FRAMESET, MAP, MENU, OL, OPTGROUP, SELECT, TABLE, TBODY, TFOOT, THEAD, TR, UL.
Variables
Basically HJ variables are Java variables. In addition HJ variable may be defined as an attribute of a widget and may be used in following HJ contexts:
in widget call in position of attribute value;
in HTML element in opposition of attribute value;
in HTML page content.
In the first two cases variables are presented by plain identifiers (same as in plain Java). In the third case variable X is presented as “$X” or “$X;” (“in-text identifier”). The nature of a variable does not depend on the way it was created or used.
Semantics of variable usage in various positions is the following:
“Hybrid” (~Java) code – as in plain Java;
widget attribute value – as initial value of the widget attribute;
HTML element attribute value - the value becomes that of HTML attribute;
in page content (“$X”) - value of variable printed within the HTML page text.
Comments
HJ code may contain Java line comments (starting with “//”), Java multi-line comments (/* */) and HTML comments (<!-- -- >). The fires two are retained in the retained in the generated Java code. The latter makes it to the generated HTML page.
Escape Symbol
HJ has one and only escape symbol - dollar (“$”). Here is a full list of escapes:
“$<” is an escape sequence for start of a tag. Any “<” not preceded with “$” and followed by a letter is interpreted as a beginning of a tag.
“$//” and “$/*” are escapes sequences for comment starts;
“$$X” is an escape for “in-text identifier” (“$X”).
HTML attribute values
In HJ values of attributes of HTML elements may be strings in single quotes or in double quotes. Those string values may be generated dynamically using concatenation operator “+” that joins string values and Java variables current values into one quoted string.
int n = 101;
<P id=”pref_” + n >
This HJ code generates such a Java code that when it is executed it generates the following HTML:
<P id=”pref_101”>
Character entities
The following signs when met in the page content text are substituted to proper form by the implementation: < , > , “ and &.
Widgets
Widgets contain Hybrid code that may be reused in multiple pages. Widgets may have attributes and “slots”. A slot is a reserved position in the widget body code that may be filled with external HJ code. Widget definition looks like below:
<widget name=widget1 Hybrid>
<attr name=attr1 type=String default=”default”>
// More attribute definitions
// some HJ code – note Hybrid keyword above
<slot name=sn1>
<p> This is a “page content” which means
that one may see it in a browser </p>
</slot>
// some HJ code – note Hybrid keyword above
<slot name=sn2 Hybrid>
// some Default Hybrid code
</slot>
</widget>
Default value of an attribute is optional. The attribute type may be any Java type – literal or class (as String is). Default attribute type is “String”. Widget usage looks like below:
// some Hybrid code
int k = 77;
<widget1 attr1=”non-default”>
<sn1> // not Hybrid!
This is a Very Important Document! <br>
Read carefully!
</sn1>
</sn2 Hybrid>
// some Hybrid (Java) code
int m = 0;
k += 1; param1 = “\”non-default \”is bad as an example”;
</sn2>
</widget1>
Variable “k” is accessible from the insertion into slot “sn2”. Widget may have zero slots and/or zero attributes. You do not have to use every slot – default code located in the widget itself will be used. If a widget has only one slot it may be used as anonymous slot:
<widget name=widget2>
…
<slot/> // or <slot> some default </slot>
…
</widget2>
Usage:
… <widget2> … this is inserted into anonymous slot … </widget2> …
Implementation
A full-blown HJ implementation might provide full Java check and even produce byte-code (.class files). However it is sufficient (and that is about the current implementation) to stop at the point where the Java source code is generated, leaving most of the rest of the work to Java compiler. Thus the generated Java code may not compile depending on what y the user wrote in details.
For each “.hsp” file HJ compiler generates a “.java” class with the same name and the code “.hsp file” specifically translates into java code of method “void render()” in that class; when iniciated with “PrintOutput” and executed this method produces HTML page.
The code of widgets and the content of slots are compiled (maybe more than once) into the code of method “render” as well, wrapped into blocks. So that is an “open substitution” and that is what makes names from base class and the page itself seen everywhere.
HJ compiler has two command line options. Option –p defines the package of generated class. Option –b defines a common base class for the generated Java pages classes. Typically the base class may be some class derived from “Servlet”.
Conclusion
Authors strongly hope that Hybrid Java may be a good alternative to JSP. Please address you comments, requests and advice to HybridServerPages@yahoo.com.
My point is - does it really work?
Hybrid Server Pages
This proposal is a follow up to authors’ experience with JSP. We felt a clear need for a better than JSP language for dynamic web pages programming. Our aims were to:
get rid of redundant syntax;
provide more rigid syntax check;
hinder generation of wrong-HTML pages;
support code reuse;
keep everything simple.
The language was finally named “Hybrid Java” where “Hybrid” stands for “Hybrid with HTML”. The HJ grammar was received by a merge of slightly modified formal grammars of Java and HTML.
Compilation Units and files
HJ reads files “*.hsp” (Hybrid Server Page) and files “*.hsw” (Hybrid Server Widget) defining reusable HJ code fragments.
Using XML syntax
In general HJ code is presented as an XML document containing both Java code and HTML document content. It may use all possible tags - those that correspond to HTML tags present HTML elements. Other tags (except for few reserved) present widget calls and their slots calls. Each opening tag must be closed by an appropriate closing tag (<p> … </p>). Single tag HTML elements must be presented in XML style too (<br/>);
Hybrid code
Reserved word “Hybrid” met in the attribute list of an element means that the text between tags is Hybrid code (Java code mixed with more elements). Otherwise the text is interpreted as page content. The following HTML elements my not have content inside and thus are “Hybrid” by default: COLGROUP, DIR, DL, FRAMESET, MAP, MENU, OL, OPTGROUP, SELECT, TABLE, TBODY, TFOOT, THEAD, TR, UL.
Variables
Basically HJ variables are Java variables. In addition HJ variable may be defined as an attribute of a widget and may be used in following HJ contexts:
in widget call in position of attribute value;
in HTML element in opposition of attribute value;
in HTML page content.
In the first two cases variables are presented by plain identifiers (same as in plain Java). In the third case variable X is presented as “$X” or “$X;” (“in-text identifier”). The nature of a variable does not depend on the way it was created or used.
Semantics of variable usage in various positions is the following:
“Hybrid” (~Java) code – as in plain Java;
widget attribute value – as initial value of the widget attribute;
HTML element attribute value - the value becomes that of HTML attribute;
in page content (“$X”) - value of variable printed within the HTML page text.
Comments
HJ code may contain Java line comments (starting with “//”), Java multi-line comments (/* */) and HTML comments (<!-- -- >). The fires two are retained in the retained in the generated Java code. The latter makes it to the generated HTML page.
Escape Symbol
HJ has one and only escape symbol - dollar (“$”). Here is a full list of escapes:
“$<” is an escape sequence for start of a tag. Any “<” not preceded with “$” and followed by a letter is interpreted as a beginning of a tag.
“$//” and “$/*” are escapes sequences for comment starts;
“$$X” is an escape for “in-text identifier” (“$X”).
HTML attribute values
In HJ values of attributes of HTML elements may be strings in single quotes or in double quotes. Those string values may be generated dynamically using concatenation operator “+” that joins string values and Java variables current values into one quoted string.
int n = 101;
<P id=”pref_” + n >
This HJ code generates such a Java code that when it is executed it generates the following HTML:
<P id=”pref_101”>
Character entities
The following signs when met in the page content text are substituted to proper form by the implementation: < , > , “ and &.
Widgets
Widgets contain Hybrid code that may be reused in multiple pages. Widgets may have attributes and “slots”. A slot is a reserved position in the widget body code that may be filled with external HJ code. Widget definition looks like below:
<widget name=widget1 Hybrid>
<attr name=attr1 type=String default=”default”>
// More attribute definitions
// some HJ code – note Hybrid keyword above
<slot name=sn1>
<p> This is a “page content” which means
that one may see it in a browser </p>
</slot>
// some HJ code – note Hybrid keyword above
<slot name=sn2 Hybrid>
// some Default Hybrid code
</slot>
</widget>
Default value of an attribute is optional. The attribute type may be any Java type – literal or class (as String is). Default attribute type is “String”. Widget usage looks like below:
// some Hybrid code
int k = 77;
<widget1 attr1=”non-default”>
<sn1> // not Hybrid!
This is a Very Important Document! <br>
Read carefully!
</sn1>
</sn2 Hybrid>
// some Hybrid (Java) code
int m = 0;
k += 1; param1 = “\”non-default \”is bad as an example”;
</sn2>
</widget1>
Variable “k” is accessible from the insertion into slot “sn2”. Widget may have zero slots and/or zero attributes. You do not have to use every slot – default code located in the widget itself will be used. If a widget has only one slot it may be used as anonymous slot:
<widget name=widget2>
…
<slot/> // or <slot> some default </slot>
…
</widget2>
Usage:
… <widget2> … this is inserted into anonymous slot … </widget2> …
Implementation
A full-blown HJ implementation might provide full Java check and even produce byte-code (.class files). However it is sufficient (and that is about the current implementation) to stop at the point where the Java source code is generated, leaving most of the rest of the work to Java compiler. Thus the generated Java code may not compile depending on what y the user wrote in details.
For each “.hsp” file HJ compiler generates a “.java” class with the same name and the code “.hsp file” specifically translates into java code of method “void render()” in that class; when iniciated with “PrintOutput” and executed this method produces HTML page.
The code of widgets and the content of slots are compiled (maybe more than once) into the code of method “render” as well, wrapped into blocks. So that is an “open substitution” and that is what makes names from base class and the page itself seen everywhere.
HJ compiler has two command line options. Option –p defines the package of generated class. Option –b defines a common base class for the generated Java pages classes. Typically the base class may be some class derived from “Servlet”.
Conclusion
Authors strongly hope that Hybrid Java may be a good alternative to JSP. Please address you comments, requests and advice to HybridServerPages@yahoo.com.