Monday, November 17, 2014

How to replace HTML tag with ant

To replace a word or character with Ant,
we can use the following command.

<replaceregexp file="{FILE_TO_REPLACE}"
    match="{WORD_TO_REPLACE}"
    replace="{WORD}" flags="g" byline="true" />

But the above command can use to replace words withouth xml/html reserved characters only.
To replace words with xml/html reserved characters,

Steps:
1. encode the xml/html reserved words before putting into the the <replaceregexp /> command.
eg, <a>link</link>  =>  &lt;a&gt;link&lt;/a&gt;

2. put the encoded words into <replaceregexp />
eg,

<replaceregexp file="{FILE_TO_REPLACE}"
    match="&lt;a&gt;link&lt;/a&gt;"
    replace="&lt;a&gt;new_link&lt;/a&gt;" flags="g" byline="true" />


Done!!

Saturday, November 8, 2014

Scheduling with EJB

There is an easier way to schedule a job with EJB.
What we need is the EJB implementation and most important is the action method to be run.

@Stateless(name="serviceLookupName", mappedName="serviceLookupName")
public MyEjbServiceImpl {

    @Override
    @Schedule(dayOfMonth = "*", hour = "00", minute = "01")
    public void myScheduledMethod() {
       
        // action to run

    }
}


The advantage of this EJB schedule is easy to implement,
as just need to add the @Schedule annotation to an EJB method.

But the disadvantage is the scheduled time is hard to change,
if user wishes to change the time for the scheduler to run,
the source code need to be changed, recompile, and deploy.

for more information about the scheduler, please refer the official page.


Done!!

Thursday, November 6, 2014

reading java.util.List in velocity template

Assuming a list pass to the Velocity context.


List list = new ArrayList();
list.add("item1");
list.add("item2");
list.add("item3");

VelocityContext context = new VelocityContext();
context.put("list", list);


To get the list value,
below is the syntax in Velocity template

$list.get(0)

$list.get(1)

$list.get(2)


Done!!

Wednesday, November 5, 2014

How to convert sql date to util date


private String convertSqlDateToUtilDate(java.sql.Timestamp sqlDate) {

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

Calendar utilDate = Calendar.getInstance();

utilDate.setTimeInMillis(sqlDate.getTime());

return sdf.format(utilDate.getTime());

}

LinkWithin

Related Posts Plugin for WordPress, Blogger...