Exemple #1
0
        public ContentDocumentValidator(
            ILoggerFacade logger,
            IEventAggregator eventAggregator,
            [Import(typeof(IUrakawaSession), RequiredCreationPolicy = CreationPolicy.Shared, AllowRecomposition = false, AllowDefault = false)]
            IUrakawaSession session)
            : base(eventAggregator)
        {
            m_Logger  = logger;
            m_Session = session;

            m_DtdRegex = new DtdSharpToRegex();

            m_Logger.Log(@"ContentDocumentValidator initialized", Category.Debug, Priority.Medium);
        }
Exemple #2
0
        //check a single node
        private bool ValidateNodeContent(StringBuilder strBuilder, TreeNode node)
        {
            if (node.HasXmlProperty)
            {
                string childrenNames = DtdSharpToRegex.GenerateChildNameList(strBuilder, node);
                Regex  regex         = m_DtdRegex.GetRegex(strBuilder, node);
                if (regex == null)
                {
                    var error1 = new UndefinedElementValidationError(m_Session)
                    {
                        Target = node
                    };
                    addValidationItem(error1);
                    return(false);
                }

                Match match = regex.Match(childrenNames);

                string matchStr = match.ToString();
                if (match.Success && matchStr == childrenNames)
                {
                    return(true);
                }

                var error2 = new InvalidElementSequenceValidationError(m_Session)
                {
                    Target            = node,
                    AllowedChildNodes = regex.ToString(),
                };

                //look for more details about this error -- which child element is causing problems?
                //RevalidateChildren(regex, childrenNames, error);

                addValidationItem(error2);
                return(false);
            }

            //no XML property for the node: therefore, it is valid.
            return(true);
        }