Example #1
0
        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");
                }
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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" />
                }
            }
        }
Example #4
0
        private void ParseAndCreateObiTree(XmlNode oldNode, XmlNode newNode, XmlNode nameSpaceNode, XmlNode urakawaNodeNamespace)
        {
            if (oldNode.ChildNodes.Count > 0)
            {
                foreach (XmlNode oldChild in oldNode.ChildNodes)
                {//1
                    if (RequestCancellation)
                    {
                        return;
                    }
                    if (oldChild.Name == "mChannelMapping" &&
                        oldChild.Attributes.GetNamedItem("channel") != null &&
                        oldChild.Attributes.GetNamedItem("channel").Value == "CHID0002")
                    {
                        continue;
                    }
                    if (oldChild is XmlElement)
                    {//2
                        XmlNode newChild = null;

                        newChild = newNode.OwnerDocument.CreateElement(GetNewElementName(oldChild.Name),
                                                                       oldChild.LocalName == "section" || oldChild.LocalName == "phrase" || oldChild.LocalName == "empty"?  nameSpaceNode.NamespaceURI: urakawaNodeNamespace.NamespaceURI);
                        newNode.AppendChild(newChild);


                        foreach (XmlAttribute attr in oldChild.Attributes)
                        {//3
                            //if (attr.Name == "xmlns" && attr.Value == "http://www.daisy.org/urakawa/xuk/1.0") continue;
                            if (attr.Name == "xmlns")
                            {
                                continue;
                            }
                            //{//4
                            if (oldChild.LocalName == "mChannelMapping" && attr.Name == "channel")
                            {//5
                                XmlDocumentHelper.CreateAppendXmlAttribute(newNode.OwnerDocument, newChild, "Channel", attr.Value == "CHID0000" ? "CH00001" : "CH00000");
                            }//-5
                            else
                            {
                                XmlDocumentHelper.CreateAppendXmlAttribute(newNode.OwnerDocument, newChild, GetNewAttributeName(attr.Name), attr.Value);
                            }
                            //}//-4
                        }//-3

                        ParseAndCreateObiTree(oldChild, newChild, nameSpaceNode, urakawaNodeNamespace);
                    }//-2
                    else if (oldChild is XmlText)
                    {//2
                        XmlText newChild = newNode.OwnerDocument.CreateTextNode(oldChild.InnerText);
                        newNode.AppendChild(newChild);
                    } //-2
                }     //-1
            }
            else
            {
                return;
            }
        }
Example #5
0
        private XmlNode AddMetadataAsAttributes(XmlDocument doc, XmlNode headNode, string name, string content)
        {
            XmlNode metaNode = doc.CreateElement(null, "meta", headNode.NamespaceURI);

            headNode.AppendChild(metaNode);
            XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNode, "name", name);
            XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNode, "content", content);

            return(metaNode);
        }
        protected XmlNode AddFilenameToManifest(XmlDocument opfDocument, XmlNode manifestNode, string filename, string strID, string mediaType)
        {
            XmlNode itemNode = opfDocument.CreateElement(null, "item", manifestNode.NamespaceURI);

            manifestNode.AppendChild(itemNode);
            XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, itemNode, "href", FileDataProvider.UriEncode(filename));
            XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, itemNode, "id", strID);
            XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, itemNode, "media-type", mediaType);

            return(itemNode);
        }
        protected virtual XmlDocument CreateStub_OpfDocument()
        {
            XmlDocument document = new XmlDocument();

            document.XmlResolver = null;

            document.CreateXmlDeclaration("1.0", "utf-8", null);
            document.AppendChild(document.CreateDocumentType("package",
                                                             "+//ISBN 0-9673008-1-9//DTD OEB 1.2 Package//EN",
                                                             "http://openebook.org/dtds/oeb-1.2/oebpkg12.dtd",
                                                             null));

            XmlNode rootNode = document.CreateElement(null,
                                                      "package",
                                                      "http://openebook.org/namespaces/oeb-package/1.0/");

            document.AppendChild(rootNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(document, rootNode, "unique-identifier", "uid");

            XmlNode metadataNode = document.CreateElement(null, "metadata", rootNode.NamespaceURI);

            rootNode.AppendChild(metadataNode);

            XmlNode dcMetadataNode = document.CreateElement(null, "dc-metadata", rootNode.NamespaceURI);

            metadataNode.AppendChild(dcMetadataNode);
            XmlDocumentHelper.CreateAppendXmlAttribute(document, dcMetadataNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC, DiagramContentModelHelper.NS_URL_DC);
            XmlDocumentHelper.CreateAppendXmlAttribute(document, dcMetadataNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":oebpackage", "http://openebook.org/namespaces/oeb-package/1.0/");

            XmlNode xMetadataNode = document.CreateElement(null, "x-metadata", rootNode.NamespaceURI);

            metadataNode.AppendChild(xMetadataNode);

            XmlNode manifestNode = document.CreateElement(null, "manifest", rootNode.NamespaceURI);

            rootNode.AppendChild(manifestNode);

            XmlNode spineNode = document.CreateElement(null, "spine", rootNode.NamespaceURI);

            rootNode.AppendChild(spineNode);


            return(document);
        }
Example #8
0
        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");
                }
            }
        }
Example #9
0
        public XmlDocument CreateNCCStubDocument()
        {
            XmlDocument nccDocument = new XmlDocument();

            nccDocument.XmlResolver = null;

            nccDocument.CreateXmlDeclaration("1.0", "utf-8", null);
            nccDocument.AppendChild(nccDocument.CreateDocumentType("html",
                                                                   "-//W3C//DTD XHTML 1.0 Transitional//EN",
                                                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
                                                                   null));

            XmlNode htmlNode = nccDocument.CreateElement(null,
                                                         "html",
                                                         "http://www.w3.org/1999/xhtml");

            nccDocument.AppendChild(htmlNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, htmlNode, "lang", "en");
            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, htmlNode, "xml:lang", "en");


            XmlNode headNode = nccDocument.CreateElement(null, "head", htmlNode.NamespaceURI);

            htmlNode.AppendChild(headNode);
            XmlNode bodyNode = nccDocument.CreateElement(null, "body", htmlNode.NamespaceURI);

            htmlNode.AppendChild(bodyNode);

            // add css file
            string cssFileName = CreateCSSFile();

            if (cssFileName != null)
            {
                XmlNode linkNode = nccDocument.CreateElement("link", headNode.NamespaceURI);
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "rel", "stylesheet");
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "type", "text/css");
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "href", cssFileName);
                headNode.AppendChild(linkNode);
            }

            return(nccDocument);
        }
Example #10
0
        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);
        }
Example #11
0
        protected XmlDocument CreateStub_NcxDocument()
        {
            XmlDocument NcxDocument = new XmlDocument();

            NcxDocument.XmlResolver = null;

            NcxDocument.CreateXmlDeclaration("1.0", "utf-8", null);
            NcxDocument.AppendChild(NcxDocument.CreateDocumentType("ncx",
                                                                   "-//NISO//DTD ncx 2005-1//EN",
                                                                   "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd",
                                                                   null));

            XmlNode rootNode = NcxDocument.CreateElement(null,
                                                         "ncx",
                                                         "http://www.daisy.org/z3986/2005/ncx/");

            NcxDocument.AppendChild(rootNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(NcxDocument, rootNode, "version", "2005-1");
            XmlDocumentHelper.CreateAppendXmlAttribute(NcxDocument, rootNode,
                                                       XmlReaderWriterHelper.XmlLang,
                                                       (string.IsNullOrEmpty(m_Presentation.Language)
                ? "en-US"
                : m_Presentation.Language));


            XmlNode headNode = NcxDocument.CreateElement(null, "head", rootNode.NamespaceURI);

            rootNode.AppendChild(headNode);

            XmlNode navMapNode = NcxDocument.CreateElement(null, "navMap", rootNode.NamespaceURI);

            rootNode.AppendChild(navMapNode);

            return(NcxDocument);
        }
        protected virtual void AddMetadata_Opf(XmlDocument opfDocument)
        {
            XmlNode dc_metadataNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(opfDocument, true, "dc-metadata", null); //opfDocument.GetElementsByTagName("dc-metadata")[0];
            XmlNode x_metadataNode  = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(opfDocument, true, "x-metadata", null);  //opfDocument.GetElementsByTagName("x-metadata")[0];

            Metadata mdId = AddMetadata_DtbUid(true, opfDocument, dc_metadataNode);

            //AddMetadata_Generator(opfDocument, x_metadataNode);

            bool textOnly = m_TotalTime == null || m_TotalTime.AsLocalUnits == 0;

            if (true || !textOnly)
            {
                AddMetadataAsAttributes(opfDocument, x_metadataNode, SupportedMetadata_Z39862005.DTB_TOTAL_TIME, FormatTimeString(m_TotalTime));
            }

            //type 1 "audioOnly"
            //type 2 "audioNCX"
            //type 3 "audioPartText"
            //type 4 "audioFullText"
            //type 5 "textPartAudio"
            //type 6 "textNCX"
            //http://www.daisy.org/z3986/specifications/daisy_202.html#dtbclass
            if (true || m_Presentation.GetMetadata(SupportedMetadata_Z39862005.DTB_MULTIMEDIA_TYPE).Count == 0)
            {
                AddMetadataAsAttributes(opfDocument, x_metadataNode, SupportedMetadata_Z39862005.DTB_MULTIMEDIA_TYPE, m_Filename_Content != null ?
                                        (textOnly ? "textNCX" : "audioFullText") //"textPartAudio"
                    : "audioNCX");
            }

            //audio,text,image ???
            if (true || m_Presentation.GetMetadata(SupportedMetadata_Z39862005.DTB_MULTIMEDIA_CONTENT).Count == 0)
            {
                AddMetadataAsAttributes(opfDocument, x_metadataNode, SupportedMetadata_Z39862005.DTB_MULTIMEDIA_CONTENT, m_Filename_Content != null ?
                                        (textOnly ? "text" : "audio,text") //"audio,text"
                    : "audio");
            }

            AddMetadataAsInnerText(opfDocument, dc_metadataNode, SupportedMetadata_Z39862005.DC_Format.ToLower(), "ANSI/NISO Z39.86-2005");


            bool hasMathML_z39_86_extension_version = false;
            bool hasMathML_DTBook_XSLTFallback      = false;

            foreach (Metadata m in m_Presentation.Metadatas.ContentsAs_Enumerable)
            {
                string name = m.NameContentAttribute.Name;

                if (name == SupportedMetadata_Z39862005._z39_86_extension_version)
                {
                    hasMathML_z39_86_extension_version = true;
                }
                else if (name == SupportedMetadata_Z39862005.MATHML_XSLT_METADATA)
                {
                    hasMathML_DTBook_XSLTFallback = true;
                }

                //string lowerName = m.NameContentAttribute.Name.ToLower();
                if (mdId == m ||
                    SupportedMetadata_Z39862005.DTB_TOTAL_TIME.Equals(name, StringComparison.OrdinalIgnoreCase) ||
                    SupportedMetadata_Z39862005.DC_Format.Equals(name, StringComparison.OrdinalIgnoreCase) ||
                    SupportedMetadata_Z39862005.DTB_MULTIMEDIA_TYPE.Equals(name, StringComparison.OrdinalIgnoreCase) ||
                    SupportedMetadata_Z39862005.DTB_MULTIMEDIA_CONTENT.Equals(name, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    continue;
                }

                XmlNode metadataNodeCreated = null;
                //if (m.NameContentAttribute.Name.StartsWith(SupportedMetadata_Z39862005.DC + ":"))

                bool contains = false;
                foreach (string str in m_AllowedInDcMetadata)
                {
                    if (str.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        contains = true;
                        break;
                    }
                }

                bool containsDtb = false;
                foreach (string str in m_DtbAllowedInXMetadata)
                {
                    if (str.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        containsDtb = true;
                        break;
                    }
                }

                if (contains)
                {
                    metadataNodeCreated = AddMetadataAsInnerText(opfDocument, dc_metadataNode, name, m.NameContentAttribute.Value);
                    // add other metadata attributes if any
                    foreach (MetadataAttribute ma in m.OtherAttributes.ContentsAs_Enumerable)
                    {
                        if (ma.Name == "id" || ma.Name == Metadata.PrimaryIdentifierMark)
                        {
                            continue;
                        }
                        XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metadataNodeCreated, ma.Name, ma.Value);
                    }
                }
                //else
                //items in x-metadata may start with dtb: ONLY if they are in the list of allowed dtb:* items
                //OR, items in x-metadata may be anything else (non-dtb:*).
                else if (
                    (
                        containsDtb &&
                        m.NameContentAttribute.Name.StartsWith(SupportedMetadata_Z39862005.NS_PREFIX_DTB + ":", StringComparison.OrdinalIgnoreCase)
                    ) ||
                    !m.NameContentAttribute.Name.StartsWith(SupportedMetadata_Z39862005.NS_PREFIX_DTB + ":", StringComparison.OrdinalIgnoreCase)
                    )
                {
                    metadataNodeCreated = AddMetadataAsAttributes(opfDocument, x_metadataNode, name, m.NameContentAttribute.Value);

                    // add other metadata attributes if any
                    foreach (MetadataAttribute ma in m.OtherAttributes.ContentsAs_Enumerable)
                    {
                        if (ma.Name == "id" || ma.Name == Metadata.PrimaryIdentifierMark)
                        {
                            continue;
                        }
                        XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metadataNodeCreated, ma.Name, ma.Value);
                    }
                }
            } // end of metadata for each loop

            string mathML_XSLT = null;

            foreach (ExternalFiles.ExternalFileData efd in m_Presentation.ExternalFilesDataManager.ManagedObjects.ContentsAs_Enumerable)
            {
                if (efd is XSLTExternalFileData)
                {
                    string filename = efd.OriginalRelativePath;
                    if (filename.StartsWith(SupportedMetadata_Z39862005.MATHML_XSLT_METADATA))
                    {
                        filename = filename.Substring(SupportedMetadata_Z39862005.MATHML_XSLT_METADATA.Length);

                        mathML_XSLT = filename;
                        break;
                    }
                }
            }

            string mathPrefix = m_Presentation.RootNode.GetXmlNamespacePrefix(DiagramContentModelHelper.NS_URL_MATHML);

            if (!string.IsNullOrEmpty(mathML_XSLT))
            {
                DebugFix.Assert(hasMathML_z39_86_extension_version);
                DebugFix.Assert(hasMathML_DTBook_XSLTFallback);
            }

            if (!string.IsNullOrEmpty(mathPrefix) && !hasMathML_z39_86_extension_version)
            {
                XmlNode metaNode = opfDocument.CreateElement(null, "meta", x_metadataNode.NamespaceURI);
                x_metadataNode.AppendChild(metaNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "name", SupportedMetadata_Z39862005._z39_86_extension_version);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "content", "1.0");
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "scheme", DiagramContentModelHelper.NS_URL_MATHML);
            }

            if (!string.IsNullOrEmpty(mathPrefix) && !hasMathML_DTBook_XSLTFallback)
            {
                XmlNode metaNode = opfDocument.CreateElement(null, "meta", x_metadataNode.NamespaceURI);
                x_metadataNode.AppendChild(metaNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "name", SupportedMetadata_Z39862005.MATHML_XSLT_METADATA);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "content", string.IsNullOrEmpty(mathML_XSLT) ? SupportedMetadata_Z39862005._builtInMathMLXSLT : mathML_XSLT);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, metaNode, "scheme", DiagramContentModelHelper.NS_URL_MATHML);
            }

            //XmlNodeList totalTimeNodesList = opfDocument.GetElementsByTagName("dtb:totaltime");
            //if (totalTimeNodesList == null || (totalTimeNodesList != null && totalTimeNodesList.Count == 0))
            //{
            //    AddMetadataAsAttributes(opfDocument, x_metadataNode, "dtb:totalTime", m_TotalTime.ToString());
            //}

            // add uid to dc:identifier
            //XmlNodeList identifierList = opfDocument.GetElementsByTagName("dc:Identifier");
            //XmlNode identifierNode = null;
            //bool isUidReAssigned = false;
            //foreach (XmlNode identifierMetaNode in getChildrenElementsWithName(opfDocument, true, "dc:Identifier", null, false))
            //{
            //    if (identifierNode == null) identifierNode = identifierMetaNode;

            //    if (identifierMetaNode.Attributes.GetNamedItem("uid") != null)
            //    {
            //        identifierMetaNode.Attributes.GetNamedItem("uid").Value = "uid";
            //        isUidReAssigned = true;
            //    }
            //}
            //if (!isUidReAssigned)
            //{
            //    CommonFunctions.CreateAppendXmlAttribute(opfDocument, identifierNode, "id", "uid");
            //}
        }
Example #13
0
        private static XmlNode addFlatDiagramHeadMetadata(
            MetadataAttribute metaAttr, IEnumerable <MetadataAttribute> metaAttrs,
            XmlNode parentNode, XmlDocument descriptionDocument, XmlNode descriptionNode)
        {
            XmlNode metaNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.Meta),
                DiagramContentModelHelper.NS_URL_ZAI);

            parentNode.AppendChild(metaNode);

            if (metaAttr != null)
            {
                if (metaAttr.Name != DiagramContentModelHelper.NA)
                {
                    XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                               DiagramContentModelHelper.Property,
                                                               metaAttr.Name,
                                                               DiagramContentModelHelper.NS_URL_ZAI);
                }

                if (metaAttr.Value != DiagramContentModelHelper.NA)
                {
                    // TODO: INNER_TEXT vs CONTENT_ATTR => is this specified anywhere?
                    if (
                        DiagramContentModelHelper.DIAGRAM_Purpose.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        DiagramContentModelHelper.DIAGRAM_Credentials.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_AccessRights.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase)
                        //
                        || SupportedMetadata_Z39862005.DC_Creator.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Description.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Title.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Subject.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase)
                        )
                    {
                        metaNode.InnerText = metaAttr.Value;
                    }
                    else
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   DiagramContentModelHelper.Content,
                                                                   metaAttr.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                }
            }

            if (metaAttrs != null)
            {
                foreach (MetadataAttribute metaAttribute in metaAttrs)
                {
                    if (metaAttribute.Name == Metadata.PrimaryIdentifierMark)
                    {
                        continue;
                    }

                    if (metaAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   XmlReaderWriterHelper.NS_URL_XML);
                    }
                    else if (metaAttribute.Name.StartsWith(DiagramContentModelHelper.NS_PREFIX_ZAI + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                    else if (metaAttribute.Name.StartsWith(DiagramContentModelHelper.NS_PREFIX_DIAGRAM + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_DIAGRAM);
                    }
                    else if (DiagramContentModelHelper.Rel.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase) ||
                             DiagramContentModelHelper.Resource.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase) ||
                             DiagramContentModelHelper.About.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name.ToLower(),
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                    else
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   DiagramContentModelHelper.StripNSPrefix(metaAttribute.Name),
                                                                   metaAttribute.Value,
                                                                   descriptionNode.NamespaceURI);
                    }
                }
            }

            return(metaNode);
        }
        protected virtual void CreateOpfDocument()
        {
            //m_ProgressPercentage = 90;
            //reportProgress(m_ProgressPercentage, UrakawaSDK_daisy_Lang.AllFilesCreated);
            if (RequestCancellation)
            {
                return;
            }
            XmlDocument opfDocument = CreateStub_OpfDocument();

            XmlNode manifestNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(opfDocument, true, "manifest", null); //opfDocument.GetElementsByTagName("manifest")[0];


            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Title);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Creator);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Subject);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Description);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Identifier);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Publisher);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Contributor);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Date);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Type);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Format);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.D_Source);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Language);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Relation);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Coverage);
            m_AllowedInDcMetadata.Add(SupportedMetadata_Z39862005.DC_Rights);

            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_SOURCE_DATE);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_SOURCE_EDITION);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_SOURCE_PUBLISHER);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_SOURCE_RIGHTS);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_SOURCE_TITLE);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_MULTIMEDIA_TYPE);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_MULTIMEDIA_CONTENT);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_NARRATOR);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_PRODUCER);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_PRODUCED_DATE);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_REVISION);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_REVISION_DATE);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_REVISION_DESCRIPTION);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_TOTAL_TIME);
            m_DtbAllowedInXMetadata.Add(SupportedMetadata_Z39862005.DTB_AUDIO_FORMAT);

            AddFilenameToManifest(opfDocument, manifestNode, m_Filename_Ncx, "ncx", DataProviderFactory.NCX_MIME_TYPE);

            if (m_Filename_Content != null)
            {
                AddFilenameToManifest(opfDocument, manifestNode, m_Filename_Content, GetNextID(ID_OpfPrefix), DataProviderFactory.DTBOOK_MIME_TYPE);
            }

            AddFilenameToManifest(opfDocument, manifestNode, m_Filename_Opf, GetNextID(ID_OpfPrefix), DataProviderFactory.XML_MIME_TYPE);

            foreach (string externalFileName in m_FilesList_ExternalFiles)
            {
                // ALREADY escaped!
                //externalFileName = FileDataProvider.EliminateForbiddenFileNameCharacters(externalFileName);

                string strID = GetNextID(ID_OpfPrefix);

                string ext = Path.GetExtension(externalFileName);
                if (DataProviderFactory.CSS_EXTENSION.Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    AddFilenameToManifest(opfDocument, manifestNode, externalFileName, strID, DataProviderFactory.CSS_MIME_TYPE);
                }
                else if (DataProviderFactory.XSLT_EXTENSION.Equals(ext, StringComparison.OrdinalIgnoreCase) ||
                         DataProviderFactory.XSL_EXTENSION.Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    AddFilenameToManifest(opfDocument, manifestNode, externalFileName, strID, DataProviderFactory.XSLT_MIME_TYPE_);
                }
                else if (DataProviderFactory.DTD_EXTENSION.Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    AddFilenameToManifest(opfDocument, manifestNode, externalFileName, strID, DataProviderFactory.DTD_MIME_TYPE);
                }
            }

            if (RequestCancellation)
            {
                return;
            }

            List <string> smilIDListInPlayOrder = new List <string>();

            foreach (string smilFileName in m_FilesList_Smil)
            {
                string strID = GetNextID(ID_OpfPrefix);

                AddFilenameToManifest(opfDocument, manifestNode, smilFileName, strID, DataProviderFactory.SMIL_MIME_TYPE_);
                smilIDListInPlayOrder.Add(strID);
            }

            if (RequestCancellation)
            {
                return;
            }

            foreach (string audioFileName in m_FilesList_SmilAudio)
            {
                string strID = GetNextID(ID_OpfPrefix);

                string ext  = Path.GetExtension(audioFileName);
                string mime = DataProviderFactory.GetMimeTypeFromExtension(ext);
                AddFilenameToManifest(opfDocument, manifestNode, audioFileName, strID, mime);
            }

            if (RequestCancellation)
            {
                return;
            }

            foreach (string imageFileName in m_FilesList_Image)
            {
                string strID = GetNextID(ID_OpfPrefix);

                string ext  = Path.GetExtension(imageFileName);
                string mime = DataProviderFactory.GetMimeTypeFromExtension(ext);
                AddFilenameToManifest(opfDocument, manifestNode, imageFileName, strID, mime);
            }


