1 package org.exoplatform.ecm.connector;
2
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5 import java.util.Date;
6
7 import javax.ws.rs.GET;
8 import javax.ws.rs.Path;
9 import javax.ws.rs.QueryParam;
10 import javax.ws.rs.core.Response;
11
12 import org.exoplatform.ecm.utils.text.Text;
13 import org.exoplatform.services.rest.resource.ResourceContainer;
14
15 import com.ibm.icu.text.Transliterator;
16
17 @Path("/l11n/")
18 public class LocalizationConnector implements ResourceContainer {
19
20
21 private static final String LAST_MODIFIED_PROPERTY = "Last-Modified";
22
23 private static final String CONTENT_TYPE = "Content-Type";
24
25
26 private static final String IF_MODIFIED_SINCE_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss z";
27
28 @GET
29 @Path("/cleanName/")
30 public Response getCleanName(
31 @QueryParam("name") String name
32 ) throws Exception {
33 DateFormat dateFormat = new SimpleDateFormat(IF_MODIFIED_SINCE_DATE_FORMAT);
34 try {
35 return Response.ok(org.exoplatform.services.cms.impl.Utils.cleanString(name))
36 .header(CONTENT_TYPE, "text/html; charset=utf-8")
37 .header(LAST_MODIFIED_PROPERTY, dateFormat.format(new Date()))
38 .build();
39 } catch (Exception e) {
40 Response.serverError().build();
41 }
42 return Response.ok()
43 .header(CONTENT_TYPE, "text/html; charset=utf-8")
44 .header(LAST_MODIFIED_PROPERTY, dateFormat.format(new Date()))
45 .build();
46 }
47
48 @GET
49 @Path("/convertName/")
50 public Response convertName(
51 @QueryParam("name") String name
52 ) throws Exception {
53 DateFormat dateFormat = new SimpleDateFormat(IF_MODIFIED_SINCE_DATE_FORMAT);
54 try {
55 return Response.ok(Text.convertJcrChars(name))
56 .header(CONTENT_TYPE, "text/html; charset=utf-8")
57 .header(LAST_MODIFIED_PROPERTY, dateFormat.format(new Date()))
58 .build();
59 } catch (Exception e) {
60 Response.serverError().build();
61 }
62 return Response.ok()
63 .header(CONTENT_TYPE, "text/html; charset=utf-8")
64 .header(LAST_MODIFIED_PROPERTY, dateFormat.format(new Date()))
65 .build();
66 }
67
68 }