Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit ac4ece8

Browse files
authored
Merge pull request #19 from Pavel-Teplitsky/master
Added resources and offlineMode option
2 parents b66ef05 + 1b3a4cb commit ac4ece8

25 files changed

+4993
-61
lines changed

configuration.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ resources:
3030
##############################################
3131
# Url/link to web resources (html, js, css, etc) archive
3232
resourcesUrl: https://github.com/bobkovalex/QuickView/archive/master.zip
33+
# Enable/disable resources downloading, false for download
34+
offlineMode: true
35+
# Set default document to view
36+
defaultDocument: ''
37+
# Enable/disable HTMl rendering mode, false for image mode
38+
htmlMode: true
3339
# Pages to be loaded on document open, 0 for all
34-
preloadPageCount: 0
40+
preloadPageCount: 2
41+
# Enable/disable rewrite for uploaded file if file with the same name already exists
42+
rewrite: true
3543
# Enable/disable document zoom
3644
zoom: true
3745
# Enable/disable page navigation
@@ -48,11 +56,5 @@ resources:
4856
upload: true
4957
# Enable/disable document print
5058
print: true
51-
# Set default document to view
52-
defaultDocument: ''
5359
# Enable/disable documents browse
54-
browse: true
55-
# Enable/disable HTMl rendering mode, false for image mode
56-
htmlMode: true
57-
# Enable/disable rewrite for uploaded file if file with the same name already exists
58-
rewrite: true
60+
browse: true

src/main/java/com/aliensoft/quickview/MainService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void run(QuickViewConfig config, Environment environment) throws Exceptio
4848
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
4949

5050
// Get web resources for standalone mode
51-
if(!config.getResources().getRunAsService()){
51+
if(!config.getResources().getRunAsService() && !config.getResources().isOfflineMode()){
5252
WebAssetsManager webAssetsManager = new WebAssetsManager();
5353
webAssetsManager.update(config.getResources().getResourcesUrl());
5454
}

src/main/java/com/aliensoft/quickview/config/QuickViewConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public class Resources{
144144
@JsonProperty
145145
private boolean rewrite;
146146

147+
@Valid
148+
@JsonProperty
149+
private boolean offlineMode;
150+
147151
public Boolean getRunAsService() {
148152
return runAsService;
149153
}
@@ -263,6 +267,10 @@ public boolean isRewrite() {
263267
public void setRewrite(boolean rewrite) {
264268
this.rewrite = rewrite;
265269
}
270+
271+
public boolean isOfflineMode() { return offlineMode; }
272+
273+
public void setOfflineMode(boolean offlineMode) { this.offlineMode = offlineMode; }
266274
}
267275

268276
/**

src/main/java/com/aliensoft/quickview/manager/WebAssetsManager.java

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,51 @@ public class WebAssetsManager {
1616
* @throws IOException
1717
*/
1818
public void update(String link) throws IOException {
19-
// Temp directory
20-
File tempDirectory = new File("temp");
21-
22-
// Project resources directory
23-
//String projectAssetsPath = "src/main/resources/assets";
24-
String targetAssetsPath = "target/classes/assets";
25-
26-
// Download zip file
27-
System.out.println("DOWNLOADING FILES...");
28-
File zipFile = download(link);
29-
System.out.println("OK!");
30-
System.out.println();
31-
32-
// Extract files from zip archive
33-
System.out.println("EXTRACTING FILES...");
34-
String inResourcesPath = unzip(zipFile, tempDirectory);
35-
System.out.println("OK!");
36-
System.out.println();
37-
38-
// Clean project's resources directory
39-
System.out.println("CLEANING RESOURCE DIRECTORY...");
40-
//clean(projectAssetsPath);
41-
clean(targetAssetsPath);
42-
System.out.println("OK!");
43-
System.out.println();
44-
45-
// Copy downloaded resources to project directory
46-
System.out.println("COPYING FILES...");
47-
// Copy files to project directory (as backup)
48-
//copy(inResourcesPath, projectAssetsPath);
49-
// Copy files to target directory to get latest changes without an application restart
50-
copy(inResourcesPath, targetAssetsPath);
51-
System.out.println("OK!");
52-
System.out.println();
53-
54-
// Remove temp directory
55-
System.out.println("REMOVING TEMP DIRECTORY...");
56-
clean(tempDirectory);
57-
System.out.println("OK!");
58-
System.out.println();
19+
try {
20+
// Temp directory
21+
File tempDirectory = new File("temp");
22+
23+
// Project resources directory
24+
//String projectAssetsPath = "src/main/resources/assets";
25+
String targetAssetsPath = "target/classes/assets";
26+
27+
// Download zip file
28+
System.out.println("DOWNLOADING FILES...");
29+
File zipFile = download(link);
30+
System.out.println("OK!");
31+
System.out.println();
32+
33+
// Extract files from zip archive
34+
System.out.println("EXTRACTING FILES...");
35+
String inResourcesPath = unzip(zipFile, tempDirectory);
36+
System.out.println("OK!");
37+
System.out.println();
38+
39+
// Clean project's resources directory
40+
System.out.println("CLEANING RESOURCE DIRECTORY...");
41+
//clean(projectAssetsPath);
42+
clean(targetAssetsPath);
43+
System.out.println("OK!");
44+
System.out.println();
45+
46+
// Copy downloaded resources to project directory
47+
System.out.println("COPYING FILES...");
48+
// Copy files to project directory (as backup)
49+
//copy(inResourcesPath, projectAssetsPath);
50+
// Copy files to target directory to get latest changes without an application restart
51+
copy(inResourcesPath, targetAssetsPath);
52+
System.out.println("OK!");
53+
System.out.println();
54+
55+
// Remove temp directory
56+
System.out.println("REMOVING TEMP DIRECTORY...");
57+
clean(tempDirectory);
58+
System.out.println("OK!");
59+
System.out.println();
60+
} catch (Exception ex){
61+
System.out.println("THERE IS NO INTERNET CONNECTION");
62+
System.out.println("BUILT IN RESOURCES WILL BE USED");
63+
}
5964
}
6065

6166
/**

src/main/java/com/aliensoft/quickview/resources/QuickViewResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.groupdocs.viewer.handler.ViewerHtmlHandler;
2424
import com.groupdocs.viewer.handler.ViewerImageHandler;
2525
import com.groupdocs.viewer.licensing.License;
26-
import com.groupdocs.viewer.localization.ILocalizationHandler;
2726
import io.dropwizard.jetty.ConnectorFactory;
2827
import io.dropwizard.jetty.HttpConnectorFactory;
2928
import io.dropwizard.server.SimpleServerFactory;
@@ -131,7 +130,7 @@ public Object loadFileTree(@Context HttpServletRequest request, @Context HttpSer
131130
// parse files/folders list
132131
for(FileDescription fd : fileListContainer.getFiles()){
133132
FileDescriptionWrapper fileDescription = new FileDescriptionWrapper();
134-
fileDescription.setGuid(fd.getName());
133+
fileDescription.setGuid(fd.getGuid());
135134
// check if current file/folder is temp directory or is hidden
136135
if(tempDirectoryName.equals(fd.getName()) || new File(fileDescription.getGuid()).isHidden()) {
137136
// ignore current file and skip to next one

src/main/java/com/aliensoft/quickview/resources/QuickViewResourcesBase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.aliensoft.quickview.resources;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.fasterxml.jackson.databind.ObjectWriter;
63
import com.google.gson.Gson;
74
import org.apache.commons.io.FilenameUtils;
85
import org.json.JSONException;

src/main/resources/assets/css/font-awesome.min.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)