<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p style=&quot;font-weight:bold&quot;&gt;
&lt;p&gt;Commands are tokens defined in template layout files that describe what to do with a specific region of the layout.&lt;/p&gt;
&lt;/p&gt;
&lt;p&gt;The following commands are built in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;include(&amp;#8216;key&amp;#8217;) &amp;#8211; where key name refers to a &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; property that refers to an &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; fragement that is included. The sub portions of a page may be static &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; files, &lt;span class=&quot;caps&quot;&gt;JSP&lt;/span&gt; files, or references on another server that are loading using a &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; client.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
   {&lt;br /&gt;
      &amp;#8220;id&amp;#8221; : &amp;#8220;blueprints-css&amp;#8221;,&lt;br /&gt;
      &amp;#8220;template&amp;#8221; : &amp;#8220;templates/bp-2-column-base.html&amp;#8221;,&lt;br /&gt;
      &amp;#8220;properties&amp;#8221; : {&lt;br /&gt;
          &amp;#8220;header&amp;#8221; : { &amp;#8220;type&amp;#8221; : &amp;#8220;include&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;/header.html&amp;#8221; },&lt;br /&gt;
          &amp;#8220;sidebar&amp;#8221; : { &amp;#8220;type&amp;#8221; : &amp;#8220;include&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;/sidebar.html&amp;#8221; },&lt;br /&gt;
          &amp;#8220;footer&amp;#8221; : { &amp;#8220;type&amp;#8221; : &amp;#8220;include&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;/footer.html&amp;#8221; } &lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
A base template is much like an abstract class in Java. In the example about you can create a base template for all your pages and then create children that provide the differences.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
    {&lt;br /&gt;
       &amp;#8220;id&amp;#8221; : &amp;#8220;main&amp;#8221;,&lt;br /&gt;
       &amp;#8220;extends&amp;#8221; : &amp;#8220;blueprints-css&amp;#8221;,&lt;br /&gt;
       &amp;#8220;properties&amp;#8221; : {&lt;br /&gt;
           &amp;#8220;title&amp;#8221; : {&amp;quot;type&amp;quot; : &amp;#8220;string&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;Welcome to Acme Templates&amp;#8221;},&lt;br /&gt;
           &amp;#8220;body&amp;#8221; : { &amp;#8220;type&amp;#8221; : &amp;#8220;include&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;/main.html&amp;#8221;}&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p style=&quot;font-weight:bold&quot;&gt;
&lt;p&gt;A template can extend any number of other templates using a comma separated list. Template properties in the base template override ancestor properties. Properties in  closer descendants override those of older descendants.&lt;br /&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt; insert(&amp;#8216;key&amp;#8217;) &amp;#8211; where key refers to a &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; property that defines static text and may include references objects on the server. A good example of the insert command is for providing titles for different pages. An example of a reference to an object in the ServletContext follows:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;#8220;footer&amp;#8221; : {&amp;quot;type&amp;quot; : &amp;#8220;string&amp;#8221;, &amp;#8220;value&amp;#8221; : &amp;#8220;${context.serverName}&amp;#8221;},&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The format for expressions is : ${scope.property) or ${scope.bean.property}&lt;br /&gt;
&lt;br /&gt;
scopes are : &lt;br /&gt;
 &lt;ul&gt;&lt;br /&gt;
 &lt;li&gt;session &amp;#8211; HttpSession&lt;br /&gt;
 &lt;li&gt; request &amp;#8211; HttpServletRequest, &lt;br /&gt;
 &lt;li&gt;context &amp;#8211; ServletContext&lt;br /&gt;
 &lt;li&gt;none &amp;#8211; Protorabbit Context &amp;#8211; This context is analogous to the HttpServletRequest but is not tied to the javax.servlet &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;. &lt;/ul&gt;
&lt;p&gt;Protorabbit will first look for an object following the scope. All sub objects should have public getter methods.&lt;/p&gt;
&lt;p&gt;For example if you have a cart object in your HttpSession scope with Java object like: &lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
public class Cart {&lt;br /&gt;
   &amp;#8230;&lt;br /&gt;
   public double getTotal() {&lt;br /&gt;
       &amp;#8230;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;you can reference the property using:&lt;/p&gt;
&lt;pre&gt;
${session.cart.total}
&lt;/pre&gt;
&lt;p&gt;All properties are evaluated to Strings so you will need to make sure to take care of any formatting internally.&lt;/p&gt;
&lt;/ul&gt;
&lt;p&gt;Custom commands may be provided by implementing a simple interface and placing the class in the classpath.&lt;/p&gt;
&lt;pre&gt;
package mycommand;

import java.io.IOException;

public class HelloCommand extends BaseCommand {
    @Override
    public void doProcess(OutputStream out) throws IOException {
        
        String message = &quot;hello &quot;;
        
        if (params.length &amp;gt; 0) {
            message += params[0].getValue();
        }
        out.write(message.getBytes());
    }
}
&lt;/pre&gt;
&lt;p&gt;To use the command include the package name + class name (excluding Command) in your layout file.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;
  &amp;lt;p&amp;gt;            
    &amp;lt;^ mycommand.Hello(&quot;Proto Rabbit&quot;) ^&amp;gt;
  &amp;lt;/p&amp;gt;
&lt;/pre&gt;</body>
  <created-at type="datetime">2009-11-25T20:15:37-08:00</created-at>
  <id type="integer">206211</id>
  <permalink>commands</permalink>
  <repository-id type="integer">160673</repository-id>
  <title>Commands</title>
  <updated-at type="datetime">2009-06-03T15:29:11-07:00</updated-at>
  <user-id type="integer">31047</user-id>
</wiki>
