Java 类org.simpleframework.xml.convert.Registry 实例源码

项目:healthvault-java-sdk    文件:XmlSerializer.java   
private static Serializer getReadSerializer() throws Exception {
    if (readSerializer == null) {
    Log.d("hv", "Begin Creating Serializer");
       RegistryMatcher matcher = new RegistryMatcher();
       matcher.bind(Date.class, new DateFormatTransformer());

       Registry registry = new Registry();
       registry.bind(String.class, SimpleXMLStringConverter.class);
       Strategy strategy = new RegistryStrategy(registry);

       Serializer s = new Persister(strategy, matcher);
    Log.d("hv", "Done Creating Serializer");

    readSerializer = s;
    }
       return readSerializer;
}
项目:openmeetings    文件:BackupImport.java   
private void importRoomGroups(File f) throws Exception {
    log.info("Room import complete, starting room groups import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Group.class, new GroupConverter(groupDao, groupMap));
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));

    List<RoomGroup> list = readList(serializer, f, "rooms_organisation.xml", "room_organisations", RoomGroup.class);
    for (RoomGroup ro : list) {
        Room r = roomDao.get(ro.getRoom().getId());
        if (r == null || ro.getGroup() == null || ro.getGroup().getId() == null) {
            continue;
        }
        if (r.getGroups() == null) {
            r.setGroups(new ArrayList<>());
        }
        ro.setId(null);
        ro.setRoom(r);
        r.getGroups().add(ro);
        roomDao.update(r, null);
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importChat(File f) throws Exception {
    log.info("Room groups import complete, starting chat messages import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
    registry.bind(Date.class, DateConverter.class);

    List<ChatMessage> list = readList(serializer, f, "chat_messages.xml", "chat_messages", ChatMessage.class);
    for (ChatMessage m : list) {
        m.setId(null);
        if (m.getFromUser() == null || m.getFromUser().getId() == null) {
            continue;
        }
        chatDao.update(m, m.getSent());
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importContacts(File f) throws Exception {
    log.info("Private message folder import complete, starting user contacts import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, new UserConverter(userDao, userMap));

    List<UserContact> list = readList(serializer, f, "userContacts.xml", "usercontacts", UserContact.class);
    for (UserContact uc : list) {
        Long ucId = uc.getId();
        UserContact storedUC = userContactDao.get(ucId);

        if (storedUC == null && uc.getContact() != null && uc.getContact().getId() != null) {
            uc.setId(null);
            if (uc.getOwner() != null && uc.getOwner().getId() == null) {
                uc.setOwner(null);
            }
            uc = userContactDao.update(uc);
            userContactMap.put(ucId, uc.getId());
        }
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importRoomFiles(File f) throws Exception {
    log.info("Poll import complete, starting room files import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(BaseFileItem.class, new BaseFileItemConverter(fileItemDao, fileItemMap));

    List<RoomFile> list = readList(serializer, f, "roomFiles.xml", "RoomFiles", RoomFile.class, true);
    for (RoomFile rf : list) {
        Room r = roomDao.get(roomMap.get(rf.getRoomId()));
        if (r == null || rf.getFile() == null || rf.getFile().getId() == null) {
            continue;
        }
        if (r.getFiles() == null) {
            r.setFiles(new ArrayList<>());
        }
        rf.setId(null);
        rf.setRoomId(r.getId());
        r.getFiles().add(rf);
        roomDao.update(r, null);
    }
}
项目:aet    文件:XmlTestSuiteParser.java   
private Serializer getSerializer() throws AETException {
  Registry registry = new Registry();
  Serializer serializer = new Persister(new RegistryStrategy(registry));
  try {
    registry.bind(Collect.class, new CollectConverter());
    registry.bind(Compare.class, new CompareConverter());
  } catch (Exception e) {
    throw new AETException("Error while serializing test suite.", e);
  }
  return serializer;
}
项目:KeePassJava2    文件:SimpleDatabase.java   
/**
 * Utility to get a simple framework persister
 * @return a persister
 * @throws Exception when things get tough
 */
private static Serializer getSerializer() throws Exception {
    Registry registry = new Registry();
    registry.bind(String.class, EmptyStringConverter.class);
    Strategy strategy = new AnnotationStrategy(new RegistryStrategy(registry));
    return new Persister(strategy);

}
项目:android-anuto    文件:SerializerFactory.java   
public Serializer createSerializer() {
    Registry registry = new Registry();

    try {
        registry.bind(Vector2.class, VectorConverter.class);
    } catch (Exception e) {
        throw new RuntimeException("Error binding converters!");
    }

    Strategy strategy = new RegistryStrategy(registry);
    return new Persister(strategy);
}
项目:openmeetings    文件:BackupExport.java   
private static <T> void bindDate(Registry registry, List<T> list, Function<T, ?> func) throws Exception {
    if (list != null) {
        for (T e : list) {
            Object d = func.apply(e);
            if (d != null) {
                Class<?> dateClass = d.getClass();
                registry.bind(dateClass, DateConverter.class);
                break;
            }
        }
    }
}
项目:openmeetings    文件:BackupExport.java   
private void exportGroups(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);
    List<Group> list = groupDao.get(0, Integer.MAX_VALUE);
    bindDate(registry, list);
    writeList(ser, zos, "organizations.xml", "organisations", list);
    progressHolder.setProgress(5);
}
项目:openmeetings    文件:BackupExport.java   
private void exportUsers(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);

    registry.bind(Group.class, GroupConverter.class);
    registry.bind(Salutation.class, SalutationConverter.class);
    List<User> list = userDao.getAllBackupUsers();
    bindDate(registry, list);

    writeList(ser, zos, "users.xml", "users", list);
    progressHolder.setProgress(10);
}
项目:openmeetings    文件:BackupExport.java   
private void exportRoom(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, UserConverter.class);
    registry.bind(Room.Type.class, RoomTypeConverter.class);
    List<Room> list = roomDao.get();
    bindDate(registry, list);
    writeList(serializer, zos, "rooms.xml", "rooms", list);
    progressHolder.setProgress(15);
}
项目:openmeetings    文件:BackupExport.java   
private void exportRoomGroup(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Group.class, GroupConverter.class);
    registry.bind(Room.class, RoomConverter.class);

    writeList(serializer, zos, "rooms_organisation.xml", "room_organisations", roomDao.getGroups());
    progressHolder.setProgress(17);
}
项目:openmeetings    文件:BackupExport.java   
private void exportRoomFile(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(FileItem.class, BaseFileItemConverter.class);
    registry.bind(Recording.class, BaseFileItemConverter.class);

    writeList(serializer, zos, "roomFiles.xml", "RoomFiles", roomDao.getFiles());
    progressHolder.setProgress(17);
}
项目:openmeetings    文件:BackupExport.java   
private void exportCalendar(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<OmCalendar> list = calendarDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, UserConverter.class);

    writeList(serializer, zos, "calendars.xml", "calendars", list);
    progressHolder.setProgress(22);
}
项目:openmeetings    文件:BackupExport.java   
private void exportAppointment(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<Appointment> list = appointmentDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, UserConverter.class);
    registry.bind(Appointment.Reminder.class, AppointmentReminderTypeConverter.class);
    registry.bind(Room.class, RoomConverter.class);
    bindDate(registry, list);

    writeList(serializer, zos, "appointements.xml", "appointments", list);
    progressHolder.setProgress(25);
}
项目:openmeetings    文件:BackupExport.java   
private void exportMeetingMember(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    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, zos, "meetingmembers.xml",
            "meetingmembers", meetingMemberDao.getMeetingMembers());
    progressHolder.setProgress(30);
}
项目:openmeetings    文件:BackupExport.java   
private void exportOauth(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    List<OAuthServer> list = auth2Dao.get(0, Integer.MAX_VALUE);
    bindDate(registry, list);
    writeList(serializer, zos, "oauth2servers.xml", "oauth2servers", list);
    progressHolder.setProgress(45);
}
项目:openmeetings    文件:BackupExport.java   
private void exportPrivateMsg(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<PrivateMessage> list = privateMessageDao.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);
    bindDate(registry, list, PrivateMessage::getInserted);
    writeList(serializer, zos, "privateMessages.xml", "privatemessages", list);
    progressHolder.setProgress(50);
}
项目:openmeetings    文件:BackupExport.java   
private void exportContacts(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, UserConverter.class);

    writeList(serializer, zos, "userContacts.xml", "usercontacts", userContactDao.get());
    progressHolder.setProgress(60);
}
项目:openmeetings    文件:BackupExport.java   
private void exportFile(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<FileItem> list = fileItemDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    bindDate(registry, list);
    writeList(serializer, zos, "fileExplorerItems.xml", "fileExplorerItems", list);
    progressHolder.setProgress(65);
}
项目:openmeetings    文件:BackupExport.java   
private void exportRecording(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<Recording> list = recordingDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    bindDate(registry, list);
    writeList(serializer, zos, "flvRecordings.xml", "flvrecordings", list);
    progressHolder.setProgress(70);
}
项目:openmeetings    文件:BackupExport.java   
private void exportPoll(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<RoomPoll> list = pollManager.get();
    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(RoomPoll.Type.class, PollTypeConverter.class);
    bindDate(registry, list, RoomPoll::getCreated);
    writeList(serializer, zos, "roompolls.xml", "roompolls", list);
    progressHolder.setProgress(75);
}
项目:openmeetings    文件:BackupExport.java   
private void exportChat(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<ChatMessage> list = chatDao.get(0, Integer.MAX_VALUE);
    Registry registry = new Registry();
    registry.bind(User.class, UserConverter.class);
    registry.bind(Room.class, RoomConverter.class);
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    bindDate(registry, list, ChatMessage::getSent);
    writeList(serializer, zos, "chat_messages.xml", "chat_messages", list);
    progressHolder.setProgress(85);
}
项目:openmeetings    文件:BackupExport.java   
private static Serializer getConfigSerializer(List<Configuration> list) throws Exception {
    Registry registry = new Registry();
    registry.bind(User.class, UserConverter.class);
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    bindDate(registry, list);
    return serializer;
}
项目:openmeetings    文件:BackupImport.java   
private void importRooms(File f) throws Exception {
    log.info("Users import complete, starting room import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer ser = new Persister(strategy, matcher);

    matcher.bind(Long.class, LongTransform.class);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Room.Type.class, RoomTypeConverter.class);
    registry.bind(Date.class, DateConverter.class);
    List<Room> list = readList(ser, f, "rooms.xml", "rooms", Room.class);
    for (Room r : list) {
        Long roomId = r.getId();

        // We need to reset ids as openJPA reject to store them otherwise
        r.setId(null);
        if (r.getModerators() != null) {
            for (Iterator<RoomModerator> i = r.getModerators().iterator(); i.hasNext();) {
                RoomModerator rm = i.next();
                if (rm.getUser().getId() == null) {
                    i.remove();
                }
            }
        }
        r = roomDao.update(r, null);
        roomMap.put(roomId, r.getId());
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importCalendars(File f) throws Exception {
    log.info("Chat messages import complete, starting calendar import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    List<OmCalendar> list = readList(serializer, f, "calendars.xml", "calendars", OmCalendar.class, true);
    for (OmCalendar c : list) {
        Long id = c.getId();
        c.setId(null);
        c = calendarDao.update(c);
        calendarMap.put(id, c.getId());
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importAppointments(File f) throws Exception {
    log.info("Calendar import complete, starting appointement import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Appointment.Reminder.class, AppointmentReminderTypeConverter.class);
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
    registry.bind(Date.class, DateConverter.class);
    registry.bind(OmCalendar.class, new OmCalendarConverter(calendarDao, calendarMap));

    List<Appointment> list = readList(serializer, f, "appointements.xml", "appointments", Appointment.class);
    for (Appointment a : list) {
        Long appId = a.getId();

        // We need to reset this as openJPA reject to store them otherwise
        a.setId(null);
        if (a.getOwner() != null && a.getOwner().getId() == null) {
            a.setOwner(null);
        }
        if (a.getRoom() == null || a.getRoom().getId() == null) {
            log.warn("Appointment without room was found, skipping: {}", a);
            continue;
        }
        if (a.getStart() == null || a.getEnd() == null) {
            log.warn("Appointment without start/end time was found, skipping: {}", a);
            continue;
        }
        a = appointmentDao.update(a, null, false);
        appointmentMap.put(appId, a.getId());
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importMeetingMembers(File f) throws Exception {
    log.info("Appointement import complete, starting meeting members import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);

    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Appointment.class, new AppointmentConverter(appointmentDao, appointmentMap));
    List<MeetingMember> list = readList(ser, f, "meetingmembers.xml", "meetingmembers", MeetingMember.class);
    for (MeetingMember ma : list) {
        ma.setId(null);
        meetingMemberDao.update(ma);
    }
}
项目:openmeetings    文件:BackupImport.java   
private void importRecordings(File f) throws Exception {
    log.info("Meeting members import complete, starting recordings server import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer ser = new Persister(strategy, matcher);

    matcher.bind(Long.class, LongTransform.class);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(Date.class, DateConverter.class);
    registry.bind(Recording.Status.class, RecordingStatusConverter.class);
    List<Recording> list = readList(ser, f, "flvRecordings.xml", "flvrecordings", Recording.class);
    for (Recording r : list) {
        Long recId = r.getId();
        r.setId(null);
        if (r.getRoomId() != null) {
            r.setRoomId(roomMap.get(r.getRoomId()));
        }
        if (r.getOwnerId() != null) {
            r.setOwnerId(userMap.get(r.getOwnerId()));
        }
        if (r.getMetaData() != null) {
            for (RecordingMetaData meta : r.getMetaData()) {
                meta.setId(null);
                meta.setRecording(r);
            }
        }
        if (!Strings.isEmpty(r.getHash()) && r.getHash().startsWith(RECORDING_FILE_NAME)) {
            String name = getFileName(r.getHash());
            r.setHash(UUID.randomUUID().toString());
            fileMap.put(String.format(FILE_NAME_FMT, name, EXTENSION_JPG), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_PNG));
            fileMap.put(String.format("%s.%s.%s", name, EXTENSION_FLV, EXTENSION_MP4), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_MP4));
        }
        if (Strings.isEmpty(r.getHash())) {
            r.setHash(UUID.randomUUID().toString());
        }
        r = recordingDao.update(r);
        fileItemMap.put(recId, r.getId());
    }
}
项目:openmeetings    文件:BackupImport.java   
private List<FileItem> importFiles(File f) throws Exception {
    log.info("Private message import complete, starting file explorer item import");
    List<FileItem> result = new ArrayList<>();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer ser = new Persister(strategy, matcher);

    matcher.bind(Long.class, LongTransform.class);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(Date.class, DateConverter.class);
    List<FileItem> list = readList(ser, f, "fileExplorerItems.xml", "fileExplorerItems", FileItem.class);
    for (FileItem file : list) {
        Long fId = file.getId();
        // We need to reset this as openJPA reject to store them otherwise
        file.setId(null);
        Long roomId = file.getRoomId();
        file.setRoomId(roomMap.containsKey(roomId) ? roomMap.get(roomId) : null);
        if (file.getOwnerId() != null) {
            file.setOwnerId(userMap.get(file.getOwnerId()));
        }
        if (file.getParentId() != null && file.getParentId().longValue() <= 0L) {
            file.setParentId(null);
        }
        if (Strings.isEmpty(file.getHash())) {
            file.setHash(UUID.randomUUID().toString());
        }
        file = fileItemDao.update(file);
        result.add(file);
        fileItemMap.put(fId, file.getId());
    }
    return result;
}
项目:openmeetings    文件:BackupImport.java   
private void importPolls(File f) throws Exception {
    log.info("File explorer item import complete, starting room poll import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer serializer = new Persister(strategy, matcher);

    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
    registry.bind(RoomPoll.Type.class, PollTypeConverter.class);
    registry.bind(Date.class, DateConverter.class);

    List<RoomPoll> list = readList(serializer, f, "roompolls.xml", "roompolls", RoomPoll.class);
    for (RoomPoll rp : list) {
        rp.setId(null);
        if (rp.getRoom() == null || rp.getRoom().getId() == null) {
            //room was deleted
            continue;
        }
        if (rp.getCreator() == null || rp.getCreator().getId() == null) {
            rp.setCreator(null);
        }
        for (RoomPollAnswer rpa : rp.getAnswers()) {
            if (rpa.getVotedUser() == null || rpa.getVotedUser().getId() == null) {
                rpa.setVotedUser(null);
            }
        }
        pollDao.update(rp);
    }
}
项目:simple-xml-serializers    文件:PersisterFactory.java   
private static void addConverters(@Nonnull Registry registry, @Nonnull Serializer serializer, @Nonnull Iterable<? extends ConverterFactory> factories) {
    // LOG.info("Loading ConverterFactory instances.");
    for (ConverterFactory factory : factories) {
        // LOG.info("Factory " + factory);
        for (Map.Entry<? extends Class<?>, ? extends Converter<?>> e : factory.newConverters(serializer)) {
            // LOG.info("Register " + e.getKey() + " -> " + e.getValue());
            try {
                registry.bind(e.getKey(), e.getValue());
            } catch (Exception ex) {
                LOG.error("Failed to bind " + e.getKey() + " to " + e.getValue(), ex);
            }
        }
    }
}
项目:simple-xml    文件:CustomTransformTest.java   
public void testWithRegistryStrategy() throws Exception {
    Registry registry = new Registry();
    registry.bind(Property.class, new PropertyConverter());
    Strategy strategy = new RegistryStrategy(registry);
    Persister persister = new Persister(strategy);
    test(persister);
}
项目:openmeetings    文件:BackupExport.java   
private static <T extends HistoricalEntity> void bindDate(Registry registry, List<T> list) throws Exception {
    bindDate(registry, list, HistoricalEntity::getInserted);
}
项目:openmeetings    文件:BackupImport.java   
public void performImport(InputStream is) throws Exception {
    userMap.clear();
    groupMap.clear();
    calendarMap.clear();
    appointmentMap.clear();
    roomMap.clear();
    messageFolderMap.clear();
    userContactMap.clear();
    fileMap.clear();
    messageFolderMap.put(INBOX_FOLDER_ID, INBOX_FOLDER_ID);
    messageFolderMap.put(SENT_FOLDER_ID, SENT_FOLDER_ID);
    messageFolderMap.put(TRASH_FOLDER_ID, TRASH_FOLDER_ID);

    File f = unzip(is);
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer simpleSerializer = new Persister(strategy, matcher);

    matcher.bind(Long.class, LongTransform.class);
    registry.bind(Date.class, DateConverter.class);

    BackupVersion ver = getVersion(simpleSerializer, f);
    importConfigs(f);
    importGroups(f, simpleSerializer);
    Long defaultLdapId = importLdap(f, simpleSerializer);
    importOauth(f, simpleSerializer);
    importUsers(f, defaultLdapId);
    importRooms(f);
    importRoomGroups(f);
    importChat(f);
    importCalendars(f);
    importAppointments(f);
    importMeetingMembers(f);
    importRecordings(f);
    importPrivateMsgFolders(f, simpleSerializer);
    importContacts(f);
    importPrivateMsgs(f);
    List<FileItem> files = importFiles(f);
    importPolls(f);
    importRoomFiles(f);

    log.info("Room files import complete, starting copy of files and folders");
    /*
     * ##################### Import real files and folders
     */
    importFolders(f);

    if (ver.compareTo(BackupVersion.get("4.0.0")) < 0) {
        for (BaseFileItem bfi : files) {
            if (bfi.isDeleted()) {
                continue;
            }
            if (BaseFileItem.Type.Presentation == bfi.getType()) {
                convertOldPresentation((FileItem)bfi);
                fileItemDao._update(bfi);
            }
            if (BaseFileItem.Type.WmlFile == bfi.getType()) {
                try {
                    Whiteboard wb = WbConverter.convert((FileItem)bfi);
                    wb.save(bfi.getFile().toPath());
                } catch (Exception e) {
                    log.error("Unexpected error while converting WB", e);
                }
            }
        }
    }
    log.info("File explorer item import complete, clearing temp files");

    FileUtils.deleteDirectory(f);
}
项目:openmeetings    文件:BackupImport.java   
private void importConfigs(File f) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer serializer = new Persister(strategy, matcher);

    matcher.bind(Long.class, LongTransform.class);
    registry.bind(Date.class, DateConverter.class);
    registry.bind(User.class, new UserConverter(userDao, userMap));

    List<Configuration> list = readList(serializer, f, "configs.xml", "configs", Configuration.class);
    for (Configuration c : list) {
        if (c.getKey() == null || c.isDeleted()) {
            continue;
        }
        String newKey = outdatedConfigKeys.get(c.getKey());
        if (newKey != null) {
            c.setKey(newKey);
        }
        Configuration.Type type = configTypes.get(c.getKey());
        if (type != null) {
            c.setType(type);
            if (Configuration.Type.bool == type) {
                c.setValue(String.valueOf("1".equals(c.getValue()) || "yes".equals(c.getValue()) || "true".equals(c.getValue())));
            }
        }
        Configuration cfg = cfgDao.forceGet(c.getKey());
        if (cfg != null && !cfg.isDeleted()) {
            log.warn("Non deleted configuration with same key is found! old value: {}, new value: {}", cfg.getValue(), c.getValue());
        }
        c.setId(cfg == null ? null : cfg.getId());
        if (c.getUser() != null && c.getUser().getId() == null) {
            c.setUser(null);
        }
        if (CONFIG_CRYPT.equals(c.getKey())) {
            try {
                Class<?> clazz = Class.forName(c.getValue());
                clazz.getDeclaredConstructor().newInstance();
            } catch (Exception e) {
                log.warn("Not existing Crypt class found {}, replacing with SCryptImplementation", c.getValue());
                c.setValue(SCryptImplementation.class.getCanonicalName());
            }
        }
        cfgDao.update(c, null);
    }
}