gridjs-spreadsheet 25.3.0 → 25.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/example/Dockerfile +10 -7
  2. package/example/pom.xml +2 -2
  3. package/example/src/main/java/com/aspose/gridjs/demo/GridjsdemoApplication.java +15 -14
  4. package/example/src/main/java/com/aspose/gridjs/demo/MyConfig.java +31 -0
  5. package/example/src/main/java/com/aspose/gridjs/demo/controller/GridJs2Controller.java +38 -401
  6. package/example/src/main/resources/application.properties +3 -7
  7. package/example/src/main/resources/static/xspread/content/img/20130527034914143.gif +0 -0
  8. package/example/src/main/resources/static/xspread/content/img/20130527034914229.gif +0 -0
  9. package/example/src/main/resources/static/xspread/content/img/20130527034916363.gif +0 -0
  10. package/example/src/main/resources/static/xspread/content/img/20130527034917946.gif +0 -0
  11. package/example/src/main/resources/static/xspread/content/img/20130527034918372.gif +0 -0
  12. package/example/src/main/resources/templates/fileFromUpload.html +18 -19
  13. package/example/src/main/resources/templates/index.html +2 -2
  14. package/package.json +1 -1
  15. package/preview.gif +0 -0
  16. package/readme.md +53 -4
  17. package/xspreadsheet.css +51 -3
  18. package/xspreadsheet.js +5 -5
  19. package/2922578eabb1a88d1974da56c65189ba.svg +0 -907
  20. package/9ab1b217edd126e8925e88cc8f25a154.svg +0 -88
  21. /package/{example/src/main/resources/static/xspread/555f60323063f2b68b6eac7ce9c45b19.svg → 555f60323063f2b68b6eac7ce9c45b19.svg} +0 -0
  22. /package/{example/src/main/resources/static/xspread/a3b683289420fd8ec937908397907279.svg → a3b683289420fd8ec937908397907279.svg} +0 -0
@@ -1,30 +1,33 @@
1
1
  FROM maven:3.8.6-amazoncorretto-17 AS build
2
- # 设置工作目录
2
+ # ���ù���Ŀ¼
3
3
  WORKDIR /usr/src/app
4
4
 
5
- # 将本地的 Maven 设置文件和环境变量设置文件复制到容器中
5
+
6
+
7
+
8
+ # �����ص� Maven �����ļ��ͻ������������ļ����Ƶ�������
6
9
  COPY .mvn .mvn
7
10
  COPY pom.xml .
8
11
  COPY src src
9
-
12
+
10
13
  RUN ls -l *
11
- # 使用 Maven 构建应用
14
+ # ʹ�� Maven ����Ӧ��
12
15
  RUN mvn package -DskipTests
13
16
 
14
17
  FROM eclipse/ubuntu_jdk8
15
18
  WORKDIR /app
