showFormatError(maxAgeStr); return -1; String[] tokens = maxAgeStr.split(" +"); if ((tokens.length != 2)) { showFormatError(maxAgeStr); return -1; number = Integer.parseInt(tokens[0]); } catch (NumberFormatException e) { showFormatError(maxAgeStr); return -1; return 7 * 24 * number; } else { showFormatError(maxAgeStr); return -1;
/** * Removes all expired image cache entries from the RFS cache.<p> * * Empty directories are removed as well.<p> * * @param maxAge the maximum age of the image cache files in hours (or fractions of hours) * * @return the total number of deleted resources */ public static int cleanImageCache(float maxAge) { // calculate oldest possible date for the cache files long expireDate = System.currentTimeMillis() - (long)(maxAge * 60f * 60f * 1000f); File basedir = new File(CmsImageLoader.getImageRepositoryPath()); // perform the cache cleanup return cleanImageCache(expireDate, basedir); }
File f = files[i]; if (f.isDirectory()) { count += cleanImageCache(maxAge, f); count++; } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1, f.getAbsolutePath())); count++; } catch (Exception e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1, directory.getAbsolutePath()));
return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); report.println(Messages.get().container(Messages.RPT_IMAGE_SIZE_START_0), I_CmsReport.FORMAT_HEADLINE); report.print(Messages.get().container( Messages.RPT_IMAGE_SIZE_PROCESS_3, String.valueOf(i + 1), lockResource(cms, lock, res); cms.writeFile(file); lockResource(cms, lock, res); unlockResource(cms, lock, res); Messages.get().container(Messages.RPT_IMAGE_SIZE_UPDATE_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_SKIP_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_UNABLE_TO_CALCULATE_0), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_LOCKED_0), I_CmsReport.FORMAT_DEFAULT); report.println(Messages.get().container(Messages.RPT_IMAGE_SIZE_END_0), I_CmsReport.FORMAT_HEADLINE);
cms.getRequestContext().getLocale(), CmsDeleteExpiredResourcesJob.class); report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_START_0), I_CmsReport.FORMAT_HEADLINE); for (int j = topFoldersArr.length - 1; j >= 0; j--) { resources = cms.readResources(topFoldersArr[j], filter, true); changedFiles += deleteExpiredResources(cms, report, resources, expirationdays, currenttime); for (int j = topFoldersArr.length - 1; j >= 0; j--) { resources = cms.readResources(topFoldersArr[j], filter, true); changedFiles += deleteExpiredResources(cms, report, resources, expirationdays, currenttime); report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_END_0), I_CmsReport.FORMAT_HEADLINE);
resourcePath = cms.getRequestContext().removeSiteRoot(resource.getRootPath()); report.print( Messages.get().container(Messages.RPT_DELETE_EXPIRED_PROCESSING_1, new String[] {resourcePath}), I_CmsReport.FORMAT_DEFAULT); report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); || Boolean.FALSE.toString().equals(propertyValue)) { report.println( Messages.get().container(Messages.RPT_DELETE_EXPIRED_PROPERTY_NEVER_0), I_CmsReport.FORMAT_NOTE); continue; if (!lock.getUserId().equals(cms.getRequestContext().currentUser().getId())) { report.println( Messages.get().container(Messages.RPT_DELETE_EXPIRED_LOCKED_0), I_CmsReport.FORMAT_WARNING); continue; report.println(Messages.get().container( Messages.RPT_DELETE_EXPIRED_NOT_EXPIRED_1, new Integer[] {new Integer(expirationDaysPropertyOverride)})); report.println(Messages.get().container( Messages.RPT_DELETE_EXPIRED_FAILED_1, new String[] {CmsException.getStackTraceAsString(e)}), I_CmsReport.FORMAT_ERROR); report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_UNPUBLISHED_0));
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(org.opencms.file.CmsObject, java.util.Map) */ public String launch(CmsObject cms, Map<String, String> parameters) throws Exception { String maxAgeStr = parameters.get(PARAM_MAX_AGE); long maxAgeHours = parseMaxAge(maxAgeStr); if (maxAgeHours > 0) { long maxAgeMillis = maxAgeHours * 3600L * 1000L; long now = System.currentTimeMillis(); CmsLogFilter filter = CmsLogFilter.ALL.filterTo(now - maxAgeMillis); LOG.info("Removing all entries from CMS_LOG older than " + maxAgeHours + " hours..."); cms.deleteLogEntries(filter); } else { LOG.info("Not deleting any log entries because of a problem with the max-age format."); } return "remove old db log entries (max age : " + maxAgeStr + ")"; }
return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); report.println(Messages.get().container(Messages.RPT_IMAGE_SIZE_START_0), I_CmsReport.FORMAT_HEADLINE); Messages.get().container( Messages.RPT_IMAGE_SIZE_PROCESS_3, String.valueOf(i + 1), lockResource(cms, lock, res); cms.writeFile(file); lockResource(cms, lock, res); unlockResource(cms, lock, res); Messages.get().container(Messages.RPT_IMAGE_SIZE_UPDATE_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_SKIP_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_UNABLE_TO_CALCULATE_0), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_LOCKED_0), I_CmsReport.FORMAT_DEFAULT); report.println(Messages.get().container(Messages.RPT_IMAGE_SIZE_END_0), I_CmsReport.FORMAT_HEADLINE);
File f = files[i]; if (f.isDirectory()) { count += cleanImageCache(maxAge, f); } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1, f.getAbsolutePath())); } catch (Exception e) { LOG.error( Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1, directory.getAbsolutePath()));
cms.getRequestContext().getLocale(), CmsDeleteExpiredResourcesJob.class); report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_START_0), I_CmsReport.FORMAT_HEADLINE); for (int j = topFoldersArr.length - 1; j >= 0; j--) { resources = cms.readResources(topFoldersArr[j], filter, true); changedFiles += deleteExpiredResources(cms, report, resources, expirationdays, currenttime); for (int j = topFoldersArr.length - 1; j >= 0; j--) { resources = cms.readResources(topFoldersArr[j], filter, true); changedFiles += deleteExpiredResources(cms, report, resources, expirationdays, currenttime); report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_END_0), I_CmsReport.FORMAT_HEADLINE);
resourcePath = cms.getRequestContext().removeSiteRoot(resource.getRootPath()); report.print( Messages.get().container(Messages.RPT_DELETE_EXPIRED_PROCESSING_1, new String[] {resourcePath}), I_CmsReport.FORMAT_DEFAULT); report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); || Boolean.FALSE.toString().equals(propertyValue)) { report.println( Messages.get().container(Messages.RPT_DELETE_EXPIRED_PROPERTY_NEVER_0), I_CmsReport.FORMAT_NOTE); continue; if (!lock.getUserId().equals(cms.getRequestContext().getCurrentUser().getId())) { report.println( Messages.get().container(Messages.RPT_DELETE_EXPIRED_LOCKED_0), I_CmsReport.FORMAT_WARNING); continue; Messages.get().container( Messages.RPT_DELETE_EXPIRED_NOT_EXPIRED_1, new Integer[] {new Integer(expirationDaysPropertyOverride)})); Messages.get().container( Messages.RPT_DELETE_EXPIRED_FAILED_1, new String[] {CmsException.getStackTraceAsString(e)}), report.println(Messages.get().container(Messages.RPT_DELETE_EXPIRED_UNPUBLISHED_0));
/** * Removes all expired image cache entries from the RFS cache.<p> * * Empty directories are removed as well.<p> * * @param maxAge the maximum age of the image cache files in hours (or fractions of hours) * * @return the total number of deleted resources */ public static int cleanImageCache(float maxAge) { // calculate oldest possible date for the cache files long expireDate = System.currentTimeMillis() - (long)(maxAge * 60f * 60f * 1000f); File basedir = new File(CmsImageLoader.getImageRepositoryPath()); // perform the cache cleanup return cleanImageCache(expireDate, basedir); }
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(CmsObject, Map) */ public String launch(CmsObject cms, Map<String, String> parameters) throws Exception { if (!CmsImageLoader.isEnabled() || (CmsImageLoader.getImageRepositoryPath() == null)) { // scaling functions are not available return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); } String maxAgeStr = parameters.get(PARAM_MAXAGE); float maxAge; try { maxAge = Float.parseFloat(maxAgeStr); } catch (NumberFormatException e) { // in case of an error, use maxage of one week maxAge = 24f * 7f; LOG.error( Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_BAD_MAXAGE_2, maxAgeStr, new Float(maxAge))); } // now perform the image cache cleanup int count = cleanImageCache(maxAge); return Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_CLEANUP_COUNT_1, new Integer(count)); } }
finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName()); } catch (CmsException e) { finishMessage = Messages.get().getBundle().key( Messages.LOG_PUBLISH_FAILED_2, project.getName(), LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e);
/** * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent) */ public void cmsEvent(CmsEvent event) { if (event == null) { return; } // only react on the clear caches event int type = event.getType(); if (type != I_CmsEventListener.EVENT_CLEAR_CACHES) { return; } // only react if the clear images cache parameter is set Map data = event.getData(); if (data == null) { return; } Object param = data.get(PARAM_CLEAR_IMAGES_CACHE); if (param == null) { return; } float age = -1; if (param instanceof String) { age = Float.valueOf((String)param).floatValue(); } else if (param instanceof Number) { age = ((Number)param).floatValue(); } CmsImageCacheCleanupJob.cleanImageCache(age); }
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(CmsObject, Map) */ public String launch(CmsObject cms, Map parameters) throws Exception { if (!CmsImageLoader.isEnabled() || (CmsImageLoader.getImageRepositoryPath() == null)) { // scaling functions are not available return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); } String maxAgeStr = (String)parameters.get(PARAM_MAXAGE); float maxAge; try { maxAge = Float.parseFloat(maxAgeStr); } catch (NumberFormatException e) { // in case of an error, use maxage of one week maxAge = 24f * 7f; LOG.error(Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_BAD_MAXAGE_2, maxAgeStr, new Float(maxAge))); } // now perform the image cache cleanup int count = cleanImageCache(maxAge); return Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_CLEANUP_COUNT_1, new Integer(count)); } }
finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName()); } catch (CmsException e) { finishMessage = Messages.get().getBundle().key( Messages.LOG_PUBLISH_FAILED_2, project.getName(), LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e);
/** * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent) */ public void cmsEvent(CmsEvent event) { if (event == null) { return; } // only react on the clear caches event int type = event.getType(); if (type != I_CmsEventListener.EVENT_CLEAR_CACHES) { return; } // only react if the clear images cache parameter is set Map<String, ?> data = event.getData(); if (data == null) { return; } Object param = data.get(PARAM_CLEAR_IMAGES_CACHE); if (param == null) { return; } float age = -1; if (param instanceof String) { age = Float.valueOf((String)param).floatValue(); } else if (param instanceof Number) { age = ((Number)param).floatValue(); } CmsImageCacheCleanupJob.cleanImageCache(age); }
finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName()); } catch (CmsException e) { finishMessage = Messages.get().getBundle().key( Messages.LOG_PUBLISH_FAILED_2, project.getName(), LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e);
finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName()); } catch (CmsException e) { finishMessage = Messages.get().getBundle().key( Messages.LOG_PUBLISH_FAILED_2, project.getName(), LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e);