Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 3
// The RE Patterns
private static final RE titlePattern = new RE("<title.+(/>|</title>)",
RE.MATCH_CASEINDEPENDENT);
private static final RE inputLinePattern = new RE("(<!--.*)|((<input.+(/>|</input>))|
(<select[^>]+>)|(<textarea[^>]+>l))", RE.MATCH_CASEINDEPENDENT);
private static final RE hiddenPattern = new RE("type\\s*=\\s*\"hidden\"",
RE.MATCH_CASEINDEPENDENT);
private static final RE textPattern = new RE("type\\s*=\\s*\"text\"",
RE.MATCH_CASEINDEPENDENT);
private static final RE cbPattern = new RE("type\\s*=\\s*\"checkbox\"",
RE.MATCH_CASEINDEPENDENT);
private static final RE radioPattern = new RE("type\\s*=\\s*\"radio\"",
RE.MATCH_CASEINDEPENDENT);
private static final RE namePattern = new RE("name\\s*=\\s*\"[^\"]+\"",
RE.MATCH_CASEINDEPENDENT);
As you can see, all relevant HTML form tags are part of these patterns. The XslBeanGenerator (see Resources) scans XSL files for these tags and produces corresponding JavaBeans, where the parameter names are converted to bean member
variables. The XslParameterParser has two tasks: it first generates code to read the HTML form tag parameter values out of the servlet's request object and
then generates code to store these values in the corresponding JavaBean using its setter methods. Typically the generated
code looks like this:
import com.oreilly.servlet.ParameterParser;
// Generated statement: use O'Reilly ParameterParser
ParameterParser parser = new ParameterParser(request);
// Generated statement
String username = parser.getStringParameter("username", "");
// Generated statement: read the HTML input text value
UserDataModel model = new UserDataModel();
// This statement or similar must be inserted by the user
// It instantiates the generated JavaBean
model.setUsername(username);
// Generated statement: calling bean setter method
For a complete example of an XSL file and the generated code by both parsers, download the source code from Resources below.
This tip introduced two XSL file parsers that generate useful Java code when working with J2EE applications based on Java,
XML, XSL, and XSLT. Both generators, XslBeanGenerator and XslParameterParser, fill the gap between XSL files and Java code that relies on information provided mainly by these XSL files' HTML. One generator
produces a JavaBean that holds the user data described in XSL/HTML. The other generator produces a Java code statement to
read HTML request parameter values and stores these values in the corresponding bean.
Read more about Core Java in JavaWorld's Core Java section.
Archived Discussions (Read only)