4 Kasım 2008 Salı

How To Disable Corcurrent Logins in Spring-Security

Add the following listener to your web.xml file to keep Spring Security updated about session lifecycle events:

<listener>
<listener-class> org.springframework.security.ui.session.HttpSessionEventPublisher </listener-class>

</listener>



Then add the following line to your application context file:

<http>
...
<concurrent-session-control max-sessions="1" />
</http>



This prevents concurrent logins. A second login will cause the first to be invalidated. To prevent a second login, use following configuration:

<http>
...
<concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true"/>
</http>



The second login will then be rejected.

11 Ekim 2008 Cumartesi

Create XSL Document Using An Existing XML Document

To create an xml schema document(XSL), you should know XSL specification. But, thank goodness, there is another time saving option. Intellij IDEA does the job for us, without any effort. Intellij IDEA is capable of generating XSL documents from existing XML files. Assuming that we have such an XML document as follows:
<table>
<column>
<name>Name</name>
<type>String</type>
</column>
<column>
<name>Surname</name>
<type>String</type>
</column>
<column>
<name>Birthday</name>
<type>Date</type>
</column>
</table>


Because we don't have an XSD file for our XML file, Intellij complains about this and cannot make syntax-highlighting. Let's resolve this issue. Go to Tools/Generate Xml Schema From Document menu option:



Then, change the filename to "xml-format.xsd" and change the value of "Detect enumerations limit" to any value less than 3. This is because, we have 3 column regions in the XML document and the values inside the column tags are not enumerations. If we don't change this value to something lower than 3, xsd generator will interpret the values inside the column tag as enumerations, and generate the xsd file based on this interpretation. So, change it to 1, for example. Then click OK.



You will get the following XSD document as a result:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="table" type="tableType"/>
<xs:complexType name="columnType">
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="String"/>
<xs:enumeration value="Date"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tableType">
<xs:sequence>
<xs:element type="columnType" name="column" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

You can also change the format of the generated XSD document, using "Design Type" area in "Generate Schema From Instance Document" dialog box. There are 3 available choices:



But we are not done yet. We should tell our XML document the location of its schema document(XSD) which we just created before. Assuming that, our XML and XSD files are on the same path, change the first line of the XML as follows:

<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xml-format.xsd">
<column>
<name>Namename>
<type>Stringtype>
column>
<column>
<name>Surnamename>
<type>Stringtype>
column>
<column>
<name>Birthdayname>
<type>Datetype>
column>
table>

Now, our xml editor is able to make syntax-highlighting, using the newly generated XSD file.



And now, Ctrl+Space works also. We may not write erronous XML files any more:).

9 Ekim 2008 Perşembe

NLS_DATE_FORMAT Kullanımı

SQL> select sysdate from dual;

SYSDATE
----------
09/10/2008

SQL> alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';

Oturum değiştirildi.

SQL> select sysdate from dual;

SYSDATE
-------------------
2008-10-09 17:27:38

30 Eylül 2008 Salı

A Nice Maven Feature In Intellij 8

There is a useful maven feature in Intellij 8. As you know, maven doesn't download the sources.jar files of the libraries into the local repository, by default. You can download the sources.jar files of the dependencies of the project by just one click of a button. First open the Maven view in Intellij. Then press the "Download artifacts" button from the toolbar:



Actually this feature also exists in Intellij IDEA v7 but I can't make it work. Probably, there is a bug. Please inform me, if there is anyone who can use the feature in version 7.

17 Ağustos 2008 Pazar

Intellij Knows Swing

As I use Intellij more and more, I get more and more suprised, more and more excited.

Yesterday, I was trying to change the cursor in a swing project, using setCursor() method. I expected Cursor.W_RESIZE_CURSOR would return a java.awt.Cursor object and coded as below. But something was wrong with my code:












...And immediately, Intellij told me what was wrong with my code:). I should have called Cursor.getPreferredCursor(). I applied Intellij's suggestion, and the error was corrected. My intelligent IDE again saved me to search for example codes on the internet:

