OSDN Git Service

remove null assignment.
authorOlyutorskii <olyutorskii@users.osdn.me>
Sat, 15 Jun 2019 03:59:09 +0000 (12:59 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Sat, 15 Jun 2019 03:59:09 +0000 (12:59 +0900)
config/checkstyle/checkstyle.xml
src/main/java/jp/sfjp/mikutoga/bin/export/TextExporter.java
src/main/java/jp/sfjp/mikutoga/xml/AbstractXmlExporter.java
src/main/java/jp/sfjp/mikutoga/xml/XmlResourceResolver.java
src/test/java/jp/sfjp/mikutoga/xml/BasicXmlExporterTest.java
src/test/java/jp/sfjp/mikutoga/xml/XmlResourceResolverTest.java [new file with mode: 0644]

index 6289d5e..ad3deac 100644 (file)
     </module>
 
 
     </module>
 
 
-    </module>
+</module>
 
 <!-- EOF -->
 
 <!-- EOF -->
index cc54c26..3495f9d 100644 (file)
@@ -28,13 +28,15 @@ public class TextExporter {
     /** デフォルトの出力バッファサイズ(単位:byte)。 */
     public static final int DEFBUFSZ_BYTE = 128;
 
     /** デフォルトの出力バッファサイズ(単位:byte)。 */
     public static final int DEFBUFSZ_BYTE = 128;
 
+    private static final String DUMMYTXT = "";
+
 
     private final CharsetEncoder encoder;
     private CharBuffer cbuf = CharBuffer.allocate(DEFBUFSZ_CHAR);
     private byte[] barray = new byte[DEFBUFSZ_BYTE];
     private ByteBuffer bbuf = ByteBuffer.wrap(this.barray);
 
 
     private final CharsetEncoder encoder;
     private CharBuffer cbuf = CharBuffer.allocate(DEFBUFSZ_CHAR);
     private byte[] barray = new byte[DEFBUFSZ_BYTE];
     private ByteBuffer bbuf = ByteBuffer.wrap(this.barray);
 
-    private CharSequence textData;
+    private CharSequence textData = DUMMYTXT;
     private int textLength;
     private int inPos;
 
     private int textLength;
     private int inPos;
 
@@ -126,7 +128,7 @@ public class TextExporter {
         try{
             total = dumpTextImpl(os);
         }finally{
         try{
             total = dumpTextImpl(os);
         }finally{
-            this.textData = null;
+            this.textData = DUMMYTXT;
         }
 
         return total;
         }
 
         return total;
index c6be082..4bbf4ad 100644 (file)
@@ -379,14 +379,10 @@ abstract class AbstractXmlExporter implements XmlExporter{
         case CH_GT: escTxt = "&gt;";   break;
         case CH_DQ: escTxt = "&quot;"; break;
         case CH_SQ: escTxt = "&apos;"; break;
         case CH_GT: escTxt = "&gt;";   break;
         case CH_DQ: escTxt = "&quot;"; break;
         case CH_SQ: escTxt = "&apos;"; break;
-        default:    escTxt = null;     break;
+        default:    return putRawCh(ch);
         }
 
         }
 
-        if(escTxt != null){
-            putRawText(escTxt);
-        }else{
-            putRawCh(ch);
-        }
+        putRawText(escTxt);
 
         return this;
     }
 
         return this;
     }
