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.Constants;
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 {
//
// XPath namespace prefix shortcuts
//
/** Xpath prefix for reaching SecurityLayer 1.0 Namespaces */
private static final String SL10 = Constants.SL10_PREFIX + ":";
/** Xpath expression to the root element */
private static final String ROOT = "/" + SL10 + "ErrorResponse/";
/** Xpath expression to the ErrorCode element */
private static final String ERROR_CODE_XPATH =
ROOT + SL10 + "ErrorCode";
/** Xpath expression to the Info element */
private static final String ERROR_INFO_XPATH =
ROOT + SL10 + "Info";
/** 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() {
return XPathUtils.getElementValue(errorElement,ERROR_CODE_XPATH,null);
}
/**
* Method getErrorInfo: returns the information about the error
* @return String
*/
public String getErrorInfo() {
return XPathUtils.getElementValue(errorElement,ERROR_INFO_XPATH,null);
}
}