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.errors.ApplicationError;
\r
9 import com.indexdata.pz2utils4jsf.errors.ErrorHelper;
\r
10 import com.indexdata.pz2utils4jsf.errors.ErrorHelper.ErrorCode;
\r
11 import com.indexdata.utils.XmlUtils;
\r
14 * Captures errors encountered during the execution of a command.
\r
15 * Is parsed by Pazpar2ResponseParser, piggybacked in a (seemingly)
\r
16 * regular command respond.
\r
18 * @author Niels Erik
\r
21 public class CommandError extends Pazpar2ResponseData implements ApplicationError {
\r
23 private static final long serialVersionUID = 8878776025779714122L;
\r
24 private ErrorCode applicationErrorCode;
\r
25 private ErrorHelper errorHelper = null;
\r
28 public CommandError () {
\r
31 public String getLabel() {
\r
32 return getOneElementValue("commandname");
\r
35 public String getMessage() {
\r
36 return getOneElementValue("errormessage");
\r
39 public String getException () {
\r
40 return getOneElementValue("exception");
\r
43 public List<String> getSuggestions() {
\r
44 if (errorHelper!=null) {
\r
45 return errorHelper.getSuggestions(this);
\r
47 List<String> nohelper = new ArrayList<String>();
\r
48 nohelper.add("Tips: could not generate tips due to a programming error, error helper was not set");
\r
54 * Creates an XML string error message, embedded in an XML string document named by the command
\r
55 * @param commandName
\r
56 * @param exceptionName
\r
57 * @param errorMessage
\r
60 public static String createErrorXml (String commandName, String exceptionName, String errorMessage) {
\r
61 StringBuilder errorXml = new StringBuilder("");
\r
62 errorXml.append("<" + commandName + ">"+nl);
\r
63 errorXml.append(" <applicationerror>"+nl);
\r
64 errorXml.append(" <commandname>" + commandName + "</commandname>"+nl);
\r
65 errorXml.append(" <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl);
\r
66 errorXml.append(" <errormessage>" + XmlUtils.escape(errorMessage) + "</errormessage>"+nl);
\r
67 errorXml.append(" </applicationerror>"+nl);
\r
68 errorXml.append("</" + commandName + ">"+nl);
\r
69 return errorXml.toString();
\r
72 public void setErrorHelper (ErrorHelper errorHelper) {
\r
73 this.errorHelper = errorHelper;
\r
77 public void setApplicationErrorCode(ErrorCode code) {
\r
78 this.applicationErrorCode = code;
\r
82 public ErrorCode getApplicationErrorCode() {
\r
83 return applicationErrorCode;
\r