KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > security > license > SiteCountValidator


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 /**
8  * <p>Title: </p>
9  * <p>Description: </p>
10  * <p>Copyright: Copyright (c) 2002</p>
11  * <p>Company: Jahia Ltd</p>
12  * @author Serge Huber
13  * @version 1.0
14  */

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 JavaDoc name, String JavaDoc value, License license) {
22         super(name, value, license);
23     }
24
25     public boolean assertEquals(String JavaDoc value) {
26
27         int maxSites = Integer.parseInt(value);
28
29         // Check if the number of users is not exceeding the fixed limit
30
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 JavaDoc(nbItems), new Integer JavaDoc(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 JavaDoc fromValue, String JavaDoc toValue) {
47         int minSites = Integer.parseInt(fromValue);
48         int maxSites = Integer.parseInt(toValue);
49
50         // Check if the number of users is not exceeding the fixed limit
51
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 JavaDoc(nbItems), new Integer JavaDoc(minSites), new Integer JavaDoc(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