<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PawaStation 能猫环岛 &#187; tutorials</title>
	<atom:link href="http://blog.pawa.ca/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pawa.ca</link>
	<description>An Apple a Day Keeps the Doctor Away</description>
	<lastBuildDate>Sun, 08 Mar 2009 04:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>没有 nib 的 iphone 程序</title>
		<link>http://blog.pawa.ca/2009/01/07/nibless_iphone_app/</link>
		<comments>http://blog.pawa.ca/2009/01/07/nibless_iphone_app/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 09:45:50 +0000</pubDate>
		<dc:creator>pawaca</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.pawa.ca/?p=16</guid>
		<description><![CDATA[Interface Builder 开始用还觉得酷炫浮华，越用越觉得不对劲，对于刚开始学写 iphone 程序，没有帮助理解代码，反而隐藏了需要知道的内容，然后用线连啊连，连着连着就晕了。另外，重点是，牛人都直接用代码写 GUI 的啊 XD。刚才试了一下不用 nib，只用敲 code，真的可以耶。步骤如下： 1. 新建一个 Window-Based Application 项目 2. 删掉 1MainWindow.xib 文件 3. 删掉 1Info.plist 里面的 1Main nib file base name 属性 4. 把 1main.m 文件中的 1UIApplicationMain 函数最后一个参数由 1nil 改为  1@&#34;NiblessHelloWorldAppDelegate&#34; 也就是我们的主要 delegate 的类名字 5. 把 1NiblessHelloWorldAppAppDelegate.h 文件里的 1IBOutlet 声明删掉（不删也行） 6. 在 1NiblessHelloWorldAppDelegate.m 的程序启动回掉函数里加上我们自己创建 window 以及 view 的代码 [...]]]></description>
			<content:encoded><![CDATA[<p>Interface Builder 开始用还觉得酷炫浮华，越用越觉得不对劲，对于刚开始学写 iphone 程序，没有帮助理解代码，反而隐藏了需要知道的内容，然后用线连啊连，连着连着就晕了。另外，重点是，牛人都直接用代码写 <span class="caps">GUI </span>的啊 XD。刚才试了一下不用 nib，只用敲 code，真的可以耶。步骤如下：</p>

<p>1. 新建一个 Window-Based Application 项目</p>

<p><img class="alignnone size-medium wp-image-17" title="2009-01-07_1714" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1714-300x197.png" alt="2009-01-07_1714" width="300" height="197" /></p>

<p>2. 删掉</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MainWindow.xib</div></td></tr></tbody></table></div>

<p>文件</p>

<p><img class="alignnone size-full wp-image-18" title="2009-01-07_1720" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1720.png" alt="2009-01-07_1720" width="388" height="215" /></p>

<p>3. 删掉</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Info.plist</div></td></tr></tbody></table></div>

<p>里面的</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Main nib file base name</div></td></tr></tbody></table></div>

<p>属性</p>

<p><img class="alignnone size-full wp-image-19" title="2009-01-07_1720_1" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1720_1.png" alt="2009-01-07_1720_1" width="564" height="324" /></p>

<p>4. 把</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">main.m</div></td></tr></tbody></table></div>

<p>文件中的</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UIApplicationMain</div></td></tr></tbody></table></div>

<p>函数最后一个参数由</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">nil</div></td></tr></tbody></table></div>

<p>改为 </p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@&quot;NiblessHelloWorldAppDelegate&quot;</div></td></tr></tbody></table></div>

<p>也就是我们的主要 delegate 的类名字</p>

<p><img class="alignnone size-full wp-image-20" title="2009-01-07_1722" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1722.png" alt="2009-01-07_1722" width="552" height="134" /></p>

<p>5. 把</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NiblessHelloWorldAppAppDelegate.h</div></td></tr></tbody></table></div>

<p>文件里的</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">IBOutlet</div></td></tr></tbody></table></div>

<p>声明删掉（不删也行）</p>

<p><img class="alignnone size-full wp-image-21" title="2009-01-07_1722_1" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1722_1.png" alt="2009-01-07_1722_1" width="485" height="150" /></p>

<p>6. 在</p>

<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NiblessHelloWorldAppDelegate.m</div></td></tr></tbody></table></div>

<p>的程序启动回掉函数里加上我们自己创建 window 以及 view 的代码</p>

<p><img class="alignnone size-full wp-image-22" title="2009-01-07_1723" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1723.png" alt="2009-01-07_1723" width="585" height="241" /></p>

<p>7. Build And Go Go Go。。。</p>

<p><img class="alignnone size-full wp-image-23" title="2009-01-07_1739" src="http://blog.pawa.ca/wp-content/uploads/2009/01/2009-01-07_1739.png" alt="2009-01-07_1739" width="357" height="520" /></p>

<p>项目文件<a href="http://blog.pawa.ca/wp-content/uploads/2009/01/niblesshelloworld.zip">打包在这里</a>，请自取。。。</p>]]></content:encoded>
			<wfw:commentRss>http://blog.pawa.ca/2009/01/07/nibless_iphone_app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cairngorm In One File</title>
		<link>http://blog.pawa.ca/2007/10/18/cairngorm-in-one-file/</link>
		<comments>http://blog.pawa.ca/2007/10/18/cairngorm-in-one-file/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 06:08:24 +0000</pubDate>
		<dc:creator>pawaca</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[utilities]]></category>
		<category><![CDATA[caringorm]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://blog.pawa.ca/?p=51</guid>
		<description><![CDATA[最近有机会研究了一下传说中的 Cairngorm 框架，整体感觉还不错，其中的模块化概念可以使项目在变大变复杂之后依然可控。 具体优点就不说了，说说最大的缺点，就是 繁琐 。由于要分离用户触发事件以及对应的 Command 操作，导致几乎每个明显的用户操作都要写一个 Event 类（还真是累阿）；另外由于 Cairngorm 本身是一个 design patten 的实践，不是 library，所以造成实际使用的时候需要死版的 implement 一些不着调的空 interface。 简单来说 Cairngorm 是一个婆婆妈妈的 framework，这从技术上来说也不是什么问题，但是重点是会影响写代码人的心情。比如我，一想到要每一个 action 都要写一个没什么特别之处的 Event class 就觉得头疼，一头疼就不想干，一不想干就完了。。。 所以，我就想能不能保留 Cairngorm 的思想，但是用一种更简洁的方式来实现？最后不小心想出了一招，经过一段时间的实验，感觉效果还不错，和大家分享一蛤。 global.as 我把 Cairngorm 的思想融入到一个名叫 global 的类中，使用的时候只需要这一个文件就包含了全部 Cairngorm 相关内容。我打算用一个通过 webservices 查询当前货币兑换比例的例子来具体的说一下 Cairngorm 各方面的特性，以及如何用 global 来实现这些特性。 全局的数据管理 Cairngorm 通过一个 singleton 的 ModelLocator 来连接数据与用户界面，基本思路是全部 ui 相关的数据都不是直接设置到组件上，而是通过一个全局的对象借由 binding [...]]]></description>
			<content:encoded><![CDATA[<p>最近有机会研究了一下传说中的 Cairngorm 框架，整体感觉还不错，其中的模块化概念可以使项目在变大变复杂之后依然可控。</p>

<p>具体优点就不说了，说说最大的缺点，就是 繁琐 。由于要分离用户触发事件以及对应的 Command 操作，导致几乎每个明显的用户操作都要写一个 Event 类（还真是累阿）；另外由于 Cairngorm 本身是一个 design patten 的实践，不是 library，所以造成实际使用的时候需要死版的 implement 一些不着调的空 interface。</p>

<p>简单来说 Cairngorm 是一个婆婆妈妈的 framework，这从技术上来说也不是什么问题，但是重点是会影响写代码人的心情。比如我，一想到要每一个 action 都要写一个没什么特别之处的 Event class 就觉得头疼，一头疼就不想干，一不想干就完了。。。</p>

<p>所以，我就想能不能保留 Cairngorm 的思想，但是用一种更简洁的方式来实现？最后不小心想出了一招，经过一段时间的实验，感觉效果还不错，和大家分享一蛤。</p>

<h3>global.as</h3>

<p>我把 Cairngorm 的思想融入到一个名叫 global 的类中，使用的时候只需要这一个文件就包含了全部 Cairngorm 相关内容。我打算用一个通过 webservices 查询当前货币兑换比例的例子来具体的说一下 Cairngorm 各方面的特性，以及如何用 global 来实现这些特性。</p>

<p><img src="http://blog.pawa.ca/wp-content/uploads/2009/03/global_test.png" alt="" height="80" width="429" /></p>

<h3>全局的数据管理</h3>

<p>Cairngorm 通过一个 singleton 的 ModelLocator 来连接数据与用户界面，基本思路是全部 ui 相关的数据都不是直接设置到组件上，而是通过一个全局的对象借由 binding 来实现。这样做分离了组件、数据以及命令之间的依靠。当有某个命令修改了某一个数据源之后，不用主动的再去更新组件显示，所有已经设置对应 binding 的组件将会自动更新。</p>

<p>global.as 将自身作为 ModelLocator 来使用，相关代码如下：</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// bindable properties, access from global.data model locator.</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> fromCurrency<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=“USD”<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> toCurrency<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=“CNY”<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currencyResult<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=“”<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> state<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=STATE_LOAD<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">enabled</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #3f5fbf;">/**<br />
&nbsp;* The global singleton model locator.<br />
&nbsp;*/</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">global</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _data<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>然后在对应需要响应数据更新的组件上通过绑定 global.data 中的对应属性来实现更新。比如实例中用来显示货币兑换比例结果的 Label 组件绑定了 global.data.currencyResult 属性。</p>

<div class="codecolorer-container mxml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="mxml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;{global.data.currencyResult}&quot;</span> color=<span style="color: #ff0000;">&quot;0x00ff00&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:label</span><span style="color: #7400FF;">&gt;</span></span></div></td></tr></tbody></table></div>

<h3>全局的事件播报以及响应</h3>

<p>在 Cairngorm 中，程序通过全局的 EventDispatcher 来播报全部程序相关的事件，然后对应处理事件的 Command 则通过 FrontController 在程序初始阶段配置好与对应事件的监听关系。副作用是：随着程序复杂程度的增加，会出现一堆只是名字不同的 Event class，以及只为了 execute 一下下却不得不实现的 ICommand 类。</p>

<p>global.as 通过静态方法 fire/listen/unlisten 实现了全局的事件播报以及监听功能，其中为了避免过多 Event class 的出现，fire 方法会播报出 DynamicEvent，并允许设置任意参数到 event 对象上，在实例中当用户点击了 Calculate Conversion Rate 按钮后会这样触发事件</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;global.fire(global.EVENT_CONVERSION_RATE,{fromCurrency:fromField.text,toCurrency:toField.text})&quot;</span></div></td></tr></tbody></table></div>

<p>另一方面 command 响应事件，也做了相应的简化：直接用 function 作为 command 来进行实际的业务操作：</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> conversionRate<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>DynamicEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//..</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> fromCurrency<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=<a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span>fromCurrency<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> toCurrency<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>=<a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span>toCurrency<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//..</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>最后在程序初始化的时候将 command 和对应的事件建立联系（类似 Cairngorm 中 FrontController 的功能）</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339966; font-weight: bold;">function</span> registerDefaultCommands<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//register default commands here.</span><br />
&nbsp; &nbsp; <span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>listen<span style="color: #000000;">&#40;</span><span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>EVENT_LOAD_WSDL<span style="color: #000066; font-weight: bold;">,</span>loadWsdl<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>listen<span style="color: #000000;">&#40;</span><span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>EVENT_CONVERSION_RATE<span style="color: #000066; font-weight: bold;">,</span>conversionRate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<h3>全局的网络服务资源</h3>

<p>最后关于远程 service 的部分，Cairngorm 提供了另外一个 singleton 的 ServiceLocator 供程序使用，并通过 Responder 来响应服务返回的结果。</p>

<p>在 global.as 中通过一个 rpc 方法实现了注册以及使用 service 的功能。比如实例中 webservices 的注册如下：</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339966; font-weight: bold;">function</span> registerDefaultServices<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//register default services here.</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> s<span style="color: #000066; font-weight: bold;">:</span>WebService=<span style="color: #0033ff; font-weight: bold;">new</span> WebService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//..</span><br />
&nbsp; &nbsp; <span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>rpc<span style="color: #000000;">&#40;</span><span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>CONVERSION_DESTINATION<span style="color: #000066; font-weight: bold;">,</span>s<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>然后代码通过以下方法访问上面注册的 service：</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> currencyConvertor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:*</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> rpc<span style="color: #000000;">&#40;</span>CONVERSION_DESTINATION<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>实际上 rpc 方法返回的是一个 service 的 proxy 对象。和直接使用 service 不同的是，通过 proxy 简化了服务方法调用后结果响应部分的代码。比如实例中获取货币兑换比率的方法是这样写的：</p>

<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span>currencyConvertor<span style="color: #000066; font-weight: bold;">.</span>ConversionRate<span style="color: #000000;">&#40;</span>fromCurrency<span style="color: #000066; font-weight: bold;">,</span>toCurrency<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>currencyResult=<span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>fault<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>fault<span style="color: #000066; font-weight: bold;">.</span>faultString<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">:*</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">global</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">enabled</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>

<p>其中第一个函数处理成功，第二个函数处理失败，第三个函数无论成功失败都会先执行。</p>

<p>至此 Cairngorm 的全部功能都被 global.as 实现了。如果有盆友对我瞎掰的这些感兴趣，可以 <a href="http://blog.pawa.ca/wp-content/uploads/2009/03/global_test.zip">下载 sample source</a> 然后把你的想法告诉我。</p>

<p>Over <img src='http://blog.pawa.ca/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.pawa.ca/2007/10/18/cairngorm-in-one-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring MVC 中的中文编码问题小说一蛤</title>
		<link>http://blog.pawa.ca/2007/07/26/spring-mvc-encoding/</link>
		<comments>http://blog.pawa.ca/2007/07/26/spring-mvc-encoding/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 04:17:02 +0000</pubDate>
		<dc:creator>pawaca</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.pawa.ca/?p=57</guid>
		<description><![CDATA[原来以为 Java 中文支持的会很好，没想到一用 Spring 就出乱码啦，看来人家默认情况下都不吊你第三世界国家的。。。 anyway 切入正题，我股沟了一下相关的内容，发现大多数解决方法都是加个 servlet filter 来转换编码。觉得这方法不好，好像虽然有用但是比较糊弄事，不彻底明白始终不爽。所以我就在源代码里游啊游，整理出大概的思路，如下： 页面显示中文 这部分以 jsp 为例， Spring MVC 在 resolve 页面显示的时候是这么一个流程。 InternalResourceViewResolver 利用 InternalResourceView 来 build view。 InternalResourceView 则会将最终页面生成的请求转交给对应的 jsp 来通过 container 实现。 如果页面显示有乱码，问题貌似会出在 InternalResourceView 上，实际上 InternalResourceViewResolver 的父类中有一个叫 UrlBasedViewResolver 的东东，里面有个属性叫做 contentType，并且会在 buid view 的时候最终把这个属性赋值给 InternalResourceView 。貌似找到了问题的原因。我试着这样设置并窃喜： 12345&#60;bean id=&#34;jspViewResolver&#34; &#160; &#160; &#160; &#160;class=&#34;org.springframework.web.servlet.view.InternalResourceViewResolver&#34;&#62; &#160; &#160; &#60;property name=&#34;contentType&#34; value=&#34;utf-8&#34;&#62;&#60;/property&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>原来以为 Java 中文支持的会很好，没想到一用 Spring 就出乱码啦，看来人家默认情况下都不吊你第三世界国家的。。。</p>

<p>anyway 切入正题，我股沟了一下相关的内容，发现大多数解决方法都是加个 servlet filter 来转换编码。觉得这方法不好，好像虽然有用但是比较糊弄事，不彻底明白始终不爽。所以我就在源代码里游啊游，整理出大概的思路，如下：</p>

<h3>页面显示中文</h3>

<p>这部分以 jsp 为例， Spring <span class="caps">MVC </span>在 resolve 页面显示的时候是这么一个流程。</p>

<p>InternalResourceViewResolver 利用 InternalResourceView 来 build view。 InternalResourceView 则会将最终页面生成的请求转交给对应的 jsp 来通过 container 实现。</p>

<p>如果页面显示有乱码，问题貌似会出在 InternalResourceView 上，实际上 InternalResourceViewResolver 的父类中有一个叫 UrlBasedViewResolver 的东东，里面有个属性叫做 contentType，并且会在 buid view 的时候最终把这个属性赋值给 InternalResourceView 。貌似找到了问题的原因。我试着这样设置并窃喜：</p>

<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jspViewResolver&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;contentType&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>

<p>页面刷新后乱码依旧。。。回到源文件中，游啊游，发现其实 InternalResourceViewResolver 虽然有给 InternalResourceView 赋值 contentType，但是 InternalResourceView 忽视了这个属性。。。然后直接转交给对应的 jsp 处理。看来问题实际上出在 jsp 上。到对应的 jsp 页面，加上下面的代码：</p>

<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;%@ page <span style="color: #000066;">pageEncoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">contentType</span>=<span style="color: #ff0000;">&quot;text/html;charset=UTF-8&quot;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>

<p>然后在编辑器里确保源文件也存成 utf-8，然后刷新页面，好了。<br />
	<br />
h3. 提交中文参数<br />
	<br />
原以为这样就 OK 了，后来发现还没完。。。在表单提交的时候，中文依然乱码，sun。再游！ 发现要改的地方有两点，第一个是针对表单的 <span class="caps">POST</span>，因为默认的 request body 处理的编码不是 utf-8 所以在 decode body 的时候会解出乱码来。这需要写个Interceptor 来设置 request 的 encoding ，比如：</p>

<div class="codecolorer-container java5 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java5 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RequestEncodingInterceptor <span style="color: #000000; font-weight: bold;">implements</span> HandlerInterceptor<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @<a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/Override.html"><span style="color: #003399; font-weight: bold;">Override</span></a><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">boolean</span> preHandle<span style="color: #009900;">&#40;</span>HttpServletRequest request,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpServletResponse response, <a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="color: #003399; font-weight: bold;">Object</span></a> handler<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/Exception.html"><span style="color: #003399; font-weight: bold;">Exception</span></a><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; request.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>然后挂在对应的 handlerMapping 上面，比如：</p>

<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;handlerMapping&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; class=&quot;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping&quot;&gt;<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;interceptors&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;RequestEncodingInterceptor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>

<p>另一方面，如果 url get 中有 encode 之后的中文参数，还需要确保 url decode 也用 utf-8 来解。由于 BeanNameUrlHandlerMapping 通过 UrlPathHelper 来处理 url，所以需要这样配置：</p>

<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;handlerMapping&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; ....<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;urlPathHelper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.util.UrlPathHelper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;urlDecode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultEncoding&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>

<h3>国际化 i18n</h3>

<p>国际化的配置文件如果用 java 的 properties 文件是不支持 utf-8 滴，要换成 Spring 的 ReloadableResourceBundleMessageSource ，酱紫配置：</p>

<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;messageSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; class=&quot;org.springframework.context.support.ReloadableResourceBundleMessageSource&quot;&gt;<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;basename&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WEB-INF/i18n/messages&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultEncoding&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>

<p>搞定！（貌似？）</p>]]></content:encoded>
			<wfw:commentRss>http://blog.pawa.ca/2007/07/26/spring-mvc-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何去掉 Flash Player 8 中那个烦人的安全设置窗口</title>
		<link>http://blog.pawa.ca/2005/09/13/remove_flash_security_dialog/</link>
		<comments>http://blog.pawa.ca/2005/09/13/remove_flash_security_dialog/#comments</comments>
		<pubDate>Tue, 13 Sep 2005 07:21:20 +0000</pubDate>
		<dc:creator>pawaca</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.pawa.ca/?p=88</guid>
		<description><![CDATA[Flash Player 8 最让人郁闷的就是那个新的安全机制。所有访问网络资源的程序如果通过在桌面上双击swf来运行，都会无一幸免的弹出这个对话框。 实际上新的安全机制没有错，错就错在那个安全设置对话框太招人烦。如果你不想看繁琐的文档，又想让整个世界清静，以下是几种解决办法(任意一种既可)。 通过 Settings Manager 设置。这个就是方法就是通过点击弹出的安全对话框中的设置按钮来添加Local-trusted位置。这个方法我个人感觉严重影响用户体验，而且只能在本机使用。 如果你有Flash 8程序，可以在输出设置里把local playback选项设置为access network only。 如果你没有Flash 8程序，可以下载 Flash Local Content Updater ，来防止弹出安全对话框。（Danger在此基础上作了个允许在Windows下直接右键修改的版本，有兴趣可以去看看。&#8221;SWF 文件安全策略修改器&#8221;:http://www.dengjie.com/weblog/comments.asp?post_id=960 ） 原理 当通过本地打开swf文件时，Flash Player8执行三种不同的安全机制： Local-with-filesystem 只允许访问本地文件。 Local-with-networking 只允许访问网络。 Local-trusted 允许指定的位置进行本地和网络访问。 第三种的实现是通过网上的Settings Manager来设置来自macromedia的本地shared object来实现。第一二种则是通过向swf文件中写入一个flash player8所能识别的tag标签来设置是否允许本地访问或网络访问。这个新tag的具体格式如下（个人推断，仅供参考）： tagCode : 69 tagLength: 4 （不包含tagCodeAndLength的大小，只表示tagContent的大小） tagContent: 0&#215;00000000 (表示Local-with-filesystem) ， 0&#215;00000001（表示Local-with-networking)]]></description>
			<content:encoded><![CDATA[<p>Flash Player 8 最让人郁闷的就是那个新的安全机制。所有访问网络资源的程序如果通过在桌面上双击swf来运行，都会无一幸免的弹出这个对话框。</p>

<p><img src="http://blog.pawa.ca/wp-content/uploads/2009/03/fp8_security_popup.png" alt="" height="242" width="533" /></p>

<p>实际上新的安全机制没有错，错就错在那个安全设置对话框太招人烦。如果你不想看繁琐的文档，又想让整个世界清静，以下是几种解决办法(任意一种既可)。</p>


<ul>
<li>通过 <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html">Settings Manager</a> 设置。这个就是方法就是通过点击弹出的安全对话框中的设置按钮来添加Local-trusted位置。这个方法我个人感觉严重影响用户体验，而且只能在本机使用。</li>
</ul>



<p><img src="http://blog.pawa.ca/wp-content/uploads/2009/03/fp8_security_setting.png" alt="" height="270" width="395" /></p>


<ul>
<li>如果你有Flash 8程序，可以在输出设置里把local playback选项设置为access network only。</li>
</ul>



<p><img src="http://blog.pawa.ca/wp-content/uploads/2009/03/access_network_setting.png" alt="" height="51" width="334" /></p>


<ul>
<li>如果你没有Flash 8程序，可以下载 <a href="http://www.macromedia.com/support/flashplayer/downloads.html">Flash Local Content Updater</a> ，来防止弹出安全对话框。（Danger在此基础上作了个允许在Windows下直接右键修改的版本，有兴趣可以去看看。&#8221;SWF 文件安全策略修改器&#8221;:http://www.dengjie.com/weblog/comments.asp?post_id=960 ）</li>
</ul>



<h2>原理</h2>

<p>当通过本地打开swf文件时，Flash Player8执行三种不同的安全机制：</p>


<ul>
<li>Local-with-filesystem 只允许访问本地文件。</li>
<li>Local-with-networking 只允许访问网络。</li>
<li>Local-trusted 允许指定的位置进行本地和网络访问。</li>
</ul>



<p>第三种的实现是通过网上的Settings Manager来设置来自macromedia的本地shared object来实现。第一二种则是通过向swf文件中写入一个flash player8所能识别的tag标签来设置是否允许本地访问或网络访问。这个新tag的具体格式如下（个人推断，仅供参考）：</p>


<ul>
<li>tagCode : 69</li>
<li>tagLength: 4 （不包含tagCodeAndLength的大小，只表示tagContent的大小）</li>
<li>tagContent: 0&#215;00000000 (表示Local-with-filesystem) ， 0&#215;00000001（表示Local-with-networking)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.pawa.ca/2005/09/13/remove_flash_security_dialog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
