1 package com.proalpha.pds.util;
3 import java.io.StringWriter;
4 import java.io.UnsupportedEncodingException;
5 import java.net.URLEncoder;
6 import java.util.Iterator;
8 import javax.xml.datatype.XMLGregorianCalendar;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.swt.program.Program;
14 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntryRepos;
15 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntrySrc;
19 private String objectID =
"";
20 private String checkID =
"";
21 private String subCheckID =
"";
22 private String description =
"";
23 private String srcStatement =
"";
24 private String line =
"";
25 private String module =
"";
26 private String reported;
28 public void send(ISelection selection, String paProjectName) {
30 Iterator<?> it = ((IStructuredSelection) selection).iterator();
31 StringWriter body =
new StringWriter();
33 while (it.hasNext()) {
37 if (
object instanceof TtDSLogEntrySrc) {
38 TtDSLogEntrySrc entrySrc = (TtDSLogEntrySrc)
object;
39 setObjectID(entrySrc.getSourceFileName());
40 setCheckID(entrySrc.getDSCheckID());
41 setSubCheckID(entrySrc.getDSSubCheckID());
42 setReported(entrySrc.getReportedFirst());
43 setSrcStatement(entrySrc.getStatement());
44 setLine(entrySrc.getSourceFileLine());
45 setModule(entrySrc.getModule());
46 setDescription(entrySrc.getLogEntryDescription());
47 }
else if (
object instanceof TtDSLogEntryRepos) {
48 TtDSLogEntryRepos entryRepos = (TtDSLogEntryRepos)
object;
49 setObjectID(entryRepos.getOwningID());
50 setCheckID(entryRepos.getDSCheckID());
51 setSubCheckID(entryRepos.getDSSubCheckID());
52 setReported(entryRepos.getReportedFirst());
55 setModule(entryRepos.getModule());
56 setDescription(entryRepos.getLogEntryDescription());
59 appendLine(body, getReported());
60 appendLine(body,
"CheckID:\t" + getCheckID());
61 appendLine(body,
"SubCheckID:\t" + getSubCheckID());
62 appendLine(body, getModule());
63 appendLine(body, getObjectID());
64 appendLine(body, getLine());
66 appendLine(body, getDescription());
68 appendLine(body, getSrcStatement());
71 String subject = paProjectName +
" : " + getSubCheckID() +
" (" + getCheckID() +
")";
72 String mailto =
"mailto:" +
"?subject=" + enc(subject) +
"&body=" + enc(body.toString());
73 Program.launch(mailto);
76 private void appendLine(StringWriter body, String str)
78 body.append(str).append(System.lineSeparator());
81 private String enc(String p) {
85 return URLEncoder.encode(p,
"UTF-8").replace(
"+",
"%20");
86 }
catch (UnsupportedEncodingException e) {
87 throw new RuntimeException();
94 private String getDescription() {
101 private String getModule() {
108 private String getLine() {
115 private String getObjectID() {
122 private String getReported() {
129 private String getSrcStatement() {
136 private String getSubCheckID() {
143 private String getCheckID() {
147 private void setDescription(String description) {
149 this.description =
"Description:\t" + System.lineSeparator() + description;
153 private void setModule(String module) {
155 this.module =
"Module:\t" + module;
159 private void setLine(Integer line) {
161 this.line =
"Line:\t\t" + String.valueOf(line);
165 private void setObjectID(String objectID) {
167 this.objectID =
"Object:\t\t" + objectID;
171 private void setReported(XMLGregorianCalendar calendar) {
173 this.reported =
"Reported:\t" + calendar.getDay() +
"."
174 + calendar.getMonth() +
"." + calendar.getYear();
177 private void setSrcStatement(String srcStatement) {
179 this.srcStatement =
"Code Fragment: " + System.lineSeparator() + srcStatement;
183 private void setSubCheckID(String subCheckID) {
185 this.subCheckID = subCheckID;
188 private void setCheckID(String checkID) {
190 this.checkID = checkID;