Ejemplo n.º 1
0
        /// <summary>Create a XML start element.</summary>
        /// <remarks>Create a XML start element.</remarks>
        /// <param name="name">- the tag name.</param>
        /// <param name="nameSpace">- namespace of the tag name</param>
        /// <param name="attributes">- an ordered collection of attributes (names and values) to render with the element</param>
        /// <param name="indentLevel">- the indent level</param>
        /// <param name="close">- indicates whether or not close the element.</param>
        /// <param name="lineBreak">- indicates whether or not to include a line break</param>
        /// <returns>- the formatted result.</returns>
        public static string CreateStartElement(string name, string nameSpace, IList <KeyValuePair <string, string> > attributes, int
                                                indentLevel, bool close, bool lineBreak)
        {
            StringBuilder buffer = new StringBuilder();

            Indenter.IndentBuffer(buffer, indentLevel);
            buffer.Append("<");
            buffer.Append(name);
            if (nameSpace != null)
            {
                buffer.Append(" xmlns=\"" + nameSpace + "\"");
            }
            if (attributes != null)
            {
                foreach (KeyValuePair <string, string> attribute in attributes)
                {
                    buffer.Append(SPACE);
                    buffer.Append(attribute.Key);
                    buffer.Append(EQUALS);
                    buffer.Append(QUOTE);
                    buffer.Append(XmlStringEscape.Escape(attribute.Value));
                    buffer.Append(QUOTE);
                }
            }
            if (close)
            {
                buffer.Append("/");
            }
            buffer.Append(">");
            if (lineBreak)
            {
                buffer.Append(SystemUtils.LINE_SEPARATOR);
            }
            return(buffer.ToString());
        }
Ejemplo n.º 2
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string result = base.Format(context, hl7Value, indentLevel);

            if (hl7Value != null)
            {
                string originalText  = ((ANYMetaData)hl7Value).OriginalText;
                bool   hasNullFlavor = hl7Value.HasNullFlavor();
                bool   hasAnyValues  = HasAnyValues(hl7Value);
                this.pqValidationUtils.ValidateOriginalText(context.Type, originalText, hasAnyValues, hasNullFlavor, context.GetVersion()
                                                            , null, context.GetPropertyPath(), context.GetModelToXmlResult());
                // complete hack for BC
                if (SpecificationVersion.IsExactVersion(context.GetVersion(), SpecificationVersion.V02R04_BC))
                {
                    if (hasNullFlavor && HasAnyValues(hl7Value))
                    {
                        // dump the result and rebuild, adding in NF
                        IDictionary <string, string> attributeNameValuePairs = GetAttributeNameValuePairs(context, (PhysicalQuantity)hl7Value.BareValue
                                                                                                          , hl7Value);
                        attributeNameValuePairs.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor));
                        result = CreateElement(context, attributeNameValuePairs, indentLevel, true, true);
                    }
                }
                if (StringUtils.IsNotBlank(originalText))
                {
                    string otElement = CreateElement("originalText", null, indentLevel + 1, false, false);
                    otElement += XmlStringEscape.Escape(originalText);
                    otElement += CreateElementClosure("originalText", 0, true);
                    // pulling off the end "/>" is not the most elegant solution, but superclass would need significant refactoring otherwise
                    result = Ca.Infoway.Messagebuilder.StringUtils.Substring(result, 0, result.IndexOf("/>")) + ">" + SystemUtils.LINE_SEPARATOR
                             + otElement + CreateElementClosure(context.GetElementName(), indentLevel, true);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void AppendPostalAddressPart(StringBuilder buffer, PostalAddressPart postalAddressPart)
        {
            string openTag     = string.Empty;
            string closeTag    = string.Empty;
            bool   isDelimiter = IsDelimiter(postalAddressPart);

            if (postalAddressPart.Type != null)
            {
                if (isDelimiter && StringUtils.IsBlank(postalAddressPart.Value))
                {
                    openTag = "<" + postalAddressPart.Type.Value + "/>";
                }
                else
                {
                    openTag  = "<" + postalAddressPart.Type.Value + FormatCode(postalAddressPart.Code) + ">";
                    closeTag = "</" + postalAddressPart.Type.Value + ">";
                }
            }
            buffer.Append(openTag);
            string xmlEscapedValue = XmlStringEscape.Escape(postalAddressPart.Value);

            if (xmlEscapedValue != null)
            {
                buffer.Append(xmlEscapedValue);
            }
            buffer.Append(closeTag);
        }
Ejemplo n.º 4
0
 protected virtual void CreateChildContent(CD cd, StringBuilder result)
 {
     if (HasOriginalText(cd))
     {
         result.Append(CreateElement("originalText", null, 0, false, false));
         result.Append(XmlStringEscape.Escape(cd.OriginalText));
         result.Append("</").Append("originalText").Append(">");
     }
 }
Ejemplo n.º 5
0
 private void FormatDefaultValue(StringBuilder builder, Relationship relationship)
 {
     // suppress rendering of required or optional fixed values
     if (ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship))
     {
         builder.Append(" ").Append(relationship.Name).Append("=\"").Append(XmlStringEscape.Escape(relationship.DefaultValue)).Append
             ("\"");
     }
 }
