1 package com.indexdata.pz2utils4jsf.pazpar2.data;
\r
3 import static com.indexdata.pz2utils4jsf.utils.Utils.nl;
\r
5 import java.util.ArrayList;
\r
6 import java.util.List;
\r
8 import com.indexdata.pz2utils4jsf.pazpar2.ApplicationTroubleshooter;
\r
9 import com.indexdata.utils.XmlUtils;
\r
11 public class ApplicationError extends Pazpar2ResponseData {
\r
13 private static final long serialVersionUID = 8878776025779714122L;
\r
14 private ApplicationTroubleshooter errorHelper = null;
\r
17 public ApplicationError () {
\r
20 public String getCommandName() {
\r
21 return getOneElementValue("commandname");
\r
24 public String getErrorMessage() {
\r
25 return getOneElementValue("errormessage");
\r
28 public String getException () {
\r
29 return getOneElementValue("exception");
\r
32 public List<String> getSuggestions() {
\r
33 if (errorHelper!=null) {
\r
34 return errorHelper.getSuggestions(getCommandName(), getErrorMessage());
\r
36 List<String> nohelper = new ArrayList<String>();
\r
37 nohelper.add("Tips: could not generate tips due to a programming error, error helper was not set");
\r
43 * Creates an XML string error message, embedded in an XML string document named by the command
\r
44 * @param commandName
\r
45 * @param exceptionName
\r
46 * @param errorMessage
\r
49 public static String createErrorXml (String commandName, String exceptionName, String errorMessage) {
\r
50 StringBuilder errorXml = new StringBuilder("");
\r
51 errorXml.append("<" + commandName + ">"+nl);
\r
52 errorXml.append(" <applicationerror>"+nl);
\r
53 errorXml.append(" <commandname>" + commandName + "</commandname>");
\r
54 errorXml.append(" <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl);
\r
55 errorXml.append(" <errormessage>" + XmlUtils.escape(errorMessage) + "</errormessage>"+nl);
\r
56 errorXml.append(" </applicationerror>"+nl);
\r
57 errorXml.append("</" + commandName + ">"+nl);
\r
58 return errorXml.toString();
\r
61 public void setTroubleshooter (ApplicationTroubleshooter errorHelper) {
\r
62 this.errorHelper = errorHelper;
\r