View Javadoc

1   /*
2    * @(#)$Id: XMLGeco.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Michele Croci, mcroci@gmail.com
5    *
6    * Purpose      :   Provides methods with XML import/export 
7    *                  functionality.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Nov 28, 2007     crocimi    Initial Release
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.ximtec.igesture.geco.xml;
28  
29  import java.io.File;
30  import java.util.Collection;
31  import java.util.List;
32  
33  import org.sigtec.jdom.JdomDocument;
34  import org.sigtec.util.FileHandler;
35  import org.ximtec.igesture.core.GestureSet;
36  import org.ximtec.igesture.geco.mapping.GestureToActionMapping;
37  
38  
39  /**
40   * Provides methods with XML import/export functionality.
41   * 
42   * @version 0.9, Dec 2006
43   * @author Michele Croci, mcroci@gmail.com
44   */
45  public class XMLGeco {
46  
47     public static final String ROOT_TAG = "gestureMappings";
48  
49     public static final String CONFIG_ROOT_TAG = "configuration";
50  
51  
52     /**
53      * Exports a gesture set.
54      * 
55      * @param set the gesture set to be exported.
56      * @param file the XML file.
57      */
58     public static void exportProject(Collection<GestureToActionMapping> mappings,
59           GestureSet gestureSet, String gestureSetFileName, File file) {
60        final JdomDocument igestureDocument = new JdomDocument(ROOT_TAG);
61        igestureDocument.attach(new JdomGestureSetName(gestureSetFileName));
62  
63        for (final GestureToActionMapping map : mappings) {
64           igestureDocument.attach(new JdomGestureMapping(map, gestureSet));
65        }
66  
67        FileHandler.writeFile(file.getPath(), igestureDocument.toXml());
68     } // exportProject
69  
70  
71     /**
72      * Imports a configuration.
73      * 
74      * @param file the XML file
75      * @return the configuration.
76      */
77  
78     public static void exportGestureConfiguration(File file,
79           List<String> devices, boolean[] arr, boolean min, String lastProjectPath) {
80        final JdomDocument igestureDocument = new JdomDocument(CONFIG_ROOT_TAG);
81        igestureDocument.attach(new JdomInputDevicesElement(devices, arr));
82        igestureDocument.attach(new JdomMinimizeElement(min));
83        igestureDocument.attach(new JdomLastProjectElement(lastProjectPath));
84        FileHandler.writeFile(file.getPath(), igestureDocument.toXml());
85     } // importConfiguration
86  
87  }