Example #1
0
        internal PropertyList MakeList(
            string ns,
            string elementName,
            Attributes attributes,
            FObj parentFO)
        {
            Debug.Assert(ns != null, "Namespace should never be null.");

            string space = "http://www.w3.org/TR/1999/XSL/Format";

            if (ns != null)
            {
                space = ns;
            }

            PropertyList parentPropertyList = parentFO != null ? parentFO.properties : null;
            PropertyList par = null;

            if (parentPropertyList != null && space.Equals(parentPropertyList.GetNameSpace()))
            {
                par = parentPropertyList;
            }

            PropertyList p = new PropertyList(par, space, elementName);

            p.SetBuilder(this);

            StringCollection propsDone = new StringCollection();

            string fontsizeval = attributes.getValue(FONTSIZEATTR);

            if (fontsizeval != null)
            {
                PropertyMaker propertyMaker = FindMaker(FONTSIZEATTR);
                if (propertyMaker != null)
                {
                    try
                    {
                        p.Add(FONTSIZEATTR,
                              propertyMaker.Make(p, fontsizeval, parentFO));
                    }
                    catch (FonetException) { }
                }
                propsDone.Add(FONTSIZEATTR);
            }

            for (int i = 0; i < attributes.getLength(); i++)
            {
                string   attributeName = attributes.getQName(i);
                int      sepchar       = attributeName.IndexOf('.');
                string   propName      = attributeName;
                string   subpropName   = null;
                Property propVal       = null;
                if (sepchar > -1)
                {
                    propName    = attributeName.Substring(0, sepchar);
                    subpropName = attributeName.Substring(sepchar + 1);
                }
                else if (propsDone.Contains(propName))
                {
                    continue;
                }

                PropertyMaker propertyMaker = FindMaker(propName);

                if (propertyMaker != null)
                {
                    try
                    {
                        if (subpropName != null)
                        {
                            Property baseProp = p.GetExplicitBaseProperty(propName);
                            if (baseProp == null)
                            {
                                string baseValue = attributes.getValue(propName);
                                if (baseValue != null)
                                {
                                    baseProp = propertyMaker.Make(p, baseValue, parentFO);
                                    propsDone.Add(propName);
                                }
                            }
                            propVal = propertyMaker.Make(baseProp, subpropName,
                                                         p,
                                                         attributes.getValue(i),
                                                         parentFO);
                        }
                        else
                        {
                            propVal = propertyMaker.Make(p,
                                                         attributes.getValue(i),
                                                         parentFO);
                        }
                        if (propVal != null)
                        {
                            p[propName] = propVal;
                        }
                    }
                    catch (FonetException e)
                    {
                        FonetDriver.ActiveDriver.FireFonetError(e.Message);
                    }
                }
                else
                {
                    if (!attributeName.StartsWith("xmlns"))
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "property " + attributeName + " ignored");
                    }
                }
            }

            return(p);
        }
Example #2
0
        private void StartElement(
            string uri,
            string localName,
            Attributes attlist)
        {
            FObj fobj;

            FObj.Maker fobjMaker = GetFObjMaker(uri, localName);

            PropertyListBuilder currentListBuilder =
                (PropertyListBuilder)this.propertylistTable[uri];

            bool foreignXML = false;
            if (fobjMaker == null)
            {
                string fullName = uri + "^" + localName;
                if (!this.unknownFOs.ContainsKey(fullName))
                {
                    this.unknownFOs.Add(fullName, "");
                    FonetDriver.ActiveDriver.FireFonetError("Unknown formatting object " + fullName);
                }
                if (namespaces.Contains(String.Intern(uri)))
                {
                    fobjMaker = new Unknown.Maker();
                }
                else
                {
                    fobjMaker = new UnknownXMLObj.Maker(uri, localName);
                    foreignXML = true;
                }
            }

            PropertyList list = null;
            if (currentListBuilder != null)
            {
                list = currentListBuilder.MakeList(uri, localName, attlist, currentFObj);
            }
            else if (foreignXML)
            {
                list = null;
            }
            else
            {
                if (currentFObj == null)
                {
                    throw new FonetException("Invalid XML or missing namespace");
                }
                list = currentFObj.properties;
            }
            fobj = fobjMaker.Make(currentFObj, list);

            if (rootFObj == null)
            {
                rootFObj = fobj;
                if (!fobj.GetName().Equals("fo:root"))
                {
                    throw new FonetException("Root element must" + " be root, not " + fobj.GetName());
                }
            }
            else if (!(fobj is PageSequence))
            {
                currentFObj.AddChild(fobj);
            }

            currentFObj = fobj;
        }
Example #3
0
        internal PropertyList MakeList(
            string ns,
            string elementName,
            Attributes attributes,
            FObj parentFO)
        {
            Debug.Assert(ns != null, "Namespace should never be null.");

            string space = "http://www.w3.org/TR/1999/XSL/Format";
            if (ns != null)
            {
                space = ns;
            }

            PropertyList parentPropertyList = parentFO != null ? parentFO.properties : null;
            PropertyList par = null;
            if (parentPropertyList != null && space.Equals(parentPropertyList.GetNameSpace()))
            {
                par = parentPropertyList;
            }

            PropertyList p = new PropertyList(par, space, elementName);
            p.SetBuilder(this);

            StringCollection propsDone = new StringCollection();

            string fontsizeval = attributes.getValue(FONTSIZEATTR);
            if (fontsizeval != null)
            {
                PropertyMaker propertyMaker = FindMaker(FONTSIZEATTR);
                if (propertyMaker != null)
                {
                    try
                    {
                        p.Add(FONTSIZEATTR,
                              propertyMaker.Make(p, fontsizeval, parentFO));
                    }
                    catch (FonetException) { }
                }
                propsDone.Add(FONTSIZEATTR);
            }

            for (int i = 0; i < attributes.getLength(); i++)
            {
                string attributeName = attributes.getQName(i);
                int sepchar = attributeName.IndexOf('.');
                string propName = attributeName;
                string subpropName = null;
                Property propVal = null;
                if (sepchar > -1)
                {
                    propName = attributeName.Substring(0, sepchar);
                    subpropName = attributeName.Substring(sepchar + 1);
                }
                else if (propsDone.Contains(propName))
                {
                    continue;
                }

                PropertyMaker propertyMaker = FindMaker(propName);

                if (propertyMaker != null)
                {
                    try
                    {
                        if (subpropName != null)
                        {
                            Property baseProp = p.GetExplicitBaseProperty(propName);
                            if (baseProp == null)
                            {
                                string baseValue = attributes.getValue(propName);
                                if (baseValue != null)
                                {
                                    baseProp = propertyMaker.Make(p, baseValue, parentFO);
                                    propsDone.Add(propName);
                                }
                            }
                            propVal = propertyMaker.Make(baseProp, subpropName,
                                                         p,
                                                         attributes.getValue(i),
                                                         parentFO);
                        }
                        else
                        {
                            propVal = propertyMaker.Make(p,
                                                         attributes.getValue(i),
                                                         parentFO);
                        }
                        if (propVal != null)
                        {
                            p[propName] = propVal;
                        }
                    }
                    catch (FonetException e)
                    {
                        FonetDriver.ActiveDriver.FireFonetError(e.Message);
                    }
                }
                else
                {
                    if (!attributeName.StartsWith("xmlns"))
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "property " + attributeName + " ignored");
                    }
                }
            }

            return p;
        }
Example #4
0
        internal void Parse(XmlReader reader)
        {
            int buflen = 500;
            char[] buffer = new char[buflen];
            try
            {
                object nsuri = reader.NameTable.Add("http://www.w3.org/2000/xmlns/");

                FonetDriver.ActiveDriver.FireFonetInfo("Building formatting object tree");
                streamRenderer.StartRenderer();

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            Attributes atts = new Attributes();
                            while (reader.MoveToNextAttribute())
                            {
                                if (!reader.NamespaceURI.Equals(nsuri))
                                {
                                    SaxAttribute newAtt = new SaxAttribute();
                                    newAtt.Name = reader.Name;
                                    newAtt.NamespaceURI = reader.NamespaceURI;
                                    newAtt.Value = reader.Value;
                                    atts.attArray.Add(newAtt);
                                }
                            }
                            reader.MoveToElement();
                            StartElement(reader.NamespaceURI, reader.LocalName, atts.TrimArray());
                            if (reader.IsEmptyElement)
                            {
                                EndElement();
                            }
                            break;
                        case XmlNodeType.EndElement:
                            EndElement();
                            break;
                        case XmlNodeType.Text:
                            char[] chars = reader.ReadString().ToCharArray();
                            if (currentFObj != null)
                            {
                                currentFObj.AddCharacters(chars, 0, chars.Length);
                            }
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                goto case XmlNodeType.Element;
                            }
                            if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                goto case XmlNodeType.EndElement;
                            }
                            break;
                        default:
                            break;
                    }
                }
                FonetDriver.ActiveDriver.FireFonetInfo("Parsing of document complete, stopping renderer");
                streamRenderer.StopRenderer();
            }
            catch (Exception exception)
            {
                FonetDriver.ActiveDriver.FireFonetError(exception.ToString());
            }
            finally
            {
                if (reader.ReadState != ReadState.Closed)
                {
                    reader.Close();
                }
            }
        }