KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > admin > info > LicenseInfo


1 // $Id: LicenseInfo.java 10570 2005-09-13 09:35:40Z pvollenweider $
2
//
3
// ____.
4
// __/\ ______| |__/\. _______
5
// __ .____| | \ | +----+ \
6
// _______| /--| | | - \ _ | : - \_________
7
// \\______: :---| : : | : | \________>
8
// |__\---\_____________:______: :____|____:_____\
9
// /_____|
10
//
11
// . . . i n j a h i a w e t r u s t . . .
12
//
13
//
14
// LicenseInfo
15
//
16
// 09.08.2001 MJ added in jahia.
17
//
18

19 package org.jahia.admin.info;
20
21 import java.io.IOException JavaDoc;
22
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
27
28 import org.jahia.bin.Jahia;
29 import org.jahia.bin.JahiaAdministration;
30 import org.jahia.data.JahiaData;
31 import org.jahia.exceptions.JahiaException;
32 import org.jahia.params.ParamBean;
33 import org.jahia.registries.ServicesRegistry;
34 import org.jahia.resourcebundle.JahiaResourceBundle;
35 import org.jahia.utils.properties.PropertiesManager;
36 import org.jahia.security.license.License;
37 import org.jahia.security.license.Limit;
38 import org.jahia.security.license.DaysLeftValidator;
39 import java.util.Date JavaDoc;
40
41
42 /**
43  * desc: This class provides the business methods for license
44  * info display, from the JahiaAdministration servlet.
45  *
46  * Copyright: Copyright (c) 2002
47  * Company: Jahia Ltd
48  *
49  * @author Mikhael Janson
50  * @version 1.0
51  */

52 public class LicenseInfo
53 {
54     private static org.apache.log4j.Logger logger =
55             org.apache.log4j.Logger.getLogger(LicenseInfo.class);
56
57     private static final String JavaDoc CLASS_NAME = JahiaAdministration.CLASS_NAME;
58     private static final String JavaDoc JSP_PATH = JahiaAdministration.JSP_PATH;
59
60     private static ServicesRegistry sReg;
61
62     private License coreLicense;
63
64
65
66     /**
67     * Default constructor.
68     *
69     * @param request Servlet request.
70     * @param response Servlet response.
71     * @param session Servlet session for the current user.
72     */

73     public LicenseInfo( HttpServletRequest JavaDoc request,
74                                HttpServletResponse JavaDoc response,
75                                HttpSession JavaDoc session )
76
77     throws Throwable JavaDoc
78     {
79       JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");
80       ParamBean jParams = null;
81       if (jData != null) {
82           jParams = jData.params();
83       }
84         coreLicense = Jahia.getCoreLicense();
85         if ( coreLicense == null ){
86             // set request attributes...
87
String JavaDoc dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.invalidLicenseKey.label",
88                                                jParams, jParams.getLocale());
89             request.setAttribute("jahiaDisplayMessage", dspMsg);
90             // redirect...
91
JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" );
92             return;
93         }
94
95         displayLicenseInfo( request, response, session );
96     } // end constructor
97

98
99     /**
100      * Display installed license information, using doRedirect().
101      *
102      * @param req the HttpServletRequest object
103      * @param res the HttpServletResponse object
104      * @param sess the HttpSession object
105      */

106     private void displayLicenseInfo( HttpServletRequest JavaDoc req,
107                                      HttpServletResponse JavaDoc res,
108                                      HttpSession JavaDoc sess )
109     throws IOException JavaDoc, ServletException JavaDoc
110     {
111
112       JahiaData jData = (JahiaData) req.getAttribute("org.jahia.data.JahiaData");
113       ParamBean jParams = null;
114       if (jData != null) {
115           jParams = jData.params();
116       }
117         ServicesRegistry sReg = ServicesRegistry.getInstance();
118
119         if (sReg != null) {
120
121             try {
122                 int nbCurrentSites = sReg.getJahiaSitesService().getNbSites();
123                 int nbMaxSites = Jahia.getSiteLimit();
124                 int nbCurrentUsers = sReg.getJahiaUserManagerService().getNbUsers();
125                 int nbMaxUsers = Jahia.getUserLimit();
126                 int nbCurrentTemplates = sReg.getJahiaPageTemplateService().getNbPageTemplates();
127                 int nbMaxTemplates = Jahia.getTemplateLimit();
128                 int nbCurrentPages = sReg.getJahiaPageService().getRealActiveNbPages();
129                 int nbMaxPages = Jahia.getPageLimit();
130
131                 String JavaDoc maxSites = (nbMaxSites == -1) ? "unlimited" : Integer.toString(nbMaxSites);
132                 String JavaDoc maxUsers = (nbMaxUsers == -1) ? "unlimited" : Integer.toString(nbMaxUsers);
133                 String JavaDoc maxTemplates = (nbMaxTemplates == -1) ? "unlimited" : Integer.toString(nbMaxTemplates);
134                 String JavaDoc maxPages = (nbMaxPages == -1) ? "unlimited" : Integer.toString(nbMaxPages);
135
136                 Limit daysLeftLimit = Jahia.getCoreLicense().getLimit("maxUsageDays");
137                 // the limit might be null if a license has been created without
138
// this limit.
139
if (daysLeftLimit != null) {
140                     DaysLeftValidator daysLeftValidator = (DaysLeftValidator)
141                         daysLeftLimit.getValidator();
142                     int maxDays = Integer.parseInt(daysLeftLimit.getValueStr());
143                     req.setAttribute("allowedDays", new Integer JavaDoc(maxDays));
144                     long expirationTime = daysLeftValidator.
145                         getComponentInstallDate().getTime() +
146                         1000L * 60L * 60L * 24L * maxDays;
147                     Date JavaDoc expirationDate = new Date JavaDoc(expirationTime);
148                     req.setAttribute("expirationDate", expirationDate);
149                 }
150
151                 req.setAttribute("nbCurrentSites", Integer.toString(nbCurrentSites) );
152                 req.setAttribute("nbMaxSites", maxSites );
153                 req.setAttribute("nbCurrentUsers", Integer.toString(nbCurrentUsers) );
154                 req.setAttribute("nbMaxUsers", maxUsers );
155                 req.setAttribute("nbCurrentTemplates", Integer.toString(nbCurrentTemplates) );
156                 req.setAttribute("nbMaxTemplates", maxTemplates );
157                 req.setAttribute("nbCurrentPages", Integer.toString(nbCurrentPages) );
158                 req.setAttribute("nbMaxPages", maxPages );
159                 PropertiesManager pm = new PropertiesManager(Jahia.getJahiaPropertiesFileName());
160                 req.setAttribute("release", pm.getProperty("release"));
161                 req.setAttribute("build", Integer.toString(Jahia.BUILD_NUMBER) );
162                 JahiaAdministration.doRedirect( req, res, sess, JSP_PATH + "show_info.jsp" );
163
164             } catch (JahiaException je) {
165                 logger.debug("Error while retrieving license information", je);
166
167                 String JavaDoc dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.jahiaServicesProblem.label",
168                                                    jParams, jParams.getLocale());
169                 sess.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg);
170                 JahiaAdministration.displayMenu( req, res, sess ); // back to menu in case of problems with the Managers...
171
}
172
173         } else {
174           String JavaDoc dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.noServicesRegistry.label",
175                                              jParams, jParams.getLocale());
176           sess.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg);
177             JahiaAdministration.displayMenu( req, res, sess ); // back to menu in case of problems with the Managers...
178
}
179
180     } // end displayLicenseInfo
181

182
183 } // end class LicenseInfo
184
Popular Tags