#if SUPPORT_AUDIO_VIDEO
            if (RequestCancellation)
            {
                return;
            }

            foreach (string videoFileName in m_FilesList_Video)
            {
                string strID = GetNextID(ID_OpfPrefix);

                string ext  = Path.GetExtension(videoFileName);
                string mime = DataProviderFactory.GetMimeTypeFromExtension(ext);
                AddFilenameToManifest(opfDocument, manifestNode, videoFileName, strID, mime);
            }

            foreach (string audioFileName in m_FilesList_Audio)
            {
                string strID = GetNextID(ID_OpfPrefix);

                string ext  = Path.GetExtension(audioFileName);
                string mime = DataProviderFactory.GetMimeTypeFromExtension(ext);
                AddFilenameToManifest(opfDocument, manifestNode, audioFileName, strID, mime);
            }
#endif

            if (RequestCancellation)
            {
                return;
            }

            bool textOnly = m_TotalTime == null || m_TotalTime.AsLocalUnits == 0;
            if (true || !textOnly)
            {
                // copy resource files and place entry in manifest
                string sourceDirectoryPath    = System.AppDomain.CurrentDomain.BaseDirectory;
                string ResourceRes_Filename   = "tpbnarrator.res";
                string resourceAudio_Filename = "tpbnarrator_res.mp3";

                string ResourceRes_Filename_fullPath   = Path.Combine(sourceDirectoryPath, ResourceRes_Filename);
                string resourceAudio_Filename_fullPath = Path.Combine(sourceDirectoryPath, resourceAudio_Filename);
                if (File.Exists(ResourceRes_Filename_fullPath) && File.Exists(resourceAudio_Filename_fullPath))
                {
                    if (RequestCancellation)
                    {
                        return;
                    }

                    string destRes = Path.Combine(m_OutputDirectory, ResourceRes_Filename);

                    if (!textOnly)
                    {
                        File.Copy(ResourceRes_Filename_fullPath, destRes, true);
                        try
                        {
                            File.SetAttributes(destRes, FileAttributes.Normal);
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        string resXml = File.ReadAllText(ResourceRes_Filename_fullPath);

                        int i = -1;
                        int j = 0;
                        while ((i = resXml.IndexOf("<audio", j)) >= 0)
                        {
                            j = resXml.IndexOf("/>", i);
                            if (j > i)
                            {
                                int len = j - i + 2;
                                resXml = resXml.Remove(i, len);

                                string fill = "";
                                for (int k = 1; k <= len; k++)
                                {
                                    fill += ' '; //k.ToString();
                                }

                                resXml = resXml.Insert(i, fill);
                            }
                            else
                            {
#if DEBUG
                                Debugger.Break();
#endif
                                break;
                            }
                        }

                        StreamWriter streamWriter = File.CreateText(destRes);
                        try
                        {
                            streamWriter.Write(resXml);
                        }
                        finally
                        {
                            streamWriter.Close();
                        }
                    }

                    AddFilenameToManifest(opfDocument, manifestNode, ResourceRes_Filename, "resource", DataProviderFactory.DTB_RES_MIME_TYPE);

                    if (!textOnly)
                    {
                        string destFile = Path.Combine(m_OutputDirectory, resourceAudio_Filename);
                        File.Copy(resourceAudio_Filename_fullPath, destFile, true);
                        try
                        {
                            File.SetAttributes(destFile, FileAttributes.Normal);
                        }
                        catch
                        {
                        }

                        AddFilenameToManifest(opfDocument, manifestNode, resourceAudio_Filename, GetNextID(ID_OpfPrefix), DataProviderFactory.AUDIO_MP3_MIME_TYPE);
                    }
                }
            }

            // create spine
            XmlNode spineNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(opfDocument, true, "spine", null); //opfDocument.GetElementsByTagName("spine")[0];

            foreach (string strSmilID in smilIDListInPlayOrder)
            {
                XmlNode itemRefNode = opfDocument.CreateElement(null, "itemref", spineNode.NamespaceURI);
                spineNode.AppendChild(itemRefNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(opfDocument, itemRefNode, "idref", strSmilID);
            }

            if (RequestCancellation)
            {
                return;
            }

            AddMetadata_Opf(opfDocument);

            if (RequestCancellation)
            {
                opfDocument = null;
                return;
            }

            XmlReaderWriterHelper.WriteXmlDocument(opfDocument, OpfFilePath, null);
        }
        public const string DIAGRAM_CSS_CLASS_PREFIX = @"DIAGRAM "; // space character is crucial!

        public static string CreateImageDescriptionHTML(string imageDescriptionDirectoryPath, string imageSRC, AlternateContentProperty altProperty, out bool hasMathML, out bool hasSVG,
                                                        Dictionary <AlternateContent, string> map_AltContentAudio_TO_RelativeExportedFilePath,
                                                        Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions, bool onlyLongDesc)
        {
#if DEBUG
            DebugFix.Assert(!altProperty.IsEmpty);
#endif //DEBUG

            XmlDocument htmlDocument = new XmlDocument();
            htmlDocument.XmlResolver = null;

            htmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);

            //XmlDocumentType doctype = xmlDoc.CreateDocumentType("html", "", "", null);
            //XmlDocumentType doctype = xmlDoc.CreateDocumentType("html", null, null, "");
            XmlDocumentType doctype = htmlDocument.CreateDocumentType("html", null, null, null);
            htmlDocument.AppendChild(doctype);


            XmlNode htmlNode = htmlDocument.CreateElement(null, @"html", DiagramContentModelHelper.NS_URL_XHTML);

            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS,
                                                       DiagramContentModelHelper.NS_URL_XHTML);

            htmlDocument.AppendChild(htmlNode);

            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC,
                                                       DiagramContentModelHelper.NS_URL_DC);

            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DCTERMS,
                                                       DiagramContentModelHelper.NS_URL_DCTERMS);

            //createDiagramHeadMetadata(descriptionDocument, descriptionNode, altProperty);
            XmlNode head = htmlDocument.CreateElement(null, @"head", htmlNode.NamespaceURI);
            htmlNode.AppendChild(head);


            string css =
                "body { margin: 0; padding: 0; background: white; color: black; font-size: 130%; font-family: serif; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX.Substring(0, Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX.Length - 1) + ":before { content: attr(class); font-family: sans-serif; font-weight: bold; display: block; border: 1px dashed black; padding: 0.5em; margin: 0; margin-bottom: 0.5em; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "{ border: 2px solid black; padding: 0.5em; margin: 0; margin-top: 1em; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + ".d\\:tour { border: 2px solid green; padding: 0.5em; margin: 0; margin-top: 1em; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + ".d\\:tour:before { content: \"DIAGRAM d\\:tour\"; font-family: sans-serif; font-weight: bold; display: block; border: 1px dashed green; padding: 0.5em; margin: 0; margin-bottom: 0.5em; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "img { display: block; padding: 0; margin: 0; margin-top: 1em; margin-bottom: 0.5em; } ."
                + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "audio { display: block; padding: 0; margin: 0; margin-top: 1em; margin-bottom: 0.5em; }";

            XmlNode style = htmlDocument.CreateElement(@"style", htmlDocument.DocumentElement.NamespaceURI);
            head.AppendChild(style);
            XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, style, @"type", @"text/css");
            XmlNode cssNode = htmlDocument.CreateTextNode(css);
            style.AppendChild(cssNode);

            createDiagramBodyContentHTML(htmlDocument, htmlNode, altProperty, imageDescriptionDirectoryPath, out hasMathML, out hasSVG, map_AltContentAudio_TO_RelativeExportedFilePath, map_DiagramElementName_TO_TextualDescriptions, onlyLongDesc);

            string descFileName = Path.GetFileNameWithoutExtension(imageSRC) + IMAGE_DESCRIPTION_XML_SUFFIX + DataProviderFactory.XHTML_EXTENSION;
            XmlReaderWriterHelper.WriteXmlDocument(htmlDocument, Path.Combine(imageDescriptionDirectoryPath, descFileName), null);

            string        relativePath = Path.GetFileName(imageDescriptionDirectoryPath);
            DirectoryInfo d            = new DirectoryInfo(imageDescriptionDirectoryPath);
            DebugFix.Assert(relativePath == d.Name);

            return(Path.Combine(relativePath, descFileName));
        }
        public static string CreateImageDescription(
            bool skipACM,
            AudioLibPCMFormat pcmFormat,
            bool encodeToMp3,
            double bitRate_Mp3,
            string imageDescriptionDirectoryPath,
            string imageSRC,
            AlternateContentProperty altProperty,
            Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions,
            Dictionary <AlternateContentProperty, Description> map_AltProperty_TO_Description,
            Dictionary <AlternateContent, string> map_AltContentAudio_TO_RelativeExportedFilePath
            )
        {
#if DEBUG
            DebugFix.Assert(!altProperty.IsEmpty);
#endif //DEBUG

            XmlDocument descriptionDocument = new XmlDocument();

            //m_AltProperrty_DiagramDocument.Add(altProperty, descriptionDocument);

            // <?xml-stylesheet type="text/xsl" href="desc2html.xsl"?>
            //string processingInstructionData = "type=\"text/xsl\" href=\"desc2html.xsl\"";
            //descriptionDocument.AppendChild(descriptionDocument.CreateProcessingInstruction("xml-stylesheet", processingInstructionData));
            //string xsltFileName = "desc2html.xsl";
            //string sourceXsltPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, xsltFileName);
            //string destXsltPath = Path.Combine(imageDescriptionDirectoryPath, xsltFileName);
            //if (!File.Exists(destXsltPath)) File.Copy(sourceXsltPath, destXsltPath);

            XmlNode descriptionNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Description),
                DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS,
                                                       DiagramContentModelHelper.NS_URL_ZAI);
            descriptionDocument.AppendChild(descriptionNode);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC,
                                                       DiagramContentModelHelper.NS_URL_DC);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DCTERMS,
                                                       DiagramContentModelHelper.NS_URL_DCTERMS);

            createDiagramHeadMetadata(descriptionDocument, descriptionNode, altProperty);

            createDiagramBodyContent(skipACM, descriptionDocument, descriptionNode,
                                     altProperty, map_DiagramElementName_TO_TextualDescriptions,
                                     imageDescriptionDirectoryPath,
                                     map_AltProperty_TO_Description, encodeToMp3, bitRate_Mp3, pcmFormat,
                                     map_AltContentAudio_TO_RelativeExportedFilePath);

            string descFileName = Path.GetFileNameWithoutExtension(imageSRC) + IMAGE_DESCRIPTION_XML_SUFFIX + DataProviderFactory.XML_EXTENSION;
            XmlReaderWriterHelper.WriteXmlDocument(descriptionDocument, Path.Combine(imageDescriptionDirectoryPath, descFileName), null);

            string        relativePath = Path.GetFileName(imageDescriptionDirectoryPath);
            DirectoryInfo d            = new DirectoryInfo(imageDescriptionDirectoryPath);
            DebugFix.Assert(relativePath == d.Name);

            return(Path.Combine(relativePath, descFileName));
        }
