001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bstefanescu 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.webengine.model.impl; 021 022import java.io.File; 023import java.util.ArrayList; 024import java.util.HashSet; 025import java.util.List; 026import java.util.Set; 027 028import org.nuxeo.common.xmap.annotation.XNode; 029import org.nuxeo.common.xmap.annotation.XNodeList; 030import org.nuxeo.common.xmap.annotation.XObject; 031import org.nuxeo.ecm.webengine.ResourceBinding; 032import org.nuxeo.ecm.webengine.WebEngine; 033import org.nuxeo.ecm.webengine.app.WebEngineModule; 034import org.nuxeo.ecm.webengine.model.LinkDescriptor; 035import org.nuxeo.ecm.webengine.model.Module; 036import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException; 037 038/** 039 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 040 */ 041@XObject("module") 042public class ModuleConfiguration implements Cloneable { 043 044 /** 045 * A web module may have multiple roots 046 * 047 * @deprecated you should use new module definition - through {@link WebEngineModule} 048 */ 049 @Deprecated 050 @XNode("@path") 051 public String path; 052 053 /** 054 * @deprecated you should use new module definition - through {@link WebEngineModule} 055 */ 056 @Deprecated 057 @XNode("@root-type") 058 public String rootType; 059 060 /** 061 * Paths of root resources in the module. This is replacing the deprecated root-type. 062 */ 063 public Class<?>[] roots; 064 065 @XNode("@extends") 066 public String base; 067 068 @XNode("@name") 069 public String name; 070 071 /** 072 * Use module links instead. If a module doesn't declare a module item it will be headless by default. Still used 073 * for compatibility mode - for those modules not yet using moduleItems. 074 */ 075 @Deprecated 076 @XNode("@headless") 077 public boolean isHeadless; 078 079 /** 080 * A list of entry points into the module - to be shown in the main webengine page. This is optional and may be 081 * ignored if your don't want to provide shortcuts to your module entry points. 082 */ 083 @XNodeList(value = "shortcuts/shortcut", type = ArrayList.class, componentType = ModuleShortcut.class, nullByDefault = true) 084 public List<ModuleShortcut> moduleShortcuts; 085 086 /** 087 * Web Types explicitly declared. If null no web types were explicitly declared and old type loading method from the 088 * generated web-types file should be used. 089 */ 090 public Class<?>[] types; 091 092 /** 093 * The module directory. Must be set by the client before registering the descriptor. 094 */ 095 @XNode("home") 096 public File directory; 097 098 @XNodeList(value = "fragments/directory", type = ArrayList.class, componentType = File.class, nullByDefault = false) 099 public List<File> fragmentDirectories = new ArrayList<File>(); 100 101 /** 102 * The module configuration file (this will be set by the module config parser) 103 */ 104 public File file; 105 106 @XNodeList(value = "nature", type = HashSet.class, componentType = String.class, nullByDefault = true) 107 public Set<String> natures; 108 109 @XNodeList(value = "links/link", type = ArrayList.class, componentType = LinkDescriptor.class, nullByDefault = true) 110 public List<LinkDescriptor> links; 111 112 /** 113 * @deprecated resources are deprecated - you should use a jax-rs application to declare more resources. 114 */ 115 @XNodeList(value = "resources/resource", type = ArrayList.class, componentType = ResourceBinding.class, nullByDefault = true) 116 public List<ResourceBinding> resources; 117 118 @XNode("templateFileExt") 119 public String templateFileExt = "ftl"; 120 121 @XNodeList(value = "media-types/media-type", type = MediaTypeRef[].class, componentType = MediaTypeRef.class, nullByDefault = true) 122 public MediaTypeRef[] mediatTypeRefs; 123 124 public WebEngine engine; 125 126 private ModuleImpl module; 127 128 public boolean allowHostOverride; 129 130 public ModuleConfiguration() { 131 } 132 133 public ModuleConfiguration(WebEngine engine) { 134 this.engine = engine; 135 } 136 137 public WebEngine getEngine() { 138 return engine; 139 } 140 141 public void setEngine(WebEngine engine) { 142 this.engine = engine; 143 } 144 145 public String getName() { 146 return name; 147 } 148 149 public List<ModuleShortcut> getShortcuts() { 150 return moduleShortcuts; 151 } 152 153 public List<LinkDescriptor> getLinks() { 154 return links; 155 } 156 157 public File getDirectory() { 158 return directory; 159 } 160 161 public String getBase() { 162 return base; 163 } 164 165 /** 166 * @deprecated you should use new module definition - through {@link WebEngineModule} 167 */ 168 @Deprecated 169 public String getPath() { 170 return path; 171 } 172 173 public Module get() { 174 if (module == null) { 175 Module superModule = null; 176 if (base != null) { // make sure super modules are resolved 177 ModuleConfiguration superM = engine.getModuleManager().getModule(base); 178 if (superM == null) { 179 throw new WebResourceNotFoundException("The module '" + name 180 + "' cannot be loaded since it's super module '" + base + "' cannot be found"); 181 } 182 // force super module loading 183 superModule = superM.get(); 184 } 185 module = new ModuleImpl(engine, (ModuleImpl) superModule, this); 186 } 187 return module; 188 } 189 190 public boolean isLoaded() { 191 return module != null; 192 } 193 194 public boolean isHeadless() { 195 return isHeadless; 196 } 197 198}