Ejemplo n.º 1
0
        private List <SectionNode> GetSectionsList(urakawa.core.TreeNode rNode) //sdk2 :used treenode instead of rootnode
        {
            List <SectionNode> sectionsList = new List <SectionNode> ();

            m_FirstPageNumberedPhraseOfFirstSection = null;
            rNode.AcceptDepthFirst(
                delegate(urakawa.core.TreeNode n)
            {
                if (n is SectionNode)
                {
                    if (!((SectionNode)n).Used)
                    {
                        return(false);
                    }
                    sectionsList.Add((SectionNode)n);
                    m_NextSectionPageAdjustmentDictionary.Add((SectionNode)n, null);
                }
                else if (n is EmptyNode && ((EmptyNode)n).Used &&
                         ((EmptyNode)n).Index == 0 && ((EmptyNode)n).Role_ == EmptyNode.Role.Page)
                {
                    if (sectionsList.Count >= 2)
                    {
                        m_NextSectionPageAdjustmentDictionary[sectionsList[sectionsList.Count - 2]] = (EmptyNode)n;
                    }
                    if (sectionsList.Count == 1)
                    {
                        m_FirstPageNumberedPhraseOfFirstSection = (EmptyNode)n;
                    }
                }
                return(true);
            },
                delegate(urakawa.core.TreeNode n) { });

            return(sectionsList);
        }
Ejemplo n.º 2
0
        private urakawa.media.ExternalAudioMedia GetExternalAudioMedia(urakawa.core.TreeNode node)
        {
            List <urakawa.property.channel.Channel> channelsList = m_Presentation.ChannelsManager.GetChannelsByName(PUBLISH_AUDIO_CHANNEL_NAME);

            if (channelsList == null || channelsList.Count == 0)
            {
                return(null);
            }

            if (channelsList == null || channelsList.Count > 1)
            {
                throw new System.Exception("more than one publish channel cannot exist");
            }

            Channel publishChannel = channelsList[0];

            urakawa.property.channel.ChannelsProperty mediaProperty = node.GetProperty <ChannelsProperty>();

            if (mediaProperty == null)
            {
                return(null);
            }

            return((ExternalAudioMedia)mediaProperty.GetMedia(publishChannel));
        }
Ejemplo n.º 3
0
 public void GetRootParent()
 {
     urakawa.core.TreeNode root = mProject.Presentations.Get(0).RootNode;
     if (root != null)
     {
         Assert.IsNull(root.Parent, "Parent of root is null");
     }
 }
Ejemplo n.º 4
0
 public void TryToSetNullProperty()
 {
     urakawa.core.TreeNode root = mProject.Presentations.Get(0).RootNode;
     if (root != null)
     {
         try
         {
             root.AddProperty(null);
         }
         catch (exception.MethodParameterIsNullException)
         {
             return;
         }
         Assert.Fail("Expected MethodParameterIsNullException");
     }
 }