4 Ağustos 2008 Pazartesi

How To Sort Collections Using commons-beanutils?

Hi everybody,
Following is another simple way of sorting collections using commons-beanutils package:
Assume that we have an object as below:

public class User {
private long userId;
private String userName;
private String password;
}

And we want to sort based on userName field. We can use BeanComparator class of commons-beanutils package as below to sort the list:

ArrayList list = new ArrayList();
//...
//add User object inside the list.
//...
Collections.sort(list, new BeanComparator("userName"));

Notice that, we passed the name of the field to be sorted, as the parameter, to BeanComparator class constructor. We accomplished sorting of a collection using just one line of code:).

Download commons-beanutils from http://commons.apache.org/beanutils.

28 Temmuz 2008 Pazartesi

JBoss server'a IP numarası ile erişim

Lokal makinemizde çalışan jboss'a http://localhost:8080 adresiyle erişebiliyoruz. Ama http://127.0.0.1:8080 adresiyle denediğimizde, şeklinde erişemeyiz. Bununla beraber uzaktaki bir istemci de ip numaramızı bilmesine rağmen erişim problemi yaşayacaktır. IP numarası ile erişimi aktive etmek için Jboss'u "-b" parametresiyle başlatmamız gerekmektedir. Bu durumda kullanacağımız komut aşağıdaki gibi olacaktır.

> run.bat -b 0.0.0.0

27 Temmuz 2008 Pazar

JBoss'u baska bir domain ile başlatmak

Standart Jboss kurulumu "default" adli server instance'ı başlatmaktadır. Başka bir server instance'i başlatmak için "-c" parametresini kullanmalıyız. Örneğin standart kurulumda gelen, "minimal" adli server'ı başlatmak için aşağıdaki komutu kullanmalıyız:

> run.bat -c minimal

21 Haziran 2008 Cumartesi

JSTL Reference

Following document is a good resource about JSTL for java web developers.

http://www.manning-source.com/books/bayern/bayern_apxA.pdf

This document can also be found in Shawn Bayern's book JSTL In Action.

22 Mayıs 2008 Perşembe

Javascript ile TEXTAREA'ya metin eklemek

Javascript kullanarak, bir HTML sayfasındaki TEXTAREA'da cursor'un bulunduğu yere nasıl text eklendiğini bulmak için yaklaşık 1 saat araştırdım. Basit gibi görünen bu işlemi, en sonunda, Alex King'in blogunda buldum. Yazıya, http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript adresinden inceleyebilirsiniz. İlginçtir ki, Alex King de bu fonksiyona PhpMyAdmin'de raslamış.

21 Mayıs 2008 Çarşamba

20 Mayıs 2008 Salı

17 Mayıs 2008 Cumartesi

1 Mayıs 2008 Perşembe

İş Görüşmesine Katılacaklara Taktikler

Aşağıda, katılmış olduğum iş görüşmelerinde sıkça karşılaştığım soruları ve tavsiyelerimi yayınlıyorum.

Soru: Şirketimize katkıda bulunabileceğinizi düşünüyor musunuz?
Cevap: Düşünmeseydim buraya gelmezdim.

Soru: Bize kısaca kendinizden bahseder misiniz?
Cevap: Sadece iyi yönlerinizden bahsetmeyin. Hem iyi yönlerinizden hem de kötü yönlerinizden bahsetmeniz uygun olur. Motivasyonumu çabuk kaybederim, çabuk sinirlenirim, takıntılarım vardır gibi şeyler söylemeyin:). Eğer gerçekten bu tür problemleriniz varsa da, "Kişisel Gelişim" konulu yayınlardan faydalanabilirsiniz.

Soru: Geleceğe dair hedeflerin nelerdir?
Cevap: Bu soruyu cevaplamak size kalmış:). Böyle bir soruya karşı hazırlıklı olun.

