www.enhydra.org
 

 
Editor's Note: This article features the Enhydra technology used and extended by Softcom's SMIL to build some state-of-the-art, highly dynamic websites, including
- HBO's the Sopranos
- HBO's Beggars and Choosers and
- Showtime's Resurrection Boulevard
Bill Thompson has been a long time Enhydra supporter, having led many a productive mail thread on the Enhydra mailing list.

 

Using XMLC with SMIL Documents

Bill Thompson, Softcom, Inc.

Synchronized Multimedia Integration Language (SMIL) is written as an XML application and has been a W3C Recommendation since June 15, 1998. SMIL can be used to author TV-like multimedia presentations such as training courses on the Web. It is an easy-to-learn HTML-like language and can be composed of streaming audio, streaming video, images, text, or any other media type. The most well know implementation is RealNetwork's Realplayer which enjoys wide distribution. Other implementations include Apple Quicktime4.1, and Microsoft Player Internet Explorer 5.5.

Like HTML, dynamic SMIL content generation is a frequent requirement for online services. This paper describes a technique using XMLC from Enhydra.org that enables programmatic access to SMIL files. Multiple SMIL presentations can then be created from a template SMIL file and associated data via a servlet for instance.

XMLC and SMIL

Enhydra XMLC is a Java-based compiler that converts documents written in the eXtensible Markup Language (XML) into Java classes that can faithfully recreate the document. The resulting Java classes implement the W3C Document Object Model (DOM) APIs and can be used to insert content into the document framework at run time.

Out of the box, XMLC can generate Java classes for HTML and XML documents.  In order to generate Java classes that implement the SMIL DOM interfaces we must supply implementations of the XMLCDomFactory interface and the SMIL DOM.  The XMLCDomFactory interface is responsible for creating the DocumentType and Document objects for the specific DOM implementation.  Using a SMILDomFactory and a partial SMIL DOM implementation based on the OpenXML HTMLDomFactory,  xmlc is invoked as follows:

xmlc -parser xerces -domfactory com.softcom.xmlc.SMILDomFactory \
-class TemplateSMIL Template.smi

xmlc converts Template.smi to TemplateSMIL.class, a class implementing the org.w3c.dom.smil.Document interface.

SMILElement Nodes are created as XMLC compiles a document. Each SMILElement Node provides  methods to get and set attributes. The SMILRootLayoutELement class for instance has methods getTitle(), setHeight(), getWidth(), and so on, providing easy access to modify the document.

Nodes can be retrieved by traversing the tree, or more efficiency by the getter methods which XMLC adds to the DOM class. When XMLC compiles a document it creates a getElementBy{ID} method for each element with an ID attribute. A root-layout tag like, <root-layout id="rootLayout" background-color="black" width="750" height="433"/>, would generated a getElementRootLayout() method that would return a SMILRegionElement.

Running xmlc on the following file Template.smi file,

<?xml version="1.0"?>
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 1.0//EN" "http://www.w3.org/TR/REC-smil/SMIL10.dtd"> 
<smil>
    <head>
        <layout>
            <root-layout background-color="black" width="276" height="138"/>
            <region id="videoRegion" left="0" top="0" width="176" height="138" fit="meet"/>
            <region id="imageRegion" left="176" top="0" width="100" height="138" fit="fill"/>
        </layout>
    </head>
    <body>
        <seq id="timeline">
            <img src="image.gif" region="imageRegion" fill="freeze" id="image"/>
            <video src="video.rm" region="videoRegion" fill="freeze" id="video"/>
        </seq>
    </body>
</smil>
creates TemplateSMIL.java which implements org.w3c.dom.smil.Document and has the following additional methods,
public org.w3c.dom.smil.SMILElement getElementTimeline();
public org.w3c.dom.smil.SMILRegionElement getElementVideoRegion();
public org.w3c.dom.smil.SMILRegionElement getElementImageRegion();
public org.w3c.dom.smil.SMILElement getElementVideo();
public org.w3c.dom.smil.SMILElement getElementImage();
Note that each SMIL element with an ID attribute has a getElement{ID} method created for it.

At this point we have a Java class that represents our template SMIL file. We also have methods to get specific Nodes of the document by ID. Once we have a Node we can call get/set methods to change attributes or add other Nodes. All that is left now it to write a manipulation class. This class will:

  • create an instance of the class representing the SMIL template document
  • manipulate the contents of the template class as needed
  • output the final document

public class TweakSMIL {  
public static
void main(String[] args) {
    ExampleSMIL exampleSMIL = new ExampleSMIL();
    SMILRegionElement imageRegion = exampleSMIL.getElementImageRegion();     imageRegion.setFit("meet");         System.out.println(exampleSMIL.toDocument());
                  }
}
 

Conclusion

Enhydra XMLC combined with a SMIL DOM implementation provides a convenient  mechanism to convert SMIL documents to Java classes. These Java classes then provide programmatic access to the SMIL document through a standard API from the W3C and can be manipulated through the DOM APIs.

The ability to generate customized content from a single template is very powerful. Once a template is chosen, content generation can be completely automated resulting in quick implementation and a reduction in errors from hand coded presentations.  The open source Enhydra XMLC tool combined with the open standards and APIs from the W3C provide an elegant solution to template driven SMIL file creation.

References

 

 

TOP OF PAGE

Lutris Technologies    Legal Notices    Privacy Policy