Source code: com/obinary/cms/beans/ConfigLoader.java
1 /**
2 *
3 * Magnolia and its source-code is licensed under the LGPL.
4 * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5 * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6 * you are required to provide proper attribution to obinary.
7 * If you reproduce or distribute the document without making any substantive modifications to its content,
8 * please use the following attribution line:
9 *
10 * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11 *
12 * */
13
14
15
16
17 package com.obinary.cms.beans;
18
19
20 import org.apache.slide.jcr.core.RepositoryFactory;
21 import org.apache.slide.jcr.core.AccessManagerImpl;
22 import org.apache.slide.jcr.core.SudoCredentials;
23
24 import javax.jcr.*;
25
26
27 import java.util.ArrayList;
28 import java.util.regex.Pattern;
29
30 import com.obinary.cms.License;
31
32
33 /**
34 * User: sameercharles
35 * Date: Apr 28, 2003
36 * Time: 11:20:59 AM
37 * @author Sameer Charles
38 * @version 1.0
39 */
40
41
42 public class ConfigLoader {
43
44 private static final String CONFIG = "localfsConfig";
45 private static final String WEBSITE = "localfsWebsite";
46 private static final String USERS = "localfsUsers";
47 private static final String USER_ROLES = "localfsUserRoles";
48
49 private static RepositoryFactory repositoryFactory;
50
51 public static Repository configRepository;
52 public static Repository websiteRepository;
53 public static Repository usersRepository;
54 public static Repository userRolesRepository;
55
56 /** start page under the configRepository */
57 public static Node configRoot;
58
59
60 /**
61 * constructor
62 */
63 public ConfigLoader() throws RepositoryException {
64 /*
65 first check for the license information, will fail if this class does not exist
66 */
67 printVersionInfo();
68 ConfigLoader.loadRepositories();
69
70 Ticket userTicket = ConfigLoader.usersRepository.connect(new PasswordCredentials("superuser", "".toCharArray()));
71 Node userRoot = userTicket.getRootNode();
72
73 SudoCredentials sc = new SudoCredentials(userTicket,userRoot.getNode("/superuser"));
74
75 Ticket t = ConfigLoader.configRepository.connect(sc);
76
77 ArrayList acl = new ArrayList();
78 Pattern p = Pattern.compile("[a-z[A-Z[./[0-9[_-[:]]]]]]*");
79 Permission permission = new Permission();
80 permission.setPattern(p);
81 permission.setPermissions(31);
82 acl.add(permission);
83 ((AccessManagerImpl)t.getAccessManager()).setUserPermissions(acl);
84
85 ConfigLoader.configRoot = t.getRootNode();
86
87 new ListenerInfo(true); /* update Listener cache */
88 new TemplateInfo(true); /* update templates cache */
89 new SubscriberInfo(true); /* load subscribers info */
90 new ParagraphInfo(true);
91 new ServerInfo(true);
92 }
93
94
95 private void printVersionInfo() {
96 System.out.println("---------------------------------------------");
97 System.out.println("MAGNOLIA LICENSE");
98 System.out.println("---------------------------------------------");
99 System.out.println("Version number : "+License.getVersionNumber());
100 System.out.println("Build : "+License.getBuildNumber());
101 System.out.println("Provider : "+License.getProviderName()+" ("+License.getProviderEmail()+")");
102 }
103
104
105 /**
106 * <p>reload all config info in the same objects created on the startup</p>
107 *
108 * @throws RepositoryException
109 */
110 public static void reload() throws RepositoryException {
111 ListenerInfo.init();
112 TemplateInfo.init();
113 SubscriberInfo.init();
114 ParagraphInfo.init();
115 ServerInfo.init();
116 }
117
118
119
120 /**
121 * <p>load all available repositories</p>
122 *
123 */
124 public static void loadRepositories() throws RepositoryException {
125 ConfigLoader.repositoryFactory = RepositoryFactory.getRepositoryFactory();
126 ConfigLoader.initConfigRepository();
127 ConfigLoader.initUsersRepository();
128 ConfigLoader.initUserRolesRepository();
129 ConfigLoader.initWebsiteRepository();
130 }
131
132
133
134 /**
135 * <p>load config repository</p>
136 *
137 */
138 public static void initConfigRepository() throws RepositoryException {
139 ConfigLoader.configRepository = ConfigLoader.repositoryFactory.getRepository(CONFIG);
140 }
141
142
143
144 /**
145 * <p>load website repository</p>
146 *
147 */
148 public static void initWebsiteRepository() throws RepositoryException {
149 ConfigLoader.websiteRepository = ConfigLoader.repositoryFactory.getRepository(WEBSITE);
150 }
151
152
153
154 /**
155 * <p>load users repository</p>
156 *
157 */
158 public static void initUsersRepository() throws RepositoryException {
159 ConfigLoader.usersRepository = ConfigLoader.repositoryFactory.getRepository(USERS);
160 }
161
162
163 /**
164 * <p>load users repository</p>
165 *
166 */
167 public static void initUserRolesRepository() throws RepositoryException {
168 ConfigLoader.userRolesRepository = ConfigLoader.repositoryFactory.getRepository(USER_ROLES);
169 }
170
171
172 /**
173 *
174 */
175 public static Repository getUserRepository() {
176 return ConfigLoader.usersRepository;
177 }
178
179
180
181
182 }