annotate rep/xml/SessionXMLDecoder.java @ 56:6ead43b2475e

*** empty log message ***
author pin
date Fri, 16 Nov 2007 13:58:25 +0900
parents 86a1553028ad
children 391d44c94799
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
5c0cd6c01ba8 new file SessionXMLEncoder and SessionXMLDecoder
pin
parents:
diff changeset
1 package rep.xml;
5c0cd6c01ba8 new file SessionXMLEncoder and SessionXMLDecoder
pin
parents:
diff changeset
2
56
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
3 import java.io.File;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
4 import java.io.InputStream;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
5 import java.io.OutputStream;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
6 import java.io.StringReader;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
7 import java.io.StringWriter;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
8
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
9 import javax.xml.parsers.DocumentBuilder;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
10 import javax.xml.parsers.DocumentBuilderFactory;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
11 import javax.xml.parsers.ParserConfigurationException;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
12 import javax.xml.transform.Transformer;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
13 import javax.xml.transform.TransformerFactory;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
14 import javax.xml.transform.dom.DOMSource;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
15 import javax.xml.transform.stream.StreamResult;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
16
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
17 import org.w3c.dom.Document;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
18 import org.w3c.dom.Element;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
19 import org.w3c.dom.Node;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
20 import org.w3c.dom.NodeList;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
21 import org.xml.sax.InputSource;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
22
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
23 import rep.SessionList;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
24
40
5c0cd6c01ba8 new file SessionXMLEncoder and SessionXMLDecoder
pin
parents:
diff changeset
25 public class SessionXMLDecoder {
56
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
26
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
27 private String sessionListSize;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
28 private String[] sessionInfo;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
29
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
30
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
31 public SessionXMLDecoder(String string) {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
32 decode(string);
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
33 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
34
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
35 public SessionXMLDecoder() {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
36 // TODO Auto-generated constructor stub
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
37 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
38
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
39 public SessionList decode(String string) {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
40 SessionList sessionlist = null;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
41 System.out.println("");
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
42 try {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
43 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
44 DocumentBuilder builder = factory.newDocumentBuilder();
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
45 InputSource source = new InputSource(new StringReader(string));
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
46 source.setEncoding("UTF-8");
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
47 Document doc = builder.parse(source);
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
48 Element root = doc.getDocumentElement();
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
49 System.out.println(root.getTagName());
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
50
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
51 seachNode(root.getChildNodes());
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
52
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
53 System.out.println(sessionListSize);
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
54
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
55
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
56 } catch (Exception e) {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
57 e.printStackTrace();
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
58 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
59 return sessionlist;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
60 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
61
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
62 private void seachNode(NodeList list) {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
63 String[] host_port_name = new String[3];
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
64 for(int i = 0; i < list.getLength(); i++){
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
65 Element element = null;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
66 if(list.item(i) instanceof Element) {
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
67 element = (Element) list.item(i);
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
68 System.out.println(element.getNodeName());
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
69 }else{
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
70 String string = list.item(i).getNodeValue();
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
71 sessionListSize += string;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
72 host_port_name[i] = string;
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
73 System.out.println(" " + i + ":" + string);
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
74 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
75 if(element != null) seachNode(element.getChildNodes());
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
76 }
6ead43b2475e *** empty log message ***
pin
parents: 41
diff changeset
77 }
41
86a1553028ad *** empty log message ***
pin
parents: 40
diff changeset
78
40
5c0cd6c01ba8 new file SessionXMLEncoder and SessionXMLDecoder
pin
parents:
diff changeset
79 }