Пример #1
0
        /// <summary>
        /// Gets the result of the attribute value.
        /// </summary>
        /// <returns>The attribute result.</returns>
        /// <param name="attribute">The content or replace attribute.</param>
        /// <param name="context">The rendering context.</param>
        /// <param name="mode">Exposes the mode (either <c>text</c>, <c>structure</c> or a <c>null</c> reference).</param>
        private ExpressionResult GetAttributeResult(IZptAttribute attribute,
                                                IRenderingContext context,
                                                out string mode)
        {
            var match = ValueMatcher.Match(attribute.Value);

              if(!match.Success)
              {
            string message = String.Format(ExceptionMessages.ZptAttributeParsingError,
                                       ZptConstants.Tal.Namespace,
                                       attribute.Name,
                                       attribute.Value,
                                       context.Element.Name);
            throw new ParserException(message) {
              SourceAttributeName = attribute.Name,
              SourceAttributeValue = attribute.Value,
              SourceElementName = context.Element.Name
            };
              }

              mode = match.Groups[1].Value;
              return context.TalModel.Evaluate(match.Groups[2].Value, context);
        }
Пример #2
0
        /// <summary>
        /// Parses the value of a 'tal:repeat' attribute and exposes the variable name and expression.
        /// </summary>
        /// <param name="attribute">Attribute.</param>
        /// <param name="variableName">Variable name.</param>
        /// <param name="expression">Expression.</param>
        /// <param name="element">The element which contains the attribute.</param>
        private void ParseAttributeValue(IZptAttribute attribute,
                                     out string variableName,
                                     out string expression,
                                     IZptElement element)
        {
            var attribMatch = AttributeMatcher.Match(attribute.Value);

              if(!attribMatch.Success)
              {
            string message = String.Format(ExceptionMessages.ZptAttributeParsingError,
                                       ZptConstants.Tal.Namespace,
                                       ZptConstants.Tal.RepeatAttribute,
                                       attribute.Value,
                                       element.Name);
            throw new ParserException(message) {
              SourceAttributeName = ZptConstants.Tal.RepeatAttribute,
              SourceElementName = element.Name,
              SourceAttributeValue = attribute.Value
            };
              }

              variableName = attribMatch.Groups[1].Value;
              expression = attribMatch.Groups[2].Value;
        }