diff options
author | Henri Sara <hesara@vaadin.com> | 2015-09-23 16:28:28 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-09-28 07:16:02 +0000 |
commit | 1011cff7e8139cd1b7138b2e538264c755c7482f (patch) | |
tree | 58d0ff473452a7dc725e5df8cc6a2b20a3943645 /server/src/com/vaadin/ui | |
parent | a85e221774b5b4936a886005ec64d0d07a5c63f8 (diff) | |
download | vaadin-framework-1011cff7e8139cd1b7138b2e538264c755c7482f.tar.gz vaadin-framework-1011cff7e8139cd1b7138b2e538264c755c7482f.zip |
Use "vaadin-" as default prefix for Design (#18957)
Change-Id: Ic9e0650e5c8e305258cbce033c4ef3f33307bf0f
Diffstat (limited to 'server/src/com/vaadin/ui')
-rw-r--r-- | server/src/com/vaadin/ui/declarative/Design.java | 6 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/declarative/DesignContext.java | 90 |
2 files changed, 78 insertions, 18 deletions
diff --git a/server/src/com/vaadin/ui/declarative/Design.java b/server/src/com/vaadin/ui/declarative/Design.java index 63a2638423..8405160661 100644 --- a/server/src/com/vaadin/ui/declarative/Design.java +++ b/server/src/com/vaadin/ui/declarative/Design.java @@ -193,7 +193,7 @@ public class Design implements Serializable { ComponentFactory componentFactory, DesignContext context) { // Extract the package and class names. // Otherwise, get the full class name using the prefix to package - // mapping. Example: "v-vertical-layout" -> + // mapping. Example: "vaadin-vertical-layout" -> // "com.vaadin.ui.VerticalLayout" String[] parts = tagName.split("-", 2); if (parts.length < 2) { @@ -211,8 +211,8 @@ public class Design implements Serializable { // Split will ignore trailing and multiple dashes but that // should be // ok - // <v-button--> will be resolved to <v-button> - // <v--button> will be resolved to <v-button> + // <vaadin-button--> will be resolved to <vaadin-button> + // <vaadin--button> will be resolved to <vaadin-button> className += SharedUtil.capitalize(classNamePart); } String qualifiedClassName = packageName + "." + className; diff --git a/server/src/com/vaadin/ui/declarative/DesignContext.java b/server/src/com/vaadin/ui/declarative/DesignContext.java index 0d68c22ea0..39a30de534 100644 --- a/server/src/com/vaadin/ui/declarative/DesignContext.java +++ b/server/src/com/vaadin/ui/declarative/DesignContext.java @@ -30,6 +30,9 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import com.vaadin.annotations.DesignRoot; +import com.vaadin.server.Constants; +import com.vaadin.server.DeploymentConfiguration; +import com.vaadin.server.VaadinService; import com.vaadin.ui.Component; import com.vaadin.ui.HasComponents; import com.vaadin.ui.declarative.Design.ComponentFactory; @@ -39,13 +42,25 @@ import com.vaadin.ui.declarative.Design.ComponentMapper; * This class contains contextual information that is collected when a component * tree is constructed based on HTML design template. This information includes * mappings from local ids, global ids and captions to components , as well as a - * mapping between prefixes and package names (such as "v" -> "com.vaadin.ui"). + * mapping between prefixes and package names (such as "vaadin" -> + * "com.vaadin.ui"). + * + * Versions prior to 7.6 use "v" as the default prefix. Versions starting with + * 7.6 support reading designs with either "v" or "vaadin" as the prefix, but + * only write "vaadin" by default. Writing with the legacy prefix can be + * activated with the property or context parameter + * {@link Constants#SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX}. * * @since 7.4 * @author Vaadin Ltd */ public class DesignContext implements Serializable { + private static final String LEGACY_PREFIX = "v"; + private static final String VAADIN_PREFIX = "vaadin"; + + private static final String VAADIN_UI_PACKAGE = "com.vaadin.ui"; + // cache for object instances private static Map<Class<?>, Component> instanceCache = new ConcurrentHashMap<Class<?>, Component>(); @@ -67,23 +82,24 @@ public class DesignContext implements Serializable { // namespace mappings private Map<String, String> packageToPrefix = new HashMap<String, String>(); private Map<String, String> prefixToPackage = new HashMap<String, String>(); - // prefix names for which no package-mapping element will be created in the - // html tree (this includes at least "v" which is always taken to refer - // to "com.vaadin.ui". - private Map<String, String> defaultPrefixes = new HashMap<String, String>(); // component creation listeners private List<ComponentCreationListener> listeners = new ArrayList<ComponentCreationListener>(); private ShouldWriteDataDelegate shouldWriteDataDelegate = ShouldWriteDataDelegate.DEFAULT; + // this cannot be static because of testability issues + private Boolean legacyDesignPrefix = null; + public DesignContext(Document doc) { this.doc = doc; // Initialize the mapping between prefixes and package names. - defaultPrefixes.put("v", "com.vaadin.ui"); - for (String prefix : defaultPrefixes.keySet()) { - String packageName = defaultPrefixes.get(prefix); - addPackagePrefix(prefix, packageName); + if (isLegacyPrefixEnabled()) { + addPackagePrefix(LEGACY_PREFIX, VAADIN_UI_PACKAGE); + prefixToPackage.put(VAADIN_PREFIX, VAADIN_UI_PACKAGE); + } else { + addPackagePrefix(VAADIN_PREFIX, VAADIN_UI_PACKAGE); + prefixToPackage.put(LEGACY_PREFIX, VAADIN_UI_PACKAGE); } } @@ -259,9 +275,14 @@ public class DesignContext implements Serializable { /** * Creates a two-way mapping between a prefix and a package name. * + * Note that modifying the mapping for {@value #VAADIN_UI_PACKAGE} may + * invalidate the backwards compatibility mechanism supporting reading such + * components with either {@value #LEGACY_PREFIX} or {@value #VAADIN_PREFIX} + * as prefix. + * * @param prefix - * the prefix name without an ending dash (for instance, "v" is - * by default used for "com.vaadin.ui") + * the prefix name without an ending dash (for instance, "vaadin" + * is by default used for "com.vaadin.ui") * @param packageName * the name of the package corresponding to prefix * @@ -288,7 +309,11 @@ public class DesignContext implements Serializable { * registered */ public String getPackagePrefix(String packageName) { - return packageToPrefix.get(packageName); + if (VAADIN_UI_PACKAGE.equals(packageName)) { + return isLegacyPrefixEnabled() ? LEGACY_PREFIX : VAADIN_PREFIX; + } else { + return packageToPrefix.get(packageName); + } } /** @@ -395,8 +420,8 @@ public class DesignContext implements Serializable { Element head = doc.head(); for (String prefix : getPackagePrefixes()) { // Only store the prefix-name mapping if it is not a default mapping - // (such as "v" -> "com.vaadin.ui") - if (defaultPrefixes.get(prefix) == null) { + // (such as "vaadin" -> "com.vaadin.ui") + if (!VAADIN_PREFIX.equals(prefix) && !LEGACY_PREFIX.equals(prefix)) { Node newNode = doc.createElement("meta"); newNode.attr("name", "package-mapping"); String prefixToPackageName = prefix + ":" + getPackage(prefix); @@ -407,6 +432,31 @@ public class DesignContext implements Serializable { } /** + * Check whether the legacy prefix "v" or the default prefix "vaadin" should + * be used when writing designs. The property or context parameter + * {@link Constants#SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX} can be used to + * switch to the legacy prefix. + * + * @since + * @return true to use the legacy prefix, false by default + */ + protected boolean isLegacyPrefixEnabled() { + if (legacyDesignPrefix != null) { + return legacyDesignPrefix.booleanValue(); + } + if (VaadinService.getCurrent() == null) { + // This will happen at least in JUnit tests. + return false; + } + DeploymentConfiguration configuration = VaadinService.getCurrent() + .getDeploymentConfiguration(); + legacyDesignPrefix = configuration.getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX, "false") + .equals("true"); + return legacyDesignPrefix.booleanValue(); + } + + /** * Creates an html tree node corresponding to the given element. Also * initializes its attributes by calling writeDesign. As a result of the * writeDesign() call, this method creates the entire subtree rooted at the @@ -511,11 +561,21 @@ public class DesignContext implements Serializable { Component component = componentMapper.tagToComponent(tag, Design.getComponentFactory(), this); - assert tag.equals(componentMapper.componentToTag(component, this)); + assert tagEquals(tag, componentMapper.componentToTag(component, this)); return component; } + private boolean tagEquals(String tag1, String tag2) { + return tag1.equals(tag2) + || (hasVaadinPrefix(tag1) && hasVaadinPrefix(tag2)); + } + + private boolean hasVaadinPrefix(String tag) { + return tag.startsWith(LEGACY_PREFIX + "-") + || tag.startsWith(VAADIN_PREFIX + "-"); + } + /** * Instantiates given class via ComponentFactory. * |