g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML...

35
1 1 XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 2 Agenda Summary of Previous Session Extensible Stylesheet Language Transformation (XSL-T) Extensible Stylesheet Language Formatting Object (XSL-FO) XML and Document/Content Management Introduction to XML Application Servers Working with XSLT-T and XSL-FO Processors Assignment 4a+4b (due in two week)

Transcript of g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML...

Page 1: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

1

1

XML for Java Developers G22.3033-002

Session 7 - Main ThemeXML Information Rendering (Part I)

Dr. Jean-Claude Franchitti

New York UniversityComputer Science Department

Courant Institute of Mathematical Sciences

2

Agenda

Summary of Previous SessionExtensible Stylesheet Language Transformation (XSL-T)Extensible Stylesheet Language Formatting Object (XSL-FO)XML and Document/Content ManagementIntroduction to XML Application ServersWorking with XSLT-T and XSL-FO ProcessorsAssignment 4a+4b (due in two week)

Page 2: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

2

3

Summary of Previous SessionSummary of Previous SessionDocument Object Model (DOM)Advanced XML Parser Technology

JDOM: Java-Centric API for XMLJAXP: Java API for XML ProcessingParsers comparison

Latest W3C APIs and Standards for Processing XMLXML Infoset, DOM Level 3, Canonical XMLXML Signatures, XBase, XIncludeXML Schema Adjuncts

Java-Based XML Data Processing FrameworksAssignment #3

4

XML-Based Rendering DevelopmentXML Software Development Methodology

Language + Stepwise Process + ToolsRational Unified Process (RUP) vs. “XML Unified Process”

XML Application Development InfrastructureMetadata Management (e.g., XMI)XSLT, XPath XSL-FO APIs (JAXP, JAXB, JDOM, SAX, DOM)

