diff --git a/web/documentserver-example/csharp-mvc/Helpers/DocumentConverter.cs b/web/documentserver-example/csharp-mvc/Helpers/DocumentConverter.cs index 3e098e0c..5b65831c 100644 --- a/web/documentserver-example/csharp-mvc/Helpers/DocumentConverter.cs +++ b/web/documentserver-example/csharp-mvc/Helpers/DocumentConverter.cs @@ -82,7 +82,8 @@ namespace OnlineEditorsExampleMVC.Helpers string documentRevisionId, bool isAsync, out string convertedDocumentUri, - string filePass = null) + string filePass = null, + string lang = null) { convertedDocumentUri = string.Empty; @@ -114,7 +115,8 @@ namespace OnlineEditorsExampleMVC.Helpers { "outputtype", toExtension.Trim('.') }, { "title", title }, { "url", documentUri }, - { "password", filePass } + { "password", filePass }, + { "region", lang } }; if (JwtManager.Enabled) diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs index 1beb932e..701b3128 100644 --- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs @@ -136,6 +136,7 @@ namespace OnlineEditorsExampleMVC var body = jss.Deserialize>(fileData); var fileName = Path.GetFileName(body["filename"].ToString()); + var lang = context.Request.Cookies.GetOrDefault("ulang", null); var filePass = body["filePass"] != null ? body["filePass"].ToString() : null; var fileUri = DocManagerHelper.GetDownloadUrl(fileName); @@ -159,7 +160,7 @@ namespace OnlineEditorsExampleMVC // get the url to the converted file string newFileUri; - var result = ServiceConverter.GetConvertedUri(downloadUri.ToString(), extension, internalExtension, key, true, out newFileUri, filePass); + var result = ServiceConverter.GetConvertedUri(downloadUri.ToString(), extension, internalExtension, key, true, out newFileUri, filePass, lang); if (result != 100) { context.Response.Write("{ \"step\" : \"" + result + "\", \"filename\" : \"" + fileName + "\"}"); diff --git a/web/documentserver-example/csharp/Default.aspx.cs b/web/documentserver-example/csharp/Default.aspx.cs index 8f9982e6..bde7ee1f 100644 --- a/web/documentserver-example/csharp/Default.aspx.cs +++ b/web/documentserver-example/csharp/Default.aspx.cs @@ -369,6 +369,7 @@ namespace OnlineEditorsExample _fileName = Path.GetFileName(body["filename"].ToString()); var filePass = body["filePass"] != null ? body["filePass"].ToString() : null; + var lang = context.Request.Cookies.GetOrDefault("ulang", null); var extension = (Path.GetExtension(_fileName).ToLower() ?? "").Trim('.'); var internalExtension = FileType.GetInternalExtension(_fileName).Trim('.'); @@ -389,7 +390,7 @@ namespace OnlineEditorsExample // get the url to the converted file string newFileUri; - var result = ServiceConverter.GetConvertedUri(fileUrl.ToString() , extension, internalExtension, key, true, out newFileUri, filePass); ; + var result = ServiceConverter.GetConvertedUri(fileUrl.ToString() , extension, internalExtension, key, true, out newFileUri, filePass, lang); if (result != 100) { return "{ \"step\" : \"" + result + "\", \"filename\" : \"" + _fileName + "\"}"; diff --git a/web/documentserver-example/csharp/DocumentConverter.cs b/web/documentserver-example/csharp/DocumentConverter.cs index 615a636a..83f87244 100644 --- a/web/documentserver-example/csharp/DocumentConverter.cs +++ b/web/documentserver-example/csharp/DocumentConverter.cs @@ -84,7 +84,8 @@ namespace ASC.Api.DocumentConverter string documentRevisionId, bool isAsync, out string convertedDocumentUri, - string filePass = null) + string filePass = null, + string lang = null) { convertedDocumentUri = string.Empty; @@ -116,7 +117,8 @@ namespace ASC.Api.DocumentConverter { "outputtype", toExtension.Trim('.') }, { "title", title }, { "url", documentUri }, - { "password", filePass } + { "password", filePass }, + { "region", lang } }; if (JwtManager.Enabled) diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java index baf1d845..8bfceaa6 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java @@ -133,7 +133,7 @@ public class FileController { @PostMapping(path = "${url.converter}") @ResponseBody public String convert(@RequestBody Converter body, - @CookieValue("uid") String uid){ + @CookieValue("uid") String uid, @CookieValue("ulang") String lang){ String fileName = body.getFileName(); String fileUri = documentManager.getDownloadUrl(fileName); String filePass = body.getFilePass() != null ? body.getFilePass() : null; @@ -145,7 +145,7 @@ public class FileController { if(fileUtility.getConvertExts().contains(fileExt)){ String key = serviceConverter.generateRevisionId(fileUri); String newFileUri = serviceConverter - .getConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true); + .getConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true, lang); if(newFileUri.isEmpty()){ return "{ \"step\" : \"0\", \"filename\" : \"" + fileName + "\"}"; diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java index a2254605..de315b49 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java @@ -97,7 +97,7 @@ public class DefaultCallbackManager implements CallbackManager { //TODO: Refactoring if (!curExt.equals(downloadExt)) { try { - String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt, curExt, serviceConverter.generateRevisionId(downloadUri), null, false); // convert file and get url to a new file + String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt, curExt, serviceConverter.generateRevisionId(downloadUri), null, false, null); // convert file and get url to a new file if (newFileUri.isEmpty()) { newFileName = documentManager .getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt); // get the correct file name if it already exists @@ -208,7 +208,7 @@ public class DefaultCallbackManager implements CallbackManager { if (!curExt.equals(downloadExt)) { try { String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt, - curExt, serviceConverter.generateRevisionId(downloadUri), null, false); // convert file and get url to a new file + curExt, serviceConverter.generateRevisionId(downloadUri), null, false, null); // convert file and get url to a new file if (newFileUri.isEmpty()) { newFileName = true; } else { diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java index ae8abd72..2bfd3500 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java @@ -107,7 +107,7 @@ public class DefaultServiceConverter implements ServiceConverter public String getConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, - String filePass, Boolean isAsync) + String filePass, Boolean isAsync, String lang) { fromExtension = fromExtension == null || fromExtension.isEmpty() ? fileUtility.getFileExtension(documentUri) : fromExtension; @@ -120,6 +120,7 @@ public class DefaultServiceConverter implements ServiceConverter documentRevisionId = generateRevisionId(documentRevisionId); // create document token Convert body = new Convert(); + body.setLang(lang); body.setUrl(documentUri); body.setOutputtype(toExtension.replace(".", "")); body.setFiletype(fromExtension.replace(".", "")); @@ -133,6 +134,7 @@ public class DefaultServiceConverter implements ServiceConverter if (jwtManager.tokenEnabled()) { HashMap map = new HashMap(); + map.put("region", lang); map.put("url", body.getUrl()); map.put("outputtype", body.getOutputtype()); map.put("filetype", body.getFiletype()); diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java index c62ef2ce..7d66af88 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java @@ -27,7 +27,7 @@ import java.io.InputStream; public interface ServiceConverter { String getConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, - String filePass, Boolean isAsync); + String filePass, Boolean isAsync, String lang); String generateRevisionId(String expectedKey); String convertStreamToString(InputStream stream); JSONObject convertStringToJSON(String jsonString); diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Convert.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Convert.java index 6a34300a..1a547bd4 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Convert.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Convert.java @@ -36,4 +36,5 @@ public class Convert { private String filePass; private Boolean async; private String token; + private String lang; } diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Converter.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Converter.java index 7be541b8..6829208f 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Converter.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/Converter.java @@ -31,4 +31,6 @@ public class Converter { private String fileName; @JsonProperty("filePass") private String filePass; + @JsonProperty("lang") + private String lang; } diff --git a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java index 72302102..488462bd 100644 --- a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java @@ -163,8 +163,8 @@ public class IndexServlet extends HttpServlet } // convert a file - private static void Convert(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) - { + private static void Convert(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) throws UnsupportedEncodingException { + CookieManager cm = new CookieManager(request); response.setContentType("text/plain"); try @@ -178,6 +178,7 @@ public class IndexServlet extends HttpServlet JSONObject body = (JSONObject) parser.parse(bodyString); String fileName = FileUtility.GetFileName((String) body.get("filename")); + String lang = cm.getCookie("ulang"); String filePass = body.get("filePass") != null ? (String) body.get("filePass") : null; String fileUri = DocumentManager.GetDownloadUrl(fileName); String fileExt = FileUtility.GetFileExtension(fileName); @@ -191,7 +192,7 @@ public class IndexServlet extends HttpServlet String key = ServiceConverter.GenerateRevisionId(fileUri); // get the url to the converted file - String newFileUri = ServiceConverter.GetConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true); + String newFileUri = ServiceConverter.GetConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true, lang); if (newFileUri.isEmpty()) { @@ -234,7 +235,6 @@ public class IndexServlet extends HttpServlet fileName = correctName; // create meta information about the converted file with the user id and name specified - CookieManager cm = new CookieManager(request); User user = Users.getUser(cm.getCookie("uid")); DocumentManager.CreateMeta(fileName, user.id, user.name, null); diff --git a/web/documentserver-example/java/src/main/java/helpers/ServiceConverter.java b/web/documentserver-example/java/src/main/java/helpers/ServiceConverter.java index d2f936bc..46e90fd2 100644 --- a/web/documentserver-example/java/src/main/java/helpers/ServiceConverter.java +++ b/web/documentserver-example/java/src/main/java/helpers/ServiceConverter.java @@ -45,6 +45,7 @@ public class ServiceConverter public static class ConvertBody { + public String region; public String url; public String outputtype; public String filetype; @@ -72,7 +73,7 @@ public class ServiceConverter } // get the url of the converted file - public static String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync) throws Exception + public static String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync, String lang) throws Exception { // check if the fromExtension parameter is defined; if not, get it from the document url fromExtension = fromExtension == null || fromExtension.isEmpty() ? FileUtility.GetFileExtension(documentUri) : fromExtension; @@ -87,6 +88,7 @@ public class ServiceConverter // write all the necessary parameters to the body object ConvertBody body = new ConvertBody(); + body.region = lang; body.url = documentUri; body.outputtype = toExtension.replace(".", ""); body.filetype = fromExtension.replace(".", ""); @@ -100,6 +102,7 @@ public class ServiceConverter if (DocumentManager.TokenEnabled()) { HashMap map = new HashMap(); + map.put("region", lang); map.put("url", body.url); map.put("outputtype", body.outputtype); map.put("filetype", body.filetype); diff --git a/web/documentserver-example/java/src/main/java/helpers/TrackManager.java b/web/documentserver-example/java/src/main/java/helpers/TrackManager.java index 65fa5329..746c643e 100644 --- a/web/documentserver-example/java/src/main/java/helpers/TrackManager.java +++ b/web/documentserver-example/java/src/main/java/helpers/TrackManager.java @@ -132,7 +132,7 @@ public class TrackManager { // convert downloaded file to the file with the current extension if these extensions aren't equal if (!curExt.equals(downloadExt)) { try { - String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false); // convert file and get url to a new file + String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false, null); // convert file and get url to a new file if (newFileUri.isEmpty()) { newFileName = DocumentManager.GetCorrectName(FileUtility.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress); // get the correct file name if it already exists } else { @@ -194,7 +194,7 @@ public class TrackManager { // convert downloaded file to the file with the current extension if these extensions aren't equal if (!curExt.equals(downloadExt)) { try { - String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false); // convert file and get url to a new file + String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false, null); // convert file and get url to a new file if (newFileUri.isEmpty()) { newFileName = true; } else { diff --git a/web/documentserver-example/php/functions.php b/web/documentserver-example/php/functions.php index be6ef5bf..8f19c3e9 100644 --- a/web/documentserver-example/php/functions.php +++ b/web/documentserver-example/php/functions.php @@ -119,7 +119,7 @@ function GenerateRevisionId($expected_key) { * * @return Document request result of conversion */ -function SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, $filePass) { +function SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, $filePass, $lang) { if (empty($from_extension)) { $path_parts = pathinfo($document_uri); @@ -148,7 +148,8 @@ function SendRequestToConvertService($document_uri, $from_extension, $to_extensi "filetype" => trim($from_extension, '.'), "title" => $title, "key" => $document_revision_id, - "password" => $filePass + "password" => $filePass, + "region" => $lang ]; // add header token @@ -200,9 +201,9 @@ function SendRequestToConvertService($document_uri, $from_extension, $to_extensi * * @return The percentage of completion of conversion */ -function GetConvertedUri($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, &$converted_document_uri, $filePass) { +function GetConvertedUri($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, &$converted_document_uri, $filePass, $lang) { $converted_document_uri = ""; - $responceFromConvertService = SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, $filePass); + $responceFromConvertService = SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async, $filePass, $lang); $json = json_decode($responceFromConvertService, true); // if an error occurs, then display an error message diff --git a/web/documentserver-example/php/webeditor-ajax.php b/web/documentserver-example/php/webeditor-ajax.php index 925e343d..caf54875 100644 --- a/web/documentserver-example/php/webeditor-ajax.php +++ b/web/documentserver-example/php/webeditor-ajax.php @@ -196,6 +196,7 @@ function convert() { $post = json_decode(file_get_contents('php://input'), true); $fileName = basename($post["filename"]); $filePass = $post["filePass"]; + $lang = $_COOKIE["ulang"]; $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); $internalExtension = trim(getInternalExtension($fileName),'.'); @@ -218,7 +219,7 @@ function convert() { try { // convert file and get the percentage of the conversion completion - $percent = GetConvertedUri($fileUri, $extension, $internalExtension, $key, TRUE, $newFileUri, $filePass); + $percent = GetConvertedUri($fileUri, $extension, $internalExtension, $key, TRUE, $newFileUri, $filePass, $lang); } catch (Exception $e) { $result["error"] = "error: " . $e->getMessage(); @@ -370,4 +371,4 @@ function delTree($dir) { return rmdir($dir); } -?> \ No newline at end of file +?> diff --git a/web/documentserver-example/python/src/utils/serviceConverter.py b/web/documentserver-example/python/src/utils/serviceConverter.py index a982e037..a892f5bd 100644 --- a/web/documentserver-example/python/src/utils/serviceConverter.py +++ b/web/documentserver-example/python/src/utils/serviceConverter.py @@ -31,7 +31,7 @@ import config from . import fileUtils, jwtManager # convert file and give url to a new file -def getConverterUri(docUri, fromExt, toExt, docKey, isAsync, filePass = None): +def getConverterUri(docUri, fromExt, toExt, docKey, isAsync, filePass = None, lang = None): if not fromExt: # check if the extension from the request matches the real file extension fromExt = fileUtils.getFileExt(docUri) # if not, overwrite the extension value @@ -43,7 +43,8 @@ def getConverterUri(docUri, fromExt, toExt, docKey, isAsync, filePass = None): 'filetype': fromExt.replace('.', ''), 'title': title, 'key': docKey, - 'password': filePass + 'password': filePass, + 'region': lang } headers={'accept': 'application/json'} diff --git a/web/documentserver-example/python/src/views/actions.py b/web/documentserver-example/python/src/views/actions.py index 1f9fd9c5..b0eaf05b 100644 --- a/web/documentserver-example/python/src/views/actions.py +++ b/web/documentserver-example/python/src/views/actions.py @@ -70,6 +70,7 @@ def convert(request): body = json.loads(request.body) filename = fileUtils.getFileName(body.get("filename")) filePass = body.get("filePass") + lang = request.COOKIES.get('ulang') if request.COOKIES.get('ulang') else 'en' fileUri = docManager.getDownloadUrl(filename,request) fileExt = fileUtils.getFileExt(filename) fileType = fileUtils.getFileType(filename) @@ -78,7 +79,7 @@ def convert(request): if docManager.isCanConvert(fileExt): # check if the file extension is available for converting key = docManager.generateFileKey(filename, request) # generate the file key - newUri = serviceConverter.getConverterUri(fileUri, fileExt, newExt, key, True, filePass) # get the url of the converted file + newUri = serviceConverter.getConverterUri(fileUri, fileExt, newExt, key, True, filePass, lang) # get the url of the converted file if not newUri: # if the converter url is not received, the original file name is passed to the response response.setdefault('step', '0') diff --git a/web/documentserver-example/ruby/app/controllers/home_controller.rb b/web/documentserver-example/ruby/app/controllers/home_controller.rb index 0156eb7c..c264552c 100644 --- a/web/documentserver-example/ruby/app/controllers/home_controller.rb +++ b/web/documentserver-example/ruby/app/controllers/home_controller.rb @@ -96,6 +96,7 @@ class HomeController < ApplicationController body = JSON.parse(file_data) file_name = File.basename(body["filename"]) + lang = cookies[:ulang] ? cookies[:ulang] : "en" file_pass = body["filePass"] ? body["filePass"] : nil file_uri = DocumentHelper.get_download_url(file_name) extension = File.extname(file_name).downcase @@ -103,7 +104,7 @@ class HomeController < ApplicationController if DocumentHelper.convert_exts.include? (extension) # check if the file with such an extension can be converted key = ServiceConverter.generate_revision_id(file_uri) # generate document key - percent, new_file_uri = ServiceConverter.get_converted_uri(file_uri, extension.delete('.'), internal_extension.delete('.'), key, true, file_pass) # get the url of the converted file and the conversion percentage + percent, new_file_uri = ServiceConverter.get_converted_uri(file_uri, extension.delete('.'), internal_extension.delete('.'), key, true, file_pass, lang) # get the url of the converted file and the conversion percentage # if the conversion isn't completed, write file name and step values to the response if percent != 100 diff --git a/web/documentserver-example/ruby/app/models/service_converter.rb b/web/documentserver-example/ruby/app/models/service_converter.rb index ea331226..6a0e20ee 100644 --- a/web/documentserver-example/ruby/app/models/service_converter.rb +++ b/web/documentserver-example/ruby/app/models/service_converter.rb @@ -22,7 +22,7 @@ class ServiceConverter class << self # get the url of the converted file - def get_converted_uri(document_uri, from_ext, to_ext, document_revision_id, is_async, file_pass) + def get_converted_uri(document_uri, from_ext, to_ext, document_revision_id, is_async, file_pass, lang = nil) from_ext = from_ext == nil ? File.extname(document_uri).downcase : from_ext # get the current document extension @@ -41,7 +41,8 @@ class ServiceConverter :filetype => from_ext.delete('.'), :title => title, :key => document_revision_id, - :password => file_pass + :password => file_pass, + :region => lang } data = nil