16
- # 将构建的 jar 文件复制到新的容器中
19
+ # �������� jar �ļ����Ƶ��µ�������
17
20
  COPY --from=build /usr/src/app/target/*.jar /app/app.jar
18
21
 
19
22
 
20
23
  # web port
21
24
  EXPOSE 8080
22
- # Install Fonts because the SDK image contains very few fonts. The command copies font files from local to docker image. Make sure you have a local fonts directory that contains all the fonts you need to install. In this example, the local fonts directory is put in the same directory as the Dockerfile.
25
+ # Install Fonts because the SDK image contains very few fonts. The command copies font files from local to docker image. Make sure you have a local ��fonts�� directory that contains all the fonts you need to install. In this example, the local ��fonts�� directory is put in the same directory as the Dockerfile.
23
26
  # COPY fonts/* /usr/share/fonts/
24
27
  RUN mkdir -p /app/wb
25
28
  RUN mkdir -p /app/grid_cache/streamcache
26
29
  RUN mkdir -p /app/upload
27
30
  COPY wb/*.xlsx /app/wb/
28
31
  # RUN ls -l /app/
29
- # 启动应用
32
+ # ����Ӧ��
30
33
  ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]
package/example/pom.xml CHANGED
@@ -51,12 +51,12 @@
51
51
  <dependency>
52
52
  <groupId>com.aspose</groupId>
53
53
  <artifactId>aspose-cells</artifactId>
54
- <version>25.3</version>
54
+ <version>25.4</version>
55
55
  </dependency>
56
56
  <dependency>
57
57
  <groupId>com.aspose</groupId>
58
58
  <artifactId>aspose-cells</artifactId>
59
- <version>25.3</version>
59
+ <version>25.4</version>
60
60
  <classifier>gridjs</classifier>
61
61
  </dependency>
62
62
  <!-- <dependency>
@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
5
5
  import org.springframework.boot.autoconfigure.SpringBootApplication;
6
6
  import org.springframework.stereotype.Component;
7
7
  import org.springframework.context.ApplicationContext;
8
+ import org.springframework.context.annotation.ComponentScan;
8
9
 
9
10
  import com.aspose.cells.Workbook;
10
11
  import com.aspose.gridjs.Config;
@@ -15,19 +16,19 @@ import java.io.File;
15
16
  import javax.annotation.PostConstruct;
16
17
 
17
18
 
18
- @Component
19
- class MyConfig {
20
-
21
- @Value("${testconfig.CachePath}")
22
- public String cachePath;
23
-
24
-
25
- @Value("${testconfig.AsposeLicensePath}")
26
- public String asposeLicensePath;
27
-
28
-
29
- }
30
-
19
+ //@Component
20
+ //class MyConfig {
21
+ //
22
+ // @Value("${testconfig.CachePath}")
23
+ // public String cachePath;
24
+ //
25
+ //
26
+ // @Value("${testconfig.AsposeLicensePath}")
27
+ // public String asposeLicensePath;
28
+ //
29
+ //
30
+ //}
31
+ @ComponentScan(basePackages = {"com.aspose.gridjs.demo", "com.aspose.gridjs"})
31
32
  @SpringBootApplication
32
33
  public class GridjsdemoApplication {
33
34
 
@@ -88,7 +89,7 @@ public class GridjsdemoApplication {
88
89
  if ((new File(myConfig.asposeLicensePath)).exists()) {
89
90
  lic.setLicense(myConfig.asposeLicensePath);
90
91
  }
91
- init(myConfig);
92
+ // init(myConfig);
92
93
 
93
94
  }
94
95
 
@@ -0,0 +1,31 @@
1
+ package com.aspose.gridjs.demo;
2
+
3
+ import org.springframework.beans.factory.annotation.Value;
4
+ import org.springframework.context.annotation.Bean;
5
+ import org.springframework.context.annotation.Configuration;
6
+
7
+ import com.aspose.gridjs.GridJsOptions;
8
+ import com.aspose.gridjs.GridJsService;
9
+ import com.aspose.gridjs.IGridJsService;
10
+
11
+ @Configuration
12
+ public class MyConfig {
13
+ @Value("${testconfig.CachePath}")
14
+ public String cachePath;
15
+
16
+
17
+ @Value("${testconfig.AsposeLicensePath}")
18
+ public String asposeLicensePath;
19
+
20
+ @Bean
21
+ public GridJsOptions gridJsOptions() {
22
+ GridJsOptions options=new GridJsOptions();
23
+ options.setFileCacheDirectory(cachePath);
24
+ return options;
25
+ }
26
+
27
+ @Bean
28
+ public IGridJsService gridJsService(GridJsOptions gridJsOptions) throws Exception {
29
+ return new GridJsService(gridJsOptions);
30
+ }
31
+ }
@@ -14,6 +14,7 @@ import java.util.concurrent.ExecutorService;
14
14
  import java.util.concurrent.Executors;
15
15
  import java.util.zip.GZIPOutputStream;
16
16
 
17
+ import org.springframework.beans.factory.annotation.Autowired;
17
18
  import org.springframework.beans.factory.annotation.Value;
18
19
  import org.springframework.core.io.InputStreamResource;
19
20
  import org.springframework.http.HttpHeaders;
@@ -35,7 +36,9 @@ import com.aspose.cells.Workbook;
35
36
  import com.aspose.gridjs.Config;
36
37
  import com.aspose.gridjs.GridCellException;
37
38
  import com.aspose.gridjs.GridInterruptMonitor;
39
+ import com.aspose.gridjs.GridJsControllerBase;
38
40
  import com.aspose.gridjs.GridJsWorkbook;
41
+ import com.aspose.gridjs.IGridJsService;
39
42
 
40
43
  import javax.servlet.http.HttpServletRequest;
41
44
  import javax.servlet.http.HttpServletResponse;
@@ -43,26 +46,26 @@ import javax.servlet.http.Part;
43
46
 
44
47
  @RestController
45
48
  @RequestMapping({"/GridJs2"})
46
- public class GridJs2Controller {
49
+ public class GridJs2Controller extends GridJsControllerBase{
47
50
  @Value("${testconfig.ListDir}")
48
51
  private String listDir;//="D:\\codebase\\customerissue\\wb\\tempfromdownload\\";
49
52
 
50
53
 
54
+ // IGridJsService
55
+ @Autowired
56
+ public GridJs2Controller(IGridJsService gridJsService) {
57
+ super(gridJsService);
58
+ }
59
+
51
60
 
52
61
  @GetMapping("/DetailFileJsonWithUid")
53
62
  public ResponseEntity<String> detailFileJsonWithUid(@RequestParam String filename, @RequestParam String uid) {
54
63
  try {
55
64
 
56
65
  Path filePath = Paths.get(listDir, filename);
57
- GridJsWorkbook wbj = new GridJsWorkbook();
58
66
 
59
67
  // Check if already in cache
60
- StringBuilder sb = wbj.getJsonByUid(uid, filename);
61
- if (sb == null) {
62
- Workbook wb = new Workbook(filePath.toString());
63
- wbj.importExcelFile(uid, wb);
64
- sb = wbj.exportToJsonStringBuilder(filename);
65
- }
68
+ StringBuilder sb = _gridJsService.detailFileJsonWithUid( filePath.toString(), uid);
66
69
 
67
70
  // Return the content as plain text with UTF-8 encoding
68
71
  return ResponseEntity.ok()
@@ -78,17 +81,12 @@ public class GridJs2Controller {
78
81
 
79
82
 
80
83
  Path filePath = Paths.get(listDir, filename);
81
- GridJsWorkbook wbj = new GridJsWorkbook();
84
+
82
85
 
83
86
  response.setContentType("application/json");
84
87
  response.setHeader("Content-Encoding", "gzip");
85
88
  try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
86
- boolean isdone= wbj.jsonToStreamByUid(gzipOutputStream,uid, filename);
87
- if (!isdone) {
88
- Workbook wb = new Workbook(filePath.toString());
89
- wbj.importExcelFile(uid,wb);
90
- wbj.jsonToStream(gzipOutputStream, filename);
91
- }
89
+ _gridJsService.detailStreamJsonWithUid(gzipOutputStream, filePath.toString(), uid);
92
90
  } catch (IOException e) {
93
91
  // TODO Auto-generated catch block
94
92
  e.printStackTrace();
@@ -107,452 +105,91 @@ public class GridJs2Controller {
107
105
 
108
106
 
109
107
  Path filePath = Paths.get(uploadDir, filename);
110
- GridJsWorkbook wbj = new GridJsWorkbook();
108
+
111
109
 
112
110
  response.setContentType("application/json");
113
111
  response.setHeader("Content-Encoding", "gzip");
114
112
  try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
115
- boolean isdone= wbj.jsonToStreamByUid(gzipOutputStream,uid, filename);
116
- if (!isdone) {
117
- Workbook wb = new Workbook(filePath.toString());
118
- wbj.importExcelFile(uid,wb);
119
- wbj.jsonToStream(gzipOutputStream, filename);
120
- }
121
- } catch (IOException e) {
122
- // TODO Auto-generated catch block
123
- e.printStackTrace();
113
+ _gridJsService.detailStreamJsonWithUid(gzipOutputStream, filePath.toString(), uid);
114
+
124
115
  } catch (Exception e) {
125
116
  // TODO Auto-generated catch block
126
117
  e.printStackTrace();
127
118
  }
128
119
  }
129
120
 
130
- @PostMapping("/LazyLoading")
121
+ @PostMapping("/LazyLoadingStreamJson")
131
122
  public void lazyLoadingStreamJson(
132
123
  @RequestParam(value = "name", required = false) String sheetName,
133
124
  @RequestParam(value = "uid", required = false) String uid,
134
125
  HttpServletResponse response) throws IOException {
135
126
 
136
- GridJsWorkbook wbj = new GridJsWorkbook();
137
127
 
138
- // 设置响应头
139
- response.setContentType(MediaType.APPLICATION_JSON_VALUE);
140
- response.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
128
+ super.lazyLoadingStreamJson(sheetName,uid,response);
141
129
 
142
- try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
143
- try {
144
- wbj.lazyLoadingStream(gzipOutputStream, uid, sheetName);
145
- } catch (Exception e) {
146
- // TODO Auto-generated catch block
147
- e.printStackTrace();
148
- }
149
- }
150
130
  }
151
131
 
152
132
  @PostMapping("/UpdateCell")
153
133
  public ResponseEntity<String> updateCell(HttpServletRequest request) {
154
- String p = request.getParameter("p");
155
- String uid = request.getParameter("uid");
156
- GridJsWorkbook gwb = new GridJsWorkbook();
157
- String ret;
158
- try {
159
- ret = gwb.updateCell(p, uid);
160
- return new ResponseEntity<>(ret, HttpStatus.OK);
161
- } catch (Exception e) {
162
- // TODO Auto-generated catch block
163
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
164
- }
165
-
166
- }
167
-
168
- @PostMapping("/AddImage_FAIL")
169
- public ResponseEntity<String> addImageFail(HttpServletRequest request) {
170
- String uid = request.getParameter("uid");
171
- String p = request.getParameter("p");
172
- String isControl = request.getParameter("control");
173
- String ret = null;
174
- GridJsWorkbook gwb = new GridJsWorkbook();
175
134
  try {
176
- if (isControl == null) {
177
- Part filePart = request.getPart("image"); // Retrieves <input type="file" name="file">
178
- if (filePart == null || filePart.getSize() == 0) {
179
- // for add shape,need to set p.type as one of AutoShapeType
180
- ret = gwb.insertImage(uid, p, null, null);
181
-
182
- } else {
183
- try (InputStream inputStream = filePart.getInputStream()) {
184
- ret = gwb.insertImage(uid, p, inputStream, null);
185
- } catch (IOException e) {
186
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
187
- }
188
- }
189
- } else {
190
- ret = gwb.insertImage(uid, p, null, null);
191
- }
192
- return new ResponseEntity<>(ret, HttpStatus.OK);
193
- } catch (Exception e) {
194
- // TODO Auto-generated catch block
195
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
135
+ return super.updateCell(request);
136
+ }catch(Exception e)
137
+ {
138
+ e.printStackTrace();
139
+ return null;
196
140
  }
197
141
  }
198
142
 
199
143
  @PostMapping("/AddImage")
200
- public ResponseEntity<String> handleFileUpload(@RequestParam(value = "image", required = false) MultipartFile file,
144
+ public ResponseEntity<String> addImage(
145
+ @RequestParam(value = "image", required = false) MultipartFile file,
201
146
  @RequestParam("uid") String uid,
202
147
  @RequestParam("p") String p,
203
148
  @RequestParam(value = "control", required = false) String isControl) {
204
- String ret = null;
205
- GridJsWorkbook gwb = new GridJsWorkbook();
206
- try {
207
- if (isControl == null) {
208
- if (file != null && !file.isEmpty()) {
209
- try (InputStream inputStream = file.getInputStream()) {
210
- // Files.copy(inputStream, Paths.get("D:\\tmpdel\\tmp\\gridjsjava\\upload\\123.png"));
211
- ret = gwb.insertImage(uid, p, inputStream, null);
212
149
 
213
- } catch (IOException e) {
214
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
215
- }
216
-
217
-
218
- } else {
219
- // for add shape,need to set p.type as one of AutoShapeType
220
- ret = gwb.insertImage(uid, p, null, null);
221
-
222
- }
223
- } else {
224
- ret = gwb.insertImage(uid, p, null, null);
225
- }
226
-
227
- return new ResponseEntity<>(ret, HttpStatus.OK);
228
- } catch (Exception e) {
229
- e.printStackTrace();
230
- return ResponseEntity.internalServerError().body("Error occurred while uploading file");
231
- }
150
+ return super.addImage(file,uid,p,isControl);
232
151
  }
233
152
 
234
153
  @PostMapping("/CopyImage")
235
154
  public ResponseEntity<String> copyImage(HttpServletRequest request) {
236
- String uid = request.getParameter("uid");
237
- String p = request.getParameter("p");
238
- GridJsWorkbook gwb = new GridJsWorkbook();
239
- try {
240
- String ret = gwb.copyImageOrShape(uid, p);
241
-
242
- return new ResponseEntity<>(ret, HttpStatus.OK);
243
- } catch (Exception e) {
244
- // TODO Auto-generated catch block
245
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
246
- }
155
+ return super.copyImage(request);
247
156
  }
248
157
 
249
- private static InputStream getStreamFromUrl(String url) throws IOException {
250
- URL imageUrl = new URL(url);
251
- URLConnection connection = imageUrl.openConnection();
252
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
253
- byte[] buffer = new byte[1024];
254
- int bytesRead;
255
- try (InputStream in = connection.getInputStream()) {
256
- while ((bytesRead = in.read(buffer)) != -1) {
257
- baos.write(buffer, 0, bytesRead);
258
- }
259
- }
260
- return new ByteArrayInputStream(baos.toByteArray());
261
- }
262
158
 
263
159
  @PostMapping("/AddImageByURL")
264
160
  public ResponseEntity<String> addImageByUrl(HttpServletRequest request) {
265
- String uid = request.getParameter("uid");
266
- String p = request.getParameter("p");
267
- String imageUrl = request.getParameter("imageurl");
268
- String ret = null;
269
- GridJsWorkbook gwb = new GridJsWorkbook();
270
- try {
271
- if (imageUrl != null) {
272
- try (InputStream stream = getStreamFromUrl(imageUrl)) {
273
- ret = gwb.insertImage(uid, p, stream, imageUrl);
274
- } catch (IOException e) {
275
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
276
- }
277
- } else {
278
- return new ResponseEntity<>(gwb.errorJson("image url is null"), HttpStatus.BAD_REQUEST);
279
- }
280
-
281
- return new ResponseEntity<>(ret, HttpStatus.OK);
282
- } catch (Exception e) {
283
- // TODO Auto-generated catch block
284
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
285
- }
161
+ return super.addImageByUrl(request);
286
162
  }
287
163
 
288
164
  @GetMapping("/Image")
289
165
  public ResponseEntity<InputStreamResource> getImage(HttpServletRequest request) {
290
- String fileId = request.getParameter("id");
291
- String uid = request.getParameter("uid");
292
- try {
293
- InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
294
- if (imageStream == null) {
295
- return ResponseEntity.notFound().build();
296
- }
297
-
298
- return ResponseEntity.ok()
299
- .contentType(MediaType.IMAGE_PNG)
300
- .body(new InputStreamResource(imageStream));
301
- } catch (Exception e) {
302
- e.printStackTrace();
303
- return ResponseEntity.notFound().build();
304
- }
305
- }
306
- /*
307
- @GetMapping("/ImageTest")
308
- public ResponseEntity<InputStreamResource> getImageTest(HttpServletRequest request) {
309
- try {
310
- // Load the image file from the classpath (resources folder)
311
- String fileId = request.getParameter("id");
312
- String uid = request.getParameter("uid");
313
-
314
- InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
315
- if (imageStream == null) {
316
- return ResponseEntity.notFound().build();
317
- }
318
-
319
- // Set the headers for the response
320
- HttpHeaders headers = new HttpHeaders();
321
- headers.add("Content-Type", "image/jpeg");
322
-
323
- // Return the InputStreamResource with the headers
324
- return ResponseEntity
325
- .ok()
326
- .headers(headers)
327
- .body(new InputStreamResource(imageStream));
328
- } catch (Exception e) {
329
- e.printStackTrace();
330
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
331
- }
332
- }
333
-
334
- @GetMapping("/PImage")
335
- public ResponseEntity<InputStreamResource> getPImage(HttpServletRequest request) {
336
- String fileId = request.getParameter("id");
337
- String uid = request.getParameter("uid");
338
- try {
339
- InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
340
- if (imageStream == null) {
341
- return ResponseEntity.notFound().build();
342
- }
343
- InputStreamResource resource = new InputStreamResource(imageStream);
344
- MediaType mediaType = MediaType.IMAGE_PNG;
345
- return ResponseEntity.ok()
346
- .contentType(mediaType)
347
- .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + fileId + "\"")
348
- .body(resource);
349
- } catch (Exception e) {
350
- e.printStackTrace();
351
- return ResponseEntity.notFound().build();
352
- }
353
- }
354
-
355
- @GetMapping("/pimages/{imageName}")
356
- public ResponseEntity<InputStreamResource> getImage(@PathVariable("imageName") String imageName) {
357
- try {
358
- // Read the image file
359
- FileInputStream fis = new FileInputStream("C:\\Users\\peter\\Pictures\\test\\" + imageName);
360
- InputStreamResource resource = new InputStreamResource(fis);
361
-
362
- // Set the content type based on the image type (JPEG, PNG, etc.)
363
- MediaType mediaType = MediaType.IMAGE_JPEG; // Change this based on your image type
364
-
365
- // Create the response entity with the appropriate headers
366
- return ResponseEntity.ok()
367
- .contentType(mediaType)
368
- .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + imageName + "\"")
369
- .body(resource);
370
- } catch (IOException e) {
371
- // Handle the exception, e.g., log it
372
- e.printStackTrace();
373
- return ResponseEntity.notFound().build();
374
- }
375
- }
376
- */
377
-
378
- @GetMapping("/Ole")
379
- public ResponseEntity<?> getOle(HttpServletRequest request) {
380
- int oleId = Integer.parseInt(request.getParameter("id"));
381
- String uid = request.getParameter("uid");
382
- String sheet = request.getParameter("sheet");
383
-
384
- GridJsWorkbook gwb = new GridJsWorkbook();
385
- String[] filename = new String[1];
386
- try {
387
- byte[] fileByte = gwb.getOle(uid, sheet, oleId, filename);
388
-
389
- if (filename != null) {
390
- return ResponseEntity.ok()
391
- .contentType( (getMimeType(filename[0])))
392
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename[0] + "\"")
393
- .body(fileByte);
394
- } else {
395
- return ResponseEntity.notFound().build();
396
- }
397
- } catch (Exception e) {
398
- // TODO Auto-generated catch block
399
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
400
- }
166
+ return super.getImage(request);
401
167
  }
