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.

Links.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Sonar, open source software quality management tool.
  3. * Copyright (C) 2009 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * Sonar is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * Sonar is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Sonar; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.gwt;
  21. import com.google.gwt.user.client.Window;
  22. public final class Links {
  23. public static final String DEFAULT_POPUP_HTML_FEATURES = "height=800,width=900,scrollbars=1,resizable=1";
  24. private Links() {
  25. // only static methods
  26. }
  27. public static String baseUrl() {
  28. return Configuration.getParameter("sonar_url");
  29. }
  30. public static String apiUrl() {
  31. return baseUrl() + "/api";
  32. }
  33. public static String urlForResource(String resourceIdOrKey) {
  34. return urlForMeasure(resourceIdOrKey, null);
  35. }
  36. public static String urlForMeasure(String resourceIdOrKey, String metricKey) {
  37. String url = baseUrl() + "/resource/index/" + resourceIdOrKey;
  38. if (metricKey != null) {
  39. url += "?metric=" + metricKey;
  40. }
  41. return url;
  42. }
  43. /**
  44. *
  45. * @param resourceIdOrKey
  46. * @param pageId
  47. * @param query additional query parameters. Can be null. Example "layout=false&param1=val1"
  48. */
  49. public static String urlForResourcePage(String resourceIdOrKey, String pageId, String query) {
  50. String url = baseUrl() + "/plugins/resource/";
  51. if (resourceIdOrKey != null) {
  52. url += resourceIdOrKey;
  53. }
  54. url += "?page=";
  55. url += pageId;
  56. if (query != null) {
  57. url += "&";
  58. url += query;
  59. }
  60. return url;
  61. }
  62. public static String urlForRule(String ruleIdOrKey, boolean showLayout) {
  63. return baseUrl() + "/rules/show/" + ruleIdOrKey + "?layout=" + showLayout;
  64. }
  65. public static String urlForDrilldown(String resourceIdOrKey, String metricKey) {
  66. return baseUrl() + "/drilldown/measures/" + resourceIdOrKey + "?metric=" + metricKey;
  67. }
  68. public static void openResourcePopup(final String resourceIdOrKey) {
  69. openMeasurePopup(resourceIdOrKey, null);
  70. }
  71. /**
  72. * Open the resource in a popup with HTML features like: height=800,width=900,scrollbars=1,resizable=1
  73. *
  74. * @param resourceIdOrKey the id or key of the resource to display, not null
  75. * @param metricKey the metric to highlight (optional : can be null)
  76. */
  77. public static void openMeasurePopup(final String resourceIdOrKey, final String metricKey) {
  78. openMeasurePopup(resourceIdOrKey, metricKey, DEFAULT_POPUP_HTML_FEATURES);
  79. }
  80. public static void openMeasurePopup(final String resourceKey, final String metricKey, final String htmlFeatures) {
  81. String url = urlForMeasure(resourceKey, metricKey);
  82. Window.open(url, "resource", htmlFeatures);
  83. }
  84. public static void openResourcePage(final String pageId, final String resourceIdOrKey, final String query) {
  85. String url = urlForResourcePage(pageId, resourceIdOrKey, query);
  86. Window.Location.assign(url);
  87. }
  88. public static void openRulePopup(final String ruleIdOrKey) {
  89. openRulePopup(ruleIdOrKey, DEFAULT_POPUP_HTML_FEATURES);
  90. }
  91. public static void openRulePopup(final String ruleIdOrKey, final String htmlFeatures) {
  92. String url = urlForRule(ruleIdOrKey, false);
  93. Window.open(url, "rule", htmlFeatures);
  94. }
  95. }