XML Tools (e.g., XML Editors, Apache’s FOP, Antenna House’s XSL Formatter, HTML/CSS1/2/3, XHTML, XForms, WCAG

XML App. Components Involved in the Rendering Phase:Application(s) of XMLXML-based applications/services (markup language mediators)

MOM, POP, Other Services (e.g., persistence)

Application Infrastructure Frameworks

Page 3: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

3

5

Part I

Introduction to XSL

6

EXtensible Stylesheet (XSL) Language Family

Family of recommendations to define XML document transformation and presentation as “style sheets”Three parts:

A language for transforming XML documentsXSL Transformations (XSLT)

Expression language used by XSLT to access or refer to parts of an XML document

XML Path Language (XPath) (also used for XML Linking)A XML vocabulary for specifying formatting semantics

XSL Formatting Objects (XSL-FO)

See http://www.w3.org/Style/XSL for the XSLT 1.0, XPath 1.0, and XSL-FO 1.0 recommendations and working drafts of XSLT 2.0 and XPath 2.0

Page 4: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

4

7

How Does XSL Work?

An XSL style sheet is an XML documentXSLT elements in an XSL style sheet correspond to a series of XSL “transformation” rules (i.e., XML tree transformation and/or formatting rules)XSLT rules describe how particular XML tags are to be converted to “flow objects” as the document is readXPath (e.g., para[@type="warning"][5])

http://www.w3.org/2002/11/xquery-xpath-applets/xpathApplet.html

8

XSL Example

XML Document<scene>

<FX>General Road Building noises.</FX> <speech speaker="Prosser"> Come off it Mr Dent, you can't win you know. There's no point in lying down in the path of progress.

</speech> <speech speaker="Arthur"> I've gone off the idea of

progress. It's overrated </speech> </scene>

Page 5: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

5

9

XSL Example(continued)

Sample stylesheet<xsl:template match="FX">

<fo:block font-weight="bold"> <xsl:apply-templates/>

</fo:block> </xsl:template> <xsl:template match="speech[@speaker='Arthur']">

<fo:block background-color="blue"><xsl:value-of select="@speaker"/>: <xsl:apply-templates/>

</fo:block> </xsl:template>

10

XML Data Rendering Patterns

Manipulating and Rendering XML Structures Using Java

XSLTTransformSortOutput

XSLT + XSL-FOFormatOutput

Querying will be covered separately

Page 6: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

6

11

XSL Related TechnologiesDSSSL & DSSSL-OCSS 1, 2, 3 …

http://www.w3.org/Style/CSS/

XSLTXPath XSL-FOXSLT Processors

Stylus Studio XSL development environmentIBM XSL EditorSaxon and Xalan XSLT processors

XSL-FO ProcessorsAntenna Housefop

12

XSL ProcessingSee http://www.w3.org/Style/XSL/Processing Alternatives:

HTML + CSS -> PresentationXML + CSS -> PresentationXML + XSLT -> XSL-FO -> PresentationXML + XSLT -> XML/HTML + CSS -> Presentation

Client or Server Processing ?See Session 2 handout on IE5’s implementation of the XSL Spec.

ExamplesSee Session 2 Sub-Topic 1 Presentation: Beginning XMLSee Session 2 handouts on XSL Tree Transformation Language See Session 2 handout on Cascading StylesheetsSee Session 2 handout on Styling Documents Using XSL

Page 7: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

7

13

A Language for “Mapping XML” (LMX)

LMX is a sample textbook applicationXML and Java texbook (1st edition)

LMX can convert a document in one DTD into another DTD and vice versaLMX uses rules to describe bi-directional “MOM” conversions between two sets of documents

Rules have a “from-pattern” and a “to-pattern”b to respectively match the source document, and construct the target documentSome restrictions exist w.r.t. the LMX patterns in order to simplify the program as much as possible

LMX can also be used to convert a XML document to HTML (“POP” application)

14

How Does the LMX Processor Work?

LMX makes heavy use of the DOM 1.0 APILMX uses XML4J internally to:

Parse a rule fileParse a source documentGenerate a target document

See chapter 4.3 in the XML and Java textbook (1st Edition) for a detailed description of the LMX implementation

Page 8: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

8

15

LMX v.s. the eXtensible Stylesheet Language (XSL)

LMX and XSL both provide a syntax to encode “Style Sheets”Each XML document can be associated with a style sheet that describes how elements should be organized and formatted for presentationXSL style sheets provide custom appearances that give a web site a unified look and feel

16

Part II

Extensible Stylesheet Language Transformation(XSLT)

Page 9: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

9

17

XSLThttp://www.dpawson.co.uk/xsl/sect1/sect1.html

An XSLT stylesheet specifies the presentation of a class of XML documents

Describes how an instance of the class is transformed into an XML document that uses a formatting vocabulary (e.g., XHTML, XSL-FO)

XSLT TerminologySee http://www.dpawson.co.uk/xsl/xslvocab.htmlRef. card: http://www.mulberrytech.com/quickref/“@”: abbreviation for attribute“..”: abbreviation for parent::node()“*”: identifies all of the element children of the context node (@* means all attributes)“.”: abbreviation for self::node()

18

XSL TransformationsAssume root element of style sheet is <xsl>Each <xsl> element contains one or more rule elementsEach rule has a target and an actionTarget is a regular expression defining to which XML elements the rule appliesAction is the list of flow objects generated when the rule is applied:

Actions output a series of HTML tags in combination with the content of the elementActions may output XML tags obtained via transformation of original XML dataActions may output non-markup text, or run simple scripts or programsActions may use JavaScript to provide more complex, and dynamic behaviors

Page 10: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

10

19

XSL Transformations (continued)

Conceptual Representation of XSL Transformations:<xsl>

<rule><target-element type=“tagname”/>action

</rule><rule>

(…)</rule>

</xsl>

20

XSLT and Templates

XSLT rules are also called “Templates”There may not be rules to match every elementElements can be reordered on the output.XSL style sheet must be well-formed

e.g., a HTML empty tag specified as <br> must be written as <br/> within a XSL style sheet action

XSLT elements used as a basis for a simple stylesheet are:

<xsl:stylesheet>, <xsl:template match …>, <xsl:apply-templates>, <xsl:for-each select ...>, and <xsl:sort select …>

Page 11: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

11

21

XSLT Elements and FunctionsCreating Elements and Attributes

xsl:element, xsl:attributeIteration and Sorting (e.g., xsl:sort)Conditional Processing

xsl:apply-templates select=“ … “, xsl:if, xsl:chooseCopying Nodes (e.g., xsl:copy)Combining Stylesheets

xsl:import, xsl:includeDefining Variables & Parameters (e.g., xsl:variable)Scripting with XPath functions

22

Parsers with XSLT Support

SAX 2.0 or DOM Level 2 1.0 Support RequiredApache’s Xalan XSLT parser

org.apache.xalan.processor/templates/transformerorg.apache.xpath

Saxon XSLT parserJAXP 1.2 (javax.xml.transform)

Transformation API for XML (TraX)Supported by Xalan 2.5.1, and Saxon 6.3

Sun’s XSLTC (donated to Apache and used in Xalan)Converts stylesheet’s to class files (“translets”)

Page 12: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

12

23

XSLT APIs

24

XSLT API PackagesSee Session 3 handout on “Processing XML Documents in Java Using XPath and XSLT”javax.xml.transform

Defines the TransformerFactory and Transformer classes, which you use to get a object capable of doing transformations. After creating a transformer object, you invoke its transform() method, providing it with an input (source) and output (result).

javax.xml.transform.domClasses to create input (source) and output (result) objects from a DOM.

javax.xml.transform.saxClasses to create input (source) from a SAX parser and output (result) objects from a SAX event handler.

javax.xml.transform.streamClasses to create input (source) and output (result) objects from an I/O stream.

Page 13: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

13

25

Using TraXhttp://www-106.ibm.com/developerworks/xml/library/x-tiptrax/

Create source, style, and result objects, and manipulate them using a “Transformer” objectTransformer can consume a stream of SAX events to avoid the use of intermediate files or other objects to hold dataSee complete example using TraX at:

http://www.informit.com/isapi/product_id~%7B29A138BF-A72D-4E3F-AA1C-596EAF7099BD%7D/content/index.asp

26

Part III

Extensible Stylesheet LanguageFormatting Object (XSL-FO)

Page 14: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

14

27

XSL Formatting Pipeline

XSL-FO is an intermediate form (partial media-dependent output)Java APIs: JAXP + FOP, jFO, XEP, etc.

http://www.xmlsoftware.com/xslfo.html

28

XSL FormattingXSL flow objects are markup textMarkup language output flow objects can be HTML, DSSSL, VRML, etc.Focus is usually on HTML output flow objects (simpler, more widely understood, better supported by current tools, and do not require an extra level of translation)CSS vs. XSL-FO

CSS is an external stylesheet language Styling properties are attached to selected elements in an XML or HTML document

XSL-FO completely describes a styled document (content organization, styling, layouts, layout-selection-rules, etc.)

Page 15: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

15

29

XSL Formatting CharacteristicsXSL formatting is simpler than DSSSL (Document Style Semantics and Specification Language, pronounced “dissal”, ISO std 10179:1996)XSL formatting is more powerful than CSS (Cascading Style Sheets)XSL-FO is not a “page-description” language, instead it allows the specification of layout rules (e.g., where page breaks occur)XSL’s basic formatting syntax is understandable by anybody acquainted with DSSSL or CSSXSL-FO design guidelines

XML SyntaxDeclarativeBuilt on CSSCross-mediaMultilingual support

30

Part IV

XML and Document/Content Management

Page 16: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

16

31

What is a XSL Processor?

A XML document and its associated style sheet are combined by an XSL processor to produce a HTML document

The XSL Processor applies the style sheet to the XML document and outputs static HTMLThe process can be automated with CGI scripts, Java servlets, or ActiveX controls to convert XML to HTML on the fly

A XSL processor is a standalone program or is part of a larger XML browser

32

How Does a XSL Processor Work?

The XSL processor consults the style sheet to find the rule that matches the elementThe XSL processor takes whatever action is associated to the rule:

outputs element’s content plus assorted markupperforms more complicated operations (sorting XML data before outputting it, running a Javascript program on the XML data, adding missing content to XML data, etc.)

Page 17: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

17

33

How Does a XSL Processor Work?(continued)

XSL processor formats each element upon receiptXSL processor may process elements recursivelyXSL processor receives input from XML processor and outputs formatted data based on the nature of the elements it receives

E.g., XSL processor receives <strong> elementXSL processor may output same content as bold textIf processor is an audio renderer, it may pump up the volume a notch...2

34

Mainstream XSL ProcessorsSee Microsoft’s XML and XSL Samples and Demos at http://msdn.microsoft.com/xmlSee IBM’s LotusXSL, Apache’s xalan, and fop. Look at Appendices of the class textbooks for relevant information on XSL A comprehensive list of XSL formatters, and XSLT engines/editors/utilities is available at http//www.xmlsoftware.com

e.g., TEI’s PassiveTex, AntennaHouse XSL Formatter, RenderX’s XEP, Arbortext’s E3, Advent’s XSL-FO Renderer, Adobe’s Document Server, IBM’s Infoprint, etc.Includes links to latest product pagesIncludes Version numbers, Licensing information, and Platform details

Page 18: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

18

35

DOM 1.0 XSL Processing Support

The DOM Level 1 specification does not support XSL stylesheetsMicrosoft’s initial version of MSXML DOM included a DOM Level 1 extension that added support for XSL stylesheets

The function transformNode(…) was used to apply an XSL stylesheet to an existing XML document

Similar extensions were emulated early on by other XSL processors (LotusXSL, xalan, fop, etc.)DOM Level 2 1.0 formalizes rendering support

36

Xalan

Xalan-J version 2.5.1 is the latestProvides XSL-T processing for transforming XML documents into HTML, text, or other XML document types Built on top of SAX 2.0, DOM Level 2 1.0, JAXP 1.1Implements the TraX subset of JAXP 1.2

Page 19: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

19

37

FOP

xml.apache.org/fop, www.jtauber.comPrint formatter driven by XSL-FO objectsFormatted output is in PDF format for nowCan be embedded in a Java application by instantiating org.apache.fop.apps.Driver

38

Part IV

XML Rendition Frameworksand

Application Servers

Page 20: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

20

39

Mainstream Frameworks

Cocoon 2XangBatik

40

Rendition Architectural Patterns

Thin-ClientXML + XSL transformation

Thick-Client(XML + XSL transformation) + applets/midlets(XML + XSL transformation) + XML-driven renderers

Page 21: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

21

41

Part V

Sample WAP/WML Platform

42

Introduction to WAP

• WAP is a standard for mobile Internet applications• Open standard for optimized access via a mobile device to

the Internet or Intranet• WAP advances have been slowed down by limitations of

mobile devices and mobile networks• Small screens• Limited device memory• Less powerful CPUs• Limited bandwidth availability• Unreliable connections• High latency

Page 22: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

22

43

WAP Innerworkings• Structure Content -> Rendition -> Presentation• Presentation Infrastructures:

• HTML over HTTP + HTML Browser• WML over WAP + WAP Browser

• WAP 1.x browser requires a WAP gateway• Gateway acts as intermediary between the mobile device

and the Internet• WAP features

• Security model similar to Web security• Simplistic development (WML and WMLScript)• Widely accepted• Standards independent

44

WAP Architecture

Page 23: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

23

45

WAP Architecture(continued)

46

WAP Programming Model

Page 24: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

24

47

WAP Protocol Stack

48

Introduction to WML

• WML is a markup language based on XML• WML was developed by the WAP Forum

• http://www.wapforum.org/• WML is well-formed XML that adheres to

predefined rules• Some WAP gateways can translate HTML to WML

Page 25: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

25

49

WML vs. HTML

• WML was designed for wireless terminals with target screens a few lines long and about an inch wide

• WML is case sensitive• All tags and attributes must be in lowercase

• WML is unforgiving of incorrectly nested tags• WML does not assume that a “QWERTY” keyboard

or a mouse is available for user input

50

WML Cards• Card specifies a single interaction between the user and the

user agent• Multiple cards are grouped in decks• Deck is the topmost element of a WML document• Example:

<?xml version="1.0"?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"><wml><card id="MyFirstCard" title="First Card"><p align="center">

My First WML Example</p>

</card></wml>

Page 26: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

26

51

More WML Cards<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"><wml><card id="city" title="Ottawa Guide"><p align="center"></p><p><a title="Business" href="#business">Business</a><br/><a title="Education" href="#education">Education</a><br/><a title="Entertainment" href="#entertainment">Entertainment</a><br/><a title="Restaurants" href="#food">Restaurants</a><br/><a title="Shopping" href="#shopping">Shopping</a><br/><a title="Travel" href="#travel">Travel</a><br/><a title="Weather" href="#weather">Weather</a><br/>

</p></card> (…)

52

More WML Cards(continued)

(…)<card id="food" title="Restaurants">

<p><img src="food.bwmp" alt="logo"/></p><p><a title="Canadian" href="#canadian">Canadian</a><br/>

<a title="Chinese" href="#chinese">Chinese</a><br/><a title="Continental" href="#continental">Continental</a><br/><a title="French" href="#french">French</a><br/><a title="German" href="#german">German</a><br/><a title="Greek" href="#greek">Greek</a><br/><a title="Italian" href="#italian">Italian</a><br/>

</p></card>

</wml>

Page 27: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

27

53

Using Ericsson WapIDE(continued)

54

Loading First Card

Page 28: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

28

55

WML Navigation

• WML Anchors<anchor>

Go to food<go href="#food"/>

</anchor>• HTML <A> tags

<a href="#food">Go to food</a>• WML alternative

<do type="accept" label="Go to food"><go href="#food"/>

</do>

56

Graphics in WML

• <img> tag• Empty tag

• Wireless bitmaps (.wbmp) are specially designed for wireless devices with a small monochrome screen• Use Paint Shop Pro to create .wbmp file via converter or

plugin

Page 29: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

29

57

WMLScript

• Based on ECMAScript (standard for JavaScript)• WMLScript is compiled into byte code before it is sent to

the client (due to minimum memory and narrowband communication requirements)

• Can be used to add script support to the client• E.g., user input validation, message and dialog generation,

user agent facilities access such as making phone calls, access the SIM cars, or configure the user agent once deployed

58

WMLScript

• Based on ECMAScript (standard for JavaScript)• WMLScript is compiled into byte code before it is sent to

the client (due to minimum memory and narrowband communication requirements)

• Can be used to add script support to the client• E.g., user input validation, message and dialog generation,

user agent facilities access such as making phone calls, access the SIM cars, or configure the user agent once deployed

Page 30: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

30

59

WAP and Java Servlets

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;

/*** This is a simple servlet that will run on a cell-phone. It displays the* current date and time. */public class MobileDate extends HttpServlet {

public void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// set content type for wireless dataresponse.setContentType("text/vnd.wap.wml");

// get the communication channel with the requesting clientPrintWriter out = response.getWriter();

// write the data(…)

60

WAP and Java Servlets(continued)

(…)out.println("<?xml version=\"1.0\"?>");out.println("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD

WML 1.1//EN\"");out.println(" \"http://www.wapforum.org/DTD/wml_1.1.xml\">");out.println("<wml>");out.println("<card title=\"MobileDate\">");out.println(" <p align=\"center\">");out.println("Date and Time Service<br/>");out.println("Date is: "+ new java.util.Date());out.println("</p>");out.println("</card>");out.println("</wml>");

}

}

Page 31: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

31

61

WAP and Java Server Pages

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"

"http://www.wapforum.org/DTD/wml_1.1.xml">

<%

response.setContentType("text/vnd.wap.wml");out.println("<wml>");out.println("<card title=\"MobileDate\">");out.println(" <p align=\"center\">");out.println("Date and Time Service<br/>");out.println("Date is: "+ new java.util.Date());out.println("</p>");out.println("</card>");out.println("</wml>");%>

62

WAP Required MIME Types

• WML source files• text/vnd.wap.wml for .wml files

• WML compiled files• application/vnd.wap.wmlc for .wmlc files

• WMLScript source files• text/vnd.wap.wmlscript for .wmls files

• WMLScript compiled files• application/vnd.wap.wmlscriptc for .wmlsc files

• Wireless bitmaps• image/vnd.wap.wbmp for .wbmp files

Page 32: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

32

63

WAP 2.0 Standards

• XHTML has been adopted as the basis for WAP 2.0• XHTML Basic is the mobile version of XHTML 1.0

• WAP Forum based XHTML Mobile Profile on XHTML Basic

• WAP CSS is the mobile version of cascading style sheets (CSS)

• WAP 2.0 does not require a gateway• XHTML goes through in text format instead of

being binary encoded

64

Part VI

Conclusions

Page 33: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

33

65

Summary

XSL style sheets describe how individual elements are displayed in HTMLA XSL processor like LotusXSL converts an XML document and its associated style sheet into an HTML document that can be read by current web browsersStyle instructions are stored in rule elements

66

Summary(continued)

Each rule has a pattern and an actionThe pattern define the elements to which the rule appliesThe action specifies the flow objects that the XSL processor outputs when the rule fires

When multiple rules apply to one element, only the most specific rule is appliedFlow objects usually include the content of the element, along with some combination of HTML markup

Page 34: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

34

67

ReadingsReadings

XML and Java: Chapters 7, 10, Appendices A and BProcessing XML with Java: Chapters 16-17, and Appendix CHandouts posted on the course web siteReview WCAG status on W3C web siteReview XSL (XSLT, and XSL-FO) W3C Recommendations

Project Frameworks Setup (ongoing)Apache’s Web Server, TomCat/JRun, and CocoonApache’s Xerces, Xalan, SaxonAntenna House XML Formatter, Apache’s FOP, X-smilesPublishing Systems at http://www.xmlsoftware.comVisibroker 4.5 (or BES 5.2), WebLogic 6.1-8.1, WAS 5.0POSE & KVM (See Session 3 handout)

68

Assignment

Assignment #4:This part of the project focuses on the application content model design/development using XML information rendering technology. The design/development process should adhere to the following steps: (a) Identifying rendering/transformation targets, (b) Defining the optimal rendering approach for each target, (c) Considering data rendering issues when designing an overall application data modelMore specific project related information, and extra credit assignments will be provided during the session

Page 35: g22 3033 002 c71 - nyu.edu · XML for Java Developers G22.3033-002 Session 7 - Main Theme XML Information Rendering (Part I) Dr. Jean-Claude Franchitti New York University Computer

35

69

Next Session:XML Information Rendering (Part II)

XML/XSL and JSP/JavaBeans Rendering TechnologyInternationalization IssuesWeb Content Accessibility Guidelines (WCAG)Web Services