Mercurial > hg > RemoteEditor > REPSessionManager
annotate rep/xml/SessionXMLDecoder.java @ 468:b800b33c6988
check quit2 and ackList
author | one |
---|---|
date | Mon, 11 Oct 2010 19:57:34 +0900 |
parents | 6f356d160e58 |
children |
rev | line source |
---|---|
40 | 1 package rep.xml; |
2 | |
347 | 3 import java.io.IOException; |
56 | 4 import java.io.StringReader; |
5 | |
6 import javax.xml.parsers.DocumentBuilder; | |
7 import javax.xml.parsers.DocumentBuilderFactory; | |
347 | 8 import javax.xml.parsers.ParserConfigurationException; |
56 | 9 |
10 import org.w3c.dom.Document; | |
11 import org.w3c.dom.Element; | |
386 | 12 import org.w3c.dom.NamedNodeMap; |
13 import org.w3c.dom.Node; | |
56 | 14 import org.w3c.dom.NodeList; |
15 import org.xml.sax.InputSource; | |
347 | 16 import org.xml.sax.SAXException; |
56 | 17 |
74 | 18 import rep.Session; |
56 | 19 import rep.SessionList; |
382
4b87f89b3afd
REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
359
diff
changeset
|
20 import rep.handler.Editor; |
56 | 21 |
40 | 22 public class SessionXMLDecoder { |
56 | 23 |
347 | 24 DocumentBuilderFactory factory; |
25 DocumentBuilder builder; | |
26 | |
56 | 27 |
28 public SessionXMLDecoder() { | |
347 | 29 factory = DocumentBuilderFactory.newInstance(); |
30 try { | |
386 | 31 builder = factory.newDocumentBuilder(); |
347 | 32 } catch (ParserConfigurationException e) { |
386 | 33 assert false; |
347 | 34 } |
56 | 35 } |
36 | |
347 | 37 public SessionList decode(String string) throws SAXException, IOException { |
56 | 38 SessionList sessionlist = null; |
322 | 39 //System.out.println(""); |
347 | 40 InputSource source = new InputSource(new StringReader(string)); |
41 //source.setEncoding("UTF-8"); | |
42 Document doc = builder.parse(source); | |
43 Element root = doc.getDocumentElement(); | |
44 | |
45 //sessionlist = createSessionList(root); | |
46 sessionlist = generateSessionList(root); | |
358 | 47 //sessionlist.setMaxHost(getSessionManagerHost(root)); |
347 | 48 |
49 | |
56 | 50 return sessionlist; |
51 } | |
347 | 52 |
358 | 53 // private String getSessionManagerHost(Element root) { |
54 // NodeList nodelist = root.getChildNodes(); | |
55 // String host = null; | |
56 // for(int i = 0; i < nodelist.getLength(); i++){ | |
57 // if(nodelist.item(i).getNodeName().equals("host")){ | |
58 // host = nodelist.item(i).getTextContent(); | |
59 // } | |
60 // } | |
61 // return host; | |
62 // } | |
77 | 63 |
64 private SessionList generateSessionList(Element element){ | |
65 SessionList sessionlist = new SessionList(); | |
66 NodeList nodelistSession = element.getElementsByTagName("Session"); | |
67 for(int i = 0; i < nodelistSession.getLength(); i++){ | |
386 | 68 Node elementSession = nodelistSession.item(i); |
69 int sid = getIntValue(elementSession,"sid"); | |
70 NodeList nodelistEditor = ((Element)elementSession).getElementsByTagName("Editor"); | |
77 | 71 |
72 Session session = null; | |
73 for(int j = 0; j < nodelistEditor.getLength(); j++){ | |
74 String eid = ((Element)nodelistEditor.item(j)).getAttribute("eid"); | |
75 | |
76 Element elementEditor = (Element) nodelistEditor.item(j); | |
77 NodeList nodelistEditorHost = elementEditor.getElementsByTagName("host"); | |
78 Element elementHost = (Element) nodelistEditorHost.item(0); | |
386 | 79 Node hostValue = elementHost.getFirstChild(); |
80 String host = hostValue==null?"":hostValue.getNodeValue(); | |
77 | 81 |
82 if(elementEditor.getChildNodes().getLength() > 2){ | |
83 NodeList nodelistEditorFile = elementEditor.getElementsByTagName("file"); | |
84 Element elementFile = (Element) nodelistEditorFile.item(0); | |
85 String file = elementFile.getFirstChild().getNodeValue(); | |
86 | |
387 | 87 int id = Integer.parseInt(eid); |
88 Editor editor = new Editor(null, id); | |
89 editor.setHost(host);/* editor.setPort(port)*/; editor.setName(file); | |
322 | 90 session = new Session(sid, editor); |
77 | 91 session.addEditor(editor); |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
92 sessionlist.put(sid,session); |
77 | 93 |
94 }else { | |
387 | 95 int id = Integer.parseInt(eid); |
96 Editor editor = new Editor(null, id); | |
97 editor.setHost(host);/* editor.setPort(port)*/; editor.setName(null); | |
77 | 98 if(session != null){ |
99 session.addEditor(editor); | |
100 } | |
101 } | |
102 } | |
103 } | |
104 return sessionlist; | |
105 } | |
386 | 106 |
107 private int getIntValue(Node elementSession, String attrName) { | |
108 NamedNodeMap attr = elementSession.getAttributes(); | |
109 Node sidNode = attr.getNamedItem(attrName); | |
110 int sid = Integer.parseInt(sidNode.getNodeValue()); | |
111 return sid; | |
112 } | |
113 // | |
114 // private String getString(Node elementSession, String attrName) { | |
115 // NamedNodeMap attr = elementSession.getAttributes(); | |
116 // Node sidNode = attr.getNamedItem(attrName); | |
117 // return sidNode.getNodeValue(); | |
118 // } | |
41 | 119 |
40 | 120 } |