Пример #1
0
        /**
         * Calculates the macro-expanded value of an attribute on the node.
         * Returns true if the attribute is defined.
         */
        bool GetAttributeValue(XmlNode node, XmlMacroCollection macros, string attribName, out string value)
        {
            value = node.GetAttributeValue(attribName);

            if (value != null)
            {
                try
                {
                    value = macros.GetExpandedValue(value);
                }
                catch (Exception ex)
                {
                    throw new JRunXmlException(node, ex, "Could not expand macro value for attribute \"{0}\"", attribName);
                }
            }

            return value != null;
        }
Пример #2
0
        /**
         * Retrieve the macro-expanded text value of a child of an xml node.
         * Properties are inheritable from templates.
         * Returns true if the property is defined.
         */
        bool GetPropertyValue(XmlNode node, XmlMacroCollection macros, string propertyName, out string value)
        {
            value = null;

            // check if we define this, or any of our templates
            foreach (var templateNode in NodeTemplateTree(node, macros))
            {
                var childNode = templateNode.SelectSingleNode(propertyName);

                if (childNode != null)
                {
                    value = childNode.InnerText;
                    break;
                }
            }

            if (value != null)
            {
                try
                {
                    value = macros.GetExpandedValue(value);
                }
                catch (Exception ex)
                {
                    throw new JRunXmlException(node, ex, "Could not expand macro value for property \"{0}\"", propertyName);
                }
            }

            return value != null;
        }
Пример #3
0
        /**
         * Creates a virtual shortcut for the given context and node
         */
        XmlVirtualShortcut CreateVirtualShortcut(XmlNode context, XmlNode shortcutNode, XmlMacroCollection outerMacros)
        {
            var nodeName = shortcutNode.GetAttributeValue("name");

            if (!String.IsNullOrEmpty(nodeName))
            {
                var realName = outerMacros.GetExpandedValue(nodeName);

                if (!String.IsNullOrEmpty(realName))
                {
                    var newMacros = new XmlMacroCollection(outerMacros);

                    AddTemplateMacros(shortcutNode, newMacros);

                    return new XmlVirtualShortcut(realName, context, shortcutNode, newMacros);
                }
            }

            return null;
        }