402
168
 
403
169
 
404
170
  @GetMapping("/ImageUrl")
405
171
  public ResponseEntity<String> getImageUrl(@RequestParam String id, @RequestParam String uid) {
406
- if (GridJsWorkbook.CacheImp != null) {
407
- return ResponseEntity.ok(GridJsWorkbook.getImageUrl(uid, id, "."));
408
- } else {
409
- String file = uid + "." + id;
410
- return ResponseEntity.ok("/GridJs2/GetZipFile?f=" + file);
411
- }
412
- }
413
-
414
- @GetMapping("/GetZipFile")
415
- public ResponseEntity<StreamingResponseBody> getZipFile(@RequestParam String f) {
416
- Path filePath = Paths.get(Config.getFileCacheDirectory(), f);
417
-
418
- if (!Files.exists(filePath)) {
419
- return ResponseEntity.notFound().build();
420
- }
421
-
422
- StreamingResponseBody responseBody = outputStream -> {
423
- try (InputStream inputStream = Files.newInputStream(filePath)) {
424
- byte[] buffer = new byte[1024];
425
- int bytesRead;
426
- while ((bytesRead = inputStream.read(buffer)) != -1) {
427
- outputStream.write(buffer, 0, bytesRead);
428
- }
429
- }
430
- };
431
-
432
- return ResponseEntity.ok()
433
- .contentType(MediaType.APPLICATION_OCTET_STREAM)
434
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + f + "\"")
435
- .body(responseBody);
172
+ return super.getImageUrl(id, uid);
436
173
  }
