Merge pull request #1363 from tuub/DS-3107

DS-3107: NewsService should allow localized news files
This commit is contained in:
Pascal-Nicolas Becker
2016-04-22 19:59:35 +02:00

View File

@@ -16,12 +16,15 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import org.dspace.core.service.NewsService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Encapsulate access to the news texts.
@@ -33,10 +36,31 @@ public class NewsServiceImpl implements NewsService
private final Logger log = LoggerFactory.getLogger(NewsServiceImpl.class);
private List<String> acceptableFilenames;
@Autowired(required = true)
private ConfigurationService configurationService;
public void setAcceptableFilenames(List<String> acceptableFilenames) {
this.acceptableFilenames = acceptableFilenames;
}
this.acceptableFilenames = addLocalesToAcceptableFilenames(acceptableFilenames);
}
protected List<String> addLocalesToAcceptableFilenames(List<String> acceptableFilenames){
String [] locales = configurationService.getArrayProperty("webui.supported.locales");
List<String> newAcceptableFilenames = new ArrayList<>();
newAcceptableFilenames.addAll(acceptableFilenames);
for(String local : locales){
for(String acceptableFilename : acceptableFilenames){
int lastPoint = acceptableFilename.lastIndexOf(".");
newAcceptableFilenames.add(
acceptableFilename.substring(0, lastPoint)
+ "_"
+ local
+ acceptableFilename.substring(lastPoint));
}
}
return newAcceptableFilenames;
}
/** Not instantiable. */
protected NewsServiceImpl() {}