Skip to content

Commit

Permalink
Merge pull request DSpace#9138 from tdonohue/port_8966_to_dspace7x
Browse files Browse the repository at this point in the history
[Port to dspace-7_x] Reading localized license file.
  • Loading branch information
tdonohue authored Oct 20, 2023
2 parents 68e80b9 + fa01fde commit 21ce7d7
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions dspace-api/src/main/java/org/dspace/core/LicenseServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;

import org.dspace.core.service.LicenseService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.services.model.Request;
import org.dspace.web.ContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -101,23 +104,23 @@ public String getLicenseText(String licenseFile) {
/**
* Get the site-wide default license that submitters need to grant
*
* Localized license requires: default_{{locale}}.license file.
* Locale also must be listed in webui.supported.locales setting.
*
* @return the default license
*/
@Override
public String getDefaultSubmissionLicense() {
if (null == license) {
init();
}
init();
return license;
}

/**
* Load in the default license.
*/
protected void init() {
File licenseFile = new File(
DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir")
+ File.separator + "config" + File.separator + "default.license");
Context context = obtainContext();
File licenseFile = new File(I18nUtil.getDefaultLicense(context));

FileInputStream fir = null;
InputStreamReader ir = null;
Expand Down Expand Up @@ -169,4 +172,24 @@ protected void init() {
}
}
}

/**
* Obtaining current request context.
* Return new context if getting one from current request failed.
*
* @return DSpace context object
*/
private Context obtainContext() {
try {
Request currentRequest = DSpaceServicesFactory.getInstance().getRequestService().getCurrentRequest();
if (currentRequest != null) {
HttpServletRequest request = currentRequest.getHttpServletRequest();
return ContextUtil.obtainContext(request);
}
} catch (Exception e) {
log.error("Can't load current request context.");
}

return new Context();
}
}

0 comments on commit 21ce7d7

Please sign in to comment.