38 |
/** |
/** |
39 |
* Implementation of document. |
* Implementation of document. |
40 |
*/ |
*/ |
41 |
public class DocumentImpl implements Document { |
class DocumentImpl implements Document { |
42 |
//---------------------------------------------------------------- |
//---------------------------------------------------------------- |
43 |
// private fields |
// private fields |
44 |
//---------------------------------------------------------------- |
//---------------------------------------------------------------- |
49 |
//---------------------------------------------------------------- |
//---------------------------------------------------------------- |
50 |
// public methods |
// public methods |
51 |
//---------------------------------------------------------------- |
//---------------------------------------------------------------- |
52 |
|
/** |
53 |
|
* Create a document object. |
54 |
|
*/ |
55 |
public DocumentImpl(){ |
public DocumentImpl(){ |
56 |
id = -1; |
id = -1; |
57 |
attrs = new HashMap(31); |
attrs = new HashMap(31); |
58 |
dtexts = new ArrayList(31); |
dtexts = new ArrayList(31); |
59 |
htexts = new ArrayList(31); |
htexts = new ArrayList(31); |
60 |
} |
} |
61 |
|
/** |
62 |
|
* Create a document object made from draft data. |
63 |
|
* @param draft a string of draft data. |
64 |
|
*/ |
65 |
public DocumentImpl(String draft){ |
public DocumentImpl(String draft){ |
66 |
this(); |
this(); |
67 |
String[] lines = Utility.splitLines(draft); |
String[] lines = Utility.split_lines(draft); |
68 |
int lnum = 0; |
int lnum = 0; |
69 |
while(lnum < lines.length){ |
while(lnum < lines.length){ |
70 |
String line = lines[lnum++]; |
String line = lines[lnum++]; |
76 |
add_text(lines[lnum++]); |
add_text(lines[lnum++]); |
77 |
} |
} |
78 |
} |
} |
79 |
|
/* |
80 |
|
* Implementation of Document. |
81 |
|
*/ |
82 |
public void add_attr(String name, String value){ |
public void add_attr(String name, String value){ |
83 |
if(value != null){ |
if(value != null){ |
84 |
attrs.put(name, value); |
attrs.put(name, value); |
86 |
attrs.remove(name); |
attrs.remove(name); |
87 |
} |
} |
88 |
} |
} |
89 |
|
/* |
90 |
|
* Implementation of Document. |
91 |
|
*/ |
92 |
public void add_text(String text){ |
public void add_text(String text){ |
93 |
dtexts.add(text); |
dtexts.add(text); |
94 |
} |
} |
95 |
|
/* |
96 |
|
* Implementation of Document. |
97 |
|
*/ |
98 |
public void add_hidden_text(String text){ |
public void add_hidden_text(String text){ |
99 |
htexts.add(text); |
htexts.add(text); |
100 |
} |
} |
101 |
|
/* |
102 |
|
* Implementation of Document. |
103 |
|
*/ |
104 |
public int id(){ |
public int id(){ |
105 |
return id; |
return id; |
106 |
} |
} |
107 |
|
/* |
108 |
|
* Implementation of Document. |
109 |
|
*/ |
110 |
public List attr_names(){ |
public List attr_names(){ |
111 |
List names = new ArrayList(attrs.size()); |
List names = new ArrayList(attrs.size()); |
112 |
Iterator it = attrs.keySet().iterator(); |
Iterator it = attrs.keySet().iterator(); |
116 |
Collections.sort(names); |
Collections.sort(names); |
117 |
return names; |
return names; |
118 |
} |
} |
119 |
|
/* |
120 |
|
* Implementation of Document. |
121 |
|
*/ |
122 |
public String attr(String name){ |
public String attr(String name){ |
123 |
return (String)attrs.get(name); |
return (String)attrs.get(name); |
124 |
} |
} |
125 |
|
/* |
126 |
|
* Implementation of Document. |
127 |
|
*/ |
128 |
public List texts(){ |
public List texts(){ |
129 |
return htexts; |
return htexts; |
130 |
} |
} |
131 |
|
/* |
132 |
|
* Implementation of Document. |
133 |
|
*/ |
134 |
public String cat_texts(){ |
public String cat_texts(){ |
135 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
136 |
Iterator it = dtexts.iterator(); |
Iterator it = dtexts.iterator(); |
140 |
} |
} |
141 |
return sb.toString(); |
return sb.toString(); |
142 |
} |
} |
143 |
|
/* |
144 |
|
* Implementation of Document. |
145 |
|
*/ |
146 |
public String dump_draft(){ |
public String dump_draft(){ |
147 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
148 |
List names = attr_names(); |
List names = attr_names(); |