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