Ejemplo n.º 1
0
        public static BaseItem Fabrica(ODFDocument d, XmlNode xn)
        {
            if (xn is XmlText)
            {
                return(new TextElement(d, (XmlText)xn));
            }
            XmlElement xe = xn as XmlElement;
            BaseItem   it = null;

            if (xe == null)
            {
            }
            if (xe.Name == FontFace)
            {
                it = new FontFace(d, xe);
            }

            else if (xe.Name == DateStyle)
            {
                it = new DateStyle(d, xe);
            }
            else if (xe.Name == TimeStyle)
            {
                it = new TimeStyle(d, xe);
            }
            else if (xe.Name == TableOfContent)
            {
                it = new TableOfContent(d, xe);
            }
            else if (xe.Name == TableOfContentSource)
            {
                it = new TableOfContentSource(d, xe);
            }
            else if (xe.Name == TableOfContentEntryTemplate)
            {
                it = new TableOfContentEntryTemplate(d, xe);
            }
            else if (xe.Name == IndexTitleTemplate)
            {
                it = new IndexTitleTemplate(d, xe);
            }
            else if (xe.Name == IndexEntryLinkStart)
            {
                it = new IndexEntryLinkStart(d, xe);
            }
            else if (xe.Name == IndexEntrySpan)
            {
                it = new IndexEntrySpan(d, xe);
            }
            else if (xe.Name == IndexEntryText)
            {
                it = new IndexEntryText(d, xe);
            }
            else if (xe.Name == IndexEntryTabStop)
            {
                it = new IndexEntryTabStop(d, xe);
            }
            else if (xe.Name == IndexEntryPageNumber)
            {
                it = new IndexEntryPageNumber(d, xe);
            }
            else if (xe.Name == IndexEntryLinkEnd)
            {
                it = new IndexEntryLinkEnd(d, xe);
            }
            else if (xe.Name == IndexBody)
            {
                it = new IndexBody(d, xe);
            }

            else if (xe.Name == TextBibliographyConfiguration)
            {
                it = new TextBibliographyConfiguration(d, xe);
            }
            else if (xe.Name == TextSortKey)
            {
                it = new TextSortKey(d, xe);
            }

            else if (xe.Name == DrawTextBox)
            {
                it = new DrawTextBox(d, xe);
            }
            else if (xe.Name == SoftPageBreak)
            {
                it = new SoftPageBreak(d, xe);
            }
            else if (xe.Name == TextHeader)
            {
                it = new TextHeader(d, xe);
            }
            else if (xe.Name == TextLink)
            {
                it = new TextLink(d, xe);
            }
            else if (xe.Name == TextSection)
            {
                it = new TextSection(d, xe);
            }
            else if (xe.Name == TextSpace)
            {
                it = new TextSpace(d, xe);
            }
            else if (xe.Name == TextTab)
            {
                it = new TextTab(d, xe);
            }
            else if (xe.Name == PageLayout)
            {
                it = new PageLayout(d, xe);
            }
            else if (xe.Name == PageLayoutProperties)
            {
                it = new PageLayoutProperties(d, xe);
            }

            else if (xe.Name == MasterPage)
            {
                it = new MasterPage(d, xe);
            }

            else if (xe.Name == Frame)
            {
                it = new Frame(d, xe);
            }
            else if (xe.Name == FrameImage)
            {
                it = new FrameImage(d, xe);
            }

            else if (xe.Name == List)
            {
                it = new List(d, xe);
            }
            else if (xe.Name == ListItem)
            {
                it = new ListItem(d, xe);
            }

            else if (xe.Name == NotesConfiguration)
            {
                it = new NotesConfiguration(d, xe);
            }
            else if (xe.Name == LineNumberingConfiguration)
            {
                it = new LineNumberingConfiguration(d, xe);
            }

            else if (xe.Name == ListStyle)
            {
                it = new ListStyle(d, xe);
            }
            else if (xe.Name == ListLevelStyleBullet)
            {
                it = new ListLevelStyleBullet(d, xe);
            }
            else if (xe.Name == ListLevelStyleNumber)
            {
                it = new ListLevelStyleNumber(d, xe);
            }
            else if (xe.Name == ListLevelProperties)
            {
                it = new ListLevelProperties(d, xe);
            }
            else if (xe.Name == ListLevelLableAligment)
            {
                it = new ListLevelLableAligment(d, xe);
            }
            else if (xe.Name == OutlineStyle)
            {
                it = new OutlineStyle(d, xe);
            }
            else if (xe.Name == OutlineLevelStyle)
            {
                it = new OutlineLevelStyle(d, xe);
            }

            else if (xe.Name == ParagraphProperties)
            {
                it = new ParagraphProperties(d, xe);
            }
            else if (xe.Name == TabStops)
            {
                it = new TabStops(d, xe);
            }
            else if (xe.Name == TabStop)
            {
                it = new TabStop(d, xe);
            }
            else if (xe.Name == TextProperties)
            {
                it = new TextProperties(d, xe);
            }
            else if (xe.Name == TableProperties)
            {
                it = new TableProperties(d, xe);
            }
            else if (xe.Name == ColumnProperties)
            {
                it = new ColumnProperties(d, xe);
            }
            else if (xe.Name == CellProperties)
            {
                it = new CellProperties(d, xe);
            }
            else if (xe.Name == GraphicProperties)
            {
                it = new GraphicProperties(d, xe);
            }
            else if (xe.Name == SectionProperties)
            {
                it = new SectionProperties(d, xe);
            }
            else if (xe.Name == BackgroundImageStyle)
            {
                it = new BackgroundImageStyle(d, xe);
            }
            else if (xe.Name == ColumnsStyle)
            {
                it = new ColumnsStyle(d, xe);
            }

            else if (xe.Name == Paragraph)
            {
                it = new Paragraph(d, xe);
            }
            else if (xe.Name == TextSpan)
            {
                it = new TextSpan(d, xe);
            }
            else if (xe.Name == Placeholder)
            {
                it = new Placeholder(d, xe);
            }
            else if (xe.Name == Table)
            {
                it = new Table(d, xe);
            }
            else if (xe.Name == CoveredCell)
            {
                it = new CoveredCell(d, xe);
            }
            else if (xe.Name == Column)
            {
                it = new Column(d, xe);
            }
            else if (xe.Name == Row)
            {
                it = new Row(d, xe);
            }
            else if (xe.Name == Cell)
            {
                it = new Cell(d, xe);
            }
            else if (xe.Name == TableCalculationSettings)
            {
                it = new TableCalculationSettings(d, xe);
            }
            else if (xe.Name == DocumentStyles)
            {
                it = new DocumentStyles(d, xe);
            }
            else if (xe.Name == Styles)
            {
                it = new Styles(d, xe);
            }

            else if (xe.Name == Style)
            {
                string buf = xe.GetAttribute("style:family");
                if (buf == "graphic")
                {
                    it = new GraphicStyle(d, xe);
                }
                else if (buf == "paragraph")
                {
                    it = new ParagraphStyle(d, xe);
                }
                else if (buf == "table")
                {
                    it = new TableStyle(d, xe);
                }
                else if (buf == "table-row")
                {
                    it = new RowStyle(d, xe);
                }
                else if (buf == "table-column")
                {
                    it = new ColumnStyle(d, xe);
                }
                else if (buf == "table-cell")
                {
                    it = new CellStyle(d, xe);
                }
                else if (buf == "text")
                {
                    it = new TextStyle(d, xe);
                }
                else if (buf == "section")
                {
                    it = new SectionStyle(d, xe);
                }
                else
                {
                    it = new DefaultStyle(d, xe);
                }
            }
            else if (xe.Name == CurrencyStyle)
            {
                it = new CurrencyStyle(d, xe);
            }
            else if (xe.Name == NumberStyle)
            {
                it = new NumberStyle(d, xe);
            }
            else if (xe.Name == NumberTextStyle)
            {
                it = new NumberTextStyle(d, xe);
            }
            else if (xe.Name == Number)
            {
                it = new Number(d, xe);
            }
            else if (xe.Name == NumberText)
            {
                it = new NumberText(d, xe);
            }
            else if (xe.Name == DefaultStyle)
            {
                it = new DefaultStyle(d, xe);
            }
            else if (xe.Name == FontFaceDeclarations)
            {
                it = new FontFaceDeclarations(d, xe);
            }
            else if (xe.Name == DocumentContent)
            {
                it = new DocumentContent(d, xe);
            }
            else if (xe.Name == Scripts)
            {
                it = new Scripts(d, xe);
            }
            else if (xe.Name == AutomaticStyles)
            {
                it = new AutomaticStyles(d, xe);
            }
            else if (xe.Name == MasterStyles)
            {
                it = new MasterStyles(d, xe);
            }

            else if (xe.Name == DocumentSpreadSheet)
            {
                it = new DocumentSpreadSheet(d, xe);
            }
            else if (xe.Name == DocumentBody)
            {
                it = new DocumentBody(d, xe);
            }
            else if (xe.Name == DocumentText)
            {
                it = new BodyText(d, xe);
            }
            else if (xe.Name == TextSequeceDeclarations)
            {
                it = new TextSequenceDeclarations(d, xe);
            }
            else if (xe.Name == TextSequeceDeclaration)
            {
                it = new TextSequenceDeclaration(d, xe);
            }


            else if (xe.Name == DocumentMeta)
            {
                it = new DocumentMeta(d, xe);
            }
            else if (xe.Name == Meta)
            {
                it = new Meta(d, xe);
            }
            else if (xe.Name == MetaInitialCreator)
            {
                it = new MetaInitialCreator(d, xe);
            }
            else if (xe.Name == MetaCreationDate)
            {
                it = new MetaCreationDate(d, xe);
            }
            else if (xe.Name == MetaDate)
            {
                it = new MetaDate(d, xe);
            }
            else if (xe.Name == MetaCreator)
            {
                it = new MetaCreator(d, xe);
            }
            else if (xe.Name == MetaEditingDuration)
            {
                it = new MetaEditiongDuration(d, xe);
            }
            else if (xe.Name == MetaEditingCycles)
            {
                it = new MetaEditiongCycles(d, xe);
            }
            else if (xe.Name == MetaGenerator)
            {
                it = new MetaGenerator(d, xe);
            }
            else if (xe.Name == MetaStatistic)
            {
                it = new MetaStatistic(d, xe);
            }

            else if (xe.Name == DocumentManifest)
            {
                it = new DocumentManifest(d, xe);
            }
            else if (xe.Name == ManifestFile)
            {
                it = new ManifestFile(d, xe);
            }

            else if (xe.Name == DocumentSettings)
            {
                it = new DocumentSettings(d, xe);
            }
            else if (xe.Name == Settings)
            {
                it = new Settings(d, xe);
            }
            else if (xe.Name == ConfigItemSet)
            {
                it = new ConfigItemSet(d, xe);
            }
            else if (xe.Name == ConfigItem)
            {
                it = new ConfigItem(d, xe);
            }
            else if (xe.Name == ConfigItemMapIndexed)
            {
                it = new ConfigItemMapIndexed(d, xe);
            }
            else if (xe.Name == ConfigItemMapEntry)
            {
                it = new ConfigItemMapEntry(d, xe);
            }

            else
            {
                it = new DocumentElementCollection(d, xe);
            }
            return(it);
        }