Ejemplo n.º 6
0
 private void HandleSimpleValue(CodedTypeR2 <Code> codedType, StringBuilder result, FormatContext context)
 {
     // simpleValue (String)
     if (HasSimpleValue(codedType))
     {
         if (SimpleValueAllowed())
         {
             result.Append(XmlStringEscape.Escape(codedType.SimpleValue));
         }
     }
 }
Ejemplo n.º 7
0
        protected override string FormatNonNullValue(FormatContext context, TrivialName value, int indentLevel)
        {
            StringBuilder buffer = new StringBuilder();

            if (value != null)
            {
                buffer.Append(CreateElement(context, GetUseAttributeMap(value), indentLevel, false, false));
                buffer.Append(XmlStringEscape.Escape(value.Name));
                buffer.Append(CreateElementClosure(context, 0, true));
            }
            return(buffer.ToString());
        }
Ejemplo n.º 8
0
        private string FormatCode(Code code)
        {
            if (code == null || StringUtils.IsEmpty(code.CodeValue))
            {
                return(StringUtils.EMPTY);
            }
            string codeValue  = XmlStringEscape.Escape(code.CodeValue);
            string codeSystem = XmlStringEscape.Escape(code.CodeSystem);

            return(" code=\"" + codeValue + "\"" + (StringUtils.IsBlank(code.CodeSystem) ? string.Empty : " codeSystem=\"" + codeSystem
                                                    + "\""));
        }
Ejemplo n.º 9
0
        // leave this up to subclasses to decide if they want to do any validations
        private void AppendNamePart(StringBuilder buffer, EntityNamePart namePart)
        {
            string openTag  = string.Empty;
            string closeTag = string.Empty;

            if (namePart.Type != null)
            {
                openTag  = "<" + namePart.Type.Value + AddQualifier(namePart) + ">";
                closeTag = "</" + namePart.Type.Value + ">";
            }
            buffer.Append(openTag);
            buffer.Append(XmlStringEscape.Escape(namePart.Value));
            buffer.Append(closeTag);
        }
Ejemplo n.º 10
0
        protected override string FormatNonNullValue(FormatContext context, CodedString <Code> value, int indentLevel)
        {
            bool codeProvided       = value.Code == null ? false : StringUtils.IsNotBlank(value.Code.CodeValue);
            bool codeSystemProvided = value.Code == null ? false : StringUtils.IsNotBlank(value.Code.CodeSystem);

            this.codedStringValidationUtils.ValidateCodedString(value, codeProvided, codeSystemProvided, null, context.GetPropertyPath
                                                                    (), context.GetModelToXmlResult());
            StringBuilder buffer = new StringBuilder();

            buffer.Append(CreateElement(context, GetAttributeNameValuePairs(value), indentLevel, false, false));
            buffer.Append(XmlStringEscape.Escape(value.Value));
            buffer.Append(CreateElementClosure(context, 0, true));
            return(buffer.ToString());
        }
