00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.openmobileis.module.profiles.terminal;
00027
00028 import org.xmlpull.v1.XmlPullParserException;
00029
00030 import java.io.IOException;
00031 import java.io.Reader;
00032
00033 import org.kxml2.io.KXmlParser;
00034 import org.openmobileis.common.util.collection.Array;
00035
00044 public class TerminalXmlProfilParser {
00045 private TerminalProfile profil;
00046 private final static String TAG_XML = "xml";
00047
00048 private final static String TAG_PROFILNAME = "PROFILNAME";
00049
00050 private final static String TAG_MODULE = "MODULE";
00051
00052
00053 private String currentProfilName;
00054 private Array moduleList;
00055
00056 private Reader reader;
00057
00058 TerminalXmlProfilParser(Reader reader) {
00059 this.reader = reader;
00060 moduleList = new Array(10);
00061 }
00062
00063 public TerminalProfile parse() throws XmlPullParserException, IOException {
00064 try {
00065 KXmlParser parser = new KXmlParser();
00066 parser.setInput(this.reader);
00067
00068 int eventType = parser.getEventType();
00069 do {
00070 if (eventType == KXmlParser.START_DOCUMENT) {
00071 } else if (eventType == KXmlParser.END_DOCUMENT) {
00072 } else if (eventType == KXmlParser.START_TAG) {
00073 this.processStartElement(parser);
00074 } else if (eventType == KXmlParser.END_TAG) {
00075 this.processEndElement(parser);
00076 } else if (eventType == KXmlParser.TEXT) {
00077 this.processText(parser);
00078 }
00079 eventType = parser.next();
00080 } while (eventType != KXmlParser.END_DOCUMENT);
00081 } finally {
00082 reader.close();
00083 }
00084 return this.profil;
00085 }
00086
00087 private void processStartElement(KXmlParser parser) {
00088 String name = parser.getName();
00089
00090 if (name.equals(TerminalXmlProfilParser.TAG_XML)) {
00091
00092 } else if (name.equals(TerminalXmlProfilParser.TAG_PROFILNAME)) {
00093 this.openProfilTag(parser);
00094 } else if (name.equals(TerminalXmlProfilParser.TAG_MODULE)) {
00095 this.openModuleTag(parser);
00096 }
00097 }
00098
00099 private void openProfilTag(KXmlParser parser) {
00100 moduleList.clear();
00101 int count = parser.getAttributeCount();
00102 for (int i = 0; i < count; i++) {
00103 if (parser.getAttributeName(i).equals("name")) {
00104 currentProfilName = parser.getAttributeValue(i);
00105 }
00106 }
00107 }
00108
00109 private void openModuleTag(KXmlParser parser) {
00110 String modulename = null;
00111 String version = null;
00112 int count = parser.getAttributeCount();
00113 for (int i = 0; i < count; i++) {
00114 if (parser.getAttributeName(i).equals("moduleName")) {
00115 modulename = parser.getAttributeValue(i);
00116 } else if (parser.getAttributeName(i).equals("version")) {
00117 version = parser.getAttributeValue(i);
00118 }
00119 }
00120 TerminalProfilModule module = new TerminalProfilModule();
00121 module.moduleName = modulename;
00122 module.moduleVersion = version;
00123 moduleList.add(module);
00124 }
00125
00126 private void processEndElement(KXmlParser parser) {
00127 String name = parser.getName();
00128
00129 if (name.equals(TerminalXmlProfilParser.TAG_XML)) {
00130
00131 } else if (name.equals(TerminalXmlProfilParser.TAG_PROFILNAME)) {
00132 profil = new TerminalProfile();
00133 TerminalProfilModule[] modules = new TerminalProfilModule[moduleList.size()];
00134 moduleList.toArray(modules);
00135 profil.moduleList = modules;
00136 profil.profileName = currentProfilName;
00137 }
00138 }
00139
00140 private void processText(KXmlParser parser) throws XmlPullParserException {
00141
00142 }
00143
00144 }