예제 #1
0
        internal AttributeAction GetAttributeAction(string ns, string localName, FileFormatVersions format)
        {
            if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format.All())
            {
                return(AttributeAction.Normal);
            }

            if (string.IsNullOrEmpty(ns))
            {
                return(AttributeAction.Normal);
            }

            if (NamespaceIdMap.IsInFileFormat(ns, format))
            {
                return(AttributeAction.Normal);
            }

            if (!IsIgnorableNs(ns))
            {
                return(AttributeAction.Normal);
            }

            if (IsPreservedAttribute(ns, localName))
            {
                return(AttributeAction.Normal);
            }

            return(AttributeAction.Ignore);
        }
        internal OpenXmlCompositeElement GetContentFromACBlock(AlternateContent acblk, FileFormatVersions format)
        {
            Debug.Assert(format != (FileFormatVersions.Office2007 | FileFormatVersions.Office2010 | FileFormatVersions.Office2013));

            foreach (var choice in acblk.ChildElements.OfType <AlternateContentChoice>())
            {
                if (choice.Requires == null)
                {
                    //should we throw exception here?
                    continue;
                }
                string reqs = choice.Requires.InnerText.Trim();
                if (string.IsNullOrEmpty(reqs))
                {
                    //should we throw exception here?
                    continue;
                }

                bool chooce = true;
                foreach (var req in reqs.Split(new char[] { ' ' }))
                {
                    //fix bug 537858
                    //the LookupNamespaceDeleget is from xmlReader
                    //bug when we try to GetContentFromACBlock, the reader has already moved to the next element of ACB
                    //so we should use the element's LookupNamespace function to find it
                    //string ns = LookupNamespaceDelegate(req);
                    string ns = choice.LookupNamespace(req);
                    if (ns == null)
                    {
                        if (this._noExceptionOnError)
                        {
                            chooce = false;
                            break;
                        }
                        else
                        {
                            var msg = String.Format(System.Globalization.CultureInfo.CurrentUICulture, ExceptionMessages.UnknowMCContent, req);
                            throw new InvalidMCContentException(msg);
                        }
                    }
                    if (!NamespaceIdMap.IsInFileFormat(ns, format))
                    {
                        chooce = false;
                        break;
                    }
                }

                if (chooce)
                {
                    return(choice);
                }
            }
            var fallback = acblk.GetFirstChild <AlternateContentFallback>();

            if (fallback != null)
            {
                return(fallback);
            }
            return(null);
        }