Kohei Nozaki's blog 

Entries tagged [roller]

Java EE ブログエンジン Apache Roller のご紹介


Posted on Thursday Dec 03, 2015 at 08:00AM in Technology


このエントリは Java EE Advent Calendar 2015 の3日目(12月3日)の記事です.

自己紹介

業務ではJPA, JAX-RSなどを使っているソフトウェアエンジニアです.趣味ではWildFly, JBatch, JSFなどを使っていろいろ作ったり,Java/Java EE関連OSSの不具合を見つけてパッチやPull Requestを送ったりしています.

今回紹介する Apache Roller のコミッタをやっているのですが,日本ではあまり知名度がないので,少しでも日本の方に興味を持ってもらえればと思い,紹介記事を書くことにしました.

Apache Rollerとは?

Apache Rollerは,Javaサーブレットコンテナ向けのオープンソースブログエンジンで,WordPressやMovable Typeとほぼ同じジャンルのソフトウェアです.元Sun Microsystemsのエンジニア David M. Johnsonさんによって2002年に作られ,blogs.sun.com(現 blogs.oracle.com )などで利用されてきました.

現在の最新バーションは,2015年3月にリリースされた5.1.2です.

誰が使っているの?

Rollerはさまざまな組織や個人によって使われています.組織での使用例としては,Javaエンジニアにはおなじみの Oracle blogs や, IBM developerworks blogApache Foundationのブログなどがあります.他にも世界中のさまざまな企業,官公庁などで使われています.

個人では,Java EEを追っかけている人にはおなじみの Adam Bienさん ,Javaの父 James Goslingさんなどが,Rollerを使ってブログを書いています. コミッタもそれぞれ自分でRollerのブログを持っています.

その他多数のユーザについては オフィシャルのWikiページにまとめられています.

使われている技術

DIコンテナとしてはGuiceが使われていて,パーシステンス層ではEclipseLink,ビュー・コントローラ層はStruts2 + JSP + Servlet,ブログのデザインなどはVelocityテンプレートで書けるようになっています.認証まわりではSpring Security,全文検索エンジンとしてはLuceneが使われています.

ServletとJSPのコードが多く,今となってはちょっと時代遅れな感は否めませんが,ソースは全て公開されているので,Javaで書かれていてリアルに運用されているWebシステムのサンプルとして一つの参考になるかもしれません.

特徴

マルチユーザー・マルチブログに対応

1つのインストレーションで複数のブログ,ユーザを作ることができます.

各ユーザーには3種類の権限のうちいずれかを割り当てることができ,具体的には,エントリの下書きだけができるユーザ(Limited),エントリの投稿などはできるがブログやシステムの設定変更はできないユーザ(Author),全ての操作ができるユーザ(Admin)のうちいずれかをユーザごとに割り当てることができます.組織用ブログなどで,日常的にレビュープロセスを取り入れているようなケースで便利に使うことができます. LDAP認証に対応しているのも組織で使いやすいポイントです.

個人で使う場合でも,複数のブログをかんたんに作れるので,たとえば技術系エントリはこのブログ,趣味の旅行の話題はまた別のブログ,といった感じで使い分けることができます.もちろん,それぞれのブログのデザインやテンプレートはべつべつに管理できます.

さまざまなDB・アプリケーションサーバに対応

DBスキーマ生成用スクリプトとして,MySQL,PostgreSQL,Oracle,DB2,SQL Server,Derby,HSQLDB用のものが用意されています.ほとんどのユーザおよび開発メンバが使っているのはMySQLなので,特に理由がなければMySQL 5.6.x以降をおすすめします(次のリリースからは5.6.xより前のサポートがなくなる予定なので).個人的にはPostgreSQLを使っていて,このブログもPostgreSQLで動いています.

いわゆるサーブレットコンテナ向けに作られているので,TomcatやJettyをはじめ,JBoss(WildFly),GlassFishなどのJava EEコンテナにもデプロイできます.ほとんどのユーザはTomcatを使っているようですが,個人的にはWildFly(このブログ)やJBoss EWSにデプロイして使っています.

Javaでプラグインが書ける

最近のブログサービスでは,冗長なHTMLだけではなくMarkdownや「はてな記法」のような簡潔なシンタックスを使ってエントリを書けるものが多くでてきています.Rollerがデフォルトでサポートしているのは標準的なHTMLだけですが,プラグインを使うことで,そういったシンタックスを使ってブログエントリを書けるようになります.

個人的には, Asciidoctorjプラグインというものを作り AsciiDoc シンタックスを使って日常的にエントリを書いています(このエントリもそうです).他にも MarkdownJSPWiki プラグインなど,いくつかのプラグインが公開されており,別途インストールすることで利用できるようになります.

プラグインを書くのはとても簡単で,適用するプラグインはエントリごとにべつべつに設定できます.今後またなんらかの新たな記法が登場してそれを使いたくなったら,HTMLへの変換エンジンとRollerをつなぐ部分だけをプラグインとして書いてやれば,既存のエントリはそのままに新しい記法を使うことができるようになります.ブログエントリの記法の他にも,コメントの記法,コメント認証などもプラグインとして独自に追加することができるようになっています.

インストール

いわゆるオンプレミス環境へのインストール方法については,英語になりますが Wiki および オフィシャルのインストレーションガイド を参照してください.また OpenShift で運用することもできます(無料枠でも可能).詳細は,こちらも英語になりますが, このブログエントリを参照してください.

メンテナンスなど

まずバックアップですが,個人的にはPostgreSQLデータベースとRollerのデータファイル用ディレクトリをssh経由でバックアップするためのAntスクリプトを書いて,定期的にcronで実行しています.スクリプトは GitHubで公開しています.

他のブログエンジンからのデータ移行については,残念ながら確立されたやり方はまだ存在していませんが,WordPressのブログエクスポート形式であるWXR形式のファイルを取り込むためのツールを作っています.詳細は こちらをご確認ください.

また,SVNからのソース取得,ビルド,プラグインのインストール,自家製パッチ適用などを自動化するためのAntスクリプトを GitHub に置いてあります.

その他,運用ノウハウなどは このブログエントリ によくまとまっています.

最後に

日本語情報は少なめですが,最新リリースでは,実用上は日本語依存の問題というのは特にありません.

ただ,日本語ブログで使うと表示上の違和感があるところがいくつかあったり,メッセージの誤訳や不足,モバイル用テーマ・一部の利用者が少ないDBでのみ生じる細かいバグが残っています(詳細は JIRA を参照).SVN上の最新版では,そのうちのいくつかは修正ずみですので,可能な方はぜひ 開発中の最新版のソース をSVNからチェックアウトしてビルドしてみてください.mvn clean package でWARファイルが生成されます. 前述のAntスクリプト も併用されると便利かもしれません.

バグレポート・パッチはもちろん大歓迎です.なにか日本語まわりで質問などあれば,このエントリにコメントをつけていただいても結構です.Javaエンジニアで,自分のブログを持ちたいとお考えの方,ぜひRollerを試してみてください!

リファレンスなど

宣伝:求人のご案内

現在,私の勤務先 株式会社 L is B ではエンジニア・デザイナーを募集しています.主に direct というインスタントメッセージングサービスの開発と運用を行っている会社です.

会社所在地は東京(+徳島県に開発拠点があります)ですが,一部リモートワークも認められています.少しでも興味を持たれた方,ぜひ応募してみてください!


Disabling Roller cache for development


Posted on Friday Feb 27, 2015 at 09:43PM in Roller


When I playing with Roller source code, Roller’s caching mechanism is not comfortable because my changes are not affected until I redeploy entire application. it destroys benefit of using JRebel. so I disabled Roller’s caching mechanism with following definition in roller.properties. it would work with roller-custom.properties too.

cache.sitewide.enabled=false
cache.weblogpage.enabled=false
cache.weblogfeed.enabled=false
cache.planet.enabled=false
cache.salt.enabled=false

Also you need to disable 2nd level cache of EclipseLink. put following definition to persistence.xml.

<property name="eclipselink.cache.shared.default" value="false"/>

<shared-cache-mode>NONE</shared-cache-mode>

Velocity cache too. configuration is available at /app/src/main/webapp/WEB-INF/velocity.properties:

theme.resource.loader.cache=false
roller.resource.loader.cache=false
class.resource.loader.cache=false
webapp.resource.loader.cache=false

Container’s JSP cache too. for WildFly see /roller/kyle/entry/exploded-deployment-for-wildfly-on


Importing entries into Roller


Posted on Thursday Feb 19, 2015 at 11:54AM in Technology


Recently I migrated old articles that wrote within hand made blog (?) engine to Roller. there’s a useful Groovy script that placed in source distribution of Roller. I referenced that script and created a standalone Java program which imports entries that saved as RSS 2.0 XML. the program is intended to use with WordPress WXR file but I’ve never used it with real WXR file which WordPress produced because I don’t have any WordPress instances for my own. I used it for a XML file which produced by Rome and before import I added some tweak by hand.

I think it’s harder to use without any modification but it may be helpful for someone wants to import entries with API for Roller, so I pushed the program into GitHub.


Customizing Roller's Gaurav theme


