TogaGemは、3D動画制作ツール、MikuMikuDance(MMD)で用いられる各種データファイルを読み書きするためのJavaライブラリです。
旧TogaParserライブラリの資産は、TogaGemライブラリに吸収されました。
Revision | 32f0dae4867d4df75e5908cc945fcb7f6806e0b0 (tree) |
---|---|
Zeit | 2019-06-15 12:59:09 |
Autor | Olyutorskii <olyutorskii@user...> |
Commiter | Olyutorskii |
remove null assignment.
@@ -397,6 +397,6 @@ | ||
397 | 397 | </module> |
398 | 398 | |
399 | 399 | |
400 | - </module> | |
400 | +</module> | |
401 | 401 | |
402 | 402 | <!-- EOF --> |
@@ -28,13 +28,15 @@ public class TextExporter { | ||
28 | 28 | /** デフォルトの出力バッファサイズ(単位:byte)。 */ |
29 | 29 | public static final int DEFBUFSZ_BYTE = 128; |
30 | 30 | |
31 | + private static final String DUMMYTXT = ""; | |
32 | + | |
31 | 33 | |
32 | 34 | private final CharsetEncoder encoder; |
33 | 35 | private CharBuffer cbuf = CharBuffer.allocate(DEFBUFSZ_CHAR); |
34 | 36 | private byte[] barray = new byte[DEFBUFSZ_BYTE]; |
35 | 37 | private ByteBuffer bbuf = ByteBuffer.wrap(this.barray); |
36 | 38 | |
37 | - private CharSequence textData; | |
39 | + private CharSequence textData = DUMMYTXT; | |
38 | 40 | private int textLength; |
39 | 41 | private int inPos; |
40 | 42 |
@@ -126,7 +128,7 @@ public class TextExporter { | ||
126 | 128 | try{ |
127 | 129 | total = dumpTextImpl(os); |
128 | 130 | }finally{ |
129 | - this.textData = null; | |
131 | + this.textData = DUMMYTXT; | |
130 | 132 | } |
131 | 133 | |
132 | 134 | return total; |
@@ -379,14 +379,10 @@ abstract class AbstractXmlExporter implements XmlExporter{ | ||
379 | 379 | case CH_GT: escTxt = ">"; break; |
380 | 380 | case CH_DQ: escTxt = """; break; |
381 | 381 | case CH_SQ: escTxt = "'"; break; |
382 | - default: escTxt = null; break; | |
382 | + default: return putRawCh(ch); | |
383 | 383 | } |
384 | 384 | |
385 | - if(escTxt != null){ | |
386 | - putRawText(escTxt); | |
387 | - }else{ | |
388 | - putRawCh(ch); | |
389 | - } | |
385 | + putRawText(escTxt); | |
390 | 386 | |
391 | 387 | return this; |
392 | 388 | } |
@@ -77,6 +77,7 @@ public class XmlResourceResolver | ||
77 | 77 | /** |
78 | 78 | * 絶対URIと相対URIを合成したURIを返す。 |
79 | 79 | * 正規化も行われる。 |
80 | + * | |
80 | 81 | * @param base 絶対URIでなければならない。nullでもよい。 |
81 | 82 | * @param relative 絶対URIでもよいがその場合baseは無視される。null可。 |
82 | 83 | * @return 合成結果のURLオブジェクト。必ず絶対URIになる。 |
@@ -102,8 +103,24 @@ public class XmlResourceResolver | ||
102 | 103 | }else{ |
103 | 104 | relativeURI = EMPTY_URI; |
104 | 105 | } |
106 | + | |
107 | + URI result = buildBaseRelativeURI(baseURI, relativeURI); | |
108 | + return result; | |
109 | + } | |
105 | 110 | |
111 | + /** | |
112 | + * 絶対URIと相対URIを合成したURIを返す。 | |
113 | + * 正規化も行われる。 | |
114 | + * | |
115 | + * @param baseURI 絶対URIでなければならない。nullでもよい。 | |
116 | + * @param relativeURI 絶対URIでもよいがその場合baseは無視される。 | |
117 | + * @return 合成結果のURLオブジェクト。必ず絶対URIになる。 | |
118 | + * @throws java.lang.IllegalArgumentException 絶対URIが生成できない。 | |
119 | + */ | |
120 | + private static URI buildBaseRelativeURI(URI baseURI, URI relativeURI) | |
121 | + throws IllegalArgumentException { | |
106 | 122 | URI resultURI; |
123 | + | |
107 | 124 | if(baseURI == null || relativeURI.isAbsolute()){ |
108 | 125 | resultURI = relativeURI; |
109 | 126 | }else{ |
@@ -36,6 +36,78 @@ public class BasicXmlExporterTest { | ||
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | + * Test of putCharRef2Hex method, of class BasicXmlExporter. | |
40 | + * @throws IOException | |
41 | + */ | |
42 | + @Test | |
43 | + public void testPutCharRef2Hex() throws IOException{ | |
44 | + System.out.println("putCharRef2Hex"); | |
45 | + | |
46 | + BasicXmlExporter instance; | |
47 | + StringBuffer buf; | |
48 | + | |
49 | + instance = new BasicXmlExporter(); | |
50 | + | |
51 | + buf = new StringBuffer(); | |
52 | + instance.setAppendable(buf); | |
53 | + instance.putCharRef2Hex('\u0000'); | |
54 | + assertEquals("�", buf.toString()); | |
55 | + | |
56 | + buf = new StringBuffer(); | |
57 | + instance.setAppendable(buf); | |
58 | + instance.putCharRef2Hex('A'); | |
59 | + assertEquals("A", buf.toString()); | |
60 | + | |
61 | + buf = new StringBuffer(); | |
62 | + instance.setAppendable(buf); | |
63 | + instance.putCharRef2Hex('\u00ff'); | |
64 | + assertEquals("ÿ", buf.toString()); | |
65 | + | |
66 | + buf = new StringBuffer(); | |
67 | + instance.setAppendable(buf); | |
68 | + instance.putCharRef2Hex('\u0100'); | |
69 | + assertEquals("Ā", buf.toString()); | |
70 | + | |
71 | + return; | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * Test of putCh method, of class BasicXmlExporter. | |
76 | + * @throws IOException | |
77 | + */ | |
78 | + @Test | |
79 | + public void testPutCh() throws IOException{ | |
80 | + System.out.println("putCh"); | |
81 | + | |
82 | + BasicXmlExporter instance; | |
83 | + StringBuffer buf; | |
84 | + | |
85 | + instance = new BasicXmlExporter(); | |
86 | + | |
87 | + buf = new StringBuffer(); | |
88 | + instance.setAppendable(buf); | |
89 | + instance.putCh('A'); | |
90 | + assertEquals("A", buf.toString()); | |
91 | + | |
92 | + buf = new StringBuffer(); | |
93 | + instance.setAppendable(buf); | |
94 | + instance.putCh('B').putCh('7').putCh('あ'); | |
95 | + assertEquals("B7あ", buf.toString()); | |
96 | + | |
97 | + buf = new StringBuffer(); | |
98 | + instance.setAppendable(buf); | |
99 | + instance.putCh('&').putCh('<').putCh('>').putCh('"').putCh('\''); | |
100 | + assertEquals("&<>"'", buf.toString()); | |
101 | + | |
102 | + buf = new StringBuffer(); | |
103 | + instance.setAppendable(buf); | |
104 | + instance.putCh('\b'); | |
105 | + assertEquals("", buf.toString()); | |
106 | + | |
107 | + return; | |
108 | + } | |
109 | + | |
110 | + /** | |
39 | 111 | * Test of append method, of class BasicXmlExporter. |
40 | 112 | */ |
41 | 113 | @Test |
@@ -0,0 +1,93 @@ | ||
1 | +/* | |
2 | + */ | |
3 | + | |
4 | +package jp.sfjp.mikutoga.xml; | |
5 | + | |
6 | +import java.net.URI; | |
7 | +import org.junit.After; | |
8 | +import org.junit.AfterClass; | |
9 | +import org.junit.Before; | |
10 | +import org.junit.BeforeClass; | |
11 | +import org.junit.Test; | |
12 | +import static org.junit.Assert.*; | |
13 | + | |
14 | +/** | |
15 | + */ | |
16 | +public class XmlResourceResolverTest { | |
17 | + | |
18 | + public XmlResourceResolverTest() { | |
19 | + } | |
20 | + | |
21 | + @BeforeClass | |
22 | + public static void setUpClass() { | |
23 | + } | |
24 | + | |
25 | + @AfterClass | |
26 | + public static void tearDownClass() { | |
27 | + } | |
28 | + | |
29 | + @Before | |
30 | + public void setUp() { | |
31 | + } | |
32 | + | |
33 | + @After | |
34 | + public void tearDown() { | |
35 | + } | |
36 | + | |
37 | + /** | |
38 | + * Test of buildBaseRelativeURI method, of class XmlResourceResolver. | |
39 | + */ | |
40 | + @Test | |
41 | + public void testBuildBaseRelativeURI() throws Exception { | |
42 | + System.out.println("buildBaseRelativeURI"); | |
43 | + | |
44 | + URI result; | |
45 | + | |
46 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com", "/a"); | |
47 | + assertEquals("http://example.com/a", result.toASCIIString()); | |
48 | + | |
49 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/", "a"); | |
50 | + assertEquals("http://example.com/a", result.toASCIIString()); | |
51 | + | |
52 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/", "/a"); | |
53 | + assertEquals("http://example.com/a", result.toASCIIString()); | |
54 | + | |
55 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", "/b"); | |
56 | + assertEquals("http://example.com/b", result.toASCIIString()); | |
57 | + | |
58 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/", "b"); | |
59 | + assertEquals("http://example.com/a/b", result.toASCIIString()); | |
60 | + | |
61 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/", "/b"); | |
62 | + assertEquals("http://example.com/b", result.toASCIIString()); | |
63 | + | |
64 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", "http://example.org/b"); | |
65 | + assertEquals("http://example.org/b", result.toASCIIString()); | |
66 | + | |
67 | + result = XmlResourceResolver.buildBaseRelativeURI(null, "http://example.org/b"); | |
68 | + assertEquals("http://example.org/b", result.toASCIIString()); | |
69 | + | |
70 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", null); | |
71 | + assertEquals("http://example.com/", result.toASCIIString()); | |
72 | + | |
73 | + result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/b/", "../c"); | |
74 | + assertEquals("http://example.com/a/c", result.toASCIIString()); | |
75 | + | |
76 | + try{ | |
77 | + XmlResourceResolver.buildBaseRelativeURI("a/b/", "c/d"); | |
78 | + fail(); | |
79 | + }catch(IllegalArgumentException e){ | |
80 | + assert true; | |
81 | + } | |
82 | + | |
83 | + try{ | |
84 | + XmlResourceResolver.buildBaseRelativeURI(null, "c/d"); | |
85 | + fail(); | |
86 | + }catch(IllegalArgumentException e){ | |
87 | + assert true; | |
88 | + } | |
89 | + | |
90 | + return; | |
91 | + } | |
92 | + | |
93 | +} |