This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/master by this push:
new abe10e0906 CAUSEWAY-3402: demo: arbitrary 1000 character limit for on
error mailTo body
abe10e0906 is described below
commit abe10e090680f07c1cf4234912ba52be7908429e
Author: andi-huber <[email protected]>
AuthorDate: Thu Apr 13 16:38:21 2023 +0200
CAUSEWAY-3402: demo: arbitrary 1000 character limit for on error mailTo
body
- adding some comments:
The mailTo link has an arbitrary 1000 character limit for the mailTo
body.
For production, one would implement a more sophisticated error reporting
feature, that sends e-mails directly from the server.
---
.../applib/services/error/SimpleTicket.java | 26 ++++++++++-----
.../core/errorreportingservice/EmailTicket.java | 37 ++++++++++++++--------
2 files changed, 42 insertions(+), 21 deletions(-)
diff --git
a/api/applib/src/main/java/org/apache/causeway/applib/services/error/SimpleTicket.java
b/api/applib/src/main/java/org/apache/causeway/applib/services/error/SimpleTicket.java
index 1f069a8e49..62fed5acd1 100644
---
a/api/applib/src/main/java/org/apache/causeway/applib/services/error/SimpleTicket.java
+++
b/api/applib/src/main/java/org/apache/causeway/applib/services/error/SimpleTicket.java
@@ -19,12 +19,15 @@
package org.apache.causeway.applib.services.error;
import java.io.Serializable;
+import java.util.Map;
import java.util.function.UnaryOperator;
import org.apache.causeway.commons.internal.base._Strings;
import static org.apache.causeway.commons.internal.base._NullSafe.isEmpty;
+import lombok.val;
+
/**
* Response from the {@link ErrorReportingService}, containing information to
show to the end-user.
*
@@ -114,14 +117,21 @@ public class SimpleTicket implements Ticket {
@Override
public String getMarkup() {
- return
- "<p>" +
- ifPresentMap(getDetails(), s->"<h3>" + htmlEscape(s) +
"</h3>") +
- ifPresentMap(getKittenUrl(), s->"<img src=\"" + s +
"\"></img>") +
- "</p>" +
- ifPresentMap(getReference(), s->
- "<p><h4>Please quote reference: <span>" + htmlEscape(s) +
"</span></h4></p>")
- ;
+
+ val messageProperties = Map.<String, Object>of(
+ "title", ifPresentMap(getDetails(),
+ details->"<h3>" + htmlEscape(details) + "</h3>"),
+ "kittenImg", ifPresentMap(getKittenUrl(),
+ kittenUrl->"<img src=\"" + kittenUrl + "\"></img>"),
+ "referenceParagraph", ifPresentMap(getReference(),
+ reference->"<p><h4>Please quote reference: <span>"
+ + htmlEscape(reference)
+ + "</span></h4></p>"));
+
+ return _Strings.format(
+ "<p>${title}${kittenImg}</p>"
+ + "${referenceParagraph}",
+ messageProperties);
}
protected static String ifPresentMap(final String x, final
UnaryOperator<String> operator) {
diff --git
a/examples/demo/domain/src/main/java/demoapp/dom/services/core/errorreportingservice/EmailTicket.java
b/examples/demo/domain/src/main/java/demoapp/dom/services/core/errorreportingservice/EmailTicket.java
index 199991e092..82e34f5955 100644
---
a/examples/demo/domain/src/main/java/demoapp/dom/services/core/errorreportingservice/EmailTicket.java
+++
b/examples/demo/domain/src/main/java/demoapp/dom/services/core/errorreportingservice/EmailTicket.java
@@ -39,8 +39,11 @@ import lombok.val;
* <p>
* Implementation notes:
* <ul>
- * <li>a class has been used here so that additional fields might be
added in the future.</li>
- * <li>the class is {@link Serializable}</li> so that it can be stored
by the Wicket viewer as a Wicket model.
+ * <li>The mailTo link has an arbitrary 1000 character limit for the
mailTo body.
+ * For production, one would implement a more sophisticated error
reporting feature,
+ * that sends e-mails directly from the server.</li>
+ * <li>A class has been used here so that additional fields might be
added in the future.</li>
+ * <li>The class is {@link Serializable}</li> so that it can be stored
by the Wicket viewer as a Wicket model.
* </ul>
* </p>
*/
@@ -62,12 +65,17 @@ public class EmailTicket extends SimpleTicket {
@Builder.Default
private String body = "empty body";
+ /**
+ * @implNote this is just a demo;
+ * the body message is truncated at the 1000th character
+ * due to potential browser limitations
+ */
public String toHtmlLink() {
val messageProperties = Map.<String, Object>of(
"receiver", receiver,
"subject", htmlEscape(subject),
- "body", htmlEscape(body),
+ "body", htmlEscape(_Strings.ellipsifyAtEnd(body, 1000,
"... truncated")),
"linkName", linkName);
return _Strings.format("<a href=\"mailto:${receiver}"
@@ -115,16 +123,19 @@ public class EmailTicket extends SimpleTicket {
@Override
public String getMarkup() {
- return
- "<p>" +
- ifPresentMap(getDetails(), s->"<h3>" + htmlEscape(s) +
"</h3>") +
- ifPresentMap(getKittenUrl(), s->"<img src=\"" + s +
"\"></img>") +
- "</p>" +
- ifPresentMap(getReference(), s->
- "<p><h4>Please report this error: <span>" +
mailTo.toHtmlLink() + "</span></h4></p>")
- ;
- }
-
+ val messageProperties = Map.<String, Object>of(
+ "title", ifPresentMap(getDetails(),
+ details->"<h3>" + htmlEscape(details) + "</h3>"),
+ "kittenImg", ifPresentMap(getKittenUrl(),
+ kittenUrl->"<img src=\"" + kittenUrl + "\"></img>"),
+ "mailToParagraph", "<p><h4>Please report this error: <span>"
+ + mailTo.toHtmlLink()
+ + "</span></h4></p>");
+ return _Strings.format(
+ "<p>${title}${kittenImg}</p>"
+ + "${mailToParagraph}",
+ messageProperties);
+ }
}