Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

EmbeddedProfilChannelsParser.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2005 Creation P.Delrieu
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   /*** Parser methods  ***/
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 }

Generated on Thu Oct 6 10:06:32 2005 for OpenMobileIS by  doxygen 1.4.3