01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package xmladder;
16:
17: import org.apache.commons.digester.*;
18: import java.util.logging.*;
19: import java.io.*;
20:
21: import org.quickserver.net.server.ClientData;
22: import org.quickserver.util.pool.PoolableObject;
23: import org.apache.commons.pool.BasePoolableObjectFactory;
24: import org.apache.commons.pool.PoolableObjectFactory;
25:
26: import java.net.*;
27: import java.io.*;
28: import java.util.logging.*;
29:
30: public class Data implements ClientData, PoolableObject {
31: private static Logger logger = Logger.getLogger(Data.class
32: .getName());
33:
34: private StringBuffer xmlDump = new StringBuffer();
35:
36: public void addXmlPart(String data) throws Exception {
37: xmlDump.append(data);
38: }
39:
40: public synchronized String getNextXML() {
41: int i1 = xmlDump.indexOf("<");
42: int i2 = xmlDump.indexOf(">", i1);
43: if (i1 != -1 && i2 != -1) {
44: String tag = xmlDump.substring(i1 + 1, i2);
45: int j = -1;
46: String xmlEndTag = null;
47: if (tag.trim().charAt(tag.trim().length() - 1) == '/') {
48: j = i2;
49: xmlEndTag = ">";
50: } else {
51: xmlEndTag = "</" + tag + ">";
52: j = xmlDump.indexOf(xmlEndTag, i2);
53: }
54: if (j != -1) {
55: String data = xmlDump.substring(i1, j
56: + xmlEndTag.length());
57: xmlDump.delete(i1, j + xmlEndTag.length());
58: return data;
59: }
60: }
61: return null;
62: }
63:
64: //-- PoolableObject
65: public void clean() {
66: xmlDump.setLength(0);
67: }
68:
69: public boolean isPoolable() {
70: return true;
71: }
72:
73: public PoolableObjectFactory getPoolableObjectFactory() {
74: return new BasePoolableObjectFactory() {
75: public Object makeObject() {
76: return new Data();
77: }
78:
79: public void passivateObject(Object obj) {
80: Data ed = (Data) obj;
81: ed.clean();
82: }
83:
84: public void destroyObject(Object obj) {
85: if (obj == null)
86: return;
87: passivateObject(obj);
88: obj = null;
89: }
90:
91: public boolean validateObject(Object obj) {
92: if (obj == null)
93: return false;
94: else
95: return true;
96: }
97: };
98: }
99: }
|