Example #17
0
        private XmlNode CreateElementsForSection(XmlDocument nccDocument, SectionNode section, int sectionIndex, XmlNode prevPageXmlNode)
        {
            string  nccFileName = "ncc.html";
            XmlNode bodyNode    = nccDocument.GetElementsByTagName("body")[0];
            XmlNode headingNode = nccDocument.CreateElement(null, "h" + section.Level.ToString(), bodyNode.NamespaceURI);

            if (sectionIndex == 0)
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "class", "title");
            }
            else
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "class", "section");
            }
            string headingID = "h" + IncrementID;

            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "id", headingID);
            headingNode.AppendChild(nccDocument.CreateTextNode(section.Label));
            bodyNode.AppendChild(headingNode);


            bool isFirstPhrase = true;
            //EmptyNode adjustedPageNode = m_NextSectionPageAdjustmentDictionary[section];
            bool isPreviousNodeEmptyPage = false;

            if (prevPageXmlNode != null)
            {
                XmlNode parent = prevPageXmlNode.ParentNode;
                parent.RemoveChild(prevPageXmlNode);

                bodyNode.AppendChild(prevPageXmlNode);
                bodyNode.AppendChild(nccDocument.CreateElement(null, "br", bodyNode.NamespaceURI));
                prevPageXmlNode = null;
                //Console.WriteLine("Prev: " + prevPageXmlNode.InnerText);
            }

            for (int i = 0; i < section.PhraseChildCount; i++)
            {    //1
                EmptyNode phrase = section.PhraseChild(i);

                if ((phrase is PhraseNode && phrase.Used) ||
                    (phrase is EmptyNode && phrase.Role_ == EmptyNode.Role.Page && phrase.Used))
                {    //2
                    string  pageID   = null;
                    XmlNode pageNode = null;
                    if (phrase.Role_ == EmptyNode.Role.Page)
                    {    //3
                        string strClassVal = null;
                        // increment page counts and get page kind
                        switch (phrase.PageNumber.Kind)
                        {    //4
                        case PageKind.Front:
                            //m_PageFrontCount++;
                            strClassVal = "page-front";
                            break;

                        case PageKind.Normal:
                            m_PageNormalCount++;
                            //if (phrase.PageNumber.Number > m_MaxPageNormal) m_MaxPageNormal = phrase.PageNumber.Number;
                            strClassVal = "page-normal";
                            break;

                        case PageKind.Special:
                            //m_PageSpecialCount++;
                            strClassVal = "page-special";
                            break;
                        }    //-4

                        XmlNode pageXmlNode = pageNode = nccDocument.CreateElement(null, "span", bodyNode.NamespaceURI);
                        XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, pageNode, "class", strClassVal);
                        pageID = "p" + IncrementID;
                        XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, pageNode, "id", pageID);
                        string pageString = Profile_VA ? "Page " + phrase.PageNumber.ToString() :
                                            phrase.PageNumber.ToString();
                        pageXmlNode.AppendChild(nccDocument.CreateTextNode(pageString));
                        bodyNode.AppendChild(pageNode);
                        prevPageXmlNode = pageNode;
                        bodyNode.AppendChild(nccDocument.CreateElement(null, "br", bodyNode.NamespaceURI));
                    }    //-3

                    // add anchor and href to ncc elements
                    //XmlNode anchorNode = nccDocument.CreateElement ( null, "a", bodyNode.NamespaceURI );

                    //if (isFirstPhrase)
                    //{
                    //headingNode.AppendChild ( anchorNode );
                    //CreateAppendXmlAttribute ( nccDocument, anchorNode, "href", smilFileName + "#" + txtID );
                    //anchorNode.AppendChild (
                    //nccDocument.CreateTextNode ( section.Label ) );
                    //}
                    //else if (pageNode != null)
                    //{

                    //pageNode.AppendChild ( anchorNode );
                    //CreateAppendXmlAttribute ( nccDocument, anchorNode, "href", smilFileName + "#" + txtID );

                    //anchorNode.AppendChild (
                    //nccDocument.CreateTextNode ( phrase.PageNumber.ToString () ) );

                    //}
                    //}


                    isFirstPhrase = false;

                    if (phrase is EmptyNode && phrase.Role_ == EmptyNode.Role.Page)
                    {
                        isPreviousNodeEmptyPage = true;
                    }
                    else
                    {
                        isPreviousNodeEmptyPage = false;
                    }
                } // for loop ends
            }
            // Console.WriteLine("returning : " + prevPageXmlNode.InnerText);
            return(prevPageXmlNode);
        }
