OSDN Git Service

ver 2.23 init
authorhayashi <yuu.hayashi@deister.jp>
Fri, 4 Feb 2011 11:01:44 +0000 (20:01 +0900)
committerhayashi <yuu.hayashi@deister.jp>
Fri, 4 Feb 2011 11:01:44 +0000 (20:01 +0900)
84 files changed:
ClipbordTest.bat [new file with mode: 0644]
MemoryCheck.bat [new file with mode: 0644]
README.txt [new file with mode: 0644]
YuuMailXml.sh [new file with mode: 0644]
build.properties [new file with mode: 0644]
build.xml [new file with mode: 0644]
config/Xalan.xml [new file with mode: 0644]
config/hayashi.properties [new file with mode: 0644]
config/property.xml [new file with mode: 0644]
config/sendMail.xml [new file with mode: 0644]
config/sendmail.properties [new file with mode: 0644]
config/yuumail.properties [new file with mode: 0644]
deleteold.bat [new file with mode: 0644]
lib/activation-1.1.jar [new file with mode: 0644]
lib/junit.jar [new file with mode: 0644]
lib/mail-1.4.jar [new file with mode: 0644]
lib/servlet-api.jar [new file with mode: 0644]
lib/xercesImpl.jar [new file with mode: 0644]
manager.bat [new file with mode: 0644]
samplelog.bat [new file with mode: 0644]
sendmail.bat [new file with mode: 0644]
src/hayashi/yuu/tools/gui/QuitDialog.java [new file with mode: 0644]
src/hayashi/yuu/tools/logger/LoggerFactory.java [new file with mode: 0644]
src/hayashi/yuu/tools/logger/YuuLogFormatter.java [new file with mode: 0644]
src/hayashi/yuu/tools/logger/package.html [new file with mode: 0644]
src/hayashi/yuu/tools/mail/SendMail.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/SiteData.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/James.png [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/MailAddrPanel.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/SendMailGUI.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/SettingDialog.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/SetupMailServer.java [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/gmail.png [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/package.html [new file with mode: 0644]
src/hayashi/yuu/tools/mail/gui/so-net.png [new file with mode: 0644]
src/hayashi/yuu/tools/mail/package.html [new file with mode: 0644]
src/hayashi/yuu/tools/properties/CategoryBox.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/Encrypt.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/Properties.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/PropertyCheckItem.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/PropertyFieldItem.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/PropertyItem.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/PropertyPasswordItem.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/PropertySelectItem.java [new file with mode: 0644]
src/hayashi/yuu/tools/properties/package.html [new file with mode: 0644]
src/jp/co/areaweb/tools/command/Command.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/DeleteOldFile.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/DirSize.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/JSendmail.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/Job.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/NewFileList.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/ReadXML.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/Xalan.java [new file with mode: 0644]
src/jp/co/areaweb/tools/command/XmlJob.java [new file with mode: 0644]
src/jp/co/areaweb/tools/core/JapaneseString.java [new file with mode: 0644]
src/jp/co/areaweb/tools/core/MakeString.java [new file with mode: 0644]
src/jp/co/areaweb/tools/core/MemoryCheck.java [new file with mode: 0644]
src/jp/co/areaweb/tools/core/Tax.java [new file with mode: 0644]
src/jp/co/areaweb/tools/csv/CsvFile.java [new file with mode: 0644]
src/jp/co/areaweb/tools/csv/CsvReader.java [new file with mode: 0644]
src/jp/co/areaweb/tools/csv/CsvRecord.java [new file with mode: 0644]
src/jp/co/areaweb/tools/csv/package.html [new file with mode: 0644]
src/jp/co/areaweb/tools/database/DatabaseTool.java [new file with mode: 0644]
src/jp/co/areaweb/tools/database/DoSQL.java [new file with mode: 0644]
src/jp/co/areaweb/tools/database/Select.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/AboutDialog.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/ClipbordTest.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/Command.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/DirSizeDialog.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/DirectoryFilter.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/Manager.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/NewFileListDialog.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/ParameterPanel.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/QuitDialog.java [new file with mode: 0644]
src/jp/co/areaweb/tools/gui/ReadXMLDialog.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/SendMail.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/SiteData.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/SiteDataXml.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/XmlTool.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/YuuMailXml.java [new file with mode: 0644]
src/jp/co/areaweb/tools/mail/package.html [new file with mode: 0644]
src/jp/co/areaweb/tools/servlet/FileDownloadServlet.java [new file with mode: 0644]
test/jp/co/areaweb/tools/core/TestMakeString.java [new file with mode: 0644]
test/jp/co/areaweb/tools/core/TestTax.java [new file with mode: 0644]

diff --git a/ClipbordTest.bat b/ClipbordTest.bat
new file mode 100644 (file)
index 0000000..3cd5c8b
--- /dev/null
@@ -0,0 +1,2 @@
+java -Xms64m -Xmx512m -cp ".;hayashi_0223.jar" jp.co.areaweb.tools.gui.ClipbordTest
+pause
\ No newline at end of file
diff --git a/MemoryCheck.bat b/MemoryCheck.bat
new file mode 100644 (file)
index 0000000..423d98b
--- /dev/null
@@ -0,0 +1,14 @@
+rem
+rem \8fo\97Í\8c\8b\89Ê
+rem    Java \83\81\83\82\83\8a\8fî\95ñ : \8d\87\8cv=1,984KB\81A\8eg\97p\97Ê=458KB (23.1%)\81A\8eg\97p\89Â\94\\8dÅ\91å=65,088KB
+rem 
+rem JAVA\82Ì\83q\81[\83v\83T\83C\83Y\95Ï\8dX\95û\96@
+rem    java -Xms64m -Xmx512m Main
+rem    -Xms\8f\89\8aú\83q\81[\83v\83T\83C\83Y
+rem            Java\89¼\91z\83}\83V\83\93\82Ö\82Ì\8f\89\8aú\83\81\83\82\83\8a\8a\84\82è\93\96\82Ä\97Ê\82ð\8ew\92è\82µ\82Ü\82·\81B\83f\83t\83H\83\8b\83g\82Í2MB\82Å\82·\81B
+rem    -Xmx\8dÅ\91å\83q\81[\83v\83T\83C\83Y
+rem            Java\89¼\91z\83}\83V\83\93\82Ö\82Ì\8dÅ\91å\83\81\83\82\83\8a\8a\84\82è\93\96\82Ä\97Ê\82ð\8ew\92è\82µ\82Ü\82·\81B\83f\83t\83H\83\8b\83g\82Í64MB\82Å\82·\81B
+rem    
+
+java -Xms64m -Xmx512m -cp ".;hayashi_0222.jar" jp.co.areaweb.tools.core.MemoryCheck
+pause
diff --git a/README.txt b/README.txt
new file mode 100644 (file)
index 0000000..a020015
--- /dev/null
@@ -0,0 +1,174 @@
+hayashi.jar            02-20   2010/02/08
+
+***** 必要なライブラリ *****
+mail.jar       javamail-1.2    JavaMail(TM) API 1.2 release
+activation.jar jaf-1.0.2       JAVABEANS(tm) ACTIVATION FRAMEWORK 1.0.2
+xerces.jar     Xerces Java Parser 1.4.4 Release (or xercesImpl.jar)
+
+$CATALINA_HOME/common/lib/servlet-api.jar
+               パッケージjp.co.areaweb.tools.servletを利用するときに必要です。
+
+junit.jar      3.8.1   -- プログラムテスト時にのみ必要です。
+
+
+*************************
+***                   ***
+***  コマンドメニュー  ***
+***                   ***
+*************************
+
+-- 指定されたファイルが整形式XML文書であるかどうかをしらべる。
+exp) java -cp hayashi.jar;xerces.jar jp.co.areaweb.tools.command.ReadXML build.xml
+
+
+-- ディレクトリの使用量を計算する。
+指定したディレクトリのファイル利用量を調べる。
+exp) java -cp hayashi.jar jp.co.areaweb.tools.command.DirSize \\Mkhnt02\kls\ITグループ
+
+
+-- sendMail.xmlの内容をメール送信する。
+jp.co.areaweb.tools.common.YuuMailXml property.xml sendMail.xml
+exp) java -cp ".;hayashi.jar;xerces.jar;mail.jar;activation.jar" jp.co.areaweb.tools.common.YuuMailXml property.xml sendMail.xml
+
+
+-- 指定された時刻以降に更新されたファイルをリストアップし、その絶対パス名を標準出力に出力する。
+jp.co.areaweb.tools.command.NewFileList [directory] [CCYY.MM.DD-HH:mm:ss]
+exp) java -cp hayashi.jar jp.co.areaweb.tools.command.NewFileList \\Mkhnt02\kls\ITグループ 2002.05.29-00:50:00
+
+
+-- 指定されたディレクトリ内にある、指定時刻以前に更新されたファイルを削除する。
+-- 指定されたディレクトリのサブディレクトリ内のファイルも削除対象とします。
+-- ディレクトリ自身は削除されません。
+jp.co.areaweb.tools.command.DeleteOldFile [directory] [CCYY.MM.DD-HH:mm:ss]
+exp) java -cp hayashi.jar jp.co.areaweb.tools.command.DeleteOldFile "C:\Documents and Settings\All Users\Documents\テスト" 2002.05.29-00:50:00
+
+
+-- 指定されたディレクトリ内にある、現在の時刻よりday日以前に更新されたファイルを削除する。
+-- 指定されたディレクトリのサブディレクトリ内のファイルも削除対象とします。
+-- ディレクトリ自身は削除されません。
+jp.co.areaweb.tools.command.DeleteOldFile [directory] -day [day]
+exp) java -cp hayashi.jar jp.co.areaweb.tools.command.DeleteOldFile "C:\Documents and Settings\All Users\Documents\テスト" -day 62
+
+
+-- コマンドラインを実行する
+OSコマンドを実行する。むろん、実行するコマンドラインの書式は実行時のプラットフォームに依存する。
+jp.co.areaweb.tools.command.Command [command line]
+exp) java -cp hayashi.jar jp.co.areaweb.tools.command.Command java -version
+
+
+-- jobFileNameに記述されたコマンドを実行する
+jp.co.areaweb.tools.command.Job [jobFileName]
+
+
+--  Jobファイルに記述されたXSLT処理を順次実行する。
+--  このコマンドを利用することによって、MS-DOSとUNIXで別々のシェルファイルを記述する必要がなくなります。
+exp) java -cp hayashi.jar;xalan.jar;xerces.jar;xml-apis.jar jp.co.areaweb.tools.command.Xalan Xalan.xml
+
+
+
+*************************
+***                   ***
+***      変更履歴      ***
+***                   ***
+*************************
+02-22 2010.07.26
+・jp.co.areaweb.tools.csv.CsvFile  機能拡張
+
+02-20 2010.02.08
+・hayashi.yuu.tools.gui.QuitDialog (終了確認ダイアログ)を追加
+
+02-19 2010.02.07
+・プロパティファイルを操作するパッケージを追加
+・簡易ログ設定用のパッケージを追加
+
+02-18 2010.02.05
+・メール送信:SMTPサーバーのポート番号を指定できるように変更
+・メール送信:「POP_before_SMTP」認証に対応
+・メール送信:「USER_AUTH」認証に対応
+
+02-17 2010.01.24
+・CsvFile.save()メソッドの追加
+       jp.co.areaweb.tools.csv.CsvFile.java
+・CsvRecord.toString()メソッドの追加
+       jp.co.areaweb.tools.csv.CsvRecord.java
+
+02-16 2008.10.15
+・CsvFileのダブルクォーテーション(")への対応
+       jp.co.areaweb.tools.csv.CsvRecord.java
+・CsvFileのバグFIX。
+       jp.co.areaweb.tools.csv.CsvFile.java
+       jp.co.areaweb.tools.csv.CsvRecord.java
+
+01-16 2006.11.15
+・YuuMailEのエンハンス。
+       添付ファイルのサーバー上のファイル名と添付元のファイル名を別個に管理する。
+       jp.co.areaweb.tools.common.YuuMailE.java
+       jp.co.areaweb.tools.common.YuuMailXml.java
+
+01-15 2006.6.8
+・'FileDownloadServlet'を追加
+       サーバ上のファイル(やデータベース等に保存してあるデータ)をブラウザに送る場合は、適切なコンテントタイプをセットした
+       後にファイル内容を送信します。
+       (strutsに対応しています。)
+
+01-14 2006.3.14
+・軽微な修正
+       Javaコンパイラの警告対応。動作に影響なし.
+
+01-13 2005.7.5
+・"jp.co.areaweb.tools.core"に'Tax.class'を新規作成
+       Tax : 消費税に関係するメソッドを集めたクラス.
+
+01-12 2005.7.5
+・"jp.co.areaweb.tools.database"を変更
+       Select : SQL文に';'がついていても実行できるように変更した.
+       DoSQL : SQL文に';'がついていても実行できるように変更した.
+
+01-11 2005.6.2
+・"jp.co.areaweb.tools.csv"パッケージを追加
+       CsvFileクラス:CSV形式ファイルを扱う一種のDAO
+       CsvRecordクラス:CSV形式の1行を表現したクラス
+・"jp.co.areaweb.tools.core"パッケージを追加
+       MakeStringクラス:数値を固定長の文字列表現に変換する。
+       TestMakeStringクラス:jUnitによるテスト用のクラス
+・"jp.co.areaweb.tools.database"パッケージを追加
+       DatabaseToolクラス:
+       DoSQLクラス:SQLファイルを実行する
+       Selectクラス:SQLの"SELECT"文を実行する
+
+01-10 2005.3.21
+・Xalanクラスの呼び出しにワーク領域の指定ができるように変更。
+       Xalan.execJob(new File(args[0]), new File(workDir))
+
+01-09 2005.1.15
+・parser.jarが手に入りにくくなったため、xerces.jarに対応。
+       非標準のXMLAPIを使用していた,jp.co.areaweb.tools.common.print()メソッドを削除。
+       xerces1.4に対応し、XMLも標準APIに変更。
+・ReadXMLコマンドを追加
+  指定されたファイルが整形式XML文書であるかどうかをしらべる。
+
+01-08 2004.12.25
+・DeleteOldFileコマンドを追加
+  指定日時以前のファイルを削除する機能を作成。
+  何日前のファイルを削除する機能を作成。
+
+01-07 2002.09.25
+・Xalanコマンド
+  XSLT処理を行う一覧を記述したXMLファイルを指定すると、順次XSLT処理を行う。
+
+01-06 2002.09.11
+・YuuMailのエンハンス。
+
+01-05 2002.05.29
+・新コマンド'NewFileList'
+
+01-04 2002.04.02
+・複数のあて先(CC,BCC)に対応。
+・BCC,CCエレメントの中身がnullの時に、NullPointerExceptionが発生するバグを修正。
+
+01-03 2002.04.02
+・複数のあて先(TO)に対応。
+・バイナリファイルが正しく添付できるようにした。
+
+01-02 2002.04.02
+・非推奨メソッドを使用しない。
diff --git a/YuuMailXml.sh b/YuuMailXml.sh
new file mode 100644 (file)
index 0000000..35dcd37
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+export JAXP=jaxp.jar
+export PARSER=parser.jar
+export MAIL=mail.jar:activation.jar
+
+java -cp .:hayashi.jar:$JAXP:$PARSER:$MAIL jp.co.areaweb.tools.common.YuuMailXml property.xml sendMail.xml
diff --git a/build.properties b/build.properties
new file mode 100644 (file)
index 0000000..36c9233
--- /dev/null
@@ -0,0 +1,5 @@
+junit.jar = lib/junit.jar
+xerces = lib/xercesImpl.jar
+mail = lib/mail-1.4.jar
+activation = lib/activation-1.1.jar
+servlet = lib/servlet-api.jar
diff --git a/build.xml b/build.xml
new file mode 100644 (file)
index 0000000..159de2e
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,108 @@
+<project name="hayashi" default="all" basedir=".">
+    <property name="src" value="${basedir}/src" />
+    <property name="doc" value="${basedir}/doc" />
+    <property name="report" value="${basedir}/report" />
+    <property file="build.properties" />
+       <property name="appname" value="hayashi"></property>
+       <property name="version" value="0223"></property>
+
+    <path id="compile.classpath">
+        <pathelement location="lib/junit.jar"/>
+        <pathelement location="lib/xercesImpl.jar"/>
+        <pathelement location="lib/mail-1.4.jar"/>
+        <pathelement location="lib/activation-1.1.jar"/>
+        <pathelement location="lib/servlet-api.jar"/>
+    </path>
+
+    <target name="init">
+        <tstamp/>
+    </target>
+
+    <target name="prepare" depends="init">
+       <!--
+        <mkdir dir="${doc}" />
+        <mkdir dir="${report}"/>
+       -->
+    </target>
+
+    <target name="clean" description="Delete build directory">
+               <delete>
+                       <fileset dir="${src}" includes="**/*.class" />
+               </delete>
+    </target>
+  
+       <!-- コンパイル -->
+    <target name="compile" depends="prepare" description="Compile Java Sources">
+        <javac srcdir="${src}" destdir="${src}" encoding="UTF-8"
+               target="1.5" optimize="off" debug="on" verbose="false">
+            <include name="**/*.java" />
+            <classpath refid="compile.classpath"/>
+        </javac>
+    </target>
+
+       <!-- 
+       Javadoc作成 
+               実行させるには、PATHにJDKの「JAVA_HOME/bin」を追加する必要がある。
+       -->
+       <target name="javadoc" depends="compile" description="Create Javadoc API documentation">
+        <mkdir dir="${doc}/api" />
+        <javadoc
+                       packagenames="*"
+                       encoding="UTF-8"
+                       charset="UTF-8"
+                       sourcepath="${src}" 
+                       destdir="${doc}/api" >
+               <link href="http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/" />
+               <link href="http://java.sun.com/products/javamail/javadocs/" />
+        </javadoc>
+       </target>
+
+       <!-- Jarアーカイバの作成 -->
+    <target name="makejar" depends="compile" description="make hayashi.jar">
+               <delete file="${appname}_${version}.jar"/>
+               <tstamp>
+                       <format property="ts" pattern="yyyy/MM/dd-HH:mm:ss-z"/>
+               </tstamp>
+               <jar destfile="${appname}_${version}.jar">
+                       <fileset file="README.txt"/>
+                       <fileset dir="test" includes="**/*.class,**/*.java" />
+                       <fileset dir="${src}" includes="**/*.class,**/*.java" />
+                       <manifest>
+                               <attribute name="Implementation-Title"   value="${appname}"/>
+                               <attribute name="Implementation-Version" value="hayashi lib ${version}"/>
+                               <attribute name="Implementation-Vendor"  value="Yuu Hayashi."/>
+                               <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}])"/>
+                       </manifest>
+               </jar>
+    </target>
+
+
+    <target name="test" depends="compile" description="Run JUnit">
+        <junit printsummary="yes">
+            <classpath refid="compile.classpath"/>
+            <test name="util.money.MoneyTest"/>
+        </junit>
+    </target>
+
+    <target name="report" depends="compile" description="Report Test Results">
+        <junit printsummary="yes">
+            <classpath refid="compile.classpath"/>
+            <formatter type="xml"/>
+            <batchtest fork="yes" todir="${report}">
+                <fileset dir="${src}">
+                    <include name="**/*Test.java"/>
+                </fileset>
+            </batchtest>
+        </junit>
+        <junitreport todir="${report}">
+            <fileset dir="${report}">
+                <include name="TEST-*.xml"/>
+            </fileset>
+            <report format="frames" todir="${report}/html"/>
+        </junitreport>
+    </target>
+    
+    <target name="all" depends="clean, makejar" description="Clean build directory, then compile, and JavaDoc">
+    </target>
+
+</project>
diff --git a/config/Xalan.xml b/config/Xalan.xml
new file mode 100644 (file)
index 0000000..679bee7
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="Shift_JIS"?>
+<xalan>
+    <xslt>
+        <xml>index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>index.html</output>
+    </xslt>
+    <xslt>
+        <xml>protected/index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>protected/index.html</output>
+    </xslt>
+    <xslt>
+        <xml>album/index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>album/index.html</output>
+    </xslt>
+    <xslt>
+        <xml>poweredby/index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>poweredby/index.html</output>
+    </xslt>
+    <xslt>
+        <xml>product/index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>product/index.html</output>
+    </xslt>
+    <xslt>
+        <xml>service/index.xml</xml>
+        <xsl>syte.xsl</xsl>
+        <output>service/index.html</output>
+    </xslt>
+</xalan>
diff --git a/config/hayashi.properties b/config/hayashi.properties
new file mode 100644 (file)
index 0000000..8196b80
--- /dev/null
@@ -0,0 +1,6 @@
+# Mail send
+MAIL_SMTP=192.168.0.7
+MAIL_FROM=yuuhayashi@hotmail.com
+MAIL_TO=
+MAIL_CC=
+MAIL_BCC=
diff --git a/config/property.xml b/config/property.xml
new file mode 100644 (file)
index 0000000..23f5155
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="Shift_JIS"?>
+
+<property>
+    <smtp>192.168.0.7</smtp>
+    <from>yuuhayasi@hotmail.com</from>
+    <to></to>
+    <cc></cc>
+    <bcc></bcc>
+</property>
diff --git a/config/sendMail.xml b/config/sendMail.xml
new file mode 100644 (file)
index 0000000..ca65539
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="Shift_JIS"?>
+
+<sendMail>
+    <to>yuuhayashi@hotmail.com</to>
+    <cc></cc>
+    <bcc></bcc>
+    <subject><![CDATA[\91è\96¼]]></subject>
+    <content><![CDATA[
+\96{\95\82Ì\93à\97e
+]]></content>
+    <attachment file="hayashi.jar">1234567890.dat</attachment>
+    <attachment>activation.jar</attachment>
+</sendMail>
+
diff --git a/config/sendmail.properties b/config/sendmail.properties
new file mode 100644 (file)
index 0000000..0df42df
--- /dev/null
@@ -0,0 +1,14 @@
+#SendMail GUI
+#Tue Feb 09 19:08:39 JST 2010
+MAIL_POP_before_SMTP=false
+mail.smtp.from=hayashi@localhost
+mail.smtp.host=localhost
+MAIL_TO=proxSafe@localhost
+MAIL_BCC=
+mail.smtp.starttls.enable=false
+mail.smtp.port=25
+mail.smtp.auth=true
+MAIL_CC=
+mail.smtp.user=hayashi
+MAIL_POP=
+MAIL_PASSWORD=d3d04b7cd9d850e6
diff --git a/config/yuumail.properties b/config/yuumail.properties
new file mode 100644 (file)
index 0000000..4a362a8
--- /dev/null
@@ -0,0 +1,13 @@
+#SendMail GUI
+#Sun Feb 07 23:31:08 JST 2010
+MAIL_SMTP_PORT=587
+MAIL_FROM=yuuh@da2.so-net.ne.jp
+MAIL_SMTP_AUTH=true
+MAIL_POP_before_SMTP=false
+USER_ID=yuuh@da2.so-net.ne.jp
+MAIL_TO=hayashi.yuu@gmail.com
+MAIL_BCC=
+MAIL_SMTP=mail.so-net.ne.jp
+MAIL_CC=
+MAIL_POP=
+PASSWORD=b36d1ae80ced5a2f
diff --git a/deleteold.bat b/deleteold.bat
new file mode 100644 (file)
index 0000000..070c662
--- /dev/null
@@ -0,0 +1 @@
+java -cp hayashi.jar jp.co.areaweb.tools.command.DeleteOldFile "C:\Documents and Settings\All Users\Documents\\83e\83X\83g" -day 5
\ No newline at end of file
diff --git a/lib/activation-1.1.jar b/lib/activation-1.1.jar
new file mode 100644 (file)
index 0000000..e31e71c
Binary files /dev/null and b/lib/activation-1.1.jar differ
diff --git a/lib/junit.jar b/lib/junit.jar
new file mode 100644 (file)
index 0000000..674d71e
Binary files /dev/null and b/lib/junit.jar differ
diff --git a/lib/mail-1.4.jar b/lib/mail-1.4.jar
new file mode 100644 (file)
index 0000000..c5438c6
Binary files /dev/null and b/lib/mail-1.4.jar differ
diff --git a/lib/servlet-api.jar b/lib/servlet-api.jar
new file mode 100644 (file)
index 0000000..93186f6
Binary files /dev/null and b/lib/servlet-api.jar differ
diff --git a/lib/xercesImpl.jar b/lib/xercesImpl.jar
new file mode 100644 (file)
index 0000000..eac75ae
Binary files /dev/null and b/lib/xercesImpl.jar differ
diff --git a/manager.bat b/manager.bat
new file mode 100644 (file)
index 0000000..d5fdb3e
--- /dev/null
@@ -0,0 +1,10 @@
+rem
+rem \81y\82±\82Ì\83v\83\8d\83O\83\89\83\80\82Ì\8b@\94\\81z
+rem     \81uhayashi.jar\81v(GUI\94Å)
+rem    (1) NewFileList
+rem 
+rem \81y\8eÀ\8ds\82É\95K\97v\82È\83t\83@\83C\83\8b\81z
+rem    hayashi.jar
+rem    
+
+javaw -cp ".;classes" jp.co.areaweb.tools.gui.Manager
diff --git a/samplelog.bat b/samplelog.bat
new file mode 100644 (file)
index 0000000..ae6ee7b
--- /dev/null
@@ -0,0 +1,11 @@
+rem
+rem \81y\82±\82Ì\83v\83\8d\83O\83\89\83\80\82Ì\8b@\94\\81z
+rem     \81uhayashi.jar\81v(GUI\94Å)
+rem    (1) log.properties
+rem 
+rem \81y\8eÀ\8ds\82É\95K\97v\82È\83t\83@\83C\83\8b\81z
+rem    hayashi.jar
+rem    
+
+java -cp ".;hayashi_0222.jar" hayashi.yuu.tools.logger.LoggerFactory
+pause
diff --git a/sendmail.bat b/sendmail.bat
new file mode 100644 (file)
index 0000000..319ea90
--- /dev/null
@@ -0,0 +1,13 @@
+rem
+rem \81y\83\81\81[\83\8b\91\97\90M\81z(GUI\94Å)
+rem     \81E\83\81\81[\83\8b\91\97\90M\90Ý\92è
+rem     \81E\90Ý\92è\83f\81[\83^\82Ì\95Ï\8dX\82Æ\95Û\91
+rem     \81E\83e\83X\83g\83\81\81[\83\8b\91\97\90M
+rem 
+rem \81y\8eÀ\8ds\82É\95K\97v\82È\83t\83@\83C\83\8b\81z
+rem    \81Ehayashi.jar
+rem    \81Eactivation-1.1.jar
+rem    \81Email-1.4.jar
+rem    
+
+java -cp ".;hayashi_0220.jar;lib/activation-1.1.jar;lib/mail-1.4.jar" hayashi.yuu.tools.mail.gui.SendMailGUI config/sendmail.properties
diff --git a/src/hayashi/yuu/tools/gui/QuitDialog.java b/src/hayashi/yuu/tools/gui/QuitDialog.java
new file mode 100644 (file)
index 0000000..381122f
--- /dev/null
@@ -0,0 +1,91 @@
+package hayashi.yuu.tools.gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.Window;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+
+public class QuitDialog extends JDialog implements WindowListener
+{
+    JButton yesButton;
+    JButton noButton;
+    JLabel label1;
+
+    public QuitDialog(JFrame parent, boolean modal) {
+        super(parent, modal);
+        addWindowListener((WindowListener) this);
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+
+        setLayout(null);
+        setSize(getInsets().left + getInsets().right + 337, getInsets().top + getInsets().bottom + 135);
+        
+        yesButton = new JButton("  終了  ");
+        yesButton.addActionListener(new java.awt.event.ActionListener() {
+               public void actionPerformed(java.awt.event.ActionEvent evt) {
+                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((Window)getParent(), 201));
+                System.exit(0);
+               }
+        });
+        yesButton.setBounds(getInsets().left + 72, getInsets().top + 80, 79, 22);
+        yesButton.setFont(new Font("Dialog", 1, 12));
+        add(yesButton);
+
+        noButton = new JButton("キャンセル");
+        noButton.addActionListener(new java.awt.event.ActionListener() {
+               public void actionPerformed(java.awt.event.ActionEvent evt) {
+                       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(QuitDialog.this, WindowEvent.WINDOW_CLOSING));
+                       setVisible(false);
+               }
+        });
+        noButton.setBounds(getInsets().left + 185, getInsets().top + 80, 99, 22);
+        noButton.setFont(new Font("Dialog", 1, 12));
+        add(noButton);
+        
+        label1 = new JLabel("プログラムを終了します。", JLabel.CENTER);
+        label1.setBounds(78, 33, 180, 23);
+        add(label1);
+        setTitle("プログラムの終了");
+        setResizable(false);
+        setVisible(true);
+    }
+
+    public void setVisible(boolean b) {
+        if(b) {
+            Rectangle bounds = getParent().getBounds();
+            Rectangle abounds = getBounds();
+            setLocation(bounds.x + (bounds.width - abounds.width) / 2, bounds.y + (bounds.height - abounds.height) / 2);
+        }
+        super.setVisible(b);
+    }
+
+
+       public void windowActivated(WindowEvent e) {
+       }
+
+       public void windowClosed(WindowEvent e) {
+               setVisible(false);
+       }
+
+       public void windowClosing(WindowEvent e) {
+               setVisible(false);
+       }
+
+       public void windowDeactivated(WindowEvent e) {
+       }
+
+       public void windowDeiconified(WindowEvent e) {
+       }
+
+       public void windowIconified(WindowEvent e) {
+       }
+
+       public void windowOpened(WindowEvent e) {
+       }
+}
diff --git a/src/hayashi/yuu/tools/logger/LoggerFactory.java b/src/hayashi/yuu/tools/logger/LoggerFactory.java
new file mode 100644 (file)
index 0000000..2fb9080
--- /dev/null
@@ -0,0 +1,123 @@
+package hayashi.yuu.tools.logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+/**
+ * ロギングファイルに動作ログを出力する簡単なモデル
+ * "log"+日時+".log"ファイルに出力される。
+ * 利用例:
+ * (1) インスタンスを取得する。
+ *             Logger logger = LoggerFactory.getInstance();
+ * (2) ログ出力例
+ *             logger.finest("[finest] 詳細レベル(高)");
+ *             logger.finer("[finer] 詳細レベル(中)");
+ *             logger.fine("[fine] 詳細レベル(小)");
+ *             logger.config("[config] 設定");
+ *             logger.info("[info] 情報");
+ *             logger.warning("[warning] 警告");
+ *             logger.severe("[severe] 致命的");
+ * @author yuu
+ * @version 2010/02/07
+ * @since 2010/02/07
+ */
+public abstract class LoggerFactory 
+{
+       public static void main(String[] args) {
+               /*
+                * (設定例)
+                *              handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+                *              .level=FINEST
+                * 
+                *              java.util.logging.ConsoleHandler.level=FINEST
+                *              java.util.logging.ConsoleHandler.formatter=hayashi.yuu.tools.logger.YuuLogFormatter
+                * 
+                *              java.util.logging.FileHandler.level=WARNING
+                *              java.util.logging.FileHandler.pattern=SampleLogging%u.%g.log
+                *              java.util.logging.FileHandler.formatter=hayashi.yuu.tools.logger.YuuLogFormatter
+                *              java.util.logging.FileHandler.count=10
+                *              
+                * 
+                * 標準設定時でのログ出力。
+                * info、warning、severeの3つのレベルのみ標準エラー出力に出力されます。
+                * また、同時にファイルへも出力します。
+                * 出力先ファイルは「Logging%u.%g.txt」。ログファイルは10個でローテーションする。
+                * 
+                * 情報: [info] 情報
+                * 警告: [warning] 警告
+                * 致命的: [severe] 致命的
+                */
+               Logger logger = LoggerFactory.getInstance();
+               logger.finest("[finest] 詳細レベル(高)");
+               logger.finer("[finer] 詳細レベル(中)");
+               logger.fine("[fine] 詳細レベル(小)");
+               logger.config("[config] 設定");
+               logger.info("[info] 情報");
+               logger.warning("[warning] 警告");
+               logger.severe("[severe] 致命的");
+       }
+       
+    public static Logger logger;
+    
+    /**
+     * 簡単な標準ロガーを得る
+     * @return 標準ロガー
+     */
+    public static Logger getInstance() {
+       if (logger == null) {
+            //FileHandler handler = new FileHandler("GuardixMonitor.log", 1000, 3);    // ハンドラオブジェクトの生成
+            //handler.setFormatter(new SimpleFormatter());             // 出力フォーマットの指定
+            logger = Logger.getLogger("log");          // Loggerオブジェクトの生成
+            //GuardixMonitor.logger.addHandler(handler);               // Loggerオブジェクトにハンドラを追加
+       }
+               return logger;
+    }
+       
+    /**
+        * ログ設定プロパティファイルのファイル内容
+        * 
+        */
+       protected static final String LOGGING_PROPERTIES_DATA
+           = "handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler\n"
+           + ".level=INFO\n"
+           + "java.util.logging.ConsoleHandler.level=FINEST\n"
+           + "java.util.logging.ConsoleHandler.formatter=hayashi.yuu.tools.logger.YuuLogFormatter\n"
+           + "java.util.logging.FileHandler.level=INFO\n"
+           + "java.util.logging.FileHandler.pattern=Logging%u.%g.txt\n"
+           + "java.util.logging.FileHandler.formatter=hayashi.yuu.tools.logger.YuuLogFormatter\n"
+           + "java.util.logging.FileHandler.count=10";
+
+    
+    /**
+        * static initializer によるログ設定の初期化
+        */
+    static {
+        final Logger logger = Logger.getLogger("SampleLogging");
+        InputStream inStream = null;
+        try {
+            inStream = new ByteArrayInputStream(LOGGING_PROPERTIES_DATA.getBytes("UTF-8"));
+            try {
+                LogManager.getLogManager().readConfiguration(inStream);
+                logger.config("ログ設定: LogManagerを設定しました。");
+            }
+            catch (IOException e) {
+                logger.warning("ログ設定: LogManager設定の際に例外が発生しました。:" + e.toString());
+            }
+        }
+        catch (UnsupportedEncodingException e) {
+            logger.severe("ログ設定: UTF-8エンコーディングがサポートされていません。:" + e.toString());
+        }
+        finally {
+            try {
+                if (inStream != null) inStream.close();
+            }
+            catch (IOException e) {
+                logger.warning("ログ設定: ログ設定プロパティファイルのストリームクローズ時に例外が発生しました。:" + e.toString());
+            }
+        } 
+    }
+}
diff --git a/src/hayashi/yuu/tools/logger/YuuLogFormatter.java b/src/hayashi/yuu/tools/logger/YuuLogFormatter.java
new file mode 100644 (file)
index 0000000..373e99a
--- /dev/null
@@ -0,0 +1,47 @@
+package hayashi.yuu.tools.logger;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * シンプルなサンプルログフォーマッタ
+ */
+public class YuuLogFormatter extends Formatter {
+    private final SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+    public String format(final LogRecord argLogRecord) {
+        final StringBuffer buf = new StringBuffer();
+
+        buf.append(sdFormat.format(new Date(argLogRecord.getMillis())) +" ");
+
+        if (argLogRecord.getLevel() == Level.FINEST) {
+            buf.append("[FINEST]");
+        }
+        else if (argLogRecord.getLevel() == Level.FINER) {
+            buf.append("[FINER]");
+        }
+        else if (argLogRecord.getLevel() == Level.FINE) {
+            buf.append("[FINE]");
+        }
+        else if (argLogRecord.getLevel() == Level.CONFIG) {
+            buf.append("[CONFIG]");
+        }
+        else if (argLogRecord.getLevel() == Level.INFO) {
+            buf.append("[INFO]");
+        }
+        else if (argLogRecord.getLevel() == Level.WARNING) {
+            buf.append("[WARN]");
+        }
+        else if (argLogRecord.getLevel() == Level.SEVERE) {
+            buf.append("[SEVERE]");
+        }
+        else {
+            buf.append(Integer.toString(argLogRecord.getLevel().intValue()) +" ");
+        }
+        buf.append(" "+ /* argLogRecord.getLoggerName() +" - "+ */ argLogRecord.getMessage() +"\n");
+        return buf.toString();
+    }
+}
\ No newline at end of file
diff --git a/src/hayashi/yuu/tools/logger/package.html b/src/hayashi/yuu/tools/logger/package.html
new file mode 100644 (file)
index 0000000..7674380
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Logger</title>
+</head>
+<body>
+<p>詳細な設定なしにロギング用のロガーを簡単に取得する。</p>
+<p>
+・ファイルに出力します。<br/>
+・INFOレベル以上
+</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/hayashi/yuu/tools/mail/SendMail.java b/src/hayashi/yuu/tools/mail/SendMail.java
new file mode 100644 (file)
index 0000000..fe2553c
--- /dev/null
@@ -0,0 +1,365 @@
+package hayashi.yuu.tools.mail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
+import java.util.Properties;
+import java.util.Vector;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.Store;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimeUtility;
+
+import hayashi.yuu.tools.mail.SiteData;
+
+/**
+ * <p>Eメールを送信するためのクラス<br/>
+ * JavaMailを使用する</p>
+ * @see <a href="http://java.sun.com/products/javamail/javadocs/index.html">JavaMail API</a>
+ * 
+ * @author hayashi
+ * @version 2010/02/05 SMTPサーバーのポート番号指定を追加
+ */
+public class SendMail
+{
+    public static void main(java.lang.String[] args) {
+        try {
+               SiteData siteData = new SiteData("sendmail.properties");
+                       SendMail mail = new SendMail(siteData);
+            mail.setSubject("[SendMail] SendMail テスト");
+            mail.setContent("本文\n");
+            mail.setAttachment(new File("activation-1.1.jar"));
+            mail.send();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected Vector<String> toVector = new Vector<String>(); // プロパティ 送信先(to) の値
+    protected Vector<String> ccVector = new Vector<String>(); // プロパティ 送信先(Cc) の値
+    protected Vector<String> bccVector = new Vector<String>();    // プロパティ 送信先(Bcc) の値
+    protected String from = null;         // プロパティ 発信元(from) の値
+    protected String subject;             // プロパティ 題名(subject) の値
+    protected String content;             // プロパティ 本文(content) の値
+    protected String mailHost;            // プロパティ SMTP(mail.smtp.host) の値
+    protected String mailHostPort;        // プロパティ SMTP_PORT(mail.smtp.port) の値
+    
+    protected Vector<File> attachments = new Vector<File>();   // 添付ファイル
+    protected Vector<String> attachNames = new Vector<String>();               // 添付ファイル名
+    
+    protected boolean POP_before_SMTP = false;
+    protected boolean STARTTLS = false;
+    protected boolean USER_AUTH = false;
+    protected String popServer = "";
+    protected String userId = "";
+    protected String password ="";
+    protected Session session = null;
+    
+    /** 
+     * 新しい YuuMail インスタンスを作成する 
+     * @param mailProp メール設定ファイルのパス名称
+     */
+    public SendMail(String mailProp) {
+        this(new SiteData(mailProp));
+    }
+
+    /**
+     * 新しい インスタンスを作成する 
+     * @param siteData メール設定値を包含したオブジェクト
+     */
+    public SendMail(SiteData siteData) {
+        super();
+        
+        if (checkItem(siteData.MAIL_SMTP)) {
+            this.setMailHost(siteData.MAIL_SMTP);
+        }
+        if (checkItem(siteData.MAIL_SMTP_PORT)) {
+            this.setMailPort(siteData.MAIL_SMTP_PORT);
+        }
+        if (checkItem(siteData.MAIL_TO)) {
+            this.toVector.add(siteData.MAIL_TO);
+        }
+        if (checkItem(siteData.MAIL_CC)) {
+            this.ccVector.add(siteData.MAIL_CC);
+        }
+        if (checkItem(siteData.MAIL_BCC)) {
+            this.bccVector.add(siteData.MAIL_BCC);
+        }
+        if (checkItem(siteData.MAIL_FROM)) {
+            this.from = siteData.MAIL_FROM;
+        }
+
+        this.POP_before_SMTP = siteData.POP_before_SMTP;
+        this.STARTTLS = siteData.STARTTLS;
+        this.USER_AUTH = siteData.USER_AUTH;
+        this.popServer = siteData.MAIL_POP;
+        this.userId = siteData.USER_ID;
+        this.password = siteData.PASSWORD;
+        
+        // メール(MimeMessageオブジェクト)を生成する
+        Properties props = System.getProperties();
+        props.put("mail.smtp.host", getMailHost());
+        props.put("mail.smtp.port", getMailPort());
+        if (this.USER_AUTH) {
+               props.put("mail.smtp.auth", "true");
+        }
+        if (this.STARTTLS) {
+               props.put("mail.smtp.starttls.enable", "true");
+        }
+        this.session = Session.getDefaultInstance(props, null);
+    }
+    private boolean checkItem(String itemStr) {
+       if (itemStr == null) {
+               return false;
+       }
+       if (itemStr.trim().equals("")) {
+               return false;
+       }
+       return true;
+    }
+    
+    /** 
+     * プロパティ mailHost の取得メソッド。
+     * @return プロパティ mailHost の値。
+     */
+    public String getMailHost() {
+        return this.mailHost;
+    }
+    
+    /** 
+     * SMTPサーバーを設定
+     *  @param mailHost SMTPサーバー名またはSMTPサーバーのIPアドレス
+    */
+    public void setMailHost(String mailHost) {
+        this.mailHost = mailHost;
+    }
+    
+    /** 
+     * プロパティ SMTPポート番号 の取得メソッド。
+     * @return SMTPポート番号を表す文字列(デシマル)
+     */
+    public String getMailPort() {
+        return this.mailHostPort;
+    }
+
+    /** 
+     * SMTPポート番号を設定
+     *  @param portStr SMTPポート番号を表す文字列(デシマル)
+     */
+    public void setMailPort(String portStr) {
+        this.mailHostPort = portStr;
+    }
+    
+    /**
+     * 送信先(To)を設定.数設定可
+     * @param to 送信先(To)
+     */
+    public void setTo(String to) {
+        if (!to.equals("")) {
+            toVector.addElement(to);
+        }
+    }
+    
+    /**
+     * 送信先(Cc)を設定。複数設定可
+     * @param cc 送信先(cc)
+     */
+    public void setCc(String cc) {
+        if (!cc.equals("")) {
+            ccVector.addElement(cc);
+        }
+    }
+    
+    /**
+     * 送信先(Bco)を設定.複数選択可
+     * @param bcc 送信先(Bcc)
+     */
+    public void setBcc(String bcc) {
+        if (!bcc.equals("")) {
+            bccVector.addElement(bcc);
+        }
+    }
+    
+    /** 
+     * プロパティ from の取得メソッド。
+     * @return プロパティ from の値。
+     */
+    public String getFrom() {
+        return from;
+    }
+    
+    /** 
+     * プロパティ 送信元(from) の設定メソッド。
+     * @param from 送信元メールアドレス
+     */
+    public void setFrom(String from) {
+        this.from = from;
+    }
+    
+    /** 
+     * プロパティ subject の取得メソッド。
+     * @return プロパティ subject の値。
+     */
+    public String getSubject() {
+        return subject;
+    }
+    
+    /**
+     * プロパティ 題名(subject) の設定メソッド。
+     * メールタイトル(題名)を設定
+     * @param subject メールタイトル(題名)
+     */
+    public void setSubject(String subject) {
+        this.subject = subject;
+    }
+    
+    /** 
+     * 本文(content)の取得メソッド。
+     * @return 本文の値。
+     */
+    public String getContent() {
+        return this.content;
+    }
+    
+    /** 
+     * 本文(content)の設定メソッド。
+     * 本文(content)を設定
+     * @param content 本文(content)
+     */
+    public void setContent(String content) {
+        this.content = content;
+    }
+    
+    /** 
+     * 添付ファイルの設定メソッド。
+     * 添付するファイル(attachment)を設定.添付ファイルは複数設定可。
+     * @param attachment 添付するファイル(attachment)
+     * @throws FileNotFoundException 添付するファイルが見つからなかった。
+     */
+    public void setAttachment(File attachment) throws FileNotFoundException {
+        new FileInputStream(attachment);    // ファイルが実存することをチェックする。
+        attachments.addElement(attachment);
+        attachNames.addElement(attachment.getName());
+    }
+    
+    /** 
+     * 添付ファイルの設定メソッド。
+     * 添付するファイル(attachment)を設定.添付ファイルは複数設定可。
+     * @param attachment 添付するファイル(attachment)
+     * @param name 添付するファイルの表示名
+     * @throws FileNotFoundException 添付するファイルが見つからなかった。
+     */
+     public void setAttachment(File attachment, String name) throws FileNotFoundException {
+         new FileInputStream(attachment);    // ファイルが実存することをチェックする。
+         attachments.addElement(attachment);
+         attachNames.addElement(name);
+     }
+     
+    /**
+     * メールを送信
+     * @throws MessagingException エラー:メールの送信に失敗しました。
+     * @throws UnsupportedEncodingException エラー:メールの文字エンコードに失敗しました。
+     */
+    public void send() throws MessagingException, UnsupportedEncodingException {
+        //-------------------------
+        // POP before SMTP 対応
+        //--
+        Store store = null;
+        if (this.POP_before_SMTP == true) {
+               System.out.println("store.connect('"+ popServer +"', '"+ userId +"', '"+ password +"')");
+               store = this.session.getStore("pop3");
+               store.connect(popServer, userId, password);
+        }
+        else {
+               System.out.println("no POP_before_SMTP!");
+        }
+
+        MimeMessage message = createMessage();
+        
+        if (this.USER_AUTH) {
+               System.out.println("transport.connect(null, '"+ userId +"', '"+ password+"')");
+            Transport transport = this.session.getTransport("smtp");
+               transport.connect(null, userId, password);
+               Address[] addrs = message.getAllRecipients();
+               for (Address addr : addrs) {
+                       System.out.println("[Addr] "+ addr.toString());
+               }
+            transport.sendMessage(message, message.getAllRecipients());
+        }
+        else {
+               System.out.println("no SMTP_AUTH!");
+               Transport.send(message);
+        }
+        
+        if (this.POP_before_SMTP == true) {
+            store.close();
+        }
+    }
+    
+    /**
+     * 新規にメールインスタンスを生成する。
+     * @return メールインスタンス
+     * @throws MessagingException メール送信に失敗しました。
+     * @throws UnsupportedEncodingException 文字エンコーディングに失敗した。
+     */
+    protected MimeMessage createMessage() throws MessagingException, UnsupportedEncodingException {
+        MimeMessage msg = new MimeMessage(this.session);
+        
+        // 送信先(To)
+        InternetAddress[] toList = new InternetAddress[toVector.size()];
+        for (int i=0; i < toVector.size(); i++) {
+            toList[i] = new InternetAddress(toVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.TO, toList);
+
+        // 送信先(Cc)
+        InternetAddress[] ccList = new InternetAddress[ccVector.size()];
+        for (int i=0; i < ccVector.size(); i++) {
+            ccList[i] = new InternetAddress(ccVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.CC, ccList);
+
+        // 送信先(Bcc)
+        InternetAddress[] bccList = new InternetAddress[bccVector.size()];
+        for (int i=0; i < bccVector.size(); i++) {
+            bccList[i] = new InternetAddress(bccVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.BCC, bccList);
+        
+        // 送信元(From)
+        msg.setFrom(new InternetAddress(getFrom()));
+
+        // 件名(Subject)
+        msg.setSubject(MimeUtility.encodeText(getSubject(), "iso-2022-jp", "B"));
+
+        // 本文(Content)
+        MimeMultipart naiyou = new MimeMultipart();
+        msg.setContent(naiyou);
+        
+        MimeBodyPart honbun = new MimeBodyPart();
+        honbun.setContent(getContent(), "text/plain; charset=\"iso-2022-jp\"");
+        naiyou.addBodyPart(honbun);
+
+        // 添付(Attachment)
+        for (int i=0; i < attachments.size(); i++) {
+            File attachFile = attachments.elementAt(i);
+            MimeBodyPart tenpu = new MimeBodyPart();
+            javax.activation.FileDataSource dfs = new javax.activation.FileDataSource(attachFile);
+            javax.activation.DataHandler dh = new javax.activation.DataHandler(dfs);
+            tenpu.setDataHandler(dh);
+            tenpu.setFileName(attachNames.elementAt(i));
+            naiyou.addBodyPart(tenpu);
+        }
+        
+        return msg;
+    }
+}
diff --git a/src/hayashi/yuu/tools/mail/SiteData.java b/src/hayashi/yuu/tools/mail/SiteData.java
new file mode 100644 (file)
index 0000000..c686428
--- /dev/null
@@ -0,0 +1,108 @@
+package hayashi.yuu.tools.mail;
+
+import hayashi.yuu.tools.properties.Properties;
+import java.io.FileInputStream;
+
+/**
+ * メールアカウント設定情報を保持するインスタンス
+ * @author hayashi
+ * @version    2010/02/05      項目'MAIL_SMTP_PORT'を追加
+ */
+public class SiteData {
+    public String MAIL_SMTP = "192.168.0.10";
+    public String MAIL_SMTP_PORT = "25";
+    public String MAIL_FROM = "webserver@xxx.co.jp";
+    public String MAIL_TO = "";
+    public String MAIL_CC = "";
+    public String MAIL_BCC = "";
+    
+    /**
+     * 'POP before SMTP'認証を行うかどうか
+     */
+    public boolean POP_before_SMTP = false;
+    
+    /**
+     * 'USER_AUTH'認証を行うかどうか
+     */
+    public boolean USER_AUTH = false;
+    
+    /**
+     * 'STARTTLS'認証を行うかどうか
+     */
+    public boolean STARTTLS = false;
+    
+    /**
+     * POPサーバー名('POP before SMTP'認証時のみ)
+     */
+    public String MAIL_POP = "";
+    
+    /**
+     * POPアカウント('POP before SMTP'認証時のみ)
+     */
+    public String USER_ID = "";
+    
+    /**
+     * POPアカウントのパスワード('POP before SMTP'認証時のみ)
+     */
+    public String PASSWORD = "";
+
+    /**
+     * 指定されたプロパティファイルに定義された値でインスタンスを生成する。
+     * @param propertyFile     設定値を定義したプロパティファイルのパス名
+     */
+    public SiteData(String propertyFile) {
+        try {
+            Properties properties = new Properties();
+            properties.setPasswordItem("MAIL_PASSWORD");
+            properties.load(new FileInputStream(propertyFile));
+
+            String str = "";
+            if ((str = properties.getProperty("mail.smtp.host")) != null) {
+               MAIL_SMTP = str;
+            }
+            if ((str = properties.getProperty("mail.smtp.port")) != null) {
+               MAIL_SMTP_PORT = str;
+            }
+            if ((str = properties.getProperty("mail.smtp.from")) != null) {
+               MAIL_FROM = str;
+            }
+            if ((str = properties.getProperty("MAIL_TO")) != null) {
+               MAIL_TO = str;
+            }
+            if ((str = properties.getProperty("MAIL_CC")) != null) {
+               MAIL_CC = str;
+            }
+            if ((str = properties.getProperty("MAIL_BCC")) != null) {
+               MAIL_BCC = str;
+            }
+            
+            str = properties.getProperty("MAIL_POP_before_SMTP");
+            if ((str != null) && str.equals("true")) {
+               POP_before_SMTP = true;
+            }
+            
+            str = properties.getProperty("mail.smtp.auth");
+            if ((str != null) && str.equals("true")) {
+               USER_AUTH = true;
+            }
+
+            str = properties.getProperty("mail.smtp.starttls.enable");
+            if ((str != null) && str.equals("true")) {
+               STARTTLS = true;
+            }
+            
+            if ((str = properties.getProperty("MAIL_POP")) != null) {
+               MAIL_POP = str;
+            }
+            if ((str = properties.getProperty("mail.smtp.user")) != null) {
+               USER_ID = str;
+            }
+            if ((str = properties.getProperty("MAIL_PASSWORD")) != null) {
+               PASSWORD = str;
+            }
+        }
+        catch(Exception e) {
+            System.out.println(e);
+        }
+    }
+}
diff --git a/src/hayashi/yuu/tools/mail/gui/James.png b/src/hayashi/yuu/tools/mail/gui/James.png
new file mode 100644 (file)
index 0000000..c362c58
Binary files /dev/null and b/src/hayashi/yuu/tools/mail/gui/James.png differ
diff --git a/src/hayashi/yuu/tools/mail/gui/MailAddrPanel.java b/src/hayashi/yuu/tools/mail/gui/MailAddrPanel.java
new file mode 100644 (file)
index 0000000..909b15c
--- /dev/null
@@ -0,0 +1,80 @@
+package hayashi.yuu.tools.mail.gui;
+
+import hayashi.yuu.tools.mail.SiteData;
+import hayashi.yuu.tools.properties.Properties;
+import hayashi.yuu.tools.properties.PropertyFieldItem;
+import hayashi.yuu.tools.properties.PropertyItem;
+
+import java.awt.Dimension;
+
+import javax.swing.BoxLayout;
+import javax.swing.JPanel;
+
+
+/**
+ * <メール配信先>セットアップフォーム:
+ * (1)アイテム: [ MAIL_TO ]
+ * (2)アイテム: [ MAIL_CC ]
+ * (3)アイテム: [ MAIL_BCC ]
+ */
+@SuppressWarnings("serial")
+public class MailAddrPanel extends JPanel
+{
+    public static final int LINE_COUNT = 3;
+    public static final int CATEGORY_HEIGHT = PropertyItem.LINE_HEIGHT * LINE_COUNT;
+
+    PropertyFieldItem iTo;                     // 'MAIL_TO' メール送信先 : 宛先
+    PropertyFieldItem iCc;                     // 'MAIL_CC' メール送信先 : カーボンコピー
+    PropertyFieldItem iBcc;                    // 'MAIL_BCC' メール送信先 : ブラックカーボンコピー
+    
+       public MailAddrPanel(Properties prop) {
+               super();
+
+               /*
+                * カテゴリの配置
+                */
+           setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+               /*
+                * (1)アイテム: [ MAIL_TO ]
+                */
+               iTo = new PropertyFieldItem(prop, "MAIL_TO", "宛先", true);
+               add(iTo);
+               iTo.setBounds(0, PropertyItem.LINE_HEIGHT * 8, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+               
+               /*
+                * (2)アイテム: [ MAIL_CC ]
+                */
+               iCc = new PropertyFieldItem(prop, "MAIL_CC", "CC", true);
+               add(iCc);
+               iCc.setBounds(0, PropertyItem.LINE_HEIGHT * 9, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+               
+               /*
+                * (3)アイテム: [ MAIL_BCC ]
+                */
+               iBcc = new PropertyFieldItem(prop, "MAIL_BCC", "BCC", true);
+               add(iBcc);
+               iBcc.setBounds(0, PropertyItem.LINE_HEIGHT * 10, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+               
+               setPreferredSize(new Dimension(PropertyItem.LINE_WIDTH, CATEGORY_HEIGHT));
+       }
+       
+       public SiteData getSiteData(SiteData data) {
+               /*
+                * (9)アイテム: [ MAIL_TO ]
+                */
+               data.MAIL_TO = iTo.getValue();
+               
+               /*
+                * (10)アイテム: [ MAIL_CC ]
+                */
+               data.MAIL_CC = iCc.getValue();
+               
+               /*
+                * (11)アイテム: [ MAIL_BCC ]
+                */
+               data.MAIL_BCC = iBcc.getValue();
+               
+               return data;
+       }
+}
diff --git a/src/hayashi/yuu/tools/mail/gui/SendMailGUI.java b/src/hayashi/yuu/tools/mail/gui/SendMailGUI.java
new file mode 100644 (file)
index 0000000..8ba4b60
--- /dev/null
@@ -0,0 +1,200 @@
+package hayashi.yuu.tools.mail.gui;
+
+import hayashi.yuu.tools.logger.LoggerFactory;
+import hayashi.yuu.tools.mail.SendMail;
+import hayashi.yuu.tools.mail.SiteData;
+import hayashi.yuu.tools.properties.Encrypt;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.WindowConstants;
+
+
+@SuppressWarnings("serial")
+public class SendMailGUI extends JFrame implements ActionListener
+{
+    public static SendMailGUI mainFrame;
+    boolean fComponentsAdjusted;
+    JPanel headPanel;
+    JMenuBar mainMenuBar;      // [メニュー]
+    JMenu menuFile;                    // [メニュー]->[ファイル(F)]
+    JMenuItem miSetting;       // [メニュー]->[ファイル(F)]->[設定...]
+    JMenuItem miExit;          // [メニュー]->[ファイル(F)]->[終了(X)]
+    
+    public Logger logger;
+    public static SiteData mailProp;
+    public static String propertiesFileName;
+    
+    /**
+     * 「メール送信(SendMail)」
+     * 起動オプション:
+     *  第一: メールアカウントの設定ファイル名
+     */
+    public static void main(String args[]) throws Exception {
+               String fileName = "sendmail.properties";
+       if (args.length > 0) {
+               fileName = args[0];
+       }
+        (new SendMailGUI(fileName)).setVisible(true);
+    }
+    
+    public SendMailGUI(String propertiesName) throws Exception {
+       Encrypt.PASSWORD_KEY = "hayashihimitukagi";
+        logger = LoggerFactory.getInstance();  // Loggerオブジェクトの生成
+       SendMailGUI.propertiesFileName = propertiesName;
+        SendMailGUI.mailProp = new SiteData(SendMailGUI.propertiesFileName);
+
+        // ログ出力
+        logger.info("SendMailGUI - プログラム起動");
+        
+        // 初期設定
+        fComponentsAdjusted = false;
+        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+        Container container = getContentPane();
+        container.setLayout(new BorderLayout());
+        setTitle("SendMail GUI");
+        
+        mainFrame = this;
+        
+        // [メニュー]->[ファイル(F)]
+        menuFile = new JMenu("ファイル(F)");
+        menuFile.setMnemonic('F');
+        menuFile.setFont(new Font("Dialog", 0, 12));
+        
+        // [メニュー]->[ファイル(F)]->[設定...]
+        miSetting = new JMenuItem("設定...");
+        miSetting.addActionListener(this);
+        miSetting.setFont(new Font("Dialog", 0, 12));
+        menuFile.add(miSetting);
+        
+        // [メニュー]->[ファイル(F)]->[------------]
+        menuFile.addSeparator();
+
+        // [メニュー]->[ファイル(F)]->[終了(X)]
+        miExit = new JMenuItem("終了(X)");
+        miExit.addActionListener(this);
+        miExit.setMnemonic('X');
+        miExit.setFont(new Font("Dialog", 0, 12));
+        menuFile.add(miExit);
+        
+        // [メニュー]
+        mainMenuBar = new JMenuBar();
+        mainMenuBar.add(menuFile);
+        getRootPane().setJMenuBar(mainMenuBar);
+
+        // 上部にヘッダパネル
+        headPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+        getContentPane().add(BorderLayout.NORTH, headPanel);
+        JLabel label1 = new JLabel("SendMail GUI - サンプルプログラム", JLabel.CENTER);
+        label1.setBounds(10,10,340,20);
+        
+        // 中央に、メインパネルを配置
+        JPanel mainPanel = new JPanel(new FlowLayout());
+        //mainPanel.setPreferredSize(new Dimension(500, 400));
+        getContentPane().add(mainPanel, BorderLayout.CENTER);
+        
+        JTextArea textArea = new JTextArea(20, 60);
+        textArea.setEditable(false);
+        textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
+               textArea.append("メール送信設定 サンプルプログラム\n");
+               textArea.setCaretPosition(0);
+               JScrollPane scrollPane = new JScrollPane(textArea);
+               scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+               mainPanel.add(scrollPane, BorderLayout.CENTER);
+        
+        // 下部にコピーライトを配置
+        JPanel southPanel = new JPanel(new FlowLayout());
+        getContentPane().add(BorderLayout.SOUTH, southPanel);
+        
+        JLabel label2 = new JLabel("All rights reserved.Copyright(c) 2010,, Hayashi,Yuu.", JLabel.CENTER);
+        label2.setBounds(10,40,340,20);
+        southPanel.add(label2);
+        
+               pack();
+               setLocationRelativeTo(null);
+               setVisible(true);
+    }
+    
+    public SendMail getMailInstance() {
+               return new SendMail(SendMailGUI.mailProp);
+    }
+    
+    public static String getPropertiesFileName() {
+       return propertiesFileName;
+    }
+
+       public void addNotify() {
+        Dimension d = getSize();
+        super.addNotify();
+        if (fComponentsAdjusted) {
+            return;
+        }
+        setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++) {
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+
+        fComponentsAdjusted = true;
+    }
+
+       /**
+        * [メニュー]アクション: 
+        * @param event
+        */
+       public void actionPerformed(ActionEvent event) {
+        Object object = event.getSource();
+        if(object == miExit) {
+            miExit_Action(event);
+        }
+        else if (object == miSetting) {
+            miSetting_Action(event);
+        }
+    }
+       
+    /**
+     * アクション:
+     * [メニュー]->[ファイル]->[終了]
+     * 
+     * @param event
+     */
+    void miExit_Action(ActionEvent event) {
+       setVisible(false);
+        logger.info("SendMailGUI - プログラム終了");
+        System.exit(0);
+    }
+
+    /**
+     * アクション:
+     * [メニュー]->[ファイル]->[設定...]
+     * 
+     * @param event
+     */
+    void miSetting_Action(ActionEvent event) {
+        try {
+                       (new SettingDialog(this, true, SendMailGUI.getPropertiesFileName(), logger)).setVisible(true);
+               }
+        catch (FileNotFoundException e) {
+                       // 回復不能な重大なエラー
+                       e.printStackTrace();
+               }
+        catch (IOException e) {
+                       // 回復不能な重大なエラー
+                       e.printStackTrace();
+               }
+    }
+}
diff --git a/src/hayashi/yuu/tools/mail/gui/SettingDialog.java b/src/hayashi/yuu/tools/mail/gui/SettingDialog.java
new file mode 100644 (file)
index 0000000..e0dc236
--- /dev/null
@@ -0,0 +1,230 @@
+package hayashi.yuu.tools.mail.gui;
+import hayashi.yuu.tools.properties.Properties;
+import hayashi.yuu.tools.properties.PropertyItem;
+import hayashi.yuu.tools.mail.SendMail;
+import hayashi.yuu.tools.mail.SiteData;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+
+
+/**
+ * <p>アプリケーション設定を行うモーダルダイアログフォーム</p>
+ * <code>
+ * ・タイトルパネル
+ *             "メール送信 設定"
+ * ・メインパネル
+ *             "<メールサーバーの設定>"
+ * ・ボタンパネル
+ *             [OK]ボタン
+ *             [Cancel]ボタン
+ * </code>
+ * @author hayashi
+ *
+ */
+@SuppressWarnings("serial")
+public class SettingDialog extends JDialog implements WindowListener
+{
+    JLabel label1;
+    JLabel label2;
+    JTextArea textArea;
+    JFrame parent;
+    public static Properties prop;
+    public static SetupMailServer mailServerPanel;
+    public static MailAddrPanel mailAddrPanel;
+       public static String fileName;
+       static Logger logger;
+    
+    /*
+     * 設定項目:
+     *         
+     */
+    public SettingDialog(JFrame parent, boolean modal, String propertiesFileName, Logger logger) throws FileNotFoundException, IOException {
+        super(parent, modal);
+        SettingDialog.logger = logger;
+        SettingDialog.fileName = propertiesFileName;
+        
+        // 設定ファイルの読み込み
+        prop = new Properties();
+        prop.load(new FileInputStream(propertiesFileName));
+
+        addWindowListener(this);
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+
+        this.parent = parent;
+        setTitle("設定");
+        getContentPane().setLayout(new BorderLayout());
+        setSize(420, SetupMailServer.CATEGORY_HEIGHT + MailAddrPanel.CATEGORY_HEIGHT + (PropertyItem.LINE_HEIGHT * 9));
+        
+        /*
+         * タイトルパネル
+         */
+               JPanel topPanel = new JPanel();
+        label1 = new JLabel("メール送信 設定", JLabel.CENTER);
+        label1.setBounds(10,10,340,20);
+        topPanel.add(label1);
+        getContentPane().add(topPanel, BorderLayout.NORTH);
+        
+               /*
+                * カテゴリ:[ メールサーバーの設定 ]
+                */
+        mailServerPanel = new SetupMailServer(prop);
+               
+               /*
+                * カテゴリ:[ メールの配信先設定 ]
+                */
+        mailAddrPanel = new MailAddrPanel(prop);
+               
+        /*
+                * メインパネル
+                */
+               JPanel mainPanel = new JPanel();
+               mainPanel.setLayout(new FlowLayout());
+               mainPanel.add(makePanel("メールサーバーの設定", mailServerPanel));
+               mainPanel.add(makePanel("メールの配信先", mailAddrPanel));
+        getContentPane().add(mainPanel, BorderLayout.CENTER);
+
+        /*
+                * [OK]ボタン : このダイアログウインドウを閉じる
+                */
+           JButton saveButton = new JButton("保存");
+        saveButton.setBounds(145,65,66,27);
+        saveButton.addActionListener(new java.awt.event.ActionListener() {
+               public void actionPerformed(java.awt.event.ActionEvent evt) {
+                       try {
+                               SettingDialog.prop.store(new FileOutputStream(SettingDialog.fileName), "SendMail GUI");
+                               }
+                       catch (FileNotFoundException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       catch (IOException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       
+                       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(SettingDialog.this, WindowEvent.WINDOW_CLOSING));
+                       setVisible(false);
+               }
+        });
+
+               /*
+                * [Cancel]ボタン : このダイアログウインドウを閉じる
+                */
+           JButton cancelButton = new JButton("取消");
+           cancelButton.setBounds(145,65,66,27);
+           cancelButton.addActionListener(new java.awt.event.ActionListener() {
+               public void actionPerformed(java.awt.event.ActionEvent evt) {
+                       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(SettingDialog.this, WindowEvent.WINDOW_CLOSING));
+                       setVisible(false);
+               }
+        });
+           
+           /*
+            * [テスト送信]ボタン : テストメールを送信する
+            */
+           JButton testButton = new JButton("テスト送信");
+           testButton.setBounds(145,65,66,27);
+           testButton.addActionListener(new java.awt.event.ActionListener() {
+               public void actionPerformed(java.awt.event.ActionEvent evt) {
+                       SiteData siteData = SettingDialog.mailServerPanel.getSiteData();
+                       SettingDialog.mailAddrPanel.getSiteData(siteData);
+                       SendMail mail = new SendMail(siteData);
+                mail.setSubject("[SendMail] メール送信テスト");
+                mail.setContent("このメールは[SendMail]からのメール送信テストです。");
+                       try {
+                                       mail.send();
+                                       SettingDialog.logger.info("メールを送信しました。");
+                       JOptionPane.showMessageDialog(SendMailGUI.mainFrame, "メールを送信しました。", "成功", JOptionPane.INFORMATION_MESSAGE);
+                               } catch (Exception e) {
+                                       e.printStackTrace();
+                                       SettingDialog.logger.warning("メール送信に失敗しました。");
+                       JOptionPane.showMessageDialog(SendMailGUI.mainFrame, "メールを送信できませんでした。", "失敗", JOptionPane.ERROR_MESSAGE);
+                               }
+               }
+        });
+
+        /*
+                * ボタンパネル
+                */
+               JPanel bottomPanel = new JPanel();
+        bottomPanel.add(saveButton);
+        bottomPanel.add(cancelButton);
+        bottomPanel.add(testButton);
+        getContentPane().add(bottomPanel, BorderLayout.SOUTH);
+    }
+
+       /**
+        * 枠で囲まれたパネル
+        * @param title
+        * @param compo
+        * @return
+        */
+       private JPanel makePanel(String title, JComponent compo) {
+        JPanel p = new JPanel(new GridLayout(1,1));
+        p.setBorder(BorderFactory.createTitledBorder(title));
+        p.add(compo);
+        return p;
+    }
+       
+       public String getPropertiesFilename() {
+               return fileName;
+       }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b  if true, show the component; otherwise, hide the component.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b) {
+        if (b) {
+            Rectangle bounds = getParent().getBounds();
+            Rectangle abounds = getBounds();
+            setLocation(bounds.x + (bounds.width - abounds.width)/ 2, bounds.y + (bounds.height - abounds.height)/2);
+        }
+        super.setVisible(b);
+    }
+
+       public void windowClosed(WindowEvent e) {
+               setVisible(false);
+    }
+
+       public void windowActivated(WindowEvent arg0) {
+       }
+
+       public void windowClosing(WindowEvent arg0) {
+               setVisible(false);
+       }
+
+       public void windowDeactivated(WindowEvent arg0) {
+       }
+
+       public void windowDeiconified(WindowEvent arg0) {
+       }
+
+       public void windowIconified(WindowEvent arg0) {
+       }
+
+       public void windowOpened(WindowEvent arg0) {
+       }
+}
diff --git a/src/hayashi/yuu/tools/mail/gui/SetupMailServer.java b/src/hayashi/yuu/tools/mail/gui/SetupMailServer.java
new file mode 100644 (file)
index 0000000..0c2c387
--- /dev/null
@@ -0,0 +1,169 @@
+package hayashi.yuu.tools.mail.gui;
+
+import hayashi.yuu.tools.properties.Properties;
+import hayashi.yuu.tools.properties.PropertyCheckItem;
+import hayashi.yuu.tools.properties.PropertyFieldItem;
+import hayashi.yuu.tools.properties.PropertyItem;
+import hayashi.yuu.tools.properties.PropertyPasswordItem;
+import hayashi.yuu.tools.mail.SiteData;
+
+import java.awt.Dimension;
+
+import javax.swing.BoxLayout;
+import javax.swing.JPanel;
+
+
+
+/**
+ * セットアップフォーム:[]
+ *     ・メール送信に関する設定
+ * (1)アイテム: [ mail.smtp.host : SMPTサーバー ]
+ * (2)アイテム: [ mail.smtp.port : SMPTサーバーのポート番号 ]
+ * (3)アイテム: [ MAIL_POP : POPサーバー ]
+ * (4)アイテム: [ mail.smtp.user : ユーザーID ]
+ * (5)アイテム: [ MAIL_PASSWORD : パスワード ]
+ * (6)アイテム: [ mail.smtp.auth : SMTP auth 認証 ]
+ * (7)アイテム: [ mail.smtp.starttls.enable : STARTTLS ]
+ * (8)アイテム: [ MAIL_POP_before_SMTP : POP before SMTP ]
+ * (9)アイテム: [ mail.smtp.from ]
+ */
+@SuppressWarnings("serial")
+public class SetupMailServer extends JPanel
+{
+    public static final int LINE_COUNT = 9;
+    public static final int CATEGORY_HEIGHT = PropertyItem.LINE_HEIGHT * LINE_COUNT;
+    PropertyFieldItem ismtp;           // 'mail.smtp.host' SMTPサーバー
+    PropertyFieldItem ismtpPort;       // 'mail.smtp.port' SMTPサーバーのポート番号(25)
+    PropertyFieldItem iPop;                    // 'MAIL_POP' POPサーバー
+    PropertyFieldItem iuser;           // 'mail.smtp.user' ユーザーID
+    PropertyPasswordItem ipassword;    // 'MAIL_PASSWORD' パスワード
+       PropertyCheckItem checkMailSMTPauth;    // 'mail.smtp.auth' : SMTP auth 認証
+       PropertyCheckItem checkSTARTTLS;        // 'mail.smtp.starttls.enable' : STARTTLS
+       PropertyCheckItem checkPOPbeforeSMTP;   // 'MAIL_POP_before_SMTP : "POP before SMTP'
+    PropertyFieldItem iFrom;           // 'mail.smtp.from' メール発信元アドレス
+    
+       public SetupMailServer(Properties prop) {
+               super();
+
+               /*
+                * カテゴリの配置
+                */
+           setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+           /*
+            * (1)アイテム: [ mail.smtp.host : SMPTサーバー ]
+            */
+           ismtp = new PropertyFieldItem(prop, "mail.smtp.host", "SMPTサーバー", true);
+               add(ismtp);
+               ismtp.setBounds(0, PropertyItem.LINE_HEIGHT * 0, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+
+           /*
+            * (2)アイテム: [ mail.smtp.port : SMPTサーバーのポート番号 ]
+            */
+           ismtpPort = new PropertyFieldItem(prop, "mail.smtp.port", "ポート番号", true);
+               add(ismtpPort);
+               ismtpPort.setBounds(0, PropertyItem.LINE_HEIGHT * 1, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+
+               /*
+                * (3)アイテム: [ MAIL_POP : POPサーバー ]
+                */
+               iPop = new PropertyFieldItem(prop, "MAIL_POP", "POPサーバー", true);
+               add(iPop);
+               iPop.setBounds(0, PropertyItem.LINE_HEIGHT * 2, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+
+               /*
+                * (4)アイテム: [ mail.smtp.user : ユーザーID ]
+                */
+               iuser = new PropertyFieldItem(prop, "mail.smtp.user", "ユーザーID", true);
+               add(iuser);
+               iuser.setBounds(0, PropertyItem.LINE_HEIGHT * 3, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+
+               /*
+                * (5)アイテム: [ MAIL_PASSWORD : パスワード ]
+                */
+               ipassword = new PropertyPasswordItem(prop, "MAIL_PASSWORD", "パスワード", true);
+               add(ipassword);
+               ipassword.setBounds(0, PropertyItem.LINE_HEIGHT * 4, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+               
+               /*
+                * (6)アイテム: [ mail.smtp.auth : SMTP auth 認証 ]
+                */
+               checkMailSMTPauth = new PropertyCheckItem(prop, "mail.smtp.auth", "SMTP auth 認証", false, true);
+               add(checkMailSMTPauth);
+               checkMailSMTPauth.setBounds(PropertyItem.ITEM_WIDTH_1, PropertyItem.LINE_HEIGHT * 5, PropertyItem.ITEM_WIDTH_2, PropertyItem.LINE_HEIGHT);
+
+               /*
+                * (7)アイテム: [ mail.smtp.starttls.enable : STARTTLS ]
+                */
+               checkSTARTTLS = new PropertyCheckItem(prop, "mail.smtp.starttls.enable", "STARTTLS", false, true);
+               add(checkSTARTTLS);
+               checkSTARTTLS.setBounds(PropertyItem.ITEM_WIDTH_1, PropertyItem.LINE_HEIGHT * 6, PropertyItem.ITEM_WIDTH_2, PropertyItem.LINE_HEIGHT);
+
+               /*
+                * (8)アイテム: [ MAIL_POP_before_SMTP : POP before SMTP ]
+                */
+               checkPOPbeforeSMTP = new PropertyCheckItem(prop, "MAIL_POP_before_SMTP", "POP before SMTP", false, true);
+               add(checkPOPbeforeSMTP);
+               checkPOPbeforeSMTP.setBounds(PropertyItem.ITEM_WIDTH_1, PropertyItem.LINE_HEIGHT * 7, PropertyItem.ITEM_WIDTH_2, PropertyItem.LINE_HEIGHT);
+               
+               /*
+                * (9)アイテム: [ mail.smtp.from ]
+                */
+               iFrom = new PropertyFieldItem(prop, "mail.smtp.from", "発信元アドレス", true);
+               add(iFrom);
+               iFrom.setBounds(0, PropertyItem.LINE_HEIGHT * 8, PropertyItem.LINE_WIDTH, PropertyItem.LINE_HEIGHT);
+               
+               setPreferredSize(new Dimension(PropertyItem.LINE_WIDTH, CATEGORY_HEIGHT));
+       }
+       
+       public SiteData getSiteData() {
+               SiteData data = new SiteData("");
+
+               /*
+            * (1)アイテム: [ MAIL_SMTP : SMPTサーバー ]
+            */
+               data.MAIL_SMTP = ismtp.getValue();
+               
+           /*
+            * (2)アイテム: [ MAIL_SMTP_PORT : SMPTサーバーのポート番号 ]
+            */
+           data.MAIL_SMTP_PORT = ismtpPort.getValue();
+
+               /*
+                * (3)アイテム: [ MAIL_POP : POPサーバー ]
+                */
+               data.MAIL_POP = iPop.getValue();
+               
+               /*
+                * (4)アイテム: [ MAIL_USER_ID : ユーザーID ]
+                */
+               data.USER_ID = iuser.getValue();
+
+               /*
+                * (5)アイテム: [ MAIL_PASSWORD : パスワード ]
+                */
+               data.PASSWORD = ipassword.getValue();
+               
+               /*
+                * (6)アイテム: [ mail.smtp.auth : SMTP auth 認証 ]
+                */
+               data.USER_AUTH = checkMailSMTPauth.isSelected();
+
+               /*
+                * (7)アイテム: [ mail.smtp.starttls.enable : STARTTLS ]
+                */
+               data.STARTTLS = checkSTARTTLS.isSelected();
+
+               /*
+                * (8)アイテム: [ MAIL_POP_before_SMTP : POP before SMTP ]
+                */
+               data.POP_before_SMTP = checkPOPbeforeSMTP.isSelected();
+               
+               /*
+                * (9)アイテム: [ MAIL_FROM ]
+                */
+               data.MAIL_FROM = iFrom.getValue();
+               
+               return data;
+       }
+}
diff --git a/src/hayashi/yuu/tools/mail/gui/gmail.png b/src/hayashi/yuu/tools/mail/gui/gmail.png
new file mode 100644 (file)
index 0000000..d852c8e
Binary files /dev/null and b/src/hayashi/yuu/tools/mail/gui/gmail.png differ
diff --git a/src/hayashi/yuu/tools/mail/gui/package.html b/src/hayashi/yuu/tools/mail/gui/package.html
new file mode 100644 (file)
index 0000000..4d661d7
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Eメール送信 GUI</title>
+</head>
+<body>
+<code>Eメールを送信するためのGUIクラス群<br/>
+<br/>
+<img src="gmail.png"/><br/>
+<br/>
+<b>関連ライブラリ</b><br/>
+&nbsp;&nbsp;&nbsp;&nbsp;'<a href="http://java.sun.com/products/javamail/javadocs/index.html">JavaMail API</a>'&nbsp;mail-1.4.jar&nbsp;activation-1.1.jar<br/>
+<b>関連パッケージ</b><br/>
+&nbsp;&nbsp;&nbsp;&nbsp;hayashi.yuu.tools.mail
+</code>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/hayashi/yuu/tools/mail/gui/so-net.png b/src/hayashi/yuu/tools/mail/gui/so-net.png
new file mode 100644 (file)
index 0000000..f25b28d
Binary files /dev/null and b/src/hayashi/yuu/tools/mail/gui/so-net.png differ
diff --git a/src/hayashi/yuu/tools/mail/package.html b/src/hayashi/yuu/tools/mail/package.html
new file mode 100644 (file)
index 0000000..bf79386
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Eメール送信</title>
+</head>
+<body>
+<code>
+Eメールを送信するためのクラス群<BR/>
+<BR/>
+<b>関連ライブラリ</b><br/>
+&nbsp;&nbsp;&nbsp;&nbsp;'<a href="http://java.sun.com/products/javamail/javadocs/index.html">JavaMail API</a>'&nbsp;mail-1.4.jar&nbsp;activation-1.1.jar
+</code>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/hayashi/yuu/tools/properties/CategoryBox.java b/src/hayashi/yuu/tools/properties/CategoryBox.java
new file mode 100644 (file)
index 0000000..6e06352
--- /dev/null
@@ -0,0 +1,24 @@
+package hayashi.yuu.tools.properties;
+
+import java.awt.GridLayout;
+import javax.swing.BorderFactory;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+
+/**
+ * 枠で囲まれたパネル
+ */
+public class CategoryBox {
+       /**
+        * 枠で囲まれたパネル
+        * @param title パネルのタイトル
+        * @param compo パネルの内容
+        * @return 作成されたインスタンス
+        */
+       public static JPanel makePanel(String title, JComponent compo) {
+        JPanel p = new JPanel(new GridLayout(1,1));
+        p.setBorder(BorderFactory.createTitledBorder(title));
+        p.add(compo);
+        return p;
+    }
+}
diff --git a/src/hayashi/yuu/tools/properties/Encrypt.java b/src/hayashi/yuu/tools/properties/Encrypt.java
new file mode 100644 (file)
index 0000000..51ca7a4
--- /dev/null
@@ -0,0 +1,181 @@
+package hayashi.yuu.tools.properties;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
+
+/**
+ * 暗号化モドキ
+ * @author Hayashi,Yuu
+ * @version 2010/02/07
+ * @since 2009/01/27
+ */
+public class Encrypt
+{
+       /**
+        * @param args
+        */
+    public static void main(String[] args) {
+       String source = "deister07";
+        System.out.println("source \"" + source + "\"");
+        try {
+               Encrypt.PASSWORD_KEY = "hayashihimitukagi";
+               
+            // 暗号化
+               String encStr = encrypt(source);
+            System.out.println("encStr \"" + encStr + "\"");
+
+            // 復号
+            String decStr = decode(encStr);
+            System.out.println("decodeStr \"" + decStr + "\"");
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+       // ソルト
+       private static final byte[] SALT = {(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99};
+       private static final int NUM = 128;             // 繰り返し回数
+       
+       /**
+        * 暗号化のための秘密鍵
+        * 心配性の人は、この値を変えてください。
+        */
+       public static String PASSWORD_KEY = "himitukagi";               // 秘密鍵
+
+       /**
+     * 指定された文字列を暗号化する。
+     * @param source   暗号化したい文字列
+     * @return 暗号化された文字列
+     * @throws NoSuchAlgorithmException 
+     * @throws NoSuchPaddingException
+     * @throws InvalidKeyException 
+     * @throws BadPaddingException 
+     * @throws IllegalBlockSizeException 
+        * @throws InvalidKeySpecException 
+        * @throws InvalidAlgorithmParameterException 
+     */
+    public static String encrypt(String source) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, InvalidAlgorithmParameterException {
+               //16進数化
+               return toHexString(encrypt(source.getBytes()));
+    }
+    
+    /**
+     * 指定されたバイト配列を暗号化する。
+     * @param source   暗号化したいバイト配列
+     * @return 暗号化されたバイト配列
+     * @throws NoSuchAlgorithmException
+     * @throws NoSuchPaddingException
+     * @throws InvalidKeyException
+     * @throws IllegalBlockSizeException
+     * @throws BadPaddingException
+     * @throws InvalidKeySpecException
+     * @throws InvalidAlgorithmParameterException
+     */
+    public static byte[] encrypt(byte[] source) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, InvalidAlgorithmParameterException {
+               PBEParameterSpec pbeParam = new PBEParameterSpec(SALT, NUM);
+                   
+               char[] pass = PASSWORD_KEY.toCharArray();
+               PBEKeySpec pbeKey = new PBEKeySpec(pass);
+               SecretKeyFactory secKeys = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
+               SecretKey secKey = secKeys.generateSecret(pbeKey);
+               
+               Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
+               cipher.init(Cipher.ENCRYPT_MODE, secKey, pbeParam);
+               
+               //暗号化
+               return cipher.doFinal(source);
+    }
+    
+    /**
+     * 復号
+     * @param source   暗号化された文字列
+     * @return 復号された文字列
+     * @throws NoSuchAlgorithmException 
+     * @throws InvalidKeySpecException 
+     * @throws NoSuchPaddingException 
+     * @throws InvalidAlgorithmParameterException
+     * @throws InvalidKeyException 
+     * @throws BadPaddingException
+     * @throws IllegalBlockSizeException 
+     */
+    public static String decode(String source) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
+       if (source == null) {
+               return null;
+       }
+               byte[] bytepass = toHexBin(source);
+               return new String(decode(bytepass));
+    }
+
+    /**
+     * 復号
+     * @param source   暗号化されたバイト配列
+     * @return 復号されたバイト配列
+     * @throws NoSuchAlgorithmException
+     * @throws InvalidKeySpecException
+     * @throws NoSuchPaddingException
+     * @throws InvalidKeyException
+     * @throws InvalidAlgorithmParameterException
+     * @throws IllegalBlockSizeException
+     * @throws BadPaddingException
+     */
+    public static byte[] decode(byte[] source) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
+               // PBE を新たに生成
+        PBEParameterSpec pbeParamSpecDec = new PBEParameterSpec(SALT, NUM);
+        
+        PBEKeySpec pbeKeySpecDec = new PBEKeySpec(PASSWORD_KEY.toCharArray());
+        SecretKeyFactory keyFacDec = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
+        SecretKey pbeKeyDec = keyFacDec.generateSecret(pbeKeySpecDec);
+
+        Cipher cDec = Cipher.getInstance("PBEWithMD5AndDES");
+        cDec.init(Cipher.DECRYPT_MODE, pbeKeyDec, pbeParamSpecDec);
+        
+        return cDec.doFinal(source);
+    }
+
+
+    /**
+     * バイナリ配列を文字列に変換する。
+     * 
+     * @param bs       バイト配列(バイナリ)
+     * @return 16進表現文字列
+     */
+       private static String toHexString(byte[] binStr) {
+               StringBuffer buffer = new StringBuffer(binStr.length * 2);
+               for (int i = 0; i < binStr.length; i++) {
+                       if ((binStr[i] >= 0) && (binStr[i] < 0x10)) {
+                               buffer.append('0');
+                       }
+                       buffer.append(Integer.toHexString(0xff & binStr[i]));
+               }
+               return buffer.toString();
+       }
+
+    /**
+     * バイナリ文字列をバイナリ配列に変換する。
+     * 
+     * @param bs       16進表現文字列
+     * @return バイナリ配列
+     */
+       private static byte[] toHexBin(String binStr) {
+               byte[] bin = new byte[binStr.length() / 2];
+               
+               StringBuffer sbuf = new StringBuffer(binStr);
+               for (int i = 0; i < bin.length; i++) {
+                       String s = sbuf.substring(i*2, i*2+2).toUpperCase();
+                       bin[i] = (byte)Integer.parseInt(s, 16);
+               }
+               return bin;
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/Properties.java b/src/hayashi/yuu/tools/properties/Properties.java
new file mode 100644 (file)
index 0000000..323752e
--- /dev/null
@@ -0,0 +1,102 @@
+package hayashi.yuu.tools.properties;
+
+import java.util.Vector;
+
+/**
+ * Hayashiライブラリ専用のプロパティファイル
+ * 特定の項目(パスワードなど)を暗号化してファイルに記録する。
+ * 読み出し時には復号化します。
+ * その他の項目は通常のPropertiesと同じ処理のままです。
+ * @author Hayashi,Yuu
+ * @version 2010/02/07
+ * @since 2009/01/27
+ */
+@SuppressWarnings("serial")
+public class Properties extends java.util.Properties
+{
+       private Vector<String> passwords = new Vector<String>();
+
+       public Properties() {
+               super();
+               passwords.add("MAIL_PASSWORD");
+       }
+
+       public Properties(Properties defaults) {
+               super(defaults);
+               passwords.add("MAIL_PASSWORD");
+       }
+       
+       /**
+        * 暗号化処理を行うプロパティ項目を指定する。
+        * @param itemStr       プロパティ項目名
+        */
+       public void setPasswordItem(String itemStr) {
+               passwords.add(itemStr);
+       }
+
+       /**
+        * プロパティ値を設定する
+        * @param key プロパティ項目名
+        * @param value 設定値
+        * @return プロパティインスタンス
+        */
+       @Override
+       public synchronized Object setProperty(String key, String value) {
+               try {
+                       for (String pwItem : passwords) {
+                               if (key.equals(pwItem)) {
+                                       return super.setProperty(key, Encrypt.encrypt(value));
+                               }
+                       }
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return super.setProperty(key, value);
+       }
+
+       /**
+        * 指定されたキーを持つプロパティを、プロパティリストから探します。そのキーがプロパティリストにないと、
+        * デフォルトのプロパティリスト、さらにそのデフォルト値が繰り返し調べられます。
+        * そのプロパティが見つからない場合は、デフォルト値の引数が返されます。
+        * @param key プロパティ項目名
+        * @param defaultValue 指定されたプロパティ項目に値が設定されていなかったときに代わりに得られる値
+        * @return 値。値が設定されていなかった時にはdefaultValue。
+        */
+       @Override
+       public String getProperty(String key, String defaultValue) {
+               try {
+                       for (String pwItem : passwords) {
+                               if (key.equals(pwItem)) {
+                                       return Encrypt.decode(super.getProperty(key, Encrypt.encrypt(defaultValue)));
+                               }
+                       }
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return super.getProperty(key, defaultValue);
+       }
+
+       /**
+        * 指定されたキーを持つプロパティを、プロパティリストから探します。そのキーがプロパティリストにないと、
+        * デフォルトのプロパティリスト、さらにそのデフォルト値が繰り返し調べられます。そのプロパティが見つから
+        * ない場合は、null が返されます
+        * @param key プロパティ項目名
+        * @return 値。値が設定されていなかった時にはnull。
+        */
+       @Override
+       public String getProperty(String key) {
+               try {
+                       for (String pwItem : passwords) {
+                               if (key.equals(pwItem)) {
+                                       return Encrypt.decode(super.getProperty(key));
+                               }
+                       }
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return super.getProperty(key);
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/PropertyCheckItem.java b/src/hayashi/yuu/tools/properties/PropertyCheckItem.java
new file mode 100644 (file)
index 0000000..d1725db
--- /dev/null
@@ -0,0 +1,56 @@
+package hayashi.yuu.tools.properties;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+
+
+@SuppressWarnings("serial")
+public class PropertyCheckItem extends hayashi.yuu.tools.properties.PropertyItem {
+
+       public PropertyCheckItem(hayashi.yuu.tools.properties.Properties prop, String name, String title, boolean value, boolean editable) {
+               super(prop, name, title, editable);
+               field = new JCheckBox(title, Boolean.parseBoolean(prop.getProperty(name, "false")));
+               ((JCheckBox)field).addActionListener(this);
+               createItem(name, title, prop.getProperty(name), editable);
+       }
+
+       @Override
+       void setupField(String name, String value, boolean editable) {
+               this.value = value;
+               ((JCheckBox)field).setSelected(Boolean.valueOf(value));
+               if (!editable) {
+                       field.setEnabled(editable);
+               }
+               add(field);
+       }
+       
+       public boolean isSelected() {
+               return ((JCheckBox)field).isSelected();
+       }
+       
+       @Override
+       JLabel setupLabel(String name, String value) {
+               label = new JLabel(name, JLabel.RIGHT);
+               //add(label);
+               return label;
+       }
+
+       @Override
+       void createItem(String name, String title, String value, boolean editable) {
+               setupLabel(title, value);
+               setupField(title, value, editable);
+               
+               //label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT);
+               field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT);
+               setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT));
+       }
+       
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               this.value = Boolean.toString(((JCheckBox)field).isSelected());
+               logger.info("[反映] "+ propertyName +" = "+ this.value);
+               this.prop.setProperty(propertyName, this.value);
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/PropertyFieldItem.java b/src/hayashi/yuu/tools/properties/PropertyFieldItem.java
new file mode 100644 (file)
index 0000000..d097545
--- /dev/null
@@ -0,0 +1,48 @@
+package hayashi.yuu.tools.properties;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import javax.swing.JTextField;
+
+@SuppressWarnings("serial")
+public class PropertyFieldItem extends PropertyItem implements FocusListener
+{
+       public PropertyFieldItem(hayashi.yuu.tools.properties.Properties prop, String name, String title, boolean editable) {
+               super(prop, name, title, editable);
+               field = new JTextField(value, 20);
+               ((JTextField)field).addFocusListener(this);
+               createItem(name, title, prop.getProperty(name), editable);
+       }
+
+       @Override
+       void setupField(String name, String value, boolean editable) {
+               this.value = value;
+               ((JTextField)field).setText(value);
+               if (!editable) {
+                       field.setEnabled(editable);
+               }
+               add(field);
+       }
+
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               this.value = ((JTextField)this.field).getText();
+               logger.info("[反映] "+ propertyName +" = "+ this.value);
+               prop.setProperty(propertyName, this.value);
+       }
+
+       /**
+        * このフィールドにカーソルが移ったときの処理
+        */
+       public void focusGained(FocusEvent arg0) {
+               // 何もしない
+       }
+
+       /**
+        * このフィールドから他のフィールドへカーソルが移った時の処理。
+        */
+       public void focusLost(FocusEvent arg0) {
+               actionPerformed(null);
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/PropertyItem.java b/src/hayashi/yuu/tools/properties/PropertyItem.java
new file mode 100644 (file)
index 0000000..5202856
--- /dev/null
@@ -0,0 +1,90 @@
+package hayashi.yuu.tools.properties;
+
+import hayashi.yuu.tools.logger.LoggerFactory;
+import hayashi.yuu.tools.properties.Properties;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.logging.Logger;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+/**
+ * プロパティ項目をGUIで操作する。
+ * @author hayashi
+ * @version 2010/02/07
+ * @since 2010/02/04
+ */
+@SuppressWarnings("serial")
+public abstract class PropertyItem extends JPanel implements ActionListener {
+       hayashi.yuu.tools.properties.Properties prop;
+       String propertyName;
+       JLabel label;
+       JComponent field;
+       String value;
+       Logger logger;
+       public static final int ITEM_WIDTH_1 = 160;
+       public static final int ITEM_WIDTH_2 = 240;
+    public static final int LINE_WIDTH = ITEM_WIDTH_1 + ITEM_WIDTH_2;
+    public static final int LINE_HEIGHT = 18;
+       
+    /**
+     * コンストラクタ
+     * @param prop
+     * @param name
+     * @param editable
+     */
+       public PropertyItem(Properties prop, String name, String title, boolean editable) {
+               super(null);
+               logger = LoggerFactory.getInstance();
+               this.propertyName = name;
+               this.prop = prop;
+       }
+       
+       void createItem(String name, String title, String value, boolean editable) {
+               setupLabel(title, value);
+               setupField(name, value, editable);
+               
+               label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT);
+               field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT);
+               setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT));
+       }
+       
+       JLabel setupLabel(String title, String value) {
+               label = new JLabel(title, JLabel.RIGHT);
+               add(label);
+               return label;
+       }
+       
+       public String getValue() {
+               return value;
+       }
+       
+       /**
+        * コーディング例:
+        * 
+        *      void setupField(String name, String title, String value, boolean editable) {
+        *              this.value = value;
+        *              ((JTextField)field).setText(value);
+        *              field.setFont(new Font("MS UI Gothic", Font.PLAIN, 12));
+        *              if (!editable) {
+        *                      field.setEnabled(editable);
+        *              }
+        *              add(field);
+        *      }
+        */
+       abstract void setupField(String name, String value, boolean editable);
+
+       /**
+        * [反映]ボタンがクリックされたときの処理
+        *      
+        *      public void actionPerformed(ActionEvent e) {
+        *              System.out.println("[反映] "+ label.getText() +" = "+ text.getText());
+        *              prop.setProperty(label.getText(), text.getText());
+        *      }
+        * @param e
+        */
+       public abstract void actionPerformed(ActionEvent e);
+}
diff --git a/src/hayashi/yuu/tools/properties/PropertyPasswordItem.java b/src/hayashi/yuu/tools/properties/PropertyPasswordItem.java
new file mode 100644 (file)
index 0000000..b980764
--- /dev/null
@@ -0,0 +1,49 @@
+package hayashi.yuu.tools.properties;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import javax.swing.JPasswordField;
+
+@SuppressWarnings("serial")
+public class PropertyPasswordItem extends PropertyItem implements FocusListener
+{
+       public PropertyPasswordItem(hayashi.yuu.tools.properties.Properties prop, String name, String title, boolean editable) {
+               super(prop, name, title, editable);
+               field = new JPasswordField(value, 20);
+               ((JPasswordField)field).addFocusListener(this);
+               createItem(name, title, prop.getProperty(name), editable);
+       }
+
+       @Override
+       void setupField(String name, String value, boolean editable) {
+               this.value = value;
+               ((JPasswordField)field).setText(value);
+               if (!editable) {
+                       field.setEnabled(editable);
+               }
+               add(field);
+       }
+       
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               char[] chars = ((JPasswordField)this.field).getPassword();
+               this.value = new String(chars);
+               logger.info("[反映] "+ propertyName +" = "+ this.value);
+               prop.setProperty(propertyName, this.value);
+       }
+
+       /**
+        * このフィールドにカーソルが移ったときの処理
+        */
+       public void focusGained(FocusEvent arg0) {
+               // 何もしない
+       }
+
+       /**
+        * このフィールドから他のフィールドへカーソルが移った時の処理。
+        */
+       public void focusLost(FocusEvent arg0) {
+               actionPerformed(null);
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/PropertySelectItem.java b/src/hayashi/yuu/tools/properties/PropertySelectItem.java
new file mode 100644 (file)
index 0000000..7f2912e
--- /dev/null
@@ -0,0 +1,35 @@
+package hayashi.yuu.tools.properties;
+
+import java.awt.event.ActionEvent;
+import javax.swing.JComboBox;
+
+@SuppressWarnings("serial")
+public class PropertySelectItem extends PropertyItem {
+
+       public PropertySelectItem(hayashi.yuu.tools.properties.Properties prop, String name, String title, boolean editable, String[] items) {
+               super(prop, name, title, editable);
+               field = new JComboBox();
+               ((JComboBox)field).addActionListener(this);
+               for (int i=0; i < items.length; i++) {
+                       ((JComboBox)field).addItem(items[i]);
+               }
+               createItem(name, title, prop.getProperty(name), editable);
+       }
+
+       void setupField(String name, String value, boolean editable) {
+               this.value = value;
+               ((JComboBox)field).setSelectedItem(value);
+
+               if (!editable) {
+                       field.setEnabled(editable);
+               }
+               add(field);
+       }
+       
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               this.value = (String) ((JComboBox)this.field).getSelectedItem();
+               logger.info("[反映] "+ propertyName +" = "+ this.value);
+               prop.setProperty(propertyName, this.value);
+       }
+}
diff --git a/src/hayashi/yuu/tools/properties/package.html b/src/hayashi/yuu/tools/properties/package.html
new file mode 100644 (file)
index 0000000..2bc2595
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>properties</title>
+</head>
+<body>
+<p>プロパティファイル(properties)の操作</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/jp/co/areaweb/tools/command/Command.java b/src/jp/co/areaweb/tools/command/Command.java
new file mode 100644 (file)
index 0000000..7e1917c
--- /dev/null
@@ -0,0 +1,171 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+
+public class Command
+{
+    public static final boolean debug = false;
+    private java.lang.String cmd;    /** プロパティ cmd(実行するコマンドライン)。 */
+    private java.io.File workDir;   /** プロパティ workDir の値 */
+    private BufferedReader stdReader = null;   // 標準出力
+    private BufferedReader errReader = null;   // エラー出力
+    
+    /** 
+     * コマンドを実行しその出力ストリームを取得
+     * @exception IOException I/Oエラーが発生した場合
+     * @exception EDException EDMICSコマンドでエラーが発生した場合
+     */
+    public void execCommand() throws IOException {
+        if (debug){
+            System.out.println("[Command s] " + cmd);
+        }
+
+        if ((getCmd() == null) || getCmd().equals("")) {
+            return;
+        }
+
+        // コマンドを実行
+        Process process;
+        if (getWorkDir() == null) {
+            process = Runtime.getRuntime().exec(getCmd());
+        }
+        else {
+            process = Runtime.getRuntime().exec(getCmd(), null, getWorkDir());
+        }
+        try { 
+            process.waitFor();  // コマンド終了まで待機
+        } catch (InterruptedException e) {}
+
+        if (debug) {
+            System.out.println("[Command e] "+ getCmd() +"\n");
+        }
+
+        // コマンド標準エラー出力を取得
+        this.errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+        // コマンド標準出力の入力ストリームを取得
+        this.stdReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+        return;
+    }
+    
+    /**
+     *  コマンド実行結果
+     *  標準出力とエラー出力の結果を合成してかえす。
+     *  よって、本メソッドを実行するとgetStdout(),getErrout()は無効になる
+     *  このメソッドは、execCommand()メソッドを実行した直後の1回目の実行結果のみ有効
+     */
+    public String getOutput() throws IOException {
+        String std = getStdout();
+        if (std.equals("")) {
+            return getErrout();
+        }
+        else {
+            return std +"\n"+ getErrout();
+        }
+    }
+    
+    /**
+     *  コマンド実行結果の標準出力
+     *  このメソッドは、execCommand()メソッドを実行した直後の1回目の実行結果のみ有効
+     */
+    public String getStdout() throws IOException {
+        return convBufferedReader(this.stdReader);
+    }
+    
+    /**
+     *  コマンド実行結果のエラー出力
+     *  このメソッドは、execCommand()メソッドを実行した直後の1回目の実行結果のみ有効
+     */
+    public String getErrout() throws IOException {
+        return convBufferedReader(this.errReader);
+    }
+    
+    private static String convBufferedReader(BufferedReader reader) throws IOException {
+        if (reader == null) {
+            return "";
+        }
+        StringBuffer strbuf = new StringBuffer();
+        for (String line; (line = reader.readLine()) != null; strbuf.append(line +"\n"));
+        reader.close();
+        reader = null;
+        return strbuf.toString();
+    }
+    
+    /** プロパティ cmd の取得メソッド。
+     * @return プロパティ cmd の値。
+     */
+    public String getCmd() {
+        return cmd;
+    }
+    
+    /** プロパティ cmd の設定メソッド。
+     * @param cmd プロパティ cmd の新しい値。
+     */
+    public void setCmd(String cmd) {
+        this.cmd = cmd;
+    }
+    
+    /** プロパティ workDir の取得メソッド。
+     * @return プロパティ workDir の値。
+     */
+    public java.io.File getWorkDir() {
+        return workDir;
+    }
+    
+    /** プロパティ workDir の設定メソッド。
+     * @param workDir プロパティ workDir の新しい値。
+     */
+    public void setWorkDir(java.io.File workDir) {
+        this.workDir = workDir;
+    }
+
+    /** 
+    *  サンプル
+    */
+    static public void main(String[] args) {
+        if (args.length < 1) {
+            System.out.println("exp: java tool.job.Command [commandLine]");
+            return;
+        }
+        String commandLine = "";
+        for (int i=0; i < args.length; i++) {
+            if (i != 0) {
+                commandLine += " ";
+            }
+            commandLine += args[i];
+        }
+
+        // エラー結果と実行結果を別々に取り出す
+        System.out.println(commandLine);
+        Command command = new Command();
+        String stdout = "";
+        String errout = "";
+        try {
+            command.setCmd(commandLine);
+            command.setWorkDir(null);
+            command.execCommand();
+            stdout = command.getStdout();
+            errout = command.getErrout();
+            System.out.println("STD_OUT:");
+            System.out.println(stdout);
+            System.out.println("STD_ERROR:");
+            System.out.println(errout);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        // エラー結果と実行結果をいっしょに取り出す
+        System.out.println(commandLine);
+        command = new Command();
+        try {
+            command.setCmd(commandLine);
+            command.setWorkDir(null);
+            command.execCommand();
+            System.out.println(command.getOutput());
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/src/jp/co/areaweb/tools/command/DeleteOldFile.java b/src/jp/co/areaweb/tools/command/DeleteOldFile.java
new file mode 100644 (file)
index 0000000..2d7b268
--- /dev/null
@@ -0,0 +1,92 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+import java.util.Calendar;
+
+/**
+ * 指定されたディレクトリ内にある、指定時刻以前に更新されたファイルを削除する。<br/>
+ * java jp.co.areaweb.tools.command.DeleteOldFile [directory] [CCYY.MM.DD-HH:mm:ss]<br/>
+ * <br/>
+ * 指定されたディレクトリ内にある、現在の時刻よりday日以前に更新されたファイルを削除する。<br/>
+ * jp.co.areaweb.tools.command.DeleteOldFile [directory] -day [day]<br/>
+ * <br/>
+ * (注意)<br/>
+ * 指定されたディレクトリのサブディレクトリ内のファイルも削除対象とします。<br/>
+ * ディレクトリ自身は削除されません。<br/>
+ */
+public class DeleteOldFile
+{
+    public static void main (String args[]) {
+        if (args.length < 2) {
+            System.out.println("jp.co.areaweb.tools.command.DeleteOldFile [directory] [CCYY.MM.DD-HH:mm:ss]");
+            return;
+        }
+        
+        if (args[1].equals("-day")) {
+                       if (args.length < 3) {
+                               System.out.println("jp.co.areaweb.tools.command.DeleteOldFile [directory] -day [day]");
+                               return;
+                       }
+                       
+                       int date = 0;
+                       try {
+                               date = Integer.parseInt(args[2]);
+                       }
+                       catch(NumberFormatException e) {
+                               System.out.println("jp.co.areaweb.tools.command.DeleteOldFile [directory] -day [day]");
+                               return;
+                       }
+                       Calendar cal = Calendar.getInstance();
+                       cal.add(Calendar.DATE, date*(-1));
+                       try {
+                               DeleteOldFile.listup(new File(args[0]), cal.getTime());
+                       }
+                       catch(IOException e) {
+                               e.printStackTrace();
+                               System.out.println(e.toString());
+                       }
+        }
+        else {
+                       try {
+                               SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd'-'hh:mm:ss");
+                               Date startTime = sdf.parse(args[1], new ParsePosition(0));
+
+                               DeleteOldFile.listup(new File(args[0]), startTime);
+                       }
+                       catch(Exception e) {
+                               e.printStackTrace();
+                               System.out.println(e.toString());
+                       }
+        }
+    }
+    
+    public static void listup(File file, Date startTime) throws IOException {
+        if (file == null) {
+            System.out.println("ERROR: ディレクトリが見つかりませんでした。");
+            return;
+        }
+        
+        if (file.isDirectory()) {
+            File files[] = file.listFiles();
+            if (files != null) {
+                for (int i=0; i < files.length; i++) {
+                    listup(files[i], startTime);    // 再帰呼び出し
+                }
+            }
+        }
+        else {
+            if ((new Date(file.lastModified())).before(startTime)) {
+                System.out.print(file.getAbsolutePath());
+                if (file.delete()) {
+                                       System.out.println(" ... [DELETE]");
+                }
+                else {
+                                       System.out.println(" ... [ERROR!]");
+                }
+            }
+        }
+        return;
+    }
+}
diff --git a/src/jp/co/areaweb/tools/command/DirSize.java b/src/jp/co/areaweb/tools/command/DirSize.java
new file mode 100644 (file)
index 0000000..f5bdf6b
--- /dev/null
@@ -0,0 +1,54 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+
+/**
+ * ディレクトリのサイズを求める
+ *
+ * @author kls040
+ * @version 3.0
+ */
+public class DirSize {
+    /**
+    * @param args the command line arguments
+    */
+    public static void main (String args[]) {
+        String outputfile;
+        
+        if (args.length < 1) {
+            outputfile = ".";
+        }
+        else {
+            outputfile = args[0];
+        }
+
+        try {
+            System.out.println(DirSize.size(new File(outputfile)) +"\t"+ outputfile);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            System.out.println(e.toString());
+        }
+    }
+    
+    static long size(File file) throws IOException {
+        long size = 0L;
+        if (file == null) {
+            System.out.println("ERR: ディレクトリが見つかりませんでした。");
+            return size;
+        }
+        
+        if (file.isDirectory()) {
+            File files[] = file.listFiles();
+            if (files != null) {
+                for (int i=0; i < files.length; i++) {
+                    size += size(files[i]);
+                }
+            }
+        }
+        else {
+            size = file.length();
+        }
+        return size;
+    }
+
+}
diff --git a/src/jp/co/areaweb/tools/command/JSendmail.java b/src/jp/co/areaweb/tools/command/JSendmail.java
new file mode 100644 (file)
index 0000000..7d374ab
--- /dev/null
@@ -0,0 +1,54 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+
+/**
+ * 実際にはメールへの送信を行わずに、指定された情報をファイルに吐き出す。
+ * 「/usr/sbin/sendmail」の代替コマンド
+ * @author hayashi
+ */
+public class JSendmail
+{
+    /** 
+     * サンプル
+     * exp: java jp.co.areaweb.tools.command.JSendmail [parameter]
+     */
+    static public void main(String[] args) throws Exception {
+        String commandLine = "";
+        for (int i=0; i < args.length; i++) {
+            if (i != 0) {
+                commandLine += " ";
+            }
+            commandLine += args[i];
+        }
+
+        // 標準入力ストリームを取得
+        BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
+
+        // 出力ファイルの準備
+        File out = new File("mail.txt");
+        FileOutputStream fo=new FileOutputStream(out);
+        PrintStream ps = new PrintStream(fo);
+
+        /**
+         * 標準入力の内容を、出力ファイルに書き出す。
+         */
+        ps.println(commandLine);
+        ps.println();
+        ps.println(convBufferedReader(stdReader));
+        
+        ps.close();
+        fo.close();
+    }
+
+
+    private static String convBufferedReader(BufferedReader reader) throws IOException {
+        if (reader == null) {
+            return "";
+        }
+        StringBuffer strbuf = new StringBuffer();
+        for (String line; (line = reader.readLine()) != null; strbuf.append(line +"\n"));
+        reader.close();
+        reader = null;
+        return strbuf.toString();
+    }
+}
diff --git a/src/jp/co/areaweb/tools/command/Job.java b/src/jp/co/areaweb/tools/command/Job.java
new file mode 100644 (file)
index 0000000..db773ce
--- /dev/null
@@ -0,0 +1,52 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+
+public class Job
+{
+    public static final boolean debug = false;
+
+    public static void execJob(File jobFile) throws IOException {
+        execJob(jobFile, null);
+    }
+
+    public static void execJob(File jobFile, File workDir) throws IOException {
+        if (jobFile == null) {
+            throw new IOException("実行するジョブファイルが指定されていません。");
+        }
+        if (debug) {
+            System.out.println("[s JobFile] " + jobFile.getName());
+        }
+
+        FileInputStream fis = new FileInputStream(jobFile);
+        BufferedReader dis = new BufferedReader(new InputStreamReader(fis));
+        String commandLine;
+        Command command = new Command();
+        while((commandLine = dis.readLine()) != null) {
+            command.setCmd(commandLine);
+            command.setWorkDir(workDir);
+            command.execCommand();
+            System.out.println(command.getOutput());
+        }
+
+        if (debug) {
+            System.out.println("[e JobFile] " + jobFile.getName());
+        }
+    }
+
+    /** 
+    *  サンプル
+    */
+    static public void main(String[] args) {
+        if (args.length < 1) {
+            System.out.println("exp: java jp.co.areaweb.tools.command.Job [jobFileName]");
+            return;
+        }
+
+        try {
+            Job.execJob(new File(args[0]), null);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/src/jp/co/areaweb/tools/command/NewFileList.java b/src/jp/co/areaweb/tools/command/NewFileList.java
new file mode 100644 (file)
index 0000000..52cc817
--- /dev/null
@@ -0,0 +1,52 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+
+/**
+ * 指定された時刻以降に更新されたファイルをリストアップし、その絶対パス名を標準出力に出力する。
+ */
+public class NewFileList
+{
+    public static void main (String args[]) {
+        if (args.length < 2) {
+            System.out.println("jp.co.areaweb.tools.command.NewFileList [directory] [CCYY.MM.DD-HH:mm:ss]");
+            return;
+        }
+        
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd'-'hh:mm:ss");
+            Date startTime = sdf.parse(args[1], new ParsePosition(0));
+
+            NewFileList.listup(new File(args[0]), startTime);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            System.out.println(e.toString());
+        }
+    }
+    
+    public static void listup(File file, Date startTime) throws IOException {
+        if (file == null) {
+            System.out.println("ERR: ディレクトリが見つかりませんでした。");
+            return;
+        }
+        
+        if (file.isDirectory()) {
+            File files[] = file.listFiles();
+            if (files != null) {
+                for (int i=0; i < files.length; i++) {
+                    listup(files[i], startTime);    // 再帰呼び出し
+                }
+            }
+        }
+        else {
+            if ((new Date(file.lastModified())).after(startTime)) {
+                System.out.println(file.getAbsolutePath());
+            }
+        }
+        return;
+    }
+
+}
diff --git a/src/jp/co/areaweb/tools/command/ReadXML.java b/src/jp/co/areaweb/tools/command/ReadXML.java
new file mode 100644 (file)
index 0000000..383588d
--- /dev/null
@@ -0,0 +1,22 @@
+package jp.co.areaweb.tools.command;
+import org.apache.xerces.parsers.DOMParser;
+
+/**
+ * 指定されたファイルが整形式XML文書であるかどうかをしらべる。
+ * exp) java -cp xerces.jar jp.co.areaweb.tools.command.ReadXML build.xml
+ * @author Hayashi,Yuu
+ * @since      2005/01/15
+ */
+public class ReadXML {
+       public static void main(String[] argv) {
+               try {
+                       DOMParser document = new DOMParser();
+                       document.parse(argv[0]);
+                       System.out.println("整形式XML文書です");
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+}
diff --git a/src/jp/co/areaweb/tools/command/Xalan.java b/src/jp/co/areaweb/tools/command/Xalan.java
new file mode 100644 (file)
index 0000000..9454bba
--- /dev/null
@@ -0,0 +1,91 @@
+package jp.co.areaweb.tools.command;
+import org.w3c.dom.*;
+import javax.xml.transform.TransformerFactory;  // xml-apis.jar
+import javax.xml.transform.Transformer;         // xml-apis.jar
+import javax.xml.transform.stream.StreamSource; // xml-apis.jar
+import javax.xml.transform.stream.StreamResult; // xml-apis.jar
+import java.io.*;
+
+/**
+ * Jobファイルに記述されたXSLT処理を順次実行する。
+ *  このコマンドを利用することによって、MS-DOSとUNIXで別々のシェルファイルを記述する必要がなくなります。
+ *
+ * @author  Hayashi,Yuu
+ * @since      2002/09/19, 11:21
+ */
+public class Xalan extends XmlJob
+{
+    /** 
+     * Jobファイルに記述されたXSLT処理を順次実行する。
+     */
+    protected static void execJobElement(NodeList jobgroupNodes) throws Exception {
+        execJobElement(jobgroupNodes, null);
+    }
+    protected static void execJobElement(NodeList jobgroupNodes, File workDir) throws Exception {
+        if (debug) {
+            System.out.println("Xalan.execJobElement()");
+        }
+        
+        for (int i=0; i < jobgroupNodes.getLength(); i++) {
+            Node node = jobgroupNodes.item(i);
+            if (node.getNodeType() == Node.ELEMENT_NODE) {
+                String tagName = node.getNodeName();
+                if (tagName.equals("xslt")) {
+                    String xmlStr = "";
+                    String xslStr = "";
+                    String outputStr = "";
+                    NodeList xsltNodes = node.getChildNodes();
+                    for (int j=0; j < xsltNodes.getLength(); j++) {
+                        Node xsltNode = xsltNodes.item(j);
+                        if (xsltNode.getNodeType() == Node.ELEMENT_NODE) {
+                            String tagName2 = xsltNode.getNodeName();
+                            if (tagName2.equals("xml")) {
+                                xmlStr = xsltNode.getFirstChild().getNodeValue();
+                            }
+                            else if (tagName2.equals("xsl")) {
+                                xslStr = xsltNode.getFirstChild().getNodeValue();
+                            }
+                            else if (tagName2.equals("output")) {
+                                outputStr = xsltNode.getFirstChild().getNodeValue();
+                            }
+                        }
+                    }
+                    // コマンドの実行
+                    if (workDir == null) {
+                        execXslt(xmlStr, xslStr, outputStr);
+                    }
+                    else {
+                        execXslt(xmlStr, xslStr, outputStr, workDir);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * xmlファイルをxslファイルで処理した結果をoutputファイルに出力する。
+     */
+    protected static void execXslt(String xmlStr, String xslStr, String outputStr) throws Exception {
+        System.out.println("XALAN("+ xmlStr +" * "+ xslStr +") -> "+ outputStr);
+        
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        Transformer transformer = tFactory.newTransformer(new StreamSource(xslStr));
+        transformer.transform(new StreamSource(xmlStr), new StreamResult(new FileOutputStream(outputStr)));
+    }
+    protected static void execXslt(String xmlStr, String xslStr, String outputStr, File workDir) throws Exception {
+        System.out.println("XALAN("+ xmlStr +" * "+ xslStr +") -> "+ outputStr);
+        
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        Transformer transformer = tFactory.newTransformer(new StreamSource(new File(workDir, xslStr)));
+        transformer.transform(new StreamSource(new File(workDir, xmlStr)), new StreamResult(new FileOutputStream(new File(workDir, outputStr))));
+    }
+    
+    public static void main(String[] args) throws Exception {
+        if (args.length < 1) {
+            System.out.println("exp: java jp.co.areaweb.tools.command.Xalan [jobFileName]");
+            return;
+        }
+
+        XmlJob.execJob(new File(args[0]));
+    }
+}
diff --git a/src/jp/co/areaweb/tools/command/XmlJob.java b/src/jp/co/areaweb/tools/command/XmlJob.java
new file mode 100644 (file)
index 0000000..1306479
--- /dev/null
@@ -0,0 +1,146 @@
+package jp.co.areaweb.tools.command;
+import java.io.*;
+import java.util.*;
+import javax.xml.parsers.*;
+import org.w3c.dom.*;
+
+public class XmlJob
+{
+    public static final boolean debug = false;
+
+    /**
+     * Jobファイルに記述されたコマンドを順次実行する。
+     * @param jobFile Jobコマンドが記述されたファイル
+     * @throws IOException JOBファイルの読み込み障害
+     */
+    public static void execJob(File jobFile) throws Exception {
+        execJob(jobFile, null);
+    }
+
+    /**
+     * Jobファイルに記述されたコマンドを順次実行する。
+     * @param jobFile Jobコマンドが記述されたファイル
+     * @param workDir コマンドを実行するさいのカレントディレクトリ
+     * @throws IOException JOBファイルの読み込み障害
+     */
+    public static void execJob(File jobFile, File workDir) throws Exception {
+        if (jobFile == null) {
+            throw new IOException("実行するジョブファイルが指定されていません。");
+        }
+        
+        if (debug) {
+            System.out.println("[s JobFile] " + jobFile.getName());
+        }
+        
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        Node rootNode = builder.parse(new FileInputStream(jobFile));
+        NodeList nl = rootNode.getChildNodes();
+        for (int i=0; i < nl.getLength(); i++) {
+            Node jobgroupTag = nl.item(i);
+            if (jobgroupTag.getNodeType() == Node.ELEMENT_NODE) {
+                if ((jobgroupTag.getNodeName()).equals("jobgroup")) {
+                    execJobElement(jobFile, workDir, jobgroupTag.getChildNodes());
+                }
+                else if ((jobgroupTag.getNodeName()).equals("xalan")) {
+                    Xalan.execJobElement(jobgroupTag.getChildNodes(), workDir);
+                }
+            }
+        }
+
+        if (debug) {
+            System.out.println("[e JobFile] " + jobFile.getName());
+        }
+    }
+
+    /**
+     * Jobファイルに記述されたコマンドを順次実行する。
+     * @param jobFile Jobコマンドが記述されたファイル
+     * @param workDir コマンドを実行するさいのカレントディレクトリ
+     * @throws IOException JOBファイルの読み込み障害
+     */
+    protected static void execJobElement(File jobFile, File workDir, NodeList jobgroupNodes)
+            throws Exception {
+        if (debug) {
+            System.out.println("XmlJob.execJobElement()");
+        }
+        
+        String stdout = null;
+        String errout = null;
+        Vector<Command> commands = new Vector<Command>();
+
+        for (int i=0; i < jobgroupNodes.getLength(); i++) {
+            Node node = jobgroupNodes.item(i);
+            if (node.getNodeType() == Node.ELEMENT_NODE) {
+                String tagName = node.getNodeName();
+                if (tagName.equals("job")) {
+                    NodeList jobNodes = node.getChildNodes();
+                    Command command = new Command();
+                    for (int j=0; j < jobNodes.getLength(); j++) {
+                        Node jobNode = jobNodes.item(j);
+                        if (jobNode.getNodeType() == Node.ELEMENT_NODE) {
+                            String tagName2 = jobNode.getNodeName();
+                            if (tagName2.equals("cmd")) {
+                                command.setCmd(jobNode.getFirstChild().getNodeValue());
+                            }
+                            else if (tagName2.equals("workDir")) {
+                                command.setWorkDir(new File(jobNode.getFirstChild().getNodeValue()));
+                            }
+                        }
+                    }
+                    commands.addElement(command);                          
+                }
+                else if (tagName.equals("stdout")) {
+                    NamedNodeMap attrs = node.getAttributes();
+                    stdout = attrs.getNamedItem("file").getNodeValue();
+                }
+                else if (tagName.equals("errout")) {
+                    NamedNodeMap attrs = node.getAttributes();
+                    errout = attrs.getNamedItem("file").getNodeValue();
+                }
+            }
+        }
+
+        // コマンドの実行
+        execJobs(stdout, errout, commands);
+    }
+
+    /**
+     * Vector commandsに格納されたコマンドを順次実行する。
+     * @throws IOException JOBファイルの読み込み障害
+     */
+    protected static void execJobs(String stdout, String errout, Vector<Command> commands) throws IOException {
+        // コマンドの実行
+        PrintWriter stdoutPW;
+        if (stdout == null) {
+            stdoutPW = new PrintWriter(System.out);
+        }
+        else {
+            Writer writer = new OutputStreamWriter(new FileOutputStream(new File(stdout)));
+            stdoutPW = new PrintWriter(writer);
+        }
+
+        try {
+            for (int i=0; i < commands.size(); i++) {
+                Command command = commands.get(i);
+                command.execCommand();
+                stdoutPW.println(command.getOutput());
+            }
+        }
+        finally {
+            stdoutPW.close();
+        }
+    }
+    
+    /** 
+    *  サンプル
+    */
+    static public void main(String[] args) throws Exception {
+        if (args.length < 1) {
+            System.out.println("exp: java tool.job.XmlJob [jobFileName]");
+            return;
+        }
+
+        XmlJob.execJob(new File(args[0]));
+    }
+}
diff --git a/src/jp/co/areaweb/tools/core/JapaneseString.java b/src/jp/co/areaweb/tools/core/JapaneseString.java
new file mode 100644 (file)
index 0000000..0d33ef0
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Created on 2005/07/01
+ *
+ * 日本語文字列特有の問題に対応する機能を集めたクラス
+ */
+package jp.co.areaweb.tools.core;
+
+/**
+ * @author y_hayashi
+ *
+ */
+public abstract class JapaneseString {
+       
+       /**
+        * 文字列のトリミングを行う.通常のjava.lang.String.trim()の機能に加えて、
+        * 全角スペースもトリム対象の文字に加える。
+        * @param str トリムする文字列
+        * @return トリム後の文字列(別オブジェクト)
+        */
+       public static String trim(String str) {
+               str = str.trim();
+               char[] charArray = str.toCharArray();
+               if (charArray.length > 0) {
+                       if (java.lang.Character.isWhitespace(charArray[0])) {
+                               return trim(new String(charArray, 1, charArray.length - 1));
+                       }
+                       if (java.lang.Character.isWhitespace(charArray[charArray.length - 1])) {
+                               return trim(new String(charArray, 0, charArray.length - 1));
+                       }
+               }
+               return str;
+       }
+}
diff --git a/src/jp/co/areaweb/tools/core/MakeString.java b/src/jp/co/areaweb/tools/core/MakeString.java
new file mode 100644 (file)
index 0000000..2b28595
--- /dev/null
@@ -0,0 +1,61 @@
+package jp.co.areaweb.tools.core;
+
+/**
+ * @author y_hayashi
+ * @version 2010/02/07 'Exception'を削除
+ * @since       2005/06/02
+ */
+public abstract class MakeString
+{
+       /**
+        * intData数値を、ketaで指定された文字数の文字列に変換する。
+        * 数値が指定の桁に満たない場合は、0が埋め込まれます.
+        * 数値が指定の桁数を超えている場合には、例外を発生させます.
+        * 基数は10です。
+        * @param intData       数値
+        * @param keta  生成する桁数
+        * @return      数値を表現する文字列
+        */
+       public static String valueOf(int intData, int keta) {
+               return valueOf(new Long(intData), keta);
+       }
+       
+       /**
+        * longData数値を、ketaで指定された文字数の文字列に変換する。
+        * 数値が指定の桁に満たない場合は、0が埋め込まれます.
+        * 数値が指定の桁数を超えている場合には、例外を発生させます.
+        * 基数は10です。
+        * @param longData      数値
+        * @param keta  生成する桁数
+        * @return      数値を表現する文字列
+        */
+       public static String valueOf(long longData, int keta) {
+               return valueOf(new Long(longData), keta);
+       }
+       
+       /**
+        * longData数値を、ketaで指定された文字数の文字列に変換する。
+        * 数値が指定の桁に満たない場合は、0が埋め込まれます.
+        * 数値が指定の桁数を超えている場合には、例外を発生させます.
+        * 基数は10です。
+        * @param longData      数値
+        * @param keta  生成する桁数
+        * @return      数値を表現する文字列
+        */
+       public static String valueOf(Long longData, int keta) {
+               int hugou = 0;
+               long longValue = longData.longValue();
+               if (longValue < 0) {
+                       hugou = 1;
+                       longValue = longValue * (-1);
+               }
+
+               String dataStr = (new Long(longValue)).toString();
+               int loop = keta - hugou - dataStr.length();
+               char[] pri = new char[loop];
+               for (int i = 0; i < loop; i++) {
+                       pri[i] = '0';
+               }
+               return (hugou == 1 ? "-" : "") + (new String(pri)) + dataStr;
+       }
+}
diff --git a/src/jp/co/areaweb/tools/core/MemoryCheck.java b/src/jp/co/areaweb/tools/core/MemoryCheck.java
new file mode 100644 (file)
index 0000000..5c2aaf5
--- /dev/null
@@ -0,0 +1,42 @@
+package jp.co.areaweb.tools.core;
+
+import java.text.DecimalFormat;
+
+public class MemoryCheck {
+
+       /**
+        * 
+        * 出力結果
+        *              Java メモリ情報 : 合計=1,984KB、使用量=458KB (23.1%)、使用可能最大=65,088KB
+        * 
+        * JAVAのヒープサイズ変更方法
+        *              java -Xms64m -Xmx512m Main
+        *                      -Xms初期ヒープサイズ
+        *                              Java仮想マシンへの初期メモリ割り当て量を指定します。デフォルトは2MBです。
+        *                      -Xmx最大ヒープサイズ
+        *                              Java仮想マシンへの最大メモリ割り当て量を指定します。デフォルトは64MBです。
+        * 
+        * @param args
+        */
+       public static void main(String[] args) {
+               System.out.println(getMemoryInfo());
+       }
+
+       /**
+        * Java 仮想マシンのメモリ総容量、使用量、
+        * 使用を試みる最大メモリ容量の情報を返します。
+        * @return Java 仮想マシンのメモリ情報
+        */
+       public static String getMemoryInfo() {
+           DecimalFormat f1 = new DecimalFormat("#,###KB");
+           DecimalFormat f2 = new DecimalFormat("##.#");
+           long free = Runtime.getRuntime().freeMemory() / 1024;
+           long total = Runtime.getRuntime().totalMemory() / 1024;
+           long max = Runtime.getRuntime().maxMemory() / 1024;
+           long used = total - free;
+           double ratio = (used * 100 / (double)total);
+           String info = 
+           "Java メモリ情報 : 合計=" + f1.format(total) + "、" + "使用量=" + f1.format(used) + " (" + f2.format(ratio) + "%)、" + "使用可能最大="+f1.format(max);
+           return info;
+       }
+}
diff --git a/src/jp/co/areaweb/tools/core/Tax.java b/src/jp/co/areaweb/tools/core/Tax.java
new file mode 100644 (file)
index 0000000..10ff74c
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Created on 2005/06/09
+ *
+ */
+package jp.co.areaweb.tools.core;
+
+/**
+ * @author y_hayashi
+ *
+ *     消費税に関するメソッドを集めたクラス
+ *     端数は四捨五入する
+ */
+public abstract class Tax {
+       public static int taxRates = 5; // 消費税率。パーセンテージで示す。
+                                                                               // 税率が変更されたときにはこの値を直接変更する。
+       
+       /**
+        * 総額に対する本体の金額を求める。
+        */
+       public static long calcBody(long totalValue) {
+               return Math.round((new Long(totalValue)).doubleValue() * 100 / (100 + taxRates));
+       }
+
+       /**
+        * 総額に対する消費税額を求める。
+        */
+       public static long calcTax(long totalValue) {
+               return totalValue - calcBody(totalValue) ;
+       }
+
+
+       /**
+        * 本体価格に対する消費税額を求める。
+        */
+       public static long toTax(long bodyValue) {
+               return Math.round((new Long(bodyValue)).doubleValue() * taxRates / 100);
+       }
+
+       /**
+        * 本体価格に対する総額を求める。
+        */
+       public static long toTotal(long bodyValue) {
+               return bodyValue + toTax(bodyValue);
+       }
+}
diff --git a/src/jp/co/areaweb/tools/csv/CsvFile.java b/src/jp/co/areaweb/tools/csv/CsvFile.java
new file mode 100644 (file)
index 0000000..586e8b0
--- /dev/null
@@ -0,0 +1,162 @@
+package jp.co.areaweb.tools.csv;
+import java.io.*;
+import java.util.*;
+
+/**
+ * <p>CSVファイルを操作する。<br/>
+ * このクラスではCSVに対するファイル操作と、各行を束ねた単位で操作します。各行は、CsvRecordオブジェクトで管理します。<br/>
+ * このクラスは通常,CsvRecordクラスとセットで利用します。</p>
+ * 
+ * <p>
+ *     <b>ファイルの読み出し例</b>:<br/>
+ *       CsvFile csv = new CsvFile("C:\\Program Files\\data\\フォルダ\\ファイル.csv");<br/>
+ *       csv.load();
+ * </p>
+ * <p>
+ *     <b>CSVレコードの追加と変更</b>:<br/>
+         if (csvf.isEmpty()) {<br/>
+           // 新規レコード<br/>
+           CsvRecord line = new CsvRecord();<br/>
+           line.add("code");<br/>
+           line.add("name");<br/>
+           csvf.add(line);<br/>
+         }<br/>
+         else {<br/>
+           // 既存タグ<br/>
+           CsvRecord line = csvf.getFirst();<br/>
+           line.set(1, "name");<br/>
+         }<br/>
+ * </p>
+ * <p>
+ *     <b>ファイルに保存</b>(上書き):<br/>
+ *       csv.save();
+ * </p>
+ * 
+ * @author y_hayashi
+ * @version v2.17      2010/01/24
+ * @see jp.co.areaweb.tools.csv.CsvRecord
+ * @since 2005/06/01
+ */
+@SuppressWarnings("serial")
+public class CsvFile extends LinkedList<CsvRecord> {
+       //String pathname;              // 対象CSVファイルのパス名
+       protected String charsetName = "Windows-31J";
+       protected File file;
+       protected LinkedList<CsvRecord> allRecords = new LinkedList<CsvRecord>();       // CSVファイル内の全データを保持するコレクション
+       
+       /**
+        * pathnameで指定されたパス名のファイルを対象のCSVファイルとします.
+        * @param pathname 対象のCSVファイルのパス名
+        */
+       public CsvFile(String pathname) {
+               this(new File(pathname));
+       }
+
+       /**
+        * fileで指定されたファイルを対象のCSVファイルとします.
+        * @param file 対象のCSVファイル
+        */
+       public CsvFile(File file) {
+               this.file = file;
+       }
+       
+       /**
+        * CVSファイルからデータを読みだします。
+        */
+       public void load() throws Exception {
+               this.load(0);
+       }
+       
+       /**
+        * CVSファイルからデータを読みだします。
+        * (読み出し数の制限付き)
+        */
+       public void load(int limit) throws Exception {
+               this.clear();
+               LineNumberReader reader = new LineNumberReader(new InputStreamReader(new FileInputStream(this.file), this.charsetName));
+               String line;
+               for (int i = 0; ((limit <= 0) || (i < limit)); i++) {
+                       if ((line = reader.readLine()) == null) {
+                               break;
+                       }
+                       CsvRecord record = new CsvRecord();
+                       record.analizeRecord(line);
+                       this.add(record);
+               }
+       }
+       
+       /**
+        * インポート元のキャラクタセットを設定する。
+        * デフォルトは、「Windows31J」
+        * @param charsetName 対象のCSVファイル内の文字コード
+        */
+       public void setCharsetName(String charsetName) {
+               this.charsetName = charsetName;
+       }
+       
+       /**
+        * 現在設定されているCSVファイルの文字コードを取得する
+        * @return 現在設定されている文字コードを取得する
+        */
+       public String getCharsetName() {
+               return this.charsetName;
+       }
+       
+       /**
+        * インポート元ファイルを取得する。
+        * @return 実体ファイル
+        */
+       public File getFile() {
+               return this.file;
+       }
+
+       /**
+        * 元ファイルを設定する。
+        * @return 実体ファイル
+        */
+       public void setFile(File file) {
+               this.file = file;
+       }
+
+       /**
+        * index番目の項目がdataStrになっているレコードを読み出す。
+        * @param index 検索対象とする列番号(0~)
+        * @param dataStr 検索値
+        * @return 条件に合致したレコード(複数)
+        */
+       public CsvFile find(int index, String dataStr) {
+               CsvFile result = new CsvFile(this.file);
+               for (Iterator<CsvRecord> i = this.iterator(); i.hasNext(); ) {
+                       CsvRecord record = (CsvRecord)i.next();
+                       String data = (String)record.get(index);
+                       if (data.equals(dataStr)) {
+                               result.add(record);
+                       }
+               }
+               return result;
+       }
+
+       /**
+        * データ内容をファイルに書き戻す。<br>
+        * 当然、上書き書き込みになります。
+        * @throws IOException ファイルへの書き出しに失敗した。
+        */
+       public void save() throws IOException {
+               save(getFile());
+       }
+
+       /**
+        * データ内容をファイルに書き戻す。<br>
+        * @throws IOException ファイルへの書き出しに失敗した。
+        */
+       public void save(File outputFile) throws IOException {
+               FileOutputStream fo = new FileOutputStream(outputFile);
+               PrintStream ps = new PrintStream(fo);
+               for (Iterator<CsvRecord> i = this.iterator(); i.hasNext(); ) {
+                       CsvRecord record = (CsvRecord)i.next();
+                       ps.println(record.toString());
+               }
+               ps.close();
+               fo.close();
+       }
+}
diff --git a/src/jp/co/areaweb/tools/csv/CsvReader.java b/src/jp/co/areaweb/tools/csv/CsvReader.java
new file mode 100644 (file)
index 0000000..305ef1d
--- /dev/null
@@ -0,0 +1,172 @@
+package jp.co.areaweb.tools.csv;
+import java.io.*;
+import java.util.LinkedList;
+
+import jp.co.areaweb.tools.csv.CsvRecord;
+
+/**
+ * <p>CSVファイルの読み取りを行う。<br/>
+ * このクラスではCSVに対するファイル操作と、各行を束ねた単位で操作します。各行は、CsvRecordオブジェクトで管理します。<br/>
+ * このクラスは通常,CsvRecordクラスとセットで利用します。</p>
+ * 
+ * (読み出し可能ファイルサイズ=最大8MBまで)
+ * 
+ * @author y_hayashi
+ * @version v2.23      2010/07/27
+ * @see jp.co.areaweb.tools.csv.CsvRecord
+ * @since 2010/07/27
+ */
+@SuppressWarnings("serial")
+public class CsvReader
+{
+       /**
+        * CSVファイルの読み取りを行う。
+        * (読み出し可能ファイルサイズ=最大8MBまで)
+        * 
+        * @param args
+        */
+       public static void main(String[] args) throws Exception {
+               File file = new File("test.csv");
+               CsvReader obj = new CsvReader(file, true, ",");
+               int size = obj.load();
+               System.out.println("line count = "+ obj.size());
+               
+               for (int i=0; i < size; i++) {
+                       System.out.print(String.format("%05d : ", i));
+                       CsvRecord rec = obj.get(i);
+                       if (rec != null) {
+                               System.out.println(rec.toString());
+                       }
+                       else {
+                               System.out.println("< null >");
+                       }
+               }
+       }
+
+       
+       int size = 0;
+       int columnSize = 0;
+       boolean titleLine = false;
+       File file = null;
+       String split = ",";
+       protected String charsetName = "Windows-31J";
+       LineNumberReader reader;
+       
+       /**
+        * <コンストラクタ>
+        * fileで指定されたファイルを対象のCSVファイルとします.
+        * 
+        * @param file 対象のCSVファイル
+        * @throws IOException 
+        * @throws UnsupportedEncodingException 
+        */
+       public CsvReader(File file) throws UnsupportedEncodingException, IOException {
+               this(file, false, ",");
+       }
+       
+       /**
+        * <コンストラクタ>
+        * fileで指定されたファイルを対象のCSVファイルとします.
+        * 
+        * @param file 対象のCSVファイル
+        * @throws IOException 
+        * @throws UnsupportedEncodingException 
+        */
+       public CsvReader(File file, boolean titleLine, String split) throws UnsupportedEncodingException, IOException {
+               this.file = file;
+               this.titleLine = titleLine;
+               this.reader = null;
+               this.split = split;
+       }
+       
+       /**
+        * CVSファイルからデータを読みだします。
+        * (読み出し可能ファイルサイズ=最大8MBまで)
+        * 
+        * @param limit 全レコードを読み出したふりをする。
+        */
+       public int load() throws Exception {
+               this.reader = new LineNumberReader(new InputStreamReader(new FileInputStream(this.file), this.charsetName));
+               this.reader.mark(1024 * 1024 * 8);
+               this.size = 0;
+               this.columnSize = 0;
+               while (reader.readLine() != null) {
+                       this.size++;
+               }
+               return size;
+       }
+       
+       
+       public CsvRecord get(int index) {
+               if ((index < 0) || (index > this.size)) {
+                       return null;
+               }
+               try {
+                       this.reader.reset();
+                       
+                       for (int i=0; i < index; i++) {
+                               reader.readLine();
+                       }
+
+                       String line = reader.readLine();
+                       if (line != null) {
+                               CsvRecord record = new CsvRecord();
+                               record.analizeRecord(line, this.split);
+                               return record;
+                       }
+               }
+               catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return null;
+       }
+
+       /**
+        * index番目の項目がdataStrになっているレコードを読み出す。
+        * @param index 検索対象とする列番号(0~)
+        * @param dataStr 検索値
+        * @return 条件に合致したレコード(複数)
+        * @throws IOException 
+        */
+       public LinkedList<CsvRecord> find(int index, String dataStr) throws IOException {
+               if ((index < 0) || (index > this.size)) {
+                       return null;
+               }
+               LinkedList<CsvRecord> result = new LinkedList<CsvRecord>();
+               this.reader.reset();
+               
+               for (int i=0; i < this.size; i++) {
+                       String line = reader.readLine();
+                       if (line != null) {
+                               CsvRecord record = new CsvRecord();
+                               record.analizeRecord(line, this.split);
+                               String item = record.get(index);
+                               if ((item != null) && item.trim().equals(dataStr)) {
+                                       result.add(record);
+                               }
+                       }
+               }
+               return result;
+       }
+
+       public int size() {
+               return this.size;
+       }
+
+       /**
+        * インポート元のキャラクタセットを設定する。
+        * デフォルトは、「Windows31J」
+        * @param charsetName 対象のCSVファイル内の文字コード
+        */
+       public void setCharsetName(String charsetName) {
+               this.charsetName = charsetName;
+       }
+       
+       /**
+        * 現在設定されているCSVファイルの文字コードを取得する
+        * @return 現在設定されている文字コードを取得する
+        */
+       public String getCharsetName() {
+               return this.charsetName;
+       }
+}
diff --git a/src/jp/co/areaweb/tools/csv/CsvRecord.java b/src/jp/co/areaweb/tools/csv/CsvRecord.java
new file mode 100644 (file)
index 0000000..9b48956
--- /dev/null
@@ -0,0 +1,122 @@
+package jp.co.areaweb.tools.csv;
+import java.util.*;
+
+/**
+ * CSVファイルの1行分のレコードを表す.<br/>
+ * 1行は、Stringオブジェクトのコレクションとして表現する.<br/>
+ * このクラスは通常,CsvFileクラスとセットで利用します.<br/>
+ * 利用方法につては、CsvFileクラスのコメントを参照してください。<br/>
+ *
+ * @author y_hayashi
+ * @version v2.17      2010/01/24
+ * @see jp.co.areaweb.tools.csv.CsvFile
+ * @since 2005/06/01
+ */
+@SuppressWarnings("serial")
+public class CsvRecord extends LinkedList<String>
+{
+       /**
+        * lineで示された文字列を、CSVレコードとして構文解析を行い、自身に取り込む.
+        * 取り込まれたセル文字列は、自信(LinkedList)のアイテムとして格納されます.
+        * 格納順序は、左から順に格納される.
+        * v2.17-2010/01/24より、ダブルクォーテーションで囲まれたセルを処理できるように変更しました。
+        * 自信のアイテムとして格納するときに、前後のダブルクォーテーションは削除されます。
+        * 
+        * @param line  CSVレコード解析を行う文字列行(つまり、CSVの1ライン)
+        */
+       public void analizeRecord(String line) {
+               this.analizeRecord(line, null);
+       }
+
+       /**
+        * lineで示された文字列を、CSVレコードとして構文解析を行い、自身に取り込む.
+        * 取り込まれたセル文字列は、自信(LinkedList)のアイテムとして格納されます.
+        * 格納順序は、左から順に格納される.
+        * v2.17-2010/01/24より、ダブルクォーテーションで囲まれたセルを処理できるように変更しました。
+        * 自信のアイテムとして格納するときに、前後のダブルクォーテーションは削除されます。
+        * 
+        * @param line  CSVレコード解析を行う文字列行(つまり、CSVの1ライン)
+        * @param split 区切り記号。nullの時は「カンマ(,)」が使われる。
+        */
+       public void analizeRecord(String line, String split) {
+               this.clear();
+               if (split == null) {
+                       split = ",";
+               }
+               boolean append = false;
+               boolean sss = false;            // ダブルクォーテーション内かどうか
+               StringBuffer sbuf = null;
+               for (StringTokenizer st = new StringTokenizer(line, split + "\"", true); st.hasMoreTokens(); ) {
+                       String token = st.nextToken();
+                       if (token.equals("\"")) {
+                               if (sss) {
+                                       // ダブルクォーテーションEND
+                                       this.add(sbuf.toString());
+                                       append = true;
+                                       sss = false;
+                               }
+                               else {
+                                       // ダブルクォーテーションSTART
+                                       sbuf = new StringBuffer("");
+                                       sss = true;
+                               }
+                       }
+                       else if (token.equals(split)) {
+                               if (sss) {
+                                       sbuf.append(token);
+                               }
+                               else {
+                                       if (append == false) {
+                                               this.add("");
+                                       }
+                                       append = false;
+                               }
+                       }
+                       else {
+                               if (sss) {
+                                       sbuf.append(token);
+                               }
+                               else {
+                                       this.add(token.trim());
+                                       append = true;
+                               }
+                       }
+               }
+               if (append == false) {
+                       this.add("");
+               }
+       }
+       
+       /**
+        * レコードの内容をCSV形式の文字列にして返す.
+        * 各項目はダブルクォーテーション(")で囲まれます。
+        * 各項目間は、カンマ(,)で区切られます。
+        * 
+        * @return このオブジェクトをCSVの1ライン形式として返します。
+        */
+       public String toString() {
+               return this.toString(null);
+       }
+
+       /**
+        * レコードの内容をCSV形式の文字列にして返す.
+        * 各項目はダブルクォーテーション(")で囲まれます。
+        * 
+        * @param split 区切り記号。nullの時は「カンマ(,)」が使われる。
+        * @return このオブジェクトをCSVの1ライン形式として返します。
+        */
+       public String toString(String split) {
+               StringBuffer ret = new StringBuffer();
+               boolean top = true;
+               for (String col : this) {
+                       if (top) {
+                               top = false;
+                       }
+                       else {
+                               ret.append(",");
+                       }
+                       ret.append("\""+ col +"\"");
+               }
+               return ret.toString();
+       }
+}
diff --git a/src/jp/co/areaweb/tools/csv/package.html b/src/jp/co/areaweb/tools/csv/package.html
new file mode 100644 (file)
index 0000000..868d4c6
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Insert title here</title>
+</head>
+<body>
+<p>
+CSVファイルを扱うためのツールクラス群<br/>
+・CSVの読取<br/>
+・CSVの変更(削除・追加・値変更)<br/>
+・CSVの書き出し(上書き保存・新規書き出し)</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/jp/co/areaweb/tools/database/DatabaseTool.java b/src/jp/co/areaweb/tools/database/DatabaseTool.java
new file mode 100644 (file)
index 0000000..e4de394
--- /dev/null
@@ -0,0 +1,75 @@
+package jp.co.areaweb.tools.database;
+
+import java.io.*;
+import java.sql.*;
+import java.util.Properties;
+
+public class DatabaseTool
+{
+    /**
+     * 設定ファイルに従って、データベースコネクションをオープンしてコネクションを得る。
+     * 指定のデータベースが存在しないときは新に作成する。
+     * @throws ClassNotFoundException 指定のデータベースドライバが見つからなかった
+     * @throws SQLException データベース障害
+     * @return データベースコネクション
+     */    
+    public static Connection openDb(String propertiesFileName) throws ClassNotFoundException,SQLException,FileNotFoundException,IOException {
+        Properties properties;
+
+        String driver = null;
+        String database = null;
+        String user = null;
+        String passwd = null;
+
+        properties = new Properties();
+        properties.load(new FileInputStream(propertiesFileName +".properties"));
+        driver = properties.getProperty("db_driver");
+        database = properties.getProperty("db_url");
+        user = properties.getProperty("db_user");
+        passwd = properties.getProperty("db_passwd");
+        
+        // dbnameで指定されたDBが存在しないときには自動的にDBが新たに作成される
+        Connection conn = null;
+        Class.forName(driver);
+        conn = DriverManager.getConnection(database, user, passwd);
+        return conn;
+    }
+    
+    /**
+     * 設定ファイル("kind.properties")に従って、データベースコネクションをオープンしてコネクションを得る。
+     * 指定のデータベースが存在しないときは新に作成する。
+     * @throws ClassNotFoundException 指定のデータベースドライバが見つからなかった
+     * @throws SQLException データベース障害
+     * @return データベースコネクション
+     */    
+    public static Connection openDb() throws ClassNotFoundException,SQLException,FileNotFoundException,IOException {
+        return openDb("database");
+    }
+    
+    /**
+     * データベースコネクションをクローズする。
+     * 処理中に例外が発生しても報告しない。
+     * @param conn データベースコネクション
+     */    
+    public static void closeDb(Connection conn) {
+        try {
+            // Finally, close the connection
+            conn.close();
+        }
+        catch(Exception e) {
+            // Print out the error message
+            System.out.println(e);
+        }
+    }
+
+    /**
+     * 全角スペースもトリミングするトリムメソッド
+     * @param souce トリムする文字列
+     * @return トリム処理後の文字列
+     */
+    public static String trim(String souce) {
+        String result = souce.replace(' ', ' ');
+        return result.trim();
+    }
+}
+
diff --git a/src/jp/co/areaweb/tools/database/DoSQL.java b/src/jp/co/areaweb/tools/database/DoSQL.java
new file mode 100644 (file)
index 0000000..3d8a63b
--- /dev/null
@@ -0,0 +1,83 @@
+package jp.co.areaweb.tools.database;
+
+import java.io.*;
+import java.sql.*;
+import jp.co.areaweb.tools.core.JapaneseString;
+
+
+/**
+ * SQL文が記述されたファイルを読み込んで実行する。
+ *
+ * ・SELECTコマンドは実行できない。
+ */
+public class DoSQL
+{
+    /** コマンドラインラインからdoSQLを実行する。
+     * java DoSQL [SQLファイル名]
+     * exp) java dbtool.DoSQL  sqlfile.sql
+     * @param args パラメータ
+     */
+    static public void main(String[] args) {
+        if (args.length < 2) {
+            System.out.println("exp: java dbtool.DoSQL [propertieFile] [sqlfile]");
+        }
+        else {
+            DoSQL.doSQL(args[0], args[1]);
+        }
+    }
+
+    /**
+     * sqlfileの中のSQL文を1行づつ実行する。
+     * ・SELECT文は実行できない。
+     * ・一つのSQL文は1行で記述すること。(途中改行はだめ)
+     * @param sqlfile SQL文が記述されたファイル。
+     */
+    public static void doSQL(String propertieFile, String sqlfile) {
+        Connection conn = null;
+        try {
+            conn = DatabaseTool.openDb(propertieFile);
+            
+            BufferedReader ds = new BufferedReader(new InputStreamReader(new FileInputStream(sqlfile)));
+            String sqlStr = "";
+            while ((sqlStr = ds.readLine()) != null) {
+               sqlStr = JapaneseString.trim(sqlStr);
+               if (sqlStr.endsWith(";")) {
+                       sqlStr = sqlStr.substring(0, sqlStr.length() - 1);
+               }
+                System.out.println(sqlStr);
+                sqlExecute(conn, sqlStr);
+            }
+
+            ds.close();
+            System.out.println("SQL Finished");
+        }
+        catch(Exception e) {
+            // Print out the error message
+            System.out.println(e);
+            e.printStackTrace();
+        }
+        finally {
+            if (conn != null) {
+                DatabaseTool.closeDb(conn);
+            }
+        }
+    }
+
+    /**
+     * sqlStrを実行する
+     * @param conn データベースコネクション
+     * @param sqlStr 実行するSQL文
+     * @throws SQLException SQL実行エラー
+     */
+    static void sqlExecute(Connection conn, String sqlStr) throws SQLException {
+        // Create a statement object
+        Statement stat = conn.createStatement();
+
+        // For compatibility to other database, use varchar(255)
+        // In Hypersonic SQL, length is unlimited, like Java Strings
+        stat.execute(sqlStr);
+
+        // Close the Statement object, it is no longer used
+        stat.close();
+    }
+}
diff --git a/src/jp/co/areaweb/tools/database/Select.java b/src/jp/co/areaweb/tools/database/Select.java
new file mode 100644 (file)
index 0000000..2bf40fa
--- /dev/null
@@ -0,0 +1,91 @@
+package jp.co.areaweb.tools.database;
+
+import java.io.*;
+import java.sql.*;
+
+import jp.co.areaweb.tools.core.JapaneseString;
+
+
+/**
+ * SQL文が記述されたファイルを読み込んで実行する。
+ *
+ * ・SELECTコマンドは実行できない。
+ */
+public class Select
+{
+    /** コマンドラインラインからdoSQLを実行する。
+     * java DoSQL [SQLファイル名]
+     * exp) java dbtool.DoSQL  sqlfile.sql
+     * @param args パラメータ
+     */
+    static public void main(String[] args) {
+        if (args.length < 2) {
+            System.out.println("exp: java jp.co.areaweb.tools.database.Select [propertieFile] [sqlfile]");
+        }
+        else {
+            Select.doSQL(args[0], args[1]);
+        }
+    }
+
+    /**
+     * sqlfileの中のSQL文を1行づつ実行する。
+     * ・SELECT文は実行できない。
+     * ・一つのSQL文は1行で記述すること。(途中改行はだめ)
+     * @param sqlfile SQL文が記述されたファイル。
+     */
+    public static void doSQL(String propertieFile, String sqlfile) {
+        Connection conn = null;
+        try {
+            conn = DatabaseTool.openDb(propertieFile);
+            
+            BufferedReader ds = new BufferedReader(new InputStreamReader(new FileInputStream(sqlfile)));
+            String sqlStr = "";
+            while ((sqlStr = ds.readLine()) != null) {
+               sqlStr = JapaneseString.trim(sqlStr);
+               if (sqlStr.endsWith(";")) {
+                       sqlStr = sqlStr.substring(0, sqlStr.length() - 1);
+               }
+                System.out.println(sqlStr);
+                sqlExecute(conn, sqlStr);
+            }
+
+            ds.close();
+            System.out.println("SQL Finished");
+        }
+        catch(Exception e) {
+            // Print out the error message
+            System.out.println(e);
+            e.printStackTrace();
+        }
+        finally {
+            if (conn != null) {
+                DatabaseTool.closeDb(conn);
+            }
+        }
+    }
+
+    /**
+     * sqlStrを実行する
+     * @param conn データベースコネクション
+     * @param sqlStr 実行するSQL文
+     * @throws SQLException SQL実行エラー
+     */
+    public static void sqlExecute(Connection conn, String sqlStr) throws SQLException {
+               // テーブルの列情報を取り出す
+               Statement statement = conn.createStatement();
+               ResultSet rs = statement.executeQuery(sqlStr);
+               ResultSetMetaData rsmd = rs.getMetaData();
+               int count = rsmd.getColumnCount();
+               while (rs.next()) {
+                       for (int column = 1; column <= count; column++) {
+                               System.out.print("'"+ rs.getString(column) +"'");
+                               if (column < count) {
+                                       System.out.print(",");
+                               }
+                       }
+                       System.out.print("\n");
+               }
+               rs.close();
+               statement.close();
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/AboutDialog.java b/src/jp/co/areaweb/tools/gui/AboutDialog.java
new file mode 100644 (file)
index 0000000..0308c28
--- /dev/null
@@ -0,0 +1,132 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+
+@SuppressWarnings("serial")
+public class AboutDialog extends Dialog
+{
+    //{{DECLARE_CONTROLS
+    java.awt.Label label1;
+    java.awt.Button okButton;
+    java.awt.Label label2;
+    //}}
+
+    // Used for addNotify redundency check.
+    boolean fComponentsAdjusted = false;
+
+    class SymWindow extends java.awt.event.WindowAdapter
+    {
+        public void windowClosing(java.awt.event.WindowEvent event)
+        {
+            Object object = event.getSource();
+            if (object == AboutDialog.this)
+                AboutDialog_WindowClosing(event);
+        }
+    }
+
+    class SymAction implements java.awt.event.ActionListener
+    {
+        public void actionPerformed(java.awt.event.ActionEvent event)
+        {
+            Object object = event.getSource();
+            if (object == okButton)
+                okButton_Clicked(event);
+        }
+    }
+
+    public AboutDialog(Frame parent, boolean modal)
+    {
+        super(parent, modal);
+
+        // This code is automatically generated by Visual Cafe when you add
+        // components to the visual environment. It instantiates and initializes
+        // the components. To modify the code, only use code syntax that matches
+        // what Visual Cafe can generate, or Visual Cafe may be unable to back
+        // parse your Java file into its visual environment.
+
+
+        //{{INIT_CONTROLS
+        setLayout(null);
+        setVisible(false);
+        setSize(360,114);
+        label1 = new java.awt.Label(Manager.PROGRAM_NAME +" Version "+ Manager.PROGRAM_VARSION +" ("+ Manager.PROGRAM_UPDATE +")", Label.CENTER);
+        label1.setBounds(10,10,340,20);
+        add(label1);
+        okButton = new java.awt.Button();
+        okButton.setLabel("OK");
+        okButton.setBounds(145,65,66,27);
+        add(okButton);
+        label2 = new java.awt.Label("All rights reserved.Copyright(c) 2006,, TDOS.",Label.CENTER);
+        label2.setBounds(10,40,340,20);
+        add(label2);
+        setTitle("AboutDialog");
+        //}}
+
+        //{{REGISTER_LISTENERS
+        SymWindow aSymWindow = new SymWindow();
+        this.addWindowListener(aSymWindow);
+        SymAction lSymAction = new SymAction();
+        okButton.addActionListener(lSymAction);
+        //}}
+
+    }
+
+    public AboutDialog(Frame parent, String title, boolean modal)
+    {
+        this(parent, modal);
+        setTitle(title);
+    }
+
+    public void addNotify()
+    {
+        // Record the size of the window prior to calling parents addNotify.
+
+        super.addNotify();
+
+        // Only do this once.
+        if (fComponentsAdjusted)
+            return;
+
+        // Adjust components according to the insets
+        setSize(getInsets().left + getInsets().right + getSize().width, getInsets().top + getInsets().bottom + getSize().height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++)
+        {
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+
+        // Used for addNotify check.
+        fComponentsAdjusted = true;
+    }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b  if true, show the component; otherwise, hide the component.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b)
+    {
+        if(b)
+        {
+            Rectangle bounds = getParent().getBounds();
+            Rectangle abounds = getBounds();
+            setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
+            bounds.y + (bounds.height - abounds.height)/2);
+        }
+        super.setVisible(b);
+    }
+
+    void AboutDialog_WindowClosing(java.awt.event.WindowEvent event)
+    {
+        dispose();
+    }
+
+    void okButton_Clicked(java.awt.event.ActionEvent event)
+    {
+        //{{CONNECTION
+        // Clicked from okButton Hide the Dialog
+        dispose();
+        //}}
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/ClipbordTest.java b/src/jp/co/areaweb/tools/gui/ClipbordTest.java
new file mode 100644 (file)
index 0000000..1b6ed55
--- /dev/null
@@ -0,0 +1,39 @@
+package jp.co.areaweb.tools.gui;
+
+import java.awt.Component;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+
+public class ClipbordTest extends Component implements ClipboardOwner {
+
+       @Override
+       public void lostOwnership(Clipboard clipboard, Transferable contents) {
+               // TODO Auto-generated method stub
+
+       }
+
+       /**
+        * @param args
+        */
+       public static void main(String[] args) {
+               // TODO Auto-generated method stub
+
+               String str = "JAVA TEXT!";
+               if (args.length > 0) {
+                       str = args[0];
+               }
+               ClipbordTest.setClipboardString(str);
+       }
+       
+       public static void setClipboardString(String str) {
+               Toolkit kit = Toolkit.getDefaultToolkit();
+               Clipboard clip = kit.getSystemClipboard();
+
+               StringSelection ss = new StringSelection(str);
+               clip.setContents(ss, ss);
+       }
+
+}
diff --git a/src/jp/co/areaweb/tools/gui/Command.java b/src/jp/co/areaweb/tools/gui/Command.java
new file mode 100644 (file)
index 0000000..b0aac0a
--- /dev/null
@@ -0,0 +1,64 @@
+package jp.co.areaweb.tools.gui;
+import java.text.SimpleDateFormat;
+
+class Command extends Thread {
+       String[] args;          // コマンドパラメータ
+       private String commandName = "";        // コマンド名
+       @SuppressWarnings("unchecked")
+       private Class cmd;              // 実行対象インスタンス
+       
+       /**
+        * コンストラクタ:実行対象のインスタンスを得る
+        * @param cmd
+        */
+       @SuppressWarnings("unchecked")
+       public Command(Class cmd) {
+               super();
+               this.cmd = cmd;
+               this.commandName = cmd.getName();
+               this.args = new String[0];
+       }
+       
+       /**
+        * コマンドパラメータの設定
+        * @param folder
+        */
+       public void setArgs(String[] args) {
+               this.args = args;
+       }
+       
+       public void setCommandName(String name) {
+               this.commandName = name;
+       }
+       public String getCommandName() {
+               return this.commandName;
+       }
+
+       @SuppressWarnings("unchecked")
+       public void run() {
+               System.out.println("[START:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
+               for (int i=0; i < args.length; i++) {
+                       System.out.println(" args["+ i +"]: "+ this.args[i]);
+               }
+               System.out.println();
+
+               try {
+               try {
+                       java.lang.reflect.Method method = this.cmd.getMethod("main", new Class[] {String[].class});
+                       method.setAccessible(true);
+                       method.invoke(null, new Object[]{this.args});
+                               
+                       System.out.println();
+                       System.out.println("[END:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
+               }
+               catch (Exception e) {
+                       System.out.println("[ERR!:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
+                       throw e;
+               }
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+        }
+               System.out.println();
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/DirSizeDialog.java b/src/jp/co/areaweb/tools/gui/DirSizeDialog.java
new file mode 100644 (file)
index 0000000..97d372b
--- /dev/null
@@ -0,0 +1,173 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+import java.io.*;
+import javax.swing.*;
+
+/**
+ *     「NewFileList」処理 
+ */
+@SuppressWarnings("serial")
+public class DirSizeDialog extends JDialog {
+       public static final String TITLE = "DirSize";
+       
+    // Used for addNotify check.
+    boolean fComponentsAdjusted = false;
+    
+    //{{DECLARE_CONTROLS
+    JFrame parentFrame;        // Manager.class
+    JPanel argsPanel;          // パラメータ設定パネル       (上部)
+    ParameterPanel arg1Panel;          // parameter 1
+    
+    JPanel buttonPanel;     // ボタン配置パネル        (下部)
+    JButton closeButton;      // [クローズ]ボタン
+    JButton doButton;      // [実行]ボタン
+    TextArea textArea;      // 実行結果を表示するJTextArea    (中央)
+    //}}
+
+    class SymAction implements java.awt.event.ActionListener {
+        public void actionPerformed(java.awt.event.ActionEvent event) {
+            Object object = event.getSource();
+            if (object == closeButton) {
+                closeButton_Action(event);
+            }
+            else if (object == doButton) {
+                doButton_Action(event);
+            }
+        }
+    }
+
+    public DirSizeDialog(JFrame parentFrame) {
+        super(parentFrame, true);   // モーダルダイアログを基盤にする
+        this.parentFrame = parentFrame;
+                
+        // INIT_CONTROLS
+        Container container = getContentPane();
+        container.setLayout(new BorderLayout());
+        setVisible(false);
+        setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
+        setTitle(DirSizeDialog.TITLE);
+        setSize(500,480);
+        
+        // パラメータ設定パネル
+        argsPanel = new JPanel();
+        argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
+        
+        arg1Panel = new ParameterPanel("基準フォルダ: ", "C:\\TEMP");
+        argsPanel.add(arg1Panel);
+        
+        this.getContentPane().add("North", argsPanel);
+        
+        // コントロールパネル
+        buttonPanel = new JPanel();
+
+        doButton = new JButton("実行");
+        doButton.setToolTipText("処理を実行します.");
+        doButton.setEnabled(true);
+        buttonPanel.add(doButton);
+
+        closeButton = new JButton("閉じる");
+        closeButton.setToolTipText("処理を終了します.");
+        buttonPanel.add(closeButton);
+        
+        this.getContentPane().add("South", buttonPanel);
+        
+               // 説明文
+        textArea = new TextArea();
+        try {
+            textArea.append("/**\n");
+            textArea.append(" * "+ TITLE +"\n");
+            textArea.append(" * 指定したディレクトリのファイル利用量を調べる。\n");
+            textArea.append(" * exp) java -cp hayashi.jar jp.co.areaweb.tools.command.DirSize C:\\TEMP\n");
+            textArea.append(" */\n\n");
+        }
+        catch (Exception e) {
+            System.out.println(e.toString());
+        }
+        this.getContentPane().add("Center", textArea);
+
+        //{{REGISTER_LISTENERS
+        SymAction lSymAction = new SymAction();
+        closeButton.addActionListener(lSymAction);
+        doButton.addActionListener(lSymAction);
+        //}}
+    }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b) {
+        if(b) {
+            setLocation(80, 80);
+        }
+        super.setVisible(b);
+    }
+
+    public void addNotify()    {
+        // Record the size of the window prior to calling parents addNotify.
+        Dimension d = getSize();
+
+        super.addNotify();
+
+        if (fComponentsAdjusted)
+            return;
+
+        // Adjust components according to the insets
+        setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++)    {
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+        fComponentsAdjusted = true;
+    }
+
+    /**
+     * [実行]ボタンをクリックしたときの動作
+     * @param event
+     */
+    void doButton_Action(java.awt.event.ActionEvent event) {
+        doButton.setEnabled(false);
+        
+        PrintStream defOut = System.out;
+        PrintStream defErr = System.err;
+
+       ByteArrayOutputStream stdout = new ByteArrayOutputStream();
+        try {
+               System.setOut(new PrintStream(stdout));
+               System.setErr(new PrintStream(stdout));
+
+               Command command = new Command(jp.co.areaweb.tools.command.DirSize.class);
+               String[] args = new String[1];
+               args[0] = arg1Panel.getText();
+               command.setArgs(args);
+               command.start();                // コマンドを実行
+               while (command.isAlive()) {
+                       Thread.sleep(1000);
+                textArea.append(stdout.toString());
+                stdout.reset();
+               }
+               textArea.append(stdout.toString());
+               JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
+        }
+        finally {
+               System.setOut(defOut);
+               System.setErr(defErr);
+            doButton.setEnabled(true);
+        }
+    }
+
+    void closeButton_Action(java.awt.event.ActionEvent event) {
+        dispose();
+    }
+    
+    void changeSQL_Action(java.awt.event.ActionEvent event) {
+        textArea.setText("");
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/DirectoryFilter.java b/src/jp/co/areaweb/tools/gui/DirectoryFilter.java
new file mode 100644 (file)
index 0000000..071466c
--- /dev/null
@@ -0,0 +1,18 @@
+package jp.co.areaweb.tools.gui;
+
+import java.io.File;
+
+import javax.swing.filechooser.FileFilter;
+
+public class DirectoryFilter extends FileFilter {
+       @Override
+       public boolean accept(File f) {
+               return f.isDirectory();
+       }
+
+       @Override
+       public String getDescription() {
+               return "Just only Directory";
+       }
+
+}
diff --git a/src/jp/co/areaweb/tools/gui/Manager.java b/src/jp/co/areaweb/tools/gui/Manager.java
new file mode 100644 (file)
index 0000000..72e9abd
--- /dev/null
@@ -0,0 +1,233 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+import java.io.*;
+import javax.swing.*;
+
+/**
+ * 本プログラムのメインクラス
+ */
+@SuppressWarnings("serial")
+public class Manager extends JFrame
+{
+       public static final String PROGRAM_NAME = "ミニプログラム";
+       public static final String PROGRAM_VARSION = "0.1";
+       public static final String PROGRAM_UPDATE = "2006/03/13";
+       
+    // Used for addNotify check.
+    boolean fComponentsAdjusted = false;
+    
+    //{{DECLARE_CONTROLS
+    JTextArea textArea;
+    //JTextPane textPane;
+    //}}
+
+    //{{DECLARE_MENUS
+    java.awt.MenuBar mainMenuBar;
+    java.awt.Menu menu1;
+    java.awt.MenuItem miDoNewFileList;
+    java.awt.MenuItem miDoDirSize;
+    java.awt.MenuItem miDoReadXML;
+    java.awt.MenuItem miExit;
+    java.awt.Menu menu3;
+    java.awt.MenuItem miAbout;
+    //}}
+
+    class SymWindow extends java.awt.event.WindowAdapter {
+        /**
+         * このFrameが閉じられるときの動作。
+         * 終了確認のパネルを表示して、[OK]が押されたら終了する
+         */
+        public void windowClosing(java.awt.event.WindowEvent event) {
+            Object object = event.getSource();
+            if (object == Manager.this)
+                DbMang_WindowClosing(event);
+        }
+    }
+
+    class SymAction implements java.awt.event.ActionListener {
+        public void actionPerformed(java.awt.event.ActionEvent event) {
+            Object object = event.getSource();
+            if (object == miAbout) {
+                miAbout_Action(event);
+            }
+            else if (object == miDoNewFileList) {
+                miDoNewFileList_Action(event);
+            }
+            else if (object == miDoDirSize) {
+                miDoDirSize_Action(event);
+            }
+            else if (object == miDoReadXML) {
+                miDoReadXML_Action(event);
+            }
+            else if (object == miExit) {
+                miExit_Action(event);
+            }
+        }
+    }
+
+       /**
+        * データベース内のテーブルを一覧で表示するFrame
+        */
+    public Manager()
+    {
+        // INIT_CONTROLS
+        //setLayout(new BorderLayout());
+        Container container = getContentPane();
+        container.setLayout(new BorderLayout());
+        setVisible(false);
+        setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
+        setTitle(Manager.PROGRAM_NAME +" v"+ Manager.PROGRAM_VARSION);
+        
+        // 説明文
+        textArea = new JTextArea(5,20);
+        textArea.setEditable(false);
+        try {
+            textArea.append("1.メニュー[File]-["+ NewFileListDialog.TITLE +"]\n");
+            textArea.append("\t指定された時刻以降に更新されたファイルをリストアップする\n");
+            textArea.append("\n\n");
+
+            textArea.append("2.メニュー[File]-["+ DirSizeDialog.TITLE +"]\n");
+            textArea.append("\tディレクトリのファイル利用量を調べる\n");
+            textArea.append("\n\n");
+
+            textArea.append("3.メニュー[File]-["+ ReadXMLDialog.TITLE +"]\n");
+            textArea.append("\tファイルが整形式XML文書であるかどうかを調べる\n");
+            textArea.append("\n\n");
+
+            BufferedReader br = new BufferedReader(new FileReader(new File("README.txt")));
+            String line;
+            while((line = br.readLine()) != null) {
+                textArea.append(line + "\n");
+            }
+            br.close();
+        }
+        catch (Exception e) {
+            System.out.println(e.toString());
+            textArea.append(e.toString());
+        }
+        this.getContentPane().add("Center", textArea);
+        
+        // INIT_MENUS
+        menu1 = new java.awt.Menu("File");
+        miDoNewFileList = new java.awt.MenuItem(NewFileListDialog.TITLE);
+        miDoNewFileList.setFont(new Font("Dialog", Font.PLAIN, 12));
+        menu1.add(miDoNewFileList);
+        miDoDirSize = new java.awt.MenuItem(DirSizeDialog.TITLE);
+        miDoDirSize.setFont(new Font("Dialog", Font.PLAIN, 12));
+        menu1.add(miDoDirSize);
+        miDoReadXML = new java.awt.MenuItem(ReadXMLDialog.TITLE);
+        miDoReadXML.setFont(new Font("Dialog", Font.PLAIN, 12));
+        menu1.add(miDoReadXML);
+        
+        miExit = new java.awt.MenuItem("Quit");
+        miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
+        menu1.add(miExit);
+
+        miAbout = new java.awt.MenuItem("About Manager...");
+        miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
+
+        menu3 = new java.awt.Menu("Help");
+        menu3.setFont(new Font("Dialog", Font.PLAIN, 12));
+        menu3.add(miAbout);
+
+        mainMenuBar = new java.awt.MenuBar();
+        mainMenuBar.setHelpMenu(menu3);
+        mainMenuBar.add(menu1);
+        mainMenuBar.add(menu3);
+        setMenuBar(mainMenuBar);
+        
+
+        //{{REGISTER_LISTENERS
+        SymWindow aSymWindow = new SymWindow();
+        this.addWindowListener(aSymWindow);
+        SymAction lSymAction = new SymAction();
+        miAbout.addActionListener(lSymAction);
+        miDoNewFileList.addActionListener(lSymAction);
+        miDoDirSize.addActionListener(lSymAction);
+        miDoReadXML.addActionListener(lSymAction);
+        miExit.addActionListener(lSymAction);
+        //}}
+    }
+
+    /**
+     * Shows or hides the component depending on the boolean flag b.
+     * @param b        trueのときコンポーネントを表示; その他のとき, componentを隠す.
+     * @see java.awt.Component#isVisible
+     */
+    public void setVisible(boolean b) {
+        if(b) {
+            setLocation(50, 50);
+            
+        }
+        super.setVisible(b);
+    }
+
+       /**
+        * このクラスをインスタンスを生成して表示する。
+        * コマンドラインの引数はありません。
+        */    
+    static public void main(String args[]) {
+        (new Manager()).setVisible(true);
+    }
+
+    public void addNotify()    {
+        // Record the size of the window prior to calling parents addNotify.
+        Dimension d = getSize();
+
+        super.addNotify();
+
+        if (fComponentsAdjusted)
+            return;
+
+        // Adjust components according to the insets
+        setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++){
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+        fComponentsAdjusted = true;
+    }
+
+    void DbMang_WindowClosing(java.awt.event.WindowEvent event)        {
+        setVisible(false);  // hide the Manager
+        dispose();                     // free the system resources
+        System.exit(0);                // close the application
+    }
+
+    void miAbout_Action(java.awt.event.ActionEvent event) {
+        // Action from About Create and show as modal
+        (new AboutDialog(this, true)).setVisible(true);
+    }
+    
+    /**
+     * メニュー[NewFileList]をセレクトしたときの動作
+     * @param event
+     */
+    void miDoNewFileList_Action(java.awt.event.ActionEvent event) {
+        (new NewFileListDialog(this)).setVisible(true);
+    }
+    
+    /**
+     * メニュー[DirSize]をセレクトしたときの動作
+     * @param event
+     */
+    void miDoDirSize_Action(java.awt.event.ActionEvent event) {
+        (new DirSizeDialog(this)).setVisible(true);
+    }
+    
+    /**
+     * メニュー[ReadXML]をセレクトしたときの動作
+     * @param event
+     */
+    void miDoReadXML_Action(java.awt.event.ActionEvent event) {
+        (new ReadXMLDialog(this)).setVisible(true);
+    }
+    
+    
+    void miExit_Action(java.awt.event.ActionEvent event) {
+        // Action from Exit Create and show as modal
+        (new QuitDialog(this, true)).setVisible(true);
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/NewFileListDialog.java b/src/jp/co/areaweb/tools/gui/NewFileListDialog.java
new file mode 100644 (file)
index 0000000..65c119b
--- /dev/null
@@ -0,0 +1,184 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+import javax.swing.*;
+
+/**
+ *     「NewFileList」処理 
+ */
+@SuppressWarnings("serial")
+public class NewFileListDialog extends JDialog {
+       public static final String TITLE = "NewFileList";
+       
+    // Used for addNotify check.
+    boolean fComponentsAdjusted = false;
+    
+    //{{DECLARE_CONTROLS
+    JFrame parentFrame;        // Manager.class
+    JPanel argsPanel;          // パラメータ設定パネル       (上部)
+    ParameterPanel arg1Panel;          // parameter 1
+    ParameterPanel arg2Panel;          // parameter 2
+    
+    JPanel buttonPanel;     // ボタン配置パネル        (下部)
+    JButton closeButton;      // [クローズ]ボタン
+    JButton doButton;      // [実行]ボタン
+    TextArea textArea;      // 実行結果を表示するJTextArea    (中央)
+    //}}
+
+    class SymAction implements java.awt.event.ActionListener {
+        public void actionPerformed(java.awt.event.ActionEvent event) {
+            Object object = event.getSource();
+            if (object == closeButton) {
+                closeButton_Action(event);
+            }
+            else if (object == doButton) {
+                doButton_Action(event);
+            }
+        }
+    }
+
+    public NewFileListDialog(JFrame parentFrame) {
+        super(parentFrame, true);   // モーダルダイアログを基盤にする
+        this.parentFrame = parentFrame;
+                
+        // INIT_CONTROLS
+        Container container = getContentPane();
+        container.setLayout(new BorderLayout());
+        setVisible(false);
+        setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
+        setTitle(NewFileListDialog.TITLE);
+        setSize(500,480);
+        
+        // パラメータ設定パネル
+        argsPanel = new JPanel();
+        argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
+        
+        arg1Panel = new ParameterPanel("基準フォルダ: ", "C:\\TEMP");
+        argsPanel.add(arg1Panel);
+        
+       Calendar cal = Calendar.getInstance();
+               cal.add(Calendar.DATE, -1);     // 前日にする
+        arg2Panel = new ParameterPanel("基準日時: ", (new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss")).format(cal.getTime()));
+        argsPanel.add(arg2Panel);
+        
+        this.getContentPane().add("North", argsPanel);
+        
+        // コントロールパネル
+        buttonPanel = new JPanel();
+
+        doButton = new JButton("実行");
+        doButton.setToolTipText("処理を実行します.");
+        doButton.setEnabled(true);
+        buttonPanel.add(doButton);
+
+        closeButton = new JButton("閉じる");
+        closeButton.setToolTipText("処理を終了します.");
+        buttonPanel.add(closeButton);
+        
+        this.getContentPane().add("South", buttonPanel);
+        
+               // 説明文
+        textArea = new TextArea();
+        try {
+            textArea.append("/**\n");
+            textArea.append(" * "+ TITLE +"\n");
+            textArea.append(" * 指定された時刻以降に更新されたファイルをリストアップし、その絶対パス名を標準出力に出力する。\n");
+            textArea.append(" * jp.co.areaweb.tools.command.NewFileList [directory] [CCYY.MM.DD-HH:mm:ss]\n");
+            textArea.append(" * exp) java -cp hayashi.jar jp.co.areaweb.tools.command.NewFileList \\Server01\\Share\\フォルダ 2002.05.29-00:50:00\n");
+            textArea.append(" */\n\n");
+        }
+        catch (Exception e) {
+            System.out.println(e.toString());
+        }
+        this.getContentPane().add("Center", textArea);
+
+        //{{REGISTER_LISTENERS
+        SymAction lSymAction = new SymAction();
+        closeButton.addActionListener(lSymAction);
+        doButton.addActionListener(lSymAction);
+        //}}
+    }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b) {
+        if(b) {
+            setLocation(80, 80);
+        }
+        super.setVisible(b);
+    }
+
+    public void addNotify()    {
+        // Record the size of the window prior to calling parents addNotify.
+        Dimension d = getSize();
+
+        super.addNotify();
+
+        if (fComponentsAdjusted)
+            return;
+
+        // Adjust components according to the insets
+        setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++)    {
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+        fComponentsAdjusted = true;
+    }
+
+    /**
+     * [実行]ボタンをクリックしたときの動作
+     * @param event
+     */
+    void doButton_Action(java.awt.event.ActionEvent event) {
+        doButton.setEnabled(false);
+        
+        PrintStream defOut = System.out;
+        PrintStream defErr = System.err;
+
+       ByteArrayOutputStream stdout = new ByteArrayOutputStream();
+        try {
+               System.setOut(new PrintStream(stdout));
+               System.setErr(new PrintStream(stdout));
+
+               Command command = new Command(jp.co.areaweb.tools.command.NewFileList.class);
+               String[] args = new String[2];
+               args[0] = arg1Panel.getText();
+               args[1] = arg2Panel.getText();
+               command.setArgs(args);
+               command.start();                // コマンドを実行
+               while (command.isAlive()) {
+                       Thread.sleep(1000);
+                textArea.append(stdout.toString());
+                stdout.reset();
+               }
+               textArea.append(stdout.toString());
+               JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
+        }
+        finally {
+               System.setOut(defOut);
+               System.setErr(defErr);
+            doButton.setEnabled(true);
+        }
+    }
+
+    void closeButton_Action(java.awt.event.ActionEvent event) {
+        dispose();
+    }
+    
+    void changeSQL_Action(java.awt.event.ActionEvent event) {
+        textArea.setText("");
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/ParameterPanel.java b/src/jp/co/areaweb/tools/gui/ParameterPanel.java
new file mode 100644 (file)
index 0000000..54397ba
--- /dev/null
@@ -0,0 +1,48 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.LayoutManager;
+
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+/**
+ * パラメータを設定する為のパネル。
+ * この1インスタンスで、1パラメータをあらわす。
+ */
+@SuppressWarnings("serial")
+public class ParameterPanel extends JPanel {
+    JTextField argField;
+    JLabel argLabel;
+
+       public ParameterPanel(String label, String text) {
+               super();
+               
+               argLabel = new JLabel(label);
+               argField = new JTextField(text);
+               
+        this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
+        this.add(argLabel);
+        this.add(argField);
+       }
+       
+       public String getText() {
+               return this.argField.getText();
+       }
+
+       public ParameterPanel(boolean isDoubleBuffered) {
+               super(isDoubleBuffered);
+               // TODO 自動生成されたコンストラクター・スタブ
+       }
+
+       public ParameterPanel(LayoutManager layout) {
+               super(layout);
+               // TODO 自動生成されたコンストラクター・スタブ
+       }
+
+       public ParameterPanel(LayoutManager layout, boolean isDoubleBuffered) {
+               super(layout, isDoubleBuffered);
+               // TODO 自動生成されたコンストラクター・スタブ
+       }
+
+}
diff --git a/src/jp/co/areaweb/tools/gui/QuitDialog.java b/src/jp/co/areaweb/tools/gui/QuitDialog.java
new file mode 100644 (file)
index 0000000..a7ec4ff
--- /dev/null
@@ -0,0 +1,135 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+import java.awt.event.*;
+
+@SuppressWarnings("serial")
+public class QuitDialog extends Dialog
+{
+    // Used for addNotify check.
+    boolean fComponentsAdjusted = false;
+
+    //{{DECLARE_CONTROLS
+    java.awt.Button yesButton;
+    java.awt.Button noButton;
+    java.awt.Label label1;
+    //}}
+
+    class SymWindow extends java.awt.event.WindowAdapter
+    {
+        public void windowClosing(java.awt.event.WindowEvent event)
+        {
+            Object object = event.getSource();
+            if (object == QuitDialog.this)
+                QuitDialog_WindowClosing(event);
+        }
+    }
+
+    class SymAction implements java.awt.event.ActionListener
+    {
+        public void actionPerformed(java.awt.event.ActionEvent event)
+        {
+            Object object = event.getSource();
+            if (object == noButton)
+                noButton_Clicked(event);
+            else if (object == yesButton)
+                yesButton_Clicked(event);
+        }
+    }
+
+       public QuitDialog(Frame parent, boolean modal)
+       {
+               super(parent, modal);
+
+               // This code is automatically generated by Visual Cafe when you add
+               // components to the visual environment. It instantiates and initializes
+               // the components. To modify the code, only use code syntax that matches
+               // what Visual Cafe can generate, or Visual Cafe may be unable to back
+               // parse your Java file into its visual environment.
+               //{{INIT_CONTROLS
+               setLayout(null);
+               setSize(getInsets().left + getInsets().right + 337,getInsets().top + getInsets().bottom + 135);
+               yesButton = new java.awt.Button(" Yes ");
+               yesButton.setBounds(getInsets().left + 72,getInsets().top + 80,79,22);
+               yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
+               add(yesButton);
+               noButton = new java.awt.Button("  No  ");
+               noButton.setBounds(getInsets().left + 185,getInsets().top + 80,79,22);
+               noButton.setFont(new Font("Dialog", Font.BOLD, 12));
+               add(noButton);
+               label1 = new java.awt.Label("Do you really want to quit?",Label.CENTER);
+               label1.setBounds(78,33,180,23);
+               add(label1);
+               setTitle("DbMang - Quit");
+               setResizable(false);
+               //}}
+
+               //{{REGISTER_LISTENERS
+               SymWindow aSymWindow = new SymWindow();
+               addWindowListener(aSymWindow);
+               SymAction lSymAction = new SymAction();
+               noButton.addActionListener(lSymAction);
+               yesButton.addActionListener(lSymAction);
+               //}}
+       }
+
+    public void addNotify()
+    {
+        // Record the size of the window prior to calling parents addNotify.
+        Dimension d = getSize();
+
+               super.addNotify();
+
+               if (fComponentsAdjusted)
+                   return;
+
+               // Adjust components according to the insets
+               setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+               Component components[] = getComponents();
+               for (int i = 0; i < components.length; i++)
+               {
+                   Point p = components[i].getLocation();
+                   p.translate(getInsets().left, getInsets().top);
+                   components[i].setLocation(p);
+               }
+               fComponentsAdjusted = true;
+    }
+
+    public QuitDialog(Frame parent, String title, boolean modal)
+    {
+        this(parent, modal);
+        setTitle(title);
+    }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b  if true, show the component; otherwise, hide the component.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b)
+    {
+        if(b)
+        {
+            Rectangle bounds = getParent().getBounds();
+            Rectangle abounds = getBounds();
+
+            setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
+            bounds.y + (bounds.height - abounds.height)/2);
+        }
+        super.setVisible(b);
+    }
+
+    void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
+    {
+        dispose();
+    }
+
+    void yesButton_Clicked(java.awt.event.ActionEvent event)
+    {
+        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)getParent(), WindowEvent.WINDOW_CLOSING));
+    }
+
+    void noButton_Clicked(java.awt.event.ActionEvent event)
+    {
+        dispose();
+    }
+}
diff --git a/src/jp/co/areaweb/tools/gui/ReadXMLDialog.java b/src/jp/co/areaweb/tools/gui/ReadXMLDialog.java
new file mode 100644 (file)
index 0000000..61f51a2
--- /dev/null
@@ -0,0 +1,173 @@
+package jp.co.areaweb.tools.gui;
+import java.awt.*;
+import java.io.*;
+import javax.swing.*;
+
+/**
+ *     「ReadXML」処理 
+ */
+@SuppressWarnings("serial")
+public class ReadXMLDialog extends JDialog {
+       public static final String TITLE = "ReadXML";
+       
+    // Used for addNotify check.
+    boolean fComponentsAdjusted = false;
+    
+    //{{DECLARE_CONTROLS
+    JFrame parentFrame;        // Manager.class
+    JPanel argsPanel;          // パラメータ設定パネル       (上部)
+    ParameterPanel arg1Panel;          // parameter 1
+    
+    JPanel buttonPanel;     // ボタン配置パネル        (下部)
+    JButton closeButton;      // [クローズ]ボタン
+    JButton doButton;      // [実行]ボタン
+    TextArea textArea;      // 実行結果を表示するJTextArea    (中央)
+    //}}
+
+    class SymAction implements java.awt.event.ActionListener {
+        public void actionPerformed(java.awt.event.ActionEvent event) {
+            Object object = event.getSource();
+            if (object == closeButton) {
+                closeButton_Action(event);
+            }
+            else if (object == doButton) {
+                doButton_Action(event);
+            }
+        }
+    }
+
+    public ReadXMLDialog(JFrame parentFrame) {
+        super(parentFrame, true);   // モーダルダイアログを基盤にする
+        this.parentFrame = parentFrame;
+                
+        // INIT_CONTROLS
+        Container container = getContentPane();
+        container.setLayout(new BorderLayout());
+        setVisible(false);
+        setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
+        setTitle(ReadXMLDialog.TITLE);
+        setSize(500,480);
+        
+        // パラメータ設定パネル
+        argsPanel = new JPanel();
+        argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
+        
+        arg1Panel = new ParameterPanel("ファイル: ", "build.xml");
+        argsPanel.add(arg1Panel);
+        
+        this.getContentPane().add("North", argsPanel);
+        
+        // コントロールパネル
+        buttonPanel = new JPanel();
+
+        doButton = new JButton("実行");
+        doButton.setToolTipText("処理を実行します.");
+        doButton.setEnabled(true);
+        buttonPanel.add(doButton);
+
+        closeButton = new JButton("閉じる");
+        closeButton.setToolTipText("処理を終了します.");
+        buttonPanel.add(closeButton);
+        
+        this.getContentPane().add("South", buttonPanel);
+        
+               // 説明文
+        textArea = new TextArea();
+        try {
+            textArea.append("/**\n");
+            textArea.append(" * "+ TITLE +"\n");
+            textArea.append(" * 指定したファイルが整形式XML文書であるかどうかを調べる。\n");
+            textArea.append(" * exp) java -cp hayashi.jar;xerces.jar jp.co.areaweb.tools.command.ReadXML build.xml\n");
+            textArea.append(" */\n\n");
+        }
+        catch (Exception e) {
+            System.out.println(e.toString());
+        }
+        this.getContentPane().add("Center", textArea);
+
+        //{{REGISTER_LISTENERS
+        SymAction lSymAction = new SymAction();
+        closeButton.addActionListener(lSymAction);
+        doButton.addActionListener(lSymAction);
+        //}}
+    }
+
+    /**
+    * Shows or hides the component depending on the boolean flag b.
+    * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
+    * @see java.awt.Component#isVisible
+    */
+    public void setVisible(boolean b) {
+        if(b) {
+            setLocation(80, 80);
+        }
+        super.setVisible(b);
+    }
+
+    public void addNotify()    {
+        // Record the size of the window prior to calling parents addNotify.
+        Dimension d = getSize();
+
+        super.addNotify();
+
+        if (fComponentsAdjusted)
+            return;
+
+        // Adjust components according to the insets
+        setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
+        Component components[] = getComponents();
+        for (int i = 0; i < components.length; i++)    {
+            Point p = components[i].getLocation();
+            p.translate(getInsets().left, getInsets().top);
+            components[i].setLocation(p);
+        }
+        fComponentsAdjusted = true;
+    }
+
+    /**
+     * [実行]ボタンをクリックしたときの動作
+     * @param event
+     */
+    void doButton_Action(java.awt.event.ActionEvent event) {
+        doButton.setEnabled(false);
+        
+        PrintStream defOut = System.out;
+        PrintStream defErr = System.err;
+
+       ByteArrayOutputStream stdout = new ByteArrayOutputStream();
+        try {
+               System.setOut(new PrintStream(stdout));
+               System.setErr(new PrintStream(stdout));
+
+               Command command = new Command(jp.co.areaweb.tools.command.ReadXML.class);
+               String[] args = new String[1];
+               args[0] = arg1Panel.getText();
+               command.setArgs(args);
+               command.start();                // コマンドを実行
+               while (command.isAlive()) {
+                       Thread.sleep(1000);
+                textArea.append(stdout.toString());
+                stdout.reset();
+               }
+               textArea.append(stdout.toString());
+               JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
+        }
+        finally {
+               System.setOut(defOut);
+               System.setErr(defErr);
+            doButton.setEnabled(true);
+        }
+    }
+
+    void closeButton_Action(java.awt.event.ActionEvent event) {
+        dispose();
+    }
+    
+    void changeSQL_Action(java.awt.event.ActionEvent event) {
+        textArea.setText("");
+    }
+}
diff --git a/src/jp/co/areaweb/tools/mail/SendMail.java b/src/jp/co/areaweb/tools/mail/SendMail.java
new file mode 100644 (file)
index 0000000..052839c
--- /dev/null
@@ -0,0 +1,347 @@
+package jp.co.areaweb.tools.mail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
+import java.util.Properties;
+import java.util.Vector;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.Store;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimeUtility;
+
+import jp.co.areaweb.tools.mail.SiteData;
+
+/**
+ * <p>Eメールを送信するためのクラス<br/>
+ * JavaMailを使用する</p>
+ * @see <a href="http://java.sun.com/products/javamail/javadocs/index.html">JavaMail API</a>
+ * 
+ * @author hayashi
+ * @version 2010/02/05 SMTPサーバーのポート番号指定を追加
+ */
+public class SendMail
+{
+    public static void main(java.lang.String[] args) {
+        try {
+               SendMail mail = new SendMail("yuumail.properties");
+            mail.setSubject("[proxSafe] SendMail テスト");
+            mail.setContent("本文\n");
+            mail.setAttachment(new File("mail-1.4.jar"));
+            mail.send();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected Vector<String> toVector = new Vector<String>(); // プロパティ 送信先(to) の値
+    protected Vector<String> ccVector = new Vector<String>(); // プロパティ 送信先(Cc) の値
+    protected Vector<String> bccVector = new Vector<String>();    // プロパティ 送信先(Bcc) の値
+    protected String from = null;         // プロパティ 発信元(from) の値
+    protected String subject;             // プロパティ 題名(subject) の値
+    protected String content;             // プロパティ 本文(content) の値
+    protected String mailHost;            // プロパティ SMTP(mail.smtp.host) の値
+    protected String mailHostPort;        // プロパティ SMTP_PORT(mail.smtp.port) の値
+    
+    protected Vector<File> attachments = new Vector<File>();   // 添付ファイル
+    protected Vector<String> attachNames = new Vector<String>();               // 添付ファイル名
+    
+    protected boolean POP_before_SMTP = false;
+    protected boolean USER_AUTH = false;
+    protected String popServer = "";
+    protected String userId = "";
+    protected String password ="";
+    protected Session session = null;
+    
+    /** 
+     * 新しい YuuMail インスタンスを作成する 
+     * @param propertyFile     メール設定ファイルのパス名称
+     */
+    public SendMail(String propertyFile) {
+        this(new SiteData(propertyFile));
+    }
+
+    /**
+     * 新しい インスタンスを作成する 
+     * @param siteData メール設定値を包含したオブジェクト
+     */
+    public SendMail(SiteData siteData) {
+        super();
+        
+        if (!siteData.MAIL_SMTP.equals("")) {
+            this.setMailHost(siteData.MAIL_SMTP);
+        }
+        if (!siteData.MAIL_SMTP_PORT.equals("")) {
+            this.setMailPort(siteData.MAIL_SMTP_PORT);
+        }
+        if (!siteData.MAIL_TO.equals("")) {
+            this.toVector.addElement(siteData.MAIL_TO);
+        }
+        if (!siteData.MAIL_CC.equals("")) {
+            this.ccVector.addElement(siteData.MAIL_CC);
+        }
+        if (!siteData.MAIL_BCC.equals("")) {
+            this.bccVector.addElement(siteData.MAIL_BCC);
+        }
+        if (!siteData.MAIL_FROM.equals("")) {
+            this.from = siteData.MAIL_FROM;
+        }
+
+        this.POP_before_SMTP = siteData.POP_before_SMTP;
+        this.USER_AUTH = siteData.USER_AUTH;
+        this.popServer = siteData.MAIL_POP;
+        this.userId = siteData.USER_ID;
+        this.password = siteData.PASSWORD;
+        
+        
+        // メール(MimeMessageオブジェクト)を生成する
+        Properties props = System.getProperties();
+        props.put("mail.smtp.host", getMailHost());
+        props.put("mail.smtp.port", getMailPort());
+        if (this.USER_AUTH) {
+               props.put("mail.smtp.auth", "true");
+        }
+        this.session = Session.getDefaultInstance(props, null);
+    }
+    
+    /** 
+     * プロパティ mailHost の取得メソッド。
+     * @return プロパティ mailHost の値。
+     */
+    public String getMailHost() {
+        return this.mailHost;
+    }
+    
+    /** 
+     * SMTPサーバーを設定
+     *  @param mailHost SMTPサーバー名またはSMTPサーバーのIPアドレス
+    */
+    public void setMailHost(String mailHost) {
+        this.mailHost = mailHost;
+    }
+    
+    /** 
+     * プロパティ SMTPポート番号 の取得メソッド。
+     * @return SMTPポート番号を表す文字列(デシマル)
+     */
+    public String getMailPort() {
+        return this.mailHostPort;
+    }
+
+    /** 
+     * SMTPポート番号を設定
+     *  @param portStr SMTPポート番号を表す文字列(デシマル)
+     */
+    public void setMailPort(String portStr) {
+        this.mailHostPort = portStr;
+    }
+    
+    /**
+     * 送信先(To)を設定.数設定可
+     * @param to 送信先(To)
+     */
+    public void setTo(String to) {
+        if (!to.equals("")) {
+            toVector.addElement(to);
+        }
+    }
+    
+    /**
+     * 送信先(Cc)を設定。複数設定可
+     * @param cc 送信先(cc)
+     */
+    public void setCc(String cc) {
+        if (!cc.equals("")) {
+            ccVector.addElement(cc);
+        }
+    }
+    
+    /**
+     * 送信先(Bco)を設定.複数選択可
+     * @param bcc 送信先(Bcc)
+     */
+    public void setBcc(String bcc) {
+        if (!bcc.equals("")) {
+            bccVector.addElement(bcc);
+        }
+    }
+    
+    /** 
+     * プロパティ from の取得メソッド。
+     * @return プロパティ from の値。
+     */
+    public String getFrom() {
+        return from;
+    }
+    
+    /** 
+     * プロパティ 送信元(from) の設定メソッド。
+     * @param from 送信元メールアドレス
+     */
+    public void setFrom(String from) {
+        this.from = from;
+    }
+    
+    /** 
+     * プロパティ subject の取得メソッド。
+     * @return プロパティ subject の値。
+     */
+    public String getSubject() {
+        return subject;
+    }
+    
+    /**
+     * プロパティ 題名(subject) の設定メソッド。
+     * メールタイトル(題名)を設定
+     * @param subject メールタイトル(題名)
+     */
+    public void setSubject(String subject) {
+        this.subject = subject;
+    }
+    
+    /** 
+     * 本文(content)の取得メソッド。
+     * @return 本文の値。
+     */
+    public String getContent() {
+        return this.content;
+    }
+    
+    /** 
+     * 本文(content)の設定メソッド。
+     * 本文(content)を設定
+     * @param content 本文(content)
+     */
+    public void setContent(String content) {
+        this.content = content;
+    }
+    
+    /** 
+     * 添付ファイルの設定メソッド。
+     * 添付するファイル(attachment)を設定.添付ファイルは複数設定可。
+     * @param attachment 添付するファイル(attachment)
+     * @throws FileNotFoundException 添付するファイルが見つからなかった。
+     */
+    public void setAttachment(File attachment) throws FileNotFoundException {
+        new FileInputStream(attachment);    // ファイルが実存することをチェックする。
+        attachments.addElement(attachment);
+        attachNames.addElement(attachment.getName());
+    }
+    
+    /** 
+     * 添付ファイルの設定メソッド。
+     * 添付するファイル(attachment)を設定.添付ファイルは複数設定可。
+     * @param attachment 添付するファイル(attachment)
+     * @param name 添付するファイルの表示名
+     * @throws FileNotFoundException 添付するファイルが見つからなかった。
+     */
+     public void setAttachment(File attachment, String name) throws FileNotFoundException {
+         new FileInputStream(attachment);    // ファイルが実存することをチェックする。
+         attachments.addElement(attachment);
+         attachNames.addElement(name);
+     }
+     
+    /**
+     * メールを送信
+     * @throws MessagingException エラー:メールの送信に失敗しました。
+     * @throws UnsupportedEncodingException エラー:メールの文字エンコードに失敗しました。
+     */
+    public void send() throws MessagingException, UnsupportedEncodingException {
+        //-------------------------
+        // POP before SMTP 対応
+        //--
+        Store store = null;
+        if (this.POP_before_SMTP == true) {
+               System.out.println("store.connect("+ popServer +", '"+ userId +"', '"+ password +"')");
+               store = this.session.getStore("pop3");
+               store.connect(popServer, userId, password);
+        }
+        else {
+               System.out.println("no POP_before_SMTP!");
+        }
+
+        MimeMessage message = createMessage();
+        
+        if (this.USER_AUTH) {
+               System.out.println("transport.connect(null, '"+ userId +"', '"+ password+"')");
+            Transport transport = this.session.getTransport("smtp");
+               transport.connect(null, userId, password);
+            transport.sendMessage(message, message.getAllRecipients());
+        }
+        else {
+               System.out.println("no SMTP_AUTH!");
+               Transport.send(message);
+        }
+        
+        if (this.POP_before_SMTP == true) {
+            store.close();
+        }
+    }
+    
+    /**
+     * 新規にメールインスタンスを生成する。
+     * @return メールインスタンス
+     * @throws MessagingException メール送信に失敗しました。
+     * @throws UnsupportedEncodingException 文字エンコーディングに失敗した。
+     */
+    protected MimeMessage createMessage() throws MessagingException, UnsupportedEncodingException {
+        MimeMessage msg = new MimeMessage(this.session);
+        
+        // 送信先(To)
+        InternetAddress[] toList = new InternetAddress[toVector.size()];
+        for (int i=0; i < toVector.size(); i++) {
+            toList[i] = new InternetAddress(toVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.TO, toList);
+
+        // 送信先(Cc)
+        InternetAddress[] ccList = new InternetAddress[ccVector.size()];
+        for (int i=0; i < ccVector.size(); i++) {
+            ccList[i] = new InternetAddress(ccVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.CC, ccList);
+
+        // 送信先(Bcc)
+        InternetAddress[] bccList = new InternetAddress[bccVector.size()];
+        for (int i=0; i < bccVector.size(); i++) {
+            bccList[i] = new InternetAddress(bccVector.elementAt(i));
+        }
+        msg.setRecipients(Message.RecipientType.BCC, bccList);
+        
+        // 送信元(From)
+        msg.setFrom(new InternetAddress(getFrom()));
+
+        // 件名(Subject)
+        msg.setSubject(MimeUtility.encodeText(getSubject(), "iso-2022-jp", "B"));
+
+        // 本文(Content)
+        MimeMultipart naiyou = new MimeMultipart();
+        msg.setContent(naiyou);
+        
+        MimeBodyPart honbun = new MimeBodyPart();
+        honbun.setContent(getContent(), "text/plain; charset=\"iso-2022-jp\"");
+        naiyou.addBodyPart(honbun);
+
+        // 添付(Attachment)
+        for (int i=0; i < attachments.size(); i++) {
+            File attachFile = attachments.elementAt(i);
+            MimeBodyPart tenpu = new MimeBodyPart();
+            javax.activation.FileDataSource dfs = new javax.activation.FileDataSource(attachFile);
+            javax.activation.DataHandler dh = new javax.activation.DataHandler(dfs);
+            tenpu.setDataHandler(dh);
+            tenpu.setFileName(attachNames.elementAt(i));
+            naiyou.addBodyPart(tenpu);
+        }
+        
+        return msg;
+    }
+}
diff --git a/src/jp/co/areaweb/tools/mail/SiteData.java b/src/jp/co/areaweb/tools/mail/SiteData.java
new file mode 100644 (file)
index 0000000..619b76a
--- /dev/null
@@ -0,0 +1,99 @@
+package jp.co.areaweb.tools.mail;
+
+import hayashi.yuu.tools.properties.Properties;
+import java.io.FileInputStream;
+
+/**
+ * メールアカウント設定情報を保持するインスタンス
+ * @author hayashi
+ * @version    2010/02/05      項目'MAIL_SMTP_PORT'を追加
+ */
+public class SiteData {
+    public String MAIL_SMTP = "192.168.0.10";
+    public String MAIL_SMTP_PORT = "25";
+    public String MAIL_FROM = "webserver@xxx.co.jp";
+    public String MAIL_TO = "";
+    public String MAIL_CC = "";
+    public String MAIL_BCC = "";
+    
+    /**
+     * 'POP before SMTP'認証を行うかどうか
+     */
+    public boolean POP_before_SMTP = false;
+    
+    /**
+     * 'USER_AUTH'認証を行うかどうか
+     */
+    public boolean USER_AUTH = false;
+    
+    /**
+     * POPサーバー名('POP before SMTP'認証時のみ)
+     */
+    public String MAIL_POP = "";
+    
+    /**
+     * POPアカウント('POP before SMTP'認証時のみ)
+     */
+    public String USER_ID = "";
+    
+    /**
+     * POPアカウントのパスワード('POP before SMTP'認証時のみ)
+     */
+    public String PASSWORD = "";
+
+    /**
+     * 指定されたプロパティファイルに定義された値でインスタンスを生成する。
+     * @param propertyFile     設定値を定義したプロパティファイルのパス名
+     */
+    public SiteData(String propertyFile) {
+        try {
+            Properties properties = new Properties();
+            properties.setPasswordItem("PASSWORD");
+            properties.load(new FileInputStream(propertyFile));
+
+            String str = "";
+            if ((str = properties.getProperty("MAIL_SMTP")) != null) {
+               MAIL_SMTP = str;
+            }
+            if ((str = properties.getProperty("MAIL_SMTP_PORT")) != null) {
+               MAIL_SMTP_PORT = str;
+            }
+            if ((str = properties.getProperty("MAIL_FROM")) != null) {
+               MAIL_FROM = str;
+            }
+            if ((str = properties.getProperty("MAIL_FROM")) != null) {
+               MAIL_FROM = str;
+            }
+            if ((str = properties.getProperty("MAIL_TO")) != null) {
+               MAIL_TO = str;
+            }
+            if ((str = properties.getProperty("MAIL_CC")) != null) {
+               MAIL_CC = str;
+            }
+            if ((str = properties.getProperty("MAIL_BCC")) != null) {
+               MAIL_BCC = str;
+            }
+            
+            str = properties.getProperty("MAIL_POP_before_SMTP");
+            if ((str != null) && str.equals("true")) {
+               POP_before_SMTP = true;
+            }
+            str = properties.getProperty("MAIL_SMTP_AUTH");
+            if ((str != null) && str.equals("true")) {
+               USER_AUTH = true;
+            }
+            if ((str = properties.getProperty("MAIL_POP")) != null) {
+               MAIL_POP = str;
+            }
+            if ((str = properties.getProperty("USER_ID")) != null) {
+               USER_ID = str;
+            }
+            if ((str = properties.getProperty("PASSWORD")) != null) {
+               PASSWORD = str;
+            }
+        }
+        catch(Exception e) {
+            System.out.println(e);
+        }
+    }
+}
diff --git a/src/jp/co/areaweb/tools/mail/SiteDataXml.java b/src/jp/co/areaweb/tools/mail/SiteDataXml.java
new file mode 100644 (file)
index 0000000..fea7ad9
--- /dev/null
@@ -0,0 +1,56 @@
+package jp.co.areaweb.tools.mail;
+
+import javax.xml.parsers.*;         // jaxp.jar
+import org.w3c.dom.*;               // jaxp.jar
+import java.io.FileInputStream;
+
+public class SiteDataXml extends SiteData {
+    public SiteDataXml(String propertyFile) throws javax.xml.parsers.ParserConfigurationException,org.xml.sax.SAXException {
+       super(propertyFile);
+        try {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            Node rootNode = builder.parse(new FileInputStream(propertyFile));
+            NodeList rootNodeList = rootNode.getChildNodes();
+            for (int j=0; j < rootNodeList.getLength(); j++) {
+                Node propertyTag = rootNodeList.item(j);
+                NodeList nl = propertyTag.getChildNodes();
+                for (int i=0; i < nl.getLength(); i++) {
+                    Node mailDataTag = nl.item(i);
+                    if (mailDataTag.getNodeType() == Node.ELEMENT_NODE) {
+                        String nodeName = mailDataTag.getNodeName();
+                        if (nodeName.equals("smtp")) {
+                            this.MAIL_SMTP = paseValue(mailDataTag);
+                        }
+                        else if (nodeName.equals("from")) {
+                            this.MAIL_FROM = paseValue(mailDataTag);
+                        }
+                        else if (nodeName.equals("to")) {
+                            this.MAIL_TO = paseValue(mailDataTag);
+                        }
+                        else if (nodeName.equals("cc")) {
+                            this.MAIL_CC = paseValue(mailDataTag);
+                        }
+                        else if (nodeName.equals("bcc")) {
+                            this.MAIL_BCC = paseValue(mailDataTag);
+                        }
+                    }
+                }
+            }
+        }
+        catch(Exception e) {
+            // Print out the error message
+            System.out.println(e);
+        }
+    }
+    
+    protected static String paseValue(Node tag) {
+        Node node = tag.getFirstChild();
+        if (node != null) {
+            return node.getNodeValue();
+        }
+        else {
+            return "";
+        }
+    }
+}
diff --git a/src/jp/co/areaweb/tools/mail/XmlTool.java b/src/jp/co/areaweb/tools/mail/XmlTool.java
new file mode 100644 (file)
index 0000000..585fa7c
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * XmlTool.java
+ *
+ * Created on 2001/09/03, 14:26
+ */
+
+package jp.co.areaweb.tools.mail;
+import java.util.Calendar;
+import org.w3c.dom.*;
+
+/**
+ * XML 関連の共通クラス
+ * @author kls040
+ * @version 1.0
+ */
+public class XmlTool extends java.lang.Object {
+    /**
+     * <!ELEMENT entry (hiduke,user)>
+     * <!ELEMENT change (hiduke,user)>
+     * <!ELEMENT hiduke (#PCDATA)>
+     * <!ELEMENT user (#PCDATA)><!ATTLIST user id CDATA #IMPLIED>
+     */
+    public static Element setEntryElement(Document document, String elementName, java.util.Date hiduke, int userid) {
+        return setEntryElement(document, elementName, exchengeDate2TimeInstant(hiduke), userid, "user");
+    }
+
+    public static Element setEntryElement(Document document, String elementName, String hidukeStr, int userid, String elementName2) {
+        Element element = document.createElement(elementName);
+        element.appendChild(element);
+        Element hidukeElement = document.createElement("hiduke");
+        element.appendChild(hidukeElement);
+        hidukeElement.appendChild(document.createTextNode(hidukeStr));
+        Element userElement = document.createElement(elementName2);
+        element.appendChild(userElement);
+        Attr attribute = document.createAttribute("id");
+        attribute.setValue(Integer.toString(userid));
+        userElement.getAttributes().setNamedItem(attribute);
+        return element;
+    }
+
+    public static String exchengeDate2TimeInstant(java.sql.Date souce) {
+        return exchengeDate2TimeInstant((java.util.Date)souce);
+    }
+    public static String exchengeDate2TimeInstant(java.util.Date souce) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(souce);
+        String CCYY = Integer.toString(calendar.get(Calendar.YEAR));
+        String MM = twoNumber(calendar.get(Calendar.MONTH) + 1);
+        String DD = twoNumber(calendar.get(Calendar.DAY_OF_MONTH));
+        String hh = twoNumber(calendar.get(Calendar.HOUR));
+        String mm = twoNumber(calendar.get(Calendar.MINUTE));
+        String ss = twoNumber(calendar.get(Calendar.SECOND));
+        return (CCYY +"-"+ MM +"-"+ DD +"T"+ hh +":"+ mm +":"+ ss +".000+09:00");
+    }
+    
+    public static String exchengeDate2XMLDate(java.sql.Date souce) {
+        return exchengeDate2TimeInstant((java.util.Date)souce);
+    }
+    public static String exchengeDate2XMLDate(java.util.Date souce) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(souce);
+        String CCYY = Integer.toString(calendar.get(Calendar.YEAR));
+        String MM = twoNumber(calendar.get(Calendar.MONTH) + 1);
+        String DD = twoNumber(calendar.get(Calendar.DAY_OF_MONTH));
+        return (CCYY +"-"+ MM +"-"+ DD);
+    }
+    
+    public static String twoNumber(int number) {
+        String result = "";
+        int calc = number;
+        for (int i=10; i >= 1; i /= 10) {
+            int syou = calc / i;
+            result += Integer.toString(syou);
+            calc = calc % i;
+        }
+        return result;
+    }
+
+    public static String sevenNumber(int number) {
+        String result = "";
+        int calc = number;
+        for (int i=1000000; i >= 1; i /= 10) {
+            int syou = calc / i;
+            result += Integer.toString(syou);
+            calc = calc % i;
+        }
+        return result;
+    }
+}
diff --git a/src/jp/co/areaweb/tools/mail/YuuMailXml.java b/src/jp/co/areaweb/tools/mail/YuuMailXml.java
new file mode 100644 (file)
index 0000000..a4389ba
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * YuuMail.java
+ *
+ * Created on 2000/08/09, 14:07
+ */
+
+package jp.co.areaweb.tools.mail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import javax.xml.parsers.*;         // jaxp.jar
+import org.w3c.dom.*;               // jaxp.jar
+
+/** Eメールを送信するためのクラス
+ * JavaMailを使用する機能拡張版
+ * @author techno-infinitus Co,Ltd. Yuu Hayashi.
+ * @version 00-00
+ */
+public class YuuMailXml extends SendMail {
+    /** Creates new YuuMail */
+    public YuuMailXml(SiteData siteData) {
+        super(siteData);
+    }
+    public YuuMailXml(String propertyFile) {
+        super(propertyFile);
+    }
+
+    public void setXmlData(Node sendMailTag) throws java.io.FileNotFoundException {
+        NodeList nl = sendMailTag.getChildNodes();
+        for (int i=0; i < nl.getLength(); i++) {
+            Node mailDataTag = nl.item(i);
+            if (mailDataTag.getNodeType() == Node.ELEMENT_NODE) {
+                String nodeName = mailDataTag.getNodeName();
+                if (nodeName.equals("to")) {
+                    this.setTo(mailDataTag.getFirstChild().getNodeValue());
+                }
+                else if (nodeName.equals("cc")) {
+                    Node ccNode = mailDataTag.getFirstChild();
+                    if (ccNode != null) {
+                        this.setCc(ccNode.getNodeValue());
+                    }
+                }
+                else if (nodeName.equals("bcc")) {
+                    Node bccNode = mailDataTag.getFirstChild();
+                    if (bccNode != null) {
+                        this.setBcc(bccNode.getNodeValue());
+                    }
+                }
+                else if (nodeName.equals("from")) {
+                    Node fromNode = mailDataTag.getFirstChild();
+                    if (fromNode != null) {
+                        this.setFrom(fromNode.getNodeValue());
+                    }
+                }
+                else if (nodeName.equals("subject")) {
+                    this.setSubject(mailDataTag.getFirstChild().getNodeValue());
+                }
+                else if (nodeName.equals("content")) {
+                    this.setContent(mailDataTag.getFirstChild().getNodeValue());
+                }
+                else if (nodeName.equals("attachment")) {
+                       Node attachNode = mailDataTag.getFirstChild();
+                       File attachFile = new File(attachNode.getNodeValue());
+                    Attr attrNode = (Attr)mailDataTag.getAttributes().getNamedItem("file");
+                    if (attrNode != null) {
+                        this.setAttachment(attachFile, attrNode.getValue());
+                    }
+                    else {
+                        this.setAttachment(attachFile);
+                    }
+                }
+            }
+        }
+    }
+    
+    public void setXmlData(String inputFile) throws IOException {
+        try {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            Node rootNode = builder.parse(new FileInputStream(inputFile));
+            NodeList rootNodeList = rootNode.getChildNodes();
+            for (int j=0; j < rootNodeList.getLength(); j++) {
+                setXmlData(rootNodeList.item(j));
+            }
+        }
+        catch (javax.xml.parsers.ParserConfigurationException pce) {
+            pce.printStackTrace();
+            throw new IOException("javax.xml.parsers.ParserConfigurationException");
+        }
+        catch (org.xml.sax.SAXException saxe) {
+            saxe.printStackTrace();
+            throw new IOException("org.xml.sax.SAXException");
+        }
+    }
+    
+    /**
+     * "jp.co.areaweb.tools.common.YuuMailXml <property.xml> <sendMail.xml>"
+     */
+    public static void main(java.lang.String[] args) {
+        String inputfile;
+        String propertyFile;
+
+        if (args.length < 2) {
+            inputfile = "sendMail.xml";
+            if (args.length < 1) {
+                propertyFile = "property.xml";
+            }
+            else {
+                propertyFile = args[0];
+            }
+        }
+        else {
+            inputfile = args[1];
+            propertyFile = args[0];
+        }
+
+        try {
+            YuuMailXml mail = new YuuMailXml(new SiteDataXml(propertyFile));
+            mail.setXmlData(inputfile);
+            mail.send();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/jp/co/areaweb/tools/mail/package.html b/src/jp/co/areaweb/tools/mail/package.html
new file mode 100644 (file)
index 0000000..fc9c050
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Eメール送信</title>
+</head>
+<body>
+<code>
+Eメールを送信するためのクラス群<BR/>
+<BR/>
+<b>関連ライブラリ</b><br/>
+1999年から愛用している旧式のライブラリ。
+&nbsp;&nbsp;&nbsp;&nbsp;'<a href="http://java.sun.com/products/javamail/javadocs/index.html">JavaMail API</a>'&nbsp;mail-1.4.jar&nbsp;activation-1.1.jar
+</code>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/jp/co/areaweb/tools/servlet/FileDownloadServlet.java b/src/jp/co/areaweb/tools/servlet/FileDownloadServlet.java
new file mode 100644 (file)
index 0000000..34d1861
--- /dev/null
@@ -0,0 +1,85 @@
+package jp.co.areaweb.tools.servlet;
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+/**
+ * サーバ上のファイル(やデータベース等に保存してあるデータ)をブラウザに送る場合は、適切なコンテントタイプをセットした
+ * 後にファイル内容を送信します。
+ * その際、ブラウザ側でどのように処理して欲しいかによって、「inline」と「attachment」の2つの形式があります。
+ * inlineは送信内容がブラウザによってただちに表示されることを指し(*1)、attachmentはブラウザによってファイルに
+ * 保存されます。
+ */
+@SuppressWarnings("serial")
+public class FileDownloadServlet extends HttpServlet {
+       // 拡張子contentType対応テーブル
+       private final static String contentTypeTable[][] = {
+               {"jpg", "image/pjpeg"},
+               {"gif", "image/gif"},
+               {"txt", "text/plain"},
+               {"csv", "text/plain"},
+               {"xml", "text/plain"},
+               {"xsl", "text/plain"},
+               {"xls", "application/vnd.ms-excel"}
+       };
+       private final static int EXTENTION=0;
+       private final static int CONTENT_TYPE=1;
+
+       /**
+        * パラメータ:
+        *      fileName        クライアント側の文字エンコーディングのままのファイル名
+        */
+       public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               // ファイル読み込み用バッファ
+               byte buffer[]  = new byte[4096];
+               
+               // クライアント側の文字エンコーディングのままのファイル名
+               String fileName1 = request.getParameter("fileName");
+               // Unicodeに変更されたファイル名
+               
+               // 拡張子からcontentTypeを獲得
+               String contentType = getContentType(fileName1);
+               
+               // contentTypeを出力
+               response.setContentType(contentType);
+               
+               File file = new File(fileName1);
+               // ファイル名の送信(attachment部分をinlineに変更すればインライン表示)
+               String fileName2 = new String(file.getName().getBytes("Windows-31J"), "ISO8859_1");
+               //response.setCharacterEncoding("Windows-31J");
+               response.setHeader("Content-disposition", "attachment; filename=\""+ fileName2 +"\"");
+               // ファイル内容の出力
+               ServletOutputStream out = response.getOutputStream();
+               FileInputStream fin = new FileInputStream(file);
+               int size;
+               while((size = fin.read(buffer))!=-1) {
+                       out.write(buffer,0, size);
+               }
+               fin.close();
+               out.close();
+       }
+
+       /**
+        *  ファイル名から拡張子を取り出す
+        */
+       private String getExtention(String fileName) {
+               int idx = fileName.lastIndexOf('.');
+               if (idx!=-1) {
+                       return fileName.substring(idx+1, fileName.length());
+               }
+               return "";
+       }
+
+       /**
+        *  拡張子からcontentTypeを取り出す
+        */
+       private String getContentType(String fileName) {
+               String extention = getExtention(fileName);
+               for (int j=0; j < contentTypeTable.length; j++) {
+                       if (contentTypeTable[j][EXTENTION].equalsIgnoreCase(extention)) {
+                               return contentTypeTable[j][CONTENT_TYPE];
+                       }
+               }
+               return "application/octet-stream";
+       }
+}
diff --git a/test/jp/co/areaweb/tools/core/TestMakeString.java b/test/jp/co/areaweb/tools/core/TestMakeString.java
new file mode 100644 (file)
index 0000000..5f82e0e
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Created on 2005/06/02
+ *
+ */
+package jp.co.areaweb.tools.core;
+
+import junit.framework.TestCase;
+
+/**
+ * @author y_hayashi
+ *
+ * longData数値を、ketaで指定された文字数の文字列に変換する。
+ * 数値が指定の桁に満たない場合は、0が埋め込まれます.
+ * 数値が指定の桁数を超えている場合には、例外を発生させます.
+ * 基数は10です。
+ * @param longData
+ * @param keta
+ * @return
+ */
+public class TestMakeString extends TestCase {
+
+       /**
+        * テスト1
+        * longData数値を、ketaで指定された文字数の文字列に変換する。
+        */
+       public void test001() throws Exception {
+               assertEquals(MakeString.valueOf(0L, 3), "000");
+               assertEquals(MakeString.valueOf(123L, 3), "123");
+               assertEquals(MakeString.valueOf(1230L, 4), "1230");
+               assertEquals(MakeString.valueOf(0, 3), "000");
+               assertEquals(MakeString.valueOf(123, 3), "123");
+               assertEquals(MakeString.valueOf(1230, 4), "1230");
+       }
+       
+       /**
+        * テスト2
+        * 数値が指定の桁に満たない場合は、0が埋め込まれます.
+        */
+       public void test002() throws Exception {
+               assertEquals(MakeString.valueOf(123L, 8), "00000123");
+               assertEquals(MakeString.valueOf(1230L, 8), "00001230");
+               assertEquals(MakeString.valueOf(123, 8), "00000123");
+               assertEquals(MakeString.valueOf(1230, 8), "00001230");
+       }
+
+       /**
+        * テスト3
+        * 数値が指定の桁数を超えている場合には、例外を発生させます.
+        */
+       public void test003() throws Exception {
+               try {
+                       MakeString.valueOf(123L, 2);
+                       fail();         // 例外が発生しなければエラー
+               }
+               catch (Exception e) {
+                       // 成功
+                       assertEquals(true, true);
+               }
+               
+               try {
+                       MakeString.valueOf(-1234L, 4);
+                       fail();         // 例外が発生しなければエラー
+               }
+               catch (Exception e) {
+                       // 成功
+                       assertEquals(true, true);
+               }
+       }
+
+       /**
+        * テスト4
+        * 数値が負の場合
+        */
+       public void test004() throws Exception {
+               assertEquals("-0000123", MakeString.valueOf(-123, 8));
+               assertEquals("-0001230", MakeString.valueOf(-1230L, 8));
+               assertEquals("-1234", MakeString.valueOf(-1234L, 5));
+       }
+}
diff --git a/test/jp/co/areaweb/tools/core/TestTax.java b/test/jp/co/areaweb/tools/core/TestTax.java
new file mode 100644 (file)
index 0000000..882e591
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Created on 2005/06/09
+ *
+ */
+package jp.co.areaweb.tools.core;
+
+import jp.co.areaweb.tools.core.Tax;
+import junit.framework.TestCase;
+
+/**
+ * @author y_hayashi
+ *
+ */
+public class TestTax extends TestCase {
+
+       /**
+        * テスト1
+        * 総額から税引き価格を求める
+        */
+       public void test001() throws Exception {
+               assertEquals(95L, Tax.calcBody(100L));
+               assertEquals(5L, Tax.calcTax(100L));
+               assertEquals(5L, Tax.toTax(95L));
+               assertEquals(100L, Tax.toTotal(95L));
+       }
+       
+       /**
+        * テスト2
+        * 端数は四捨五入されること
+        */
+       public void test002() throws Exception {
+               assertEquals(99L, Tax.calcBody(104L));          // 99.04
+               assertEquals(5L, Tax.calcTax(104L));
+               assertEquals(100L, Tax.calcBody(105L));         // 100.0
+               assertEquals(5L, Tax.calcTax(105L));
+               assertEquals(101L, Tax.calcBody(106L));         // 100.9
+               assertEquals(5L, Tax.calcTax(106L));
+               assertEquals(102L, Tax.calcBody(107L));         // 101.9
+               assertEquals(5L, Tax.calcTax(106L));
+
+               assertEquals(5L, Tax.toTax(99L));
+               assertEquals(104L, Tax.toTotal(99L));
+               assertEquals(5L, Tax.toTax(100L));
+               assertEquals(105L, Tax.toTotal(100L));
+               assertEquals(5L, Tax.toTax(101L));
+               assertEquals(106L, Tax.toTotal(101L));
+               assertEquals(5L, Tax.toTax(102L));
+               assertEquals(107L, Tax.toTotal(102L));
+       }
+
+       /**
+        * テスト3
+        * 10兆円までは計算できる。
+        */
+       public void test003() throws Exception {
+               try {
+                       assertEquals(9523809523810L, Tax.calcBody(10000000000000L));
+                       assertEquals(476190476190L, Tax.calcTax(10000000000000L));
+                       assertEquals(500000000000L, Tax.toTax(10000000000000L));
+                       assertEquals(10500000000000L, Tax.toTotal(10000000000000L));
+               }
+               catch (Exception e) {
+                       fail();         // 例外が発生
+               }
+       }
+
+       /**
+        * テスト4
+        * 数値が負の場合
+        */
+       public void test004() throws Exception {
+               assertEquals(-95L, Tax.calcBody(-100L));
+               assertEquals(-5L, Tax.calcTax(-100L));
+               assertEquals(-5L, Tax.toTax(-95L));
+               assertEquals(-100L, Tax.toTotal(-95L));
+       }
+}