You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PathFormatHelper.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.osgi.resources.impl;
  17. /**
  18. * Helper for formatting the Alias, and Theme and Widgetset names.
  19. *
  20. * @author Vaadin Ltd.
  21. *
  22. * @since 8.1
  23. */
  24. public final class PathFormatHelper {
  25. private static final String VAADIN_ROOT_ALIAS_FORMAT = "/%s/VAADIN/%s";
  26. private static final String VAADIN_ROOT_FORMAT = "/VAADIN/%s";
  27. private static final String VAADIN_THEME_ALIAS_FORMAT = "/%s/VAADIN/themes/%s";
  28. private static final String VAADIN_WIDGETSET_ALIAS_FORMAT = "/%s/VAADIN/widgetsets/%s";
  29. private static final String VAADIN_THEME_PATH_FORMAT = "/VAADIN/themes/%s";
  30. private static final String VAADIN_WIDGETSET_PATH_FORMAT = "/VAADIN/widgetsets/%s";
  31. private PathFormatHelper() {
  32. }
  33. /**
  34. * Returns the alias for the theme given a the theme name and a path prefix.
  35. *
  36. * @param themeName
  37. * the theme name
  38. * @param pathPrefix
  39. * the prefix for the /VAADIN/ folder
  40. * @return the alias
  41. */
  42. public static String getThemeAlias(String themeName, String pathPrefix) {
  43. return String.format(VAADIN_THEME_ALIAS_FORMAT, pathPrefix, themeName);
  44. }
  45. /**
  46. * Returns the expected/default path of the theme folder in the source
  47. * bundle.
  48. *
  49. * @param themeName
  50. * the name of the theme
  51. * @return the path of the theme folder in the source bundle
  52. */
  53. public static String getThemePath(String themeName) {
  54. return String.format(VAADIN_THEME_PATH_FORMAT, themeName);
  55. }
  56. /**
  57. * Returns the alias for a widgetset given a the widgetset name and a path
  58. * prefix.
  59. *
  60. * @param widgetsetName
  61. * the name of the widgetset
  62. * @param pathPrefix
  63. * the prefix for the /VAADIN/ folder
  64. * @return the alias
  65. */
  66. public static String getWidgetsetAlias(String widgetsetName,
  67. String pathPrefix) {
  68. return String.format(VAADIN_WIDGETSET_ALIAS_FORMAT, pathPrefix,
  69. widgetsetName);
  70. }
  71. /**
  72. * Returns the expected/default path of the widgetset folder in the source
  73. * bundle.
  74. *
  75. * @param widgetsetName
  76. * the name of the widgetset
  77. * @return the path of the widgetset folder in the source bundle
  78. */
  79. public static String getWidgetsetPath(String widgetsetName) {
  80. return String.format(VAADIN_WIDGETSET_PATH_FORMAT, widgetsetName);
  81. }
  82. /**
  83. * Returns the alias for a resource that will placed under the /VAADIN/
  84. * folder.
  85. *
  86. * @param resourceName
  87. * the name of the resource
  88. * @param pathPrefix
  89. * the prefix for the /VAADIN/ folder
  90. * @return the alias
  91. */
  92. public static String getRootResourceAlias(String resourceName,
  93. String pathPrefix) {
  94. return String.format(VAADIN_ROOT_ALIAS_FORMAT, pathPrefix,
  95. resourceName);
  96. }
  97. /**
  98. * Returns the expected/default path of the resource in the source bundle.
  99. *
  100. * @param resourceName
  101. * the name of the resource
  102. * @return the path of the resource in the source bundle
  103. */
  104. public static String getRootResourcePath(String resourceName) {
  105. return String.format(VAADIN_ROOT_FORMAT, resourceName);
  106. }
  107. }