use of org.simpleframework.xml.transform.RegistryMatcher in project randomizedtesting by randomizedtesting.
the class TestXmlStringsRoundtrip method check.
private void check(char[] chars) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
RegistryMatcher rm = new RegistryMatcher();
rm.bind(String.class, XmlStringTransformerAccess.getInstance());
Persister persister = new Persister(rm);
persister.write(new Model(new String(chars)), baos);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
try {
docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
} catch (SAXParseException e) {
System.out.println("Input: " + Arrays.toString(chars));
System.out.println("XML: " + new String(baos.toByteArray(), StandardCharsets.UTF_8));
throw e;
}
}
use of org.simpleframework.xml.transform.RegistryMatcher in project openmeetings by apache.
the class BackupImport method performImport.
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);
}
use of org.simpleframework.xml.transform.RegistryMatcher in project openmeetings by apache.
the class BackupImport method importPolls.
/*
* ##################### Import Room Polls
*/
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);
}
}
use of org.simpleframework.xml.transform.RegistryMatcher in project openmeetings by apache.
the class BackupImport method importRecordings.
/*
* ##################### Import Recordings
*/
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());
}
}
Aggregations