Package org.simpleframework.xml

Examples of org.simpleframework.xml.Serializer


    }

    public <T> BeanDesc<T> load(String fileName, Class<? extends T> clazz) throws Exception {
        String xml = getXml(fileName);
        checkState(xml != null, "loader[%s] appName[%s] fileName[%s] get xml null", getClass().getSimpleName(), appName, fileName);
        Serializer serializer = new Persister();
        T bean = serializer.read(clazz, xml, false);
        checkState(bean != null, "xml[%s] to bean null", xml.replaceAll("\\s+", ""));
        cacheXml(fileName, xml);
        String md5 = Md5Util.md5(xml);
        return new BeanDesc<T>(fileName, md5, bean);
    }
View Full Code Here


                    for (FilePublished change : changes) {
                        String fileName = change.getFileName();
                        String xml = change.getXml();
                        String md5 = change.getMd5();
                        Class<?> clazz = classMap.get(fileName);
                        Serializer serializer = new Persister();
                        Object bean = serializer.read(clazz, change.getXml(), false);
                        BeanDesc<?> beanDesc = new BeanDesc<Object>(fileName, md5, bean);
                        cache.replace(clazz, beanDesc); // 更新cache
                        remoteLoader.cacheXml(fileName, xml); // 缓存到本地
                    }
                } catch (Exception e) {
View Full Code Here

      boolean includeFiles) throws Exception {

    if (!backup_dir.exists()) {
      backup_dir.mkdirs();
    }
    Serializer simpleSerializer = new Persister();
   
    /*
     * ##################### Backup Organizations
     */
    writeList(simpleSerializer, backup_dir, "organizations.xml",
        "organisations", organisationManager.getOrganisations(3L));

    /*
     * ##################### Backup Users
     */
    exportUsers(backup_dir, usersDao.getAllUsersDeleted());

    /*
     * ##################### Backup Room
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(RoomType.class, RoomTypeConverter.class);
     
      writeList(serializer, backup_dir, "rooms.xml",
          "rooms", roomManager.getBackupRooms());
    }

    /*
     * ##################### Backup Room Organizations
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(Organisation.class, OrganisationConverter.class);
      registry.bind(Room.class, RoomConverter.class);
     
      writeList(serializer, backup_dir, "rooms_organisation.xml",
          "room_organisations", roomManager.getRoomsOrganisations());
    }

    /*
     * ##################### Backup Appointments
     */
    {
      List<Appointment> list = appointmentDao.getAppointments();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(AppointmentCategory.class, AppointmentCategoryConverter.class);
      registry.bind(User.class, UserConverter.class);
      registry.bind(AppointmentReminderTyps.class, AppointmentReminderTypeConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getAppointmentStarttime().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "appointements.xml", "appointments", list);
    }

    /*
     * ##################### Backup Meeting Members
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Appointment.class, AppointmentConverter.class);
     
      writeList(serializer, backup_dir, "meetingmembers.xml",
          "meetingmembers", meetingMemberDao.getMeetingMembers());
    }

    /*
     * ##################### LDAP Configs
     */
    writeList(simpleSerializer, backup_dir, "ldapconfigs.xml",
        "ldapconfigs", ldapConfigDao.getLdapConfigs());

    /*
     * ##################### Private Messages
     */
    {
      List<PrivateMessage> list = privateMessagesDao.getPrivateMessages();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "privateMessages.xml",
          "privatemessages", list);
    }

    /*
     * ##################### Private Message Folders
     */
    writeList(simpleSerializer, backup_dir, "privateMessageFolder.xml",
        "privatemessagefolders", privateMessageFolderDao.getPrivateMessageFolders());

    /*
     * ##################### User Contacts
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
     
      writeList(serializer, backup_dir, "userContacts.xml",
          "usercontacts", userContactsDao.getUserContacts());
    }

    /*
     * ##################### File-Explorer
     */
    {
      List<FileExplorerItem> list = fileExplorerItemDao.getFileExplorerItems();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "fileExplorerItems.xml",
          "fileExplorerItems", list);
    }

    /*
     * ##################### Recordings
     */
    {
      List<FlvRecording> list = flvRecordingDao.getAllFlvRecordings();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "flvRecordings.xml",
          "flvrecordings", list);
    }

    /*
     * ##################### Polls
     */
    {
      List<RoomPoll> list = pollManager.getPollListBackup();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      registry.bind(PollType.class, PollTypeConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getCreated().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "roompolls.xml", "roompolls", list);
    }

    /*
     * ##################### Config
     */
    {
      List<Configuration> list = configurationDao.getConfigurations(
          0, Integer.MAX_VALUE, "c.configuration_id", true);
      Registry registry = new Registry();
      registry.bind(OmTimeZone.class, OmTimeZoneConverter.class);
      registry.bind(State.class, StateConverter.class);
      registry.bind(User.class, UserConverter.class);
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStarttime().getClass(), DateConverter.class);
      }
     
