Esempio n. 1
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");

            //XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);
            doc.AppendChild(declaration);
            //doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            //XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                //typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                //doc.AppendChild(typeChapter);

                DOMWriterUtility.DOMWrite(doc, chapter);

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */

            /** ******* START WRITING THE METADATA ********* */

            // Pick the main node for the descriptor
            var metadata = adventureData.getImsCPMetadata();

            if (metadata != null)
            {
                var xmlMetadata = SerializeToXmlElement(new XmlDocument(), metadata);
                doc         = new XmlDocument();
                xmlMetadata = MetadataUtility.CleanXMLGarbage(doc, xmlMetadata);
                doc.AppendChild(xmlMetadata);
                doc.Save(folderName + "/imscpmetadata.xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */
            dataSaved = true;
            return(dataSaved);
        }
Esempio n. 2
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            // TODO re-add indentation
            //indentDOM(mainNode, 0);

            // Create the necessary elements for export the DOM into a XML file
            //transformer = tFactory.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "descriptor.dtd");

            // Create the output buffer, write the DOM and close it
            //fout = new FileOutputStream(folderName + "/descriptor.xml");
            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();
            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                doc.AppendChild(typeChapter);
                // Pick the main node of the chapter

                // TODO FIX THIS and use normal domwriter

                var chapterwriter = new ChapterDOMWriter();

                DOMWriterUtility.DOMWrite(doc, chapter);

                // TODO re-add indentation
                //indentDOM(mainNode, 0);

                //TODO: testing
                //doc = new XmlDocument();

                // Create the necessary elements for export the DOM into a XML file
                //transformer = tFactory.newTransformer();
                //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "eadventure.dtd");

                // Create the output buffer, write the DOM and close it
                //fout = new FileOutputStream(folderName + "/chapter" + chapterIndex++ + ".xml");
                //writeFile = new OutputStreamWriter(fout, "UTF-8");
                //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
                //writeFile.close();
                //fout.close();

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */

            // Update the zip files
            //File.umount( );
            dataSaved = true;
            return(dataSaved);
        }