Neatware  Header

Introduction

Snaml is an XML generator. Snaml for Java is a Snaml application for Java platform. (Snaml means Snaky Markup Language. It represents an ancient snake. When Snaml's head is attacked, its tail will come to help; when its tail is attacked, its head will be back to help; when its body is attacked, both head and tail will defense.)

HyperText Markup Language (HTML) is a description language for web document. Berent. Lee innovated the HTML from SGML. Netscape first implemented a widely used HTML browser. Today HTML is a defacto standard for web document. The new Extensible Markup Language (XML) of W3 standard extended HTML to allow authors define new tags and attributes. XHTML 1.0 is an XML application for HTML 4.0. XHTML is designed to be the presentation standard for both web and mobile document. As description languages, XHTML and XML are very suitable to represent embedded documents. However, since these languages are lack of variables, it is difficult to use them as programming languages. Therefore, the XHTML document may be not well on modularity and reusability.

Java is an object-oriented programming language for web and wireless applications. J2EE and J2ME are Java's platforms for Enterprise and Mobile applications. Java servlet runs on the server side and connects to database. JSP is a popular solution to combine the HTML and Java. However, JSP solution is not consistance with the Java language. And JSP need to translate to Java servlet and recompile in the runtime, this makes performance down.

Snaml for Java integrates the XHTML and other XML standards into Java. Developers can use the Snaml package to generate XHTML pages dynamically. They can create a website in higher level consistence by using the Snaml library. In addition, Snaml for Java is much easier to connect to a database and present database content. Since Snaml for Java was implemented as servlets it was fast, maintainable, and reusable. Finally, Snaml for Java is suitable to the Presentation Logic on Web Applications.

XHTML class is a component in the Snaml for Java package. XHTML inheritants from Java's servlet class. A developer can extends the XHTML class and replace the page() method to generate a XHTML page dynamically. XHTML methods are cataloged as following types:

  • Block Method

    Block Method may specify a scope of a set of methods. Start method is the beginning of a block method. Snaml for Java specifies the satrt method name with the underscore prefix such as '_method( attribute );'. A start method may have zero or one argument called attributes. End method is the end of a block method. The method name has the underscore postfix such as 'method_();'. An end method has no argument. The methods between the start and end methods are called content.

    Attribute is a list of key/value pairs separated by whitespace. A pair has the format key='value' where key must be a character string (include letters, digits, hypen, period, and underscore). The value may be any of strings or variables. The single quote ' ' groups the value. A key that is not defined as an attribute of a start method will be ignored. A non-declared key will be assigned to its default value when a start method is invocated.

    Block methods may be nested. A difference between the block method and regular Java method is that the attributes of a block method may be inherited. The inner methods in the content of a block method may inherite the attributes of the outer block method. A method in the content is called a child of the outer block method. In contrast, the outer block method is a parent of the inner methods. Finally, the block methods should be properly paired. For example,

    _anchor( "title='Hello'" );
      _b();
        quote( "an example of block command" );
      b_();
    anchor_();
    
  • Empty Method

    Empty method is a special case of the block method where the content is empty. A special syntax with double underscore prefix such as '__method( attribute );' can represent empty method in short. It is convenient for a parser to check a program for empty method since there is no end method is expected. For example,

    This simple Snaml for Java program displays a picture with the title 'Hello Snaml'.

    import packages. neatware.snaml is the Snaml package.

    import java.io.*
    import javax.servlet.*
    import neatware.snaml.*
    

    HelloSnaml class extends from XHTML class in the Sanml package.

    public void class HelloSnaml extends XHTML
    {
    

    The page method is inherited from the XHTML method. The web page initialization has been done in the XHTML object.

      public void page() throws ServletException, IOException
      {
    

    uses xml 1.0 and UTF8 encoding. doctype uses XHTML strict DTD specification.

         __pi( "xml version='1.0' encoding='UTF-8'" );
         __doctype( "html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'"
           + " 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'" );
    

    xhtml header specifies xml namespace and language. quote writes a string on title.

         _html( "xmlns='http://www.w3.org/1999/xhtml '"
              + "xml:lang='en' lang='en'" );
         _head();
           _title();
             quote( "Hello Snaml" );
           title_();
         head_();
    

    In the xhtml body a web page displays a hello.gif picture and writes a string.

         _body();
           __img( "src='hello.gif' alt='hello'" );
           quote( "Hello Snaml for Java!" );
         body_();
         html_();
      }
    }