/** * @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)); } }
/** * @see org.opencms.loader.I_CmsResourceLoader#load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override public void load(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) throws IOException, CmsException { if (m_enabled) { if (canSendLastModifiedHeader(resource, req, res)) { // no image processing required at all return; } // get the scale information from the request CmsImageScaler scaler = new CmsImageScaler(req, m_maxScaleSize, m_maxBlurSize); // load the file from the cache CmsFile file = getScaledImage(cms, resource, scaler); // now perform standard load operation inherited from dump loader super.load(cms, file, req, res); } else { // scaling is disabled super.load(cms, resource, req, res); } }
/** * Initializes the members with the default values.<p> */ private void init() { m_height = -1; m_width = -1; m_type = 0; m_position = 0; m_renderMode = 0; m_quality = 0; m_cropX = -1; m_cropY = -1; m_cropHeigt = -1; m_cropWidth = -1; m_color = Color.WHITE; m_filters = new ArrayList(); m_maxBlurSize = CmsImageLoader.getMaxBlurSize(); }
public void init() { if (CmsImageLoader.isEnabled()) { try {
/** * 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); }
if (CmsImageLoader.isEnabled()) { String downScaleParams = CmsImageLoader.getDownScaleParams(); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(downScaleParams)) { m_downScaler = new CmsImageScaler(downScaleParams);
public void init() { if (CmsImageLoader.isEnabled()) { try {
/** * 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); }
if (CmsImageLoader.isEnabled()) { String downScaleParams = CmsImageLoader.getDownScaleParams(); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(downScaleParams)) { m_downScaler = new CmsImageScaler(downScaleParams);
/** * @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)); } }
/** * @see org.opencms.file.types.I_CmsResourceType#createResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, java.lang.String, byte[], java.util.List) */ @Override public CmsResource createResource( CmsObject cms, CmsSecurityManager securityManager, String resourcename, byte[] content, List properties) throws CmsException { if (CmsImageLoader.isEnabled()) { String rootPath = cms.getRequestContext().addSiteRoot(resourcename); // get the downscaler to use CmsImageScaler downScaler = getDownScaler(cms, rootPath); // create a new image scale adjuster CmsImageAdjuster adjuster = new CmsImageAdjuster(content, rootPath, properties, downScaler); // update the image scale adjuster - this will calculate the image dimensions and (optionally) downscale the size adjuster.adjust(); // continue with the updated content and properties content = adjuster.getContent(); properties = adjuster.getProperties(); } return super.createResource(cms, securityManager, resourcename, content, properties); }
String oName = f.getAbsolutePath().substring(CmsImageLoader.getImageRepositoryPath().length()); oName = CmsStringUtil.substitute(oName, "\\", "/"); if (!oName.startsWith("/")) {
/** * @see org.opencms.loader.I_CmsResourceLoader#load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override public void load(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) throws IOException, CmsException { if (m_enabled) { if (canSendLastModifiedHeader(resource, req, res)) { // no image processing required at all return; } // get the scale information from the request CmsImageScaler scaler = new CmsImageScaler(req, m_maxScaleSize, m_maxBlurSize); // load the file from the cache CmsFile file = getScaledImage(cms, resource, scaler); // now perform standard load operation inherited from dump loader super.load(cms, file, req, res); } else { // scaling is disabled super.load(cms, resource, req, res); } }
/** * Initializes the members with the default values.<p> */ private void init() { m_height = -1; m_width = -1; m_maxHeight = -1; m_maxWidth = -1; m_type = 0; m_position = 0; m_renderMode = 0; m_quality = 0; m_cropX = -1; m_cropY = -1; m_cropHeight = -1; m_cropWidth = -1; m_color = Color.WHITE; m_filters = new ArrayList<String>(); m_maxBlurSize = CmsImageLoader.getMaxBlurSize(); }
/** * @see org.opencms.file.types.I_CmsResourceType#createResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, java.lang.String, byte[], java.util.List) */ @Override public CmsResource createResource( CmsObject cms, CmsSecurityManager securityManager, String resourcename, byte[] content, List<CmsProperty> properties) throws CmsException { if (CmsImageLoader.isEnabled()) { String rootPath = cms.getRequestContext().addSiteRoot(resourcename); // get the downscaler to use CmsImageScaler downScaler = getDownScaler(cms, rootPath); // create a new image scale adjuster CmsImageAdjuster adjuster = new CmsImageAdjuster(content, rootPath, properties, downScaler); // update the image scale adjuster - this will calculate the image dimensions and (optionally) downscale the size adjuster.adjust(); // continue with the updated content and properties content = adjuster.getContent(); properties = adjuster.getProperties(); } return super.createResource(cms, securityManager, resourcename, content, properties); }
/** * Reads all cached images.<p> * * @param cms the cms context * @param withVariations if also variations should be read * @param showSize if it is needed to compute the image size * @param statsOnly if only statistical information should be retrieved */ private void init(CmsObject cms, boolean withVariations, boolean showSize, boolean statsOnly) { File basedir = new File(CmsImageLoader.getImageRepositoryPath()); try { CmsObject clonedCms = OpenCms.initCmsObject(cms); // only online images get caches clonedCms.getRequestContext().setCurrentProject(clonedCms.readProject(CmsProject.ONLINE_PROJECT_ID)); // paths are always root path clonedCms.getRequestContext().setSiteRoot(""); // get the images visitImages(clonedCms, basedir, withVariations, showSize, statsOnly); } catch (CmsException e) { // should never happen } m_variations = Collections.unmodifiableMap(m_variations); m_sizes = Collections.unmodifiableMap(m_sizes); m_lengths = Collections.unmodifiableMap(m_lengths); }
List<CmsProperty> properties) throws CmsException { if (CmsImageLoader.isEnabled()) {
List properties) throws CmsException { if (CmsImageLoader.isEnabled()) {
List properties) throws CmsException { if (CmsImageLoader.isEnabled()) {
List<CmsProperty> properties) throws CmsException { if (CmsImageLoader.isEnabled()) {