Sunday Oct 25, 2009

How to invoke defaut email function in your application? You can do it in this way after SDK 3.0:

iPhone Tutorial - In-App Email

In case you are still work for 2.x version, you have to use openURL to send email:

Using openURL To Send Email From You App

For SMS function, there don't have a official SDK openned.  One possible way is using openURL function as same way for email:

sms:[target phone number] URL to open the SMS application.

But there are no indications on how to prefill a SMS body with text. Also, there have two other private ways to do it but it's illegal and couldn't upload to store:

 One is using 'AT' command, another way is using private framework for SMS.

Could you share it to me if you know other way can do it?

Wednesday Oct 14, 2009

In these day, I am write a client to access web. But I met issue on one site who is using http redirection by returning http status code 302. It's common shortage for HTTPURLConnection which didn't put the cookie from response into new access request for the redirect url. 

I search solution from web and find one library jCookie. It's quite old project but it really solve my problem. Here is a sample code to use it's HTTPRedirectHandler to handle redirection case:

    String link = "http://xxx.com/xxx";
    URL url = new java.net.URL(link);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setRequestProperty("user-agent","    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; zh-CN; rv:1.9.1.3)   Gecko/20090824 Firefox/3.5.3");
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    StringBuffer sb = new StringBuffer();

    sb.append("xx=x&xx=x");

    OutputStream os = connection.getOutputStream();
    os.write(sb.toString().getBytes("US-ASCII"));
    os.close();

    HTTPRedirectHandler connection1 = new HTTPRedirectHandler(connection);
    connection1.connect();

    connection = connection1.getConnection();

    InputStream in = connection.getInputStream();
    BufferedReader breader = new BufferedReader(new InputStreamReader(in , "UTF8"));
    String str=breader.readLine();

    while(str != null) {
          //Analyse the html;
          str = breader.readLine();
    }

    breader.close();
    connection1.close()

There have one more thing  I did:  update one line in connection function for class HTTPRedirectHandler:

        huc.setFollowRedirects(false);  ->   huc.setInstanceFollowRedirects(false);

Tuesday Sep 08, 2009

