1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.http;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.xml.sax.Attributes;
29 import org.xml.sax.SAXException;
30
31 import de.bea.domingo.DBase;
32 import de.bea.domingo.DDocument;
33 import de.bea.domingo.DNotesMonitor;
34 import de.bea.domingo.DViewEntry;
35
36 /***
37 *
38 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
39 */
40 public final class ViewEntryHttp extends BaseHttp implements DViewEntry {
41
42 /*** serial version ID for serialization. */
43 private static final long serialVersionUID = -3064457774812021395L;
44
45 private boolean fConflict;
46
47 private String fUniversalId;
48
49 private String fNoteId;
50
51 private boolean fDocument;
52
53 private boolean fCategory;
54
55 private int fChildren;
56
57 private int fDescendents;
58
59 private int fSibblings;
60
61 private List fColumnValues;
62
63 private boolean fTotal;
64
65 private BaseHandler fParser = new ViewEntryParser();
66
67 private String fPosition;
68
69 /***
70 * Private Constructor for this class.
71 *
72 * @param theFactory the controlling factory
73 * @param session the session that produced the database
74 * @param database Notes database object
75 * @param monitor the monitor that handles logging
76 * @param forceOpen whether the database should be forced to be open or not
77 * @see lotus.domino.Database
78 */
79 private ViewEntryHttp(final NotesHttpFactory theFactory, final DBase theParent, final DNotesMonitor monitor) {
80 super(theFactory, theParent, monitor);
81 }
82
83 /***
84 * Factory method for instances of this class.
85 *
86 * @param theFactory the controlling factory
87 * @param theParent the parent object
88 * @param monitor the monitor that handles logging
89 *
90 * @return Returns a DDatabase instance of type DatabaseProxy
91 */
92 static DViewEntry getInstance(final NotesHttpFactory theFactory, final DBase theParent, final DNotesMonitor monitor) {
93 return new ViewEntryHttp(theFactory, theParent, monitor);
94 }
95
96 /***
97 * Returns a SAX parser for the current view entry.
98 *
99 * @return a SAX parser
100 */
101 protected BaseHandler getParser() {
102 return fParser;
103 }
104
105 /***
106 * @see java.lang.Object#toString()
107 * @return a string representation of the object.
108 */
109 public String toString() {
110 return "[" + fUniversalId + ", " + fColumnValues + "]";
111 }
112
113 /***
114 * {@inheritDoc}
115 *
116 * @see de.bea.domingo.DViewEntry#getColumnValues()
117 */
118 public List getColumnValues() {
119 return fColumnValues;
120 }
121
122 /***
123 * {@inheritDoc}
124 *
125 * @see de.bea.domingo.DViewEntry#getDocument()
126 */
127 public DDocument getDocument() {
128 return DocumentHttp.getInstance(getFactory(), getParent().getParent(), fUniversalId, getMonitor());
129 }
130
131 /***
132 * {@inheritDoc}
133 *
134 * @see de.bea.domingo.DViewEntry#isCategory()
135 */
136 public boolean isCategory() {
137 return fCategory;
138 }
139
140 /***
141 * {@inheritDoc}
142 *
143 * @see de.bea.domingo.DViewEntry#isDocument()
144 */
145 public boolean isDocument() {
146 return fDocument;
147 }
148
149 /***
150 * {@inheritDoc}
151 *
152 * @see de.bea.domingo.DViewEntry#isTotal()
153 */
154 public boolean isTotal() {
155 return fTotal;
156 }
157
158 /***
159 * {@inheritDoc}
160 *
161 * @see de.bea.domingo.DViewEntry#getUniversalID()
162 */
163 public String getUniversalID() {
164 return fUniversalId;
165 }
166
167 /***
168 * {@inheritDoc}
169 *
170 * @see de.bea.domingo.DViewEntry#getChildCount()
171 */
172 public int getChildCount() {
173 return fChildren;
174 }
175
176 /***
177 * {@inheritDoc}
178 *
179 * @see de.bea.domingo.DViewEntry#isConflict()
180 */
181 public boolean isConflict() {
182 return fConflict;
183 }
184
185 /***
186 * {@inheritDoc}
187 *
188 * @see de.bea.domingo.DViewEntry#getDescendantCount()
189 */
190 public int getDescendantCount() {
191 return fDescendents;
192 }
193
194 /***
195 * {@inheritDoc}
196 *
197 * @see de.bea.domingo.DViewEntry#getSiblingCount()
198 */
199 public int getSiblingCount() {
200 return fSibblings;
201 }
202
203 /***
204 * {@inheritDoc}
205 *
206 * @see de.bea.domingo.DViewEntry#getSibblingCount()
207 * @deprecated use method {@link #getSiblingCount()} instead
208 */
209 public int getSibblingCount() {
210 return fSibblings;
211 }
212
213 /***
214 * {@inheritDoc}
215 *
216 * @see de.bea.domingo.DViewEntry#getIndentLevel()
217 */
218 public int getIndentLevel() {
219
220 return 0;
221 }
222
223 /***
224 * {@inheritDoc}
225 *
226 * @see de.bea.domingo.DViewEntry#isValid()
227 */
228 public boolean isValid() {
229
230 return false;
231 }
232
233 /***
234 * {@inheritDoc}
235 *
236 * @see de.bea.domingo.DViewEntry#getNoteID()
237 */
238 public String getNoteID() {
239 return fNoteId;
240 }
241
242 /***
243 * {@inheritDoc}
244 *
245 * @see de.bea.domingo.DViewEntry#getPosition(char)
246 */
247 public String getPosition(final char seperator) {
248 return fPosition.replace('.', seperator);
249 }
250
251 /***
252 * SAX parser for view entries.
253 */
254 class ViewEntryParser extends BaseHandler {
255
256 /***
257 * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
258 * java.lang.String, java.lang.String, org.xml.sax.Attributes)
259 */
260 public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts)
261 throws SAXException {
262 if ("viewentry".equals(qName)) {
263 fUniversalId = atts.getValue("unid");
264 fDescendents = parseInt(atts, "descendents");
265 fSibblings = parseInt(atts, "sibblings");
266 fChildren = parseInt(atts, "children");
267 fPosition = atts.getValue("position");
268 fColumnValues = new ArrayList();
269 } else if ("entrydata".equals(qName)) {
270 reset();
271 if ("true".equals(atts.getValue("category"))) {
272 fCategory = true;
273 }
274 } else {
275 super.startElement(namespaceURI, localName, qName, atts);
276 }
277 }
278
279 /***
280 * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String,
281 * java.lang.String)
282 */
283 public void endElement(final String uri, final String localName, final String qName) throws SAXException {
284 if ("viewentry".equals(qName)) {
285 return;
286 } else if ("entrydata".equals(qName)) {
287 fColumnValues.add(getValues());
288 } else {
289 super.endElement(uri, localName, qName);
290 }
291 }
292
293 /***
294 * Parses an attribute value to a number, null-values are converted to
295 * zero.
296 *
297 * @param atts Attributes
298 * @param name name of attribute to parse
299 * @return attribute value, parsed as integer
300 */
301 private int parseInt(final Attributes atts, final String name) {
302 String value = atts.getValue(name);
303 return value == null ? 0 : Integer.parseInt(value);
304 }
305 }
306 }