2010年6月30日水曜日

groovyとJCIFSでWindows共有上のファイルを読み取り専用に設定する

groovyとJCIFSでWindows共有上のファイルを読み取り専用に設定するには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file = "test1.txt"

file = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file}"
)

// windows共有上のファイルを読み取り専用に設定する
file.setReadOnly()


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartPreparation,
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("test88.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test88.pptx)
ScriptomとPower Pointで描画したフロチャートの準備形

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

2010年6月29日火曜日

groovyとJCIFSでWindows共有上のファイルの最終更新日時を設定する

groovyとJCIFSでWindows共有上のファイルの最終更新日時を設定するには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file = "test1.txt"

file = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file}"
)

// windows共有上のファイルの最終更新日時を設定する
file.setLastModified(
new GregorianCalendar(2010, 5-1, 5, 11, 22, 33).timeInMillis
)


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

groovyとVI Java APIで仮想マシンのCPU数とメモリを一覧表示する

groovyとVI Java APIで仮想マシンのCPU数とメモリを一覧表示するには、以下のコードを実行します。

import com.vmware.vim25.*
import com.vmware.vim25.mo.*

// VMWare ESXiに接続
host = "https://192.168.1.161/sdk"
user = "root"
password = "password"
si = new ServiceInstance(new URL(host), user, password, true)
rf = si.getRootFolder()

// 仮想マシンのCPU数とメモリを一覧表示
sc = [["VirtualMachine", "name"]] as String[][]
vms = new InventoryNavigator(rf).searchManagedEntities(sc, true)
for( vm in vms ){
println "${vm.name}:CPU数=${vm.config?.hardware?.numCPU}:" +
"メモリ=${vm.config?.hardware?.memoryMB}(MB)"
}
si.getServerConnection().logout()


動作環境
groovy 1.7.1, JDK6 Update19, VMware VI (vSphere) Java API vijava2u120091204,
VMWare ESXi 4.0 Update1

関連情報
groovyとVI Java APIのまとめ
VMware VI (vSphere) Java APIのホームページ
http://vijava.sourceforge.net/

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.msoShapeFlowchartPredefinedProcess,
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("test87.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test87.pptx)
ScriptomとPower Pointで描画したフロチャートの定義済み処理形

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

2010年6月28日月曜日

groovyとJCIFSでWindows共有上のファイルの作成日時を設定する

groovyとJCIFSでWindows共有上のファイルの作成日時を設定するには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file = "test1.txt"

file = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file}"
)

// windows共有上のファイルの作成日時を設定する
file.setCreateTime(
new GregorianCalendar(2010, 5-1, 5, 0, 10, 30).timeInMillis
)


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartOr,
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("test86.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test86.pptx)
ScriptomとPower Pointで描画したフロチャートの論理和形

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

2010年6月27日日曜日

groovyとJCIFSでWindows共有上のファイルをリネームする

groovyとJCIFSでWindows共有上のファイルをリネームするには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file1 = "test.txt"
file2 = "テスト.txt"

oldfile = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file1}"
)
newfile = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file2}"
)

// windows共有上のファイルのリネーム
oldfile.renameTo(newfile)


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartOffpageConnector,
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("test85.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test85.pptx)
ScriptomとPower Pointで描画したフロチャートの他ページ接続子形

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

2010年6月26日土曜日

groovyとJCIFSでWindows共有上にディレクトリを作成する

groovyとJCIFSでWindows共有上にディレクトリを作成するには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir/newdir1/newdir2"

dir = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}"
)

// windows共有上にディレクトリを作成する
dir.mkdirs()


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartMultidocument,
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("test84.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test84.pptx)
ScriptomとPower Pointで描画したフロチャートの複数書類形

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

2010年6月25日金曜日

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 id
@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
}

// フォルダカテゴリ
public class FolderCategory
{
@Key("@scheme")
String scheme = "http://schemas.google.com/g/2005#kind"
@Key("@term")
String term = "http://schemas.google.com/docs/2007#folder"
}

// エントリ
public class FolderEntry
{
@Key
FolderCategory category = new FolderCategory()
@Key
String title
}


// 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)

