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 package org.igesture.app.keyboard;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 import org.jdom.Document;
34 import org.jdom.Element;
35 import org.ximtec.igesture.io.keyboard.Key;
36 import org.ximtec.igesture.util.XMLTool;
37
38
39 public class XMLImport {
40
41 private static final String GESTURE = "gesture";
42 private static final String KEY = "key";
43 private static String ROOT_TAG = "gestureMapping";
44
45
46 @SuppressWarnings("unchecked")
47 public static List<GestureKeyMapping> importKeyMappings(File file) {
48 final List<GestureKeyMapping> mappings = new ArrayList<GestureKeyMapping>();
49 final Document document = XMLTool.importDocument(file);
50 final List<Element> mappingElements = document.getRootElement().getChildren(ROOT_TAG);
51
52 for (final Element mappingElement : mappingElements) {
53 String keyList = mappingElement.getChildText(KEY);
54 String gesture = mappingElement.getChildText(GESTURE);
55 try{
56 mappings.add(new GestureKeyMapping(gesture, Key.parseKeyList(keyList)));
57 }catch(Exception e){
58 e.printStackTrace();
59 }
60 }
61
62 return mappings;
63 }
64
65 }