Example #18
0
        protected virtual void CreateDTBookDocument()
        {
            // check if there is preserved internal DTD
            //string[] dtbFilesList = Directory.GetFiles(m_Presentation.DataProviderManager.DataFileDirectoryFullPath, daisy.import.Daisy3_Import.INTERNAL_DTD_NAME, SearchOption.AllDirectories);
            //string strInternalDTD = null;
            //if (dtbFilesList.Length > 0)
            //{
            //    strInternalDTD = File.ReadAllText(dtbFilesList[0]);
            //    if (strInternalDTD.Trim() == "") strInternalDTD = null;
            //}



            List <ExternalFileData> list_ExternalStyleSheets = new List <ExternalFileData>();
            string strInternalDTD = null;

            foreach (ExternalFiles.ExternalFileData efd in m_Presentation.ExternalFilesDataManager.ManagedObjects.ContentsAs_Enumerable)
            {
                if (RequestCancellation)
                {
                    return;
                }

                if (efd is ExternalFiles.DTDExternalFileData &&
                    efd.OriginalRelativePath == daisy.import.Daisy3_Import.INTERNAL_DTD_NAME &&
                    !efd.IsPreservedForOutputFile &&
                    string.IsNullOrEmpty(strInternalDTD))
                {
                    StreamReader sr = new StreamReader(efd.OpenInputStream(), Encoding.UTF8);
                    strInternalDTD = sr.ReadToEnd();
                }
                else if (efd is ExternalFiles.CSSExternalFileData ||
                         efd is XSLTExternalFileData
                         //&& !efd.OriginalRelativePath.StartsWith(SupportedMetadata_Z39862005.MATHML_XSLT_METADATA)
                         )
                {
                    list_ExternalStyleSheets.Add(efd);
                }
            }

            if (RequestCancellation)
            {
                return;
            }

            //m_ProgressPercentage = 0;
            reportProgress(-1, UrakawaSDK_daisy_Lang.CreatingXMLFile);
            XmlDocument DTBookDocument = XmlDocumentHelper.CreateStub_DTBDocument(m_Presentation.Language, strInternalDTD, list_ExternalStyleSheets);

            string mathML_XSLT = null;

            foreach (ExternalFileData efd in list_ExternalStyleSheets)
            {
                string filename = efd.OriginalRelativePath;
                if (filename.StartsWith(SupportedMetadata_Z39862005.MATHML_XSLT_METADATA))
                {
                    filename = filename.Substring(SupportedMetadata_Z39862005.MATHML_XSLT_METADATA.Length);

                    mathML_XSLT = filename;
                }

                filename = FileDataProvider.EliminateForbiddenFileNameCharacters(filename);

                if (efd.IsPreservedForOutputFile &&
                    !m_FilesList_ExternalFiles.Contains(filename))
                {
                    string filePath = Path.Combine(m_OutputDirectory, filename);
                    efd.DataProvider.ExportDataStreamToFile(filePath, true);
                    m_FilesList_ExternalFiles.Add(filename);
                }
            }

            string mathPrefix = m_Presentation.RootNode.GetXmlNamespacePrefix(DiagramContentModelHelper.NS_URL_MATHML);


            if (!string.IsNullOrEmpty(mathPrefix) && string.IsNullOrEmpty(mathML_XSLT))
            {
                string appDir       = System.AppDomain.CurrentDomain.BaseDirectory;
                string xsltFileName = FileDataProvider.EliminateForbiddenFileNameCharacters(SupportedMetadata_Z39862005._builtInMathMLXSLT);
                string xsltFullPath = Path.Combine(appDir, xsltFileName);

                if (File.Exists(xsltFullPath))
                {
                    string destFile = Path.Combine(m_OutputDirectory, xsltFileName);
                    File.Copy(xsltFullPath, destFile, true);
                    try
                    {
                        File.SetAttributes(destFile, FileAttributes.Normal);
                    }
                    catch
                    {
                    }
                    m_FilesList_ExternalFiles.Add(xsltFileName);
                }
            }

            m_ListOfLevels = new List <TreeNode>();
            Dictionary <string, string> old_New_IDMap             = new Dictionary <string, string>();
            List <XmlAttribute>         referencingAttributesList = new List <XmlAttribute>();



            // add metadata
            XmlNode headNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(DTBookDocument, true, "head", null); //DTBookDocument.GetElementsByTagName("head")[0]

            Metadata mdId = AddMetadata_DtbUid(false, DTBookDocument, headNode);

            AddMetadata_Generator(DTBookDocument, headNode);

            bool hasMathML_z39_86_extension_version = false;
            bool hasMathML_DTBook_XSLTFallback      = false;

            // todo: filter-out unecessary metadata for DTBOOK (e.g. dtb:multimediatype)
            foreach (Metadata m in m_Presentation.Metadatas.ContentsAs_Enumerable)
            {
                if (mdId == m)
                {
                    continue;
                }

                XmlNode metaNode = DTBookDocument.CreateElement(null, "meta", headNode.NamespaceURI);
                headNode.AppendChild(metaNode);

                string name = m.NameContentAttribute.Name;

                if (name == SupportedMetadata_Z39862005._z39_86_extension_version)
                {
                    hasMathML_z39_86_extension_version = true;
                }
                else if (name == SupportedMetadata_Z39862005.MATHML_XSLT_METADATA)
                {
                    hasMathML_DTBook_XSLTFallback = true;
                }

                string prefix;
                string localName;
                urakawa.property.xml.XmlProperty.SplitLocalName(name, out prefix, out localName);

                if (!string.IsNullOrEmpty(prefix))
                {
                    // split the metadata name and make first alphabet upper, required for daisy 3.0

                    localName = localName.Substring(0, 1).ToUpper() + localName.Remove(0, 1);

                    name = prefix + ":" + localName;
                }

                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "name", name);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "content", m.NameContentAttribute.Value);

                // add metadata optional attributes if any
                foreach (MetadataAttribute ma in m.OtherAttributes.ContentsAs_Enumerable)
                {
                    if (ma.Name == "id" || ma.Name == Metadata.PrimaryIdentifierMark)
                    {
                        continue;
                    }

                    XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, ma.Name, ma.Value);
                }
            }

            if (!string.IsNullOrEmpty(mathML_XSLT))
            {
                DebugFix.Assert(hasMathML_z39_86_extension_version);
                DebugFix.Assert(hasMathML_DTBook_XSLTFallback);
            }

            if (!string.IsNullOrEmpty(mathPrefix) && !hasMathML_z39_86_extension_version)
            {
                XmlNode metaNode = DTBookDocument.CreateElement(null, "meta", headNode.NamespaceURI);
                headNode.AppendChild(metaNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "name", SupportedMetadata_Z39862005._z39_86_extension_version);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "content", "1.0");
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "scheme", DiagramContentModelHelper.NS_URL_MATHML);
            }

            if (!string.IsNullOrEmpty(mathPrefix) && !hasMathML_DTBook_XSLTFallback)
            {
                XmlNode metaNode = DTBookDocument.CreateElement(null, "meta", headNode.NamespaceURI);
                headNode.AppendChild(metaNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "name", SupportedMetadata_Z39862005.MATHML_XSLT_METADATA);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "content", string.IsNullOrEmpty(mathML_XSLT) ? SupportedMetadata_Z39862005._builtInMathMLXSLT : mathML_XSLT);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, metaNode, "scheme", DiagramContentModelHelper.NS_URL_MATHML);
            }

            // add elements to book body
            m_TreeNode_XmlNodeMap = new Dictionary <TreeNode, XmlNode>();



            XmlNode bookNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(DTBookDocument, true, "book", null); //DTBookDocument.GetElementsByTagName("book")[0];

            if (bookNode == null)
            {
                bookNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(DTBookDocument, true, "body", null);
            }


            XmlNode docRootNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(DTBookDocument, true, "dtbook", null);

            if (docRootNode == null)
            {
                docRootNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(DTBookDocument, true, "html", null);
            }

            if (false && !string.IsNullOrEmpty(mathML_XSLT)) // namespace prefix attribute automatically added for each m:math element because of MathML DTD
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(
                    DTBookDocument,
                    bookNode,
                    XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + "dtbook",
                    bookNode.NamespaceURI,
                    XmlReaderWriterHelper.NS_URL_XMLNS
                    );
            }

            m_ListOfLevels.Add(m_Presentation.RootNode);

            m_TreeNode_XmlNodeMap.Add(m_Presentation.RootNode, bookNode);
            XmlNode currentXmlNode         = null;
            bool    isHeadingNodeAvailable = true;

            m_Presentation.RootNode.AcceptDepthFirst(
                delegate(TreeNode n)
            {
                if (RequestCancellation)
                {
                    return(false);
                }
                // add to list of levels if xml property has level string
                //QualifiedName qName = n.GetXmlElementQName();
                //if (qName != null &&
                //    (qName.LocalName.StartsWith("level") || qName.LocalName == "doctitle" || qName.LocalName == "docauthor"))
                //{
                //    m_ListOfLevels.Add(n);
                //}

                if (doesTreeNodeTriggerNewSmil(n))
                {
                    if (!isHeadingNodeAvailable && m_ListOfLevels.Count > 1)
                    {
                        m_ListOfLevels.RemoveAt(m_ListOfLevels.Count - 1);
                        //System.Windows.Forms.MessageBox.Show ( "removing :" + m_ListOfLevels.Count.ToString () );
                    }
                    m_ListOfLevels.Add(n);
                    isHeadingNodeAvailable = false;
                    reportProgress(-1, UrakawaSDK_daisy_Lang.CreatingXMLFile);
                }

                if (IsHeadingNode(n))
                {
                    isHeadingNodeAvailable = true;
                }
                if (n.HasXmlProperty && (n.GetXmlElementLocalName() == "note" || n.GetXmlElementLocalName() == "annotation"))
                {
                    m_NotesNodeList.Add(n);
                }

                property.xml.XmlProperty xmlProp = n.GetXmlProperty();

                if (xmlProp == null)
                {
                    string txtx = n.GetTextMedia() != null ? n.GetTextMedia().Text : null;
                    if (txtx != null)
                    {
                        XmlNode textNode = DTBookDocument.CreateTextNode(txtx);


                        ExternalAudioMedia extAudio = GetExternalAudioMedia(n);

                        if (extAudio == null)
                        {
                            m_TreeNode_XmlNodeMap[n.Parent].AppendChild(textNode);
                            m_TreeNode_XmlNodeMap.Add(n, textNode);
                        }
                        else
                        {
                            Debug.Fail("TreeNode without XmlProperty but with TextMedia cannot have Audio attached to it ! (reason: at authoring time, an XmlProperty should have been added when audio was recorded for the pure-text TreeNode) => " + txtx);

                            //XmlNode textParent = DTBookDocument.CreateElement(null, "sent", bookNode.NamespaceURI);
                            //textParent.AppendChild(textNode);

                            //m_TreeNode_XmlNodeMap[n.Parent].AppendChild(textParent);
                            //m_TreeNode_XmlNodeMap.Add(n, textParent);
                        }
                    }

                    return(true);
                }

                // create sml node in dtbook document

                // code removed because XmlProperty stores proper namespaces, useful for inline MathML, SVG, whatever...
                //string name = xmlProp.LocalName;
                //string prefix = name.Contains(":") ? name.Split(':')[0] : null;
                //string elementName = name.Contains(":") ? name.Split(':')[1] : name;
                //currentXmlNode = DTBookDocument.CreateElement(prefix, elementName, bookNode.NamespaceURI);

                bool notBookRoot = !"book".Equals(xmlProp.LocalName, StringComparison.OrdinalIgnoreCase) &&
                                   !"body".Equals(xmlProp.LocalName, StringComparison.OrdinalIgnoreCase);


                bool forceXmlNamespacePrefix = false;

                if (        //xmlProp.LocalName.Equals("math", StringComparison.OrdinalIgnoreCase)
                    xmlProp.GetNamespaceUri() == DiagramContentModelHelper.NS_URL_MATHML &&
                    bookNode.LocalName.Equals("book", StringComparison.OrdinalIgnoreCase)
                    )
                {
                    // Hack, because some MathML in DAISY is produced
                    // with redundant (and DTD-invalid) xmlns="http://MATHML"
                    forceXmlNamespacePrefix = true;
                }

                if (!notBookRoot)
                {
                    currentXmlNode = bookNode;
                }
                else
                {
                    XmlNode xmlNodeParent = m_TreeNode_XmlNodeMap[n.Parent];

                    string nsUri = n.GetXmlNamespaceUri();

                    if (string.IsNullOrEmpty(nsUri))
                    {
                        nsUri = xmlNodeParent.NamespaceURI;
                    }

                    DebugFix.Assert(!string.IsNullOrEmpty(nsUri));

                    if (string.IsNullOrEmpty(nsUri))
                    {
                        nsUri = bookNode.NamespaceURI;
                    }

                    if (string.IsNullOrEmpty(nsUri))
                    {
                        nsUri = DTBookDocument.DocumentElement.NamespaceURI;
                    }

                    if (string.IsNullOrEmpty(nsUri))
                    {
                        nsUri = DTBookDocument.NamespaceURI;
                    }

                    string prefix = (forceXmlNamespacePrefix || n.NeedsXmlNamespacePrefix()) ? n.GetXmlNamespacePrefix(nsUri) : null;

                    currentXmlNode = DTBookDocument.CreateElement(
                        prefix,
                        xmlProp.LocalName,
                        nsUri);

                    xmlNodeParent.AppendChild(currentXmlNode);

                    m_TreeNode_XmlNodeMap.Add(n, currentXmlNode);
                }

                // add attributes
                for (int i = 0; i < xmlProp.Attributes.Count; i++)
                {
                    property.xml.XmlAttribute xmlAttr = xmlProp.Attributes.Get(i);

                    string prefix            = xmlAttr.Prefix;
                    string nameWithoutPrefix = xmlAttr.PrefixedLocalName != null ? xmlAttr.PrefixedLocalName : xmlAttr.LocalName;

                    if (!string.IsNullOrEmpty(prefix))
                    {
                        string nsUriPrefix = xmlProp.GetNamespaceUri(prefix);

                        if (string.IsNullOrEmpty(nsUriPrefix))
                        {
#if DEBUG
                            Debugger.Break();
#endif //DEBUG
                            nsUriPrefix = currentXmlNode.GetNamespaceOfPrefix(prefix);
                        }

                        if (!string.IsNullOrEmpty(nsUriPrefix) &&
                            string.IsNullOrEmpty(DTBookDocument.DocumentElement.GetNamespaceOfPrefix(prefix)) &&
                            string.IsNullOrEmpty(bookNode.GetNamespaceOfPrefix(prefix)))
                        {
                            XmlDocumentHelper.CreateAppendXmlAttribute(
                                DTBookDocument,
                                docRootNode,         //bookNode,
                                XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + prefix,
                                nsUriPrefix,
                                XmlReaderWriterHelper.NS_URL_XMLNS
                                );
                        }
                    }

                    //todo: check ID attribute, normalize with fresh new list of IDs
                    // (warning: be careful maintaining ID REFS, such as idref attributes for annotation/annoref and prodnote/noteref
                    // (be careful because idref contain URIs with hash character),
                    // and also the special imgref and headers attributes which contain space-separated list of IDs, not URIs)

                    if (nameWithoutPrefix == "id")         //  xmlAttr.LocalName == "id" || xmlAttr.LocalName == XmlReaderWriterHelper.XmlId)
                    {
                        string id_New = GetNextID(ID_DTBPrefix);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument,
                                                                   currentXmlNode,
                                                                   "id", id_New);

                        if (!old_New_IDMap.ContainsKey(xmlAttr.Value))
                        {
                            old_New_IDMap.Add(xmlAttr.Value, id_New);
                        }
                        else
                        {
                            System.Diagnostics.Debug.Fail("Duplicate ID found in original DTBook document", "Original DTBook document has duplicate ID: " + xmlProp.Attributes.Get(i).Value);
                        }
                    }
                    else
                    {
                        XmlNode xmlNd = null;
                        if (currentXmlNode == bookNode
                            &&
                            (prefix == XmlReaderWriterHelper.NS_PREFIX_XMLNS ||
                             nameWithoutPrefix == "lang"))
                        {
                            // Hack: to make sure DTD validation passes.
                            xmlNd = docRootNode;
                        }
                        else
                        {
                            xmlNd = currentXmlNode;
                        }

                        if (forceXmlNamespacePrefix &&
                            nameWithoutPrefix == XmlReaderWriterHelper.NS_PREFIX_XMLNS &&
                            xmlAttr.Value == DiagramContentModelHelper.NS_URL_MATHML
                            )
                        {
                            bool debug = true;         // skip xmlns="http://MATH"
                        }
                        else
                        {
                            XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument,
                                                                       xmlNd,
                                                                       xmlAttr.LocalName,
                                                                       xmlAttr.Value,
                                                                       xmlAttr.GetNamespaceUri());
                        }
                    }
                }         // for loop ends

                if (!notBookRoot)
                {
                    return(true);
                }


                if (xmlProp.LocalName == "imggroup")
                {
                    m_TempImageId = new List <string>(1);
                }
                if (m_TempImageId != null &&      // !string.IsNullOrEmpty(m_TempImageId)
                    (xmlProp.LocalName == "caption" || xmlProp.LocalName == "prodnote"))
                {
                    string imgIds = "";
                    foreach (string imgId in m_TempImageId)
                    {
                        imgIds += imgId + " ";
                    }
                    imgIds = imgIds.Trim();
                    if (!string.IsNullOrEmpty(imgIds))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, currentXmlNode, "imgref", imgIds);
                    }
                }

                XmlAttributeCollection currentXmlNodeAttrs = currentXmlNode.Attributes;

                // add id attribute in case it do not exists and it is required
                if (IsIDRequired(currentXmlNode.LocalName) && currentXmlNodeAttrs != null)
                {
                    XmlNode idAttr = currentXmlNodeAttrs.GetNamedItem("id");
                    if (idAttr == null)
                    {
                        string id = GetNextID(ID_DTBPrefix);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, currentXmlNode, "id", id);
                    }
                    else if (xmlProp.LocalName != null &&
                             xmlProp.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase) &&
                             m_TempImageId != null)
                    {
                        string id = idAttr.Value;
                        m_TempImageId.Add(id);
                    }
                }

                // add text from text property

                string txt = n.GetTextMedia() != null ? n.GetTextMedia().Text : null;
                if (txt != null)
                {
                    XmlNode textNode = DTBookDocument.CreateTextNode(txt);
                    currentXmlNode.AppendChild(textNode);

                    DebugFix.Assert(n.Children.Count == 0);
                }

                // if current xmlnode is referencing node, add its referencing attribute to referencingAttributesList
                AddReferencingNodeToReferencedAttributesList(currentXmlNode, referencingAttributesList);

                if (currentXmlNodeAttrs != null && currentXmlNode.LocalName != null)
                {
                    bool isHTML = @"body".Equals(m_Presentation.RootNode.GetXmlElementLocalName(), StringComparison.OrdinalIgnoreCase);         //n.Presentation
                    // TODO: special treatment of subfolders in file paths (restore full hierarchy, including OPF, XHTMLs, etc., not just referenced media assets)

                    if (currentXmlNode.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase))
                    {
                        XmlAttribute imgSrcAttribute =
                            (XmlAttribute)currentXmlNodeAttrs.GetNamedItem("src");
                        if (imgSrcAttribute != null &&
                            n.GetImageMedia() != null &&
                            n.GetImageMedia() is media.data.image.ManagedImageMedia)
                        {
                            media.data.image.ManagedImageMedia managedImage =
                                (media.data.image.ManagedImageMedia)n.GetImageMedia();

                            //if (FileDataProvider.isHTTPFile(managedImage.ImageMediaData.OriginalRelativePath))
                            //exportImageName = Path.GetFileName(managedImage.ImageMediaData.OriginalRelativePath);

                            string exportImageName =
                                //Path.GetFileName
                                FileDataProvider.EliminateForbiddenFileNameCharacters
                                    (managedImage.ImageMediaData.OriginalRelativePath)
                            ;

                            string destPath = Path.Combine(m_OutputDirectory, exportImageName);

                            if (!File.Exists(destPath))
                            {
                                if (RequestCancellation)
                                {
                                    return(false);
                                }
                                managedImage.ImageMediaData.DataProvider.ExportDataStreamToFile(destPath, false);
                            }

                            imgSrcAttribute.Value = FileDataProvider.UriEncode(exportImageName);

                            if (!m_FilesList_Image.Contains(exportImageName))
                            {
                                m_FilesList_Image.Add(exportImageName);
                            }

                            generateImageDescriptionInDTBook(n, currentXmlNode, exportImageName, DTBookDocument);
                        }
                    }
                    else if (currentXmlNode.LocalName.Equals(DiagramContentModelHelper.Math, StringComparison.OrdinalIgnoreCase))
                    {
                        XmlAttribute imgSrcAttribute =
                            (XmlAttribute)currentXmlNodeAttrs.GetNamedItem("altimg");
                        if (imgSrcAttribute != null &&
                            n.GetImageMedia() != null &&
                            n.GetImageMedia() is media.data.image.ManagedImageMedia)
                        {
                            media.data.image.ManagedImageMedia managedImage =
                                (media.data.image.ManagedImageMedia)n.GetImageMedia();

                            //if (FileDataProvider.isHTTPFile(managedImage.ImageMediaData.OriginalRelativePath))
                            //exportImageName = Path.GetFileName(managedImage.ImageMediaData.OriginalRelativePath);

                            string exportImageName =
                                //Path.GetFileName
                                FileDataProvider.EliminateForbiddenFileNameCharacters
                                    (managedImage.ImageMediaData.OriginalRelativePath)
                            ;

                            string destPath = Path.Combine(m_OutputDirectory, exportImageName);

                            if (!File.Exists(destPath))
                            {
                                if (RequestCancellation)
                                {
                                    return(false);
                                }
                                managedImage.ImageMediaData.DataProvider.ExportDataStreamToFile(destPath, false);
                            }

                            imgSrcAttribute.Value = FileDataProvider.UriEncode(exportImageName);

                            if (!m_FilesList_Image.Contains(exportImageName))
                            {
                                m_FilesList_Image.Add(exportImageName);
                            }
                        }
                    }