Ejemplo n.º 11
0
        private string AddOriginalText(string xml, BareANY dataType, int indentLevel)
        {
            // TM - RM20416: R2 URG<PQ> now has an explicit OT element (as opposed to being within the inner PQ.LAB)
            string originalText = ((ANYMetaData)dataType).OriginalText;

            if (StringUtils.IsNotBlank(originalText))
            {
                string otElement = CreateElement("originalText", null, indentLevel + 1, false, false);
                otElement += XmlStringEscape.Escape(originalText);
                otElement += CreateElementClosure("originalText", 0, false);
                int indexOf = xml.IndexOf(">");
                xml = Ca.Infoway.Messagebuilder.StringUtils.Substring(xml, 0, indexOf + 2) + otElement + Ca.Infoway.Messagebuilder.StringUtils.Substring
                          (xml, indexOf + 2);
            }
            return(xml);
        }
Ejemplo n.º 12
0
        private string CreateText(BareANY dataType)
        {
            string textValue = GetStringValue(dataType);
            string results   = null;

            if (dataType is ANYMetaData && ((ANYMetaData)dataType).IsCdata)
            {
                // RM18719 - do not escape text, but wrap with a CDATA block
                results = "<![CDATA[" + textValue + "]]>";
            }
            else
            {
                results = XmlStringEscape.Escape(textValue);
            }
            return(results);
        }
Ejemplo n.º 13
0
        private string CreateText(BareANY dataType)
        {
            object bareValue = dataType.BareValue;
            string textValue = bareValue == null ? string.Empty : bareValue.ToString();
            string results   = null;

            if (dataType is ANYMetaData && ((ANYMetaData)dataType).IsCdata)
            {
                // RM18719 - do not escape text, but wrap with a CDATA block
                results = "<![CDATA[" + textValue + "]]>";
            }
            else
            {
                results = XmlStringEscape.Escape(textValue);
            }
            return(results);
        }
Ejemplo n.º 14
0
        private void AppendNamePart(StringBuilder buffer, EntityNamePart namePart, int indentLevel)
        {
            string openTag       = string.Empty;
            string closeTag      = string.Empty;
            bool   valueProvided = namePart.Value != null;

            if (namePart.Type != null)
            {
                openTag = "<" + namePart.Type.Value + AddQualifier(namePart) + AddNullFlavor(namePart) + (valueProvided ? string.Empty :
                                                                                                          "/") + ">";
                closeTag = "</" + namePart.Type.Value + ">";
            }
            Indenter.IndentBuffer(buffer, indentLevel);
            buffer.Append(openTag);
            if (valueProvided)
            {
                buffer.Append(XmlStringEscape.Escape(namePart.Value));
                buffer.Append(closeTag);
            }
            buffer.Append(SystemUtils.LINE_SEPARATOR);
        }
Ejemplo n.º 15
0
        private void AppendPostalAddressPart(StringBuilder buffer, PostalAddressPart postalAddressPart, int indentLevel)
        {
            bool   hasPartType = postalAddressPart.Type != null;
            bool   hasValue    = postalAddressPart.Value != null && postalAddressPart.Value.Length > 0;
            string tagName     = (hasPartType ? postalAddressPart.Type.Value : string.Empty);

            if (hasPartType)
            {
                if (!hasValue)
                {
                    buffer.Append(CreateElement(tagName, null, indentLevel, true, true));
                }
                else
                {
                    buffer.Append(CreateElement(tagName, GetCodeAttributes(postalAddressPart.Code), indentLevel, false, false));
                }
            }
            if (hasValue)
            {
                if (!hasPartType)
                {
                    Indenter.IndentBuffer(buffer, indentLevel);
                }
                string xmlEscapedValue = XmlStringEscape.Escape(postalAddressPart.Value);
                if (xmlEscapedValue != null)
                {
                    buffer.Append(xmlEscapedValue);
                }
            }
            if (hasPartType && hasValue)
            {
                buffer.Append(CreateElementClosure(tagName, 0, true));
            }
            else
            {
                buffer.Append(SystemUtils.LINE_SEPARATOR);
            }
        }
