220 likes | 371 Views
Sue Spielman President/Consulting Engineer www.switchbacksoftware.com sspielman@switchbacksoftware.com. XSP Session. Session Overview. XSP Overview XSP vs. JSP Technologies Involved Object Model Implementation Details Samples Questions. XSP – What Is It?. eXtensible Server Pages
E N D
Sue Spielman President/Consulting Engineer www.switchbacksoftware.com sspielman@switchbacksoftware.com XSP Session XSP SessionO’Reilly Enterprise Java Conference
Session Overview • XSP Overview • XSP vs. JSP • Technologies Involved • Object Model • Implementation Details • Samples • Questions XSP SessionO’Reilly Enterprise Java Conference
XSP – What Is It? • eXtensible Server Pages • Component of Cocoon used for building web apps with dynamic XML content • Dynamic content is based on • Request Parameters • Databases • Remote Server Processes XSP SessionO’Reilly Enterprise Java Conference
XSP – Purpose • Created to allow web authors to generate dynamic content without forcing them to learn a programming language • Promotes a clean division of labor: • Application Developers • Content authors • Presentation designers XSP SessionO’Reilly Enterprise Java Conference
XSP vs. JSP Similarities • Follows the compiled server pages model • Can be parsed and validated by regular XML parsers • Can be transformed by XSLT processors • Aim to programming language abstraction XSP SessionO’Reilly Enterprise Java Conference
XSP vs. JSP Differences • Output Exposure • XSP doesn’t have access to the output stream • JSP has access to output stream • Page Readability • XSP uses the XML features to allows code to be easily distinguishable between markup elements • JSP needs to enclose programming code by scriptlet tags XSP SessionO’Reilly Enterprise Java Conference
X* Technologies Involved • XSP – eXtensible Server Pages • XML – eXtensible Markup Language • Portable Data • XSL - Stylesheet language for XML • Includes an XML vocabulary for specifying formatting • XSLT – XSL Transformations • Language for transforming XML documents into other XML documents. XSP SessionO’Reilly Enterprise Java Conference
Object Model • Processors – take a DOM tree as input and produce another DOM tree as output (i.e. XSP engine in Cocoon) • Producers – what XSP pages are compiled into (Cocoon Java type). • Similar to the fact that JSPs are compiled into Servlets XSP SessionO’Reilly Enterprise Java Conference
Object Model Model from xml.apache.org XSP SessionO’Reilly Enterprise Java Conference
Built-in Objects Should look familiar to JSP programmers… XSP SessionO’Reilly Enterprise Java Conference
XSPUtil Class • DOM utility methods • cloneNode, toMarkup • HTTP • encodeMarkup, formEncode, formDecode • File • pathComponent, fileComponent, baseName, normalizeBaseName, relativeFileName • String • split, isAlphaNumeric XSP SessionO’Reilly Enterprise Java Conference
What is an XSP Page • An XSP page is an XML page with the following requirements: • A Cocoon processing instruction that invokes the XSP processor <?cocoon processtype="xsp"?> • Document root element must be <xsp:page> • Any language and Taglib declarations as attributes in the <xsp:page> tag .Example: <xsp:page language="java“ xmlns:xsp="http://www.apache.org/1999/XSP/Core"> • An <xsp:logic> element and an <xsp:exp> element. XSP SessionO’Reilly Enterprise Java Conference
Sample Minimal XSP <?xml version="1.0"?> <?cocoon-process type="xsp"?> <?cocoon-process type="xslt"?> <?xml-stylesheet href="page-html.xsl" type="text/xsl"?> <xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core"> <xsp:logic> static private int counter = 0; private synchronized int count() { return counter++; } </xsp:logic> <page> <p>This page has been requested <xsp:expr>count()</xsp:expr> times.</p> </page> </xsp:page> XSP SessionO’Reilly Enterprise Java Conference
Processing Instruction • XML PIs used to forward the document to the right processor or formatter. • <?cocoon-process type="xxx"?> for processing • <?cocoon-format type="yyy"?> for formatting • Examples: • <?cocoon-process type="xsp"?> • <?cocoon-process type="xslt"?><?xml-stylesheet href="sample.xsl” type="text/xsl"?> XSP SessionO’Reilly Enterprise Java Conference
Logic Tags • <xsp:logic> encloses developer-supplied program logic. Transcribed verbatim into the generated Cocoon producer • <xsp:expr> evaluates a program expression and substitutes its value as a Text DOM node in the resulting document XSP SessionO’Reilly Enterprise Java Conference
Tagset XSP SessionO’Reilly Enterprise Java Conference
Scripting Languages • XSP designed to support scripting languages other than Java • In theory, any programming language that has a Java-based interpreter could be used to script XSP • Right now, only Java XSP SessionO’Reilly Enterprise Java Conference
Sample - Embedded Logic sample.xml sample.xsl Well formed XSP page Stylesheet sample.html HTML XSP XSP SessionO’Reilly Enterprise Java Conference
Sample - Included Logicsheet sample-xsp.xsl LogicSheet sample.xsl Stylesheet sample.html HTML sample.xml XML XSP Transformed XML XSP SessionO’Reilly Enterprise Java Conference
Sample - Taglib Logicsheet Cocoon properties taglib.xsl Properties File LogicSheet sample.xsl Stylesheet sample.html HTML sample.xml XSP That Includes A Reference To A Taglib XSP Transformed XML XSP SessionO’Reilly Enterprise Java Conference
Additional Resources • xml.apache.org • xml.apache.org/cocoon/wd-xsp.html • www.w3.org/TR/xslt • www.w3.org/TR/REC-xml XSP SessionO’Reilly Enterprise Java Conference
Questions <xsp:logic> ? ? ? </xsp:logic> XSP SessionO’Reilly Enterprise Java Conference