View Javadoc

1   /*
2    * @(#)$Id: XMLImport.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      :   
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Mar 09, 2007     ukurmann    Initial Release
15   * Mar 24, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
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     } // importKeyMappings
64  
65  }