December 6, 2013

Javascript: String has no method 'trim'

The trim method returns the string stripped of whitespace from both ends.
If the trim function it's not natively available, the following code will create it:
if (!String.prototype.trim) {
 String.prototype.trim = function () {
     return this.replace(/^\s+|\s+$/gm, '');

With jquery it's very easy:

November 22, 2013

xstream: com.thoughtworks.xstream.converters.reflection.ObjectAccessException

If you get any com.thoughtworks.xstream.converters.reflection.ObjectAccessException from your java programs, it may be due to : an upgraded of java version to 7.
As mentioned in xstream site
  • Java 7 is detected and supported since xstream 1.4
Solution: Upgrade your xstream to 1.4

With maven: 

March 10, 2013

mongoDB, scala, play...

I was asked to develop a web application with a large number of concurrent accesses and a big database. I am a Java developer but I thought to scala for the following reasons:

Database: mongoDB
MongoDB is an open source, document oriented database designed for ease of development and scaling. It allows multiple clients to read and write a single corpus of data using a locking system to ensurethat all clients receive a consistent view of the data and to prevent multiple applications from modifying the exact same pieces of data at the same time.

Driver: ReactiveMongo
ReactiveMongo is a scala driver that provides fully non-blocking and asynchronous I/O operations. It is designed to avoid any kind of blocking request. Every operation returns immediately, freeing the running thread and resuming execution when it is over.

Presentation: play framework
Play is the high velocity web framework for java and scala. It is based on a lightweight, stateless, web-friendly architecture.

of course, I can use Spring scala for business layer.

January 29, 2013

JAXB: use namespaces

I want to use jaxb to generate a xsl file from xsd file.
The xsd file contains, in addition to the default namespace (DEFAULT_NAMESPACE), another namespace (MY_NAMESPACE) which is not used in xsd but it will be used in the xsl.
The generator does not copy MY_NAMESPACE, so the xsl file is no longer valid.

One proposed solution is to use NamespacePrefixMapper

final Marshaller marshaller = JAXBContext.newInstance(MyObjectFactory.class)
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  new NamespacePrefixMapper() {
      public String[] getPreDeclaredNamespaceUris() {
        return new String[] { MY_NAMESPACE };
      public String getPreferredPrefix(final String namespaceUri,
        final String suggestion, final boolean requirePrefix) {
        if (namespaceUri.equals(MY_NAMESPACE)) {
           return MY_NAMESPACE_PREFIX;
        return suggestion;

Xsd example:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="" 
  <xs:element name="stylesheet" type="tns:Stylesheet"></xs:element>
     <xs:complexType name="Stylesheet">
    <xs:attribute name="name" type="xs:string"></xs:attribute>
    <xs:attribute name="select" type="xs:string"></xs:attribute>
  </xs:complexType> </xs:schema>

when I use jaxb to generate xsl, I do not get the namespace xmlns:s="". Which is util for xsl.
So the usefulness of this article