Ejemplo n.º 16
0
 public EncapsulatedData(
     x_DocumentMediaType mediaType_0,
     String reference_1, String lanuage_2, byte[] content_3)
 {
     MediaType    = mediaType_0;
     Language     = lanuage_2;
     this.content = content_3 == null || content_3.Length == 0 ? null : XmlStringEscape.Escape(ASCIIEncoding.ASCII.GetString(content_3));
     if (!StringUtils.IsBlank(reference_1))
     {
         String[] parts = reference_1.Split(new string[] { "://" }, StringSplitOptions.None);
         if (parts.Length > 0)
         {
             Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme urlsScheme = null;
             if (parts.Length > 1)
             {
                 urlsScheme = Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme.ValueOf <Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme>(
                     typeof(Ca.Infoway.Messagebuilder.Domainvalue.Basic.URLScheme), parts[0]);
             }
             String address = (parts.Length > 1 ? parts[1] : parts[0]);
             ReferenceObj = new TelecommunicationAddress(urlsScheme, address);
         }
     }
 }
Ejemplo n.º 17
0
        /// <summary>A utility that creates a representation of the element and its attributes.</summary>
        /// <remarks>
        /// A utility that creates a representation of the element and its attributes.
        /// This representation would typically be used in error messages to help the
        /// user recognize which element is a problem.
        /// </remarks>
        /// <param name="element">- the element</param>
        /// <returns>- an XML-like repesentation of the element.</returns>
        public static string DescribeSingleElement(XmlElement element)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("<").Append(NodeUtil.GetLocalOrTagName(element));
            XmlAttributeCollection attributes = element.Attributes;
            List <string>          set        = new List <string>();

            if (attributes != null)
            {
                foreach (XmlNode node in new XmlNamedNodeMapIterable(attributes))
                {
                    XmlAttribute item = (XmlAttribute)node;
                    set.Add(item.Name);
                }
            }
            set.Sort();
            foreach (string name in set)
            {
                XmlAttribute item = (XmlAttribute)attributes.GetNamedItem(name);
                builder.Append(" ").Append(NodeUtil.GetLocalOrTagName(item)).Append("=\"").Append(XmlStringEscape.Escape(item.Value)).Append
                    ("\"");
            }
            if (element.HasChildNodes)
            {
                builder.Append(">");
            }
            else
            {
                builder.Append("/>");
            }
            return(builder.ToString());
        }
Ejemplo n.º 18
0
 private void FormatValue(StringBuilder builder, Relationship relationship, object value)
 {
     builder.Append(" ").Append(relationship.Name).Append("=\"").Append(XmlStringEscape.Escape(ValueAsString(value, relationship
                                                                                                             ))).Append("\"");
 }
Ejemplo n.º 19
0
 public virtual string GetMissingAttributeErrorMessage(string type, string attributeName, string attributeValue)
 {
     return(System.String.Format("Data type " + type + " requires the attribute {0}=\"{1}\"", attributeName, XmlStringEscape.Escape
                                     (attributeValue)));
 }
Ejemplo n.º 20
0
 public virtual string CreateLog(string logLevel, int indentLevel, string text)
 {
     return(this.outputWarnings ? Indenter.Indent("<!-- " + logLevel + (StringUtils.IsBlank(logLevel) ? string.Empty : ": ") +
                                                  XmlStringEscape.Escape(text) + " -->" + SystemUtils.LINE_SEPARATOR, indentLevel) : StringUtils.EMPTY);
 }
Ejemplo n.º 21
0
 public virtual string GetIncorrectAttributeValueErrorMessage(string type, string attributeName, string attributeValue)
 {
     return(System.String.Format("Data type " + type + " expected the attribute {0}=\"{1}\"", attributeName, XmlStringEscape.Escape
                                     (attributeValue)));
 }