コード例 #1
0
        public EpubSummaryParser(Stream source)
        {
            _zip = ZipContainer.Unzip(source);
            XDocument xmlDocument = _zip.GetFileStream("META-INF/container.xml").GetXmlDocument();
            XElement root = xmlDocument.Root;
            if (root == null)
                throw new DataException(InvalidEpubMetaInfo);

            XAttribute attribute = root.Attribute("xmlns");
            XNamespace xmlns = (attribute != null) ? XNamespace.Get(attribute.Value) : XNamespace.None;
            XAttribute fullPath = xmlDocument.Descendants(xmlns + "rootfile").First().Attribute("full-path");
            if (fullPath == null)
                throw new DataException(InvalidEpubMetaInfo);

            string path = fullPath.Value;
            _opfPath = path;
            _opf = _zip.GetFileStream(path).GetXmlDocument();
            _opfRoot = _opf.Root;
            if (_opfRoot == null)
                throw new DataException(InvalidEpubMetaInfo);

            _oebps = GetPath(path);
            _opfns = XNamespace.Get("http://www.idpf.org/2007/opf");
            _opfdc = XNamespace.Get("http://purl.org/dc/elements/1.1/");

            _coverHelper = new EpubCoverHelper(_zip, _opfns, _opfRoot, _oebps);
        }
コード例 #2
0
        public EpubSummaryParser(Stream source)
        {
            _zip = ZipContainer.Unzip(source);
            XDocument xmlDocument = _zip.GetFileStream("META-INF/container.xml").GetXmlDocument();
            XElement  root        = xmlDocument.Root;

            if (root == null)
            {
                throw new DataException(InvalidEpubMetaInfo);
            }

            XAttribute attribute = root.Attribute("xmlns");
            XNamespace xmlns     = (attribute != null) ? XNamespace.Get(attribute.Value) : XNamespace.None;
            XAttribute fullPath  = xmlDocument.Descendants(xmlns + "rootfile").First().Attribute("full-path");

            if (fullPath == null)
            {
                throw new DataException(InvalidEpubMetaInfo);
            }

            string path = fullPath.Value;

            _opfPath = path;
            _opf     = _zip.GetFileStream(path).GetXmlDocument();
            _opfRoot = _opf.Root;
            if (_opfRoot == null)
            {
                throw new DataException(InvalidEpubMetaInfo);
            }

            _oebps = GetPath(path);
            _opfns = XNamespace.Get("http://www.idpf.org/2007/opf");
            _opfdc = XNamespace.Get("http://purl.org/dc/elements/1.1/");

            _coverHelper = new EpubCoverHelper(_zip, _opfns, _opfRoot, _oebps);
        }