Skip to content
Snippets Groups Projects
Commit a0d30a23 authored by srosse's avatar srosse
Browse files

OO-3234: use the xstream helper to create new instance of XStream (-2 very special cases)

parent ac4e6d55
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ import org.olat.core.id.Identity;
import org.olat.core.id.User;
import org.olat.core.util.StringHelper;
import org.olat.core.util.Util;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.home.HomeMainController;
import org.olat.login.SupportsAfterLoginInterceptor;
import org.olat.user.ProfileAndHomePageEditController;
......@@ -101,7 +102,7 @@ public class ChangeEMailExecuteController extends ChangeEMailController implemen
* @return
*/
public boolean changeEMail(WindowControl wControl) {
XStream xml = new XStream();
XStream xml = XStreamHelper.createXStreamInstance();
@SuppressWarnings("unchecked")
HashMap<String, String> mails = (HashMap<String, String>) xml.fromXML(tempKey.getEmailAddress());
......
......@@ -37,18 +37,18 @@ import com.thoughtworks.xstream.converters.collections.MapConverter;
import com.thoughtworks.xstream.mapper.MapperWrapper;
/**
* This implmentation of XStream automatically convert hibernat list, set and map
* to standard java collections and convert by import / deserialization
* the old hibernate 3 collection packages to the new one.
* This implmentation of XStream automatically convert hibernat list, set and
* map to standard java collections and convert by import / deserialization the
* old hibernate 3 collection packages to the new one.
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class EnhancedXStream extends XStream {
public class EnhancedXStream extends XStream {
public EnhancedXStream(boolean export) {
super();
if(export) {
if (export) {
addDefaultImplementation(PersistentList.class, List.class);
addDefaultImplementation(PersistentBag.class, List.class);
addDefaultImplementation(PersistentMap.class, Map.class);
......@@ -56,24 +56,26 @@ public class EnhancedXStream extends XStream {
addDefaultImplementation(PersistentSet.class, Set.class);
addDefaultImplementation(PersistentSortedSet.class, Set.class);
addDefaultImplementation(ArrayList.class, List.class);
registerConverter(new CollectionConverter(getMapper()) {
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentList.class == type || PersistentBag.class == type;
}
@Override
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentList.class == type || PersistentBag.class == type;
}
});
registerConverter(new MapConverter(getMapper()) {
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentMap.class == type;
}
@Override
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentMap.class == type;
}
});
}
}
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new EnhancedMapper(next);
}
}
......@@ -84,6 +84,7 @@ public class XStreamHelper {
private static final String ENCODING = "UTF-8";
private static XStream unconfiguredXStream = new XStream();
/**
* Write a an object to an XML file. UTF-8 is used as encoding
......@@ -227,8 +228,7 @@ public class XStreamHelper {
* writing to a configured XML mapping
*/
public static XStream createXStreamInstance() {
EnhancedXStream xstream = new EnhancedXStream(false);
return xstream;
return new EnhancedXStream(false);
}
/**
......@@ -238,8 +238,7 @@ public class XStreamHelper {
* @return
*/
public static XStream createXStreamInstanceForDBObjects() {
EnhancedXStream xstream = new EnhancedXStream(true);
return xstream;
return new EnhancedXStream(true);
}
/**
......
......@@ -25,6 +25,8 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.olat.core.util.xml.XStreamHelper;
import com.thoughtworks.xstream.XStream;
/**
......@@ -42,7 +44,7 @@ public class GroupXStream {
private final XStream xstream;
public GroupXStream() {
xstream = new XStream();
xstream = XStreamHelper.createXStreamInstance();
xstream.alias("OLATGroupExport", OLATGroupExport.class);
xstream.alias("AreaCollection", AreaCollection.class);
xstream.alias("GroupCollection", GroupCollection.class);
......
......@@ -98,7 +98,7 @@ public class FeedFileStorge {
public FeedFileStorge() {
fileResourceManager = FileResourceManager.getInstance();
xstream = new XStream();
xstream = XStreamHelper.createXStreamInstance();
xstream.alias("feed", FeedImpl.class);
xstream.aliasField("type", FeedImpl.class, "resourceableType");
xstream.omitField(FeedImpl.class, "id");
......
......@@ -55,6 +55,7 @@ import org.olat.core.util.WebappHelper;
import org.olat.core.util.i18n.I18nModule;
import org.olat.core.util.mail.MailManager;
import org.olat.core.util.mail.MailerResult;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.properties.Property;
import org.olat.properties.PropertyManager;
import org.olat.user.UserManager;
......@@ -361,7 +362,7 @@ public class RegistrationManager {
List<TemporaryKey> tk = rm.loadTemporaryKeyByAction(RegistrationManager.EMAIL_CHANGE);
if (tk != null) {
for (TemporaryKey temporaryKey : tk) {
XStream xml = new XStream();
XStream xml = XStreamHelper.createXStreamInstance();
@SuppressWarnings("unchecked")
Map<String, String> mails = (Map<String, String>) xml.fromXML(temporaryKey.getEmailAddress());
if (emailAddress.equalsIgnoreCase(mails.get("changedEMail"))) {
......
......@@ -545,7 +545,7 @@ public class ProfileFormController extends FormBasicController {
mailMap.put("currentEMail", currentEmail);
mailMap.put("changedEMail", changedEmail);
XStream xml = new XStream();
XStream xml = XStreamHelper.createXStreamInstance();
String serMailMap = xml.toXML(mailMap);
TemporaryKey tk = rm.createAndDeleteOldTemporaryKey(identityToModify.getKey(), serMailMap, ip, RegistrationManager.EMAIL_CHANGE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment