AppDefinition appDef = appService.getAppDefinition(appId, appVersion.toString());
if (appDef == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
UserviewDefinition userviewDef = userviewDefinitionDao.loadById(userviewId, appDef);
if (userviewDef == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
String json = userviewDef.getJson();
Userview userview = userviewService.createUserview(json, null, false, request.getContextPath(), request.getParameterMap(), null, false);
boolean cacheEnabled = "true".equals(userview.getSetting().getProperty("mobileCacheEnabled"));
if (!cacheEnabled) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// set response type
response.setContentType("text/cache-manifest");
// set expires header
response.addDateHeader("Expires", 0);
// generate cache manifest for the app userview
String contextPath = AppUtil.getRequestContextPath();
String currentUser = WorkflowUtil.getCurrentUsername();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
String manifest = "CACHE MANIFEST\n"
+ "# " + appDef.getAppId() + " v" + appDef.getVersion() + " " + userviewDef.getId() + " " + userviewDef.getDateModified() + " " + currentUser + " " + cal.getTime() + "\n"
+ "NETWORK:\n"
+ "*\n"
+ "\n"
+ "CACHE:\n"
+ contextPath + "/home/logo.png\n"
+ contextPath + "/home/style.css\n"
+ contextPath + "/js/jquery/themes/ui-lightness/jquery-ui-1.10.3.custom.css\n"
+ contextPath + "/mobile/jqm/jquery.mobile-1.4.0-rc.1.css\n"
+ contextPath + "/mobile/mobile.css\n"
+ contextPath + "/js/jquery/jquery-1.9.1.min.js\n"
+ contextPath + "/js/jquery/jquery-migrate-1.2.1.min.js\n"
+ contextPath + "/js/jquery/ui/jquery-ui-1.10.3.min.js\n"
+ contextPath + "/mobile/jqm/jquery.mobile-1.4.0-rc.1.min.js\n"
+ contextPath + "/mobile/jqm/jquery.cookie.js\n"
+ contextPath + "/mobile/mobile.js\n"
+ contextPath + "/mobile/mobile_util.js\n"
+ contextPath + "/js/json/ui.js\n"
+ contextPath + "/js/json/ui_ext.js\n"
+ contextPath + "/js/json/util.js\n"
+ contextPath + "/mobile/jqm/images/ajax-loader.gif\n"
+ contextPath + "/css/form.css\n"
+ contextPath + "/plugin/org.joget.apps.form.model.Section/js/section.js\n";
UserviewSetting setting = userview.getSetting();
String backgroundUrl = setting.getPropertyString("mobileViewBackgroundUrl");
String logoUrl = setting.getPropertyString("mobileViewLogoUrl");
if (backgroundUrl != null && !backgroundUrl.trim().isEmpty()) {
manifest += backgroundUrl + "\n";
}
if (logoUrl != null && !logoUrl.trim().isEmpty()) {
manifest += logoUrl + "\n";
}
Collection<UserviewCategory> categories = userview.getCategories();
for (UserviewCategory cat : categories) {
Collection<UserviewMenu> menus = cat.getMenus();
for (UserviewMenu menu : menus) {
String menuId = userviewService.getMenuId(menu);
manifest += contextPath + "/web/mobile/" + appDef.getId() + "/" + userviewDef.getId() + "//" + menuId + "\n";
}
}
LogUtil.debug(getClass().getName(), "Request: " + request.getRequestURI());
// output manifest