index 56c7132..196a900 100644 (file)
@@ -77,6 +77,7 @@ public class XmlResourceResolver
     /**
      * 絶対URIと相対URIを合成したURIを返す。
      * 正規化も行われる。
     /**
      * 絶対URIと相対URIを合成したURIを返す。
      * 正規化も行われる。
+     *
      * @param base 絶対URIでなければならない。nullでもよい。
      * @param relative 絶対URIでもよいがその場合baseは無視される。null可。
      * @return 合成結果のURLオブジェクト。必ず絶対URIになる。
      * @param base 絶対URIでなければならない。nullでもよい。
      * @param relative 絶対URIでもよいがその場合baseは無視される。null可。
      * @return 合成結果のURLオブジェクト。必ず絶対URIになる。
@@ -102,8 +103,24 @@ public class XmlResourceResolver
         }else{
             relativeURI = EMPTY_URI;
         }
         }else{
             relativeURI = EMPTY_URI;
         }
+        
+        URI result = buildBaseRelativeURI(baseURI, relativeURI);
+        return result;
+    }
 
 
+    /**
+     * 絶対URIと相対URIを合成したURIを返す。
+     * 正規化も行われる。
+     *
+     * @param baseURI 絶対URIでなければならない。nullでもよい。
+     * @param relativeURI 絶対URIでもよいがその場合baseは無視される。
+     * @return 合成結果のURLオブジェクト。必ず絶対URIになる。
+     * @throws java.lang.IllegalArgumentException 絶対URIが生成できない。
+     */
+    private static URI buildBaseRelativeURI(URI baseURI, URI relativeURI)
+            throws IllegalArgumentException {
         URI resultURI;
         URI resultURI;
+
         if(baseURI == null || relativeURI.isAbsolute()){
             resultURI = relativeURI;
         }else{
         if(baseURI == null || relativeURI.isAbsolute()){
             resultURI = relativeURI;
         }else{
index 61edcc4..30781e2 100644 (file)
@@ -36,6 +36,78 @@ public class BasicXmlExporterTest {
     }
 
     /**
     }
 
     /**
+     * Test of putCharRef2Hex method, of class BasicXmlExporter.
+     * @throws IOException
+     */
+    @Test
+    public void testPutCharRef2Hex() throws IOException{
+        System.out.println("putCharRef2Hex");
+
+        BasicXmlExporter instance;
+        StringBuffer buf;
+
+        instance = new BasicXmlExporter();
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCharRef2Hex('\u0000');
+        assertEquals("&#x00;", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCharRef2Hex('A');
+        assertEquals("&#x41;", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCharRef2Hex('\u00ff');
+        assertEquals("&#xFF;", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCharRef2Hex('\u0100');
+        assertEquals("&#x0100;", buf.toString());
+
+        return;
+    }
+
+    /**
+     * Test of putCh method, of class BasicXmlExporter.
+     * @throws IOException
+     */
+    @Test
+    public void testPutCh() throws IOException{
+        System.out.println("putCh");
+
+        BasicXmlExporter instance;
+        StringBuffer buf;
+
+        instance = new BasicXmlExporter();
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCh('A');
+        assertEquals("A", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCh('B').putCh('7').putCh('あ');
+        assertEquals("B7あ", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCh('&').putCh('<').putCh('>').putCh('"').putCh('\'');
+        assertEquals("&amp;&lt;&gt;&quot;&apos;", buf.toString());
+
+        buf = new StringBuffer();
+        instance.setAppendable(buf);
+        instance.putCh('\b');
+        assertEquals("&#x08;", buf.toString());
+
+        return;
+    }
+
+    /**
      * Test of append method, of class BasicXmlExporter.
      */
     @Test
      * Test of append method, of class BasicXmlExporter.
      */
     @Test
diff --git a/src/test/java/jp/sfjp/mikutoga/xml/XmlResourceResolverTest.java b/src/test/java/jp/sfjp/mikutoga/xml/XmlResourceResolverTest.java
new file mode 100644 (file)
index 0000000..4b54030
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ */
+
+package jp.sfjp.mikutoga.xml;
+
+import java.net.URI;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ */
+public class XmlResourceResolverTest {
+
+    public XmlResourceResolverTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() {
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of buildBaseRelativeURI method, of class XmlResourceResolver.
+     */
+    @Test
+    public void testBuildBaseRelativeURI() throws Exception {
+        System.out.println("buildBaseRelativeURI");
+
+        URI result;
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com", "/a");
+        assertEquals("http://example.com/a", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/", "a");
+        assertEquals("http://example.com/a", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/", "/a");
+        assertEquals("http://example.com/a", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", "/b");
+        assertEquals("http://example.com/b", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/", "b");
+        assertEquals("http://example.com/a/b", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/", "/b");
+        assertEquals("http://example.com/b", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", "http://example.org/b");
+        assertEquals("http://example.org/b", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI(null, "http://example.org/b");
+        assertEquals("http://example.org/b", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a", null);
+        assertEquals("http://example.com/", result.toASCIIString());
+
+        result = XmlResourceResolver.buildBaseRelativeURI("http://example.com/a/b/", "../c");
+        assertEquals("http://example.com/a/c", result.toASCIIString());
+
+        try{
+            XmlResourceResolver.buildBaseRelativeURI("a/b/", "c/d");
+            fail();
+        }catch(IllegalArgumentException e){
+            assert true;
+        }
+
+        try{
+            XmlResourceResolver.buildBaseRelativeURI(null, "c/d");
+            fail();
+        }catch(IllegalArgumentException e){
+            assert true;
+        }
+
+        return;
+    }
+
+}