package at.gv.egovernment.moa.id.auth.parser;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.w3c.dom.Element;
import at.gv.egovernment.moa.id.ParseException;
import at.gv.egovernment.moa.util.DOMUtils;
import at.gv.egovernment.moa.util.XPathUtils;
/**
* Parses an <InfoboxReadResponse>
.
*
* @author Stefan Knirsch
* @version $Id$
*/
public class ErrorResponseParser {
/** This is the root element of the XML-Document provided by the Security Layer Card */
private Element errorElement;
/**
* Constructor for InfoboxReadResponseParser.
* A DOM-representation of the incoming String will be created
* @param xmlResponse <InfoboxReadResponse>
as String
* @throws ParseException on any error
*/
public ErrorResponseParser(String xmlResponse) throws ParseException {
try {
InputStream s = new ByteArrayInputStream(xmlResponse.getBytes("UTF-8"));
errorElement = DOMUtils.parseXmlValidating(s);
}
catch (Throwable t) {
throw new ParseException("parser.01", new Object[] { t.toString()}, t);
}
}
/**
* Constructor for InfoboxReadResponseParser.
* A DOM-representation of the incoming Inputstream will be created
* @param xmlResponse <InfoboxReadResponse>
as InputStream
* @throws ParseException on any error
*/
public ErrorResponseParser(InputStream xmlResponse) throws ParseException {
try {
errorElement = DOMUtils.parseXmlValidating(xmlResponse);
}
catch (Throwable t) {
throw new ParseException("parser.01", new Object[] { t.toString() }, t);
}
}
/**
* Method getErrorCode. returns the error code
* @return String
*/
public String getErrorCode() {
String slPrefix = XPathUtils.getSlPrefix(errorElement);
StringBuffer sb = new StringBuffer("/");
sb.append(slPrefix);
sb.append(":ErrorResponse/");
sb.append(slPrefix);
sb.append(":ErrorCode");
String errorCodeXPath = sb.toString();
return XPathUtils.getElementValue(errorElement,errorCodeXPath,null);
}
/**
* Method getErrorInfo: returns the information about the error
* @return String
*/
public String getErrorInfo() {
String slPrefix = XPathUtils.getSlPrefix(errorElement);
StringBuffer sb = new StringBuffer("/");
sb.append(slPrefix);
sb.append(":ErrorResponse/");
sb.append(slPrefix);
sb.append(":Info");
String errorInfoXPath = sb.toString();
return XPathUtils.getElementValue(errorElement,errorInfoXPath,null);
}
}