</module>
- </module>
+</module>
<!-- EOF -->
/** デフォルトの出力バッファサイズ(単位: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 CharSequence textData;
+ private CharSequence textData = DUMMYTXT;
private int textLength;
private int inPos;
try{
total = dumpTextImpl(os);
}finally{
- this.textData = null;
+ this.textData = DUMMYTXT;
}
return total;
case CH_GT: escTxt = ">"; break;
case CH_DQ: escTxt = """; break;
case CH_SQ: escTxt = "'"; break;
- default: escTxt = null; break;
+ default: return putRawCh(ch);
}
- if(escTxt != null){
- putRawText(escTxt);
- }else{
- putRawCh(ch);
- }
+ putRawText(escTxt);
return this;
}
/**
* 絶対URIと相対URIを合成したURIを返す。
* 正規化も行われる。
+ *
* @param base 絶対URIでなければならない。nullでもよい。
* @param relative 絶対URIでもよいがその場合baseは無視される。null可。
* @return 合成結果のURLオブジェクト。必ず絶対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;
+
if(baseURI == null || relativeURI.isAbsolute()){
resultURI = relativeURI;
}else{
}
/**
+ * 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("�", buf.toString());
+
+ buf = new StringBuffer();
+ instance.setAppendable(buf);
+ instance.putCharRef2Hex('A');
+ assertEquals("A", buf.toString());
+
+ buf = new StringBuffer();
+ instance.setAppendable(buf);
+ instance.putCharRef2Hex('\u00ff');
+ assertEquals("ÿ", buf.toString());
+
+ buf = new StringBuffer();
+ instance.setAppendable(buf);
+ instance.putCharRef2Hex('\u0100');
+ assertEquals("Ā", 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("&<>"'", buf.toString());
+
+ buf = new StringBuffer();
+ instance.setAppendable(buf);
+ instance.putCh('\b');
+ assertEquals("", buf.toString());
+
+ return;
+ }
+
+ /**
* Test of append method, of class BasicXmlExporter.
*/
@Test
--- /dev/null
+/*
+ */
+
+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;
+ }
+
+}