As store is already open to many countries in world, many developers start to i18n/l10n their applications to make their application can sell to customer all over the world.  There have a great article talking about iphone application i18n/l10n(Seemed you couldn't acces those links from China mainland):  

All things work!

  • Locale identifier for Chinese
Usually, we use 'zh_CN' or 'zh_TW' as locale identifier for Simplified Chinese and Traditional Chinese. But we need use 'zh-hans' or 'zh-hant' for Simplified Chinese and Traditional Chinese on iphone. Please keep it in mind if you try to l10ned your application to Chinese.

Tuesday Sep 01, 2009

In DocWeb 2.1, there have big feature: JavaFX API Doc Support.  Though JavaFX doclet api is kind of similiar to standard j2se doclet api, there still have some different.  We finally make it work by overcome following issues:

  • Run customized doclet class under web context. There have an issue if you try it in jdk 1.6.
  • Make sure JavaFX doclet api can work together with Java doclet.
  • Handle more tags for JavaFX

 Just like it shown in pic. User can choose 'JavaFX 1.2' from left frame. Then they can search or navigate APIs by 'Class', 'Variables/Fields', 'Functions/Methods' and 'Packages' . Finally, use will saw similiar doc interface in DocWeb as I shown below.

Now, we already release DocWeb 2.1. Please enjoy those features on DocWeb site and feel free to share us your feedback or suggestion. We will make more user friendly and absoluately we need your help!

Thursday Aug 27, 2009

NSString 是 Object C 中常用的类。在这里,我搜集整理一些关于 NSString 的操作供参考:

  • 添加 '@' 在字符串前变成 NSString

NSString *t = @"test"

  • 连接 

连接有三种方法:

NSString* string1; NSString* string2;

1. NString* compose = [NSString initWithFormat:@"%@,%@", string1, string2 ];

2. NString* compose = [string1 stringByAppendingString:string2];

3 . NString* compose = [string stringByAppendingFormat:@"%@,%@",string1, string2];

其中 format 的格式为:

'%@'   是格式化 NSString 类型

%d, %D, %i 是格式化  32位有符号整数 (int)

具体见参考手册

  • 转换
int 到 NSString:   [NSString stringWithFormat:@"%d", myInt];

NSInteger 到 NSString: [NSString  stringWithFormat:@"%d", [myNSInt intValue]];


Sunday Aug 23, 2009

As some unexpected maintenance activity from web host team,  the machine hosted DocWeb is down during this weekend.  I am very sorry for this. Today, I already started that machine to make DocWeb online.

Wednesday Aug 19, 2009

There are few features in coming DocWeb 2.1. And I just finish those features for DocWeb 2.1.  Actually I got some feedback from users that they like the whole style very much but found couldn't bookmark those APIs. So we put Ajax back/forward/bookmarks support as one of highest features in this release.

Now, we partial support that feature in coming DocWeb 2.1. User can bookmark their favorite APIs in DocWeb. They can also click browser's back/forward button to view the their history page. The only limitation here is that we only support package/class link in left frame current.  You couldn't bookmark pages got by clicking method/field link in left. You also couldn't bookmark pages got by clicking link in right frame of page. Those limitations will be disappear maybe in DocWeb 2.2.

BTW, we already support most of popular browser:

  • Internet Explorer
  • FireFox
  • Mozilla
  • Safari
  • Chrome
  • Opera
Please let me know if it didn't work in your browser.

Here is one of early picture for your reference:

 The few difference user may feel when using the new version in detail:

  • one is url change from 'DocWeb/#' to 'DocWeb/#r/CLDC 1.1/java.util.Random/columnMain'
  • Second is title changed from 'DocWeb' to 'DocWeb-CLDC 1.1-java.util.Random'
We will release it very soon. Please keep in tune and enjoy it at that time!

Thursday Aug 13, 2009

Today, I tried to find a way to merge my two accounts in LinkedIn. It's make me disappointed that there is no easy way to do it. Here I just get some anwser from LinkedIn:

  • Import one account information
  • Close that one
  • Send invitation to all connections in your first account to rebuild the connection with your second account
Not sure why they didn't provide a way to this. Do this break some thing in SNS's rule?

Sunday Aug 09, 2009

Web team decided put some servers into EOF.  DocWeb unfortunately is hosted on one of those servers. So we got a notification we need move DocWeb to new server. I was very busy on this thing last week:

  • Apply a new virtual machine
  • Setup GlassFish and do performance tunning
  • Migrate all data from old server to new server
  • Stress testing on new server
  • Request old hostname doc.java.sun.com  point to new server's ip address
All of those jobs have been done last week. Now, our doc.java.sun.com  already point to that new server. You may aren't unaware of this migration as it is really running smoothly. Cheers!

Thursday Aug 06, 2009

这些年在 Sun 一直在工作之余,做了一些 Sun 技术相关的推广工作,基本上一年会有一俩次。一直没有时间整理一下所做的演讲,看看这些年自己在这方面的成长历程。还记得 2006 年在上海的 Sun 技术日上我做的演讲,那应该是我比较正式的在公开场合上做幻灯。上台时一看下面黑压压的一片听众,当时头就大了,下来后知道当时有 600 多人在下面听。现在我重新听当时的录音还能感觉到我当时是非常的紧张阿。经过这些年的历练,在今年的江苏省架构师的培训讲座上,我已经能很游刃有余的控制局面了。现在回想所有这些事件,还历历在目。

1、2009年7月26,在江苏南京受邀为南京虚拟软件园做“如何用 J2EE 架构企业应用”。

这里是我的幻灯:PDF 格式 。  很高兴 Tina 为我拍了几张照片:


2、2008年在复旦的大学教师培训

我记得做了两个演讲,一个是 JavaFX 概论,另外一个是 NetBeans 移动上的游戏开发。现在找不到幻灯了,只有等啥时找到补上了。

3、2007年3月22日在成都的 Sun 开发者大会上,当时又 200 多人参加巴。我做了两个演讲:

- 轻松 AJAX,这里是幻灯:PDF 格式

- JavaSE 6 新功能介绍 ,这里是幻灯:PDF 格式

可惜当时没留下什么影像阿,现在都不记得当时还有谁和我一起主持的这次活动。

4、2006年9月22-24日在上海,27-29日在北京的 Sun 技术日上做的“如何'掌'控您的企业应用”。

这里是我的幻灯:PDF 格式 。  感谢同事为我照相,我还能找到一张:-)

这次演讲有录音,在 SDN 的网站上的这里可以听到。可惜该音频有 50 M,我不能直接上传到博客上。

Monday Jul 27, 2009

Now, there already have NetBeans plugin for Android. You can following the instruction to setup Android development plugin in NetBeans.

The next step is downloading Android SDK from Google and zip it to your favorite directory.

The rest steps you can refer Troubleshooting page and Introducing Android Development with NetBeans

One thing need be attention:

there have a bug in Android emulator setup. You need use a workaround:

Go in console to <SDK Path>/tools and type "android create avd -n <name> -t <target>". You can get target id by running 'android list-targets'.

Here is running result on my Mac, I make it work in NetBeans 6.7:

By the way, the emulator starting up process seemed a little slow, you just need wait for a while when click 'Run' in NetBeans.

Saturday Jul 04, 2009

