Skip to content

Commit

Permalink
Fix character encoding (#510)
Browse files Browse the repository at this point in the history
* SWORD updateDatastream change charset to UTF-8

* produces statements to accept application/json and text/*

* define new constant for UTF-8 in AbstractSwordController

* CSV export in UTF-8
  • Loading branch information
harringj authored and bbpennel committed Sep 22, 2016
1 parent cce6342 commit 9a7e569
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.abdera.parser.Parser;
import org.apache.abdera.parser.ParserOptions;
import org.apache.abdera.parser.stax.FOMExtensibleElement;
import org.apache.http.Consts;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
Expand All @@ -45,6 +46,8 @@

public class AbstractSwordController extends AbstractSolrSearchController {
private static final Logger log = LoggerFactory.getLogger(AbstractSwordController.class);
public static final ContentType APPLICATION_ATOM_XML_UTF8 = ContentType.create(
"application/atom+xml", Consts.UTF_8);

@Autowired
private String swordUrl;
Expand Down Expand Up @@ -82,7 +85,7 @@ public String updateDatastream(String pid, String datastream, HttpServletRequest
StringWriter stringWriter = new StringWriter(2048);
StringEntity requestEntity;
entry.writeTo(stringWriter);
requestEntity = new StringEntity(stringWriter.toString(), ContentType.APPLICATION_ATOM_XML);
requestEntity = new StringEntity(stringWriter.toString(), APPLICATION_ATOM_XML_UTF8);
method.setEntity(requestEntity);
} catch (UnsupportedEncodingException e) {
log.error("Encoding not supported", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void export(@PathVariable("pid") String pid, HttpServletRequest request,
queryLayer.getChildrenCounts(objects, searchRequest);

try (ServletOutputStream out = response.getOutputStream()) {
Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1));
Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));

try (CSVPrinter printer = CSVFormat.EXCEL.print(writer)) {
printHeaders(printer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public String editDescription(@PathVariable("pid") String pid, Model model,
return "edit/description";
}

@RequestMapping(value = "describeInfo/{pid}", method = RequestMethod.GET)
@RequestMapping(value = "describeInfo/{pid}", method = RequestMethod.GET, produces = {"application/json; text/*; charset=UTF-8"})
public @ResponseBody
Map<String, Object> editDescription(@PathVariable("pid") String pid, HttpServletResponse response) {
response.setContentType("application/json");
Expand Down Expand Up @@ -165,7 +165,7 @@ Map<String, Object> editDescription(@PathVariable("pid") String pid, HttpServlet
* @param id
* @return
*/
@RequestMapping(value = "{pid}/mods", method = RequestMethod.GET, produces = {"text/xml; charset=UTF-8"})
@RequestMapping(value = "{pid}/mods", method = RequestMethod.GET, produces = {"application/json; text/*; charset=UTF-8"})
public @ResponseBody
String getMods(@PathVariable("pid") String pid) {
String mods = "";
Expand Down Expand Up @@ -214,7 +214,7 @@ String getMods(@PathVariable("pid") String pid) {
* @param request
* @return
*/
@RequestMapping(value = "describe/{pid}", method = RequestMethod.POST)
@RequestMapping(value = "describe/{pid}", method = RequestMethod.POST, produces = {"application/json; text/*; charset=UTF-8"})
public @ResponseBody
String updateDescription(@PathVariable("pid") String pid, Model model,
HttpServletRequest request, HttpServletResponse response) {
Expand Down

0 comments on commit 9a7e569

Please sign in to comment.