Tuesday, 18 December 2012

Using non-standard font in Web UI

During Web UI development, IE gets on nerves. But few things can be fixed with work-around.

If you want to use non-standard fonts in your application, then following steps can help.

1) Download the font (otf or ttf file).

2) To make it work in browsers other than IE, put the following in your css file.


@font-face {
            font-family: 'Your Custom name of the font';
            src: url('fonts/.otf', format('opentype'));
}

body {
            font-family:'Your Custom name of the font';
}


OR

@font-face {
            font-family: 'Your Custom name of the font';
            src: url('fonts/.ttf', format('truetype'));
}

body {
            font-family:'Your Custom name of the font';
}


3) This won't work in IE because IE supports only 'eot' format. So you can convert the otf or ttf file to eot format using the converters. There are converters available online like http://www.font2web.com/

4) Now use multiple URLs to support it in multiple browsers.

For Example,

@font-face {
            font-family: 'Your Custom name of the font';
            src: url('fonts/.eot');
            src: local(''), url('fonts/.woff') format('woff'), url('fonts/.ttf') format('truetype'), url('fonts/.svg') format('svg');
}


Now, this can be used in IE. IE is more restrictive in terms of syntax, so do not forget to use the classification group of the font you are using.

For example,

body
{
            font-family:'Your Custom name of the font', Sans Serif;
}

Saturday, 16 June 2012

JMX with Spring



I was already impressed by Spring as it allows you to learn the complexities of enterprise world within few minutes. We don't have to bother about the application server's complexity of deployment. We don't have to frustrate ourselves with those non-understandable errors. While exploring it, I came across JMX integration using Spring. I had little idea what JMX can provide us, but hadn't dared  to create my own MBeans. And here, Spring gives one of the simplest ways to create your own MBean. Within 10 min, I could create my own MBean and also could observe it through JConsole. I wrote just a TestMbean class and the configuration XML as shown below. 

package com.test.spring.jmx;
public class TestMBean
{
    private int count;

    public TestMBean(final int count)
    {
        this.count = count;
    }

    public int getCount()
    {
        System.out.println(count);
        return count;
    }
}
 



And then tested the above with following test class - 
package com.test.spring.jmx;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* Unit test for simple App.
*/
public class AppTest
{

    final private static String SPRING_CONFIG_LOCATION = "applicationContext.xml";

    @Test
    public void test() throws Exception
    {

        new ClassPathXmlApplicationContext(SPRING_CONFIG_LOCATION);

        Thread.sleep(70000);
    }

}
  
 After this, I ran the JConsole for $JAVA_HOME/bin and could see the following -