/api/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessage.java

https://github.com/nickarls/international · Java · 112 lines · 13 code · 9 blank · 90 comment · 0 complexity · d04c2442ca74f97e931a6546689ebe6f MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jboss.seam.international.status.builder;
  18. import org.jboss.seam.international.status.Level;
  19. import org.jboss.seam.international.status.Message;
  20. import org.jboss.seam.international.status.MessageBuilder;
  21. /**
  22. * This {@link MessageBuilder} implementation creates {@link Message} objects by loading resource bundle keys as templates with
  23. * values supplied as parameters.
  24. * <p/>
  25. * <b>For example:</b>
  26. * <p/>
  27. * Given the following {@link Message} m
  28. * <p/>
  29. * <pre>
  30. * Message m = {@link MessageFactory}.info(new {@link BundleKey}(&quot;messageBundle&quot;, &quot;keyName&quot;), 5, &quot;green&quot;)
  31. * &nbsp;&nbsp;&nbsp;.defaultText("This is default text.").build();
  32. * </pre>
  33. * <p/>
  34. * And the corresponding messageBundle.properties file:<br>
  35. * <p/>
  36. * <pre>
  37. * keyName=There are {0} cars, and they are all {1}.
  38. * </pre>
  39. * <p/>
  40. * A subsequent call to <code>m.getText()</code> will return:<br/>
  41. * <p/>
  42. * <pre>
  43. * &quot;There are 5 cars, and they are all green.&quot;
  44. * </pre>
  45. * <p/>
  46. * <b>Note:</b> If a bundle/key pair cannot be resolved, the default template will be used instead. If there is no default
  47. * template, a String representation of the {@link BundleKey} will be displayed instead.
  48. * <p/>
  49. *
  50. * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  51. * @author <a href="mailto:ssachtleben@gmail.com">Sebastian Sachtleben</a>
  52. */
  53. public interface BundleTemplateMessage extends MessageBuilder {
  54. /**
  55. * Use the given {@link BundleKey} to perform a resource lookup, resolving the template to render for this message.
  56. * <p/>
  57. * Any expressions of the form "{0}, {1} ... {N}" found in the template will be interpolated; numbers reference the index of
  58. * any given parameters, and can be used more than once per template.
  59. */
  60. public BundleTemplateMessage key(final BundleKey text);
  61. /**
  62. * Use the given {@link BundleKey} to perform a resource lookup, resolving the template to render detail text for this message.
  63. * <p/>
  64. * Any expressions of the form "{0}, {1} ... {N}" found in the template will be interpolated; numbers reference the index of
  65. * any given parameters, and can be used more than once per template.
  66. */
  67. public BundleTemplateMessage detail(final BundleKey detail);
  68. /**
  69. * Set the default template text.
  70. * <p/>
  71. * If the bundle cannot be loaded for any reason, the builder will fall back to using provided default template text; if
  72. * there is no default template, a string representation of the {@link BundleKey} will be used instead.
  73. * <p/>
  74. * Any expressions of the form "{0}, {1} ... {N}" found in the template will be interpolated; numbers reference the index of
  75. * any given parameters, and can be used more than once per template.
  76. */
  77. public BundleTemplateMessage defaults(final String text);
  78. /**
  79. * Set the parameters for this builder's template.
  80. * <p/>
  81. * Parameters may be referenced by index in the template or {@link #textDefault(String)}, using expressions of the form "
  82. * {0}, {1} ... {N}". The same parameters will be used when interpolating default text, in the case when a {@link BundleKey}
  83. * cannot be resolved.
  84. */
  85. public BundleTemplateMessage params(final Object... textParams);
  86. /**
  87. * Set the parameters for detail text of this builder's template.
  88. * <p/>
  89. * Parameters may be referenced by index in the template or {@link #textDefault(String)}, using expressions of the form "
  90. * {0}, {1} ... {N}". The same parameters will be used when interpolating default text, in the case when a {@link BundleKey}
  91. * cannot be resolved.
  92. */
  93. public BundleTemplateMessage detailParams(final Object... detailParams);
  94. /**
  95. * Set the targets for this message. If supported by the consuming view-layer, these targets may control where/how the
  96. * message is displayed to the user.
  97. */
  98. public BundleTemplateMessage targets(final String targets);
  99. /**
  100. * Set the severity, level of importance of this message.
  101. */
  102. public BundleTemplateMessage level(final Level level);
  103. }