Last active
August 29, 2015 14:27
-
-
Save nickrussler/53d4ef0e023bfb268428 to your computer and use it in GitHub Desktop.
Class to get XKB keyboard models and layouts with JAXB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.xml.bind.JAXBContext; | |
import javax.xml.bind.Unmarshaller; | |
import javax.xml.bind.annotation.XmlElement; | |
import javax.xml.bind.annotation.XmlElementWrapper; | |
import javax.xml.bind.annotation.XmlRootElement; | |
@XmlRootElement | |
public class XkbConfigRegistry { | |
public static class Model { | |
public static class ModelConfigItem { | |
@XmlElement | |
String name; | |
@XmlElement | |
String description; | |
@XmlElement | |
String vendor; | |
} | |
@XmlElement | |
ModelConfigItem configItem; | |
} | |
public static class Layout { | |
public static class LayoutConfigItem { | |
@XmlElement | |
String name; | |
@XmlElement | |
String description; | |
} | |
@XmlElement | |
LayoutConfigItem configItem; | |
} | |
@XmlElementWrapper(name="modelList") | |
@XmlElement(name="model") | |
List<Model> modelList = new ArrayList<Model>(); | |
@XmlElementWrapper(name="layoutList") | |
@XmlElement(name="layout") | |
List<Layout> layoutList = new ArrayList<Layout>(); | |
private static XkbConfigRegistry instance = null; | |
public static XkbConfigRegistry getXkbConfigRegistry() { | |
if (instance == null) { | |
try { | |
JAXBContext jc = JAXBContext.newInstance(XkbConfigRegistry.class); | |
Unmarshaller unmarshaller = jc.createUnmarshaller(); | |
File xml = new File("/usr/share/X11/xkb/rules/base.xml"); | |
instance = (XkbConfigRegistry) unmarshaller.unmarshal(xml); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment