1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.parser;
17
18 import java.io.IOException;
19
20 public class Adapter implements Appendable {
21 private final Element adaptable;
22 private char content;
23 private final CharSequence oneCharSequence = new CharSequence() {
24 @Override
25 public CharSequence subSequence(int start, int end) {
26 if (start == 0 && end == 0) {
27 return this;
28 } else {
29 throw new ArrayIndexOutOfBoundsException();
30 }
31 }
32
33 @Override
34 public int length() {
35 return 1;
36 }
37
38 @Override
39 public char charAt(int index) {
40 return content;
41 }
42 };
43
44 @Override
45 public Appendable append(CharSequence csq, int start, int end) throws IOException {
46 adaptable.characters(csq, start, end);
47 return this;
48 }
49
50 @Override
51 public Appendable append(char c) throws IOException {
52 content = c;
53 return append(oneCharSequence, 0, 1);
54 }
55
56 @Override
57 public Appendable append(CharSequence csq) throws IOException {
58 return append(csq, 0, csq.length());
59 }
60
61 public Adapter(Element adaptable) {
62 this.adaptable = adaptable;
63 }
64 }