/* * Created on 20.11.2003 * * (c) Stabsstelle IKT-Strategie des Bundes */ package at.gv.egovernment.moa.spss.slinterface.transformers; import java.util.ArrayList; import java.util.HashMap; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import at.gv.egovernment.moa.spss.slinterface.Constants; /** * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) */ public class MOA2SL { /** * Transforms an MOA VerifyXMLSignatureResponse into a SL VerifyXMLSignatureResponse. * * @param moaVerifyXMLSignatureResponse The MOA VerifyXMLSignatureResponse to be transformed. * * @return the specified response document, transformed into a SL VerifyXMLSignatureResponse. Please note * that moaVerifyXMLSignatureResponse is modified into the sl response. * * @pre moaVerifyXMLSignatureResponse is a valid instance of the SL Schema (version 1.2 or 1.1). */ public static Document toSlVerifyXMLSignatureResponse(Document moaVerifyXMLSignatureResponse) { // Namespace to namespace prefix mapping HashMap prefixMap = new HashMap(4); prefixMap.put(Constants.NSURI_SL_10_, Constants.NSPRE_SL_10_); prefixMap.put(Constants.NSURI_SL_11_, Constants.NSPRE_SL_11_); prefixMap.put(Constants.NSURI_SL_12_, Constants.NSPRE_SL_12_); prefixMap.put(Constants.NSURI_MOA_12_, Constants.NSPRE_MOA_12_); // Namespaces to be changed HashMap nsTransforms = new HashMap(); nsTransforms.put(Constants.NSURI_MOA_12_, Constants.NSURI_SL_11_); // Names to be changed HashMap nameTransforms = new HashMap(); nameTransforms.put( new QName(Constants.NSURI_MOA_12_, "PublicAuthority"), new QName(Constants.NSURI_MOA_12_,"PublicAuthority")); Element verifyResponseElem = moaVerifyXMLSignatureResponse.getDocumentElement(); verifyResponseElem.setAttributeNS(Constants.NSURI_NAMESPACES_, "xmlns:" + Constants.NSPRE_SL_10_, Constants.NSURI_SL_10_); verifyResponseElem.setAttributeNS(Constants.NSURI_NAMESPACES_, "xmlns:" + Constants.NSPRE_SL_11_, Constants.NSURI_SL_11_); // Convert SL request into MOA request verifyResponseElem = Utils.transformDeep(verifyResponseElem, prefixMap, nsTransforms, nameTransforms); // Add SignatureManifestCheck element (Code = 98) Element signatureMFCheckElem = moaVerifyXMLSignatureResponse.createElementNS( Constants.NSURI_SL_11_, Constants.NSPRE_SL_11_ + ":SignatureManifestCheck"); Element smfCodeElem = moaVerifyXMLSignatureResponse.createElementNS( Constants.NSURI_SL_11_, Constants.NSPRE_SL_11_ + ":Code"); signatureMFCheckElem.appendChild(smfCodeElem); smfCodeElem.appendChild(moaVerifyXMLSignatureResponse.createTextNode("98")); Element signatureCheckElem = (Element) verifyResponseElem.getElementsByTagNameNS( Constants.NSURI_SL_11_, "SignatureCheck").item(0); verifyResponseElem.insertBefore(signatureMFCheckElem, signatureCheckElem.getNextSibling()); // Siblings of Certificate check must be in sl10 namespace nsTransforms.clear(); nsTransforms.put(Constants.NSURI_SL_11_, Constants.NSURI_SL_10_); nameTransforms.clear(); Element certCheckElem = (Element) verifyResponseElem.getElementsByTagNameNS( Constants.NSURI_SL_11_, "CertificateCheck").item(0); NodeList certCheckChildren = certCheckElem.getChildNodes(); ArrayList certCheckChildElemsList = new ArrayList(certCheckChildren.getLength()); for (int i = 0; i < certCheckChildren.getLength(); i++) { Node currentNode = certCheckChildren.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) certCheckChildElemsList.add(certCheckChildren.item(i)); } for (int i = 0; i < certCheckChildElemsList.size(); i++) Utils.transformDeep((Element) certCheckChildElemsList.get(i), prefixMap, nsTransforms, nameTransforms); return moaVerifyXMLSignatureResponse; } }