Sunday, March 30, 2014

Instiantiating Spring Bean Manually

public PresentationTab()
{
ApplicationContextFactory application = ApplicationContextFactory.getInstance();
mailScheduler = (MailScheduler) application.getBean("mailScheduler");
}

NoSuchBeanDefinitionException

It is common to get similar error:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'photoUserTag' is defined

The solution is:
Verify that bean name matches with the bean definition. 

Browser URL encoding for &

Browser does not display urls with & character, to resolve this issue I wrote a method to convert & to its encoded value:

private String replaceSpecialChar(String originalImagePath)
{
int indexAmp = originalImagePath.indexOf("&");
if (indexAmp > -1)
 originalImagePath = originalImagePath.replaceAll("&""%26");
int indexSpace = originalImagePath.indexOf(" ");
if (indexSpace > -1)
 originalImagePath = originalImagePath.replaceAll(" ""%20");
return originalImagePath;
}

Google Keyword Search

How does google keywords search work?

- Google scans for similar search keyword i.e. football and how often it appears in site content. The more the merrier.
- Google uses mathematical calculations to find out site popularity. In other words, how often other websites have linked to your home website.
- Google calculates your site ranking.
- Google looks up your territory and retrieves results that are closer to your geographical location.

Tip about google search keywords:
- Basic keywords such as football instead of sport football
Below is a search results for football vs. sport football keyword. Notice how football keyword retrieves more results than sport football:






How to add Google Keyword Search meta tag

To add a google search keyword, you need to add below meta tag in your site HTML page:

<meta name="keywords"
content="blacktea, greentea, tea, tea pot, herbal tea" />

Axis: building using ant

 <target name="generateAuthenticationWSDL" depends="compile">
      <axis-java2wsdl 
        classname="com.hmco.morse.authentication.service.RemoteAuthenticationService" 
        namespace="urn:AuthenticationWS
        location="${soap.service}/AuthenticationWS" 
        output="${project.config.dir}/AuthenticationWS.wsdl">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
      </axis-java2wsdl>
    </target>

    <!-- Generate WSDL -->
    <target name="generateAuthenticationWrappedWSDL" depends="compile">
      <axis-java2wsdl 
        classname="com.hmco.morse.authentication.service.RemoteAuthenticationService" 
        namespace="urn:AuthenticationWS
        location="${soap.service}/AuthenticationWS" 
        output="${project.config.dir}/AuthenticationWS.wsdl"
        style="wrapped">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
      </axis-java2wsdl>
    </target>

    <!-- Generate Client And Move Descriptors -->
    <target name="generateAuthenticationClient">
      <axis-wsdl2java 
        url="${project.config.dir}/AuthenticationWS.wsdl" 
        output="${java2wsdl.output.dir}" 
        deployscope="request" 
        serverSide="yes"
      verbose="true" 
      helpergen="false">
      <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
    </axis-wsdl2java>
    <antcall target="moveAxisDescriptors"/>
    </target>

  <target name="moveAxisDescriptors">
    <echo message="moving: ${java2wsdl.output.dir}/com/hmco/morse/authentication/service/deploy.wsdd"/>
    <move file="${java2wsdl.output.dir}/com/hmco/morse/authentication/service/deploy.wsdd" todir="${project.deploy.dir}" failonerror="false"/>
    <echo message="moving: ${java2wsdl.output.dir}/com/hmco/morse/authentication/service/undeploy.wsdd"/>
    <move file="${java2wsdl.output.dir}/com/hmco/morse/authentication/service/undeploy.wsdd" todir="${project.deploy.dir}" failonerror="false"/>
  </target>

Ant: TAR and GZIP task

You can create an ant task called, tar task, to compress a directory instead of manually creating the tar in command line.

http://ant.apache.org/manual/CoreTasks/tar.html

Insert below text in your build.xml file for your project:
<tar destfile="${dist}/manual.tar" basedir="htdocs/manual"/>
<gzip destfile="${dist}/manual.tar.gz" src="${dist}/manual.tar"/>

JavaScript: ArrayList

Example of use


var list = new ArrayList();
list.add("c");
list.add("f");
list.add("a");
list.add("d");
list.add("e");
list.add("b");
list.remove("d");
alert('get()' + list.get());
alert('getSortedAsc()' + list.getSortedAsc());
alert('getSortedDesc()' + list.getSortedDesc());

The JavaScript implementation of (pseudo) ArrayList for MSIE and Mozilla:


function ArrayList() {
    var _array = [];

    this.add = add;
    this.get = get;
    this.remove = remove;
    this.size = size;
    this.toString = toString;
    this.getElementIndex = getElementIndex;
    this.getSortedAsc = getSortedAsc;
    this.getSortedDesc = getSortedDesc;
    this.isElementExists = isElementExists;
    this.hasAnyNotNullElement = hasAnyNotNullElement;

    function add(value){
    _array.push(value);
    }

    function remove(value){
    var toDelete = getElementIndex(value);
    delete _array[toDelete];
    }

    function size(){
    return _array.length;
    }

    function toString(){
    var t = '';
    for(var i = 0; i < size(); i++){
      t += _array[i];
      if(i < size() 1t += ', ';
    }
    return t;
    }

    function getElementIndex(value){
    for(var i = 0; i < size(); i++)
      if(_array[i== valuereturn i;
    return 'false';
    }

    function isElementExists(value){
    return (getElementIndex(value== 'false') false true;
    }

    function hasAnyNotNullElement(){
    for(var i = 0; i < size(); i++){
      if(_array[i!= '' && typeof(_array[i]) != 'undefined')
        return true;
    }
    return false;
    }

    function get(){
    var tmp = [];
    var j = 0;
    for(var i = 0; i < size(); i++){
      if(typeof(_array[i]) != 'undefined'){
        tmp[j= _array[i];
        j++;
      }
    }
    return tmp;
    }

    function getSortedAsc(){
    var tmp = [];
    tmp = get();
    return tmp.sort();
    }

    function getSortedDesc(){
    var tmp = [];
    tmp = get();
    tmp.sort();
    return tmp.reverse();
    }
}