Ayrım yapmadan bütün teknoloji şirketlerine cv'nizi gönderdiniz. Aşağıdaki soruya karşı hazırlıklı olmalısınız:
Soru: Neden bizim şirketimizi tercih ettiniz?
Cevap: Bütün teknoloji şirketlerine cv'mi yolladım. Sizin bir özelliğiniz yok pek tercih edilecek bir cevap değil.

26 Nisan 2008 Cumartesi

Javascript İle Gizleme/Gösterme

HTML sayfamızdaki herhangi bir alanın gizlenmesi ya da görünür hale gelmesini displayözelliğini kullanarak yapabiliriz.
Alanın gizlenmesi için bu özelliğin değerini display: none şeklinde değiştirmeliyiz.
Gizli bir alanın görünür hale gelmesi için bu özelliğin değerini display: block şeklinde değiştirmeliyiz.

Aşağıdaki örnekte new_artist_region alanı görünmezdir:

<span id="new_artist_region" style="display: none;">
<input name="new_artist" type="text">
</span>



Aşağıdaki örnekte ise new_artist_region alanı görünür durumdadır:

<span id="new_artist_region" style="display: block;">
<input name="new_artist" type="text">
</span>



Aşağıda ise, javascript kullanarak bir alanın nasıl görünür/görünmez hale geldiğini görüyoruz:

<script language="Javascript">
function showhide(area_id){
var area = document.getElementById(area_id);
if (area.style.display == "block") area.style.display = "none";
else if (area.style.display == "none") area.style.display = "block";
}

</script>
<input type="checkbox" name="new_artist" onclick="showhide('new_artist')">New Artist
<span id="new_artist" style="display: none">
<input type="text" name="new_artist">
</span>

25 Nisan 2008 Cuma

How To Export Query Results In Mysql

Use "INTO OUTFILE" directive in your queries to export data from mysql into a text file.

mysql> select * from videos order by artist INTO OUTFILE "c:\videos.csv"
Query OK, 3269 rows affected (0.05 sec)


Use "FIELDS TERMINATED BY" directive to determine delimiter between fields.

mysql> select * from videos order by artist INTO OUTFILE "c:\videos.csv" FIELDS TERMINATED BY "|";
Query OK, 3269 rows affected (0.06 sec)


If you do not specify absolute path in "INTO OUTFILE" directive, the file will be recorded in current database's path. For example, assume that mysql is installed in "D:\dev\mysql" and the current database is "video_db"; then the path of videos.csv would be "D:\dev\mysql\data\video_db".

24 Nisan 2008 Perşembe

How To Change MySql Root Password

In this example, I am going to change mysql root account's password from 1234 to 123456 using SQL. The queries are so self-explanatory. So, there is no need to describe them.

D:\dev\xampp\mysql\bin>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD("123456") where User="root";
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

D:\dev\xampp\mysql\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

14 Nisan 2008 Pazartesi

Some Mysql-Specific Commands

Following is a list of some of mysql specific commands that I frequently use. You should be connected to mysql server through the command-line to execute the commands.

>show databases;
Display the list of databases hosted by the mysql server

>use db;
Selects the database to be working on.

>desc table;
Describes the metadata of the table;

>show tables;
Display tables of the selected database

>source test.sql;
execute an SQL script file

8 Nisan 2008 Salı

How To Kill A Process In Windows: TASKKILL

What is taskkill?

To kill a process in Windows using command-line use TASKKILL command.

If you know the name of the process use /im switch. Following command terminates Windows Media Player:

taskkill /im wmplayer.exe

If you know the process id, use /pid switch. Following command terminates the process identified by PID=1545:

taskkill /pid 1545

If you want to kill the parent process and its child processes, namely tree-kill, use /t switch. Following command terminates the process identified by PID=1545:

taskkill /t /pid 1545

If you want to force the process to be terminated, use /f switch. Following command terminates the process forcefully:

taskkill /f /pid 1545

5 Nisan 2008 Cumartesi

Why Doesn't PrintWriter Work?

