1 package org.jahia.security.license; 2 3 import org.jahia.registries.ServicesRegistry; 4 import org.jahia.exceptions.JahiaException; 5 import org.jahia.resourcebundle.ResourceMessage; 6 7 15 16 public class SiteCountValidator extends AbstractValidator { 17 18 private static org.apache.log4j.Logger logger = 19 org.apache.log4j.Logger.getLogger(SiteCountValidator.class); 20 21 public SiteCountValidator(String name, String value, License license) { 22 super(name, value, license); 23 } 24 25 public boolean assertEquals(String value) { 26 27 int maxSites = Integer.parseInt(value); 28 29 try { 31 int nbItems = ServicesRegistry.getInstance(). 32 getJahiaSitesService(). 33 getNbSites (); 34 35 if (nbItems > maxSites) { 36 errorMessage = new ResourceMessage("org.jahia.security.license.SiteCountValidator.invalidSiteCount.label", new Integer (nbItems), new Integer (maxSites)); 37 return false; 38 } 39 } 40 catch (JahiaException ex) { 41 logger.error("Error while checking site limit", ex); 42 errorMessage = new ResourceMessage("org.jahia.security.license.SiteCountValidator.errorInSiteCountCheck.label"); 43 } 44 return true; 45 } 46 public boolean assertInRange(String fromValue, String toValue) { 47 int minSites = Integer.parseInt(fromValue); 48 int maxSites = Integer.parseInt(toValue); 49 50 try { 52 int nbItems = ServicesRegistry.getInstance(). 53 getJahiaSitesService(). 54 getNbSites (); 55 56 if ((nbItems > maxSites) || (nbItems < minSites)) { 57 errorMessage = new ResourceMessage("org.jahia.security.license.SiteCountValidator.siteCountNotInRange.label", new Integer (nbItems), new Integer (minSites), new Integer (maxSites)); 58 return false; 59 } 60 } 61 catch (JahiaException ex) { 62 logger.error("Error while checking site limit", ex); 63 errorMessage = new ResourceMessage("org.jahia.security.license.SiteCountValidator.errorInSiteCountCheck.label"); 64 } 65 return true; 66 } 67 68 } | Popular Tags |