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