Even though you may call method PrintWriter.println(), you may not get any output. This is because PrintWriter is auto-flush off by default. Check the code below:

 1 public class Test {
2 public static void main(String[] args) {
3 OutputStream out1 = System.out;
4 PrintWriter out = new PrintWriter(out1);
5 out.println("hello");
6 System.out.println("text is about to be flushed.");
7 out.flush();
8 }
9 }

The output is as follows:
text is about to be flushed.
hello

To enable auto-flush, you must initialize PrintWriter as follows:
PrintWriter out = new PrintWriter(out1, true);

26 Mart 2008 Çarşamba

Java Tabanlı Oyun Motorları

Bu aralar bol bol boş vaktim var. Ben de, çok merak edip de şimdiye kadar ilgilenemediğim, değişik değişik konularla zamanımı değerlendiriyorum. Şu anda java tabanlı açık kaynak kodlu oyun motorlarını araştırıyorum. Bir yandan da OpenGL ve DirectX'i araştırıyorum. Google'da "java game engine" araması sonucu bulduğum bazı sonuçları aşağıda yayınlıyorum.

Java Monkey Engine:
http://www.jmonkeyengine.com/

EasyWay:
http://easyway.sourceforge.net/joomla/index.php
Adı üstünde kullanımı ve öğrenimi kolay bir oyun motoru. Şimdilik sadece 2 boyutlu oyunlar yapılabiliyor. 3 boyut desteği yok. Tam ekran ve pencere desteği var. Applet desteği sıradaki versiyonla beraber geliyor. Bir an önce oyun programlamaya başlamak istiyorum diyorsanız, seçiminiz bu olsun. Sitedeki tutorial'leri okuduktan sonra kendi oyununuzu yazmaya başlayabilirsiniz.

OctLight:
https://jge.dev.java.net/
OctLight öncelikle online oyun geliştirilmesi amacıyla tasarlanmış. Fakat normal oyunlar da geliştirilebiliyor. Proje'nin şimdilik çok eksiği var. Yaklaşık bir senedir güncelleme görmemiş.

Golden T Game Engine:
http://goldenstudios.or.id/products/GTGE/
GTGE ile de 2 boyutlu oyunlar hazırlanabiliyor. Tam ekran, pencere ve applet desteği var. Sitesinde onlarca örnek oyunu kaynak koduyla beraber indirebilirsiniz.
Bu proje, EasyWay'den daha aktif bir proje. Sadece forumlarında bile, EasyWay'den çok daha fazla post mevcut.

JGame:
http://www.13thmonkey.org/~boris/jgame/

Şimdilik hangisi daha kullanışlı ben de bilmiyorum. Zaman içinde bu gönderiyi güncelleyeceğim.

23 Mart 2008 Pazar

Online JavaOne Seminerleri

Aşağıdaki adresten, şimdiye kadar yapılmış olan JavaOne seminerlerini izleyebilir ve sunum dosyalarını indirebilirsiniz.

http://developers.sun.com/learning/javaoneonline/index.jsp

Sitede, aklınıza gelebilecek her türlü konuda görsel, işitsel içerik mevcut:).

20 Mart 2008 Perşembe

ServletContext ile ServletConfig Arasındaki Fark

ServletContext, uygulamaya ait parametrelere erişmek için kullanılır. 1 uygulamada, 1 ServletContext objesi bulunur. Bu parametreler, web.xml dosyasında, aşağıdaki gibi saklanır:
<context-param>
<param-name>logfile_path</param-name>
<param-value>\logs\log.txt</param-value>
</context-param>


ServletConfig, ait olduğu servlet'e ait parametreleri barındırır. Uygulama içindeki her servlet'in 1 ServletConfig objesi vardır. Bu parametreler, web.xml'de aşağıdaki gibi saklanır.
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
<init-param>
<param-name>About the Servlet</param-name>
<param-value>This is my servlet.</param-value>
</init-param>
</servlet>

15 Mart 2008 Cumartesi

Halil'in Dönüşü

Evet arkadaşlar, Nisan 2007'de başladığım askerlik vazifemi bugün itibariyle bitirdim:). Darısı askerliğini henüz yapmamış arkadaşlarımız başına:)