public Object load() { Object result = new JSONArray(); try { GenericBasicFileFilter jsonFilter = new GenericBasicFileFilter(null, ".cdfde"); List<IBasicFile> defaultTemplatesList = CdeEnvironment.getPluginSystemReader(SYSTEM_CDF_DD_TEMPLATES) .listFiles(null, jsonFilter, IReadAccess.DEPTH_ALL); if (defaultTemplatesList != null) { loadFiles(defaultTemplatesList.toArray(new IBasicFile[] {}), (JSONArray) result, "default"); } else { result = Messages.getString("CdfTemplates.ERROR_002_LOADING_TEMPLATES_EXCEPTION"); } List<IBasicFile> customTemplatesList = CdeEnvironment.getPluginRepositoryReader(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM) .listFiles(null, jsonFilter, IReadAccess.DEPTH_ALL); if (customTemplatesList != null) { loadFiles(customTemplatesList.toArray(new IBasicFile[] {}), (JSONArray) result, "custom"); } } catch (IOException e) { logger.error(e); result = Messages.getString("CdfTemplates.ERROR_002_LOADING_EXCEPTION"); } return result; }
private void loadFiles(final IBasicFile[] jsonFiles, final JSONArray result, final String type) throws IOException { Arrays.sort( jsonFiles, new Comparator<IBasicFile>() { @Override public int compare(IBasicFile file1, IBasicFile file2) { if (file1 == null && file2 == null) { return 0; } else { return file1.getFullPath().toLowerCase().compareTo(file2.getFullPath().toLowerCase()); } } }); IReadAccess access = CdeEnvironment.getPluginSystemReader(SYSTEM_CDF_DD_TEMPLATES); for (int i = 0; i < jsonFiles.length; i++) { final JSONObject template = new JSONObject(); String imgResourcePath = resoureUrl + "unknown.png"; if (access.fileExists(jsonFiles[i].getName().replace(".cdfde", ".png"))) { imgResourcePath = resoureUrl + jsonFiles[i].getName().replace(".cdfde", ".png"); } template.put("img", imgResourcePath); template.put("type", type); template.put("structure", JsonUtils.readJsonFromInputStream(jsonFiles[i].getContents())); result.add(template); } }
protected IBasicFile getGlobalBaseMessageFile() { if (globalBaseMessageFile == null) { globalBaseMessageFile = CdeEnvironment.getPluginSystemReader(SYSTEM_PLUGIN_GLOBAL_LANGUAGES_DIR) .fetchFile(BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties"); } return globalBaseMessageFile; }
public void saveI18NMessageFilesToCache() { if (!CdeEnvironment.getPluginSystemReader(BASE_CACHE_DIR).fileExists(msgsRelativeDir)) { CdeEnvironment.getPluginSystemWriter() .createFolder(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir)); } try { copyStdGlobalMessageFileToCache(); appendMessageFiles( sourceDashboardBaseMsgFile, getGlobalBaseMessageFile(), getTargetDashboardBaseMessageFile()); } catch (IOException e) { logger.error(e); } }
protected void copyStdGlobalMessageFileToCache() throws IOException { IBasicFile globalMsgCacheFile = getGlobalMsgCacheFile(); if (globalMsgCacheFile != null && globalMsgCacheFile.getContents() != null) { return; } else { String globalMsgFileName = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties"; IBasicFile globalMsgFile = CdeEnvironment.getPluginSystemReader(SYSTEM_PLUGIN_GLOBAL_LANGUAGES_DIR) .fetchFile(globalMsgFileName); CdeEnvironment.getPluginSystemWriter() .saveFile( Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir, globalMsgFileName), globalMsgFile.getContents()); } }
protected IBasicFile getGlobalMsgCacheFile() { if (globalMsgCacheFile == null) { IReadAccess systemReader = CdeEnvironment.getPluginSystemReader(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir)); String msg = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties"; if (systemReader.fileExists(msg)) { globalMsgCacheFile = systemReader.fetchFile(msg); } } return globalMsgCacheFile; }
protected IBasicFile getTargetDashboardBaseMessageFile() { if (targetDashboardBaseMsgFile == null) { IReadAccess systemReader = CdeEnvironment.getPluginSystemReader(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir)); String msg = sourceDashboardBaseMsgFile != null ? sourceDashboardBaseMsgFile.getName() : BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties"; if (systemReader.fileExists(msg)) { targetDashboardBaseMsgFile = systemReader.fetchFile(msg); } } return targetDashboardBaseMsgFile; }
public void save(String file, String structure) throws DashboardStructureException, IOException { logger.info("Saving File:" + file); IRWAccess access = CdeEnvironment.getPluginRepositoryWriter(); if (!access.fileExists(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM)) { access.createFolder(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM); } structure = addDashboardStyleAndRendererTypeToTemplate(structure); byte[] fileData = structure.getBytes(CharsetHelper.getEncoding()); if (!access.saveFile( Utils.joinPath(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM, file), new ByteArrayInputStream(fileData))) { throw new DashboardStructureException( Messages.getString("DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION")); } }