コード例 #1
0
  public Conference parseConference(XmlPullParser xpp)
      throws XmlPullParserException, IOException, ParseException {
    String content = null;
    int eventType = xpp.getEventType();
    Conference conference = new Conference();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        launchEvent(xpp.getName(), ParserEventListener.TAG_OPEN);
        content = null;

      } else if (eventType == XmlPullParser.END_TAG) {
        launchEvent(xpp.getName(), ParserEventListener.TAG_CLOSED);
        if (xpp.getName().equals(TITLE)) {
          conference.setTitle(content);
        } else if (xpp.getName().equals(SUBTITLE)) {
          conference.setSubtitle(content);
        } else if (xpp.getName().equals(VENUE)) {
          conference.setVenue(content);
        } else if (xpp.getName().equals(CITY)) {
          conference.setCity(content);
        } else if (xpp.getName().equals(START)) {
          conference.setStart(DateUtil.getDate(content));
        } else if (xpp.getName().equals(END)) {
          conference.setEnd(DateUtil.getDate(content));
        } else if (xpp.getName().equals(DAYS)) {
          conference.setDays(Integer.parseInt(content));
        } else if (xpp.getName().equals(DAY_CHANGE)) {
          conference.setDay_change(content);
        } else if (xpp.getName().equals(TIMESLOT_DURATION)) {
          conference.setTimeslot_duration(content);
        } else if (xpp.getName().equals(CONFERENCE)) {
          return conference;
        }
      } else if (eventType == XmlPullParser.TEXT) {
        content = xpp.getText();
      }
      eventType = xpp.next();
    }
    return null;
  }
コード例 #2
0
  public Schedule parse() throws ParserException {
    try {
      List<Day> days = new ArrayList<Day>();
      Event event = null;
      List<Event> events = null;
      List<Room> rooms = null;
      Conference conference = null;

      Day day = null;
      Room room = null;

      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();

      xpp.setInput(stream, "UTF-8");

      @SuppressWarnings("unused")
      String content = null;

      int eventType = xpp.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          launchEvent(xpp.getName(), ParserEventListener.TAG_OPEN);
          if (xpp.getName().equals(CONFERENCE)) {
            xpp.next();
            conference = parseConference(xpp);
          } else if (xpp.getName().equals(DAY)) {
            Date date = null;
            int idx = 0;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(DATE)) {
                date = DateUtil.getDate(xpp.getAttributeValue(i));
              } else if (xpp.getAttributeName(i).equals(INDEX)) {
                idx = Integer.parseInt(xpp.getAttributeValue(i));
              }
            }
            day = new Day(date, idx);
            rooms = new ArrayList<Room>();

          } else if (xpp.getName().equals(ROOM)) {
            String name = null;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(NAME)) {
                name = xpp.getAttributeValue(i);
              }
            }
            room = new Room(name);
            events = new ArrayList<Event>();
          } else if (xpp.getName().equals(EVENT)) {
            int id = -1;
            for (int i = 0; i < xpp.getAttributeCount(); i++) {
              if (xpp.getAttributeName(i).equals(ID)) {
                id = Integer.parseInt(xpp.getAttributeValue(i));
              }
            }
            xpp.next();
            Event e = parseEvent(xpp, day);
            e.setId(id);
            room.addEvent(e);
          }
          content = null;
        } else if (eventType == XmlPullParser.END_TAG) {
          launchEvent(xpp.getName(), ParserEventListener.TAG_CLOSED);
          if (xpp.getName().equals(DAY)) {
            day.addRooms(rooms);
            days.add(day);
            rooms = null;
          } else if (xpp.getName().equals(ROOM)) {
            room.addEvents(events);
            rooms.add(room);
            events = null;
          } else if (xpp.getName().equals(EVENT)) {
            events.add(event);
            event = null;
          }
        } else if (eventType == XmlPullParser.TEXT) {
          content = xpp.getText();
        }
        eventType = xpp.next();
      }
      return new Schedule(conference, days);
    } catch (Exception e) {
      throw new ParserException(e);
    }
  }
コード例 #3
0
  public Event parseEvent(XmlPullParser xpp, Day day)
      throws XmlPullParserException, IOException, ParseException {
    // Log.v(getClass().getName(),day.getDate().toString());
    String content = null;
    int eventType = xpp.getEventType();
    Event event = new Event();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        launchEvent(xpp.getName(), ParserEventListener.TAG_OPEN);
        if (xpp.getName().equals(EVENT)) {
          int id = 0;
          for (int i = 0; i < xpp.getAttributeCount(); i++) {
            if (xpp.getAttributeName(i).equals(ID)) {
              id = Integer.parseInt(xpp.getAttributeValue(i));
            }
          }
          event.setId(id);
        } else if (xpp.getName().equals(PERSONS)) {
          ArrayList<Person> persons = parsePersons(xpp);
          event.setPersons(persons);
        }
        content = null;
      } else if (eventType == XmlPullParser.END_TAG) {
        launchEvent(xpp.getName(), ParserEventListener.TAG_CLOSED);
        if (xpp.getName().equals(START)) {
          Date d = (Date) day.getDate().clone();
          d.setHours(Integer.parseInt(content.substring(0, 2)));
          d.setMinutes(Integer.parseInt(content.substring(3, 5)));
          d.setSeconds(0);

          event.setStart(d);
          event.setDayindex(day.getIndex());
        } else if (xpp.getName().equals(DURATION)) {
          event.setDuration(DateUtil.convertStringToMinutes(content));
        } else if (xpp.getName().equals(ROOM)) {
          event.setRoom(content);
        } else if (xpp.getName().equals(TAG)) {
          event.setTag(content);
        } else if (xpp.getName().equals(TITLE)) {
          event.setTitle(content.trim());
        } else if (xpp.getName().equals(SUBTITLE)) {
          event.setSubtitle(content);
        } else if (xpp.getName().equals(TRACK)) {
          event.setTrack(content);
        } else if (xpp.getName().equals(TYPE)) {
          event.setType(content);
        } else if (xpp.getName().equals(LANGUAGE)) {
          event.setLanguage(content);
        } else if (xpp.getName().equals(ABSTRACT)) {
          event.setAbstract_description(content);
        } else if (xpp.getName().equals(DESCRIPTION)) {
          event.setDescription(content);
        } else if (xpp.getName().equals(EVENT)) {
          return event;
        }
      } else if (eventType == XmlPullParser.TEXT) {
        content = xpp.getText();
      }
      eventType = xpp.next();
    }
    return null;
  }