package com.sun.identity.saml2.protocol.impl;

import com.sun.identity.saml2.common.SAML2Exception;
import com.sun.identity.saml2.protocol.StatusMessage;

public class StatusMessageImpl implements StatusMessage {
   private final String messageValue;

   public StatusMessageImpl(String value) {
      this.messageValue = value;
   }

   @Override
   public String getValue() {
      return this.messageValue;
   }

   @Override
   public String toXMLString() throws SAML2Exception {
      return this.toXMLString(true, false);
   }

   @Override
   public String toXMLString(boolean includeNSPrefix, boolean declareNS) throws SAML2Exception {
      String xmlStr = null;
      if (this.messageValue != null && !this.messageValue.isEmpty()) {
         StringBuilder xmlString = new StringBuilder(500);
         xmlString.append("<");
         if (includeNSPrefix) {
            xmlString.append("samlp:");
         }

         xmlString.append("StatusMessage");
         if (declareNS) {
            xmlString.append(" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"");
         }

         xmlString.append(">");
         xmlString.append("\n").append(this.messageValue);
         xmlString.append("\n").append("</samlp:").append("StatusMessage").append(">");
         xmlStr = xmlString.toString();
      }

      return xmlStr;
   }
}