Ejemplo n.º 5
0
        private static core.TreeNode getTreeNodeWithXmlElementId(core.TreeNode node, string id)
        {
            if (node.GetXmlElementId() == id)
            {
                return(node);
            }

            for (int i = 0; i < node.ChildCount; i++)
            {
                core.TreeNode child = getTreeNodeWithXmlElementId(node.GetChild(i), id);
                if (child != null)
                {
                    return(child);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        private void parseDTBookXmlDocAndPopulateDataModel(XmlNode xmlNode, core.TreeNode parentTreeNode)
        {
            XmlNodeType xmlType = xmlNode.NodeType;

            switch (xmlType)
            {
            case XmlNodeType.Attribute:
            {
                System.Diagnostics.Debug.Fail("Calling this method with an XmlAttribute should never happen !!");
                break;
            }

            case XmlNodeType.Document:
            {
                parseDTBookXmlDocAndPopulateDataModel(((XmlDocument)xmlNode).DocumentElement, parentTreeNode);
                break;
            }

            case XmlNodeType.Element:
            {
                Presentation presentation = m_Project.GetPresentation(0);

                core.TreeNode treeNode = presentation.TreeNodeFactory.Create();

                if (parentTreeNode == null)
                {
                    presentation.RootNode = treeNode;
                    parentTreeNode        = presentation.RootNode;
                }
                else
                {
                    parentTreeNode.AppendChild(treeNode);
                }

                XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty();
                treeNode.AddProperty(xmlProp);
                xmlProp.LocalName = xmlNode.Name;
                if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document)
                {
                    presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI;
                }

                if (xmlNode.NamespaceURI != presentation.PropertyFactory.DefaultXmlNamespaceUri)
                {
                    xmlProp.NamespaceUri = xmlNode.NamespaceURI;
                }

                XmlAttributeCollection attributeCol = xmlNode.Attributes;

                if (attributeCol != null)
                {
                    for (int i = 0; i < attributeCol.Count; i++)
                    {
                        XmlNode attr = attributeCol.Item(i);
                        if (attr.Name != "smilref")
                        {
                            xmlProp.SetAttribute(attr.Name, "", attr.Value);
                        }
                    }


                    if (xmlNode.Name == "meta")
                    {
                        XmlNode attrName    = attributeCol.GetNamedItem("name");
                        XmlNode attrContent = attributeCol.GetNamedItem("content");
                        if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) &&
                            !String.IsNullOrEmpty(attrContent.Value))
                        {
                            Metadata md = presentation.MetadataFactory.CreateMetadata();
                            md.Name    = attrName.Value;
                            md.Content = attrContent.Value;
                            presentation.AddMetadata(md);
                        }
                    }
                }


                foreach (XmlNode childXmlNode in xmlNode.ChildNodes)
                {
                    parseDTBookXmlDocAndPopulateDataModel(childXmlNode, treeNode);
                }
                break;
            }

            case XmlNodeType.Text:
            {
                Presentation presentation = m_Project.GetPresentation(0);

                string    text      = xmlNode.Value;
                TextMedia textMedia = presentation.MediaFactory.CreateTextMedia();
                textMedia.Text = text;

                ChannelsProperty cProp = presentation.PropertyFactory.CreateChannelsProperty();
                cProp.SetMedia(m_textChannel, textMedia);

                int counter = 0;
                foreach (XmlNode childXmlNode in xmlNode.ParentNode.ChildNodes)
                {
                    XmlNodeType childXmlType = childXmlNode.NodeType;
                    if (childXmlType == XmlNodeType.Text || childXmlType == XmlNodeType.Element)
                    {
                        counter++;
                    }
                }
                if (counter == 1)
                {
                    parentTreeNode.AddProperty(cProp);
                }
                else
                {
                    core.TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create();
                    txtWrapperNode.AddProperty(cProp);
                    parentTreeNode.AppendChild(txtWrapperNode);
                }

                break;
            }

            default:
            {
                return;
            }
            }
        }
Ejemplo n.º 7
0
        private void parseSmil(string fullSmilPath)
        {
            Presentation presentation = m_Project.GetPresentation(0);

            string dirPath = Path.GetDirectoryName(m_Book_FilePath);

            XmlDocument smilXmlDoc = readXmlDocument(fullSmilPath);

            XmlNodeList listOfAudioNodes = smilXmlDoc.GetElementsByTagName("audio");

            if (listOfAudioNodes != null)
            {
                foreach (XmlNode audioNode in listOfAudioNodes)
                {
                    XmlAttributeCollection attributeCol = audioNode.Attributes;

                    if (attributeCol != null)
                    {
                        XmlNode attrAudioSrc = attributeCol.GetNamedItem("src");
                        if (attrAudioSrc != null && !String.IsNullOrEmpty(attrAudioSrc.Value))
                        {
                            XmlNode parent = audioNode.ParentNode;
                            if (parent != null && parent.Name == "a")
                            {
                                parent = parent.ParentNode;
                            }

                            if (parent != null)
                            {
                                XmlNodeList listOfAudioPeers = parent.ChildNodes;
                                foreach (XmlNode peerNode in listOfAudioPeers)
                                {
                                    if (peerNode.NodeType == XmlNodeType.Element && peerNode.Name == "text")
                                    {
                                        XmlAttributeCollection peerAttrs = peerNode.Attributes;

                                        if (peerAttrs != null)
                                        {
                                            XmlNode attrTextSrc = peerAttrs.GetNamedItem("src");
                                            if (attrTextSrc != null && !String.IsNullOrEmpty(attrTextSrc.Value))
                                            {
                                                int index = attrTextSrc.Value.LastIndexOf('#');
                                                if (index < (attrTextSrc.Value.Length - 1))
                                                {
                                                    string        dtbookFragmentId = attrTextSrc.Value.Substring(index + 1);
                                                    core.TreeNode tNode            = getTreeNodeWithXmlElementId(dtbookFragmentId);
                                                    if (tNode != null)
                                                    {
                                                        AbstractAudioMedia existingAudioMedia = tNode.GetAudioMedia();
                                                        if (existingAudioMedia != null)
                                                        {
                                                            //Ignore.
                                                            //System.Diagnostics.Debug.Fail("TreeNode already has media ??");
                                                        }

                                                        XmlNode attrClipBegin = attributeCol.GetNamedItem("clipBegin");
                                                        XmlNode attrClipEnd   = attributeCol.GetNamedItem("clipEnd");

                                                        Media media = null;
                                                        if (attrAudioSrc.Value.EndsWith("wav"))
                                                        {
                                                            string fullWavPath = Path.Combine(dirPath,
                                                                                              attrAudioSrc.Value);

                                                            PCMDataInfo pcmInfo   = null;
                                                            Stream      wavStream = null;
                                                            try
                                                            {
                                                                wavStream = File.Open(fullWavPath, FileMode.Open,
                                                                                      FileAccess.Read, FileShare.Read);
                                                                pcmInfo = PCMDataInfo.ParseRiffWaveHeader(wavStream);
                                                                presentation.MediaDataManager.DefaultPCMFormat = pcmInfo.Copy();
                                                                TimeDelta duration = new TimeDelta(pcmInfo.Duration);

                                                                Time clipB = Time.Zero;
                                                                Time clipE = Time.MaxValue;

                                                                if (attrClipBegin != null &&
                                                                    !string.IsNullOrEmpty(attrClipBegin.Value))
                                                                {
                                                                    clipB = new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                                }
                                                                if (attrClipEnd != null &&
                                                                    !string.IsNullOrEmpty(attrClipEnd.Value))
                                                                {
                                                                    clipE = new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                                }
                                                                if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue))
                                                                {
                                                                    duration = clipE.GetTimeDelta(clipB);
                                                                }
                                                                long byteOffset = 0;
                                                                if (!clipB.IsEqualTo(Time.Zero))
                                                                {
                                                                    byteOffset = pcmInfo.GetByteForTime(clipB);
                                                                }
                                                                if (byteOffset > 0)
                                                                {
                                                                    wavStream.Seek(byteOffset, SeekOrigin.Current);
                                                                }

                                                                presentation.MediaDataFactory.DefaultAudioMediaDataType =
                                                                    typeof(WavAudioMediaData);

                                                                WavAudioMediaData mediaData =
                                                                    (WavAudioMediaData)
                                                                    presentation.MediaDataFactory.CreateAudioMediaData();
                                                                mediaData.InsertAudioData(wavStream, Time.Zero, duration);

                                                                media = presentation.MediaFactory.CreateManagedAudioMedia();
                                                                ((ManagedAudioMedia)media).AudioMediaData = mediaData;
                                                            }
                                                            finally
                                                            {
                                                                if (wavStream != null)
                                                                {
                                                                    wavStream.Close();
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            media = presentation.MediaFactory.CreateExternalAudioMedia();
                                                            ((ExternalAudioMedia)media).Src = attrAudioSrc.Value;
                                                            if (attrClipBegin != null &&
                                                                !string.IsNullOrEmpty(attrClipBegin.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipBegin =
                                                                    new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                            }
                                                            if (attrClipEnd != null &&
                                                                !string.IsNullOrEmpty(attrClipEnd.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipEnd =
                                                                    new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                            }
                                                        }

                                                        ChannelsProperty chProp = tNode.GetProperty <ChannelsProperty>();
                                                        if (chProp == null)
                                                        {
                                                            chProp =
                                                                presentation.PropertyFactory.CreateChannelsProperty();
                                                            tNode.AddProperty(chProp);
                                                        }
                                                        chProp.SetMedia(m_audioChannel, media);
                                                        break; // scan peers to audio node
                                                    }
                                                    else
                                                    {
                                                        System.Diagnostics.Debug.Fail("XmlProperty with ID not found ??");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }