May 19

最近在狂補 XML,真不是一般的頭痛,一個標准盛行的同時,衍生的問題通常也不在少數,對 XML 的操作可算是其中一個比較那個的問題,感覺很混亂,得花些時間搞明白它。我找到一本書(沒看之前可不敢說好不好):《Essential XML Quick Reference》,下面是它的一些介紹:

Essential XML Quick Reference: A Programmer’s Reference to XML, XPath, XSLT, XML Schema, SOAP, and More

Addison-Wesley and Developmentor have provided TheServerSide.NET with the entire book of Essential XML Quick Reference for free download. Essential XML Quick Reference is for anyone working with today’s mainstream XML technologies. It was specifically designed to serve as a handy but thorough quick reference that answers the most common XML-related technical questions.It goes beyond the traditional pocket reference design by providing complete coverage of each topic along with plenty of meaningful examples. Each chapter provides a brief introduction, which is followed by the detailed reference information. This approach assumes the reader has a basic understanding of the given topic.The detailed outline (at the beginning), index (in the back), bleeding tabs (along the side), and the page headers/footers were designed to help readers quickly find answers to their questions.

About the Authors

Aaron Skonnard is a founder of PluralSight and a contributing editor to MSDN Magazine, where he writes “The XML Files” column.

Martin Gudgin works at Microsoft, where he spends his time thinking about component software and related technologies. A Windows developer since 1987 and a COM developer since 1994, Martin has trained and mentored developers from a wide range of companies, including Microsoft, in numerous technical areas such as COM, IDL, MTS, COM+ and XML. He is a member of several W3C Working Groups, including XML Schema and SOAP.

不管這本書好不好,首先,能把這厚的東東貢獻出來本身就是件了不起的事,再說 Addison-Wesley 的出品應該還是有保證的,感謝 Aaron Skonnard/Martin Gudgin 和 Addison-Wesley,以及 TheServerSide.net。(點擊下圖下載)

Essential XML QUick Reference

May 18

重裝系統後工具還沒來得及裝,發現找不到 Editplus 了,想了想,算了,試著轉用 jEdit 吧,用 Cracked 的 Editplus 總是心有不安,盡管一年也用不了幾次。

很久以前就用過 jEdit,那時候因爲原來 JDK 的 Swing 實在太慢,加上“原裝”的 jEditEclipse 一樣,沒有插件就什麽也不是,所以也沒來得及深究就把它抛棄了。今天 down 了 Stable 的版本(4.2,development 版本現在是 4.3pre2),好好的折騰了一會,發現還挺好用的,尤其是它的插件管理機制,比 Eclipse 實在好太多了,嗯….這話還是別讓 Eclipse 的 Fans 們聽到的好,不然我會死得很慘的。不過 Eclipse 實在是。。。也不曉得該怎麽說好,不用吧,感覺自己追不上潮流;用吧,怎麽用怎麽不爽;插件亂七八糟互不兼容、免費的不好用好用的不免費,好了,加上各種各樣的插件可以工作了吧,又發現 Eclipse 打開的時間長了好幾倍,偶爾還跟你罷罷工,崩潰一下什麽的,天,什麽東東?好像扯的有些遠了。

剛才用 jEdit 的 Plug-in Manager 安裝了 Console 和 Buffer Selector 兩個插件,已經可以對付基本的工作了,據說還有 N 多很好的 Plug-in 使它不弱於 IDE,有空真得好好研究一下才行,確實是挺好用的,由於 JDK1.5的 Swing 重構了,所以現在無論是觀感和速度,jEdit 都已經和 Native 的程序相差無幾了,以後就用它和 Vim 好了,大東東再用 netBeans

jEdit

May 18

摘自《Struts Or JSF? Struts And JSF?》 【From Craig McClanahan’s Weblog

Introduction

It should come as no surprise that the most frequent questions I get asked center around the issue of which of these two web tier technologies an organization or individual developer should consider using. It makes sense to ask me, because I was the original creator of the Struts Framework, and was the co-specification lead for JavaServer Faces 1.0 (JSF).

Usually, the question is framed as an or issue, based on an understanding that the two technologies are mutually exclusive. That turns out not to be the case, but it can still be difficult to determine what to do. This blog entry provides my current advice on the subject — but, to understand it better, it’s worth briefly reviewing the development and focus of the two technologies.

The story is a little long compared to typical blog entries; if you want to cut to the chase and see my advice, scroll down to the section entitled The Bottom Line, below.

Struts

Struts grew out of a personal need (open source developers often call this scratching your own itch) to support the development of an application that I was responsible for, prior to joining Sun in 2000. My task was to take a US-centric application to Europe, initially in four languages, and make it available (among other delivery channels) on the web. At the time, there was lots of discussion about appropriate architectures for on the JSP-INTEREST mailing list at java.sun.com, but there were few available implementations. Therefore, I set out to create an application framework for my own use, particularly focused on some key functional areas:

  • An architecture based on the Model-View-Controller design patterns commonly seen in rich client applications, focusing on separation of concerns between presentation logic and business logic.
  • A request processing lifecycle that is applied to all incomding HTTP requests, allowing the centralized management of common functionality like input form validation, and invoking business logic via a logical alias, rather than embedding knowledge of the business tier into a view tier component.
  • Robust support for localizing the user interface of a web application.
  • Since I was planning to use JSP for the view tier, a set of JSP custom tags that simplified the creation of user interfaces based on HTML forms.

The resulting framework served my needs quite well. As it became obvious that my needs were not unique, I began the process of open sourcing this idea of a web application framework at the Apache Software Foundation. What happened next was nothing short of extraordinary — Struts quickly became the de facto standard web application architecture in the J2EE space (the number of significant Internet applications built with it is substantial, but is dwarfed by the number of intranet applications that use it), integrated into nearly all the major app servers and tools, supported by a rich ecosystem of knowledgeable proffesionals and skilled developers, backed by significant documentation in the form of books and articles, and the basis for a large user community centered around the Struts User mailing list (to subscribe, send an empty message to user-subscribe@struts.apache.org).

As Struts became a common starting point for developers new to the Java platform, an interesting phenomenom was occurring — for many developers, the key perceived value of using Struts was assumed to be the JSP custom tags for HTML forms. While these tags are quite useful, they do not constitute a robust user interface component model, which has led to the need to create or integrate of third party tag libraries for more complex presentation requirements. To me, the core value has always been in the controller tier (the request processing lifecycle, and the features which this lifecycle has enabled, such as the additions of the Tiles framework for reusable look and feel, and the Validator Framework for client side and server side enforcement of form validation business rules). This perception, then, has led to some of the current confusion.

JavaServer Faces

After Struts was released, and was beginning to demonstrate its popularity, an increasing number of other frameworks and component implementations were becoming available. Indeed, at one point during the development of JSF, I had pointers to over 50 such technologies on a spreasheet being used to survey the market. While a large amount of innovation occurred, it was difficult to forsee the development of a common standard API for user interface components — one that would enable the creation of a component marketplace where tools vendors could support one component API instead of 50, and where component developers could count on interoperation with many tools instead of one or two.

JSR-127 was introduced with the goal of solving this problem — providing a common base level API for building user interface components for web applications, with the specific goals of being both accessible to developers writing applications by hand, but also easy to integrate into tools. In order to complete this JSR in any reasonable amount of time (and, if you wish to argue that we didn’t achieve this goal, I won’t disagree :-), we stayed strictly focused on the view tier. Controller tier functionality was considered out of scope, although to be of any practical use we had to provide hooks for basic things like instantiating objects on demand, as well as support for page navigation.

The focus on the view tier was clear from the feature list for JSF 1.0:

  • Standard component API for user interface components, ranging from simple input fields to more complex tree controls and menus, to sophisticated scrollable tables which allowed both input and output. Components also support standard JavaBeans style events and event listeners.
  • Decoupled rendering model, so that the same component could be rendered in different ways (for example, a command component used to submit a form might be rendered as either a button or a hyperlink).
  • Request processing lifecycle focused on the handling of user interface events (such as the node of a tree control being expanded or contracted), coupled with support for data type conversions and component level validation rules.
  • Utility technologies supporting the component APIs, including value binding and method binding expressions, managed beans (create on demand), and page navigation support.

JSF 1.0 was released in March 2004, followed by a maintenance release (1.1) in May, and is being rapidly adopted by tools vendors, component writers, and application developers alike. The beginnings of widespread adoption are clearly occurring, and any application which you are about to start should certainly evaluate JSF to see if it meets your needs. Besides the functional APIs described above, you will enjoy the availability of robust tools support from many vendors (shamless plug — including the product I am currently an architect for, Sun Java Studio Creator).

The Bottom Line

