2010年6月9日水曜日

groovyとGanymed SSH-2/Orion SSH2を使用してSFTPでシンボリックリンクを作成する

groovyとGanymed SSH-2/Orion SSH2を使用してSFTPでシンボリックリンクを作成するには、以下のコードを実行します。

// Ganymed SSH-2の場合
// (http://www.cleondris.ch/opensource/ssh2/)
//import ch.ethz.ssh2.*
// Orion SSH2の場合
// (http://sourceforge.net/apps/mediawiki/orion-ssh2/index.php?title=Main_Page)
import com.trilead.ssh2.*

host = "192.168.1.100"
username = "user"
password = "password"

// サーバに接続
conn = new Connection(host)
conn.connect()
if( !conn.authenticateWithPassword(username, password) ){
throw new Exception("authentication failed.")
}

// SFTP client作成
sftpc = new SFTPv3Client(conn)
sftpc.setCharset("UTF-8")

// シンボリックリンクを作成
sftpc.createSymlink("symlink.jpg", "SF.JPG")

sftpc.close()
conn.close()


動作環境
groovy 1.7.1, JDK6 Update19, ganymed-ssh2-build250, orion-ssh2-214rc1
○関連項目

2010年6月8日火曜日

ScriptomとPower Pointで爆発パターン2を描画する

ScriptomとPower Pointで爆発パターン2を描画するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
// 爆発パターン2を描画する
slide = ppa.Presentations(1).slides(1)
shape = slide.Shapes.AddShape(
MsoAutoShapeType.msoShapeExplosion2,
100/* =left */, 100/* =top*/, 200/* =width*/, 200/* height */)

// 線の色
shape.Line.ForeColor.RGB = 0xffffff /* BGR*/
// 塗りつぶし色
shape.Fill.ForeColor.RGB = 0xffddbb /* BGR*/

