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

OO-273: normalize the filename of the files

parent 871a4867
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ import java.io.FileOutputStream; ...@@ -38,6 +38,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.Normalizer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
...@@ -217,7 +218,7 @@ public class FileUtils { ...@@ -217,7 +218,7 @@ public class FileUtils {
* @return true upon success * @return true upon success
*/ */
public static long getDirSize(File path) { public static long getDirSize(File path) {
Iterator path_iterator; Iterator<File> path_iterator;
File current_file; File current_file;
long size; long size;
...@@ -226,7 +227,7 @@ public class FileUtils { ...@@ -226,7 +227,7 @@ public class FileUtils {
path_iterator = (Arrays.asList(f)).iterator(); path_iterator = (Arrays.asList(f)).iterator();
size = 0; size = 0;
while (path_iterator.hasNext()) { while (path_iterator.hasNext()) {
current_file = (File) path_iterator.next(); current_file = path_iterator.next();
if (current_file.isFile()) { if (current_file.isFile()) {
size += current_file.length(); size += current_file.length();
} else { } else {
...@@ -805,6 +806,19 @@ public class FileUtils { ...@@ -805,6 +806,19 @@ public class FileUtils {
return true; return true;
} }
public static String normalizeFilename(String name) {
String nameFirstPass = name.replace(" ", "_");
nameFirstPass = nameFirstPass.replace("\u00C4", "Ae");
nameFirstPass = nameFirstPass.replace("\u00D6", "Oe");
nameFirstPass = nameFirstPass.replace("\u00DC", "Ue");
nameFirstPass = nameFirstPass.replace("\u00E4", "ae");
nameFirstPass = nameFirstPass.replace("\u00F6", "oe");
nameFirstPass = nameFirstPass.replace("\u00FC", "ue");
String nameNormalized = Normalizer.normalize(nameFirstPass, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+","");
String nameSanitized = nameNormalized.replaceAll("\\W+", "");
return nameSanitized;
}
/** /**
* Creates a new directory in the specified directory, using the given prefix and suffix strings to generate its name. * Creates a new directory in the specified directory, using the given prefix and suffix strings to generate its name.
* It uses File.createTempFile() and should provide a unique name. * It uses File.createTempFile() and should provide a unique name.
......
...@@ -311,9 +311,9 @@ public class BusinessGroupArchiver { ...@@ -311,9 +311,9 @@ public class BusinessGroupArchiver {
List<Member> participants = new ArrayList<Member>(); List<Member> participants = new ArrayList<Member>();
List<Member> waitings = new ArrayList<Member>(); List<Member> waitings = new ArrayList<Member>();
List groups = BGContextManagerImpl.getInstance().getGroupsOfBGContext(context); List<BusinessGroup> groups = BGContextManagerImpl.getInstance().getGroupsOfBGContext(context);
for (Iterator iter = groups.iterator(); iter.hasNext();) { for (Iterator<BusinessGroup> iter = groups.iterator(); iter.hasNext();) {
BusinessGroup group = (BusinessGroup) iter.next(); BusinessGroup group = iter.next();
if (groupList.contains(group)) { //rely on the equals() method of the BusinessGroup impl if (groupList.contains(group)) { //rely on the equals() method of the BusinessGroup impl
if(group.getOwnerGroup()!=null) { if(group.getOwnerGroup()!=null) {
Iterator ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator(); Iterator ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator();
...@@ -420,6 +420,7 @@ public class BusinessGroupArchiver { ...@@ -420,6 +420,7 @@ public class BusinessGroupArchiver {
//add two of _ more if this is not the case //add two of _ more if this is not the case
fileNamePrefix = fileNamePrefix + "_"; fileNamePrefix = fileNamePrefix + "_";
fileNamePrefix = fileNamePrefix.length() >= 3 ? fileNamePrefix : fileNamePrefix +"__"; fileNamePrefix = fileNamePrefix.length() >= 3 ? fileNamePrefix : fileNamePrefix +"__";
fileNamePrefix = FileUtils.normalizeFilename(fileNamePrefix);
outFile = File.createTempFile(fileNamePrefix, ".xls", tempDir); outFile = File.createTempFile(fileNamePrefix, ".xls", tempDir);
FileUtils.save(outFile, stringBuffer.toString(), charset); FileUtils.save(outFile, stringBuffer.toString(), charset);
//FileUtils.saveString(outFile, stringBuffer.toString()); //FileUtils.saveString(outFile, stringBuffer.toString());
...@@ -481,9 +482,9 @@ public class BusinessGroupArchiver { ...@@ -481,9 +482,9 @@ public class BusinessGroupArchiver {
Iterator<OrganisationalEntity> groupIterator = groupList.iterator(); Iterator<OrganisationalEntity> groupIterator = groupList.iterator();
while (groupIterator.hasNext()) { while (groupIterator.hasNext()) {
OrganisationalEntity group = groupIterator.next(); OrganisationalEntity group = groupIterator.next();
List<Member> groupOwners = getFilteredList(owners, group, this.OWNER); List<Member> groupOwners = getFilteredList(owners, group, OWNER);
List<Member> groupParticipants = getFilteredList(participants, group, this.PARTICIPANT); List<Member> groupParticipants = getFilteredList(participants, group, PARTICIPANT);
List<Member> groupWaiting = getFilteredList(waitings, group, this.WAITING); List<Member> groupWaiting = getFilteredList(waitings, group, WAITING);
File filePerGroup = archiveAllInOne(context, groupOwners, groupParticipants, groupWaiting, contextName, columnList, groupList, File filePerGroup = archiveAllInOne(context, groupOwners, groupParticipants, groupWaiting, contextName, columnList, groupList,
orgEntityTitle, userLocale, group.getName(), tempDir, charset); orgEntityTitle, userLocale, group.getName(), tempDir, charset);
...@@ -530,9 +531,9 @@ public class BusinessGroupArchiver { ...@@ -530,9 +531,9 @@ public class BusinessGroupArchiver {
Iterator<OrganisationalEntity> groupIterator = groupList.iterator(); Iterator<OrganisationalEntity> groupIterator = groupList.iterator();
while (groupIterator.hasNext()) { while (groupIterator.hasNext()) {
OrganisationalEntity group = groupIterator.next(); OrganisationalEntity group = groupIterator.next();
List<Member> groupOwners = getFilteredList(owners, group, this.OWNER); List<Member> groupOwners = getFilteredList(owners, group, OWNER);
List<Member> groupParticipants = getFilteredList(participants, group, this.PARTICIPANT); List<Member> groupParticipants = getFilteredList(participants, group, PARTICIPANT);
List<Member> groupWaiting = getFilteredList(waitings, group, this.WAITING); List<Member> groupWaiting = getFilteredList(waitings, group, WAITING);
File filePerGroup = archiveFileSingleGroup(context, groupOwners, groupParticipants, groupWaiting, columnList, groupList, orgEntityTitle, File filePerGroup = archiveFileSingleGroup(context, groupOwners, groupParticipants, groupWaiting, columnList, groupList, orgEntityTitle,
userLocale, group.getName(), tempDir, charset); userLocale, group.getName(), tempDir, charset);
......
...@@ -346,10 +346,10 @@ public class MemberListWizardController extends BasicController { ...@@ -346,10 +346,10 @@ public class MemberListWizardController extends BasicController {
*/ */
private File archiveMembers(UserRequest ureq) { private File archiveMembers(UserRequest ureq) {
File outputFile = null; File outputFile = null;
List columnList = this.getColumList(); List<String> columnList = getColumList();
List groupList = this.getGroupList(); List<BusinessGroup> groupList = getGroupList();
String archiveType = this.getArchiveType(); String archiveType = getArchiveType();
List areaList = this.getAreaList(); List<BGArea> areaList = getAreaList();
if(GROUPS_MEMBERS.equals(wizardType)) { if(GROUPS_MEMBERS.equals(wizardType)) {
outputFile = BusinessGroupArchiver.getInstance().archiveGroupMembers(context, columnList, groupList, archiveType, ureq); outputFile = BusinessGroupArchiver.getInstance().archiveGroupMembers(context, columnList, groupList, archiveType, ureq);
......
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