BrightSide Workbench Full Report + Source Code
MailError.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.error;
19 
20 import org.turro.action.MailSenders;
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.elephant.context.IConstructor;
24 import org.turro.elephant.security.IUser;
25 import org.turro.mail.impl.MailReport;
26 import org.turro.plugin.contacts.IContact;
27 
32 public class MailError {
33 
34  private ErrorReport errorReport;
35  private String doing;
36  private Application app;
37 
38  public MailError(ErrorReport errorReport, String doing) {
39  this.errorReport = errorReport;
40  this.doing = doing;
41  }
42 
43  public void sendEmail(Application app) {
44  this.app = app;
45  IConstructor constructor = app.getConstructor();
47  .addUser("Support", "support@turro.org")
48  .send("Bug notification", getMessage());
49  }
50 
51  private String getMessage() {
52  MailReport report = new MailReport();
53  report.startReport();
54  report.startTitle().write("Bug notification");
55  report.endTag();
56 
57  report.startHeading1()
58  .write("BrightSide Workbench")
59  .endTag();
60 
61  report.startDetailContent();
62 
63  report.startTitle()
64  .write("Doing")
65  .endTag();
66 
67  IContact user = app.getConstructor().getUser();
68  if(user != null) {
69  report.addValueLabel("Server:");
70  report.addValue(ElephantContext.getServerUrl("http"));
71  report.addSpace();
72  report.addValueLabel("User:");
73  report.addValue(user.getName());
74  report.addSpace();
75  report.addValueLabel("Email:");
77  report.writeNewLine().writeNewLine();
78  }
79  report.addValue(doing);
80  report.writeNewLine().writeNewLine();
81 
82  report.startTitle()
83  .write("Stack trace")
84  .endTag();
85 
86  for(String s : errorReport) {
87  report.addValue(s);
88  report.writeNewLine();
89  }
90 
91  report.endAllTags();
92  return report.toString();
93  }
94 
95  public static MailError getInstance(Class jclass, Throwable error, String msg) {
96  ErrorReport errorReport = new ErrorReport(0, jclass, error.getMessage(), error, null, null);
97  return new org.turro.error.MailError(errorReport, ElephantContext.getSiteName() + ":" + msg);
98  }
99 
100 }
static IMailSender getPool()
static String getServerUrl(String scheme)
static MailError getInstance(Class jclass, Throwable error, String msg)
Definition: MailError.java:95
MailError(ErrorReport errorReport, String doing)
Definition: MailError.java:38
void sendEmail(Application app)
Definition: MailError.java:43
HTMLGenerator write(String value)
HTMLGenerator startDetailContent()
Definition: MailReport.java:82
HTMLGenerator addValue(String value)
Definition: MailReport.java:92
HTMLGenerator addValueLabel(String label)
Definition: MailReport.java:86
T addUser(String name, String email)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27
String getProperty(String key)