437
174
 
438
- public static MediaType getMimeType(String fileName) {
439
- Path filePath = Paths.get(fileName);
440
- try {
441
- // Probe the content type of the file
442
- String mimeType = Files.probeContentType(filePath);
443
-
444
- // If the MIME type couldn't be determined, default to binary
445
- if (mimeType == null) {
446
- mimeType = "application/octet-stream";
447
- }
448
-
449
- // Parse and return the MediaType
450
- return MediaType.parseMediaType(mimeType);
451
-
452
- } catch (IOException e) {
453
- e.printStackTrace();
454
- // Return a default MediaType in case of an error
455
- return MediaType.APPLICATION_OCTET_STREAM;
456
- }
175
+ @GetMapping("/Ole")
176
+ public ResponseEntity<?> getOle(HttpServletRequest request) {
177
+ return super.getOle(request);
457
178
  }
458
179
 
459
180
  @GetMapping("/GetFile")
460
- public ResponseEntity<byte[]> getFile(@RequestParam("id") String fileid,@RequestParam("filename") String filename) throws IOException {
461
-
462
- MediaType mimeType = getMimeType(filename);
463
-
464
- // try {
465
- // TimeUnit.SECONDS.sleep(3); // simulate network lag
466
- // } catch (InterruptedException e) {
467
- // Thread.currentThread().interrupt();
468
- // }
469
- Path filePath = Paths.get(Config.getFileCacheDirectory(), fileid.replace('/', '.')+"."+filename);
470
- byte[] bytes = Files.readAllBytes(filePath);
471
- return ResponseEntity.ok()
472
- .contentType(mimeType)
473
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
474
- .body(bytes);
475
- }
476
-
477
-
478
- //this is for the way that implment GridCacheForStream
479
- @GetMapping("/GetFileUseCacheStream")
480
- public ResponseEntity<InputStreamResource> getFileUseCacheStream(@RequestParam("id") String fileid) throws IOException {
481
-
482
- MediaType mimeType = getMimeType(fileid);
483
- String name = fileid.replace('/', '.');
484
-
485
-
486
- InputStream inputStream = GridJsWorkbook.CacheImp.loadStream(fileid);
487
- if (inputStream == null) {
488
- // Handle the case where the file is not found
489
- return ResponseEntity.notFound().build();
181
+ public ResponseEntity<?> getFile(@RequestParam("id") String id) {
182
+ return super.getFile(id);
490
183
  }
491
184
 
492
- HttpHeaders headers = new HttpHeaders();
493
- headers.setContentType(mimeType);
494
- headers.setContentDispositionFormData("attachment", name);
495
-
496
- return ResponseEntity.ok()
497
- .headers(headers)
498
- .body(new InputStreamResource(inputStream));
499
-
185
+ @PostMapping("/Download")
186
+ public ResponseEntity<String> download(HttpServletRequest request) {
187
+ return super.download(request);
500
188
  }
501
189
 
502
190
 
503
191
 
504
- private static void InterruptMonitor(GridInterruptMonitor monitor,int milliseconds)
505
- {
506
192
 
507
- try
508
- {
509
- Thread.sleep(milliseconds);
510
-
511
- (monitor).interrupt();
512
- }
513
- catch (Exception e)
514
- {
515
- System.out.println("Succeeded for load in give time.");
516
- }
517
- }
518
-
519
- @PostMapping("/Download")
520
- public ResponseEntity<String> download(HttpServletRequest request) {
521
- String p = request.getParameter("p");
522
- String uid = request.getParameter("uid");
523
- String filename = request.getParameter("file");
524
-
525
- GridJsWorkbook gwb = new GridJsWorkbook();
526
- try {
527
- gwb.mergeExcelFileFromJson(uid, p);
528
-
529
- GridInterruptMonitor m = new GridInterruptMonitor();
530
- gwb.setInterruptMonitorForSave(m);
531
-
532
- ExecutorService executor = Executors.newSingleThreadExecutor();
533
- executor.submit(() -> InterruptMonitor(m, 30 * 1000));
534
-
535
- try {
536
- gwb.saveToCacheWithFileName(uid, filename, null);
537
- } catch (Exception ex) {
538
- if (ex instanceof GridCellException) {
539
- return ResponseEntity
540
- .ok(((GridCellException) ex).getMessage() + ((GridCellException) ex).getCode());
541
- }
542
- }
543
-
544
- String fileUrl = null;
545
- if (GridJsWorkbook.CacheImp != null) {
546
- fileUrl = GridJsWorkbook.CacheImp.getFileUrl(uid + "/" + filename);
547
- } else {
548
- fileUrl = "/GridJs2/GetFile?id=" + uid + "&filename=" + filename;
549
- }
550
- return ResponseEntity.ok("\""+fileUrl+"\"");
551
- } catch (Exception e) {
552
- // TODO Auto-generated catch block
553
- return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
554
- }
555
- }
556
193
 
557
194
 
558
195
  }