Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

LocatorUtil.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.client.componentlocator;
  17. import com.google.gwt.regexp.shared.RegExp;
  18. /**
  19. * Common String manipulator utilities used in VaadinFinderLocatorStrategy and
  20. * SelectorPredicates.
  21. *
  22. * @since 7.2
  23. * @author Vaadin Ltd
  24. */
  25. public class LocatorUtil {
  26. /**
  27. * Find first occurrence of character that's not inside quotes starting from
  28. * specified index.
  29. *
  30. * @param str
  31. * Full string for searching
  32. * @param find
  33. * Character we want to find
  34. * @param startingAt
  35. * Index where we start
  36. * @return Index of character. -1 if character not found
  37. */
  38. protected static int indexOfIgnoringQuoted(String str, char find,
  39. int startingAt) {
  40. boolean quote = false;
  41. String quoteChars = "'\"";
  42. char currentQuote = '"';
  43. for (int i = startingAt; i < str.length(); ++i) {
  44. char cur = str.charAt(i);
  45. if (quote) {
  46. if (cur == currentQuote) {
  47. quote = !quote;
  48. }
  49. continue;
  50. } else if (cur == find) {
  51. return i;
  52. } else {
  53. if (quoteChars.indexOf(cur) >= 0) {
  54. currentQuote = cur;
  55. quote = !quote;
  56. }
  57. }
  58. }
  59. return -1;
  60. }
  61. /**
  62. * Find first occurrence of character that's not inside quotes starting from
  63. * the beginning of string.
  64. *
  65. * @param str
  66. * Full string for searching
  67. * @param find
  68. * Character we want to find
  69. * @return Index of character. -1 if character not found
  70. */
  71. protected static int indexOfIgnoringQuoted(String str, char find) {
  72. return indexOfIgnoringQuoted(str, find, 0);
  73. }
  74. /**
  75. * Checks if path refers to vaadin UI element com.vaadin.ui.UI.
  76. *
  77. * @param path
  78. * to vaadin element
  79. * @return true if path refers to UI element, false otherwise
  80. */
  81. public static boolean isUIElement(String path) {
  82. String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?UI[\\/\\[]?";
  83. RegExp regexp = RegExp.compile(regex);
  84. return regexp.test(path);
  85. }
  86. /**
  87. * Checks if path refers to vaadin Notification element
  88. * com.vaadin.ui.Notification.
  89. *
  90. * @param path
  91. * to vaadin element
  92. * @return true if path refers to Notification element, false otherwise
  93. */
  94. public static boolean isNotificationElement(String path) {
  95. String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?Notification[\\/\\[]?";
  96. RegExp regexp = RegExp.compile(regex);
  97. return regexp.test(path);
  98. }
  99. }