Andrei Ermicioi's Blog

Just another weblog

Archive for April 2010

Web proiect pe SpringFramework 3.0

Acest post va fi un refactoring la alt post de al meu postat pe fostul blog, pe care nu-l mai utilizez šŸ™‚

Aici voi incerca sa arat cum utilizez eu SpringFramework-ul si MVC-ul sau.

Tehnologiile utilizate in proiect sunt:

  • Spring framework 3.0
  • Hibernate
  • Tiles2
  • Maven

Tiles2 – este un framework ce tine de partea de layouting.

Maven – raspunde de satisfacerea dependetilor de librarii. Read the rest of this entry »


Written by eraniblog

April 26, 2010 at 17:30

Posted in Coding

Fu**ing with java PL localization :(

That was the post on twitter 16 min. ago, without stars :). What happen?

I’m working on a Java web application which must have PL localization. The current task was to add the PL localization to application, so with fmt tag lib from jstl I start to implement it. When all static text was replaced with fmt tags I found that some chars are not rendered correctly. Today all morning I was searching why it happening, I was thinking that problem was JSTL, but not at finally I found that the problem is JVM it trying to convert sources and resource files from any encoding to unicode and somewhere something is not working as I expected :(. Ok here is the solution if you have resource files in ru, pl, etc.

In java exist utility native2ascii translate your files with that utility like:

# native2ascii

and all will be ok.

Ok, I leave to take a launch, now I can do it quite šŸ™‚

Written by eraniblog

April 20, 2010 at 13:40

Posted in Coding

Adding a Java library to local maven repository

Downloading jar file somewhere on hdd.
Execute command:

mvn install:install-file -Dfile=/home/erani/jlibs/kaptcha-2.3.jar
-DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar

adding dependency in pom.xml


Written by eraniblog

April 20, 2010 at 13:36

Posted in Coding

SVN and web access

So we need an access to svn throw apache, here is how to do it.
I will assume that a svn repository already made, if not, consult pleaseĀ

1. Install apache2, and libapache2-svn
2. Create “svn” directory in /etc and enter in it.

mkdir /etc/svn
cd /etc/svn

3. Create access file for two users:

htpasswd -cm users root
htpasswd -m users user

You will be prompted to enter password twice for each user, do it.
4. Create roles file

nano control

And add following:


If you want to add role for specific folder in project than add also


5. Configure Apache2.
Find configuration file for apache2, it’s depend of Linux distribution. Add/Edit the file so that in result you will have:

DAV svn
SVNPath /lib/svn # path to svn repository
AuthzSVNAccessFile /etc/svn/control
Require valid-user
AuthType Basic
AuthName "Subversion Repositories at"
AuthUserFile /etc/svn/users

6. Restart apache

I hope it will be helpful.

Also you can look at:

Written by eraniblog

April 20, 2010 at 13:29

Posted in Coding

Kubuntu KDE4 file sharing

So, I have problem sharing the folders on my Kubuntu 9.04 desktop. So I do following to enable it:

1.Ā apt-get install samba4, kdenetwork-filesharing
2.Ā sudo chmod u+s /usr/lib/kde4/libexec/fileshareset
3.Ā sudo rm -R /var/tmp/kdecache-root

Maybe not all of this is needed, but next time when I will have the same problem I’ll try to figure how fix it correct.

Written by eraniblog

April 20, 2010 at 13:21

Posted in Coding

Java, get a file from URL

The following code show how to get a file from URL.

URL serviceUrl = new URL("");
URLConnection urlConn = serviceUrl.openConnection();
InputStream is = serviceUrl.openStream();
FileOutputStream fos = new FileOutputStream("/tmp/myfile.tmp");
int aChar;
while ((aChar = != -1) {

If you want to save in original file name then you can add the code

String filename;
StringTokenizer tokenizer = new StringTokenizer(serviceUrl.getFile(), "/");
while (tokenizer.hasMoreTokens()) {
filename = tokenizer.nextToken();

before code

FileOutputStream fos = new FileOutputStream("/tmp/myfile.tmp");

do not forget to change name toĀ filenameĀ variable

Written by eraniblog

April 20, 2010 at 13:15

Posted in Coding


Din pacate titlul postului nu exprima concrete ce am dorit sa scriu acum.
Deci ideea e urmatoarea, cum sa obtin numarul paginei cerute de client? Ex.
avem pagina index.php?page=1 in cod trebuie sa obtinem valoare la parametrul page, o facem simplu

$page = $_GET['page'];

sigur trebuie apoi $page sa fie prelucrat ca sa nu fie trimis un SQL Injection sau chiar valoare negativa a paginei, -1 si iata solutia simpla este sigur:

$page = (isset($_GET['page'] && $_GET['page'] > 0) ? (int)$_GET['page'] : 0;

dar mi-a venit si o astfel de idee:

$page = (isset($_GET['page']) ? abs((int)$_GET['page']) : 0

parerea mea e ca arata putin mai elegant, dar care e mai rapdi?
xdebug_trace mi-a aratat rezulatele:

0.0016 pentru if()
0.0482 pentru abs()

sigur este timpul de executie. Codul pentru test a fost:

$numbers = array();
for ($i = -1000; $i < 0; $i++) {
$value = ($i > 0) ? $i : 0;

for ($i = -1000; $i < 0; $i++) {
$value = abs($i);

Deci totusi variantul cu if() a fost mai rapdi, bun il folosesc atunci pe el.

Written by eraniblog

April 20, 2010 at 13:02

Posted in Coding