From 578ad0d6bc408edf9e6c875156054374f5fd8337 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Mon, 22 Mar 2021 18:40:26 +0100 Subject: change to EGIZ codestyle --- .../moa/spss/api/xmlbind/ResponseBuilderUtils.java | 601 +++++++++++---------- 1 file changed, 307 insertions(+), 294 deletions(-) (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/ResponseBuilderUtils.java') diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/ResponseBuilderUtils.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/ResponseBuilderUtils.java index a7113fd..dff1fcc 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/ResponseBuilderUtils.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/ResponseBuilderUtils.java @@ -21,16 +21,14 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moa.spss.api.xmlbind; import java.io.IOException; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; -import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import java.util.Calendar; import java.util.TimeZone; import javax.xml.bind.DatatypeConverter; @@ -44,8 +42,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import iaik.utils.RFC2253NameParser; -import iaik.utils.RFC2253NameParserException; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.MOASystemException; import at.gv.egovernment.moa.spss.api.common.ExtendedCertificateCheckResult; @@ -53,10 +49,12 @@ import at.gv.egovernment.moa.spss.api.common.TslInfos; import at.gv.egovernment.moaspss.util.Base64Utils; import at.gv.egovernment.moaspss.util.Constants; import at.gv.egovernment.moaspss.util.MiscUtil; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; /** * Utility methods used by the verious ResponseBuilder classes. - * + * * @author Patrick Peck * @version $Id$ */ @@ -71,35 +69,35 @@ public class ResponseBuilderUtils { /** * Add an DOM element with a specific name as child to a root element - * + * * @param elementName Name of the DOM element - * @param response Full document with namespace information + * @param response Full document with namespace information * @param rootElement Root element * @return new child DOM element */ public static Element addChildElement(String elementName, Document response, - Element rootElement) { - Element childElement = response.createElementNS(MOA_NS_URI, elementName); - rootElement.appendChild(childElement); - return childElement; - + Element rootElement) { + final Element childElement = response.createElementNS(MOA_NS_URI, elementName); + rootElement.appendChild(childElement); + return childElement; + } - + /** * Create a response element with all the namespaces set. - * + * * @param responseName The name of the response root element. * @return A DOM document containing the response root element and predefined - * MOA, DSIG and XML namespace declarations. + * MOA, DSIG and XML namespace declarations. * @throws MOASystemException An error building the response document. */ public static Document createResponse(String responseName) - throws MOASystemException { + throws MOASystemException { try { - DocumentBuilder docBuilder = - DocumentBuilderFactory.newInstance().newDocumentBuilder(); - DOMImplementation impl = docBuilder.getDOMImplementation(); + final DocumentBuilder docBuilder = + DocumentBuilderFactory.newInstance().newDocumentBuilder(); + final DOMImplementation impl = docBuilder.getDOMImplementation(); Document response; Element root; String attrValue; @@ -113,159 +111,170 @@ public class ResponseBuilderUtils { root.setAttributeNS(XMLNS_NS_URI, attrValue, DSIG_NS_URI); return response; - } catch (ParserConfigurationException e) { + } catch (final ParserConfigurationException e) { throw new MOASystemException("2200", null, e); } } /** * Add a SignerInfo element to the response. - * - * @param response The response document, in order to create new elements in - * it. - * @param root The root element into which the SignerInfo element - * will be inserted. - * @param cert The signer certificate to add. - * @param isQualified Indicates, whether cert is a qualified - * certificate. - * @param isPublicAuthority Indicates, whether cert is - * certificate owned by a public authority. + * + * @param response The response document, in order to create new + * elements in it. + * @param root The root element into which the + * SignerInfo element will be inserted. + * @param cert The signer certificate to add. + * @param isQualified Indicates, whether cert is a qualified + * certificate. + * @param isPublicAuthority Indicates, whether cert is certificate + * owned by a public authority. * @param publicAuthorityID Information about the public authority owning - * cert. Must not be null, if - * isPublicAuthority ! = null. + * cert. Must not be null, if + * isPublicAuthority ! = null. * @throws MOAApplicationException An error occurred reading data from the - * certificate. + * certificate. */ public static void addSignerInfo( - Document response, - Element root, - X509Certificate cert, - boolean isQualified, - String qcSource, - boolean isPublicAuthority, - String publicAuthorityID, - boolean isSSCD, - String sscdSource, - String issuerCountryCode, - TslInfos tslInfos) - throws MOAApplicationException { - - Element signerInfoElem = response.createElementNS(MOA_NS_URI, "SignerInfo"); - Element x509DataElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509Data"); - Element x509IssuerSerialElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509IssuerSerial"); - Element x509IssuerElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509IssuerName"); - String issuer = cert.getIssuerDN().getName(); - Element x509SerialNumberElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509SerialNumber"); - String serialNumber = cert.getSerialNumber().toString(); - Element x509SubjectNameElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509SubjectName"); - Element x509CertificateElem = - response.createElementNS(DSIG_NS_URI, DSIG + "X509Certificate"); - Element qualifiedCertificateElem = - isQualified - ? response.createElementNS(MOA_NS_URI, "QualifiedCertificate") - : null; - Element sscdElem = - isSSCD - ? response.createElementNS(MOA_NS_URI, "SecureSignatureCreationDevice") - : null; + Document response, + Element root, + X509Certificate cert, + boolean isQualified, + String qcSource, + boolean isPublicAuthority, + String publicAuthorityID, + boolean isSSCD, + String sscdSource, + String issuerCountryCode, + TslInfos tslInfos) + throws MOAApplicationException { + + final Element signerInfoElem = response.createElementNS(MOA_NS_URI, "SignerInfo"); + final Element x509DataElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509Data"); + final Element x509IssuerSerialElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509IssuerSerial"); + final Element x509IssuerElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509IssuerName"); + final String issuer = cert.getIssuerDN().getName(); + final Element x509SerialNumberElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509SerialNumber"); + final String serialNumber = cert.getSerialNumber().toString(); + final Element x509SubjectNameElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509SubjectName"); + final Element x509CertificateElem = + response.createElementNS(DSIG_NS_URI, DSIG + "X509Certificate"); + final Element qualifiedCertificateElem = + isQualified + ? response.createElementNS(MOA_NS_URI, "QualifiedCertificate") + : null; + final Element sscdElem = + isSSCD + ? response.createElementNS(MOA_NS_URI, "SecureSignatureCreationDevice") + : null; Element issuerCountryCodeElem = null; if (issuerCountryCode != null) { - issuerCountryCodeElem = response.createElementNS(MOA_NS_URI, "IssuerCountryCode"); - issuerCountryCodeElem.setTextContent(issuerCountryCode); + issuerCountryCodeElem = response.createElementNS(MOA_NS_URI, "IssuerCountryCode"); + issuerCountryCodeElem.setTextContent(issuerCountryCode); } - - //add TSL infos + + // add TSL infos Element tslInfoElement = null; if (tslInfos != null) { - tslInfoElement = response.createElementNS(MOA_NS_URI, "TSLInformation"); - - //append TSL issuer country-code - if (MiscUtil.isNotEmpty(tslInfos.getTslIssuerCountry())); { - Element tslIssuerCountryCodeElem = response.createElementNS(MOA_NS_URI, "TSLIssuerCountryCode"); - tslIssuerCountryCodeElem.setTextContent(tslInfos.getTslIssuerCountry()); - tslInfoElement.appendChild(tslIssuerCountryCodeElem); - - } - - //append Service-Type Status - if (MiscUtil.isNotEmpty(tslInfos.getServiceTypeStatus())); { - Element tslServiceInfo = response.createElementNS(MOA_NS_URI, "ServiceTypeStatus"); - tslServiceInfo.setTextContent(tslInfos.getServiceTypeStatus()); - tslInfoElement.appendChild(tslServiceInfo); - - } - - //append Service-Type Identifier - if (MiscUtil.isNotEmpty(tslInfos.getServiceTypeIdentifier())); { - Element tslServiceInfo = response.createElementNS(MOA_NS_URI, "ServiceTypeIdentifier"); - tslServiceInfo.setTextContent(tslInfos.getServiceTypeIdentifier()); - tslInfoElement.appendChild(tslServiceInfo); - - } - - //append qualifiers - if (tslInfos.getQualifiers() != null && tslInfos.getQualifiers().size() > 0) { - Element tslQualifiers = response.createElementNS(MOA_NS_URI, "Qualifiers"); - - for (String el : tslInfos.getQualifiers()) { - Element tslQualifier = response.createElementNS(MOA_NS_URI, "Qualifier"); - tslQualifier.setTextContent(el); - tslQualifiers.appendChild(tslQualifier); - - } - - tslInfoElement.appendChild(tslQualifiers); - - } - - //append additional service information - if (tslInfos.getAdditionalServiceInformation() != null - && tslInfos.getAdditionalServiceInformation().size() > 0) { - Element tslAdditionalServiceInformations = response.createElementNS(MOA_NS_URI, "AdditionalServiceInformations"); - - for (String el : tslInfos.getAdditionalServiceInformation()) { - Element tslAdditionalServiceInformation = response.createElementNS(MOA_NS_URI, "AdditionalServiceInformation"); - tslAdditionalServiceInformation.setTextContent(el); - tslAdditionalServiceInformations.appendChild(tslAdditionalServiceInformation); - - } - tslInfoElement.appendChild(tslAdditionalServiceInformations); - - } + tslInfoElement = response.createElementNS(MOA_NS_URI, "TSLInformation"); + + // append TSL issuer country-code + if (MiscUtil.isNotEmpty(tslInfos.getTslIssuerCountry())) { + ; + } + { + final Element tslIssuerCountryCodeElem = response.createElementNS(MOA_NS_URI, "TSLIssuerCountryCode"); + tslIssuerCountryCodeElem.setTextContent(tslInfos.getTslIssuerCountry()); + tslInfoElement.appendChild(tslIssuerCountryCodeElem); + + } + + // append Service-Type Status + if (MiscUtil.isNotEmpty(tslInfos.getServiceTypeStatus())) { + ; + } + { + final Element tslServiceInfo = response.createElementNS(MOA_NS_URI, "ServiceTypeStatus"); + tslServiceInfo.setTextContent(tslInfos.getServiceTypeStatus()); + tslInfoElement.appendChild(tslServiceInfo); + + } + + // append Service-Type Identifier + if (MiscUtil.isNotEmpty(tslInfos.getServiceTypeIdentifier())) { + ; + } + { + final Element tslServiceInfo = response.createElementNS(MOA_NS_URI, "ServiceTypeIdentifier"); + tslServiceInfo.setTextContent(tslInfos.getServiceTypeIdentifier()); + tslInfoElement.appendChild(tslServiceInfo); + + } + + // append qualifiers + if (tslInfos.getQualifiers() != null && tslInfos.getQualifiers().size() > 0) { + final Element tslQualifiers = response.createElementNS(MOA_NS_URI, "Qualifiers"); + + for (final String el : tslInfos.getQualifiers()) { + final Element tslQualifier = response.createElementNS(MOA_NS_URI, "Qualifier"); + tslQualifier.setTextContent(el); + tslQualifiers.appendChild(tslQualifier); + + } + + tslInfoElement.appendChild(tslQualifiers); + + } + + // append additional service information + if (tslInfos.getAdditionalServiceInformation() != null + && tslInfos.getAdditionalServiceInformation().size() > 0) { + final Element tslAdditionalServiceInformations = response.createElementNS(MOA_NS_URI, + "AdditionalServiceInformations"); + + for (final String el : tslInfos.getAdditionalServiceInformation()) { + final Element tslAdditionalServiceInformation = response.createElementNS(MOA_NS_URI, + "AdditionalServiceInformation"); + tslAdditionalServiceInformation.setTextContent(el); + tslAdditionalServiceInformations.appendChild(tslAdditionalServiceInformation); + + } + tslInfoElement.appendChild(tslAdditionalServiceInformations); + + } } - - Element publicAuthorityElem = - isPublicAuthority - ? response.createElementNS(MOA_NS_URI, "PublicAuthority") - : null; - Element codeElem = - publicAuthorityID != null - ? response.createElementNS(MOA_NS_URI, "Code") - : null; + + final Element publicAuthorityElem = + isPublicAuthority + ? response.createElementNS(MOA_NS_URI, "PublicAuthority") + : null; + final Element codeElem = + publicAuthorityID != null + ? response.createElementNS(MOA_NS_URI, "Code") + : null; // fill in text x509IssuerElem.appendChild(response.createTextNode(issuer)); x509SerialNumberElem.appendChild(response.createTextNode(serialNumber)); try { - RFC2253NameParser parser = - new RFC2253NameParser(cert.getSubjectDN().getName()); - String subjectRfc2253 = parser.parse().getRFC2253String(); + final RFC2253NameParser parser = + new RFC2253NameParser(cert.getSubjectDN().getName()); + final String subjectRfc2253 = parser.parse().getRFC2253String(); x509SubjectNameElem.appendChild(response.createTextNode(subjectRfc2253)); - } catch (RFC2253NameParserException e) { + } catch (final RFC2253NameParserException e) { x509SubjectNameElem.appendChild( - response.createTextNode(cert.getSubjectDN().getName())); + response.createTextNode(cert.getSubjectDN().getName())); } try { x509CertificateElem.appendChild( - response.createTextNode(Base64Utils.encode(cert.getEncoded()))); - } catch (CertificateEncodingException e) { + response.createTextNode(Base64Utils.encode(cert.getEncoded()))); + } catch (final CertificateEncodingException e) { throw new MOAApplicationException("2245", null, e); - } catch (IOException e) { + } catch (final IOException e) { throw new MOAApplicationException("2245", null, e); } @@ -276,10 +285,11 @@ public class ResponseBuilderUtils { x509DataElem.appendChild(x509IssuerSerialElem); x509DataElem.appendChild(x509CertificateElem); if (isQualified) { - if (qcSource.compareToIgnoreCase("TSL") == 0) - qualifiedCertificateElem.setAttributeNS(MOA_NS_URI, "Source", qcSource); - - x509DataElem.appendChild(qualifiedCertificateElem); + if (qcSource.compareToIgnoreCase("TSL") == 0) { + qualifiedCertificateElem.setAttributeNS(MOA_NS_URI, "Source", qcSource); + } + + x509DataElem.appendChild(qualifiedCertificateElem); } if (isPublicAuthority) { x509DataElem.appendChild(publicAuthorityElem); @@ -289,16 +299,18 @@ public class ResponseBuilderUtils { } } if (isSSCD) { - sscdElem.setAttributeNS(MOA_NS_URI, "Source", sscdSource); - x509DataElem.appendChild(sscdElem); - } - if (issuerCountryCodeElem != null) - x509DataElem.appendChild(issuerCountryCodeElem); - - //add TSL infos to X509Date if TSL infos exists - if (tslInfoElement != null) - x509DataElem.appendChild(tslInfoElement); - + sscdElem.setAttributeNS(MOA_NS_URI, "Source", sscdSource); + x509DataElem.appendChild(sscdElem); + } + if (issuerCountryCodeElem != null) { + x509DataElem.appendChild(issuerCountryCodeElem); + } + + // add TSL infos to X509Date if TSL infos exists + if (tslInfoElement != null) { + x509DataElem.appendChild(tslInfoElement); + } + signerInfoElem.appendChild(x509DataElem); root.appendChild(signerInfoElem); } @@ -306,24 +318,24 @@ public class ResponseBuilderUtils { /** * Add an element containing Code and Info * subelements. - * - * @param response The response document, in order to create new elements in - * it. - * @param root The root element into which to insert the newly created - * element. + * + * @param response The response document, in order to create new elements in + * it. + * @param root The root element into which to insert the newly created + * element. * @param elementName The name of the newly created element. - * @param code The content of the Code subelement. - * @param info The content of the Info subelement. + * @param code The content of the Code subelement. + * @param info The content of the Info subelement. */ public static void addCodeInfoElement( - Document response, - Element root, - String elementName, - int code, - NodeList info) { - - Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); - Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); + Document response, + Element root, + String elementName, + int code, + NodeList info) { + + final Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); + final Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); Element infoElem; int i; @@ -339,34 +351,34 @@ public class ResponseBuilderUtils { } root.appendChild(codeInfoElem); } - + /** * Add an element containing Code and Info * subelements. - * - * @param response The response document, in order to create new elements in - * it. - * @param root The root element into which to insert the newly created - * element. + * + * @param response The response document, in order to create new elements in + * it. + * @param root The root element into which to insert the newly created + * element. * @param elementName The name of the newly created element. - * @param code The content of the Code subelement. - * @param info The content of the Info subelement. + * @param code The content of the Code subelement. + * @param info The content of the Info subelement. */ public static void addCodeInfoElement( - Document response, - Element root, - String elementName, - int code, - String info) { - - Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); - Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); + Document response, + Element root, + String elementName, + int code, + String info) { + + final Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); + final Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); Element infoElem; - int i; + final int i; codeElem.appendChild(response.createTextNode(Integer.toString(code))); codeInfoElem.appendChild(codeElem); - + if (info != null) { infoElem = response.createElementNS(MOA_NS_URI, "Info"); infoElem.appendChild(response.createTextNode(info)); @@ -376,137 +388,138 @@ public class ResponseBuilderUtils { } public static void addSigningTime(Document response, - Element root, - Date signingTime) { - if(signingTime != null) { - Element extElem = response.createElementNS(MOA_NS_URI, "SigningTime"); - TimeZone tz = TimeZone.getTimeZone("UTC"); - Calendar calendar = new GregorianCalendar(); + Element root, + Date signingTime) { + if (signingTime != null) { + final Element extElem = response.createElementNS(MOA_NS_URI, "SigningTime"); + final TimeZone tz = TimeZone.getTimeZone("UTC"); + final Calendar calendar = new GregorianCalendar(); calendar.setTimeZone(tz); calendar.setTime(signingTime); - String date = DatatypeConverter.printDateTime(calendar); + final String date = DatatypeConverter.printDateTime(calendar); extElem.appendChild(response.createTextNode(date)); root.appendChild(extElem); } } public static void addSignatureAlgorithm(Document response, - Element root, - String algorithm) { - if(algorithm != null) { - Element extElem = response.createElementNS(MOA_NS_URI, "SignatureAlgorithm"); - extElem.appendChild(response.createTextNode(algorithm)); - root.appendChild(extElem); - } + Element root, + String algorithm) { + if (algorithm != null) { + final Element extElem = response.createElementNS(MOA_NS_URI, "SignatureAlgorithm"); + extElem.appendChild(response.createTextNode(algorithm)); + root.appendChild(extElem); + } } - + public static void addSignatureCoversFullPDF(Document response, - Element root, - Boolean coversFull) { - if( coversFull != null) { - Element extElem = response.createElementNS(MOA_NS_URI, "SignatureCoversFullPDF"); - extElem.appendChild(response.createTextNode(String.valueOf(coversFull))); - root.appendChild(extElem); - } + Element root, + Boolean coversFull) { + if (coversFull != null) { + final Element extElem = response.createElementNS(MOA_NS_URI, "SignatureCoversFullPDF"); + extElem.appendChild(response.createTextNode(String.valueOf(coversFull))); + root.appendChild(extElem); + } } - + public static void addSignatureByteRange(Document response, - Element root, - int[] byteRange) { - if(byteRange != null) { - String byteRangeTextual = StringUtils.EMPTY; - for (int el : byteRange) - byteRangeTextual += "," + String.valueOf(el); - - Element extElem = response.createElementNS(MOA_NS_URI, "SignatureByteRange"); - extElem.appendChild(response.createTextNode(byteRangeTextual.substring(1))); - root.appendChild(extElem); - } + Element root, + int[] byteRange) { + if (byteRange != null) { + String byteRangeTextual = StringUtils.EMPTY; + for (final int el : byteRange) { + byteRangeTextual += "," + String.valueOf(el); + } + + final Element extElem = response.createElementNS(MOA_NS_URI, "SignatureByteRange"); + extElem.appendChild(response.createTextNode(byteRangeTextual.substring(1))); + root.appendChild(extElem); + } } - + public static Element createAndAddChildElement(Document response, Element root, String name) { - Element element = response.createElementNS(MOA_NS_URI, name); - root.appendChild(element); - return element; - + final Element element = response.createElementNS(MOA_NS_URI, name); + root.appendChild(element); + return element; + } - + public static void addHashAlgorithm(Document response, - Element root, - String algorithm) { - if(algorithm != null) { - Element extElem = response.createElementNS(MOA_NS_URI, "HashAlgorithm"); - extElem.appendChild(response.createTextNode(algorithm)); - root.appendChild(extElem); - } -} - + Element root, + String algorithm) { + if (algorithm != null) { + final Element extElem = response.createElementNS(MOA_NS_URI, "HashAlgorithm"); + extElem.appendChild(response.createTextNode(algorithm)); + root.appendChild(extElem); + } + } + public static void addExtendendResult(Document response, - Element root, - ExtendedCertificateCheckResult result) { - Element extElem = response.createElementNS(MOA_NS_URI, "ExtendedCertificateCheck"); - - Element extMajorElem = response.createElementNS(MOA_NS_URI, "Major"); - - Element codeMajorCodeElem = response.createElementNS(MOA_NS_URI, "Code"); - Element codeMajorNameElem = response.createElementNS(MOA_NS_URI, "Name"); - codeMajorCodeElem.appendChild(response.createTextNode(Integer.toString( - result.getMajorCode()))); - codeMajorNameElem.appendChild(response.createTextNode(result.getMajorInfo())); - - extMajorElem.appendChild(codeMajorCodeElem); - extMajorElem.appendChild(codeMajorNameElem); - - extElem.appendChild(extMajorElem); - - if(result.getMinorCode() >= 0) { - Element extMinorElem = response.createElementNS(MOA_NS_URI, "Minor"); - Element codeMinorCodeElem = response.createElementNS(MOA_NS_URI, "Code"); - Element codeMinorNameElem = response.createElementNS(MOA_NS_URI, "Name"); - codeMinorCodeElem.appendChild(response.createTextNode(Integer.toString( - result.getMinorCode()))); - codeMinorNameElem.appendChild(response.createTextNode(result.getMinorInfo())); - - extMinorElem.appendChild(codeMinorCodeElem); - extMinorElem.appendChild(codeMinorNameElem); - - extElem.appendChild(extMinorElem); - } - - root.appendChild(extElem); + Element root, + ExtendedCertificateCheckResult result) { + final Element extElem = response.createElementNS(MOA_NS_URI, "ExtendedCertificateCheck"); + + final Element extMajorElem = response.createElementNS(MOA_NS_URI, "Major"); + + final Element codeMajorCodeElem = response.createElementNS(MOA_NS_URI, "Code"); + final Element codeMajorNameElem = response.createElementNS(MOA_NS_URI, "Name"); + codeMajorCodeElem.appendChild(response.createTextNode(Integer.toString( + result.getMajorCode()))); + codeMajorNameElem.appendChild(response.createTextNode(result.getMajorInfo())); + + extMajorElem.appendChild(codeMajorCodeElem); + extMajorElem.appendChild(codeMajorNameElem); + + extElem.appendChild(extMajorElem); + + if (result.getMinorCode() >= 0) { + final Element extMinorElem = response.createElementNS(MOA_NS_URI, "Minor"); + final Element codeMinorCodeElem = response.createElementNS(MOA_NS_URI, "Code"); + final Element codeMinorNameElem = response.createElementNS(MOA_NS_URI, "Name"); + codeMinorCodeElem.appendChild(response.createTextNode(Integer.toString( + result.getMinorCode()))); + codeMinorNameElem.appendChild(response.createTextNode(result.getMinorInfo())); + + extMinorElem.appendChild(codeMinorCodeElem); + extMinorElem.appendChild(codeMinorNameElem); + + extElem.appendChild(extMinorElem); + } + + root.appendChild(extElem); } - + /** * Add an element containing Code and Info * subelements. - * - * @param response The response document, in order to create new elements in - * it. - * @param root The root element into which to insert the newly created - * element. + * + * @param response The response document, in order to create new elements in + * it. + * @param root The root element into which to insert the newly created + * element. * @param elementName The name of the newly created element. - * @param code The content of the Code subelement. - * @param info The content of the Info subelement. + * @param code The content of the Code subelement. + * @param info The content of the Info subelement. */ public static void addFormCheckElement( - Document response, - Element root, - String elementName, - int code, - String name) { - - Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); - Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); + Document response, + Element root, + String elementName, + int code, + String name) { + + final Element codeInfoElem = response.createElementNS(MOA_NS_URI, elementName); + final Element codeElem = response.createElementNS(MOA_NS_URI, "Code"); Element infoElem; - + codeElem.appendChild(response.createTextNode(Integer.toString(code))); codeInfoElem.appendChild(codeElem); - + infoElem = response.createElementNS(MOA_NS_URI, "Name"); infoElem.appendChild(response.createTextNode(name)); codeInfoElem.appendChild(infoElem); - + root.appendChild(codeInfoElem); } - + } -- cgit v1.2.3