Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

can we use xkins without web contex

Help
Great
2004-11-03
2013-02-27
  • Great
    Great
    2004-11-03

    hello Guillermo
    thanks for the replying me ... for the previous question I have done all the Configuration what you  told me, but! Not working any way now I want to Use skins without web context for that I have written simple java Program

    /**********************test.java****************************/

    import ar.com.koalas.xkins.*;

    class test {

    public static void main (String _[])    {
    Xkins xks = null;
    try {
             xks = (new XkinsLoader()).loadSkins("/forms/maildef.xml");
            System.out.println("this is Xkins"+xks. printHTML());
            Skin skin=null;
            skin = xks.getSkin("base");
            XkinProcessor xkpBody =null;
            xkpBody = new XkinProcessor();
            Template tmpBody =null;
            tmpBody = skin.getTemplate("defaultSkin");
            xkpBody.setTemplate(tmpBody);
            xkpBody.addParameter("text", "This is a text");
            String Result= xkpBody.processContent();
            System.out.println("Result We Got "+Result);
            }catch(Exception e){
                                        System.out.println("Errer is due to..."+e.getMessage() );
        e.printStackTrace();
            }

        }
    }
    /**************************** maildef.xml************/
    <?xml version="1.0" encoding="UTF-8"?>
    <xkins>
        <global-processor id="velocity" type="ar.com.koalas.xkins.processor.VelocityTemplateProcessor"/>
        <skin name="base" url="/base" definition="/definition.xml"/>
        <skin name="mail" url="/mail" definition="/definition.xml" defaultSkin="true"/>   
    </xkins>

    /**************************** /mail/definition.xml ************/

    <?xml version="1.0" encoding="UTF-8"?>
    <xkins>
           <!-- SKIN default -->
           <skin name="mail" >
                 <processor type="ar.com.koalas.xkins.processor.VelocityTemplateProcessor"/>
                 <template name="mail">
                        <content><![CDATA[
    <table>
        <tr bgcolor="cyan">
            <td>This is a text</td>
        </tr>
    </table>   

                 ]]></content>
                 </template>
           </skin>
    </xkins>

    while compiling  its not giving Err
    I have put
    xkins-processors.jar
    xkins.jar
    commons-digester.jar;
    commons-beanutils.jar;
    commons-collections.jar;
    this many Jar in CLASSPATH
    while running its Throw errr
    xception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
           at ar.com.koalas.xkins.XkinsLogger.getLogger(Unknown Source)
           at ar.com.koalas.xkins.XkinsLogger.getLogger(Unknown Source)
           at ar.com.koalas.xkins.XkinsLoader.loadSkins(Unknown Source)
           at ar.com.koalas.xkins.XkinsLoader.loadSkins(Unknown Source)
           at test.main(test.java:8)
    I tried to put log4j.jar then its telling log4j Property is missing  we want to run this this without WEB contex. ?  Give me  your Suggestion
    Regards
    Nilesh

     
    • Nilesh:
      As you are using VelicityTemplateProcessor, you will also need the following jars:
      velocity-1.4.jar
      log4j-1.2.8.jar
      junit.jar
      asm.jar

      These jars are in the Xkins distribution in the xkins-0.9.9.war (subdirectory WEB-INF/lib)

      Its ok to use Xkins in a no web environment.

      You could also use xkins like this:
      In this example, using JByte and having a template in other place. Here we do not use xkins-definition.xml file nor definition.xml file:

      //creates the template on the fly
      Template tmp = new Template(strTemplateContent, JByteTemplateProcessor.class);       

      //creates the XkinProcessor with the template
      XkinProcessor xkp = new XkinProcessor(tmp);           
      //adds the parameters
      xkp.addParameter("paramName", "valueX");

      //processes the content
      System.out.println(xkp.processContent());

      Here, strContent is a String containing the template to be processed. in this example we use JByte, but you could use Velocity or create your own template processor.

      Regards.
      Guillermo.