ppa.Presentations(1).saveAs(new File("test67.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test67.pptx)
ScriptomとPower Pointで描画した爆発パターン2

動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007

groovyとgdata-java-clientでGoogle Documentsの文書を一覧表示する

groovyとgdata-java-clientでGoogle Documentsの文書を一覧表示するには、以下のコードを実行します。

import com.google.api.client.googleapis.*
import com.google.api.client.googleapis.auth.clientlogin.*
import com.google.api.data.docs.v3.*
import com.google.api.data.docs.v3.atom.*
import com.google.api.client.xml.atom.*
import com.google.api.client.util.*

// エントリ
public class Entry
{
@Key
String title
}

// リンク
public class Link
{
@Key("@rel")
String rel
@Key("@type")
String type
@Key("@href")
String href
}

// フィード
public class Feed
{
@Key
String title
@Key
List<Link> link
@Key
List<Entry> entry
}

// Parser設定
GoogleTransport transport = new GoogleTransport()
transport.applicationName = "yourcorp-yourapp-1.0"
transport.setVersionHeader(GoogleDocumentsList.VERSION)
ap = new AtomParser()
ap.namespaceDictionary = GoogleDocumentsListAtom.NAMESPACE_DICTIONARY
transport.addParser(ap)

username = "youraccount@gmail.com"
password = 'yourpassword'

// 認証
cl = new ClientLogin()
cl.authTokenType = GoogleDocumentsList.AUTH_TOKEN_TYPE
cl.username = username
cl.password = password
cl.authenticate().setAuthorizationHeader(transport)

// 検索リクエスト
requrl = "https://docs.google.com/feeds/default/private/full"
while(requrl != null){
request = transport.buildGetRequest()
request.url = requrl
feed = request.execute().parseAs(Feed.class)
println "feed title:" + feed.title
for(item in feed.entry){
println " title:${item.title}"
}
// 100個以上の文書の場合
requrl = null
for(link in feed.link){
if( link.rel == "next" ){
requrl = link.href
}
}
}


動作環境
groovy 1.7.2, JDK6 Update20, gdata-java-2.2.1-alpha

関連情報
gdata-java-client
http://code.google.com/p/gdata-java-client/

groovyとGanymed SSH-2/Orion SSH2を使用してSFTPでファイルをダウンロードする

groovyとGanymed SSH-2/Orion SSH2を使用してSFTPでファイルをダウンロードするには、以下のコードを実行します。

// Ganymed SSH-2の場合
// (http://www.cleondris.ch/opensource/ssh2/)
//import ch.ethz.ssh2.*
// Orion SSH2の場合
// (http://sourceforge.net/apps/mediawiki/orion-ssh2/index.php?title=Main_Page)
import com.trilead.ssh2.*

host = "192.168.1.100"
username = "user"
password = "password"

// サーバに接続
conn = new Connection(host)
conn.connect()
if( !conn.authenticateWithPassword(username, password) ){
throw new Exception("authentication failed.")
}

// SFTP client作成
sftpc = new SFTPv3Client(conn)
sftpc.setCharset("UTF-8")

// ファイルをダウンロード
fh = sftpc.openFileRO("SF.JPG")
bos = new BufferedOutputStream(new FileOutputStream("download.JPG"))
buf = new byte[1024]
long fo = 0
while((sz = sftpc.read(fh, fo, buf, 0, 1024)) != -1){
bos.write(buf, 0, sz)
fo += sz
}
sftpc.closeFile(fh)
bos.flush()
bos.close()

sftpc.close()
conn.close()


動作環境
groovy 1.7.1, JDK6 Update19, ganymed-ssh2-build250, orion-ssh2-214rc1
○関連項目

2010年6月7日月曜日

ScriptomとPower Pointで爆発パターン1を描画する

ScriptomとPower Pointで爆発パターン1を描画するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
// 爆発パターン1を描画する
slide = ppa.Presentations(1).slides(1)
shape = slide.Shapes.AddShape(
MsoAutoShapeType.msoShapeExplosion1,
100/* =left */, 100/* =top*/, 200/* =width*/, 200/* height */)

// 線の色
shape.Line.ForeColor.RGB = 0xffffff /* BGR*/
// 塗りつぶし色
shape.Fill.ForeColor.RGB = 0xffddbb /* BGR*/

ppa.Presentations(1).saveAs(new File("test66.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test66.pptx)
ScriptomとPower Pointで描画した爆発パターン1

動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007

groovyとApache Commons VFSでHTTPファイルシステム上のファイルを表示する

groovyとApache Commons VFSでHTTPファイルシステム上のファイルを表示するには、以下のコードを実行します。

import org.apache.commons.vfs.*

fsm = VFS.getManager()

// HTTP file systemのファイル(apache common httpclient 3.1が必要)
file = fsm.resolveFile("http://groovy.codehaus.org/")
br = new BufferedReader(new InputStreamReader(
file.getContent().getInputStream()))
while((line = br.readLine()) != null){
println line
}

動作環境
groovy 1.7.1, JDK6 Update19, apache commons vfs 1.0, apache commons logging 1.1.1

2010年6月6日日曜日

ScriptomとPower Pointで下方向に向いた矢印がついた吹き出しを描画する

ScriptomとPower Pointで下方向に向いた矢印がついた吹き出しを描画するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
// 下方向に向いた矢印がついた吹き出しを描画する
slide = ppa.Presentations(1).slides(1)
shape = slide.Shapes.AddShape(
MsoAutoShapeType.msoShapeDownArrowCallout,
100/* =left */, 100/* =top*/, 200/* =width*/, 200/* height */)

// 線の色
shape.Line.ForeColor.RGB = 0xffffff /* BGR*/
// 塗りつぶし色
shape.Fill.ForeColor.RGB = 0xffddbb /* BGR*/

ppa.Presentations(1).saveAs(new File("test65.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test65.pptx)
ScriptomとPower Pointで描画した下方向に向いた矢印がついた吹き出し

動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007