From 235241ec5f18ad26c013b091887ce5f651462553 Mon Sep 17 00:00:00 2001 From: "harald.bratko" Date: Fri, 2 Sep 2005 16:01:29 +0000 Subject: Redesigned because response has been parsed twice. git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@490 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../moa/id/auth/parser/ErrorResponseParser.java | 92 +++++++++------------- 1 file changed, 37 insertions(+), 55 deletions(-) (limited to 'id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java') diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java index 7084faf1f..8edeec8ae 100644 --- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java +++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java @@ -1,89 +1,71 @@ package at.gv.egovernment.moa.id.auth.parser; -import java.io.ByteArrayInputStream; -import java.io.InputStream; +import java.util.List; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import at.gv.egovernment.moa.id.ParseException; import at.gv.egovernment.moa.util.DOMUtils; -import at.gv.egovernment.moa.util.XPathUtils; /** - * Parses an <InfoboxReadResponse>. + * Parses an <ErrorResponse>. * * @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 + * The error code included in this error response. + * 1000 is used as default value, if some problems occur on + * evaluating the error response. */ - 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); - } - } + private String errorCode_ = "1000"; + + /** + * The error info included in this error response. + * <Unklassifizierter Fehler.> is used as default value, + * if some problems occur on evaluating the error response. + */ + private String errorInfo_ = "Unklassifizierter Fehler."; + /** - * Constructor for InfoboxReadResponseParser. - * A DOM-representation of the incoming Inputstream will be created - * @param xmlResponse <InfoboxReadResponse> as InputStream - * @throws ParseException on any error + * This Constructor extracts the error code and error info included in this + * error response. + * + * @param errorElement The error element. This is the root element of + * the error response. */ - public ErrorResponseParser(InputStream xmlResponse) throws ParseException { - try { - errorElement = DOMUtils.parseXmlValidating(xmlResponse); - } - catch (Throwable t) { - throw new ParseException("parser.01", new Object[] { t.toString() }, t); + public ErrorResponseParser(Element errorElement) throws ParseException { + if (errorElement != null) { + String namespace = errorElement.getNamespaceURI(); + NodeList nl = errorElement.getElementsByTagNameNS(namespace, "ErrorCode"); + if (nl.getLength() == 1) { + errorCode_ = ((Element)nl.item(0)).getFirstChild().getNodeValue(); + } + nl = errorElement.getElementsByTagNameNS(namespace, "Info"); + if (nl.getLength() == 1) { + errorInfo_ = ((Element)nl.item(0)).getFirstChild().getNodeValue(); + } } } /** - * Method getErrorCode. returns the error code - * @return String + * Returns the error code included in this error response. */ 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); - + return errorCode_ ; } /** - * Method getErrorInfo: returns the information about the error - * @return String + * Returns the information included in this error response. + * @return */ 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); - + return errorInfo_ ; } -- cgit v1.2.3