メモ代わり。てきとーに。 いや、ですからてきとーですって。 2年前ぐらいにPythonあたりでメールくれた方、ごめんなさい。メール紛失してしまい無視した形になってしまいました。。。

2009年7月31日金曜日

[Apache Shindig][お勉強][OpenSocial] メモ114 content-rewriterを使ってみる

shindigのソースを読む限り、使えそうなcontent-rewriter機能を使ってみる。
shindigのバージョンは1.1-SNAPSHOT。

まず、デフォルトでの機能をオフにする。
デフォルトでは全てのURLで有効になっている模様。
この設定を変更するには、

shindig.properties

をいじる。
デフォルトだと、


shindig.content-rewrite.include-urls=.*
shindig.content-rewrite.exclude-urls=
shindig.content-rewrite.include-tags=link,script,embed,img,style
shindig.content-rewrite.expires=86400
shindig.content-rewrite.proxy-url=/gadgets/proxy?url=
shindig.content-rewrite.concat-url=/gadgets/concat?

となっているので、

shindig.content-rewrite.exclude-urls=



shindig.content-rewrite.exclude-urls=.*

とする。

exclude-urlsとinclude-urlsはexclude-urlsが優先。
で、Patternクラス用正規表現で指定できる。

キャッシュを無効にするだけであれば、

shindig.content-rewrite.expires=86400



shindig.content-rewrite.expires=0

とすればよさそう、だけど試していない。
注意点としては、GadgetのXML自体のキャッシュの無効化、とは関係ない点。
content-rewriterは、あくまでGadgetXMLの中の要素にのみ有効となっている模様。
もし、GadgetのXMLファイルのキャッシュを無効化したいのであれば、
nocacheパラメータをつけるか、もしくは
shindig.propertiesのshindig.cache.xml.refreshIntervalを0なりに設定するか、
shindig.propertiesのshindig.cache.lru.gadgetSpecs.capacityの行を削除するか、
で、無効化できる。

ついでに、gadgetのXMLファイルのキャッシュも無効化。
shindig.propertiesの

shindig.cache.xml.refreshInterval=300000



shindig.cache.xml.refreshInterval=0

に修正。

修正したら、コンパイルして起動。
で、アクセスしてみると、修正の度に新しいGadgetXMLが読み込まれるし、
imgタグなんかのURLもrewriteされていない。

proxyUrlとconcatのURLは、container.jsに記述があれば、そちらが優先。
container.jsに記述が無ければshindig.propertiesが優先される。



そしたら、今度は、
content-rewriterフィーチャーを使ってみる。
で、使ってみたXMLは以下。
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <Module>  
  3.   <ModulePrefs title="content-rewrite">  
  4.     <Require feature="opensocial-0.8" />  
  5.     <Optional feature="content-rewrite">  
  6.       <Param name="expires">86400</Param>  
  7.       <Param name="include-urls">.*</Param>  
  8.       <Param name="exclude-urls"></Param>  
  9.     </Optional>  
  10.   </ModulePrefs>  
  11.   <Content type="html" view="canvas,profile,view">  
  12.   <![CDATA[ 
  13.     <div id="content_div" style="height: 100px;"></div> 
  14.     <script type="text/javascript"> 
  15.     </script> 
  16. どうかな, 
  17. どうかな, 
  18. どうかな 
  19.     <img src="http://www.google.co.jp/intl/ja_jp/images/logo.gif" alt="googleだよ" /> 
  20.   ]]>  
  21.   </Content>  
  22. </Module>  

imgタグはちゃんとproxy経由になった。
キャッシュも効いている模様。

さて、http://wiki.opensocial.org/index.php?title=Content_Rewriter_Feature

を見ると、
  1. <Param name="include-urls">.*</Param>  
  2. <Param name="exclude-urls"></Param>  

のところは、
  1. <Param name="include-url">.*</Param>  
  2. <Param name="exclude-url"></Param>  

と's'なしで指定すべきっぽいが、shindig-1.1-SNAPSHOTでは
's'ありで指定しなきゃ動かないっぽい。

あとexclude-urlsは空で定義してあるけど、
shindig.propertiesでexclude-urlsを指定してある場合には、
Optional featuresでは空で指定してあげないと、
shindig.propertiesの方のexclude-urlsが優先される。



おしまい。
.

0 コメント: