private void ImportFromXHTML() { try { XmlDocument nccDocument = null; if (m_Settings.Project_ImportNCCFileWithWindows1252Encoding) { // some old files may have 7 bit encoding. StreamReader sr = new StreamReader(m_NccPath, Encoding.GetEncoding(1252), false); string xmlData = sr.ReadToEnd(); nccDocument = XmlReaderWriterHelper.ParseXmlDocumentFromString(xmlData, false, false); } else { nccDocument = XmlReaderWriterHelper.ParseXmlDocument(m_NccPath, false, false); } XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(nccDocument.DocumentElement, true, "head", nccDocument.DocumentElement.NamespaceURI); PopulateMetadataFromNcc(headNode); XmlNode bodyNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(nccDocument.DocumentElement, true, "body", nccDocument.DocumentElement.NamespaceURI); ParseNccDocument(bodyNode); if (RequestCancellation) { return; } reportProgress(20, ""); AppendPhrasesFromSmil(); reportProgress(100, ""); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } }
public static string GrabIdentifier(string xhtmlPath) { string uId = null; XmlDocument xmlDoc = XmlReaderWriterHelper.ParseXmlDocument(xhtmlPath, false, false); XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlDoc.DocumentElement, true, "head", xmlDoc.DocumentElement.NamespaceURI); if (headNode != null) { foreach (XmlNode metaNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(headNode, true, "meta", headNode.NamespaceURI, false)) { string name = metaNode.Attributes.GetNamedItem("name") != null?metaNode.Attributes.GetNamedItem("name").Value : null; string content = metaNode.Attributes.GetNamedItem("content") != null?metaNode.Attributes.GetNamedItem("content").Value : null; if (name == null) { continue; } if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(content) && name.ToLower() == "dc:identifier") { return(content); } } } return(uId); }
protected virtual void AddPagePropertiesToAudioNode(TreeNode audioWrapperNode, XmlNode pageTargetNode) { TextMedia textMedia = audioWrapperNode.Presentation.MediaFactory.CreateTextMedia(); textMedia.Text = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(pageTargetNode, true, "text", pageTargetNode.NamespaceURI).InnerText; ChannelsProperty cProp = audioWrapperNode.Presentation.PropertyFactory.CreateChannelsProperty(); cProp.SetMedia(audioWrapperNode.Presentation.ChannelsManager.GetOrCreateTextChannel(), textMedia); audioWrapperNode.AddProperty(cProp); System.Xml.XmlAttributeCollection pageAttributes = pageTargetNode.Attributes; if (pageAttributes != null) { XmlProperty xmlProp = audioWrapperNode.GetXmlProperty(); xmlProp.SetQName("pagenum", ""); string nsUri = audioWrapperNode.GetXmlNamespaceUri(); foreach (System.Xml.XmlAttribute attr in pageAttributes) { string uri = ""; if (!string.IsNullOrEmpty(attr.NamespaceURI)) { if (attr.NamespaceURI != nsUri) { uri = attr.NamespaceURI; } } xmlProp.SetAttribute(attr.Name, uri, attr.Value); } } }
public void ImportFromXHTML(string filePath) { try { XmlDocument xhtmlDocument = null; xhtmlDocument = urakawa.xuk.XmlReaderWriterHelper.ParseXmlDocument(filePath, false, false); if (xhtmlDocument != null && xhtmlDocument.DocumentType != null && xhtmlDocument.DocumentType.ParentNode != null) { //XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName( // xhtmlDocument.DocumentElement, true, "head", xhtmlDocument.DocumentElement.NamespaceURI); //PopulateMetadataFromNcc(headNode); XmlNode bodyNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName( xhtmlDocument.DocumentElement, true, "body", xhtmlDocument.DocumentElement.NamespaceURI); if (bodyNode != null) { ParseXHTMLDocument(bodyNode); } } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } }
private void ImportMetadatas(XmlDocument sourceXmlDoc, XmlDocument destXmlDoc) { XmlNode OldMetadataParent = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(sourceXmlDoc.DocumentElement, true, "mMetadata", null); XmlNode newMetadatas = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(destXmlDoc.DocumentElement, true, "Metadatas", null); //foreach (XmlNode childToRemove in newMetadatas.ChildNodes) newMetadatas.RemoveChild(childToRemove); Dictionary <string, XmlNode> existingMetadataAttributeNode = new Dictionary <string, XmlNode>(); foreach (XmlNode newMetadataAttributeItem in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(newMetadatas, true, "MetadataAttribute", null, false)) { existingMetadataAttributeNode.Add(newMetadataAttributeItem.Attributes.GetNamedItem("Name").Value, newMetadataAttributeItem); } foreach (XmlNode metadataItem in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(OldMetadataParent, true, "Metadata", OldMetadataParent.NamespaceURI, false)) { if (existingMetadataAttributeNode.ContainsKey(metadataItem.Attributes.GetNamedItem("name").Value)) { existingMetadataAttributeNode[metadataItem.Attributes.GetNamedItem("name").Value].Attributes.GetNamedItem("Value").Value = metadataItem.Attributes.GetNamedItem("content").Value; //System.Windows.Forms.MessageBox.Show(metadataItem.Attributes.GetNamedItem("name").Value); } else { // create new metadata node in dest document XmlNode newMetadata = destXmlDoc.CreateElement("Metadata", newMetadatas.NamespaceURI); newMetadatas.AppendChild(newMetadata); XmlNode newMetadataAttribute = destXmlDoc.CreateElement("MetadataAttribute", newMetadata.NamespaceURI); newMetadata.AppendChild(newMetadataAttribute); XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newMetadataAttribute, "Name", metadataItem.Attributes.GetNamedItem("name").Value); XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newMetadataAttribute, "Value", metadataItem.Attributes.GetNamedItem("content") != null?metadataItem.Attributes.GetNamedItem("content").Value: "NA"); } } }
protected void AddMetadata_Smil(XmlDocument smilDocument, string strElapsedTime, List <string> currentSmilCustomTestList) { XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(smilDocument, true, "head", null); //smilDocument.GetElementsByTagName("head")[0]; AddMetadata_DtbUid(false, smilDocument, headNode); AddMetadata_Generator(smilDocument, headNode); AddMetadataAsAttributes(smilDocument, headNode, SupportedMetadata_Z39862005.DTB_TOTAL_ELAPSED_TIME, strElapsedTime); //if (isCustomTestRequired) //{ if (currentSmilCustomTestList != null && currentSmilCustomTestList.Count > 0) { XmlNode customAttributesNode = smilDocument.CreateElement(null, "customAttributes", headNode.NamespaceURI); headNode.AppendChild(customAttributesNode); foreach (string customTestName in currentSmilCustomTestList) { XmlNode customTestNode = smilDocument.CreateElement(null, "customTest", headNode.NamespaceURI); customAttributesNode.AppendChild(customTestNode); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, customTestNode, "defaultState", "false"); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, customTestNode, "id", customTestName); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, customTestNode, "override", "visible"); //<customTest defaultState="false" id="note" override="visible" /> } } }
private XmlNode CreateDocTitle(XmlDocument ncxDocument, XmlNode ncxRootNode, TreeNode n, TreeNode levelNode) { XmlNode docNode = ncxDocument.CreateElement(null, "docTitle", ncxRootNode.NamespaceURI); XmlNode navMapNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(ncxDocument, true, "navMap", null); ncxRootNode.InsertBefore(docNode, navMapNode); XmlNode docTxtNode = ncxDocument.CreateElement(null, "text", docNode.NamespaceURI); docNode.AppendChild(docTxtNode); docTxtNode.AppendChild( ncxDocument.CreateTextNode(prepareNcxLabelText(n))); ExternalAudioMedia externalAudio = GetExternalAudioMedia(n); if (externalAudio != null) { // create audio node XmlNode docAudioNode = ncxDocument.CreateElement(null, "audio", docNode.NamespaceURI); docNode.AppendChild(docAudioNode); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, docAudioNode, "clipBegin", FormatTimeString(externalAudio.ClipBegin)); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, docAudioNode, "clipEnd", FormatTimeString(externalAudio.ClipEnd)); string extAudioSrc = AdjustAudioFileName(externalAudio, levelNode); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, docAudioNode, "src", FileDataProvider.UriEncode(Path.GetFileName(extAudioSrc))); } return(docNode); }
protected override TreeNode CheckAndAssignForHeadingAudio(TreeNode navPointTreeNode, TreeNode phraseTreeNode, XmlNode audioXmlNode) { XmlNode navLabelXmlNode = m_NavPointNode_NavLabelMap[navPointTreeNode]; XmlNode headingAudio = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navLabelXmlNode, true, "audio", navLabelXmlNode.NamespaceURI); //XmlNode textNode = XmlDocumentHelper.GetFirstChildElementWithName(navLabelXmlNode, true, "text", navLabelXmlNode.NamespaceURI); if (headingAudio == null) { Console.WriteLine("NCX Heading node is null for " + navLabelXmlNode.InnerText); return(null); } double headingClipBegin = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds); double headingClipEnd = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds); double audioClipBegin = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds); double audioClipEnd = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds); if (((SectionNode)navPointTreeNode).PhraseChild(0) != phraseTreeNode && headingAudio.Attributes.GetNamedItem("src").Value == audioXmlNode.Attributes.GetNamedItem("src").Value && Math.Abs(headingClipBegin - audioClipBegin) <= 1 && Math.Abs(headingClipEnd - audioClipEnd) <= 1) { ((EmptyNode)phraseTreeNode).Role_ = EmptyNode.Role.Heading; } return(phraseTreeNode); }
protected virtual TreeNode CheckAndAssignForHeadingAudio(TreeNode navPointTreeNode, TreeNode phraseTreeNode, XmlNode audioXmlNode) { XmlNode navLabelXmlNode = m_NavPointNode_NavLabelMap[navPointTreeNode]; XmlNode headingAudio = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navLabelXmlNode, true, "audio", navLabelXmlNode.NamespaceURI); XmlNode textNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navLabelXmlNode, true, "text", navLabelXmlNode.NamespaceURI); double headingClipBegin = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds); double headingClipEnd = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds); double audioClipBegin = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds); double audioClipEnd = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds); if (headingAudio.Attributes.GetNamedItem("src").Value == audioXmlNode.Attributes.GetNamedItem("src").Value && Math.Abs(headingClipBegin - audioClipBegin) <= 1 && Math.Abs(headingClipEnd - audioClipEnd) <= 1) { TextMedia textMedia = navPointTreeNode.Presentation.MediaFactory.CreateTextMedia(); textMedia.Text = textNode.InnerText; ChannelsProperty cProp = navPointTreeNode.Presentation.PropertyFactory.CreateChannelsProperty(); cProp.SetMedia(navPointTreeNode.Presentation.ChannelsManager.GetOrCreateTextChannel(), textMedia); //TreeNode txtWrapperNode = parentNode.Presentation.TreeNodeFactory.Create(); phraseTreeNode.AddProperty(cProp); //treeNode.AppendChild(txtWrapperNode); XmlProperty TextNodeXmlProp = navPointTreeNode.Presentation.PropertyFactory.CreateXmlProperty(); phraseTreeNode.AddProperty(TextNodeXmlProp); TextNodeXmlProp.SetQName("hd", ""); } return(phraseTreeNode); }
public virtual void ParseNCXDocument(XmlDocument ncxDocument) { m_SmilRefToNavPointTreeNodeMap = new Dictionary <string, TreeNode>(); m_NavPointNode_NavLabelMap = new Dictionary <TreeNode, XmlNode>(); //string ncxPath = Directory.GetFiles(Directory.GetParent(m_Book_FilePath).FullName, "*.ncx")[0]; //ncxDocument = xuk.OpenXukAction.ParseXmlDocument(ncxPath, false); XmlNode navMap = ncxDocument.GetElementsByTagName("navMap")[0]; Presentation presentation = m_Project.Presentations.Get(0); XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty(); xmlProp.SetQName("book", navMap.NamespaceURI == null ? "" : navMap.NamespaceURI); presentation.PropertyFactory.DefaultXmlNamespaceUri = navMap.NamespaceURI; TreeNode treeNode = null; if (presentation.RootNode == null) { treeNode = presentation.TreeNodeFactory.Create(); presentation.RootNode = treeNode; } else { treeNode = presentation.RootNode; } treeNode.AddProperty(xmlProp); m_DocTitleXmlNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(ncxDocument.DocumentElement, true, "docTitle", ncxDocument.DocumentElement.NamespaceURI); m_IsDocTitleCreated = false; ParseNCXNodes(presentation, navMap, treeNode); CollectPagesFromPageList(navMap); }
protected override void AddPagePropertiesToAudioNode(TreeNode audioWrapperNode, XmlNode pageTargetNode) { string strKind = pageTargetNode.Attributes.GetNamedItem("type").Value; PageKind kind = strKind == "front" ? PageKind.Front : strKind == "normal" ? PageKind.Normal : PageKind.Special; string pageNumberString = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(pageTargetNode, true, "text", pageTargetNode.NamespaceURI).InnerText; 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); } else { pageNumberString = pageTargetNode.Attributes.GetNamedItem("value") != null?pageTargetNode.Attributes.GetNamedItem("value").Value : ""; pageNumber = EmptyNode.SafeParsePageNumber(pageNumberString); if (pageNumber > 0) { number = new PageNumber(pageNumber, kind); } } } if (number != null) { EmptyNode node = (EmptyNode)audioWrapperNode; node.PageNumber = number; } /* * TextMedia textMedia = audioWrapperNode.Presentation.MediaFactory.CreateTextMedia(); * textMedia.Text = XmlDocumentHelper.GetFirstChildElementWithName(pageTargetNode, true, "text", pageTargetNode.NamespaceURI).InnerText; * ChannelsProperty cProp = audioWrapperNode.Presentation.PropertyFactory.CreateChannelsProperty(); * cProp.SetMedia(m_textChannel, textMedia); * audioWrapperNode.AddProperty(cProp); * System.Xml.XmlAttributeCollection pageAttributes = pageTargetNode.Attributes; * if (pageAttributes != null) * { * XmlProperty xmlProp = audioWrapperNode.GetXmlProperty(); * foreach (System.Xml.XmlAttribute attr in pageAttributes) * { * xmlProp.SetAttribute(attr.Name, attr.NamespaceURI, attr.Value); * } * } */ }
private string GetSmilReferenceString(XmlNode xNode) { XmlNode anchorNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xNode, true, "a", xNode.NamespaceURI); if (anchorNode == null) { return(null); } XmlNode attr = anchorNode.Attributes.GetNamedItem("href"); return(attr != null? attr.Value : null); }
protected override TreeNode CreateTreeNodeForNavPoint(TreeNode parentNode, XmlNode navPoint) { SectionNode treeNode = m_Presentation.CreateSectionNode(); //= parentNode.Presentation.TreeNodeFactory.Create(); //parentNode.AppendChild(treeNode); if (navPoint.LocalName == "docTitle") { ((ObiNode)m_Presentation.RootNode).Insert(treeNode, 0); } else { if (parentNode is ObiRootNode) { ((ObiNode)parentNode).AppendChild(treeNode); } else { ((SectionNode)parentNode).AppendChild(treeNode); } } //XmlProperty xmlProp = parentNode.Presentation.PropertyFactory.CreateXmlProperty(); //treeNode.AddProperty(xmlProp); XmlNode textNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navPoint, true, "text", navPoint.NamespaceURI); //xmlProp.LocalName = "level";//+":" + textNode.InnerText; // create urakawa tree node //TextMedia textMedia = parentNode.Presentation.MediaFactory.CreateTextMedia(); //textMedia.Text = textNode.InnerText; //treeNode.Label = textNode.InnerText; string strLabel = textNode.InnerText; strLabel = strLabel.Replace("\n", "").Replace("\r", "").Replace("\t", ""); treeNode.Label = strLabel; //ChannelsProperty cProp = parentNode.Presentation.PropertyFactory.CreateChannelsProperty(); //cProp.SetMedia(m_textChannel, textMedia); //TreeNode txtWrapperNode = parentNode.Presentation.TreeNodeFactory.Create(); //txtWrapperNode.AddProperty(cProp); //treeNode.AppendChild(txtWrapperNode); //XmlProperty TextNodeXmlProp = parentNode.Presentation.PropertyFactory.CreateXmlProperty(); //txtWrapperNode.AddProperty(TextNodeXmlProp); //TextNodeXmlProp.LocalName = "hd"; return(treeNode); }
protected void AddMetadata_Ncx(XmlDocument ncxDocument, string strTotalPages, string strMaxNormalPage, string strDepth, List <string> ncxCustomTestList) { XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(ncxDocument, true, "head", null); //ncxDocument.GetElementsByTagName("head")[0]; AddMetadata_DtbUid(false, ncxDocument, headNode); AddMetadata_Generator(ncxDocument, headNode); AddMetadataAsAttributes(ncxDocument, headNode, SupportedMetadata_Z39862005.DTB_DEPTH, strDepth); AddMetadataAsAttributes(ncxDocument, headNode, SupportedMetadata_Z39862005.DTB_TOTAL_PAGE_COUNT, strTotalPages); AddMetadataAsAttributes(ncxDocument, headNode, SupportedMetadata_Z39862005.DTB_MAX_PAGE_NUMBER, strMaxNormalPage); // add custom test to headNode if (ncxCustomTestList != null && ncxCustomTestList.Count > 0) { // create dictionary for custom test Dictionary <string, string> bookStrucMap = new Dictionary <string, string>(); bookStrucMap.Add("pagenum", "PAGE_NUMBER"); bookStrucMap.Add("linenum", "LINE_NUMBER"); bookStrucMap.Add("note", "NOTE"); bookStrucMap.Add("noteref", "NOTE_REFERENCE"); bookStrucMap.Add("annoref", "NOTE_REFERENCE"); bookStrucMap.Add("annotation", "ANNOTATION"); bookStrucMap.Add("prodnote", "OPTIONAL_PRODUCER_NOTE"); bookStrucMap.Add("sidebar", "OPTIONAL_SIDEBAR"); bookStrucMap.Add("footnote", "NOTE"); bookStrucMap.Add("endnote", "NOTE"); foreach (string customTestName in ncxCustomTestList) { if (!bookStrucMap.ContainsKey(customTestName)) { continue; } XmlNode customTestNode = ncxDocument.CreateElement(null, "smilCustomTest", headNode.NamespaceURI); headNode.AppendChild(customTestNode); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, customTestNode, "bookStruct", bookStrucMap[customTestName]); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, customTestNode, "defaultState", "false"); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, customTestNode, "id", customTestName); XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, customTestNode, "override", "visible"); } } }
private void CollectPagesFromPageList(XmlNode navMap) { m_PageReferencesMapDictionaryForNCX = new Dictionary <string, XmlNode>(); //XmlNode pageListNode = XmlDocumentHelper.GetFirstChildElementWithName(navMap, true, "pageList", navMap.NamespaceURI); XmlNode pageListNode = navMap.OwnerDocument.GetElementsByTagName("pageList")[0]; if (pageListNode != null) { foreach (XmlNode pageTargetNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(pageListNode, true, "pageTarget", navMap.NamespaceURI, false)) { XmlNode contentNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(pageTargetNode, true, "content", pageTargetNode.NamespaceURI); string urlDecoded = FileDataProvider.UriDecode(contentNode.Attributes.GetNamedItem("src").Value); m_PageReferencesMapDictionaryForNCX.Add(urlDecoded, pageTargetNode); } } }
public static void getTitleFromOpfFile(string opfFilePath, ref string dc_Title, ref string dc_Identifier) { string opfTitle = ""; string identifier = ""; XmlDocument opfFileDoc = urakawa.xuk.XmlReaderWriterHelper.ParseXmlDocument(opfFilePath, false, false); XmlNode packageNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(opfFileDoc.DocumentElement, true, "package", null); string uidAttribute = packageNode.Attributes.GetNamedItem("unique-identifier").Value; XmlNodeList listOfChildrenOfDCMetadata = opfFileDoc.GetElementsByTagName("dc-metadata"); if (listOfChildrenOfDCMetadata == null || listOfChildrenOfDCMetadata.Count == 0) { listOfChildrenOfDCMetadata = opfFileDoc.GetElementsByTagName("metadata"); } foreach (XmlNode xnode in listOfChildrenOfDCMetadata) { foreach (XmlNode node in xnode.ChildNodes) { if (node.Name.ToLower() == "dc:title" && string.IsNullOrEmpty(opfTitle)) { opfTitle = node.InnerText; } if (node.Name.ToLower() == "dc:identifier" && string.IsNullOrEmpty(identifier) && node.Attributes.GetNamedItem("id") != null && node.Attributes.GetNamedItem("id").Value == uidAttribute) { identifier = node.InnerText; } if (!string.IsNullOrEmpty(opfTitle) && !string.IsNullOrEmpty(identifier)) { break; } } } if (!string.IsNullOrEmpty(opfTitle)) { dc_Title = opfTitle; } if (!string.IsNullOrEmpty(identifier)) { dc_Identifier = identifier; } }
private void ImportFromXHTML() { try { XmlDocument nccDocument = XmlReaderWriterHelper.ParseXmlDocument(m_NccPath, false, false); XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(nccDocument.DocumentElement, true, "head", nccDocument.DocumentElement.NamespaceURI); PopulateMetadataFromNcc(headNode); XmlNode bodyNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(nccDocument.DocumentElement, true, "body", nccDocument.DocumentElement.NamespaceURI); ParseNccDocument(bodyNode); if (RequestCancellation) { return; } reportProgress(20, ""); AppendPhrasesFromSmil(); reportProgress(100, ""); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } }
private void ParseNCXNodes(Presentation presentation, XmlNode node, TreeNode tNode) { //if (node.ChildNodes == null || node.ChildNodes.Count == 0) //{ //System.Windows.Forms.MessageBox.Show("returning " + node.LocalName); //return; //} //else //{ //System.Windows.Forms.MessageBox.Show("working " + node.LocalName); TreeNode treeNode = null; if (node.LocalName == "navPoint") { treeNode = CreateTreeNodeForNavPoint(tNode, node); XmlNode contentNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(node, true, "content", node.NamespaceURI); string urlDecoded = FileDataProvider.UriDecode(contentNode.Attributes.GetNamedItem("src").Value); m_SmilRefToNavPointTreeNodeMap.Add(urlDecoded, treeNode); XmlNode navLabelXmlNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(node, true, "navLabel", node.NamespaceURI); if (navLabelXmlNode != null) { m_NavPointNode_NavLabelMap.Add(treeNode, navLabelXmlNode); } } if (node.ChildNodes == null || node.ChildNodes.Count == 0) { return; } foreach (XmlNode n in node.ChildNodes) { ParseNCXNodes(presentation, n, treeNode != null ? treeNode : tNode); } //} }
private void AppendPhrasesFromSmil() { if (m_SectionNodesToSmilReferenceMap.Count == 0) { return; } int progressIncrement = 80 / m_SectionNodesToSmilReferenceMap.Count; int progressCounter = 20; foreach (SectionNode section in m_SectionNodesToSmilReferenceMap.Keys) { if (RequestCancellation) { return; } string smilReferenceString = m_SectionNodesToSmilReferenceMap[section]; if (smilReferenceString == null) { continue; } string[] StringArray = smilReferenceString.Split('#'); string smilFileName = StringArray[0]; string strId = StringArray[1]; string fullSmilFilePath = Path.Combine(Path.GetDirectoryName(m_NccPath), smilFileName); if (!File.Exists(fullSmilFilePath)) { continue; } XmlDocument smilDocument = XmlReaderWriterHelper.ParseXmlDocument(fullSmilFilePath, false, false); Console.WriteLine(section.Label + " : " + smilFileName); XmlNode mainSeqNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(smilDocument.DocumentElement, true, "seq", smilDocument.DocumentElement.NamespaceURI); ParseSmilDocument(section, mainSeqNode, smilFileName, strId); progressCounter += progressIncrement; if (progressCounter < 100) { reportProgress(progressCounter, ""); } } }
private void UpdateRegisteredTypes(XmlDocument destXmlDoc) { XmlNode treeNodeFactory = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(destXmlDoc.DocumentElement, true, "TreeNodeFactory", null); XmlNode refRootNode = null; foreach (XmlNode typeNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(treeNodeFactory, true, "Type", null, false)) { if (typeNode.Attributes.GetNamedItem("XukLocalName").Value == "root") { refRootNode = typeNode; break; } } //create section type XmlNode sectionNode = refRootNode.CloneNode(true); sectionNode.Attributes.GetNamedItem("XukLocalName").Value = "section"; sectionNode.Attributes.GetNamedItem("FullName").Value = "Obi.SectionNode"; refRootNode.ParentNode.AppendChild(sectionNode); //create empty type XmlNode emptyNode = refRootNode.CloneNode(true); emptyNode.Attributes.GetNamedItem("XukLocalName").Value = "empty"; emptyNode.Attributes.GetNamedItem("FullName").Value = "Obi.EmptyNode"; refRootNode.ParentNode.AppendChild(emptyNode); //Create type for phrase XmlNode phraseNode = refRootNode.CloneNode(true); phraseNode.Attributes.GetNamedItem("XukLocalName").Value = "phrase"; XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, phraseNode, "BaseXukLocalName", "empty"); XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, phraseNode, "BaseXukNamespaceUri", "http://www.daisy.org/urakawa/obi"); phraseNode.Attributes.GetNamedItem("FullName").Value = "Obi.PhraseNode"; refRootNode.ParentNode.AppendChild(phraseNode); }
protected override TreeNode AddAnchorNode(TreeNode navPointTreeNode, XmlNode smilNode, string fullSmilPath) { XmlNode seqParent = smilNode != null ? smilNode.ParentNode : null; while (seqParent != null) { if (seqParent.Name == "seq" || seqParent.Attributes.GetNamedItem("customTest") != null) { break; } seqParent = seqParent.ParentNode; } if (seqParent == null || XmlDocumentHelper.GetFirstChildElementOrSelfWithName(smilNode, true, "audio", smilNode.NamespaceURI) == null) { return(null); } EmptyNode anchor = m_Presentation.TreeNodeFactory.Create <EmptyNode>(); ((SectionNode)navPointTreeNode).AppendChild(anchor); if (smilNode != null) { string strReference = smilNode.Attributes.GetNamedItem("href").Value; anchor.SetRole(EmptyNode.Role.Anchor, null); if (!m_AnchorNodeSmilRefMap.ContainsKey(anchor)) { string[] refArray = strReference.Split('#'); if (refArray.Length == 1 || string.IsNullOrEmpty(refArray[0])) { strReference = Path.GetFileName(fullSmilPath) + "#" + refArray[refArray.Length - 1]; } m_AnchorNodeSmilRefMap.Add(anchor, strReference); } } return(anchor); }
protected bool parseContentDocParts(string filePath, Project project, XmlDocument xmlDoc, string displayPath, DocumentMarkupType type) { if (RequestCancellation) { return(true); } reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ParsingMetadata, displayPath)); XmlNode headXmlNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlDoc.DocumentElement, true, "head", null); parseMetadata(filePath, project, xmlDoc, headXmlNode); if (RequestCancellation) { return(true); } parseHeadLinks(filePath, project, xmlDoc); if (RequestCancellation) { return(true); } reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ParsingContent, displayPath)); try { urakawa.core.TreeNode.EnableTextCache = false; parseContentDocument(filePath, project, xmlDoc, null, null, type); } finally { urakawa.core.TreeNode.EnableTextCache = true; } return(false); }
protected override TreeNode GetFirstTreeNodeForXmlDocument(Presentation presentation, XmlNode xmlNode) { int level = -1; XmlNode xNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlNode, true, "section", null); if (xNode != null) { XmlNode headingNode = ParseToFineHtmlHeadingNode(xNode); if (headingNode != null) { string strLevel = headingNode.LocalName.Replace("h", ""); //Console.WriteLine("str level " + strLevel); level = int.Parse(strLevel); } } if (level <= 1) { return(presentation.RootNode); } else { List <SectionNode> sectionsList = new List <SectionNode>(m_XmlIdToSectionNodeMap.Values); for (int i = sectionsList.Count - 1; i >= 0; i--) { if (sectionsList[i].Level < level) { return(sectionsList[i]); } } return(presentation.RootNode); } }
private void diagramXmlParseBody_(XmlNode diagramElementNode, string xmlFilePath, TreeNode treeNode, int objectIndex) { string diagramElementName = diagramElementNode.Name; AlternateContent altContent = treeNode.Presentation.AlternateContentFactory.CreateAlternateContent(); AlternateContentAddCommand cmd_AltContent = treeNode.Presentation.CommandFactory.CreateAlternateContentAddCommand(treeNode, altContent); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent); Metadata diagramElementName_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementName_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementName_Metadata.NameContentAttribute.Name = DiagramContentModelHelper.DiagramElementName; diagramElementName_Metadata.NameContentAttribute.NamespaceUri = null; diagramElementName_Metadata.NameContentAttribute.Value = diagramElementName; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementName_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementName_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElementName_Metadata); if (diagramElementNode.Attributes != null) { for (int i = 0; i < diagramElementNode.Attributes.Count; i++) { XmlAttribute attribute = diagramElementNode.Attributes[i]; if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":")) { // } else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS) { // } else if (attribute.Name == DiagramContentModelHelper.TOBI_Audio) { string fullPath = null; if (FileDataProvider.isHTTPFile(attribute.Value)) { fullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(attribute.Value); } else { fullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), attribute.Value); } if (fullPath != null && File.Exists(fullPath)) { string extension = Path.GetExtension(fullPath); bool isWav = extension.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase); AudioLibPCMFormat wavFormat = null; if (isWav) { Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); try { uint dataLength; wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength); } finally { fileStream.Close(); } } string originalFilePath = null; DebugFix.Assert(treeNode.Presentation.MediaDataManager.EnforceSinglePCMFormat); bool wavNeedsConversion = false; if (wavFormat != null) { wavNeedsConversion = !wavFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data); } if (!isWav || wavNeedsConversion) { originalFilePath = fullPath; var audioFormatConvertorSession = new AudioFormatConvertorSession( //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY, treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath, treeNode.Presentation.MediaDataManager.DefaultPCMFormat, false, m_UrakawaSession.IsAcmCodecsDisabled); //filePath = m_AudioFormatConvertorSession.ConvertAudioFileFormat(filePath); bool cancelled = false; var converter = new AudioClipConverter(audioFormatConvertorSession, fullPath); bool error = ShellView.RunModalCancellableProgressTask(true, "Converting audio...", converter, () => { m_Logger.Log(@"Audio conversion CANCELLED", Category.Debug, Priority.Medium); cancelled = true; }, () => { m_Logger.Log(@"Audio conversion DONE", Category.Debug, Priority.Medium); cancelled = false; }); if (cancelled) { //DebugFix.Assert(!result); break; } fullPath = converter.ConvertedFilePath; if (string.IsNullOrEmpty(fullPath)) { break; } m_Logger.Log(string.Format("Converted audio {0} to {1}", originalFilePath, fullPath), Category.Debug, Priority.Medium); //Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); //try //{ // uint dataLength; // wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength); //} //finally //{ // fileStream.Close(); //} } ManagedAudioMedia manAudioMedia = treeNode.Presentation.MediaFactory.CreateManagedAudioMedia(); AudioMediaData audioMediaData = treeNode.Presentation.MediaDataFactory.CreateAudioMediaData(DataProviderFactory.AUDIO_WAV_EXTENSION); manAudioMedia.AudioMediaData = audioMediaData; FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); dataProv.InitByCopyingExistingFile(fullPath); audioMediaData.AppendPcmData(dataProv); // Stream wavStream = null; // try // { // wavStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); // uint dataLength; // AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength); // if (!treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo)) // { //#if DEBUG // Debugger.Break(); //#endif //DEBUG // wavStream.Close(); // wavStream = null; // var audioFormatConvertorSession = // new AudioFormatConvertorSession( // //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY, // treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath, // treeNode.Presentation.MediaDataManager.DefaultPCMFormat, m_UrakawaSession.IsAcmCodecsDisabled); // string newfullWavPath = audioFormatConvertorSession.ConvertAudioFileFormat(fullPath); // FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); // dataProv.InitByMovingExistingFile(newfullWavPath); // audioMediaData.AppendPcmData(dataProv); // } // else // use original wav file by copying it to data directory // { // FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); // dataProv.InitByCopyingExistingFile(fullPath); // audioMediaData.AppendPcmData(dataProv); // } // } // finally // { // if (wavStream != null) wavStream.Close(); // } AlternateContentSetManagedMediaCommand cmd_AltContent_diagramElement_Audio = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, manAudioMedia); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElement_Audio); //SetDescriptionAudio(altContent, audio, treeNode); } } else { Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementAttribute_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementAttribute_Metadata.NameContentAttribute.Name = attribute.Name; diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI; diagramElementAttribute_Metadata.NameContentAttribute.Value = attribute.Value; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementAttribute_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute( cmd_AltContent_diagramElementAttribute_Metadata); } } } int nObjects = -1; XmlNode textNode = diagramElementNode; if (diagramElementName == DiagramContentModelHelper.D_SimplifiedImage || diagramElementName == DiagramContentModelHelper.D_Tactile) { string localTourName = DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Tour); XmlNode tour = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramElementNode, false, localTourName, DiagramContentModelHelper.NS_URL_DIAGRAM); textNode = tour; IEnumerable <XmlNode> objects = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(diagramElementNode, false, DiagramContentModelHelper. Object, DiagramContentModelHelper. NS_URL_ZAI, false); nObjects = 0; foreach (XmlNode obj in objects) { nObjects++; } int i = -1; foreach (XmlNode obj in objects) { i++; if (i != objectIndex) { continue; } if (obj.Attributes == null || obj.Attributes.Count <= 0) { break; } for (int j = 0; j < obj.Attributes.Count; j++) { XmlAttribute attribute = obj.Attributes[j]; if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":")) { // } else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS) { // } else if (attribute.Name == DiagramContentModelHelper.Src) { // } else if (attribute.Name == DiagramContentModelHelper.SrcType) { // } else { Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementAttribute_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementAttribute_Metadata.NameContentAttribute.Name = attribute.Name; diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI; diagramElementAttribute_Metadata.NameContentAttribute.Value = attribute.Value; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementAttribute_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute( cmd_AltContent_diagramElementAttribute_Metadata); } } XmlAttribute srcAttr = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.Src); if (srcAttr != null) { XmlAttribute srcType = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.SrcType); ManagedImageMedia img = treeNode.Presentation.MediaFactory.CreateManagedImageMedia(); string imgFullPath = null; if (FileDataProvider.isHTTPFile(srcAttr.Value)) { imgFullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(srcAttr.Value); } else { imgFullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), srcAttr.Value); } if (imgFullPath != null && File.Exists(imgFullPath)) { string extension = Path.GetExtension(imgFullPath); ImageMediaData imgData = treeNode.Presentation.MediaDataFactory.CreateImageMediaData(extension); if (imgData != null) { imgData.InitializeImage(imgFullPath, Path.GetFileName(imgFullPath)); img.ImageMediaData = imgData; AlternateContentSetManagedMediaCommand cmd_AltContent_Image = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand( treeNode, altContent, img); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Image); } } } } } if (textNode != null) { string strText = textNode.InnerXml; if (!string.IsNullOrEmpty(strText)) { strText = strText.Trim(); strText = Regex.Replace(strText, @"\s+", " "); strText = strText.Replace("\r\n", "\n"); } if (!string.IsNullOrEmpty(strText)) { TextMedia txtMedia = treeNode.Presentation.MediaFactory.CreateTextMedia(); txtMedia.Text = strText; AlternateContentSetManagedMediaCommand cmd_AltContent_Text = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, txtMedia); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Text); } } if (nObjects > 0 && ++objectIndex <= nObjects - 1) { diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, objectIndex); } }
public void ImportDiagramXML(string xmlFilePath) { Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection(); TreeNode treeNode = selection.Item2 ?? selection.Item1; var altProp = treeNode.GetAlternateContentProperty(); XmlDocument diagramXML = XmlReaderWriterHelper.ParseXmlDocument(xmlFilePath, false, false); XmlNode description = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramXML, false, "description", DiagramContentModelHelper.NS_URL_DIAGRAM); if (description == null) { return; } XmlAttributeCollection descrAttrs = description.Attributes; if (descrAttrs != null) { for (int i = 0; i < descrAttrs.Count; i++) { XmlAttribute attr = descrAttrs[i]; if (!attr.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":")) { continue; } Metadata altContMetadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); altContMetadata.NameContentAttribute = new MetadataAttribute(); altContMetadata.NameContentAttribute.Name = attr.Name; altContMetadata.NameContentAttribute.NamespaceUri = XmlReaderWriterHelper.NS_URL_XML; altContMetadata.NameContentAttribute.Value = attr.Value; AlternateContentMetadataAddCommand cmd_AltPropMetadata_XML = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, altProp, null, altContMetadata, null ); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltPropMetadata_XML); } } XmlNode head = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(description, false, "head", DiagramContentModelHelper.NS_URL_DIAGRAM); if (head != null) { foreach (XmlNode metaNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(head, true, "meta", DiagramContentModelHelper.NS_URL_ZAI, false)) { if (metaNode.NodeType != XmlNodeType.Element || metaNode.LocalName != "meta") { #if DEBUG Debugger.Break(); #endif // DEBUG continue; } //XmlNode childMetadata = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(node, false, "meta", DiagramContentModelHelper.NS_URL_ZAI); //if (childMetadata != null) //{ // continue; //} bool foundAtLeastOneChildMeta = false; foreach (XmlNode child in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(metaNode, false, "meta", DiagramContentModelHelper.NS_URL_ZAI, false)) { if (child == metaNode) { continue; } foundAtLeastOneChildMeta = true; break; } if (foundAtLeastOneChildMeta) { continue; } XmlAttributeCollection mdAttributes = metaNode.Attributes; if (mdAttributes == null || mdAttributes.Count <= 0) { continue; } XmlNode attrName = mdAttributes.GetNamedItem("name"); XmlNode attrProperty = mdAttributes.GetNamedItem("property"); string property = (attrName != null && !String.IsNullOrEmpty(attrName.Value)) ? attrName.Value : (attrProperty != null && !String.IsNullOrEmpty(attrProperty.Value) ? attrProperty.Value : null); XmlNode attrContent = mdAttributes.GetNamedItem("content"); string content = (attrContent != null && !String.IsNullOrEmpty(attrContent.Value)) ? attrContent.Value : metaNode.InnerText; if (!( String.IsNullOrEmpty(property) && String.IsNullOrEmpty(content) || !String.IsNullOrEmpty(property) && !String.IsNullOrEmpty(content) )) { continue; } Metadata altContMetadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); altContMetadata.NameContentAttribute = new MetadataAttribute(); altContMetadata.NameContentAttribute.Name = String.IsNullOrEmpty(property) ? DiagramContentModelHelper.NA : property; altContMetadata.NameContentAttribute.NamespaceUri = String.IsNullOrEmpty(property) ? null : ( property.StartsWith(DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA + ":") ? DiagramContentModelHelper.NS_URL_DIAGRAM : (property.StartsWith(SupportedMetadata_Z39862005.NS_PREFIX_DUBLIN_CORE + ":") ? SupportedMetadata_Z39862005.NS_URL_DUBLIN_CORE : null) ) ; altContMetadata.NameContentAttribute.Value = String.IsNullOrEmpty(content) ? DiagramContentModelHelper.NA : content; AlternateContentMetadataAddCommand cmd_AltPropMetadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, altProp, null, altContMetadata, null ); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltPropMetadata); bool parentIsMeta = metaNode.ParentNode.LocalName == "meta"; var listAttrs = new List <XmlAttribute>(mdAttributes.Count + (parentIsMeta && metaNode.ParentNode.Attributes != null ? metaNode.ParentNode.Attributes.Count : 0) ); for (int i = 0; i < mdAttributes.Count; i++) { XmlAttribute attribute = mdAttributes[i]; listAttrs.Add(attribute); } if (parentIsMeta && metaNode.ParentNode.Attributes != null) { for (int i = 0; i < metaNode.ParentNode.Attributes.Count; i++) { XmlAttribute attribute = metaNode.ParentNode.Attributes[i]; if (mdAttributes.GetNamedItem(attribute.LocalName, attribute.NamespaceURI) == null) { listAttrs.Add(attribute); } } } foreach (var attribute in listAttrs) { if (attribute.LocalName == DiagramContentModelHelper.Name || attribute.LocalName == DiagramContentModelHelper.Property || attribute.LocalName == DiagramContentModelHelper.Content) { continue; } if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":")) { // } else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS) { // } else { MetadataAttribute metadatattribute = new MetadataAttribute(); metadatattribute.Name = attribute.Name; metadatattribute.NamespaceUri = attribute.Name.IndexOf(':') >= 0 //attribute.Name.Contains(":") ? attribute.NamespaceURI : null; metadatattribute.Value = attribute.Value; AlternateContentMetadataAddCommand cmd_AltPropMetadataAttr = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, altProp, null, altContMetadata, metadatattribute ); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltPropMetadataAttr); } } } } XmlNode body = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(description, false, "body", DiagramContentModelHelper.NS_URL_DIAGRAM); if (body != null) { diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.D_Summary); diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.D_LondDesc); diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.D_SimplifiedLanguageDescription); diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.D_Tactile); diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.D_SimplifiedImage); //#if true || SUPPORT_ANNOTATION_ELEMENT // diagramXmlParseBodySpecific(xmlFilePath, treeNode, body, DiagramContentModelHelper.Annotation); //#endif //SUPPORT_ANNOTATION_ELEMENT diagramXmlParseBody(xmlFilePath, treeNode, body); } OnPanelLoaded(); }
protected DocumentMarkupType parseContentDocument_DTD(Project project, XmlDocument xmlDoc, TreeNode parentTreeNode, string filePath, out string dtdUniqueResourceId) { dtdUniqueResourceId = null; DocumentMarkupType docMarkupType = DocumentMarkupType.NA; //xmlNode.OwnerDocument string dtdID = xmlDoc.DocumentType == null ? string.Empty : !string.IsNullOrEmpty(xmlDoc.DocumentType.SystemId) ? xmlDoc.DocumentType.SystemId : !string.IsNullOrEmpty(xmlDoc.DocumentType.PublicId) ? xmlDoc.DocumentType.PublicId : xmlDoc.DocumentType.Name; string rootElemName = xmlDoc.DocumentElement.LocalName; if (dtdID == @"html" && string.IsNullOrEmpty(xmlDoc.DocumentType.SystemId) && string.IsNullOrEmpty(xmlDoc.DocumentType.PublicId)) { dtdID = @"html5"; docMarkupType = DocumentMarkupType.XHTML5; DebugFix.Assert(rootElemName == @"html"); } else if (dtdID.Contains(@"xhtml1") //systemId.Contains(@"xhtml11.dtd") //|| systemId.Contains(@"xhtml1-strict.dtd") //|| systemId.Contains(@"xhtml1-transitional.dtd") ) { dtdID = @"http://www.w3.org/xhtml-math-svg-flat.dtd"; docMarkupType = DocumentMarkupType.XHTML; DebugFix.Assert(rootElemName == @"html"); } else if (rootElemName == @"dtbook") { docMarkupType = DocumentMarkupType.DTBOOK; } else if (rootElemName == @"html") { dtdID = @"html5"; docMarkupType = DocumentMarkupType.XHTML5; } if (docMarkupType == DocumentMarkupType.NA) { #if DEBUG Debugger.Break(); #endif } if (string.IsNullOrEmpty(dtdID)) { return(docMarkupType); } if (!string.IsNullOrEmpty(dtdID) && !dtdID.StartsWith(@"http://")) { dtdID = @"http://www.daisy.org/" + dtdID; } bool needToLoadDTDManuallyToCheckMixedContentElements = docMarkupType == DocumentMarkupType.XHTML5; if (docMarkupType == DocumentMarkupType.DTBOOK) { XmlNode rootElement = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlDoc, true, "book", null); DebugFix.Assert(rootElement != null); if (rootElement != null) { XmlAttributeCollection attrs = rootElement.Attributes; if (attrs != null) { XmlNode attr = attrs.GetNamedItem("space", XmlReaderWriterHelper.NS_URL_XML); if (attr == null) { attr = attrs.GetNamedItem("xml:space", XmlReaderWriterHelper.NS_URL_XML); } if (attr != null && attr.Value == "preserve") { //Bookshare hack! :( needToLoadDTDManuallyToCheckMixedContentElements = true; } } } } if (!needToLoadDTDManuallyToCheckMixedContentElements) { return(docMarkupType); } bool isHTML = docMarkupType == DocumentMarkupType.XHTML || docMarkupType == DocumentMarkupType.XHTML5; #if ENABLE_DTDSHARP Stream dtdStream = LocalXmlUrlResolver.mapUri(new Uri(dtdID, UriKind.Absolute), out dtdUniqueResourceId); if (!string.IsNullOrEmpty(dtdUniqueResourceId)) { DebugFix.Assert(dtdStream != null); List <string> list; m_listOfMixedContentXmlElementNames.TryGetValue(dtdUniqueResourceId, out list); if (list == null) { if (dtdStream != null) { list = new List <string>(); m_listOfMixedContentXmlElementNames.Add(dtdUniqueResourceId, list); initMixedContentXmlElementNamesFromDTD(dtdUniqueResourceId, dtdStream); } else { #if DEBUG Debugger.Break(); #endif } } else { if (dtdStream != null) { dtdStream.Close(); } } } else { #if DEBUG Debugger.Break(); #endif } #else dtdUniqueResourceId = dtdID; List <string> list; m_listOfMixedContentXmlElementNames.TryGetValue(dtdUniqueResourceId, out list); if (list != null) { return(docMarkupType); } list = new List <string>(); m_listOfMixedContentXmlElementNames.Add(dtdUniqueResourceId, list); IXmlReader reader = null; //string dll = @"SaxNET.dll"; ////#if NET40 //// dll = @"\SaxNET_NET4.dll"; ////#endif //string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //string dtdPath = Path.Combine(appFolder, dll); //Assembly assembly = Assembly.LoadFrom(dtdPath); // try // { // reader = SaxReaderFactory.CreateReader(assembly, null); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } bool useCSharpSaxImpl = IsRunning64(); // docMarkupType == DocumentMarkupType.XHTML5; if (useCSharpSaxImpl) { reader = new SaxDriver(); } else { reader = new ExpatReader(); } DebugFix.Assert(reader != null); if (reader == null) { return(docMarkupType); } //Type readerType = reader.GetType(); reader.EntityResolver = new SaxEntityResolver(); SaxErrorHandler errorHandler = new SaxErrorHandler(); reader.ErrorHandler = errorHandler; if (reader is SaxDriver) { //"namespaces" try { reader.SetFeature(Constants.NamespacesFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } //"namespace-prefixes" try { reader.SetFeature(Constants.NamespacePrefixesFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } //"external-general-entities" try { reader.SetFeature(Constants.ExternalGeneralFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } //"external-parameter-entities" try { reader.SetFeature(Constants.ExternalParameterFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } //"xmlns-uris" try { reader.SetFeature(Constants.XmlNsUrisFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } //"resolve-dtd-uris" try { reader.SetFeature(Constants.ResolveDtdUrisFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } } if (reader is ExpatReader) { // http://xml.org/sax/features/namespaces try { reader.SetFeature(Constants.NamespacesFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } // http://xml.org/sax/features/external-general-entities try { reader.SetFeature(Constants.ExternalGeneralFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } // http://xml.org/sax/features/external-parameter-entities try { reader.SetFeature(Constants.ExternalParameterFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } // http://xml.org/sax/features/resolve-dtd-uris try { reader.SetFeature(Constants.ResolveDtdUrisFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } // http://xml.org/sax/features/lexical-handler/parameter-entities try { reader.SetFeature(Constants.LexicalParameterFeature, true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } if (false) { try { reader.SetFeature("http://kd-soft.net/sax/features/skip-internal-entities", false); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } try { reader.SetFeature( "http://kd-soft.net/sax/features/parse-unless-standalone", true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } try { reader.SetFeature("http://kd-soft.net/sax/features/parameter-entities", true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } try { reader.SetFeature("http://kd-soft.net/sax/features/standalone-error", true); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } } // SUPPORTED, but then NOT SUPPORTED (deeper inside Expat C# wrapper code) // // http://xml.org/sax/features/namespace-prefixes // try // { // reader.SetFeature(Constants.NamespacePrefixesFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // // http://xml.org/sax/features/xmlns-uris // try // { // reader.SetFeature(Constants.XmlNsUrisFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // // http://xml.org/sax/features/validation // try // { // reader.SetFeature(Constants.ValidationFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // // http://xml.org/sax/features/unicode-normalization-checking // try // { // reader.SetFeature(Constants.UnicodeNormCheckFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // NOT SUPPORTED: // http://xml.org/sax/features/xml-1.1 // try // { // reader.SetFeature(Constants.Xml11Feature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // http://xml.org/sax/features/xml-declaration // try // { // reader.SetFeature(Constants.XmlDeclFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // http://xml.org/sax/features/use-external-subset // try // { // reader.SetFeature(Constants.UseExternalSubsetFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } // http://xml.org/sax/features/reader-control // try // { // reader.SetFeature(Constants.ReaderControlFeature, true); // } // catch (Exception e) // { //#if DEBUG // Debugger.Break(); //#endif // } } SaxContentHandler handler = new SaxContentHandler(list); try { reader.DtdHandler = handler; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif errorHandler.AddMessage("Cannot set dtd handler: " + e.Message); } try { reader.ContentHandler = handler; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif errorHandler.AddMessage("Cannot set content handler: " + e.Message); } try { reader.LexicalHandler = handler; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif errorHandler.AddMessage("Cannot set lexical handler: " + e.Message); } try { reader.DeclHandler = handler; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif errorHandler.AddMessage("Cannot set declaration handler: " + e.Message); } string rootElementName = isHTML ? @"html" : @"dtbook"; string dtdWrapper = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE " + rootElementName + " SYSTEM \"" + dtdID + "\"><" + rootElementName + "></" + rootElementName + ">"; //StringReader strReader = new StringReader(dtdWrapper); Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(dtdWrapper)); TextReader txtReader = new StreamReader(stream, Encoding.UTF8); InputSource input = new InputSource <TextReader>(txtReader, dtdID + "/////SYSID"); input.Encoding = "UTF-8"; input.PublicId = "??"; reader.Parse(input); #endif //ENABLE_DTDSHARP return(docMarkupType); }
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); } } }
protected override TreeNode CreateTreeNodeForAudioNode(TreeNode navPointTreeNode, bool isHeadingNode, XmlNode smilNode, string fullSmilPath) { PhraseNode audioWrapperNode = m_Presentation.CreatePhraseNode(); if (smilNode == null || !m_SmilXmlNodeToTreeNodeMap.ContainsKey(smilNode)) { ((SectionNode)navPointTreeNode).AppendChild(audioWrapperNode); XmlNode seqParent = smilNode != null ? smilNode.ParentNode : null; while (seqParent != null) { if ((seqParent.Name == "seq" || seqParent.Name == "par") && (seqParent.Attributes != null && seqParent.Attributes.GetNamedItem("customTest") != null)) { break; } seqParent = seqParent.ParentNode; } string strClass = null; if (seqParent != null && seqParent.Attributes.GetNamedItem("class") != null && (strClass = seqParent.Attributes.GetNamedItem("class").Value) != null && (strClass == EmptyNode.Annotation || strClass == EmptyNode.EndNote || strClass == EmptyNode.Footnote || strClass == EmptyNode.ProducerNote || strClass == EmptyNode.Sidebar || strClass == EmptyNode.Note)) { audioWrapperNode.SetRole(EmptyNode.Role.Custom, strClass); if (!m_Skippable_IdMap.ContainsKey(audioWrapperNode)) { ObiNode preceedingNode = audioWrapperNode.PrecedingNode; if (preceedingNode == null || preceedingNode is SectionNode || ((EmptyNode)preceedingNode).CustomRole != audioWrapperNode.CustomRole) { m_Skippable_IdMap.Add(audioWrapperNode, new List <string>()); XmlNode seqChild = seqParent; while (seqChild != null && seqChild != smilNode) { if (seqChild.Attributes.GetNamedItem("id") != null) { m_Skippable_IdMap[audioWrapperNode].Add(Path.GetFileName(fullSmilPath) + "#" + seqChild.Attributes.GetNamedItem("id").Value); } seqChild = seqChild.FirstChild; } AssignSkippableToAnchorNode(); } } } else if (seqParent != null && seqParent.Attributes != null && seqParent.Attributes.GetNamedItem("customTest") != null) { XmlNode anchorNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(seqParent, true, "a", seqParent.NamespaceURI); if (anchorNode != null) { string strReference = anchorNode.Attributes.GetNamedItem("href").Value; audioWrapperNode.SetRole(EmptyNode.Role.Anchor, null); if (!m_AnchorNodeSmilRefMap.ContainsKey(audioWrapperNode)) { string[] refArray = strReference.Split('#'); if (refArray.Length == 1 || string.IsNullOrEmpty(refArray[0])) { strReference = Path.GetFileName(fullSmilPath) + "#" + refArray[refArray.Length - 1]; } m_AnchorNodeSmilRefMap.Add(audioWrapperNode, strReference); } } } } else { ((SectionNode)navPointTreeNode).InsertAfter(audioWrapperNode, m_SmilXmlNodeToTreeNodeMap[smilNode]); m_SmilXmlNodeToTreeNodeMap[smilNode] = audioWrapperNode; } return(audioWrapperNode); }
protected override void parseContentDocument(string filePath, Project project, XmlNode xmlNode, TreeNode parentTreeNode, string dtdUniqueResourceId, DocumentMarkupType docMarkupType) { if (RequestCancellation) { return; } 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: { XmlNode bodyElement = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlNode, true, "body", null); if (bodyElement == null) { bodyElement = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(xmlNode, true, "book", null); } if (bodyElement != null) { Presentation presentation = m_Project.Presentations.Get(0); presentation.PropertyFactory.DefaultXmlNamespaceUri = bodyElement.NamespaceURI; parseContentDocument(filePath, project, bodyElement, parentTreeNode, null, docMarkupType); } //parseContentDocument(((XmlDocument)xmlNode).DocumentElement, parentTreeNode); break; } case XmlNodeType.Element: { Presentation presentation = m_Project.Presentations.Get(0); TreeNode treeNode = null; if (parentTreeNode == null) { parentTreeNode = GetFirstTreeNodeForXmlDocument(presentation, xmlNode); //parentTreeNode = presentation.RootNode; } if (parentTreeNode != null) { treeNode = CreateAndAddTreeNodeForContentDocument(parentTreeNode, xmlNode, Path.GetFileName(filePath)); if (treeNode != null && treeNode is EmptyNode && ((EmptyNode)treeNode).PageNumber != null) { string strfRefID = Path.GetFileName(filePath) + "#" + xmlNode.Attributes.GetNamedItem("id").Value; m_XmlIdToPageNodeMap.Add(strfRefID, (EmptyNode)treeNode); } //parentTreeNode.AppendChild(treeNode); } if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document) { presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI; } XmlProperty xmlProp = null; if (treeNode != null) { xmlProp = presentation.PropertyFactory.CreateXmlProperty(); treeNode.AddProperty(xmlProp); // we get rid of element name prefixes, we use namespace URIs instead. // check inherited NS URI string nsUri = treeNode.Parent != null? treeNode.Parent.GetXmlNamespaceUri() : xmlNode.NamespaceURI; //presentation.PropertyFactory.DefaultXmlNamespaceUri if (xmlNode.NamespaceURI != nsUri) { nsUri = xmlNode.NamespaceURI; xmlProp.SetQName(xmlNode.LocalName, nsUri == null ? "" : nsUri); } else { xmlProp.SetQName(xmlNode.LocalName, ""); } //string nsUri = treeNode.GetXmlNamespaceUri(); // if xmlNode.NamespaceURI != nsUri // => xmlProp.GetNamespaceUri() == xmlNode.NamespaceURI } if (parentTreeNode is SectionNode && (xmlNode.LocalName == "h1" || xmlNode.LocalName == "h2" || xmlNode.LocalName == "h3" || xmlNode.LocalName == "h4" || xmlNode.LocalName == "h5" || xmlNode.LocalName == "h6" || xmlNode.LocalName == "HD")) { ((SectionNode)parentTreeNode).Label = xmlNode.InnerText.Replace("\n", "").Replace("\r", "").Replace("\t", ""); Console.WriteLine("DTBook: " + ((SectionNode)parentTreeNode).Label); if (xmlNode.Attributes.GetNamedItem("id") != null) { string strfRefID = Path.GetFileName(filePath) + "#" + xmlNode.Attributes.GetNamedItem("id").Value; if (!m_XmlIdToSectionNodeMap.ContainsKey(strfRefID)) { m_XmlIdToSectionNodeMap.Add(strfRefID, (SectionNode)parentTreeNode); } } } if (treeNode != null && treeNode is SectionNode && xmlNode.LocalName == "doctitle") { ((SectionNode)treeNode).Label = xmlNode.InnerText.Replace("\n", "").Replace("\r", "").Replace("\t", "");; } if (RequestCancellation) { return; } foreach (XmlNode childXmlNode in xmlNode.ChildNodes) { parseContentDocument(filePath, project, childXmlNode, treeNode != null && treeNode is SectionNode ? treeNode : parentTreeNode, null, docMarkupType); } break; } case XmlNodeType.Whitespace: case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: case XmlNodeType.Text: { /* * Presentation presentation = Project.Presentations.Get(0); * * if (xmlType == XmlNodeType.Whitespace) * { * bool onlySpaces = true; * for (int i = 0; i < xmlNode.Value.Length; i++) * { * if (xmlNode.Value[i] != ' ') * { * onlySpaces = false; * break; * } * } * if (!onlySpaces) * { * break; * } * //else * //{ * // int l = xmlNode.Value.Length; * //} * } #if DEBUG * if (xmlType == XmlNodeType.CDATA) * { * Debugger.Break(); * } * * if (xmlType == XmlNodeType.SignificantWhitespace) * { * Debugger.Break(); * } #endif * //string text = xmlNode.Value.Trim(); * string text = System.Text.RegularExpressions.Regex.Replace(xmlNode.Value, @"\s+", " "); * * Debug.Assert(!string.IsNullOrEmpty(text)); * #if DEBUG * if (text.Length != xmlNode.Value.Length) * { * int debug = 1; * //Debugger.Break(); * } * * if (string.IsNullOrEmpty(text)) * { * Debugger.Break(); * } * if (xmlType != XmlNodeType.Whitespace && text == " ") * { * int debug = 1; * //Debugger.Break(); * } #endif * if (string.IsNullOrEmpty(text)) * { * break; * } * urakawa.media.TextMedia textMedia = presentation.MediaFactory.CreateTextMedia(); * textMedia.Text = text; * * urakawa.property.channel.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 || childXmlType == XmlNodeType.Whitespace || childXmlType == XmlNodeType.SignificantWhitespace || childXmlType == XmlNodeType.CDATA) || { || counter++; || } ||} ||if (counter == 1) ||{ || parentTreeNode.AddProperty(cProp); ||} ||else ||{ || TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create(); || txtWrapperNode.AddProperty(cProp); || parentTreeNode.AppendChild(txtWrapperNode); ||} */ break; } default: { return; } } }
private void parseSmilForNCX(string fullSmilPath) { //foreach (string s in m_SmilRefToNavPointTreeNodeMap.Keys) System.Windows.Forms.MessageBox.Show(s + " : " + m_SmilRefToNavPointTreeNodeMap[s].GetXmlElementLocalName() ); if (RequestCancellation) { return; } XmlDocument smilXmlDoc = XmlReaderWriterHelper.ParseXmlDocument(fullSmilPath, false, false); if (RequestCancellation) { return; } m_SmilXmlNodeToTreeNodeMap = new Dictionary <XmlNode, TreeNode>(); //we skip SMIL metadata parsing (we get publication metadata only from OPF and DTBOOK/XHTMLs) //parseMetadata(smilXmlDoc); //XmlNodeList allTextNodes = smilXmlDoc.GetElementsByTagName("text"); //if (allTextNodes.Count == 0) //{ // return; //} //reportProgress(-1, "Parsing SMIL: [" + Path.GetFileName(fullSmilPath) + "]"); TreeNode navPointTreeNode = null; XmlNamespaceManager firstDocNSManager = new XmlNamespaceManager(smilXmlDoc.NameTable); firstDocNSManager.AddNamespace("firstNS", smilXmlDoc.DocumentElement.NamespaceURI); bool isHeading = false; bool isPageInProcess = false; TreeNode audioWrapperNode = null; XmlNodeList smilNodeList = smilXmlDoc.DocumentElement.SelectNodes(".//firstNS:seq | .//firstNS:par", firstDocNSManager); //foreach (XmlNode parNode in XmlDocumentHelper.GetChildrenElementsWithName(smilXmlDoc, true, "par", null, false)) foreach (XmlNode parNode in smilNodeList) { XmlAttributeCollection parNodeAttrs = parNode.Attributes; if (parNodeAttrs == null || parNodeAttrs.Count == 0) { continue; } //XmlNode textNodeAttrSrc = parNodeAttrs.GetNamedItem("src"); XmlNode parNodeID = parNodeAttrs.GetNamedItem("id"); if (parNodeID == null || String.IsNullOrEmpty(parNodeID.Value)) { continue; } string ncxContentSRC = Path.GetFileName(fullSmilPath) + "#" + parNodeID.Value; TreeNode obj; m_SmilRefToNavPointTreeNodeMap.TryGetValue(ncxContentSRC, out obj); // for now we are assuming the first phrase as heading phrase. this need refinement such that phrase anywhere in section can be imported as heading) if (obj != null) //m_SmilRefToNavPointTreeNodeMap.ContainsKey(ncxContentSRC)) { m_IsDocTitleCreated = true; navPointTreeNode = obj; // m_SmilRefToNavPointTreeNodeMap[ncxContentSRC]; //System.Windows.Forms.MessageBox.Show(ncxContentSRC + " section:" + navPointTreeNode.GetXmlElementLocalName() + " : " + Path.GetFileName( fullSmilPath ) ); //: audioWrapperNode = CreateTreeNodeForAudioNode(navPointTreeNode, true); //isHeading = true; } // handle doctitle if audio exists before first heading by adding doctitle node as first treenode if (navPointTreeNode == null && !m_IsDocTitleCreated && (XmlDocumentHelper.GetFirstChildElementOrSelfWithName(parNode, false, "audio", null) != null || XmlDocumentHelper.GetFirstChildElementOrSelfWithName(parNode, false, "text", null) != null)) { m_IsDocTitleCreated = true; navPointTreeNode = CreateTreeNodeForNavPoint(m_Project.Presentations.Get(0).RootNode, m_DocTitleXmlNode); m_NavPointNode_NavLabelMap.Add(navPointTreeNode, m_DocTitleXmlNode); } //else if (m_PageReferencesMapDictionaryForNCX.ContainsKey(ncxContentSRC) if (m_PageReferencesMapDictionaryForNCX.ContainsKey(ncxContentSRC) || (parNode.Attributes.GetNamedItem("customTest") != null && parNode.Attributes.GetNamedItem("customTest").Value == "pagenum")) { isPageInProcess = true; if (navPointTreeNode == null) { continue; } //:audioWrapperNode = CreateTreeNodeForAudioNode(navPointTreeNode, false); } if (navPointTreeNode == null) { continue; } //System.Windows.Forms.MessageBox.Show(parNode.LocalName); ManagedAudioMedia textTreeNodeAudio = navPointTreeNode.GetManagedAudioMedia(); if (textTreeNodeAudio != null) { //Ignore. continue; } XmlNodeList textPeers = parNode.ChildNodes; foreach (XmlNode textPeerNode in textPeers) //foreach (XmlNode textPeerNode in XmlDocumentHelper.GetChildrenElementsWithName(parNode, true, "audio", null, false)) { if (RequestCancellation) { return; } //if (XmlDocumentHelper.GetFirstChildElementWithName(parNode, false, "audio", null) == null) continue; if (textPeerNode.NodeType != XmlNodeType.Element) { continue; } if (textPeerNode.LocalName == "audio") { audioWrapperNode = CreateTreeNodeForAudioNode(navPointTreeNode, isHeading, textPeerNode, fullSmilPath); CheckAndAssignForHeadingAudio(navPointTreeNode, audioWrapperNode, textPeerNode); XmlProperty xmlProp = navPointTreeNode.Presentation.PropertyFactory.CreateXmlProperty(); audioWrapperNode.AddProperty(xmlProp); // +":" + navPointTreeNode.GetTextFlattened(false); xmlProp.SetQName("phrase", ""); string pageRefInSmil = Path.GetFileName(fullSmilPath) + "#" + parNode.Attributes.GetNamedItem("id").Value; XmlNode xNode; m_PageReferencesMapDictionaryForNCX.TryGetValue(pageRefInSmil, out xNode); if (xNode != null && //m_PageReferencesMapDictionaryForNCX.ContainsKey(pageRefInSmil) isPageInProcess) { isPageInProcess = false; XmlNode pageTargetNode = xNode; //m_PageReferencesMapDictionaryForNCX[pageRefInSmil]; AddPagePropertiesToAudioNode(audioWrapperNode, pageTargetNode); } isHeading = false; addAudio(audioWrapperNode, textPeerNode, false, fullSmilPath); break; } else if (textPeerNode.LocalName == "a") { XmlNodeList aChildren = textPeerNode.ChildNodes; foreach (XmlNode aChild in aChildren) { if (aChild.LocalName == "audio") { //addAudio(audioWrapperNode, aChild, false, fullSmilPath); audioWrapperNode = CreateTreeNodeForAudioNode(navPointTreeNode, false, aChild, fullSmilPath); addAudio(audioWrapperNode, aChild, false, fullSmilPath); break; } else { AddAnchorNode(navPointTreeNode, textPeerNode, fullSmilPath); break; } } } else if (textPeerNode.LocalName == "seq" || textPeerNode.LocalName == "par") { if (audioWrapperNode != null) { m_SmilXmlNodeToTreeNodeMap.Add(textPeerNode, audioWrapperNode); } /* * XmlNodeList seqChildren = textPeerNode.ChildNodes; * foreach (XmlNode seqChild in seqChildren) * //1{ * if (seqChild.LocalName == "audio") * {//2 * addAudio(audioWrapperNode, seqChild, true, fullSmilPath); * }//-2 * }//-1 * * SequenceMedia seqManAudioMedia = audioWrapperNode.GetManagedAudioSequenceMedia(); * if (seqManAudioMedia == null) * {//1 * //Debug.Fail("This should never happen !"); * break; * }//-1 * * ManagedAudioMedia managedAudioMedia = audioWrapperNode.Presentation.MediaFactory.CreateManagedAudioMedia(); * AudioMediaData mediaData = audioWrapperNode.Presentation.MediaDataFactory.CreateAudioMediaData(); * managedAudioMedia.AudioMediaData = mediaData; * * foreach (Media seqChild in seqManAudioMedia.ChildMedias.ContentsAs_YieldEnumerable) * {//1 * ManagedAudioMedia seqManMedia = (ManagedAudioMedia)seqChild; * mediaData.MergeWith(seqManMedia.AudioMediaData); * }//-1 * * ChannelsProperty chProp = audioWrapperNode.GetChannelsProperty(); * chProp.SetMedia(m_audioChannel, null); * chProp.SetMedia(m_audioChannel, managedAudioMedia); */ break; } } } }