예제 #1
0
        /// <summary>
        /// Increase the level of the section.
        /// </summary>
        public static void Move(SectionNode section)
        {
            SectionNode sibling = section.PrecedingSibling;

            section.Detach();
            sibling.AppendChild(section);
            int children = section.SectionChildCount;

            for (int i = 0; i < children; ++i)
            {
                SectionNode child = section.SectionChild(0);
                child.Detach();
                sibling.AppendChild(child);
            }
        }
예제 #2
0
        private SectionNode CreateSectionNode(XmlNode node)
        {
            int         level    = int.Parse(node.LocalName.Substring(1));
            SectionNode parent   = getAvailableParent(level);
            SectionNode section  = m_Presentation.CreateSectionNode();
            string      strLabel = GetTextContent(node);

            strLabel      = strLabel.Replace("\n", "").Replace("\r", "").Replace("\t", "");
            section.Label = strLabel;
            //if no parent was found, then we must be an h1 sibling or first node
            if (parent == null)
            {
                if (node.LocalName != "h1")
                {
                    throw new Exception(Localizer.Message("wrong_heading_order"));
                }
                m_Presentation.RootNode.AppendChild(section);
            }
            else
            {
                parent.AppendChild(section);
            }


            return(section);
        }
        // Add a page of the given kind; parse the content to get the page number.
        private void addPage(XmlTextReader source, PageKind kind)
        {
            if (mCurrentSection == null)
            {
                throw new Exception(Localizer.Message("error_adding_page_number"));
            }
            string     pageNumberString = GetTextContent(source);
            PageNumber number           = null;

            if (kind == PageKind.Special && pageNumberString != null && pageNumberString != "")
            {
                number = new PageNumber(pageNumberString);
            }
            else if (kind == PageKind.Front || kind == PageKind.Normal)
            {
                int pageNumber = EmptyNode.SafeParsePageNumber(pageNumberString);
                if (pageNumber > 0)
                {
                    number = new PageNumber(pageNumber, kind);
                }
            }
            if (number != null)
            {
                EmptyNode node = mPresentation.TreeNodeFactory.Create <EmptyNode>();
                node.PageNumber = number;
                mCurrentSection.AppendChild(node);
            }
        }
예제 #4
0
 private void ParseNccDocument(XmlNode node)
 {
     if (node.ChildNodes.Count == 0)
     {
         return;
     }
     foreach (XmlNode n in node.ChildNodes)
     {
         if (n.NodeType == XmlNodeType.Element)
         {
             if (n.LocalName == "h1" || n.LocalName == "h2" || n.LocalName == "h3" ||
                 n.LocalName == "h4" || n.LocalName == "h5" || n.LocalName == "h6")
             {
                 //foundHeadings = true;
                 Obi.SectionNode section = CreateSectionNode(n);
                 if (section != null && section.Level < 6)
                 {
                     m_OpenSectionNodes.Push(section);
                 }
                 m_CurrentSection = section;
                 m_SectionNodesToSmilReferenceMap.Add(section, GetSmilReferenceString(n));
             }
             else if (n.LocalName == "p" || n.LocalName == "span")
             {
                 string classAttr = n.Attributes.GetNamedItem("class").Value;
                 if (classAttr == "phrase")
                 {
                     EmptyNode empty = m_Presentation.TreeNodeFactory.Create <EmptyNode>();
                     m_CurrentSection.AppendChild(empty);
                 }
                 else if (classAttr == "page" || classAttr == "page-normal")
                 {
                     addPage(n, PageKind.Normal);
                 }
                 else if (classAttr == "page-front")
                 {
                     addPage(n, PageKind.Front);
                 }
                 else if (classAttr == "page-special")
                 {
                     addPage(n, PageKind.Special);
                 }
             }
         }
         ParseNccDocument(n);
     }
 }
예제 #5
0
        private PhraseNode CreatePhraseNodeFromAudioElement(SectionNode section, XmlNode audioNode)
        {
            PhraseNode phrase = m_Presentation.CreatePhraseNode();

            section.AppendChild(phrase);
            addAudio(phrase, audioNode, true);
            return(phrase);
        }
예제 #6
0
        /// <summary>
        /// Increase the level of the section.
        /// </summary>
        public static void Move(SectionNode section)
        {
            int         index    = section.Index + 1;
            SectionNode sibling  = section.ParentAs <SectionNode>();
            int         children = sibling.SectionChildCount;

            for (int i = index; i < children; ++i)
            {
                SectionNode child = sibling.SectionChild(index);
                child.Detach();
                section.AppendChild(child);
            }
            section.Detach();
            sibling.ParentAs <ObiNode>().InsertAfter(section, sibling);
        }
        private void CreateStructure(List <int> levelsList, List <string> sectionNamesList, List <int> pagesPerSection)
        {
            List <ObiNode> listOfSectionNodes = new List <ObiNode>();

            listOfSectionNodes.Add((ObiNode)m_Presentation.RootNode);
            int         pageNumber     = 0;
            SectionNode currentSection = null;

            Console.WriteLine("level list  count" + levelsList.Count);
            for (int i = 0; i < levelsList.Count; i++)
            {
                SectionNode section = m_Presentation.CreateSectionNode();
                section.Label = sectionNamesList[i].Trim();
                Console.WriteLine("section " + section.Label + ", level: " + levelsList[i]);
                if (currentSection == null)
                {
                    m_Presentation.RootNode.AppendChild(section);
                }
                else
                {
                    // iterate back in list of sections to find the parent
                    for (int j = listOfSectionNodes.Count - 1; j >= 0; j--)
                    {
                        ObiNode iterationSection = listOfSectionNodes[j];
                        if (iterationSection.Level < levelsList[i])
                        {
                            iterationSection.AppendChild(section);
                            break;
                        }
                    }
                }
                currentSection = section;
                listOfSectionNodes.Add(section);
                if (pagesPerSection[i] > 0)
                {
                    for (int j = 0; j < pagesPerSection[i]; j++)
                    {
                        EmptyNode pageNode = m_Presentation.TreeNodeFactory.Create <EmptyNode>();
                        ++pageNumber;
                        pageNode.PageNumber = new PageNumber(pageNumber, PageKind.Normal);
                        section.AppendChild(pageNode);
                        Console.WriteLine("page : " + pageNode.PageNumber.ToString());
                    }
                }
            }
        }
예제 #8
0
        private void ParseSmilDocument(SectionNode section, XmlNode xNode, string smilFileName, string strId)
        {
            if (xNode.ChildNodes.Count == 0)
            {
                return;
            }
            foreach (XmlNode n in xNode.ChildNodes)
            {
                if (n.LocalName == "par")
                {
                    // check for skippable items
                    string  skippableName      = null;
                    XmlNode systemRequiredNode = n.Attributes.GetNamedItem("system-required");
                    if (systemRequiredNode != null)
                    {
                        string strSkippableName = systemRequiredNode.Value;
                        if (!string.IsNullOrEmpty(strSkippableName))
                        {
                            strSkippableName = strSkippableName.Replace("-on", "");
                            //Console.WriteLine(strSkippableName) ;
                            if (EmptyNode.SkippableNamesList.Contains(strSkippableName))
                            {
                                skippableName = strSkippableName;
                            }
                        }
                    }
                    EmptyNode page             = null;
                    EmptyNode originalPageNode = null;
                    XmlNode   txtNode          = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(n, true, "text", n.NamespaceURI);
                    if (txtNode != null)
                    {
                        string src   = txtNode.Attributes.GetNamedItem("src").Value;
                        string nccID = src.Split('#')[1];

                        if (m_NccReferenceToPageMap.ContainsKey(nccID))
                        {
                            originalPageNode = m_NccReferenceToPageMap[nccID];
                            // if text ID has no audio or seq sibling it means that its page with no audio
                            if (txtNode.ParentNode.ChildNodes.Count == 1)
                            {
                                Console.WriteLine("Page text node in smil has no sibling: no audio, no seq");
                                EmptyNode newNode = m_Presentation.TreeNodeFactory.Create <EmptyNode>();
                                section.AppendChild(newNode);
                                if (page == null)
                                {
                                    page = newNode;
                                }
                                UpdatePageNumber(originalPageNode, page);
                            }
                        }
                    }
                    XmlNode seqNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(n, true, "seq", n.NamespaceURI);
                    if (seqNode != null)
                    {
                        foreach (XmlNode audioNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(seqNode, true, "audio", seqNode.NamespaceURI, false))
                        {
                            EmptyNode newNode = CreatePhraseNodeFromAudioElement(section, audioNode);
                            if (page == null)
                            {
                                page = newNode;
                            }
                            if (!string.IsNullOrEmpty(skippableName))
                            {
                                newNode.SetRole(EmptyNode.Role.Custom, skippableName);
                            }
                        }
                        UpdatePageNumber(originalPageNode, page);
                    }
                    else
                    {     //1
                        foreach (XmlNode audioNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(n, true, "audio", n.NamespaceURI, false))
                        { //2
                            EmptyNode newNode = CreatePhraseNodeFromAudioElement(section, audioNode);
                            if (page == null)
                            {
                                page = newNode;
                            }
                        } //-2
                        UpdatePageNumber(originalPageNode, page);
                    }     //-1
                    if (page == null)
                    {
                        ParseSmilDocument(section, n, smilFileName, strId);
                    }
                }
                else if (n.LocalName == "audio")
                {
                    CreatePhraseNodeFromAudioElement(section, n);
                    ParseSmilDocument(section, n, smilFileName, strId);
                }
            }
        }
예제 #9
0
        protected override void parseContentDocuments(List <string> spineOfContentDocuments,
                                                      Dictionary <string, string> spineAttributes,
                                                      List <Dictionary <string, string> > spineItemsAttributes,
                                                      string coverImagePath, string navDocPath)
        {
            if (spineOfContentDocuments == null || spineOfContentDocuments.Count <= 0)
            {
                return;
            }
            // assign obi project file path to xuk path to prevent creation of xukspine file.
            XukPath = m_session.Path;
            //Console.WriteLine(XukPath);

            Presentation spinePresentation = m_Project.Presentations.Get(0);

            m_IsTOCFromNavDoc = false;
            if (navDocPath != null)
            {
                string fullNavPath = Path.Combine(Path.GetDirectoryName(m_Book_FilePath), navDocPath);

                XmlDocument navDoc = urakawa.xuk.XmlReaderWriterHelper.ParseXmlDocument(fullNavPath, true, true);
                ParseNCXDocument(navDoc);
                m_IsTOCFromNavDoc = true;
            }
            //spinePresentation.RootNode.GetOrCreateXmlProperty().SetQName("spine", "");

            //if (!string.IsNullOrEmpty(m_OPF_ContainerRelativePath))
            //{
            //spinePresentation.RootNode.GetOrCreateXmlProperty().SetAttribute(OPF_ContainerRelativePath, "", m_OPF_ContainerRelativePath);
            //}

            //foreach (KeyValuePair<string, string> spineAttribute in spineAttributes)
            //{
            //spinePresentation.RootNode.GetOrCreateXmlProperty().SetAttribute(spineAttribute.Key, "", spineAttribute.Value);
            //}

            //if (m_PackagePrefixAttr != null)
            //{
            //spinePresentation.RootNode.GetOrCreateXmlProperty().SetAttribute("prefix", "", m_PackagePrefixAttr.Value);
            //}

            // Audio files may be shared between chapters of a book!

            m_OriginalAudioFile_FileDataProviderMap.Clear();
            TreenodesWithoutManagedAudioMediaData = new List <TreeNode>();
            Presentation spineItemPresentation = null;

            int index = -1;

            foreach (string docPath in spineOfContentDocuments)
            {
                index++;

                reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ReadXMLDoc, docPath));
                //System.Windows.Forms.MessageBox.Show(docPath);
                //DirectoryInfo opfParentDir = Directory.GetParent(m_Book_FilePath);
                //string dirPath = opfParentDir.ToString();
                string fullDocPath = Path.Combine(Path.GetDirectoryName(m_Book_FilePath), docPath);

                fullDocPath = FileDataProvider.NormaliseFullFilePath(fullDocPath).Replace('/', '\\');

                if (!File.Exists(fullDocPath))
                {
#if DEBUG
                    Debugger.Break();
#endif //DEBUG
                    continue;
                }

                addOPF_GlobalAssetPath(fullDocPath);

                ///TreeNode spineChild = spinePresentation.TreeNodeFactory.Create();
                //TextMedia txt = spinePresentation.MediaFactory.CreateTextMedia();
                //txt.Text = docPath; // Path.GetFileName(fullDocPath);
                //spineChild.GetOrCreateChannelsProperty().SetMedia(spinePresentation.ChannelsManager.GetOrCreateTextChannel(), txt);
                //spinePresentation.RootNode.AppendChild(spineChild);

                //spineChild.GetOrCreateXmlProperty().SetQName("metadata", "");

                //foreach (KeyValuePair<string, string> spineItemAttribute in spineItemsAttributes[index])
                //{
                //spineChild.GetOrCreateXmlProperty().SetAttribute(spineItemAttribute.Key, "", spineItemAttribute.Value);
                //}

                string ext = Path.GetExtension(fullDocPath);

                if (docPath == coverImagePath)
                {
                    DebugFix.Assert(ext.Equals(DataProviderFactory.IMAGE_SVG_EXTENSION, StringComparison.OrdinalIgnoreCase));

                    //spineChild.GetOrCreateXmlProperty().SetAttribute("cover-image", "", "true");
                }

                if (docPath == navDocPath)
                {
                    DebugFix.Assert(
                        ext.Equals(DataProviderFactory.XHTML_EXTENSION, StringComparison.OrdinalIgnoreCase) ||
                        ext.Equals(DataProviderFactory.HTML_EXTENSION, StringComparison.OrdinalIgnoreCase));

                    //spineChild.GetOrCreateXmlProperty().SetAttribute("nav", "", "true");
                }

                if (
                    !ext.Equals(DataProviderFactory.XHTML_EXTENSION, StringComparison.OrdinalIgnoreCase) &&
                    !ext.Equals(DataProviderFactory.HTML_EXTENSION, StringComparison.OrdinalIgnoreCase) &&
                    !ext.Equals(DataProviderFactory.DTBOOK_EXTENSION, StringComparison.OrdinalIgnoreCase) &&
                    !ext.Equals(DataProviderFactory.XML_EXTENSION, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    DebugFix.Assert(ext.Equals(DataProviderFactory.IMAGE_SVG_EXTENSION, StringComparison.OrdinalIgnoreCase));

                    bool notExistYet = true;
                    foreach (ExternalFileData externalFileData in m_Project.Presentations.Get(0).ExternalFilesDataManager.ManagedObjects.ContentsAs_Enumerable)
                    {
                        if (!string.IsNullOrEmpty(externalFileData.OriginalRelativePath))
                        {
                            bool notExist = docPath != externalFileData.OriginalRelativePath;
                            notExistYet = notExistYet && notExist;
                            if (!notExist)
                            {
                                break;
                            }
                        }
                    }

                    DebugFix.Assert(notExistYet);

                    if (notExistYet)
                    {
                        ExternalFileData externalData = null;
                        if (docPath == coverImagePath)
                        {
                            externalData = m_Project.Presentations.Get(0).ExternalFilesDataFactory.Create
                                           <CoverImageExternalFileData>();
                        }
                        else
                        {
                            externalData = m_Project.Presentations.Get(0).ExternalFilesDataFactory.Create
                                           <GenericExternalFileData>();
                        }
                        if (externalData != null)
                        {
                            externalData.InitializeWithData(fullDocPath, docPath, true, null);

                            addOPF_GlobalAssetPath(fullDocPath);
                        }
                    }

                    continue;
                }

                //spineChild.GetOrCreateXmlProperty().SetAttribute("xuk", "", "true");

                XmlDocument xmlDoc = urakawa.xuk.XmlReaderWriterHelper.ParseXmlDocument(fullDocPath, true, true);

                if (RequestCancellation)
                {
                    return;
                }

                ///m_PublicationUniqueIdentifier = null;
                //m_PublicationUniqueIdentifierNode = null;

                //Project spineItemProject = new Project();
                //spineItemProject.PrettyFormat = m_XukPrettyFormat;

                //string dataFolderPrefix = FileDataProvider.EliminateForbiddenFileNameCharacters(docPath);
                //spineItemPresentation = spineItemProject.AddNewPresentation(new Uri(m_outDirectory),

                //dataFolderPrefix
                //);

                //PCMFormatInfo pcmFormat = spineItemPresentation.MediaDataManager.DefaultPCMFormat; //.Copy();
                //pcmFormat.Data.SampleRate = (ushort)m_audioProjectSampleRate;
                //pcmFormat.Data.NumberOfChannels = m_audioStereo ? (ushort)2 : (ushort)1;
                //spineItemPresentation.MediaDataManager.DefaultPCMFormat = pcmFormat;

                //TextChannel textChannel = spineItemPresentation.ChannelFactory.CreateTextChannel();
                //textChannel.Name = "The Text Channel";
                //DebugFix.Assert(textChannel == spineItemPresentation.ChannelsManager.GetOrCreateTextChannel());

                //AudioChannel audioChannel = spineItemPresentation.ChannelFactory.CreateAudioChannel();
                //audioChannel.Name = "The Audio Channel";
                //DebugFix.Assert(audioChannel == spineItemPresentation.ChannelsManager.GetOrCreateAudioChannel());

                //ImageChannel imageChannel = spineItemPresentation.ChannelFactory.CreateImageChannel();
                //imageChannel.Name = "The Image Channel";
                //DebugFix.Assert(imageChannel == spineItemPresentation.ChannelsManager.GetOrCreateImageChannel());

                //VideoChannel videoChannel = spineItemPresentation.ChannelFactory.CreateVideoChannel();
                //videoChannel.Name = "The Video Channel";
                //DebugFix.Assert(videoChannel == spineItemPresentation.ChannelsManager.GetOrCreateVideoChannel());


                if (m_AudioConversionSession != null)
                {
                    RemoveSubCancellable(m_AudioConversionSession);
                    m_AudioConversionSession = null;
                }

                m_AudioConversionSession = new AudioFormatConvertorSession(
                    m_Presentation.DataProviderManager.DataFileDirectoryFullPath,
                    m_Presentation.MediaDataManager.DefaultPCMFormat,
                    m_autoDetectPcmFormat,
                    true);

                //AddSubCancellable(m_AudioConversionSession);



                if (RequestCancellation)
                {
                    return;
                }

                if (parseContentDocParts(fullDocPath, m_Project, xmlDoc, docPath, DocumentMarkupType.NA))
                {
                    return; // user cancel
                }



                /*
                 * string title = GetTitle(spineItemPresentation);
                 * if (!string.IsNullOrEmpty(title))
                 * {
                 *  spineChild.GetOrCreateXmlProperty().SetAttribute("title", "", title);
                 * }
                 *
                 *
                 * if (false) // do not copy metadata from project to individual chapter
                 * {
                 *  foreach (Metadata metadata in m_Project.Presentations.Get(0).Metadatas.ContentsAs_Enumerable)
                 *  {
                 *      Metadata md = spineItemPresentation.MetadataFactory.CreateMetadata();
                 *      md.NameContentAttribute = metadata.NameContentAttribute.Copy();
                 *
                 *      foreach (MetadataAttribute metadataAttribute in metadata.OtherAttributes.ContentsAs_Enumerable)
                 *      {
                 *          MetadataAttribute mdAttr = metadataAttribute.Copy();
                 *          md.OtherAttributes.Insert(md.OtherAttributes.Count, mdAttr);
                 *      }
                 *
                 *      spineItemPresentation.Metadatas.Insert(spineItemPresentation.Metadatas.Count, md);
                 *  }
                 * }
                 */

                foreach (KeyValuePair <string, string> spineItemAttribute in spineItemsAttributes[index])
                {
                    if (spineItemAttribute.Key == "media-overlay")
                    {
                        string opfDirPath  = Path.GetDirectoryName(m_Book_FilePath);
                        string overlayPath = spineItemAttribute.Value;


                        reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ParsingMediaOverlay, overlayPath));


                        string fullOverlayPath = Path.Combine(opfDirPath, overlayPath);
                        if (!File.Exists(fullOverlayPath))
                        {
                            continue;
                        }

                        XmlDocument overlayXmlDoc = XmlReaderWriterHelper.ParseXmlDocument(fullOverlayPath, false, false);

                        SectionNode           section      = m_Presentation.FirstSection;
                        IEnumerable <XmlNode> textElements = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(overlayXmlDoc, true, "text", null, false);
                        if (textElements == null)
                        {
                            continue;
                        }
                        // audio list replaced by text list
                        //IEnumerable<XmlNode> audioElements = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(overlayXmlDoc, true, "audio", null, false);
                        //if (audioElements == null)
                        //{
                        //continue;
                        //}

                        //foreach (XmlNode audioNode in audioElements)
                        foreach (XmlNode textNode in textElements)
                        {
                            XmlAttributeCollection attrs = textNode.Attributes;
                            if (attrs == null)
                            {
                                continue;
                            }
                            //XmlAttributeCollection attrs = audioNode.Attributes;
                            //if (attrs == null)
                            //{
                            //continue;
                            //}
                            XmlNode attrSrc = attrs.GetNamedItem("src");
                            if (attrSrc == null)
                            {
                                continue;
                            }

                            //XmlNode attrBegin = attrs.GetNamedItem("clipBegin");
                            //XmlNode attrEnd = attrs.GetNamedItem("clipEnd");

                            //string overlayDirPath = Path.GetDirectoryName(fullOverlayPath);
                            //string fullAudioPath = Path.Combine(overlayDirPath, attrSrc.Value);

                            //if (!File.Exists(fullAudioPath))
                            //{
                            //    continue;
                            //}


                            //if (RequestCancellation) return;
                            //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.DecodingAudio, Path.GetFileName(fullAudioPath)));


                            TreeNode   textTreeNode = null;
                            XmlNode    audioNode    = null;
                            PageNumber pgNumber     = null;
                            //XmlNodeList children = audioNode.ParentNode.ChildNodes;
                            XmlNodeList children = textNode.ParentNode.ChildNodes;
                            foreach (XmlNode child in children)
                            {
                                //if (child == audioNode)
                                //{
                                //continue;
                                //}
                                //if (child.LocalName != "text")
                                //{
                                //continue;
                                //}
                                if (child.LocalName == "audio")
                                {
                                    audioNode = child;
                                }

                                //XmlAttributeCollection textAttrs = child.Attributes;
                                XmlAttributeCollection textAttrs = textNode.Attributes;
                                if (textAttrs == null)
                                {
                                    continue;
                                }

                                XmlNode textSrc = textAttrs.GetNamedItem("src");
                                if (textSrc == null)
                                {
                                    continue;
                                }

                                string urlDecoded = FileDataProvider.UriDecode(textSrc.Value);
                                string contentFilesDirectoryPath = Path.GetDirectoryName(fullOverlayPath);
                                if (urlDecoded.StartsWith("./"))
                                {
                                    urlDecoded = urlDecoded.Remove(0, 2);
                                }
                                if (urlDecoded.StartsWith("../"))
                                {
                                    urlDecoded = urlDecoded.Remove(0, 3);
                                    contentFilesDirectoryPath = Path.GetDirectoryName(contentFilesDirectoryPath);
                                }
                                if (urlDecoded.IndexOf('#') > 0)
                                {
                                    string[] srcParts = urlDecoded.Split('#');
                                    if (srcParts.Length != 2)
                                    {
                                        continue;
                                    }

                                    string fullTextRefPath = Path.Combine(contentFilesDirectoryPath,
                                                                          srcParts[0]);
                                    fullTextRefPath =
                                        FileDataProvider.NormaliseFullFilePath(fullTextRefPath).Replace('/', '\\');

                                    if (!fullTextRefPath.Equals(fullDocPath, StringComparison.OrdinalIgnoreCase))
                                    {
                                        //#if DEBUG
                                        //                                Debugger.Break();
                                        //#endif //DEBUG

                                        continue;
                                    }

                                    string txtId = srcParts[1];

                                    //textTreeNode = spineItemPresentation.RootNode.GetFirstDescendantWithXmlID(txtId);
                                    // replacing it
                                    //System.Windows.Forms.MessageBox.Show("retrieving: " + urlDecoded);
                                    if (m_XmlIdToSectionNodeMap.ContainsKey(urlDecoded))
                                    {
                                        textTreeNode = m_XmlIdToSectionNodeMap[urlDecoded];
                                    }
                                    else if (m_XmlIdToSectionNodeMap.ContainsKey(srcParts[0]))
                                    {
                                        textTreeNode = m_XmlIdToSectionNodeMap[srcParts[0]];
                                    }
                                    if (textTreeNode != null)
                                    {
                                        section = (SectionNode)textTreeNode;
                                        //System.Windows.Forms.MessageBox.Show(((SectionNode)textTreeNode).Label);
                                    }
                                }
                                else
                                {
                                    string fullTextRefPath = Path.Combine(Path.GetDirectoryName(fullOverlayPath),
                                                                          urlDecoded);
                                    fullTextRefPath =
                                        FileDataProvider.NormaliseFullFilePath(fullTextRefPath).Replace('/', '\\');

                                    if (!fullTextRefPath.Equals(fullDocPath, StringComparison.OrdinalIgnoreCase))
                                    {
                                        //#if DEBUG
                                        //                                Debugger.Break();
                                        //#endif //DEBUG

                                        continue;
                                    }

                                    textTreeNode = spineItemPresentation.RootNode;
                                }
                                if (m_XmlIdToPageNodeMap.ContainsKey(urlDecoded) &&
                                    m_XmlIdToPageNodeMap[urlDecoded] != null)
                                {
                                    EmptyNode pgNode = m_XmlIdToPageNodeMap[urlDecoded];
                                    pgNumber = pgNode.PageNumber;

                                    // if the section does not match then the parent of the page node should become the section.
                                    if (pgNode.IsRooted &&
                                        textTreeNode == null &&
                                        pgNode.Parent != section)
                                    {
                                        section = pgNode.ParentAs <SectionNode>();
                                        //Console.WriteLine("text node is null");
                                    }
                                    if (pgNode.IsRooted)
                                    {
                                        pgNode.Detach();
                                    }
                                    // the phrases following the page phrase in smil will refer to same content doc ID. so to avoid reassigning page, the page node in dictionary is assigned to null.
                                    m_XmlIdToPageNodeMap[urlDecoded] = null;
                                }
                            }

                            if (section != null && audioNode != null)
                            {
                                PhraseNode audioWrapperNode = m_Presentation.CreatePhraseNode();

                                section.AppendChild(audioWrapperNode);
                                addAudio(audioWrapperNode, audioNode, false, fullOverlayPath);
                                if (audioWrapperNode.Duration == 0 && !TreenodesWithoutManagedAudioMediaData.Contains(audioWrapperNode))
                                {
                                    TreenodesWithoutManagedAudioMediaData.Add(audioWrapperNode);
                                }
                                if (pgNumber != null)
                                {
                                    audioWrapperNode.PageNumber = pgNumber;
                                    pgNumber = null;
                                }
                            }

                            audioNode = null;
                        }
                    }
                }


                //spinePresentation.MediaDataManager.DefaultPCMFormat = spineItemPresentation.MediaDataManager.DefaultPCMFormat; //copied!

                //string xuk_FilePath = GetXukFilePath_SpineItem(m_outDirectory, docPath, title, index);

                //string xukFileName = Path.GetFileName(xuk_FilePath);
                //spineChild.GetOrCreateXmlProperty().SetAttribute("xukFileName", "", xukFileName);

                //deleteDataDirectoryIfEmpty();
                //string dataFolderPath = spineItemPresentation.DataProviderManager.DataFileDirectoryFullPath;
                //spineItemPresentation.DataProviderManager.SetCustomDataFileDirectory(Path.GetFileNameWithoutExtension(xuk_FilePath));

                //string newDataFolderPath = spineItemPresentation.DataProviderManager.DataFileDirectoryFullPath;
                //DebugFix.Assert(Directory.Exists(newDataFolderPath));

                //if (newDataFolderPath != dataFolderPath)
                {
                    /*
                     * try
                     * {
                     *  if (Directory.Exists(newDataFolderPath))
                     *  {
                     *      FileDataProvider.TryDeleteDirectory(newDataFolderPath, false);
                     *  }
                     *
                     *  Directory.Move(dataFolderPath, newDataFolderPath);
                     * }
                     * catch (Exception ex)
                     * {
                     #if DEBUG
                     *  Debugger.Break();
                     #endif // DEBUG
                     *  Console.WriteLine(ex.Message);
                     *  Console.WriteLine(ex.StackTrace);
                     *
                     *  spineItemPresentation.DataProviderManager.SetCustomDataFileDirectory(dataFolderPrefix);
                     * }
                     */
                }
            }
        }