Ejemplo n.º 2
0
        public void Load(Stream mainStream)
        {
            if (mainStream == null)
            {
                return;
            }

            using (ZipFile zipfile = new ZipFile(mainStream))
            {
                xmlStyles   = new XmlDocument();
                xmlContent  = new XmlDocument();
                xmlManifest = new XmlDocument();
                xmlMeta     = new XmlDocument();
                xmlSettings = new XmlDocument();

                files = new Dictionary <string, Dictionary <string, object> >();
                foreach (ZipEntry zipEntry in zipfile)
                {
                    Stream streamOfFile = zipfile.GetInputStream(zipEntry);

                    if (zipEntry.Name == fContent)
                    {
                        xmlContent.Load(streamOfFile);
                    }
                    else if (zipEntry.Name == fStyles)
                    {
                        xmlStyles.Load(streamOfFile);
                    }
                    else if (zipEntry.Name == fMeta)
                    {
                        xmlMeta.Load(streamOfFile);
                    }
                    else if (zipEntry.Name == fMainfest)
                    {
                        xmlManifest.Load(streamOfFile);
                    }
                    else if (zipEntry.Name == fSetting)
                    {
                        xmlSettings.Load(streamOfFile);
                    }

                    byte[] data = new byte[zipEntry.Size];
                    try
                    {
                        streamOfFile.Read(data, 0, data.Length);
                    }
                    catch
                    {
                    }
                    streamOfFile.Close();
                    files.Add(zipEntry.Name, new Dictionary <string, object>
                    {
                        { "ZipFileIndex", zipEntry.ZipFileIndex },
                        { "IsDirectory", zipEntry.IsDirectory },
                        { "Data", data }
                    });
                }
            }

            documentStyles  = (DocumentStyles)Service.Fabrica(this, xmlStyles.DocumentElement);
            documentContent = (DocumentContent)Service.Fabrica(this, xmlContent.DocumentElement);

            if (xmlMeta.DocumentElement != null)
            {
                documentMeta = (DocumentMeta)Service.Fabrica(this, xmlMeta.DocumentElement);
            }

            if (xmlManifest.DocumentElement != null)
            {
                documentManifest = (DocumentManifest)Service.Fabrica(this, xmlManifest.DocumentElement);
            }

            if (xmlSettings.DocumentElement != null)
            {
                documentSettings = (DocumentSettings)Service.Fabrica(this, xmlSettings.DocumentElement);
            }
        }