- 追加された行はこの色です。
- 削除された行はこの色です。
#topicpath
----
//ここにコンテンツを記述します。
#contents
まずはGUIに関係ない、Coreな部分を作ります。Eclipseプラグイン開発では、GUI部分とCoreな部分に分けて設計するのが基本みたいですね。とりあえず、それに則ってみます。
開発時、実行時に必要なクラスは
-Apache Axis
-Log4j
-Google Web APIs のクラスライブラリ
です。Apache AxisはWSDLからクラスを生成したり、ランタイム時に使用されたりします。Log4jはログ制御をLog4jで行っているため必要です。Google Web APIs はWSDLファイルとAxisより自動生成されるクラスライブラリ群です。
*** plugin.xml [#i90829c2]
このプラグインのplugin.xmlはこんな感じです。
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
id="nu.mine.kino.plugin.google.core"
name="%pluginName"
version="0.1.1"
provider-name="%providerName"
class="nu.mine.kino.plugin.google.core.GoogleCorePlugin">
<runtime>
<library name="core.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="nu.mine.kino.axis"/>
<import plugin="nu.mine.kino.log4j"/>
</requires>
</plugin>
*** nu.mine.kino.axis [#f30a7d19]
このプラグインはApache Axisのライブラリを利用するためにプラグインにしておきました。ソース自体は[[こちらのCVS:http://kino.mine.nu/cgi-bin/viewvc.cgi/nu.mine.kino.axis/]]を見てみて下さい。使うときはApache Axisのランタイムライブラリをlibディレクトリに置いておきます。
*** nu.mine.kino.log4j [#v70d9c23]
このプラグインはLog4jのライブラリを利用するためにプラグインにしておきました。ソース自体は[[こちらのCVS:http://kino.mine.nu/cgi-bin/viewcvs.cgi/nu.mine.kino.log4j/]]を見てみて下さい。あとはLog4jの設定ファイルを指定する程度の機能をつけてあります。
このプラグインはLog4jのライブラリを利用するためにプラグインにしておきました。ソース自体は[[こちらのCVS:http://kino.mine.nu/cgi-bin/viewvc.cgi/nu.mine.kino.log4j/]]を見てみて下さい。あとはLog4jの設定ファイルを指定する程度の機能をつけてあります。
***プラグインクラス [[nu.mine.kino.plugin.google.core.GoogleCorePlugin:http://kino.mine.nu/cgi-bin/viewcvs.cgi/nu.mine.kino.plugin.google.core/source/nu/mine/kino/plugin/google/core/GoogleCorePlugin.java]] [#mf52116b]
***プラグインクラス [[nu.mine.kino.plugin.google.core.GoogleCorePlugin:http://kino.mine.nu/cgi-bin/viewvc.cgi/nu.mine.kino.plugin.google.core/source/nu/mine/kino/plugin/google/core/GoogleCorePlugin.java]] [#mf52116b]
次にプラグインクラスにビジネスロジックを記述していきます。必要なメソッドは
-Google検索するメソッド search
-Googleでスペルチェックするメソッド getSplellingSuggestion
などです。必要な箇所だけ抜粋しておきます。
package nu.mine.kino.plugin.google.core;
/**
* Google検索を行うプラグインです。
*
* @author Masatomi KINO
* @version $Revision$
*/
public class GoogleCorePlugin extends Plugin {
// いろいろ省略
private GoogleSearchPort googleSearch;
/**
* プラグインの活性化時に呼ばれます。
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
logger.debug("start(BundleContext) - start");
super.start(context);
try {
GoogleSearchServiceLocator locator = new GoogleSearchServiceLocator();
googleSearch = locator.getGoogleSearchPort();
} catch (ServiceException e) {
logger.error(e);
log(e);
}
logger.debug("start(BundleContext) - end");
}
/**
* 引数の文字列でGoogle検索を行います。エラーが発生した場合
* nullが返るか、例外を投げます。
*
* @param myGoogleKey Googleのキー
* @param searchText 検索文字列
* @return GoogleSearchResult
* @throws CoreException 何らかのエラーが発生したとき。
*/
public GoogleSearchResult search(String myGoogleKey, String searchText)
throws CoreException {
logger.debug("search(String) - start");
GoogleSearchResult result = null;
if (googleSearch != null) {
try {
result = googleSearch.doGoogleSearch(myGoogleKey, searchText,
1, 10, false, "", false, "lang_ja", "", "");
} catch (RemoteException e) {
logger.error(e);
log(e);
IStatus status = new Status(IStatus.ERROR, getPluginId(),
IStatus.ERROR, e.toString(), e);
throw new CoreException(status);
}
}
logger.debug("search(String) - end");
return result;
}
/**
* 引数の文字列にスペルミスがないかをチェックするメソッドです。
* スペルミスがある場合、候補を返します。スペルミスがない場合、nullが返ります。
*
* @param myGoogleKey
* @param text
* @return
*/
public String getSplellingSuggestion(String myGoogleKey, String text) {
logger.debug("getSplellingSuggestion(String, String) - start");
String suggestionText = null;
try {
suggestionText = googleSearch.doSpellingSuggestion(myGoogleKey,
text);
} catch (Exception e) {
// 文字によっては例外が発生するので、その場合は
// とりあえず候補がなかったことにして通り過ぎちゃう
logger.warn(e);
logger.warn("スペルミス補正でエラーが発生しました。");
}
logger.debug("getSplellingSuggestion(String, String) - end");
return suggestionText;
}
}
Coreについてはとりあえず、こんなもんでしょうか。
つぎは -[[UI部のロジック>Eclipse/プラグイン開発のTIPS集/GooglePlugin/UI部のロジックをつくる]] を作成します。
----
この記事は
#vote(おもしろかった[1],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}