Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/xml/SessionXMLDecoder.java @ 74:391d44c94799
*** empty log message ***
author | pin |
---|---|
date | Sun, 25 Nov 2007 02:26:23 +0900 |
parents | 6ead43b2475e |
children | eb78312ea831 |
comparison
equal
deleted
inserted
replaced
73:4d887f38284b | 74:391d44c94799 |
---|---|
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.InputStream; | 4 import java.io.InputStream; |
5 import java.io.OutputStream; | 5 import java.io.OutputStream; |
6 import java.io.StringReader; | 6 import java.io.StringReader; |
7 import java.io.StringWriter; | 7 import java.io.StringWriter; |
8 import java.nio.channels.SocketChannel; | |
9 import java.util.LinkedList; | |
8 | 10 |
9 import javax.xml.parsers.DocumentBuilder; | 11 import javax.xml.parsers.DocumentBuilder; |
10 import javax.xml.parsers.DocumentBuilderFactory; | 12 import javax.xml.parsers.DocumentBuilderFactory; |
11 import javax.xml.parsers.ParserConfigurationException; | 13 import javax.xml.parsers.ParserConfigurationException; |
12 import javax.xml.transform.Transformer; | 14 import javax.xml.transform.Transformer; |
18 import org.w3c.dom.Element; | 20 import org.w3c.dom.Element; |
19 import org.w3c.dom.Node; | 21 import org.w3c.dom.Node; |
20 import org.w3c.dom.NodeList; | 22 import org.w3c.dom.NodeList; |
21 import org.xml.sax.InputSource; | 23 import org.xml.sax.InputSource; |
22 | 24 |
25 import rep.Editor; | |
26 import rep.Session; | |
23 import rep.SessionList; | 27 import rep.SessionList; |
24 | 28 |
25 public class SessionXMLDecoder { | 29 public class SessionXMLDecoder { |
26 | 30 |
27 private String sessionListSize; | 31 private SocketChannel channel; |
28 private String[] sessionInfo; | |
29 | |
30 | 32 |
31 public SessionXMLDecoder(String string) { | 33 public SessionXMLDecoder(String string) { |
32 decode(string); | 34 decode(string); |
33 } | 35 } |
34 | 36 |
35 public SessionXMLDecoder() { | 37 public SessionXMLDecoder() { |
36 // TODO Auto-generated constructor stub | |
37 } | 38 } |
38 | 39 |
39 public SessionList decode(String string) { | 40 public SessionList decode(String string) { |
40 SessionList sessionlist = null; | 41 SessionList sessionlist = null; |
41 System.out.println(""); | 42 System.out.println(""); |
44 DocumentBuilder builder = factory.newDocumentBuilder(); | 45 DocumentBuilder builder = factory.newDocumentBuilder(); |
45 InputSource source = new InputSource(new StringReader(string)); | 46 InputSource source = new InputSource(new StringReader(string)); |
46 source.setEncoding("UTF-8"); | 47 source.setEncoding("UTF-8"); |
47 Document doc = builder.parse(source); | 48 Document doc = builder.parse(source); |
48 Element root = doc.getDocumentElement(); | 49 Element root = doc.getDocumentElement(); |
49 System.out.println(root.getTagName()); | |
50 | 50 |
51 seachNode(root.getChildNodes()); | 51 //System.out.println(root.getTagName()); |
52 | 52 |
53 System.out.println(sessionListSize); | 53 sessionlist = createSessionList(root); |
54 | 54 |
55 | 55 |
56 } catch (Exception e) { | 56 } catch (Exception e) { |
57 e.printStackTrace(); | 57 e.printStackTrace(); |
58 } | 58 } |
59 return sessionlist; | 59 return sessionlist; |
60 } | 60 } |
61 | |
62 SessionList createSessionList(Element root){ | |
63 NodeList nodelistSession = root.getChildNodes(); | |
64 SessionList sessionlist = new SessionList(); | |
65 | |
66 for(int i = 0; i < nodelistSession.getLength(); i++){ | |
67 Node nodeSession = nodelistSession.item(i); | |
68 NodeList nodelistEditor = nodeSession.getChildNodes(); | |
69 Session session = null; | |
70 | |
71 for(int j = 0; j < nodelistEditor.getLength(); j++){ | |
72 Node nodeEditor = nodelistEditor.item(j); | |
73 NodeList nodelistEditorInfo = nodeEditor.getChildNodes(); | |
74 | |
75 Editor editor = new Editor(); | |
76 String host = nodelistEditorInfo.item(0).getTextContent(); | |
77 editor.setHost(host); | |
78 String port = nodelistEditorInfo.item(1).getTextContent(); | |
79 editor.setPort(port); | |
80 if(nodelistEditorInfo.getLength() == 3){ | |
81 String name = nodelistEditorInfo.item(2).getTextContent(); | |
82 editor.setName(name); | |
83 session = new Session(editor); | |
84 } | |
85 //System.out.println(editor.toString()); | |
86 session.addEditor(editor); | |
87 | |
88 } | |
89 sessionlist.addSession(session); | |
61 | 90 |
91 } | |
92 | |
93 return sessionlist; | |
94 } | |
95 | |
96 /* | |
62 private void seachNode(NodeList list) { | 97 private void seachNode(NodeList list) { |
63 String[] host_port_name = new String[3]; | 98 String[] host_port_name = new String[3]; |
64 for(int i = 0; i < list.getLength(); i++){ | 99 for(int i = 0; i < list.getLength(); i++){ |
65 Element element = null; | 100 Element element = null; |
66 if(list.item(i) instanceof Element) { | 101 if(list.item(i) instanceof Element) { |
73 System.out.println(" " + i + ":" + string); | 108 System.out.println(" " + i + ":" + string); |
74 } | 109 } |
75 if(element != null) seachNode(element.getChildNodes()); | 110 if(element != null) seachNode(element.getChildNodes()); |
76 } | 111 } |
77 } | 112 } |
113 */ | |
78 | 114 |
79 } | 115 } |