Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 0c657ad

Browse files
authored
Merge pull request #56 from groupdocs-viewer/update_viewer_to_v20_7
Updated GroupDocs.Viewer to v20.7 and Angular Viewer UI to v0.8.15
2 parents 75150f9 + 75753f4 commit 0c657ad

35 files changed

+1263
-579
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@angular/platform-browser": "^8.2.14",
3737
"@angular/platform-browser-dynamic": "^8.2.14",
3838
"@angular/router": "^8.2.14",
39-
"@groupdocs.examples.angular/viewer": "^0.5.5",
39+
"@groupdocs.examples.angular/viewer": "^0.8.15",
4040
"@nrwl/angular": "^8.8.2",
4141
"core-js": "^2.5.4",
4242
"rxjs": "~6.4.0",

configuration.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ viewer:
8787
# Print secured documents mode
8888
# Set false to ignore document print security
8989
# Set true to check document print security
90-
printAllowed: true
90+
printAllowed: true
91+
# Set true to show grid lines
92+
showGridLines: true
93+
# Set cache folder name
94+
cacheFolderName: cache

pom.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.groupdocs.ui</groupId>
88
<artifactId>viewer-spring</artifactId>
9-
<version>1.14.32</version>
9+
<version>1.14.33</version>
1010
<packaging>${packaging.type}</packaging>
1111

1212
<name>GroupDocs.Viewer for Java Spring Sample</name>
@@ -128,17 +128,26 @@
128128
<artifactId>spring-boot-starter-thymeleaf</artifactId>
129129
<version>2.0.4.RELEASE</version>
130130
</dependency>
131-
131+
<dependency>
132+
<groupId>com.fasterxml.jackson.core</groupId>
133+
<artifactId>jackson-databind</artifactId>
134+
<version>2.9.4</version>
135+
</dependency>
132136
<dependency>
133137
<groupId>commons-io</groupId>
134138
<artifactId>commons-io</artifactId>
135139
<version>2.6</version>
136140
</dependency>
141+
<dependency>
142+
<groupId>org.apache.commons</groupId>
143+
<artifactId>commons-lang3</artifactId>
144+
<version>3.4</version>
145+
</dependency>
137146

138147
<dependency>
139148
<groupId>com.groupdocs</groupId>
140149
<artifactId>groupdocs-viewer</artifactId>
141-
<version>19.8.1</version>
150+
<version>20.7</version>
142151
<type>jar</type>
143152
</dependency>
144153

src/main/java/com/groupdocs/ui/Application.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public static void main(String[] args) {
3434
SpringApplication.run(Application.class, args);
3535
}
3636

37-
@Override
38-
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
39-
return application.sources(Application.class);
40-
}
41-
4237
@Bean
4338
public static PropertySourcesPlaceholderConfigurer properties() {
4439
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
@@ -68,9 +63,15 @@ public static YamlPropertiesFactoryBean getYamlPropertiesFactoryBean() {
6863
return propertiesFactoryBean;
6964
}
7065

66+
@Override
67+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
68+
return application.sources(Application.class);
69+
}
70+
7171
/**
7272
* Configure CORS parameters
73-
* @return
73+
*
74+
* @return Web Mvc configurer
7475
*/
7576
@Bean
7677
public WebMvcConfigurer corsConfigurer() {

src/main/java/com/groupdocs/ui/ApplicationStartup.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public class ApplicationStartup implements ApplicationListener<WebServerInitiali
1818
/**
1919
* This method is called during Spring's startup.
2020
*
21-
* @param event Event raised when an ApplicationContext gets initialized or
22-
* refreshed.
21+
* @param event Event raised when an ApplicationContext gets initialized or refreshed.
2322
*/
2423
public void onApplicationEvent(WebServerInitializedEvent event) {
2524
// use this event for obtaining the local port of a running server
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
package com.groupdocs.ui.cache;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
5+
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
6+
import com.groupdocs.ui.cache.mixin.PageMixIn;
7+
import com.groupdocs.ui.cache.mixin.PdfViewInfoMixIn;
8+
import com.groupdocs.ui.cache.mixin.ViewInfoMixIn;
9+
import com.groupdocs.ui.exception.DiskAccessException;
10+
import com.groupdocs.viewer.results.Page;
11+
import com.groupdocs.viewer.results.PdfViewInfo;
12+
import com.groupdocs.viewer.results.ViewInfo;
13+
import com.groupdocs.viewer.utils.PathUtils;
14+
import org.apache.commons.io.IOUtils;
15+
16+
import java.io.*;
17+
18+
public class FileViewerCache implements ViewerCache {
19+
private static final ObjectMapper MAPPER = new ObjectMapper();
20+
private static final long WAIT_TIMEOUT = 100L;
21+
22+
static {
23+
MAPPER.addMixIn(ViewInfo.class, ViewInfoMixIn.class);
24+
MAPPER.addMixIn(PdfViewInfo.class, PdfViewInfoMixIn.class);
25+
MAPPER.addMixIn(Page.class, PageMixIn.class);
26+
}
27+
28+
/**
29+
* Gets the Relative or absolute path to the cache folder.
30+
*/
31+
public String mCachePath;
32+
/**
33+
* Gets the sub-folder to append to the CachePath.
34+
*/
35+
public String mCacheSubFolder;
36+
37+
/**
38+
* Initializes a new instance of the FileViewerCache class.
39+
*
40+
* @param cachePath or absolute path where document cache will be stored.
41+
* @param cacheSubFolder sub-folder to append to cachePath.
42+
*/
43+
public FileViewerCache(String cachePath, String cacheSubFolder) {
44+
if (cachePath == null) {
45+
throw new IllegalArgumentException("cachePath");
46+
}
47+
48+
if (cacheSubFolder == null) {
49+
throw new IllegalArgumentException("cacheSubFolder");
50+
}
51+
52+
this.mCachePath = cachePath;
53+
this.mCacheSubFolder = cacheSubFolder;
54+
}
55+
56+
/**
57+
* Serializes data to the local disk.
58+
*
59+
* @param key An unique identifier for the cache entry.
60+
* @param value The object to serialize.
61+
*/
62+
@Override
63+
public void set(String key, Object value) {
64+
if (value == null) {
65+
return;
66+
}
67+
68+
String filePath = this.getCacheFilePath(key);
69+
try {
70+
OutputStream dst = null;
71+
try {
72+
if (value instanceof InputStream) {
73+
dst = this.getStream(filePath);
74+
IOUtils.copy((InputStream) value, dst);
75+
76+
} else {
77+
dst = this.getStream(filePath);
78+
MAPPER.writerWithDefaultPrettyPrinter().writeValue(dst, value);
79+
}
80+
} finally {
81+
if (dst != null) {
82+
dst.close();
83+
}
84+
}
85+
} catch (Exception e) {
86+
throw new RuntimeException(e);
87+
}
88+
}
89+
90+
/**
91+
* Deserializes data associated with this key if present.
92+
*
93+
* @param key A key identifying the requested entry.
94+
* @return true if the key was found.
95+
*/
96+
public <T> T getValue(String key, T defaultEntry, Class<?>[] clazzs) {
97+
String cacheFilePath = this.getCacheFilePath(key);
98+
if (!new File(cacheFilePath).exists()) {
99+
set(key, defaultEntry);
100+
return defaultEntry;
101+
}
102+
try {
103+
for (Class<?> clazz : clazzs) {
104+
final FileInputStream inputStream = new FileInputStream(cacheFilePath);
105+
try {
106+
return (T) MAPPER.readValue(inputStream, clazz);
107+
} catch (UnrecognizedPropertyException e) {
108+
// continue;
109+
} finally {
110+
inputStream.close();
111+
}
112+
}
113+
} catch (MismatchedInputException e) {
114+
try {
115+
return (T) new FileInputStream(cacheFilePath);
116+
} catch (IOException ex) {
117+
throw new RuntimeException(ex);
118+
}
119+
} catch (IOException e) {
120+
e.printStackTrace();
121+
}
122+
return null;
123+
}
124+
125+
126+
@Override
127+
public String getCacheFilePath(String key) {
128+
String folderPath = PathUtils.combine(this.getCachePath(), this.getCacheSubFolder());
129+
String filePath = PathUtils.combine(folderPath, key);
130+
131+
final File file = new File(folderPath);
132+
if (!file.exists() && !file.mkdirs()) {
133+
throw new DiskAccessException("create cache directory", file);
134+
}
135+
136+
return filePath;
137+
}
138+
139+
@Override
140+
public boolean contains(String key) {
141+
String file = PathUtils.combine(this.getCachePath(), this.getCacheSubFolder(), key);
142+
return new File(file).exists();
143+
}
144+
145+
private OutputStream getStream(String path) throws FileNotFoundException, InterruptedException {
146+
OutputStream stream = null;
147+
long totalTime = 0;
148+
long interval = 50;
149+
while (stream == null) {
150+
try {
151+
stream = new FileOutputStream(path);
152+
} catch (IOException e) {
153+
Thread.sleep(50);
154+
totalTime += interval;
155+
156+
if (totalTime > WAIT_TIMEOUT) {
157+
throw e;
158+
}
159+
}
160+
}
161+
162+
return stream;
163+
}
164+
165+
@Override
166+
public String getCachePath() {
167+
return mCachePath;
168+
}
169+
170+
@Override
171+
public String getCacheSubFolder() {
172+
return mCacheSubFolder;
173+
}
174+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.groupdocs.ui.cache;
2+
3+
/**
4+
* Defines methods required for storing rendered document and document resources сache.
5+
*/
6+
public interface ViewerCache {
7+
/**
8+
* The Relative or absolute path to the cache folder.
9+
*/
10+
String getCachePath();
11+
12+
/**
13+
* The sub-folder to append to the CachePath.
14+
*/
15+
String getCacheSubFolder();
16+
17+
/**
18+
* Inserts a cache entry into the cache.
19+
*
20+
* @param key A unique identifier for the cache entry.
21+
* @param value The object to insert.
22+
*/
23+
<T> void set(String key, T value);
24+
25+
/**
26+
* Gets the entry associated with this key if present.
27+
*
28+
* @param key A key identifying the requested entry.
29+
* @return true if the key was found.
30+
*/
31+
<T> T getValue(String key, T defaultEntry, Class<?>[] clazzs);
32+
33+
/**
34+
* Gets cache file path;.
35+
*
36+
* @param key The cache file key.
37+
* @return Cache file path.
38+
*/
39+
String getCacheFilePath(String key);
40+
41+
boolean contains(String key);
42+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.groupdocs.ui.cache.mixin;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.groupdocs.viewer.results.Line;
5+
6+
import java.util.List;
7+
8+
public abstract class PageMixIn {
9+
PageMixIn(@JsonProperty("number") int number, @JsonProperty("visible") boolean visible, @JsonProperty("width") int width, @JsonProperty("height") int height, @JsonProperty("lines") List<Line> lines) {
10+
}
11+
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.groupdocs.ui.cache.mixin;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.groupdocs.viewer.FileType;
5+
import com.groupdocs.viewer.results.Page;
6+
7+
import java.util.List;
8+
9+
public abstract class PdfViewInfoMixIn {
10+
PdfViewInfoMixIn(@JsonProperty("fileType") FileType fileType, @JsonProperty("pages") List<Page> pages, @JsonProperty("printingAllowed") boolean printingAllowed) {
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.groupdocs.ui.cache.mixin;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.groupdocs.viewer.FileType;
5+
import com.groupdocs.viewer.results.Page;
6+
7+
import java.util.List;
8+
9+
public abstract class ViewInfoMixIn {
10+
ViewInfoMixIn(@JsonProperty("fileType") FileType fileType, @JsonProperty("pages") List<Page> pages) {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)