LangTable – viz https://www.abclinuxu.cz/clanky/ze-4-s-na-0-9-s-programovaci-jazyk-vala-v-praxi
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/LangTable/src/cz/frantovo/langtable/Keyboards.java Tue Aug 06 17:51:00 2013 +0200
1.3 @@ -0,0 +1,149 @@
1.4 +package cz.frantovo.langtable;
1.5 +
1.6 +import java.util.List;
1.7 +import javax.xml.bind.annotation.XmlElement;
1.8 +import javax.xml.bind.annotation.XmlElementWrapper;
1.9 +import javax.xml.bind.annotation.XmlRootElement;
1.10 +
1.11 +/**
1.12 + *
1.13 + * @author Ing. František Kučera (frantovo.cz)
1.14 + */
1.15 +@XmlRootElement
1.16 +public class Keyboards {
1.17 +
1.18 + private List<Keyboard> keyboards;
1.19 +
1.20 + @XmlElement(name = "keyboard")
1.21 + public List<Keyboard> getKeyboards() {
1.22 + return keyboards;
1.23 + }
1.24 +
1.25 + public void setKeyboards(List<Keyboard> keyboards) {
1.26 + this.keyboards = keyboards;
1.27 + }
1.28 +
1.29 + public static class Keyboard {
1.30 +
1.31 + private String id;
1.32 + private String description;
1.33 + private String comment;
1.34 + private boolean ascii;
1.35 + private List<Language> languages;
1.36 + private List<Territory> territories;
1.37 +
1.38 + @XmlElement(name = "keyboardId")
1.39 + public String getId() {
1.40 + return id;
1.41 + }
1.42 +
1.43 + public void setId(String id) {
1.44 + this.id = id;
1.45 + }
1.46 +
1.47 + @XmlElement
1.48 + public String getDescription() {
1.49 + return description;
1.50 + }
1.51 +
1.52 + public void setDescription(String description) {
1.53 + this.description = description;
1.54 + }
1.55 +
1.56 + @XmlElement
1.57 + public String getComment() {
1.58 + return comment;
1.59 + }
1.60 +
1.61 + public void setComment(String comment) {
1.62 + this.comment = comment;
1.63 + }
1.64 +
1.65 + @XmlElement
1.66 + public boolean isAscii() {
1.67 + return ascii;
1.68 + }
1.69 +
1.70 + public void setAscii(boolean ascii) {
1.71 + this.ascii = ascii;
1.72 + }
1.73 +
1.74 + @XmlElement(name = "language")
1.75 + @XmlElementWrapper(name = "languages")
1.76 + public List<Language> getLanguages() {
1.77 + return languages;
1.78 + }
1.79 +
1.80 + public void setLanguages(List<Language> languages) {
1.81 + this.languages = languages;
1.82 + }
1.83 +
1.84 + @XmlElement(name = "territory")
1.85 + @XmlElementWrapper(name = "territories")
1.86 + public List<Territory> getTerritories() {
1.87 + return territories;
1.88 + }
1.89 +
1.90 + public void setTerritories(List<Territory> territories) {
1.91 + this.territories = territories;
1.92 + }
1.93 + }
1.94 +
1.95 + public static class Language {
1.96 +
1.97 + private String id;
1.98 + private int rank;
1.99 +
1.100 + @XmlElement(name = "languageId")
1.101 + public String getId() {
1.102 + return id;
1.103 + }
1.104 +
1.105 + public void setId(String id) {
1.106 + this.id = id;
1.107 + }
1.108 +
1.109 + @XmlElement
1.110 + public int getRank() {
1.111 + return rank;
1.112 + }
1.113 +
1.114 + public void setRank(int rank) {
1.115 + this.rank = rank;
1.116 + }
1.117 +
1.118 + @Override
1.119 + public String toString() {
1.120 + return getId() + " (" + getRank() + ")";
1.121 + }
1.122 + }
1.123 +
1.124 + public static class Territory {
1.125 +
1.126 + private String id;
1.127 + private int rank;
1.128 +
1.129 + @XmlElement(name = "territoryId")
1.130 + public String getId() {
1.131 + return id;
1.132 + }
1.133 +
1.134 + public void setId(String id) {
1.135 + this.id = id;
1.136 + }
1.137 +
1.138 + @XmlElement
1.139 + public int getRank() {
1.140 + return rank;
1.141 + }
1.142 +
1.143 + public void setRank(int rank) {
1.144 + this.rank = rank;
1.145 + }
1.146 +
1.147 + @Override
1.148 + public String toString() {
1.149 + return getId() + " (" + getRank() + ")";
1.150 + }
1.151 + }
1.152 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/LangTable/src/cz/frantovo/langtable/LangTable.java Tue Aug 06 17:51:00 2013 +0200
2.3 @@ -0,0 +1,51 @@
2.4 +package cz.frantovo.langtable;
2.5 +
2.6 +import cz.frantovo.langtable.Keyboards.*;
2.7 +import java.io.File;
2.8 +import javax.xml.bind.JAXBContext;
2.9 +import javax.xml.bind.JAXBException;
2.10 +import javax.xml.bind.Unmarshaller;
2.11 +
2.12 +/**
2.13 + *
2.14 + * @author Ing. František Kučera (frantovo.cz)
2.15 + */
2.16 +public class LangTable {
2.17 +
2.18 + /**
2.19 + * @param args the command line arguments
2.20 + */
2.21 + public static void main(String[] args) throws JAXBException {
2.22 +
2.23 +
2.24 + JAXBContext c = JAXBContext.newInstance(Keyboards.class);
2.25 + Unmarshaller u = c.createUnmarshaller();
2.26 +
2.27 + long start = System.currentTimeMillis();
2.28 + Object o = u.unmarshal(new File("data/keyboards.xml"));
2.29 + System.out.println("Time: " + (System.currentTimeMillis() - start) + " ms");
2.30 +
2.31 + Keyboards keyboards = (Keyboards) o;
2.32 +
2.33 + for (Keyboard k : keyboards.getKeyboards()) {
2.34 + System.out.println(k.getId());
2.35 + System.out.println(" " + k.getDescription());
2.36 + System.out.println(" " + k.getComment());
2.37 + System.out.println(" " + k.isAscii());
2.38 +
2.39 + System.out.println(" languages: " + k.getLanguages().size());
2.40 + for (Language l : k.getLanguages()) {
2.41 + System.out.println(" " + l);
2.42 + }
2.43 +
2.44 + System.out.println(" territories: " + k.getTerritories().size());
2.45 + for (Territory t : k.getTerritories()) {
2.46 + System.out.println(" " + t);
2.47 + }
2.48 + }
2.49 +
2.50 +
2.51 +
2.52 +
2.53 + }
2.54 +}