protected IPDFRemoteComponent GetParsedParent(IPDFComponent component)
        {
            if (component is IPDFRemoteComponent)
            {
                IPDFRemoteComponent remote = (IPDFRemoteComponent)component;
                return(remote);
            }

            if (null != component.Parent)
            {
                return(GetParsedParent(component.Parent));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the closest parent component that was parsed from a file
        /// </summary>
        /// <returns></returns>
        protected virtual IPDFRemoteComponent GetParsedParent()
        {
            if (this is IPDFRemoteComponent)
            {
                IPDFRemoteComponent remote = (IPDFRemoteComponent)this;
                if (remote.LoadType != ParserLoadType.None && !string.IsNullOrEmpty(remote.LoadedSource))
                {
                    return(remote);
                }
            }

            if (null != this.Parent)
            {
                return(this.Parent.GetParsedParent());
            }
            else
            {
                return(null);
            }
        }
        protected virtual XmlNamespaceManager GetNamespaceManager(IPDFComponent owner)
        {
            System.Xml.NameTable           nt               = new System.Xml.NameTable();
            System.Xml.XmlNamespaceManager mgr              = new System.Xml.XmlNamespaceManager(nt);
            IPDFRemoteComponent            parsed           = this.GetParsedParent(owner);
            IDictionary <string, string>   parsedNamespaces = null;

            //add the namespaces of the last parsed document so we can infer any declarations
            if (null != parsed)
            {
                parsedNamespaces = parsed.GetDeclaredNamespaces();
                if (null != parsedNamespaces)
                {
                    foreach (string prefix in parsedNamespaces.Keys)
                    {
                        mgr.AddNamespace(prefix, parsedNamespaces[prefix]);
                    }
                }
            }


            return(mgr);
        }
Exemplo n.º 4
0
        private System.Xml.XmlNamespaceManager GetNamespaceManager()
        {
            System.Xml.NameTable           nt               = new System.Xml.NameTable();
            System.Xml.XmlNamespaceManager mgr              = new System.Xml.XmlNamespaceManager(nt);
            IPDFRemoteComponent            parsed           = this.GetParsedParent();
            IDictionary <string, string>   parsedNamespaces = null;

            //add the namespaces of the last parsed document so we can infer any declarations
            if (null != parsed)
            {
                parsedNamespaces = parsed.GetDeclaredNamespaces();

                if (null != parsedNamespaces)
                {
                    foreach (string prefix in parsedNamespaces.Keys)
                    {
                        mgr.AddNamespace(prefix, parsedNamespaces[prefix]);
                    }
                }
            }

            if (null != this._nss)
            {
                string found;
                foreach (XmlNamespaceDeclaration dec in _nss)
                {
                    //makes sure this overrides any existing namespace declaration
                    if (null != parsedNamespaces && parsedNamespaces.TryGetValue(dec.Prefix, out found))
                    {
                        mgr.RemoveNamespace(dec.Prefix, found);
                    }

                    mgr.AddNamespace(dec.Prefix, dec.NamespaceURI);
                }
            }
            return(mgr);
        }
        //
        // IPDFTemplate Instantiate method.
        //

        public IEnumerable <IPDFComponent> Instantiate(int index, IPDFComponent owner)
        {
            if (!_initialised)
            {
                this.InitTemplate(this.XmlContent, this.NamespacePrefixMappings);
            }

            if (null == owner)
            {
                throw new ArgumentNullException("owner");
            }

            using (System.IO.StringReader sr = new System.IO.StringReader(this._toparse))
            {
                //Get the closest remote component
                IPDFRemoteComponent remote = this.GetRemoteComponent(owner);
                IPDFDocument        doc    = owner.Document;
                IPDFComponent       comp;
                if (doc is IPDFTemplateParser)
                {
                    comp = ((IPDFTemplateParser)doc).ParseTemplate(remote, sr);
                }
                else
                {
                    throw RecordAndRaise.NullReference(Errors.ParentDocumentMustBeTemplateParser);
                }

                if (this.IsBlock)
                {
                    if (!(comp is TemplateBlockInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateBlockInstance));
                    }

                    TemplateBlockInstance template = (TemplateBlockInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }
                else
                {
                    if (!(comp is TemplateInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateInstance));
                    }

                    TemplateInstance template = (TemplateInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }

                if (comp is Component && owner is Component && this.UseDataStyleIdentifier)
                {
                    var stem = this.DataStyleStem;
                    if (string.IsNullOrEmpty(stem))
                    {
                        stem = ((Component)owner).UniqueID;
                    }

                    DataStyleIdentifierVisitor visitor = new DataStyleIdentifierVisitor(stem, 1);
                    visitor.PushToComponents(comp as Component);
                }

                List <IPDFComponent> all = new List <IPDFComponent>(1);

                all.Add(comp);
                return(all);
            }
        }