com.ibm.tivoli.imi.drivers.moc2007.util

Class TemplateLoader

  • java.lang.Object
    • com.ibm.tivoli.imi.drivers.moc2007.util.TemplateLoader


  • public final class TemplateLoader
    extends java.lang.Object
    This class loads a text file and replaces tokens defined inside it.

    Let's suppose the file /com/ibm/di/maximo/query.xml.template defines the following template:

     <?xml version='1.0' encoding='UTF-8'?>
     <Query<b>{mos.name}</b>
         xmlns="http://www.ibm.com/maximo"
         creationDateTime="<b>{creation.date.time}</b>"
         baseLanguage="EN"
         transLanguage="EN"
         messageID="<b>{message.id}</b>"
         maximoVersion="<b>{maximo.version}</b>"
         uniqueResult="false"
         maxItems="<b>{max.items}</b>"
         rsStart="<b>{rs.start}</b>">
       <<b>{mos.name}</b>Query>
         <<b>{root.mbo.name}</b>>
           <b>{criteria}</b>
         </<b>{root.mbo.name}</b>>
       </<b>{mos.name}</b>Query>
     </Query<b>{mos.name}</b>>
     

    The code bellow can be used to load and replace the tokens:

     TemplateLoader tl = new TemplateLoader("/com/ibm/di/maximo/query.xml.template");
     tl.setProperty("mos.name", "MXASSET");
     tl.setProperty("maximo.version", "MX_VERSION");
     tl.setProperty("creation.date.time", "2007-07-25T10:00:00-03:00");
     tl.setProperty("message.id", 123);
     tl.setProperty("max.items", "10");
     tl.setProperty("rs.start", "1");
     tl.setProperty("root.mbo.name", "ASSET");
     tl.setProperty("criteria", "<SOME CRITERIA />");
     
     System.out.println(tl.toString());
     

    The result should be something like:

     <QueryMXASSET
         xmlns="http://www.ibm.com/maximo"
         creationDateTime="2007-07-25T10:00:00-03:00"
         baseLanguage="EN"
         transLanguage="EN"
         messageID="123"
         maximoVersion="MX_VERSION"
         uniqueResult="false"
         maxItems="10"
         rsStart="1">
       <MXASSETQuery>
         <ASSET>
           <SOME CRITERIA />
         </ASSET>
       </MXASSETQuery>
     </QueryMXASSET>
     
    • Constructor Summary

      Constructors 
      Constructor and Description
      TemplateLoader(java.lang.String templateName)
      Constructs a TemplateLoader with the specified file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void setProperty(java.lang.String token, long value)
      Defines the value associated with the given token.
      void setProperty(java.lang.String token, java.lang.String value)
      Defines the value associated with the given token.
      java.lang.String toString()
      Returns the template content with all tokens replaced.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TemplateLoader

        public TemplateLoader(java.lang.String templateName)
        Constructs a TemplateLoader with the specified file.
        Parameters:
        templateName - name of the file that contains the template definition
    • Method Detail

      • setProperty

        public void setProperty(java.lang.String token,
                                long value)
        Defines the value associated with the given token.
        Parameters:
        token - token defined inside the template
        value - value to be associated with the given token
      • setProperty

        public void setProperty(java.lang.String token,
                                java.lang.String value)
        Defines the value associated with the given token.
        Parameters:
        token - token defined inside the template
        value - value to be associated with the given token
      • toString

        public java.lang.String toString()
        Returns the template content with all tokens replaced.
        Overrides:
        toString in class java.lang.Object
        Returns:
        template content with all tokens replaced