Here, I try to list some debugging tools for different kinds of browser:

  • Internet Explorer
    • There have script editor in Microsoft Office which we can use to debug javascript which is stable than Microsoft Script Debugger according to my experience. You can install it from Microsoft Office(eg, Office 2003). 
    • Internet Explorer Developer Toolbar is a tool to help you explore and understand web page, such as view and modify DOM, finding the css style used on an element
    • Microsoft Visual Studio include heavy tool to debug javascript and view DOM tree which is maybe your another option.
  • FireFox
    • FireBug is wonderful tools for javascript debug and web page explore
  • Chrome
    • It come from WebKit and Google provide an embed tools in it. You can get javascript debugger tool shown below:

and explore web page as below:

  • Safari
    • It also base on WebKit, so it's same as Google way.
  • Opera
    • Opera dragonfly is option for javascript debugging and web exploring. You can easy get tools by access Opera debug menu in Opera. A menu will be added like belowing:

  • SeaMonkey
    • Tools is there in browser. You can invoke it from menu:

  • Konqueror
    • Web Browser, File Manager and more for the K Desktop Environment

Monday Jun 22, 2009

最近去南京做关于Java EE 架构的讲座,期间有来自企业的同行问了很多问题。其中有些问题很有意思:

  • 如何从 structs 移植到 JSF

我问了他原因,其主要是对开源框架的迁移有担心。象 structs 的迁移,到 structs 2 就与 structs 1 完全不兼容。这样的情况对原有企业的应用带来很大的问题,谁也不知道什么时候 structs 1 就没人支持和维护了。而要去迁移,成本又太大了。

这也许是某些开源框架的特性,它们会去追求最新技术,会去力求自己的框架最优。那么其演化就会比较激进,就不得不牺牲兼容性。而统观 Java EE 标准的发展,每一次更新都很好的考虑的已有应用的迁移。比如 Java EE 1.4 支持 EJB 2.1,而 Java EE 5 支持 EJB 3.0。其跨越在某种程度上是比较大的,但其仍然提供了很好的途径给企业迁移应用。在 Java EE 6 中,在考虑将实体 bean 不列为必须支持的部分,但其也提了商业的 Container 仍然可选择继续支持。

可见,技术上的先进性是不错,但有时很多企业却宁愿选择一个比较稳定的东西。那么在架构自己的企业应用的时候,尽量选用 Java EE 标准支持的技术,就是一个比较好的选择了。记得在哪里看到 IBM 50% 的利润来自它的主框架系统,使得许多人都感到意外。我想也是因为喜欢稳健使这些客户这么多年仍然选用一个相当多人认为已经消失的技术。

会上还有人问了另外一个问题:

  • 现在企业应用运行在 JDK 1.4 上,他们往 JDK 5 或 6 上迁移要考虑些什么?同时他还抱怨 JDK 版本是不是升级得太快了。
其实 JDK 版本升级不能算太快吧。象 JDK 5 中加入 annotation,JDK 7 中加入对 OSGi 的支持。这些都已经是业界支持了好一段时间了,最后才加入 JDK 中。不管怎么样,JDK 的各个版本间都保持了很好的兼容性,相对与 .Net 的用户,应该是很幸福的了。

Wednesday Jun 17, 2009

Two weeks past after we officially release DocWeb 2.0 outside. Now, we have visit data in my hand. Here is just make a simple analysis base on those data:

  • We already have 3,600 unique users access system and total access number is 4,507. The new visitor is 3600 which is 80% of all. That means the returning visitor is 900, it's 20% of overall.
  • We got about 300 new visitors everyday in past 2 weeks. At the same time, we got about 50-100 returning visitor everyday. That's good news for us: DocWeb make some users keep in loop and continue to attract more new users.
  • Those users come from all over the world. And top 10 countries are China, United States, Japan, India,Germany,Brazil,France,Mexico,United Kingdom and South Korea.
  • Most of popular browser used are Internet Explorer and FireFox. 9% of visits use Chrome and Safari.
  • 92 % of visits have Java plugin ready in browser
  • Most of import features from feedback are: Doc translatable and searchable.

Welcome all users from the world!


Monday Jun 01, 2009

今天, 2009年6月1日,我们正式在 http://doc.java.sun.com  上发布的 DocWeb 2.0 版本。SDN 的用户可以直接登陆 DocWeb。

DocWeb 2.0 使用 SDN 的用户界面风格,独特的支持 SDN 单点登录,多语言的内容,丰富的用户交互形式:意见,代码示例,投票,错误参考等等... 对全球的 JavaSE, ME, EE开发者而言,希望这个版本将大大增强用户体验和引进更多的方便和实用。衷心的欢迎大家浏览 DocWeb 2.0 并提更多宝贵意见!

This blog copyright 2009 by leonfan