KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > SimpleContentModule


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-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.beans.config.VirtualURIManager;
17 import info.magnolia.cms.core.Content;
18 import info.magnolia.cms.core.NodeData;
19 import info.magnolia.cms.module.InitializationException;
20 import info.magnolia.cms.module.RegisterException;
21 import info.magnolia.cms.util.ContentUtil;
22 import info.magnolia.cms.util.NodeDataUtil;
23
24 /**
25  * A simple module which just set a default URI in a public instance from the module definition's
26  * defaultPublicURI property.
27  *
28  * @author gjoseph
29  * @version $Revision: $ ($Author: $)
30  */

31 public class SimpleContentModule extends AbstractAdminModule {
32     private static final String JavaDoc SERVER_ADMIN_NODEPATH = "/server/admin";
33     private static final String JavaDoc DEFAULT_URI_NODEPATH = "/modules/adminInterface/virtualURIMapping/default";
34     private static final String JavaDoc DEFAULT_URI_PROPNAME = "defaultPublicURI";
35
36     protected void onInit() throws InitializationException {
37         // nothing to do ...
38
}
39
40     protected void onRegister(int registerState) throws RegisterException {
41         super.onRegister(registerState);
42
43         // set the default URI to features.html if we're in a public instance
44
if (isPublicInstance() && (registerState == REGISTER_STATE_INSTALLATION || registerState == REGISTER_STATE_NEW_VERSION)) {
45             final String JavaDoc defaultPublicURI = getModuleDefinition().getProperty(DEFAULT_URI_PROPNAME);
46             // TODO : inverse this check if this code is moved to AbstractAdminModule
47
if (defaultPublicURI == null) {
48                 throw new RegisterException("Can't register module " + getName() + ", " + DEFAULT_URI_PROPNAME + " property is not set.");
49             }
50             setupDefaultPublicUri(defaultPublicURI);
51         }
52     }
53
54     private void setupDefaultPublicUri(final String JavaDoc defaultPublicURI) throws RegisterException {
55         try {
56             final Content defaultUriNode = ContentUtil.getContent(ContentRepository.CONFIG, DEFAULT_URI_NODEPATH);
57             final NodeData toUriData = defaultUriNode.getNodeData(VirtualURIManager.TO_URI_NODEDATANAME);
58             toUriData.setValue(defaultPublicURI);
59             toUriData.save();
60         } catch (javax.jcr.RepositoryException e) {
61             throw new RegisterException("Could not change the default URI: " + e.getMessage(), e);
62         }
63     }
64
65     private boolean isPublicInstance() {
66         final String JavaDoc isAdmin = NodeDataUtil.getString(ContentRepository.CONFIG, SERVER_ADMIN_NODEPATH);
67         return !("true".equalsIgnoreCase(isAdmin));
68     }
69 }
70
Popular Tags