#if SUPPORT_AUDIO_VIDEO
                    else if (currentXmlNode.LocalName.Equals("video", StringComparison.OrdinalIgnoreCase) ||
                             (
                                 currentXmlNode.LocalName.Equals("source", StringComparison.OrdinalIgnoreCase) &&
                                 currentXmlNode.ParentNode != null &&
                                 currentXmlNode.ParentNode.LocalName.Equals("video", StringComparison.OrdinalIgnoreCase)
                             )
                             )
                    {
                        XmlAttribute videoSrcAttribute =
                            (XmlAttribute)currentXmlNodeAttrs.GetNamedItem("src");
                        if (videoSrcAttribute != null &&
                            n.GetVideoMedia() != null &&
                            n.GetVideoMedia() is ManagedVideoMedia)
                        {
                            ManagedVideoMedia managedVideo = (ManagedVideoMedia)n.GetVideoMedia();

                            //if (FileDataProvider.isHTTPFile(managedVideo.VideoMediaData.OriginalRelativePath))
                            //exportVideoName = Path.GetFileName(managedVideo.VideoMediaData.OriginalRelativePath);

                            string exportVideoName =
                                FileDataProvider.EliminateForbiddenFileNameCharacters(
                                    managedVideo.VideoMediaData.OriginalRelativePath);

                            string destPath = Path.Combine(m_OutputDirectory, exportVideoName);



                            if (!File.Exists(destPath))
                            {
                                if (RequestCancellation)
                                {
                                    return(false);
                                }
                                managedVideo.VideoMediaData.DataProvider.ExportDataStreamToFile(destPath, false);
                            }

                            videoSrcAttribute.Value = FileDataProvider.UriEncode(exportVideoName);

                            if (!m_FilesList_Video.Contains(exportVideoName))
                            {
                                m_FilesList_Video.Add(exportVideoName);
                            }
                        }
                    }
                    else if (currentXmlNode.LocalName.Equals("audio", StringComparison.OrdinalIgnoreCase) ||
                             (
                                 currentXmlNode.LocalName.Equals("source", StringComparison.OrdinalIgnoreCase) &&
                                 currentXmlNode.ParentNode != null &&
                                 currentXmlNode.ParentNode.LocalName.Equals("audio", StringComparison.OrdinalIgnoreCase)
                             )
                             )
                    {
                        XmlAttribute audioSrcAttribute =
                            (XmlAttribute)currentXmlNodeAttrs.GetNamedItem("src");
                        ManagedAudioMedia managedAudio = n.GetManagedAudioMedia();
                        if (audioSrcAttribute != null &&
                            managedAudio != null)
                        {
                            //if (FileDataProvider.isHTTPFile(managedAudio.AudioMediaData.OriginalRelativePath))
                            //exportAudioName = Path.GetFileName(managedAudio.AudioMediaData.OriginalRelativePath);

                            string exportAudioName =
                                FileDataProvider.EliminateForbiddenFileNameCharacters(
                                    managedAudio.AudioMediaData.OriginalRelativePath);

                            string destPath = Path.Combine(m_OutputDirectory, exportAudioName);



                            if (!File.Exists(destPath))
                            {
                                if (RequestCancellation)
                                {
                                    return(false);
                                }
                                managedAudio.AudioMediaData.DataProvider.ExportDataStreamToFile(destPath, false);
                            }

                            audioSrcAttribute.Value = FileDataProvider.UriEncode(exportAudioName);

                            if (!m_FilesList_Audio.Contains(exportAudioName))
                            {
                                m_FilesList_Audio.Add(exportAudioName);
                            }
                        }
                    }
#endif
                }


                return(true);
            },
                delegate(urakawa.core.TreeNode n)
            {
                property.xml.XmlProperty xmlProp = n.GetXmlProperty();
                //QualifiedName qName = n.GetXmlElementQName();
                if (xmlProp != null && xmlProp.LocalName == "imggroup")
                {
                    m_TempImageId = null;
                }
            });

            if (RequestCancellation)
            {
                return;
            }
            // set references to new ids
            foreach (XmlAttribute attr in referencingAttributesList)
            {
                string strIDToFind = attr.Value;
                if (strIDToFind.IndexOf('#') >= 0) //strIDToFind.Contains("#")
                {
                    strIDToFind = strIDToFind.Split('#')[1];
                }

                string str;
                old_New_IDMap.TryGetValue(strIDToFind, out str);

                if (!string.IsNullOrEmpty(str)) //old_New_IDMap.ContainsKey(strIDToFind))
                {
                    string id_New = str;        // old_New_IDMap[strIDToFind];

                    attr.Value = "#" + id_New;
                }
            }

            m_DTBDocument = DTBookDocument;
            //CommonFunctions.WriteXmlDocumentToFile(DTBookDocument,
            //  Path.Combine(m_OutputDirectory, m_Filename_Content));
        }
Example #19
0
        private static void createDiagramHeadMetadata(XmlDocument descriptionDocument, XmlNode descriptionNode, AlternateContentProperty altProperty)
        {
            XmlNode headNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Head),
                DiagramContentModelHelper.NS_URL_DIAGRAM);

            descriptionNode.AppendChild(headNode);

            //TODO: ALWAYS DISABLE THE DEBUG CODE BELOW UNLESS NEEDED FOR TESTING!!
#if false && DEBUG
            foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable)
            {
                addFlatDiagramHeadMetadata(
                    md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable,
                    headNode, descriptionDocument, descriptionNode);
            }
#endif // DEBUG

            List <Metadata> flatMetadatas = new List <Metadata>();
            Dictionary <string, List <Metadata> > groupedMetadata_Id          = new Dictionary <string, List <Metadata> >();
            Dictionary <string, List <Metadata> > groupedMetadata_RelResource = new Dictionary <string, List <Metadata> >();

            foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable)
            {
                if (md.NameContentAttribute == null)
                {
#if DEBUG
                    Debugger.Break();
#endif // DEBUG
                    continue;
                }

                if (
                    md.NameContentAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":")

                    //&& (md.OtherAttributes == null || md.OtherAttributes.Count == 0)

                    && (descriptionNode.Attributes == null || descriptionNode.Attributes.GetNamedItem(md.NameContentAttribute.Name) == null))
                {
                    XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                               md.NameContentAttribute.Name,
                                                               md.NameContentAttribute.Value,
                                                               XmlReaderWriterHelper.NS_URL_XML);
                }
                else
                {
                    if (md.OtherAttributes != null && md.OtherAttributes.Count > 0)
                    {
                        MetadataAttribute mdAttr_Rel      = null;
                        MetadataAttribute mdAttr_Resource = null;
                        MetadataAttribute mdAttr_Id       = null;
                        bool hasOtherAttrs = false;
                        foreach (MetadataAttribute mdAttr in md.OtherAttributes.ContentsAs_Enumerable)
                        {
                            if (mdAttr.Name == Metadata.PrimaryIdentifierMark)
                            {
                                continue;
                            }

                            if (mdAttr.Name == DiagramContentModelHelper.Rel)
                            {
                                mdAttr_Rel = mdAttr;
                                continue;
                            }
                            if (mdAttr.Name == DiagramContentModelHelper.Resource)
                            {
                                mdAttr_Resource = mdAttr;
                                continue;
                            }
                            if (mdAttr.Name == XmlReaderWriterHelper.XmlId)
                            {
                                mdAttr_Id = mdAttr;
                                continue;
                            }

                            hasOtherAttrs = true;
                        }

                        if (mdAttr_Id != null)
                        {
                            addDic_(groupedMetadata_Id, mdAttr_Id.Value, md);

                            continue;
                        }
                        else if (mdAttr_Rel != null || mdAttr_Resource != null)
                        {
                            string key = (mdAttr_Rel != null ? mdAttr_Rel.Value : "")
                                         + "_-_"
                                         + (mdAttr_Resource != null ? mdAttr_Resource.Value : "");
                            addDic_(groupedMetadata_RelResource, key, md);

                            continue;
                        }
                    }

                    //md.NameContentAttribute.Name != DiagramContentModelHelper.NA
                    //    && md.NameContentAttribute.Value != DiagramContentModelHelper.NA

                    flatMetadatas.Add(md);
                }
            }

            foreach (Metadata md in flatMetadatas)
            {
                addFlatDiagramHeadMetadata(
                    md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable,
                    headNode, descriptionDocument, descriptionNode);
            }

            handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_Id);
            handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_RelResource);
        }
Example #20
0
        public void UpgradeProject()
        {
            string      referencePath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "EmptyProject.obi");
            XmlDocument sourceXmlDoc  = new XmlDocument();

            sourceXmlDoc.Load(m_Source);

            XmlDocument destXmlDoc = new XmlDocument();

            destXmlDoc.Load(referencePath);

            int progressPercentage = 1;

            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }

//start with adding data providers
            XmlNode oldDataProviders = sourceXmlDoc.GetElementsByTagName("mDataProviders")[0];
            XmlNode newDataProviders = destXmlDoc.GetElementsByTagName("DataProviders")[0];

            foreach (XmlNode dataProviderItem in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(oldDataProviders, true, "mDataProviderItem", oldDataProviders.NamespaceURI, false))
            {
                XmlNode newFileDataProvider = destXmlDoc.CreateElement("FileDataProvider", newDataProviders.NamespaceURI);
                newDataProviders.AppendChild(newFileDataProvider);
                XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newFileDataProvider, "Uid", dataProviderItem.Attributes.GetNamedItem("uid").Value);
                XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newFileDataProvider, "MimeType", "audio/x-wav");
                XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newFileDataProvider, "DataFileRelativePath", dataProviderItem.FirstChild.Attributes.GetNamedItem("dataFileRelativePath").Value);
            }
            progressPercentage = 10;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }

            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }

            // update audio format
            XmlNode oldMediaDataManager = sourceXmlDoc.GetElementsByTagName("mMediaDataManager")[0];
            XmlNode oldPCMInfo          = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(oldMediaDataManager, true, "PCMFormatInfo", oldMediaDataManager.NamespaceURI);

            XmlNode newMediaDataManager = destXmlDoc.GetElementsByTagName("MediaDataManager")[0];
            XmlNode newPCMInfo          = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(newMediaDataManager, true, "PCMFormatInfo", newMediaDataManager.NamespaceURI);

            newPCMInfo.Attributes.GetNamedItem("NumberOfChannels").Value = oldPCMInfo.Attributes.GetNamedItem("numberOfChannels").Value;
            newPCMInfo.Attributes.GetNamedItem("SampleRate").Value       = oldPCMInfo.Attributes.GetNamedItem("sampleRate").Value;

            // add AudioMediaDatas Next
            XmlNode oldAudioMediaDatas = sourceXmlDoc.GetElementsByTagName("mMediaData")[0];
            XmlNode newAudioMediaDatas = destXmlDoc.GetElementsByTagName("MediaDatas")[0];

            float audioMediaLoopPercentage = 0;

            foreach (XmlNode oldMediaDataItem in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(oldAudioMediaDatas, true, "mMediaDataItem", oldAudioMediaDatas.NamespaceURI, false))
            {
                audioMediaLoopPercentage += 0.05f;
                if (audioMediaLoopPercentage >= progressPercentage + 1 && progressPercentage <= 50)
                {
                    progressPercentage = (int)audioMediaLoopPercentage;
                    if (ProgressChanged != null)
                    {
                        ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
                    }
                }
                XmlNode newAudioMediaItem = destXmlDoc.CreateElement("WavAudioMediaData", newAudioMediaDatas.NamespaceURI);
                newAudioMediaDatas.AppendChild(newAudioMediaItem);
                XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newAudioMediaItem, "Uid", oldMediaDataItem.Attributes.GetNamedItem("uid").Value);
                //XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newItem, "MimeType", "audio/x-wav");
                //XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newItem, "DataFileRelativePath", item.Attributes.GetNamedItem("dataFileRelativePath").Value);

                XmlNode wavClips = destXmlDoc.CreateElement("WavClips", newAudioMediaItem.NamespaceURI);
                newAudioMediaItem.AppendChild(wavClips);

                foreach (XmlNode wavItem in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(oldMediaDataItem, true, "WavClip", oldAudioMediaDatas.NamespaceURI, false))
                {
                    if (RequestCancellation)
                    {
                        sourceXmlDoc = null;
                        destXmlDoc   = null;
                        return;
                    }
                    XmlNode newWavClip = destXmlDoc.CreateElement("WavClip", newAudioMediaItem.NamespaceURI);
                    wavClips.AppendChild(newWavClip);
                    // add attributes of wavClip
                    foreach (XmlAttribute attr in wavItem.Attributes)
                    {
                        string attrName    = attr.Name;
                        string firstString = attrName.Substring(0, 1);
                        attrName = firstString.ToUpper() + attrName.Substring(1, attrName.Length - 1);
                        attrName.ToUpperInvariant();
                        Console.WriteLine("name " + attr.Value);
                        XmlDocumentHelper.CreateAppendXmlAttribute(destXmlDoc, newWavClip, attrName, attr.Value);
                    }
                }
            }
            progressPercentage = 55;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }

            //change the root uri to null
            XmlNode newPresentations   = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(destXmlDoc.DocumentElement, true, "Presentations", null);
            XmlNode newObiPresentation = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(destXmlDoc.DocumentElement, true, "ObiPresentation", null);

            newObiPresentation.Attributes.GetNamedItem("RootUri").Value = "";

            UpdateRegisteredTypes(destXmlDoc);
            progressPercentage = 60;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }
            ImportMetadatas(sourceXmlDoc, destXmlDoc);

            progressPercentage = 70;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }
            //import the section and phrase tree from the rootnode
            XmlNode oldRootNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(sourceXmlDoc.DocumentElement, true, "mRootNode", null);
            XmlNode oldRootChildrenContainer = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(oldRootNode, true, "mChildren", oldRootNode.NamespaceURI);

            XmlNode newRootNode = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(destXmlDoc.DocumentElement, true, "RootNode", null);
            XmlNode newRootChildrenContainer = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(newRootNode, true, "Children", newRootNode.NamespaceURI);
            XmlNode namespaceNode            = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(newRootNode, true, "root", null);

            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }

            ParseAndCreateObiTree(oldRootChildrenContainer, newRootChildrenContainer, namespaceNode, newRootNode);

            if (RequestCancellation)
            {
                sourceXmlDoc = null;
                destXmlDoc   = null;
                return;
            }
            progressPercentage = 90;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
            WriteXmlDocumentToFile(destXmlDoc, m_Destination);
            sourceXmlDoc = null;
            destXmlDoc   = null;
            RenameProjectFilesAfterOperation();

            progressPercentage = 100;
            if (ProgressChanged != null)
            {
                ProgressChanged(this, new System.ComponentModel.ProgressChangedEventArgs(progressPercentage, ""));
            }
        }
Example #21
0
        protected Metadata AddMetadata_DtbUid(bool asInnerText, XmlDocument doc, XmlNode parentNode)
        {
            Metadata mdUid       = null;
            XmlNode  metaNodeUid = null;

            foreach (Metadata md in m_Presentation.Metadatas.ContentsAs_Enumerable)
            {
                if (!isUniqueIdName(md.NameContentAttribute.Name))
                {
                    continue;
                }

                foreach (MetadataAttribute mda in md.OtherAttributes.ContentsAs_Enumerable)
                {
                    if (mda.Name != "id")
                    {
                        continue;
                    }

                    //AddMetadataAsAttributes(ncxDocument, headNode, "dtb:uid", md.NameContentAttribute.Value);

                    if (asInnerText)
                    {
                        metaNodeUid = AddMetadataAsInnerText(doc, parentNode, SupportedMetadata_Z39862005.NS_PREFIX_DUBLIN_CORE + ":Identifier", md.NameContentAttribute.Value);
                        XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, "id", "uid");
                    }
                    else
                    {
                        metaNodeUid = doc.CreateElement(null, "meta", parentNode.NamespaceURI);
                        parentNode.AppendChild(metaNodeUid);

                        XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, DiagramContentModelHelper.Name, SupportedMetadata_Z39862005.DTB_UID);
                        XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, DiagramContentModelHelper.Content, md.NameContentAttribute.Value);
                    }

                    mdUid = md;
                    break;
                }

                if (mdUid != null)
                {
                    // add metadata optional attributes if any
                    foreach (MetadataAttribute ma in md.OtherAttributes.ContentsAs_Enumerable)
                    {
                        if (ma.Name == "id" || ma.Name == Metadata.PrimaryIdentifierMark)
                        {
                            continue;
                        }

                        XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, ma.Name, ma.Value);
                    }

                    return(mdUid);
                }
            }

            foreach (Metadata md in m_Presentation.Metadatas.ContentsAs_Enumerable)
            {
                if (!isUniqueIdName(md.NameContentAttribute.Name))
                {
                    continue;
                }

                //AddMetadataAsAttributes(ncxDocument, headNode, "dtb:uid", md.NameContentAttribute.Value);
                if (asInnerText)
                {
                    metaNodeUid = AddMetadataAsInnerText(doc, parentNode, SupportedMetadata_Z39862005.NS_PREFIX_DUBLIN_CORE + ":Identifier", md.NameContentAttribute.Value);
                    XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, "id", "uid");
                }
                else
                {
                    metaNodeUid = doc.CreateElement(null, "meta", parentNode.NamespaceURI);
                    parentNode.AppendChild(metaNodeUid);

                    XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, DiagramContentModelHelper.Name, SupportedMetadata_Z39862005.DTB_UID);
                    XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, DiagramContentModelHelper.Content,
                                                               md.NameContentAttribute.Value);
                }

                // add metadata optional attributes if any
                foreach (MetadataAttribute ma in md.OtherAttributes.ContentsAs_Enumerable)
                {
                    if (ma.Name == "id" || ma.Name == Metadata.PrimaryIdentifierMark)
                    {
                        continue;
                    }

                    XmlDocumentHelper.CreateAppendXmlAttribute(doc, metaNodeUid, ma.Name, ma.Value);
                }
                return(md);
            }

            return(null);
        }
Example #22
0
        private XmlNode CreateNavPointWithoutContentNode(XmlDocument ncxDocument, TreeNode urakawaNode, TreeNode currentHeadingTreeNode, TreeNode n, Dictionary <TreeNode, XmlNode> treeNode_NavNodeMap)
        {
            XmlNode navMapNode = ncxDocument.GetElementsByTagName("navMap")[0];

            ExternalAudioMedia externalAudio = GetExternalAudioMedia(n);

            // first create navPoints
            XmlNode navPointNode = ncxDocument.CreateElement(null, "navPoint", navMapNode.NamespaceURI);

            if (currentHeadingTreeNode != null)
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, navPointNode, "class", currentHeadingTreeNode.GetXmlProperty().LocalName);
            }
            XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, navPointNode, "id", GetNextID(ID_NcxPrefix));
            XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, navPointNode, "playOrder", "");

            TreeNode parentNode = GetParentLevelNode(urakawaNode);

            if (parentNode == null)
            {
                navMapNode.AppendChild(navPointNode);
            }
            else
            {
                XmlNode obj;
                treeNode_NavNodeMap.TryGetValue(parentNode, out obj);

                if (obj != null)                   //treeNode_NavNodeMap.ContainsKey(parentNode))
                {
                    obj.AppendChild(navPointNode); //treeNode_NavNodeMap[parentNode]
                }
                else // surch up for node
                {
                    int counter = 0;
                    while (parentNode != null && counter <= 6)
                    {
                        parentNode = GetParentLevelNode(parentNode);

                        if (parentNode != null
                            //&& treeNode_NavNodeMap.ContainsKey(parentNode)
                            )
                        {
                            treeNode_NavNodeMap.TryGetValue(parentNode, out obj);
                            if (obj != null)
                            {
                                obj.AppendChild(navPointNode); //treeNode_NavNodeMap[parentNode]
                                break;
                            }
                        }
                        counter++;
                    }

                    if (parentNode == null || counter > 7)
                    {
                        navMapNode.AppendChild(navPointNode);
                    }
                }
            }


            treeNode_NavNodeMap.Add(urakawaNode, navPointNode);

            // create navLabel
            XmlNode navLabel = ncxDocument.CreateElement(null, "navLabel", navPointNode.NamespaceURI);

            navPointNode.AppendChild(navLabel);

            // create text node
            XmlNode txtNode = ncxDocument.CreateElement(null, "text", navMapNode.NamespaceURI);

            navLabel.AppendChild(txtNode);
            if (currentHeadingTreeNode != null)
            {
                txtNode.AppendChild(
                    ncxDocument.CreateTextNode(prepareNcxLabelText(n)));
            }

            if (externalAudio != null)
            {
                // create audio node
                XmlNode audioNode = ncxDocument.CreateElement(null, "audio", navMapNode.NamespaceURI);
                navLabel.AppendChild(audioNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, audioNode, "clipBegin",
                                                           FormatTimeString(externalAudio.ClipBegin));
                XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, audioNode, "clipEnd",
                                                           FormatTimeString(externalAudio.ClipEnd));

                string extAudioSrc = AdjustAudioFileName(externalAudio, urakawaNode);

                XmlDocumentHelper.CreateAppendXmlAttribute(ncxDocument, audioNode, "src",
                                                           FileDataProvider.UriEncode(Path.GetFileName(extAudioSrc)));
            }
            return(navPointNode);
        }
        private void generateImageDescriptionInDTBook(TreeNode n, XmlNode currentXmlNode, string exportImageName, XmlDocument DTBookDocument)
        {
            AlternateContentProperty altProp = n.GetAlternateContentProperty();

            if (currentXmlNode.LocalName == null ||
                !currentXmlNode.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase) ||
                altProp == null || altProp.IsEmpty)
            {
                return;
            }

            m_Map_AltProperty_TO_Description.Add(altProp, new Description());

            PCMFormatInfo     audioFormat = m_Presentation.MediaDataManager.DefaultPCMFormat;
            AudioLibPCMFormat pcmFormat   = audioFormat.Data;

            pcmFormat.SampleRate       = (ushort)m_sampleRate;
            pcmFormat.NumberOfChannels = (ushort)(m_audioStereo ? 2 : 1);

            Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions = new Dictionary <string, List <string> >();

            string imageDescriptionDirectoryPath = GetAndCreateImageDescriptionDirectoryPath(true, exportImageName, m_OutputDirectory);
            string descriptionFile = CreateImageDescription(m_SkipACM, pcmFormat, m_encodeAudioFiles, m_BitRate_Encoding,
                                                            imageDescriptionDirectoryPath, exportImageName,
                                                            altProp,
                                                            map_DiagramElementName_TO_TextualDescriptions,
                                                            m_Map_AltProperty_TO_Description,
                                                            m_Map_AltContentAudio_TO_RelativeExportedFilePath);

            if (m_includeImageDescriptions && !String.IsNullOrEmpty(descriptionFile))
            {
                //short term way for executing image description code: will be updated in later phase of implementation
                XmlNode prodNoteNode = DTBookDocument.CreateElement("prodnote", currentXmlNode.NamespaceURI);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "render", "optional");
                string id_Prodnote = GetNextID(ID_DTBPrefix);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "id", id_Prodnote);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "imgref", currentXmlNode.Attributes.GetNamedItem("id").Value);
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "class", DiagramContentModelHelper.EPUB_DescribedAt);

                currentXmlNode.ParentNode.AppendChild(prodNoteNode);
                if (!m_Image_ProdNoteMap.ContainsKey(n))
                {
                    m_Image_ProdNoteMap.Add(n, new List <XmlNode>());
                }
                m_Image_ProdNoteMap[n].Add(prodNoteNode);
                XmlNode anchorNode = DTBookDocument.CreateElement("a", currentXmlNode.NamespaceURI);

                XmlNode pAnchor = DTBookDocument.CreateElement(
                    DiagramContentModelHelper.P, currentXmlNode.NamespaceURI
                    );
                pAnchor.AppendChild(anchorNode);
                prodNoteNode.AppendChild(pAnchor);
                string descriptionFileUrl = descriptionFile.Replace('\\', '/');

                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, anchorNode, "href", FileDataProvider.UriEncode(descriptionFileUrl));
                XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, anchorNode, "external", "true");
                anchorNode.AppendChild(DTBookDocument.CreateTextNode("Image description (DIAGRAM XML)"));

                if (map_DiagramElementName_TO_TextualDescriptions.Count > 0)
                {
                    foreach (string diagramDescriptionElementName in map_DiagramElementName_TO_TextualDescriptions.Keys)
                    {
                        //System.Windows.Forms.MessageBox.Show(s + " : " + imageDescriptions[s]);

                        XmlNode prodNoteDesc = DTBookDocument.CreateElement("prodnote", currentXmlNode.NamespaceURI);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "render", "optional");
                        string id_ProdnoteDesc = GetNextID(ID_DTBPrefix);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "id", id_ProdnoteDesc);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "imgref", currentXmlNode.Attributes.GetNamedItem("id").Value);
                        XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "class", diagramDescriptionElementName);
                        currentXmlNode.ParentNode.AppendChild(prodNoteDesc);
                        m_Image_ProdNoteMap[n].Add(prodNoteDesc);

                        foreach (string txt in map_DiagramElementName_TO_TextualDescriptions[diagramDescriptionElementName])
                        {
                            string descText = txt;

                            bool xmlParseFail = descText.StartsWith(DIAGRAM_XML_PARSE_FAIL);

                            bool descriptionTextContainsMarkup = !xmlParseFail && descText.IndexOf('<') >= 0; // descText.Contains("<");
                            if (descriptionTextContainsMarkup)
                            {
                                try
                                {
                                    prodNoteDesc.InnerXml = descText;
                                }
                                catch (Exception ex)
                                {
#if DEBUG
                                    Debugger.Break();
#endif
                                    Console.WriteLine(@"Cannot set DIAGRAM XML: " + descText);

                                    XmlNode wrapperNode = DTBookDocument.CreateElement(DiagramContentModelHelper.CODE,
                                                                                       currentXmlNode.NamespaceURI);
                                    prodNoteDesc.AppendChild(wrapperNode);
                                    wrapperNode.AppendChild(DTBookDocument.CreateTextNode(descText));
                                }
                            }
                            else if (xmlParseFail)
                            {
                                //descText = descText.Replace(DIAGRAM_XML_PARSE_FAIL, "");
                                descText = descText.Substring(DIAGRAM_XML_PARSE_FAIL.Length);

                                XmlNode wrapperNode = DTBookDocument.CreateElement(DiagramContentModelHelper.CODE, currentXmlNode.NamespaceURI);
                                prodNoteDesc.AppendChild(wrapperNode);
                                wrapperNode.AppendChild(DTBookDocument.CreateTextNode(descText));
                            }
                            else
                            {
                                string normalizedText = descText.Replace("\r\n", "\n");

                                string[] parasText = normalizedText.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                //string[] parasText = System.Text.RegularExpressions.Regex.Split(normalizedText, "\n");

                                for (int i = 0; i < parasText.Length; i++)
                                {
                                    string paraText = parasText[i].Trim();
                                    if (string.IsNullOrEmpty(paraText))
                                    {
                                        continue;
                                    }

                                    XmlNode paragraph = DTBookDocument.CreateElement(
                                        //DiagramContentModelHelper.NS_PREFIX_ZAI,
                                        DiagramContentModelHelper.P
                                        , currentXmlNode.NamespaceURI
                                        //, DiagramContentModelHelper.NS_URL_ZAI
                                        );

                                    paragraph.InnerText = paraText;

                                    prodNoteDesc.AppendChild(paragraph);
                                }
                            }
                        }
                    }
                }

                /*
                 * if ( EXPORT_IMAGE_DESCRIPTION_IN_DTBOOK )
                 * {//1
                 * // to do copy the diagram nodes that descend directly from body
                 *  if (m_AltProperrty_DiagramDocument.ContainsKey(n.GetAlternateContentProperty()))
                 *  {//2
                 *
                 *      XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, DTBookDocument.GetElementsByTagName("dtbook")[0],
                 * XmlReaderWriterHelper.NS_PREFIX_XMLNS+":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                 * DiagramContentModelHelper.NS_URL_DIAGRAM);
                 *      XmlDocument descriptionDocument = m_AltProperrty_DiagramDocument[n.GetAlternateContentProperty()];
                 *      XmlNodeList diagramNodesList = descriptionDocument.GetElementsByTagName("d:body")[0].ChildNodes;
                 *      foreach (XmlNode xn in diagramNodesList)
                 *      {//3
                 *          XmlNode newNode = DTBookDocument.ImportNode(xn, true);
                 *          prodNoteNode.AppendChild(newNode);
                 *          for (int i = 0; i < newNode.Attributes.Count; i++)
                 *          {//4
                 *              XmlAttribute attr = newNode.Attributes[i];
                 *              if (attr.Name == DiagramContentModelHelper.NS_PREFIX_XML + ":id")
                 *              {//-4
                 *                  XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, newNode, "id", attr.Value);
                 *                  newNode.Attributes.Remove(attr);
                 *              }//-3
                 *          }//-2
                 *
                 *      }//-1
                 *
                 *  }
                 *
                 * //XmlNode newNode = DTBookDocument.ImportNode(M_DescriptionDocument.GetElementsByTagName("d:description")[0], true);
                 *  //prodNoteNode.AppendChild(newNode);
                 * }
                 */
            }
            //}
            //catch (System.Exception ex)
            //{
            //System.Windows.Forms.MessageBox.Show(ex.ToString());
            //}
            //}

            //}
        }
        public void CreateSmilNodesForImageDescription(TreeNode levelNodeDescendant, XmlDocument smilDocument, XmlNode smilBodySeq, Time durationOfCurrentSmil, AlternateContentProperty altProperty, string smilFileName)
        {
            //try
            //{
            int counter = 0;

            foreach (string diagramDescriptionElementName in m_Map_AltProperty_TO_Description[altProperty].Map_DiagramElementName_TO_AltContent.Keys)
            {
                AlternateContent altContent = m_Map_AltProperty_TO_Description[altProperty].Map_DiagramElementName_TO_AltContent[diagramDescriptionElementName];
                if (altContent.Text == null)
                {
                    continue;
                }
                counter++;
                if (m_Image_ProdNoteMap[levelNodeDescendant].Count <= counter)
                {
                    break;
                }
                XmlNode seqNode = smilDocument.CreateElement("seq", smilBodySeq.NamespaceURI);
                smilBodySeq.AppendChild(seqNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "class", "prodnote");
                string strSeqID = GetNextID(ID_SmilPrefix);
                //System.Windows.Forms.MessageBox.Show(counter.ToString ()  + " : " + m_Image_ProdNoteMap[n].Count.ToString());
                string dtbookID = m_Image_ProdNoteMap[levelNodeDescendant][counter].Attributes.GetNamedItem("id").Value;
                string par_id   = GetNextID(ID_SmilPrefix);
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "id", strSeqID);
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "class", "prodnote");
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "customTest", "prodnote");
                XmlDocumentHelper.CreateAppendXmlAttribute(m_DTBDocument, m_Image_ProdNoteMap[levelNodeDescendant][counter], "smilref",
                                                           FileDataProvider.UriEncode(smilFileName + "#" + strSeqID));

                XmlNode parNode = smilDocument.CreateElement(null, "par", smilBodySeq.NamespaceURI);
                seqNode.AppendChild(parNode);
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, parNode, "id", par_id);
                XmlNode SmilTextNode = smilDocument.CreateElement(null, "text", smilBodySeq.NamespaceURI);
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, SmilTextNode, "id", GetNextID(ID_SmilPrefix));
                XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, SmilTextNode, "src",
                                                           FileDataProvider.UriEncode(m_Filename_Content + "#" + dtbookID));
                parNode.AppendChild(SmilTextNode);


                if (altContent.Audio != null)
                {
                    media.data.audio.ManagedAudioMedia managedAudio = altContent.Audio;
                    string srcPath = m_Map_AltContentAudio_TO_RelativeExportedFilePath[altContent];

                    DebugFix.Assert(!string.IsNullOrEmpty(srcPath));

                    XmlNode audioNode = smilDocument.CreateElement(null, "audio", smilBodySeq.NamespaceURI);
                    XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "clipBegin",
                                                               "00:00:00");
                    XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "clipEnd",
                                                               FormatTimeString(managedAudio.Duration));
                    XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "src",
                                                               FileDataProvider.UriEncode(srcPath));
                    parNode.AppendChild(audioNode);

                    if (!m_FilesList_SmilAudio.Contains(srcPath))
                    {
                        m_FilesList_SmilAudio.Add(srcPath);
                    }

                    // add to duration
                    durationOfCurrentSmil.Add(managedAudio.Duration);
                }
            }
            //}
            //catch (System.Exception ex)
            //{
            //    System.Windows.Forms.MessageBox.Show(ex.ToString());
            //}
        }