View Full Code Here

    exportUsers(fos, list);
  }
  public void exportUsers(OutputStream os, List<User> list) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Organisation.class, OrganisationConverter.class);
    registry.bind(OmTimeZone.class, OmTimeZoneConverter.class);
    registry.bind(State.class, StateConverter.class);
    if (list != null && list.size() > 0) {
View Full Code Here

    zipinputstream.close();

    /*
     * ##################### Import Organizations
     */
    Serializer simpleSerializer = new Persister();
    {
      List<Organisation> list = readList(simpleSerializer, f, "organizations.xml", "organisations", Organisation.class);
      for (Organisation o : list) {
        long oldId = o.getOrganisation_id();
        o.setOrganisation_id(null);
        Long newId = organisationManager.addOrganisationObj(o);
        organisationsMap.put(oldId, newId);
      }
    }

    log.info("Organizations import complete, starting user import");
    /*
     * ##################### Import Users
     */
    {
      List<User> list = readUserList(f, "users.xml", "users");
      for (User u : list) {
        OmTimeZone tz = u.getOmTimeZone();
        if (tz == null || tz.getJname() == null) {
          String jNameTimeZone = configurationDao.getConfValue(
              "default.timezone", String.class, "Europe/Berlin");
          OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
          u.setOmTimeZone(omTimeZone);
          u.setForceTimeZoneCheck(true);
        } else {
          u.setForceTimeZoneCheck(false);
        }
       
        u.setStarttime(new Date());
        long userId = u.getUser_id();
        u.setUser_id(null);
        if (u.getSipUser() != null && u.getSipUser().getId() != 0) {
          u.getSipUser().setId(0);
        }
        usersDao.update(u, -1L);
        usersMap.put(userId, u.getUser_id());
      }
    }

    log.info("Users import complete, starting room import");
    /*
     * ##################### Import Rooms
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions
      Serializer serializer = new Persister(strategy, matcher);

      matcher.bind(Long.class, LongTransform.class);
      matcher.bind(Integer.class, IntegerTransform.class);
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
      registry.bind(RoomType.class, new RoomTypeConverter(roomManager));
     
      List<Room> list = readList(serializer, f, "rooms.xml", "rooms", Room.class);
      for (Room r : list) {
        Long roomId = r.getRooms_id();

        // We need to reset ids as openJPA reject to store them otherwise
        r.setRooms_id(null);
        if (r.getModerators() != null) {
          for (Iterator<RoomModerator> i = r.getModerators().iterator(); i.hasNext();) {
            RoomModerator rm = i.next();
            if (rm.getUser().getUser_id() == null) {
              i.remove();
            }
          }
        }
        r = roomDao.update(r, null);
        roomsMap.put(roomId, r.getRooms_id());
      }
    }

    log.info("Room import complete, starting room organizations import");
    /*
     * ##################### Import Room Organisations
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(Organisation.class, new OrganisationConverter(orgDao, organisationsMap));
      registry.bind(Room.class, new RoomConverter(roomDao, roomsMap));
     
      List<RoomOrganisation> list = readList(serializer, f, "rooms_organisation.xml", "room_organisations", RoomOrganisation.class);
      for (RoomOrganisation ro : list) {
        if (!ro.getDeleted()) {
          // We need to reset this as openJPA reject to store them otherwise
          ro.setRooms_organisation_id(null);
          roomManager.addRoomOrganisation(ro);
        }
      }
    }

    log.info("Room organizations import complete, starting appointement import");
    /*
     * ##################### Import Appointements
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(AppointmentCategory.class, new AppointmentCategoryConverter(appointmentCategoryDaoImpl));
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
      registry.bind(AppointmentReminderTyps.class, new AppointmentReminderTypeConverter(appointmentReminderTypDaoImpl));
      registry.bind(Room.class, new RoomConverter(roomDao, roomsMap));
      registry.bind(Date.class, DateConverter.class);
     
      List<Appointment> list = readList(serializer, f, "appointements.xml", "appointments", Appointment.class);
      for (Appointment a : list) {
        Long appId = a.getAppointmentId();

        // We need to reset this as openJPA reject to store them otherwise
        a.setAppointmentId(null);
        if (a.getUserId() != null && a.getUserId().getUser_id() == null) {
          a.setUserId(null);
        }
        Long newAppId = appointmentDao.addAppointmentObj(a);
        appointmentsMap.put(appId, newAppId);
      }
    }

    log.info("Appointement import complete, starting meeting members import");
    /*
     * ##################### Import MeetingMembers
     *
     * Reminder Invitations will be NOT send!
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
      registry.bind(Appointment.class, new AppointmentConverter(appointmentDao, appointmentsMap));
     
      List<MeetingMember> list = readList(serializer, f, "meetingmembers.xml", "meetingmembers", MeetingMember.class);
      for (MeetingMember ma : list) {
        if (ma.getUserid() != null && ma.getUserid().getUser_id() == null) {
          ma.setUserid(null);
        }
        if (!ma.getDeleted()) {
          // We need to reset this as openJPA reject to store them otherwise
          ma.setMeetingMemberId(null);
          meetingMemberDao.addMeetingMemberByObject(ma);
        }
      }
    }

    log.info("Meeting members import complete, starting ldap config import");
    /*
     * ##################### Import LDAP Configs
     */
    {
      List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true);
      for (LdapConfig c : list) {
        ldapConfigDao.addLdapConfigByObject(c);
      }
    }

    log.info("Ldap config import complete, starting recordings import");
    /*
     * ##################### Import Recordings
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions
      Serializer serializer = new Persister(strategy, matcher);

      matcher.bind(Long.class, LongTransform.class);
      matcher.bind(Integer.class, IntegerTransform.class);
      registry.bind(Date.class, DateConverter.class);
     
      List<FlvRecording> list = readList(serializer, f, "flvRecordings.xml", "flvrecordings", FlvRecording.class, true);
      for (FlvRecording fr : list) {
        fr.setFlvRecordingId(0);
        if (fr.getRoom_id() != null) {
          fr.setRoom_id(roomsMap.get(fr.getRoom_id()));
        }
        if (fr.getOwnerId() != null) {
          fr.setOwnerId(usersMap.get(fr.getOwnerId()));
        }
        if (fr.getFlvRecordingMetaData() != null) {
          for (FlvRecordingMetaData meta : fr.getFlvRecordingMetaData()) {
            meta.setFlvRecordingMetaDataId(0);
            meta.setFlvRecording(fr);
          }
        }
        flvRecordingDao.addFlvRecordingObj(fr);
      }
    }

    log.info("FLVrecording import complete, starting private message folder import");
    /*
     * ##################### Import Private Message Folders
     */
    {
      List<PrivateMessageFolder> list = readList(simpleSerializer, f, "privateMessageFolder.xml"
        , "privatemessagefolders", PrivateMessageFolder.class, true);
      for (PrivateMessageFolder p : list) {
        Long folderId = p.getPrivateMessageFolderId();
        PrivateMessageFolder storedFolder = privateMessageFolderDao
            .getPrivateMessageFolderById(folderId);
        if (storedFolder == null) {
          p.setPrivateMessageFolderId(0);
          Long newFolderId = privateMessageFolderDao
              .addPrivateMessageFolderObj(p);
          messageFoldersMap.put(folderId, newFolderId);
        }
      }
    }

    log.info("Private message folder import complete, starting user contacts import");
    /*
     * ##################### Import User Contacts
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
     
      List<UserContact> list = readList(serializer, f, "userContacts.xml", "usercontacts", UserContact.class, true);
      for (UserContact uc : list) {
        Long ucId = uc.getUserContactId();
        UserContact storedUC = userContactsDao.getUserContacts(ucId);

        if (storedUC == null && uc.getContact() != null && uc.getContact().getUser_id() != null) {
          uc.setUserContactId(0);
          Long newId = userContactsDao.addUserContactObj(uc);
          userContactsMap.put(ucId, newId);
        }
      }
    }

    log.info("Usercontact import complete, starting private messages item import");
    /*
     * ##################### Import Private Messages
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
      registry.bind(Room.class, new RoomConverter(roomDao, roomsMap));
      registry.bind(Date.class, DateConverter.class);
     
      List<PrivateMessage> list = readList(serializer, f, "privateMessages.xml", "privatemessages", PrivateMessage.class, true);
      for (PrivateMessage p : list) {
        p.setPrivateMessageId(0);
        p.setPrivateMessageFolderId(
          getNewId(p.getPrivateMessageFolderId(), Maps.MESSAGEFOLDERS));
        p.setUserContactId(
          getNewId(p.getUserContactId(), Maps.USERCONTACTS));
        if (p.getRoom() != null && p.getRoom().getRooms_id() == null) {
          p.setRoom(null);
        }
        if (p.getTo() != null && p.getTo().getUser_id() == null) {
          p.setTo(null);
        }
        if (p.getFrom() != null && p.getFrom().getUser_id() == null) {
          p.setFrom(null);
        }
        if (p.getOwner() != null && p.getOwner().getUser_id() == null) {
          p.setOwner(null);
        }
        privateMessagesDao.addPrivateMessageObj(p);
      }
    }

    log.info("Private message import complete, starting file explorer item import");
    /*
     * ##################### Import File-Explorer Items
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions
      Serializer serializer = new Persister(strategy, matcher);

      matcher.bind(Long.class, LongTransform.class);
      matcher.bind(Integer.class, IntegerTransform.class);
      registry.bind(Date.class, DateConverter.class);
     
      List<FileExplorerItem> list = readList(serializer, f, "fileExplorerItems.xml", "fileExplorerItems", FileExplorerItem.class, true);
      for (FileExplorerItem file : list) {
        // We need to reset this as openJPA reject to store them otherwise
        file.setFileExplorerItemId(0);
        Long roomId = file.getRoom_id();
        file.setRoom_id(roomsMap.containsKey(roomId) ? roomsMap.get(roomId) : null);
        fileExplorerItemDao.addFileExplorerItem(file);
      }
    }

    log.info("File explorer item import complete, starting file poll import");
    /*
     * ##################### Import Room Polls
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions
      Serializer serializer = new Persister(strategy, matcher);
 
      matcher.bind(Integer.class, IntegerTransform.class);
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
      registry.bind(Room.class, new RoomConverter(roomDao, roomsMap));
      registry.bind(PollType.class, new PollTypeConverter(pollManager));
      registry.bind(Date.class, DateConverter.class);
     
      List<RoomPoll> list = readList(serializer, f, "roompolls.xml", "roompolls", RoomPoll.class, true);
      for (RoomPoll rp : list) {
        if (rp.getRoom().getRooms_id() == null) {
          //room was deleted
          continue;
        }
        if (rp.getCreatedBy().getUser_id() == null) {
          rp.setCreatedBy(null);
        }
        for (RoomPollAnswers rpa : rp.getRoomPollAnswerList()) {
          if (rpa.getVotedUser().getUser_id() == null) {
            rpa.setVotedUser(null);
          }
        }
        pollManager.savePollBackup(rp);
      }
    }
   
    log.info("Poll import complete, starting configs import");
    /*
     * ##################### Import Configs
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions
      Serializer serializer = new Persister(strategy, matcher);

      matcher.bind(Long.class, LongTransform.class);
      registry.bind(Date.class, DateConverter.class);
      registry.bind(User.class, new UserConverter(usersDao, usersMap));
     
View Full Code Here

 
  //FIXME (need to be removed in later versions) HACK to fix 2 deleted nodes in users.xml and inline Adresses and sipData
  private List<User> readUserList(InputSource xml, String listNodeName) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);

    registry.bind(Organisation.class, new OrganisationConverter(orgDao, organisationsMap));
    registry.bind(OmTimeZone.class, new OmTimeZoneConverter(omTimeZoneDaoImpl));
    registry.bind(State.class, new StateConverter(statemanagement));
    registry.bind(Date.class, DateConverter.class);

    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = dBuilder.parse(xml);
    NodeList nl = getNode(getNode(doc, "root"), listNodeName).getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
      Node user = nl.item(i);
      NodeList nl1 = user.getChildNodes();
      boolean deletedFound = false;
      for (int j = 0; j < nl1.getLength(); ++j) {
        Node node = nl1.item(j);
        if (node.getNodeType() == Node.ELEMENT_NODE && "deleted".equals(node.getNodeName())) {
          if (deletedFound) {
            user.removeChild(node);
            break;
          }
          deletedFound = true;
        }
      }
    }
   
    StringWriter sw = new StringWriter();
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.transform(new DOMSource(doc), new StreamResult(sw));
       
    List<User> list = new ArrayList<User>();
    InputNode root = NodeBuilder.read(new StringReader(sw.toString()));
    InputNode root1 = NodeBuilder.read(new StringReader(sw.toString())); //HACK to handle Address inside user
    InputNode listNode = root.getNext();
    InputNode listNode1 = root1.getNext(); //HACK to handle Address inside user
    if (listNodeName.equals(listNode.getName())) {
      InputNode item = listNode.getNext();
      InputNode item1 = listNode1.getNext(); //HACK to handle Address inside user
      while (item != null) {
        User u = ser.read(User.class, item, false);
       
        //HACK to handle Address inside user
        if (u.getAdresses() == null) {
          Address a = ser.read(Address.class, item1, false);
          u.setAdresses(a);
        }
        list.add(u);
        item = listNode.getNext();
        do {
View Full Code Here

    this.externalUserType = externalUserType;
  }

  public String toXml() throws Exception {
    StringWriter sw = new StringWriter();
    Serializer serializer = new Persister();
    serializer.write(this, sw);
    return sw.toString();
  }
View Full Code Here

    serializer.write(this, sw);
    return sw.toString();
  }

  public static RemoteSessionObject fromXml(String xml) {
    Serializer serializer = new Persister();
    try {
      return serializer.read(RemoteSessionObject.class, new StringReader(xml));
    } catch (Exception e) {
      log.error("Unexpected error while restoring object from XML: " + xml, e);
    }
    return null;
  }
View Full Code Here

      boolean includeFiles) throws Exception {

    if (!backup_dir.exists()) {
      backup_dir.mkdirs();
    }
    Serializer simpleSerializer = new Persister();
   
    /*
     * ##################### Backup Organizations
     */
    writeList(simpleSerializer, backup_dir, "organizations.xml",
        "organisations", organisationDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Backup Users
     */
    exportUsers(backup_dir, usersDao.getAllUsersDeleted());

    /*
     * ##################### Backup Room
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(RoomType.class, RoomTypeConverter.class);
     
      writeList(serializer, backup_dir, "rooms.xml", "rooms", roomDao.get());
    }

    /*
     * ##################### Backup Room Organizations
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(Organisation.class, OrganisationConverter.class);
      registry.bind(Room.class, RoomConverter.class);
     
      writeList(serializer, backup_dir, "rooms_organisation.xml",
          "room_organisations", roomOrganisationDao.get());
    }

    /*
     * ##################### Backup Appointments
     */
    {
      List<Appointment> list = appointmentDao.getAppointments();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(AppointmentCategory.class, AppointmentCategoryConverter.class);
      registry.bind(User.class, UserConverter.class);
      registry.bind(AppointmentReminderTyps.class, AppointmentReminderTypeConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStart().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "appointements.xml", "appointments", list);
    }

    /*
     * ##################### Backup Meeting Members
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Appointment.class, AppointmentConverter.class);
     
      writeList(serializer, backup_dir, "meetingmembers.xml",
          "meetingmembers", meetingMemberDao.getMeetingMembers());
    }

    /*
     * ##################### LDAP Configs
     */
    writeList(simpleSerializer, backup_dir, "ldapconfigs.xml",
        "ldapconfigs", ldapConfigDao.getLdapConfigs());

    /*
     * ##################### Cluster servers
     */
    writeList(simpleSerializer, backup_dir, "servers.xml", "servers", serverDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### OAuth2 servers
     */
    writeList(simpleSerializer, backup_dir, "oauth2servers.xml", "oauth2servers", auth2Dao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Private Messages
     */
    {
      List<PrivateMessage> list = privateMessagesDao.get(0, Integer.MAX_VALUE);
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "privateMessages.xml",
          "privatemessages", list);
    }

    /*
     * ##################### Private Message Folders
     */
    writeList(simpleSerializer, backup_dir, "privateMessageFolder.xml",
        "privatemessagefolders", privateMessageFolderDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### User Contacts
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
     
      writeList(serializer, backup_dir, "userContacts.xml",
          "usercontacts", userContactsDao.getUserContacts());
    }

    /*
     * ##################### File-Explorer
     */
    {
      List<FileExplorerItem> list = fileExplorerItemDao.getFileExplorerItems();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "fileExplorerItems.xml",
          "fileExplorerItems", list);
    }

    /*
     * ##################### Recordings
     */
    {
      List<FlvRecording> list = flvRecordingDao.getAllFlvRecordings();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "flvRecordings.xml",
          "flvrecordings", list);
    }

    /*
     * ##################### Polls
     */
    {
      List<RoomPoll> list = pollManager.getPollListBackup();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      registry.bind(PollType.class, PollTypeConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getCreated().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "roompolls.xml", "roompolls", list);
    }

    /*
     * ##################### Config
     */
    {
      List<Configuration> list = configurationDao.getConfigurations(
          0, Integer.MAX_VALUE, "c.configuration_id", true);
      Registry registry = new Registry();
      registry.bind(State.class, StateConverter.class);
      registry.bind(User.class, UserConverter.class);
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStarttime().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "configs.xml", "configs", list);
    }
   
    /*
     * ##################### Chat
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      List<ChatMessage> list = chatDao.get(0, Integer.MAX_VALUE);
      if (list != null && list.size() > 0) {
View Full Code Here

    exportUsers(fos, list);
  }
  public void exportUsers(OutputStream os, List<User> list) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Organisation.class, OrganisationConverter.class);
    registry.bind(State.class, StateConverter.class);
    if (list != null && list.size() > 0) {
      registry.bind(list.get(0).getRegdate().getClass(), DateConverter.class);
View Full Code Here

TOP

Related Classes of org.simpleframework.xml.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.