But what about all those existing Struts applications? Are they going to get left out in the cold, or the developers forced to abandon their existing code and rewrite it? Nothing could be further from the truth.

The ideal scenario for existing Struts applications would be that we should be able to migrate, one page at a time (nobody has time to replace their entire UI in one fell swoop) to using JSF component tags — either the standard ones shipped with JSF, or from any available third party component library — to improve the richness of the user interface. And, because of the original MVC-based promise of separation of concerns, this migration should require little or no change in the back end functionality of the application (for Struts, that primarily means Action and ActionForm classes). Also, the migration should not eliminate the ability to use key Struts features like Tiles and the Validator Framework.

This scenario is, in fact, achieveable. In the Struts source repository is the Struts-Faces Integration Library, that achieves exactly this goal. It is currently available in nightly builds, but will shortly be released as a stand-alone add on library for Struts 1.1 or 1.2 based environments. The nightly builds include two versions of the canonical Struts example application, one using Tiles and one not, both using the Validator Framework.

If you have an existing Struts based application, then, I encourage you to evaluate a migration towards using JSF components instead of the original Struts HTML tags. Not only are the original tags effectively superceded by JSF, they are also not undergoing active development at the moment. You will find effectively equivalent functionality in JSF components already available, and much more sophisticated user interface components under development by many providers, for use in the future.

For new development, here’s the best strategy for determining what to do:

  • Evaluate the two technologies individually, to see if they satisfy your requirements.
  • If one or the other technology is sufficient, go ahead and use it (it’s easier to learn and use one technology rather than two where possible); keeping in mind, however, the caveats about Struts HTML tags mentioned above.
  • If your requirements include unique features supported only by Struts (such as Tiles or client side validation support), feel free to use the two frameworks together.

The Future

It should be clear by now that there is overlap between Struts and JSF, particularly in the view tier. Over time, JSF will continue to evolve in the view tier area, and I’m going to be encouraging the Struts community to focus on value adds in the controller and model tiers. Thus, it will become more and more clear that there is room in many web application architectures for two frameworks, each focused on their own tiers, cooperating to meet overall architectural requirements. The details of this, however, will be the subject of further discussions on the Struts developer mailing list, and (undoubtedly) future blog entries.

May 13

最近好像總是失眠,怎麽也睡不著,於是昨晚索性通宵來研究 linux 的中文化問題,總算不枉我犧牲了寶貴的睡眠時間,搞懂了許多東東。以前我懶得折騰,總是用別人修改的帶有粗體、斜體和粗斜體 Simsun.ttf,現在覺得總這樣也不是辦法,原理還是得搞懂才行的。現在 Linux 的 Desktop 上中文的顯示問題由於台灣 Firefly 兄的努力,已經得到了很大的改善。我看了一會,現在解決中文問題只需要打上 Fontconfig(Ver. 2.2.3)和 libXft(Ver. 2.1.2)的 Patch 就可以了,不再需要像以前那樣把 Pango 啦、Qt 啦、Freetype 啦這些東東都 Patch 個遍了。但是本人比較懶,所以想嘗試找出更簡單直接的方法,還好,運氣不錯,發現編譯 Firefly 兄 Patch 過的 libXft 然後直接覆蓋系統的的 libXft.so.2.1.2(位於/usr/lib/下,負責粗、斜體的運算)加上自定義的 fonts.conf 文件就可以獲得很㊣的效果了,我不曉得爲什麽還有那麽多人還要 Patch Fontconfig 才行,難道是因爲俺長得比較帥的緣故嗎…….

通過 Patch 過的 libXft 和 .fonts.conf 的結合現在顯示方面對比 Windows 已經只是強不弱了,有圖爲證:

Konqueror on Gentoo Box

我的 .fonts.conf 在這裏(下載後放在用戶目錄下),PS 一下,不要直接修改或覆蓋 /etc/fonts/fonts.conf 和 /etc/fonts/local.conf,因爲它們都會在 Fontconfig 昇級或重建的時候被重置、覆蓋掉,放在自己的用戶目錄下就不會有這個問題,而且用戶目錄下的 .fonts.conf 優先級也是最高的,從優先級來說: ~/.fonts.conf > /etc/fonts/local.conf > /etc/fonts/fonts.conf

JDK1.5 的中文問題相對來說就好解決得多了,但 sun-jdk 發展到現在,在 server 端上發展如此迅猛的 linux 平台下 SDK 的中文乃至於其它很多雙字節文字的顯示問題仍然沒有得到解決這點卻讓人很不能理解,白癡的 Sun!我們有強大的 Bea、老不死的 IBM,再這樣下去恐怕你會連自己是怎麽完蛋都不曉得的了。

