1 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 31 public class SimpleContentModule extends AbstractAdminModule { 32 private static final String SERVER_ADMIN_NODEPATH = "/server/admin"; 33 private static final String DEFAULT_URI_NODEPATH = "/modules/adminInterface/virtualURIMapping/default"; 34 private static final String DEFAULT_URI_PROPNAME = "defaultPublicURI"; 35 36 protected void onInit() throws InitializationException { 37 } 39 40 protected void onRegister(int registerState) throws RegisterException { 41 super.onRegister(registerState); 42 43 if (isPublicInstance() && (registerState == REGISTER_STATE_INSTALLATION || registerState == REGISTER_STATE_NEW_VERSION)) { 45 final String defaultPublicURI = getModuleDefinition().getProperty(DEFAULT_URI_PROPNAME); 46 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 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 isAdmin = NodeDataUtil.getString(ContentRepository.CONFIG, SERVER_ADMIN_NODEPATH); 67 return !("true".equalsIgnoreCase(isAdmin)); 68 } 69 } 70 | Popular Tags |