• R/O
  • SSH

JinArchiver: Commit

JinArchiverは、人狼BBSの過去ログを独自のXML形式でローカルディスクに保存するためのツールです。


Commit MetaInfo

Revision8e3b8c226b3a3e6bc5f6825e995bef30605b8eaa (tree)
Time2016-07-01 02:05:39
Author <olyutorskii@user...>

Log Message

checkstyle警告対応

Change Summary

Incremental Difference

diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/Builder.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/Builder.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/Builder.java Fri Jul 01 02:05:39 2016 +0900
@@ -34,8 +34,8 @@
3434 * 隠れコンストラクタ。
3535 */
3636 private Builder(){
37- super();
38- return;
37+ assert false;
38+ throw new AssertionError();
3939 }
4040
4141
@@ -53,10 +53,11 @@
5353 StreamDecoder decoder;
5454 ContentBuilder builder;
5555
56- if(charset.name().equalsIgnoreCase("Shift_JIS")){
56+ String name = charset.name();
57+ if("Shift_JIS".equalsIgnoreCase(name)){
5758 decoder = new SjisDecoder();
5859 builder = new ContentBuilderSJ(BUF_SZ);
59- }else if(charset.name().equalsIgnoreCase("UTF-8")){
60+ }else if("UTF-8".equalsIgnoreCase(name)){
6061 decoder = new StreamDecoder(charset.newDecoder());
6162 builder = new ContentBuilderUCS2(BUF_SZ);
6263 }else{
@@ -99,14 +100,17 @@
99100 if(url == null){
100101 url = new URL(resource.getOrigUrlText());
101102 }
103+
104+ DecodedContent content;
102105 URLConnection conn = url.openConnection();
103- InputStream istream = conn.getInputStream();
104- if(resource.getDownTimeMs() <= 0){
105- long downTimeMs = conn.getDate();
106- resource.setDownTimeMs(downTimeMs);
106+ try(InputStream istream = conn.getInputStream()){//;
107+ if(resource.getDownTimeMs() <= 0){
108+ long downTimeMs = conn.getDate();
109+ resource.setDownTimeMs(downTimeMs);
110+ }
111+ content = contentFromStream(charset, istream);
107112 }
108- DecodedContent content = contentFromStream(charset, istream);
109- istream.close();
113+
110114 parser.parseAutomatic(content);
111115 }
112116
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/EventData.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/EventData.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/EventData.java Fri Jul 01 02:05:39 2016 +0900
@@ -30,9 +30,8 @@
3030
3131 /**
3232 * コンストラクタ。
33- * @param periodData 所属元Period
3433 */
35- public EventData(PeriodData periodData){
34+ public EventData(){
3635 super();
3736 return;
3837 }
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/Handler.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/Handler.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/Handler.java Fri Jul 01 02:05:39 2016 +0900
@@ -224,12 +224,12 @@
224224
225225 if(periodType == null){
226226 newType = DisclosureType.COMPLETE;
227- }else if(periodType == PeriodType.EPILOGUE
228- && this.currentResource.getPeriodType()
227+ }else if( periodType == PeriodType.EPILOGUE
228+ && this.currentResource.getPeriodType()
229229 != PeriodType.EPILOGUE){
230230 newType = DisclosureType.COMPLETE;
231- }else if( periodType != PeriodType.PROLOGUE
232- && this.currentResource.getPeriodType()
231+ }else if( periodType != PeriodType.PROLOGUE
232+ && this.currentResource.getPeriodType()
233233 == PeriodType.PROLOGUE){
234234 newType = DisclosureType.COMPLETE;
235235 }else{
@@ -373,32 +373,24 @@
373373 }
374374 }
375375
376- if( ! this.currentPeriod.hasMurderResult()
377- && this.currentTalk.getTalkType() == TalkType.WOLFONLY
378- && this.currentTalk.getLineNum() == 1){
376+ TalkType currentTalkType = this.currentTalk.getTalkType();
377+ int talkLineNum = this.currentTalk.getLineNum();
378+
379+ boolean hasNotMurder = ! this.currentPeriod.hasMurderResult();
380+ boolean isWolfTalk = currentTalkType == TalkType.WOLFONLY;
381+ boolean isOneLineTalk = talkLineNum == 1;
382+
383+ boolean maybeAssaultEvent =
384+ hasNotMurder && isWolfTalk && isOneLineTalk;
385+
386+ if(maybeAssaultEvent){
379387 DecodedContent line1st = this.currentTalk.get1stLine();
380388 Matcher matcher = MURDER_PATTERN.matcher(line1st);
381389 if(matcher.matches()){
382- AvatarData byWhom = this.currentTalk.getAvatarData();
383390 String avatarName = matcher.group(1);
384391 AvatarData target =
385392 this.villageData.getAvatarData(avatarName);
386- String xname = this.currentTalk.getXName();
387- int hour = this.currentTalk.getHour();
388- int minute = this.currentTalk.getMinute();
389- String iconUri = this.currentTalk.getFaceIconUri();
390- EventData event = new EventData(this.currentPeriod);
391- event.setEventType(SysEventType.ASSAULT);
392- event.addLine(line1st);
393- event.addAvatarData(byWhom);
394- event.addAvatarData(target);
395- event.addDecodedContent(new DecodedContent(xname));
396- event.addInteger(hour);
397- event.addInteger(minute);
398- event.addDecodedContent(new DecodedContent(iconUri));
399- if(byWhom.getFaceIconUri() == null){
400- byWhom.setFaceIconUri(iconUri);
401- }
393+ EventData event = buildAssaultEvent(target);
402394 this.currentPeriod.addTopicData(event);
403395 this.currentTalk = null;
404396 return;
@@ -411,6 +403,39 @@
411403 }
412404
413405 /**
406+ * 襲撃イベントを生成する。
407+ * @param target 襲撃対象
408+ * @return 襲撃イベント
409+ */
410+ private EventData buildAssaultEvent(AvatarData target){
411+ DecodedContent line1st = this.currentTalk.get1stLine();
412+
413+ String xname = this.currentTalk.getXName();
414+
415+ int hour = this.currentTalk.getHour();
416+ int minute = this.currentTalk.getMinute();
417+
418+ AvatarData byWhom = this.currentTalk.getAvatarData();
419+ String iconUri = this.currentTalk.getFaceIconUri();
420+ if(byWhom.getFaceIconUri() == null){
421+ byWhom.setFaceIconUri(iconUri);
422+ }
423+
424+ EventData event = new EventData();
425+
426+ event.setEventType(SysEventType.ASSAULT);
427+ event.addLine(line1st);
428+ event.addAvatarData(byWhom);
429+ event.addAvatarData(target);
430+ event.addDecodedContent(new DecodedContent(xname));
431+ event.addInteger(hour);
432+ event.addInteger(minute);
433+ event.addDecodedContent(new DecodedContent(iconUri));
434+
435+ return event;
436+ }
437+
438+ /**
414439 * {@inheritDoc}
415440 * @param eventFamily {@inheritDoc}
416441 * @throws HtmlParseException {@inheritDoc}
@@ -418,7 +443,7 @@
418443 @Override
419444 public void startSysEvent(EventFamily eventFamily)
420445 throws HtmlParseException{
421- this.currentEvent = new EventData(this.currentPeriod);
446+ this.currentEvent = new EventData();
422447 return;
423448 }
424449
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/HttpAccess.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/HttpAccess.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/HttpAccess.java Fri Jul 01 02:05:39 2016 +0900
@@ -33,7 +33,8 @@
3333 * 隠しコンストラクタ。
3434 */
3535 private HttpAccess(){
36- throw new Error();
36+ assert false;
37+ throw new AssertionError();
3738 }
3839
3940
@@ -76,9 +77,10 @@
7677 URL url = getPeriodListURL(landDef, vid);
7778
7879 Charset charset = landDef.getEncoding();
79- InputStream istream = url.openStream();
80- DecodedContent content = Builder.contentFromStream(charset, istream);
81- istream.close();
80+ DecodedContent content;
81+ try(InputStream istream = url.openStream()){
82+ content = Builder.contentFromStream(charset, istream);
83+ }
8284
8385 HtmlParser parser = new HtmlParser();
8486 PeriodListHandler handler = new PeriodListHandler(landDef, vid);
@@ -125,10 +127,10 @@
125127 */
126128 public String getURL(PeriodType type, int day){
127129 String base = this.landDef.getCgiURI().toASCIIString();
128- base += "?vid=" + this.vid;
130+ base += "?vid=" + this.vid + "&meslog=";
129131
130- if(this.landDef.getLandId().equals("wolfg")){
131- base += "&meslog=";
132+ String landId = this.landDef.getLandId();
133+ if("wolfg".equals(landId)){
132134 String dnum = "000" + (day - 1);
133135 dnum = dnum.substring(dnum.length() - 3);
134136 switch(type){
@@ -148,7 +150,7 @@
148150 return null;
149151 }
150152 }else{
151- base += "&meslog=" + this.vid + "_";
153+ base += this.vid + "_";
152154 switch(type){
153155 case PROLOGUE:
154156 base += "ready_0";
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/JinArchiver.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/JinArchiver.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/JinArchiver.java Fri Jul 01 02:05:39 2016 +0900
@@ -11,6 +11,7 @@
1111 import java.io.BufferedReader;
1212 import java.io.BufferedWriter;
1313 import java.io.File;
14+import java.io.FileNotFoundException;
1415 import java.io.FileOutputStream;
1516 import java.io.IOException;
1617 import java.io.InputStream;
@@ -26,7 +27,6 @@
2627 import jp.sourceforge.jindolf.corelib.LandDef;
2728 import jp.sourceforge.jindolf.parser.DecodeException;
2829 import jp.sourceforge.jindolf.parser.HtmlParseException;
29-import org.w3c.dom.ls.LSResourceResolver;
3030 import org.xml.sax.SAXException;
3131
3232 /**
@@ -49,6 +49,11 @@
4949 /** バージョン定義リソース。 */
5050 private static final String RES_VERDEF = "resources/version.properties";
5151
52+ private static final String FORM_FILENAME =
53+ "jin_{0}_{1,number,#00000}.xml";
54+
55+ private static final Charset CS_UTF8 = Charset.forName("UTF-8");
56+
5257
5358 static{
5459 SELF_KLASS = JinArchiver.class;
@@ -79,16 +84,11 @@
7984 private static Properties loadVersionDefinition(Class<?> klass){
8085 Properties result = new Properties();
8186
82- InputStream istream = klass.getResourceAsStream(RES_VERDEF);
83-
84- try{
85- try{
86- result.load(istream);
87- }finally{
88- istream.close();
89- }
87+ try(InputStream istream = klass.getResourceAsStream(RES_VERDEF)){
88+ result.load(istream);
9089 }catch(IOException e){
9190 // NOTHING
91+ assert true;
9292 }
9393
9494 return result;
@@ -172,9 +172,6 @@
172172 return;
173173 }
174174
175- LSResourceResolver resolver = new XmlResolver();
176- validator.setResourceResolver(resolver);
177-
178175 Writer writer;
179176 if(outdir != null){
180177 writer = getFileWriter(outdir, landDef, vid);
@@ -289,6 +286,55 @@
289286 }
290287
291288 /**
289+ * 出力ディレクトリの検査。
290+ * @param outFile 出力ディレクトリ
291+ */
292+ private static void probeOutDirectory(File outFile){
293+ String errMsg = null;
294+
295+ if( ! outFile.exists() ){
296+ errMsg = outFile.toString() + " が存在しません。";
297+ }else if( ! outFile.isDirectory() ){
298+ errMsg = outFile.toString() + " はディレクトリではありません。";
299+ }else if( ! outFile.canWrite() ){
300+ errMsg = outFile.toString() + " に書き込めません。";
301+ }
302+
303+ if(errMsg != null){
304+ errprintln(errMsg);
305+ exit(1);
306+ assert false;
307+ }
308+
309+ return;
310+ }
311+
312+ /**
313+ * 出力ファイルを生成する。
314+ * @param file 出力ファイル
315+ */
316+ private static void createFile(File file){
317+ String errMsg = null;
318+
319+ try{
320+ boolean created = file.createNewFile();
321+ if( ! created ){
322+ errMsg = file.getName() + " が既に存在します。";
323+ }
324+ }catch(IOException e){
325+ errMsg = file.getName() + " が作成できません。";
326+ }
327+
328+ if(errMsg != null){
329+ errprintln(errMsg);
330+ exit(1);
331+ assert false;
332+ }
333+
334+ return;
335+ }
336+
337+ /**
292338 * ローカルファイルへの出力先を得る。
293339 * @param outdir 出力ディレクトリ
294340 * @param landDef 国情報
@@ -299,61 +345,37 @@
299345 LandDef landDef,
300346 int vid ){
301347 File outFile = new File(outdir);
302- if( ! outFile.exists() ){
303- errprintln(
304- outdir + " が存在しません。");
305- exit(1);
306- return null;
307- }
308- if( ! outFile.isDirectory() ){
309- errprintln(
310- outdir + " はディレクトリではありません。");
311- exit(1);
312- return null;
313- }
314- if( ! outFile.canWrite() ){
315- errprintln(
316- outdir + " に書き込めません。");
317- exit(1);
318- return null;
319- }
320- String fname = MessageFormat.format(
321- "jin_{0}_{1,number,#00000}.xml", landDef.getLandId(), vid);
348+ probeOutDirectory(outFile);
349+
350+ String fname =
351+ MessageFormat.format(
352+ FORM_FILENAME, landDef.getLandId(), vid
353+ );
322354 File xmlFile = new File(outFile, fname);
323- boolean created;
324- try{
325- created = xmlFile.createNewFile();
326- }catch(IOException e){
327- errprintln(
328- xmlFile.getName() + " が作成できません。");
329- exit(1);
330- return null;
331- }
332- if( ! created ){
333- errprintln(
334- fname + " が既に" + outdir + "に存在します。");
335- exit(1);
336- return null;
337- }
355+
356+ createFile(xmlFile);
357+
338358 /* JRE 1.6 only
339359 xmlFile.setReadable(true);
340360 xmlFile.setWritable(true);
341361 xmlFile.setExecutable(false, false);
342362 */
343- Writer writer;
363+
364+ OutputStream ostream;
344365 try{
345- OutputStream ostream;
346366 ostream = new FileOutputStream(xmlFile);
347- ostream = new BufferedOutputStream(ostream, 4 * 1024);
348- writer = new OutputStreamWriter(ostream, "UTF-8");
349- writer = new BufferedWriter(writer, 4 * 1024);
350- }catch(IOException e){
351- errprintln(
352- xmlFile.getName() + " に書き込めません。");
367+ }catch(FileNotFoundException e){
368+ errprintln(xmlFile.getName() + " に書き込めません。");
353369 exit(1);
354370 return null;
355371 }
356372
373+ ostream = new BufferedOutputStream(ostream, 4 * 1024);
374+
375+ Writer writer;
376+ writer = new OutputStreamWriter(ostream, CS_UTF8);
377+ writer = new BufferedWriter(writer, 4 * 1024);
378+
357379 return writer;
358380 }
359381
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/TalkData.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/TalkData.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/TalkData.java Fri Jul 01 02:05:39 2016 +0900
@@ -74,10 +74,10 @@
7474
7575 /**
7676 * 元発言のname属性値を設定する。
77- * @param xName name属性値
77+ * @param xNameArg name属性値
7878 */
79- public void setXName(String xName){
80- this.xName = xName;
79+ public void setXName(String xNameArg){
80+ this.xName = xNameArg;
8181 return;
8282 }
8383
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/Win31j.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/Win31j.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/Win31j.java Fri Jul 01 02:05:39 2016 +0900
@@ -42,7 +42,8 @@
4242 * 隠しコンストラクタ。
4343 */
4444 private Win31j(){
45- throw new Error();
45+ assert false;
46+ throw new AssertionError();
4647 }
4748
4849
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/XmlOut.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/XmlOut.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/XmlOut.java Fri Jul 01 02:05:39 2016 +0900
@@ -726,7 +726,7 @@
726726 nl();
727727
728728 indent(1);
729- append("http://jindolf.sourceforge.jp/");
729+ append("http://jindolf.osdn.jp/");
730730 nl();
731731
732732 append("-->");
diff -r 1b9ee7c7c2e8 -r 8e3b8c226b3a src/main/java/jp/sourceforge/jindolf/archiver/XmlUtils.java
--- a/src/main/java/jp/sourceforge/jindolf/archiver/XmlUtils.java Thu Jun 30 00:42:19 2016 +0900
+++ b/src/main/java/jp/sourceforge/jindolf/archiver/XmlUtils.java Fri Jul 01 02:05:39 2016 +0900
@@ -14,6 +14,7 @@
1414 import javax.xml.validation.Schema;
1515 import javax.xml.validation.SchemaFactory;
1616 import javax.xml.validation.Validator;
17+import org.w3c.dom.ls.LSResourceResolver;
1718 import org.xml.sax.SAXException;
1819
1920 /**
@@ -61,6 +62,9 @@
6162
6263 Validator validator = schema.newValidator();
6364
65+ LSResourceResolver resolver = new XmlResolver();
66+ validator.setResourceResolver(resolver);
67+
6468 return validator;
6569 }
6670
Show on old repository browser