• R/O
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonbathyscaphephpgamewindowsguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

OmegaT の翻訳状況(Statistics)を Excel で表示します。


コミットメタ情報

リビジョン11 (tree)
日時2014-05-04 14:48:39
作者yu-tang

ログメッセージ

OmegaT 3.1 対応 (#50224)
Excel テンプレートに集計列を追加
テンプレートのバージョンを ini ファイルで管理

変更サマリ

差分

--- src-stubs/org/omegat/util/StringUtil.java (nonexistent)
+++ src-stubs/org/omegat/util/StringUtil.java (revision 11)
@@ -0,0 +1,26 @@
1+/**************************************************************************
2+ This code is only a stub.
3+ **************************************************************************/
4+
5+package org.omegat.util;
6+
7+/**
8+ * Utilities for string processing.
9+ *
10+ * @author Maxym Mykhalchuk
11+ * @author Didier Briel
12+ * @author Tiago Saboga
13+ * @author Zoltan Bartko
14+ * @author Andrzej Sawula
15+ * @author Alex Buloichik (alex73mail@gmail.com)
16+ */
17+public class StringUtil {
18+
19+ /**
20+ * Check if string is empty, i.e. null or length==0
21+ */
22+ public static boolean isEmpty(final String str) {
23+ throw new UnsupportedOperationException("This method is only a stub.");
24+ }
25+
26+}
--- src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/Settings.java (nonexistent)
+++ src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/Settings.java (revision 11)
@@ -0,0 +1,92 @@
1+/**************************************************************************
2+ Stats2Excel - open Statistics with Excel from standard Tools menu.
3+
4+ Copyright (C) 2014 Yu Tang
5+ Home page: http://sourceforge.jp/users/yu-tang/
6+ Support center: http://sourceforge.jp/users/yu-tang/
7+
8+ This file is part of plugin for OmegaT.
9+ http://www.omegat.org/
10+
11+ License: GNU GPL version 3 or (at your option) any later version.
12+
13+ You should have received a copy of the GNU General Public License
14+ along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ **************************************************************************/
16+
17+package jp.sourceforge.users.yutang.omegat.plugin.stats2excel;
18+
19+import java.io.BufferedReader;
20+import java.io.BufferedWriter;
21+import java.io.File;
22+import java.io.FileInputStream;
23+import java.io.FileWriter;
24+import java.io.IOException;
25+import java.io.InputStreamReader;
26+import java.io.Writer;
27+import java.util.Properties;
28+import org.omegat.util.OConsts;
29+
30+/**
31+ *
32+ * @author Yu-Tang
33+ */
34+public class Settings {
35+
36+ private final File file;
37+ private final Properties properties;
38+
39+ // Key
40+ private final String TEMPLATE_VERSION = "TemplateVersion";
41+
42+ public Settings(File file) throws IOException {
43+ this.file = file;
44+ properties = new Properties(getDefaultProperties());
45+
46+ if (file.isFile()) {
47+ BufferedReader reader = null;
48+ try {
49+ FileInputStream in = new FileInputStream(file);
50+ reader = new BufferedReader(new InputStreamReader(in, OConsts.UTF8));
51+ properties.load(reader);
52+ } finally {
53+ try {
54+ if (reader != null) {
55+ reader.close();
56+ }
57+ } catch(IOException ex) { /* ignore */ }
58+ }
59+ }
60+ }
61+
62+ public String getTemplateVersion() {
63+ return properties.getProperty(TEMPLATE_VERSION);
64+ }
65+
66+ public void setTemplateVersion(String versionString) {
67+ properties.setProperty(TEMPLATE_VERSION, versionString);
68+ }
69+
70+ public void save() throws IOException {
71+ Writer writer = null;
72+ try {
73+ writer = new BufferedWriter(new FileWriter(file));
74+ properties.store(writer, null);
75+ } finally {
76+ try {
77+ if (writer != null) {
78+ writer.close();
79+ }
80+ } catch(IOException ex) { /* ignore */ }
81+ }
82+ }
83+
84+ private Properties getDefaultProperties() {
85+ Properties p = new Properties();
86+
87+ // set default property here
88+ p.setProperty(TEMPLATE_VERSION, "V1");
89+
90+ return p;
91+ }
92+}
--- src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/ExcelModel.java (revision 10)
+++ src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/ExcelModel.java (revision 11)
@@ -19,15 +19,19 @@
1919 import java.io.ByteArrayInputStream;
2020 import java.io.ByteArrayOutputStream;
2121 import java.io.File;
22+import java.io.FileNotFoundException;
2223 import java.io.IOException;
2324 import java.io.InputStream;
2425 import java.util.ArrayList;
2526 import java.util.Arrays;
2627 import java.util.List;
28+import javax.swing.JOptionPane;
29+import org.omegat.core.Core;
2730 import org.omegat.util.LFileCopy;
2831 import org.omegat.util.Log;
2932 import org.omegat.util.OConsts;
3033 import org.omegat.util.StaticUtils;
34+import org.omegat.util.StringUtil;
3135
3236 /**
3337 *
@@ -39,11 +43,16 @@
3943 private static final String LEGACY_STANDARD_TEMPLATE_NAME = "StandardTemplate.xlt";
4044 private static final String STANDARD_TEMPLATE_NAME = "StandardTemplate.xltx";
4145 private static final String TXT_NAME = "Stats2Excel.txt";
46+ private static final String SETTINGS_FILE_NAME = "Stats2Excel.ini";
4247 private static final File _wsf;
4348 private static final File _txt;
4449 private static String windowTitle;
4550 private static int installedExcelVersion;
4651
52+ private static enum TemplateVersion {
53+ NA, CUSTOMIZED, V1, V2
54+ }
55+
4756 public static final int INSTALLED_VERSION_NOT_FOUND = -1;
4857
4958 static {
@@ -145,10 +154,45 @@
145154 LEGACY_STANDARD_TEMPLATE_NAME; // Excel 2003 or earlier
146155 File template = new File(parent, templateName);
147156
148- if (! template.exists()) {
157+ // check if we should replace the template file with the latest one.
158+ final Settings settings = new Settings(new File(parent, SETTINGS_FILE_NAME));
159+ TemplateVersion ver = getTemplateVersion(settings, template);
160+ switch (ver) {
161+ case NA:
162+ // File not found, version not available.
163+ break;
164+ case V1:
165+ // Probably older version is found. Ask user for upgrade.
166+ String msg = L10n.getUpdateTemplateDialogMessage();
167+ String title = L10n.getUpdateTemplateDialogTitle();
168+ int ret = Core.getMainWindow().showConfirmDialog(msg, title,
169+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
170+ if (ret == JOptionPane.YES_OPTION) {
171+ template.delete();
172+ } else {
173+ // set template version setting to CUSTOMIZED
174+ settings.setTemplateVersion(TemplateVersion.CUSTOMIZED.name());
175+ settings.save();
176+ }
177+ break;
178+ case V2:
179+ // OK, we have the latest version. Go on.
180+ break;
181+ case CUSTOMIZED:
182+ // Maybe user uses the customized template file. Don't touch it.
183+ break;
184+ default:
185+ // We shouldn't have come here. Something is wrong.
186+ throw new IOException("Unknown Template Version Error: " + ver.toString());
187+ }
188+
189+ if (!template.exists()) {
149190 InputStream in = ExcelModel.class.getResourceAsStream(templateName);
150191 try {
151192 LFileCopy.copy(in, template);
193+
194+ settings.setTemplateVersion(TemplateVersion.V2.name());
195+ settings.save();
152196 } finally {
153197 in.close();
154198 }
@@ -156,6 +200,23 @@
156200 return template;
157201 }
158202
203+ private static TemplateVersion getTemplateVersion(Settings settings, File template) throws IOException {
204+ if (!template.isFile()) {
205+ return TemplateVersion.NA;
206+ }
207+
208+ String ver = settings.getTemplateVersion();
209+ if (StringUtil.isEmpty(ver)) {
210+ return TemplateVersion.V1;
211+ } else {
212+ try {
213+ return TemplateVersion.valueOf(ver);
214+ } catch (IllegalArgumentException ex) {
215+ return TemplateVersion.V1;
216+ }
217+ }
218+ }
219+
159220 private static File getWSF() throws IOException {
160221 if (! _wsf.exists()) {
161222 InputStream in = ExcelModel.class.getResourceAsStream(WSF_NAME);
--- src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/L10n.java (revision 10)
+++ src/jp/sourceforge/users/yutang/omegat/plugin/stats2excel/L10n.java (revision 11)
@@ -42,6 +42,16 @@
4242 return bundle.getString("S2E_EXCEL_WINDOW_TITLE");
4343 }
4444
45+ // Update template dialog
46+
47+ public static String getUpdateTemplateDialogTitle() {
48+ return bundle.getString("S2E_UPDATE_TEMPLATE_DIALOG_TITLE");
49+ }
50+
51+ public static String getUpdateTemplateDialogMessage() {
52+ return bundle.getString("S2E_UPDATE_TEMPLATE_DIALOG_MESSAGE");
53+ }
54+
4555 // Error
4656
4757 public static String getLoadingErrorFormat() {