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
00027
00028
00029 package org.openmobileis.modules.profils.embedded.data;
00030
00031 import com.microstar.xml.HandlerBase;
00032 import org.openmobileis.common.util.collection.Array;
00033
00041 public final class EmbeddedProfilChannelsParser extends HandlerBase {
00042
00043 private EmbeddedProfilChannel currentChannel;
00044 private EmbeddedProfilRubric currentRubric;
00045 private int level = -1;
00046 private Array channels = new Array(5);
00047 private boolean takeSelectionAccount;
00048 String currentTag;
00049 private String currentPropValue = null;
00050 private String currentPropkey = null;
00051
00052 public EmbeddedProfilChannelsParser(boolean takeSelectionAccount) {
00053 this.takeSelectionAccount = takeSelectionAccount;
00054 }
00055
00056 public Array getChannels() {
00057 return channels;
00058 }
00059
00060
00061 public void startElement (String name) throws Exception {
00062 if (name.equals("channel")) {
00063 currentChannel = new EmbeddedProfilChannel();
00064 } else if (name.equals("rubric")) {
00065 currentRubric = new EmbeddedProfilRubric();
00066 }
00067 currentTag = name;
00068 }
00069
00070 public void endElement (String name) throws Exception {
00071 if (name.equals("channel")) {
00072 channels.add(currentChannel);
00073 } else if (name.equals("rubric")) {
00074 currentChannel.addRubic(currentRubric);
00075 currentRubric = null;
00076 } else if ( (name.equals("selected")) && (takeSelectionAccount)) {
00077 currentRubric.setSelection(true);
00078 } else if (name.equals("property")) {
00079 if((currentRubric!= null) && (currentPropkey != null) && (currentPropValue != null)) {
00080 currentRubric.addProperty(currentPropkey, currentPropValue);
00081 }
00082 }
00083 }
00084
00085 public void charData(char ch[],
00086 int start,
00087 int length) throws Exception {
00088 String value = new String(ch, start, length);
00089 if ((ch[start] != '\n') &&(currentTag.equals("name"))) {
00090 if (currentRubric == null)
00091 currentChannel.setName(value);
00092 else
00093 currentRubric.setName(value);
00094 } else if ((ch[start] != '\n') &&(currentTag.equals("description"))) {
00095 currentRubric.setDescription(value);
00096 }
00097 }
00102 public void attribute (String name, String value, boolean isSpecified) {
00103 if (name.equals("key")) {
00104 currentPropkey = value;
00105 } else if (name.equals("value")) {
00106 currentPropValue = value;
00107 }
00108 }
00109
00110 }