JDK 的中文設置按這裏,把這個文件 CP 到 JDK 的安裝目錄下({JDK_HOME}/jre/lib),確認你的 locale 裏 LC_CTYPE 的值是(zh_CN.Encoding),然後打開 JDK 的 ControlPanel 測試({JDK_HOME} /jre/bin/ControlPanel),OK,這下終於正常了。然後?廢話,當然是開始幹活了!

ME的:

JDK on Gentoo Box

May 12

剛用 LiveCD 裝好了基系統,把默認的 GCC3.3.5 換成了 GCC3.4.3,打開了 NPTL 重建基礎工具集和基系統,用的是 Stage3。使用 GCC3.4.3 和打開 NPTL 重建系統花了挺多的時間。正常情況下使用 LiveCD 從 Stage3 完成基系統的安裝需要大概 2 小時。而切換到 GCC3.4.3 以及打開NPTL 後,單是更新 gcc、glibc 以及重建基系統都需要將近 10 小時。也就是說,用 2005.0、使用 GCC3.4.3、打開 NPTL,從 Stage3 開始安裝好一個基系統,最少得預留 12 個小時。當然,如果你是有錢人,在用 A64 這樣的 U、2G 的 RAM,就當我剛才什麽沒說好了,不過我想我的 Config 應該可以代表當前廣大人民群衆的主流,俺的主配置如下:

  • 底板:Asus A7N8X PCB1.03(nForce2)
  • CPU:AMD 2000+ OC 2400+(L1 Cache 64KB、L2 Cache 256KB)
  • RAM:StarRam DDR400 512*2
  • HDA:Seagate7 120G 8M
  • HDB:WD800JB 80G 8M

使用 LiveCD 啓動的時候加上了 nofirewire、nokeymap 禁用了 firewire 和非 US 鍵盤映射的選擇以節省時間。切換至 GCC3.4.3 所帶來性能的提昇也是很明顯的,運行性能暫時還不曉得,但目前看來最起碼編譯的性能得到了很大的提昇,xorg 過往需要將近兩小時,現在使用 GCC3.4.3,40 分鍾就好了。這樣的話,號稱大幅提高性能要趕超 ICCGCC4.0 的確很值得期待,希望它能盡快的進入實用階段。基系統的安裝過程中發現了 2005.0 的一個小Bug,不大不小,其實應該算是文檔方面的問題。以往要啓用 rp-pppoe,必須在 /etc/conf.d/net 內加入:

# For rp-pppoe only
iface_eth0=”up”

我照以往的做法,結果發現 Base 安裝完成後啓動時總是出現 “netmount not start” 的error,用 rc-status 一看,結果是 net.eth0 都沒有啓動成功。用 dmesg | grep eth0、lsmod、lspci 在 livecd 和基系統間反複的切換比較著,檢查檢查再檢查,首先確認了 nForce 的 onboard Ethernet Controller(Forcedeth)已安裝成功,驅動問題排除;然後發現用 lsmod 在 livecd 裏可以看到 Forcedeth 的模塊名,心裏汗了一下:“不會那麽變態吧:’編入 kernel 不行反而要編成模塊再加載這麽的弱智’?’”,事到如今也只好試試了,也總算是有個解決問題的方向,重編 kernel,然後把 Forcedeth 加到/etc/modules.autoload.d/kernel-2.6 裏,滿心歡喜的看著機器 reboot 准備上網繼續安裝系統,結果親愛的 netmount error 又回來了,把我氣個半死。忽然間留意到 netmount error 前面的錯誤提示:”up is not a correct module to load…”,難道???於是把安裝時在 /etc/conf.d/net 裏加入的 rp-pppoe 相關項注釋掉:

# For rp-pppoe only
#iface_eth0=”up”

重啓net.eth0:

/etc/init.d/net.eth0 restart

Woooohhhh,成功了,再 restart netmount 的時候已經正常,可以連上網了,thx Me:)
2005.0 的 handbook 裏可能還有一些類似的小 Bug,不過因爲我並沒有完全按照 handbook 來做,所以也沒看完 handbook。但還是希望以後 Gentoo釋出 Release 時,通過測試的不僅是 Product 本身,handbook 作爲與用戶最初的交互,也是很重要的。