17. XMLC

Java Servlet Programming, 2nd Edition > 17. XMLC

 
< BACKCONTINUE >

Chapter 17. XMLC

XMLC uses XML technology to make HTML files into resources for Java. It was created by Lutris as part of their open source Enhydra Application Server and can be downloaded separately for use with any other servlet container.[1] Here we talk about XMLC 1.2b1, available for download at http://xmlc.enhydra.org. XMLC requires JDK 1.1 or later and any version of the Servlet API. It's released under the Enhydra Public License (EPL), an open source license similar to the Mozilla Public License (MPL). Basically, it requires changes to the existing code to be contributed back but allows private extensions, even commercial ones.

[1] Enhydra Lutris is the scientific name for a sea otter, a fitting corporate identity for a company based in Santa Cruz with sea otters swimming in the nearby Monterey Bay.

XMLC stands for XML Compiler. The tool takes a standard HTML or XML document and "compiles" it into a Java class. That class contains the Java instructions necessary to create an XML DOM (Document Object Model) tree representation of the document in memory. A programmer can manipulate the in-memory tree to add dynamic content and after manipulation can output the modified tree as HTML, XHTML, or any other XML.

In traditional use, a page designer creates one or more "mock-up" versions of the web page being developed. The mock-ups are pure HTML files. They are reviewed by interested parties, discussed, debated, and fine-tuned as necessary. The designer doesn't need to add any XMLC instructions into the file, only HTML 4.0-compliant ID attributes to the areas in the page to be replaced with dynamic content.

Offline, the XMLC tool compiles the mock-up page into a Java class containing the DOM tree representation of the document. The Java programmer makes use of the public API of this class to write a manipulation class that creates an instance of the tree, locates the sections of the document that need to be changed, and modifies each section as necessary. The sections to change are located using accessor methods added to the tree by XMLC for every ID attribute in the document. The HTML files become, essentially, resources for Java.

If the page should contain a list of items, the mock-up can include maybe five or ten items to make the page look realistic. The Java programmer can delete all but the first item, then construct the actual list by repeatedly cloning the first item thus matching the style of the mock-up but using data generated dynamically. It's even possible to tell the XMLC compiler to remove all but the first item automatically, improving performance at runtime.

XMLC achieves a high level of separation between content and presentation. HTML files are pure HTML, Java files are pure Java, and the files connect only through agreed-upon ID markers. As new mock-ups are created, they can be used directly with no retrofitting, and if a relied-upon tag is absent in the new mock-up, it triggers a compile error when the manipulation class tries to invoke the method to retrieve the ID that no longer exists.


Last updated on 3/20/2003
Java Servlet Programming, 2nd Edition, © 2001 O'Reilly

< BACKCONTINUE >


Java servlet programming
Java Servlet Programming (Java Series)
ISBN: 0596000405
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net