/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/registry/PortletEntityIdStringUtils.java

https://github.com/Jasig/uPortal · Java · 97 lines · 44 code · 13 blank · 40 comment · 1 complexity · e61c4713e9c15ecc5c7581fb88046b5a MD5 · raw file

  1. /**
  2. * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
  3. * distributed with this work for additional information regarding copyright ownership. Apereo
  4. * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use
  5. * this file except in compliance with the License. You may obtain a copy of the License at the
  6. * following location:
  7. *
  8. * <p>http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * <p>Unless required by applicable law or agreed to in writing, software distributed under the
  11. * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. package org.apereo.portal.portlet.registry;
  16. import java.util.regex.Pattern;
  17. /**
  18. * Utility class for defining methods to be used for dealing with portlet entity ID strings.
  19. *
  20. * <p>A portlet entity ID string consists of three parts separated by underscores. The format is:
  21. * <portlet-entity-id>_<layout-node-id>_<user-id>
  22. *
  23. * <p>Examples: 88_n149_52 71_u54_12
  24. *
  25. * <p>Note that if a portlet has a 'delegate' portlet, then the 'layout-node-id' will have the
  26. * format: dlg-<delegate-portlet-window-id-with-underscores-replaced-by-dashes>
  27. *
  28. * <p>Examples: 90_dlg-5-ctf1-18_18 // here the portlet window ID of the delegate portlet is:
  29. * 5_ctf1_18 75_dlg-10-ctf2-32.tw_32 // here the portlet entity ID of the delegate portlet is:
  30. * 10_ctf2_32.tw
  31. *
  32. * <p>Currently, the admin interface uses Spring Webflow with 'delegate' portlets to display portlet
  33. * configuration views. When the admin interface portlet content is fetched with an 'exclusive'
  34. * window state URL, the layout node ID includes the "tw" transient (stateless) window instance ID.
  35. * This behavior was observed with RespondrJS UI using 'exclusive' window state URLs.
  36. *
  37. * @see flows/edit-portlet/configMode.jsp
  38. * @see org.apereo.portal.portlet.delegation.*
  39. * @see https://issues.jasig.org/browse/UP-2563
  40. * @see PortletWindowIdStringUtils
  41. * @see PortletWindowRegistryImpl#STATELESS_PORTLET_WINDOW_ID
  42. */
  43. public class PortletEntityIdStringUtils {
  44. private static final char ID_PART_SEPARATOR = '_';
  45. private static final Pattern ID_PART_SEPARATOR_PATTERN =
  46. Pattern.compile(Pattern.quote(String.valueOf(ID_PART_SEPARATOR)));
  47. private static final char DELEGATE_LAYOUT_NODE_ID_SEPARATOR = '-';
  48. private static final String DELEGATE_LAYOUT_NODE_ID_PREFIX =
  49. "dlg" + DELEGATE_LAYOUT_NODE_ID_SEPARATOR;
  50. public static String format(
  51. final String portletDefinitionId, final String layoutNodeId, final int userId) {
  52. return portletDefinitionId + ID_PART_SEPARATOR + layoutNodeId + ID_PART_SEPARATOR + userId;
  53. }
  54. public static String format(
  55. final String portletDefinitionId, final String layoutNodeId, final String userId) {
  56. return portletDefinitionId + ID_PART_SEPARATOR + layoutNodeId + ID_PART_SEPARATOR + userId;
  57. }
  58. public static String convertToDelegateLayoutNodeId(final String portletEntityIdString) {
  59. return DELEGATE_LAYOUT_NODE_ID_PREFIX
  60. + portletEntityIdString.replace(
  61. ID_PART_SEPARATOR, DELEGATE_LAYOUT_NODE_ID_SEPARATOR);
  62. }
  63. public static boolean isDelegateLayoutNode(final String layoutNodeId) {
  64. return layoutNodeId.startsWith(DELEGATE_LAYOUT_NODE_ID_PREFIX);
  65. }
  66. public static boolean hasCorrectNumberOfParts(final String portletEntityIdString) {
  67. return parseParts(portletEntityIdString).length == 3;
  68. }
  69. public static String parsePortletDefinitionId(final String portletEntityIdString) {
  70. final String[] parts = parseParts(portletEntityIdString);
  71. return parts.length > 0 ? parts[0] : null;
  72. }
  73. public static String parseLayoutNodeId(final String portletEntityIdString) {
  74. final String[] parts = parseParts(portletEntityIdString);
  75. return parts.length > 1 ? parts[1] : null;
  76. }
  77. public static String parseUserIdAsString(final String portletEntityIdString) {
  78. final String[] parts = parseParts(portletEntityIdString);
  79. return parts.length > 2 ? parts[2] : null;
  80. }
  81. private static String[] parseParts(final String portletEntityIdString) {
  82. return ID_PART_SEPARATOR_PATTERN.split(portletEntityIdString);
  83. }
  84. }