// フォルダ検索リクエスト
query = "テストフォルダ"
requrl = "https://docs.google.com/feeds/default/private/full/-/folder?title-exact=true&title=${URLEncoder.encode(query, "UTF-8")}"
while(requrl != null){
request = transport.buildGetRequest()
request.url = requrl
feed = request.execute().parseAs(Feed.class)

for(item in feed.entry){
// サブフォルダの作成
entry = new FolderEntry()
entry.title = "サブフォルダの作成テスト"
request = transport.buildPostRequest()
request.url = "https://docs.google.com/feeds/default/private/full/" +
"${item.id.substring(item.id.indexOf("folder%3A"))}/contents"
content = new AtomContent()
content.entry = entry
content.namespaceDictionary = GoogleDocumentsListAtom.NAMESPACE_DICTIONARY
request.content = content;
request.execute().parseAsString()
}

// 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とJCIFSでWindows共有上のファイルが隠しファイルかどうか調べる

groovyとJCIFSでWindows共有上のファイルが隠しファイルかどうか調べるには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file = "test2.txt"

file = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file}"
)

// windows共有上のファイルが隠しファイルか調べる
println file.isHidden()


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartMerge,
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("test83.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test83.pptx)
ScriptomとPower Pointで描画したフロチャートの組み合わせ形

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

2010年6月24日木曜日

groovyとJCIFSでWindows共有上のパスがファイルかどうか調べる

groovyとJCIFSでWindows共有上のパスがファイルかどうか調べるには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir"
file = "test1.txt"

file = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}/${file}"
)

// windows共有のパスがファイルかどうか調べる
println file.isFile()


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

groovyとVI Java APIで仮想マシンのCPU/MMU仮想化設定を一覧表示する

groovyとVI Java APIで仮想マシンのCPU/MMU仮想化設定を一覧表示するには、以下のコードを実行します。

import com.vmware.vim25.*
import com.vmware.vim25.mo.*

// VMWare ESXiに接続
host = "https://192.168.1.161/sdk"
user = "root"
password = "password"
si = new ServiceInstance(new URL(host), user, password, true)
rf = si.getRootFolder()

// 仮想マシンのCPU/MMU仮想化設定を一覧表示
sc = [["VirtualMachine", "name"]] as String[][]
vms = new InventoryNavigator(rf).searchManagedEntities(sc, true)
for( vm in vms ){
println "${vm.name}:${vm.config?.flags?.virtualMmuUsage}"
}
si.getServerConnection().logout()


動作環境
groovy 1.7.1, JDK6 Update19, VMware VI (vSphere) Java API vijava2u120091204,
VMWare ESXi 4.0 Update1

関連情報
groovyとVI Java APIのまとめ
VMware VI (vSphere) Java APIのホームページ
http://vijava.sourceforge.net/

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.msoShapeFlowchartManualOperation,
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("test82.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test82.pptx)
ScriptomとPower Pointで描画したフロチャートの手作業形

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

2010年6月23日水曜日

groovyとjOpenDocumentでOpen Office Calcのシートをコピーする

groovyとjOpenDocumentでOpen Office Calcのシートをコピーするには、以下のコードを実行します。

import org.jopendocument.dom.spreadsheet.*

sheets = SpreadSheet.createFromFile(new File("sample1.ods"))
// シートを4番目にコピー
sheets.getSheet(0).copy(3, "複製")
sheets.saveAs(new File("sample4.ods"))


元ファイル(sample1.ods)


出力ファイル(sample4.ods)


動作環境
groovy 1.7.2, JDK6 Update20, jOpenDocument-1.2b3, OpenOffice 3.2

関連情報
jOpenDocumentのホームページ
http://www.jopendocument.org/

groovyとJCIFSでWindows共有上のパスがディレクトリかどうか調べる

groovyとJCIFSでWindows共有上のパスがディレクトリかどうか調べるには、以下のコードを実行します。

import jcifs.smb.*

domain = "workgroup"
user = "testuser"
password = "password"
server = "win01"
path = "sharedir/testdir"

dir = new SmbFile(
"smb://${domain};${user}:${password}@${server}/${path}"
)

// windows共有のパスがディレクトリかどうか調べる
println dir.isDirectory()


動作環境
groovy 1.7.1, JDK6 Update19, JCIFS 1.3.14

関連情報
JCIFSまとめ

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.msoShapeFlowchartManualInput,
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("test81.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


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


出力プレゼンテーション(test81.pptx)
ScriptomとPower Pointで描画したフロチャートの手操作入力形

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