Posted on Tuesday Feb 03, 2015 at 04:37PM in Technology


I started using Gaurav theme which is HTML5/CSS3 enabled responsive theme, introduced with Apache Roller 5.1. it enables us to use same HTML template for various browsing environment such as smartphones, tables and PC. it changes its layout to suit these different displays automatically. and I added some customization as my prefer.

For smartphones and tablets

I added following definition to the template standard_head to use of appropriate viewport and font size.

<meta name="viewport" content="width=device-width"/>

Also added some to style sheet:

/* to prevent narrower displaying in iPhone */
div.entryContent code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

div.entryContent a {
    word-wrap: break-word;
}

Add tweet button and Twitter widget

Add following snippet to standard_head template.

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

Add following snippet to _day template. I put it just after the title of an entry. don’t forget to put your account into data-via attribute.

<a href="https://twitter.com/share" class="twitter-share-button" data-url="$url.entry($entry.anchor)" data-text="$entry.title" data-via="[YOUR TWITTER ACCOUNT HERE]">Tweet</a>

I also added Timeline widget which can be created in Twitter website (user configuration page) to Weblog template.

Add Google Adsense

I added responsive units into standard_header, standard_footer and Weblog templates.

Recent entries

I added recent 20 entries listing to Weblog template as follows:

<div class="well">
	<h3>Recent entries</h3>
	#set($recent = $model.weblog.getRecentWeblogEntries(nil, 20))
	<ul>#foreach($recentEntry in $recent)
		  <li class="entryLink"><a href="$recentEntry.permalink">$recentEntry.title</a></li>
	#end</ul>
</div>

Recent comments

I added recent 10 comments listing to Weblog template as follows:

<div class="well">
	<h3>Recent comments</h3>
	#set($recent = $model.weblog.getRecentComments(10))
	<ul>#foreach($recentComment in $recent)
		  <li class="entryLink">
		  #if($utils.isNotEmpty($recentComment.url))
		  	<a href="$recentComment.url">$recentComment.name</a>
		  #else
		  	$recentComment.name
		  #end
		  on
		  <a href="$recentComment.weblogEntry.permalink">$recentComment.weblogEntry.title</a>
		  </li>
	#end</ul>
</div>

Calendar

Added following snippet in Weblog template to show Calendar:

<div class="well">
<h3>Archives</h3>
#showWeblogEntryCalendar($model.weblog "nil")
</div>

Also tweak its style:

table.hCalendarTable {
	width: 100%;
}

Using Web Font

I like to use Oswald font to headings so I added following to standard_head template.

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Oswald"/>

Also added following to stylesheet:

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    font-family: Oswald,Helvetica,Arial,sans-serif !important;
}

Tweak other fonts

Added following to style sheet:

body {
	font-family: Georgia, Palatino, Verdana, Libertine, 'Palatino Linotype', 'Book Antiqua', 'Times New Roman', serif;
}

div.entryContent pre, div.entryContent code {
	font-family: Menlo,Inconsolata,Consolas,'Ubuntu Mono',monospace;
}

div.entryContent pre {
	font-size: 85%;
}

Minor tweaks

I added following element to inside head element of a template named TagsIndex which is missing custom.css.

<link rel="stylesheet" href='$url.page("custom.css")' />

Removed following element from _day template because I’m the only person who is writing the blog.

<p class="lead">by <span style="text-transform: capitalize;">$entry.creator.screenName</span></p>

About jquery.min.map

In some environments jQuery requests a file named jquery.min.map and Roller returns 404. someone said that it makes debug of jQuery easier. I think there’s no side effect for regular use but following procedure would resolve the issue. note that you have to do this before copying initial template.

  1. Download http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.map

  2. Put jquery.min.map to $ROLLER_HOME/themes/gaurav/js

  3. Put <resource path="js/jquery.min.map"/> to theme.xml

  4. Reload roller

  5. Change the theme of your weblog to custom theme using Gaurav


Automating backup of Roller


Posted on Sunday Feb 01, 2015 at 11:17AM in Technology


I wrote an another Ant script to backup Apache Roller database and data directory. intended to use for PostgreSQL and Linux server. see my GitHub repository for more information.

At first I implemented it with sshexec task and used its output attribute to download the backup stream to local file but the file was corrupted. unfortunately sshexec task uses ByteArrayOutputStream to collect the output stream, then converts the byte array to String as far as I found out. I think it’s not preferable and it can be simply redirected to local file stream. so I changed implementation to that dump the data as a temporary file on remote server, then download it with scp task. I know it’s inefficient and consumes free space the same as the data. implementing redirection of the streams to sshexec task or changing the script to use ssh command directly would be a solution.