Monday, December 01, 2008

Mobile Device Detection

ini ada beberapa contoh code untuk mobile device detection yaitu code di server untuk mendeteksi device apa yang digunakan client untuk mengakses server contoh sederhana apa menggunakan web browser via pc atau mobile device, masih banyak contoh2 yang lain.... intinya
memanfaatkan HTTP_USER_AGENT...

PHP
=====
http://www.richardshepherd.com/2008/09/ismobile-php-mobile-detection-goodness/


function isMobile() {
if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) {
return true;
}
if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
return true;
}
if(isset($_SERVER["HTTP_USER_AGENT"])){
$user_agents = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
foreach($user_agents as $user_string){
if(preg_match("/".$user_string."/i",$_SERVER["HTTP_USER_AGENT"])) {
return true;
}
}
}
if(preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) {
return false;
}
return false;
}
if (isMobile()) {
echo "mobile";
} else {
echo "web";
}
?>

JAVA
=====
http://code.google.com/p/mobiledevicedetector/

ASP Version
=========
http://mobiforge.com/developing/story/lightweight-device-detection-asp

dan masih banyak contoh yang laen.... smoga bermanfaaaatttttttt....

Thursday, November 27, 2008

String Buffer Query

Pernah coding java untuk dengan menggunakan SQL Native... seperti contoh di bawah ini:

String sql = " SELECT nc.NewsCategoryID, nc.NewsCategoryName, nc.BrandID, nc.ParentID " +
" FROM news_categorydetail ncd, news n, news_category nc" +
" WHERE ncd.newsID = n.newsID" +
" AND ncd.newsID = " + news.getNewsID() +
" AND n.NewsStatusID = " + Constant.NEWS_STATUSPUBLISH +
" AND nc.NewsCategoryID = ncd.newscategoryID ";

nah ternyata query semacam ini ada yang bilang tidak cukup efektif.... karena concat string sperti ini akan memakan alokasi memory... mestinya String sql bisa dialokasikan untuk satu tempat saja di memory.. tetapi karena proses concat string seperti itu akan memakan (weeeww rakusss..) alokasi memory... dimana setiap concat dilakukan akan menambah alokasi tersendiri di memory untuk menyimpang variabel string... kelihatannya sedikit tapi klo dalam sebuah aplikasi ternyata Query String cukup banyak.... gimenong.... hhehee??

untuk lebih efektifnya disimpan dalam object StringBuffer Seperti code di bawah ini :

StringBuffer buffer = new StringBuffer();
buffer.append(" SELECT nc.NewsCategoryID, nc.NewsCategoryName, nc.BrandID, nc.ParentID ");
buffer.append(" FROM news_categorydetail ncd, news n, news_category nc ");
buffer.append(" WHERE ncd.newsID = n.newsID ");
buffer.append(" AND ncd.newsID = " + news.getNewsID());
buffer.append(" AND n.NewsStatusID = " + Constant.NEWS_STATUSPUBLISH);
buffer.append(" AND nc.NewsCategoryID = ncd.newscategoryID ");
Setelah buffer string tersebut di buat maka String sql nya bisa diambil dengan buffer.toString()
cara seperti ini mungkin sedikit lebih efektif....
Haikkkk haikkkkk smoga bermanfaat...

Friday, August 29, 2008

JAX-WS dan Java 1.6

Bila menggunakan java 1.6 (jdk) dan mengimplementasikan aplikasi RESTful dengan Jersey library dan IDE Netbeans 6.1 maka ketika akan menggunakan fasilitas dari Netbeans untuk testing RESTful akan muncul alert javascript cannot access wadl .

untuk solusinya yang pernah aku lakukan, ikuti aja warning yang keluar pada apache tomcat log nya.

To use JAX-WS 2.1 with JDK 6, newer versions of API jars need to be in bootclasspath
before rt.jar. To do this you can use Java endorsed mechanism to override what is in
Java platform. The easiest way to do so is to copy all jars from the
C:\Program Files\NetBeans 6.1\java2\modules\ext\jaxws21\api folder to
C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\endorsed.


alias aku copy semua file *.jar mengikuti message yang ada di Log apache tomcat tersebut.
direktori "endorsed" by default belum ada dan perlu buat sendiri folder dengan nama endorsed.