示例#1
0
        /// <summary>
        /// convenience method which initiates parsing of an XML source from string.
        /// </summary>
        /// <param name="handler">
        /// XMLHandler based object which will process the XML elements.
        /// </param>
        /// <param name="source">
        /// The XML source passed as a String
        /// </param>
        /// <param name="schemaName">
        /// String object holding the name of the XML schema file to use for validating the XML.
        /// Note that whether this is used or not is dependant upon the XMLParser in use.
        /// </param>
        public virtual void ParseXmlString(XmlHandler handler, string source, string schemaName)
        {
            // Put the source string into a RawDataContainer
            using (var rawXMLData = new RawDataContainer())
            {
                rawXMLData.SetData(new MemoryStream(global::System.Text.Encoding.ASCII.GetBytes(source)));

                try
                {
                    // The actual parsing action (this is overridden and depends on the specific parser)
                    ParseXml(handler, rawXMLData, schemaName);
                }
                catch
                {
                    //// make sure we don't allow rawXMLData to release String owned data no matter what!
                    //rawXMLData.SetData((byte[]) null);
                    //rawXMLData.SetSize(0);
                    //throw;
                }

                //// !!! We must not allow DataContainer to delete String owned data,
                ////     therefore, we set it's data to 0 to avoid double-deletion
                //rawXMLData.SetData((byte[]) null);
                //rawXMLData.SetSize(0);
            }
        }
示例#2
0
        /// <summary>
        /// convenience method which initiates parsing of an XML file.
        /// </summary>
        /// <param name="handler">
        /// XMLHandler based object which will process the XML elements.
        /// </param>
        /// <param name="filename">
        /// String object holding the filename of the XML file to be parsed.
        /// </param>
        /// <param name="schemaName">
        /// String object holding the name of the XML schema file to use for validating the XML.
        /// Note that whether this is used or not is dependant upon the XMLParser in use.
        /// </param>
        /// <param name="resourceGroup">
        /// String object holding the resource group identifier which will be passed to the
        /// ResourceProvider when loading the XML and schema files.
        /// </param>
        /// <param name="allowXmlValidation">
        /// A boolean object used for disallowing xml validation for a single call,
        /// defaulting to "true" to allow validation.
        /// Only needed if xml validation should be disallowed once.
        /// </param>
        public virtual void ParseXmlFile(XmlHandler handler, string filename, string schemaName, string resourceGroup, bool allowXmlValidation = true)
        {
            // Acquire resource using CEGUI ResourceProvider
            var rawXmlData = new RawDataContainer();

            System.GetSingleton().GetResourceProvider()
            .LoadRawDataContainer(filename, rawXmlData, resourceGroup);

            try
            {
                // The actual parsing action (this is overridden and depends on the specific parser)
                ParseXml(handler, rawXmlData, schemaName);
            }
            catch (Exception)
            {
                // hint the related file name in the log
                System.GetSingleton().Logger
                .LogEvent("The last thrown exception was related to XML file '" +
                          filename + "' from resource group '" + resourceGroup + "'.", LoggingLevel.Errors);

                throw;
            }
            finally
            {
                // Release resource
                System.GetSingleton().GetResourceProvider()
                .UnloadRawDataContainer(rawXmlData);
            }
        }
        /*!
         * \brief
         *  Creates a new T object from a RawDataContainer and adds it to the collection.
         *
         *  Use an instance of the xml resource loading class \a U to process the
         *  XML source thereby creating an instance of class \a T and add it to the collection under
         *  the name specified in the XML file.
         *
         * \param source
         *  RawDataContainer holding the XML source to be used when creating the
         *  new object instance.
         *
         * \param action
         *  One of the XMLResourceExistsAction enumerated values indicating what
         *  action should be taken when an object with the specified name
         *  already exists within the collection.
         */

        public T CreateFromContainer(RawDataContainer source,
                                     XMLResourceExistsAction action = XMLResourceExistsAction.XREA_RETURN)
        {
            var xmlLoader = new U();

            xmlLoader.HandleContainer(source);

            return(DoExistingObjectAction(xmlLoader.GetObjectName(),
                                          xmlLoader.GetObject(), action));
        }
示例#4
0
        private void Reinit()
        {
            var fontData = new RawDataContainer();

            System.GetSingleton().GetResourceProvider()
            .LoadRawDataContainer(d_filename, fontData, String.IsNullOrEmpty(d_resourceGroup)
                                                                  ? GetDefaultResourceGroup()
                                                                  : d_resourceGroup);
            LoadFntFile(fontData.Stream());
        }
        public override void LoadRawDataContainer(string filename, RawDataContainer output, string resourceGroup)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new InvalidRequestException("Filename supplied for data loading must be valid.");
            }

            var finalFilename = GetFinalFilename(filename, resourceGroup);

            var buffer = File.ReadAllBytes(finalFilename);

            output.SetData(new MemoryStream(buffer, 0, buffer.Length, false, true));
        }
        public override void ParseXml(XmlHandler handler, RawDataContainer source, string schemaName, bool allowXmlValidation = true)
        {
            var settings = new XmlReaderSettings {
                IgnoreWhitespace = true
            };

            if (!String.IsNullOrEmpty(schemaName))
            {
                using (var schemaFile = new RawDataContainer())
                {
                    System.GetSingleton().GetResourceProvider().LoadRawDataContainer(schemaName, schemaFile, "schemas");
                    settings.Schemas.Add(null, new XmlTextReader(schemaFile.Stream()));
                }
            }

            using (var reader = XmlReader.Create(source.Stream(), settings))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        OnStartElement(reader, handler);
                        reader.MoveToElement();
                        if (reader.IsEmptyElement)
                        {
                            OnEndElement(reader, handler);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        OnEndElement(reader, handler);
                        break;

                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        OnText(reader, handler);
                        break;
                    }
                }
            }
        }
 public override void UnloadRawDataContainer(RawDataContainer data)
 {
     data.Release();
 }
 /// <summary>
 /// Unload raw binary data. This gives the resource provider a change to unload the data
 /// in its own way before the data container object is destroyed.  If it does nothing,
 /// then the object will release its memory.
 /// </summary>
 /// <param name="rawDataContainer">
 /// Reference to a RawDataContainer object that is about to be destroyed.
 /// </param>
 public virtual void UnloadRawDataContainer(RawDataContainer rawDataContainer)
 {
 }
        /*!
         * \brief
         *  Destructor for the ResourceProvider class
         */
        // TODO: virtual ~ResourceProvider(void) { }

        /*************************************************************************
        *   Accessor functions
        *************************************************************************/

        //    /*!
        //    \brief
        //        Load XML data using InputSource objects.
        //
        //    \param filename
        //        String containing a filename of the resource to be loaded.
        //
        //	\param output
        //		Reference to a InputSourceContainer object to load the data into.
        //   */
        //    virtual void loadInputSourceContainer(const String& filename, InputSourceContainer& output) = 0;

        /// <summary>
        /// Load raw binary data.
        /// </summary>
        /// <param name="filename">
        /// String containing a filename of the resource to be loaded.
        /// </param>
        /// <param name="output">
        /// Reference to a RawDataContainer object to load the data into.
        /// </param>
        /// <param name="resourceGroup">
        /// Optional String that may be used by implementations to identify the group from
        /// which the resource should be loaded.
        /// </param>
        public abstract void LoadRawDataContainer(string filename, RawDataContainer output, string resourceGroup);
示例#10
0
        /*!
         * \brief
         *  Destructor
         */
        // TODO: ~WidgetLookManager();

        /*!
         * \brief
         *  Parses a file containing window look & feel specifications (in the form of XML).
         *
         * \note
         *  If the new file contains specifications for widget types that are already specified, it is not an error;
         *  the previous definitions are overwritten by the new data.  An entry will appear in the log each time any
         *  look & feel component is overwritten.
         *
         * \param source
         *  RawDataContainer containing the source code that will be parsed
         *
         * \param resourceGroup
         *  Resource group identifier to pass to the resource provider when loading the file.
         *
         * \return
         *  Nothing.
         *
         * \exception FileIOException             thrown if there was some problem accessing or parsing the file \a filename
         * \exception InvalidRequestException     thrown if an invalid filename was provided.
         */
        public void ParseLookNFeelSpecificationFromContainer(RawDataContainer source)
        {
            throw new NotImplementedException();
        }
示例#11
0
 /// <summary>
 /// Takes given RawDataContainer containing XML and handles it
 ///
 /// This is basically a convenience function used by NamedXMLResourceManager
 /// <internal>No need for this to be virtual</internal>
 /// </summary>
 /// <param name="source"></param>
 public void HandleContainer(RawDataContainer source)
 {
     System.GetSingleton().GetXMLParser()
     .ParseXml(this, source, GetSchemaName());
 }
示例#12
0
 /// <summary>
 /// abstract method which initiates parsing of an XML.
 /// </summary>
 /// <param name="handler">
 /// XMLHandler based object which will process the XML elements.
 /// </param>
 /// <param name="source">
 /// RawDataContainer containing the data to parse
 /// </param>
 /// <param name="schemaName">
 /// String object holding the name of the XML schema file to use for validating the XML.
 /// Note that whether this is used or not is dependant upon the XMLParser in use.
 /// </param>
 /// <param name="allowXmlValidation">
 ///  A boolean object used for disallowing xml validation for a single call,
 /// defaulting to "true" to allow validation.
 /// Only needed if xml validation should be disallowed once.
 /// </param>
 public abstract void ParseXml(XmlHandler handler, RawDataContainer source, string schemaName, bool allowXmlValidation = true);
示例#13
0
        /*!
         * \brief
         *  Creates a set of windows (a GUI layout) from the information in the specified XML.
         *
         * \param source
         *  RawDataContainer holding the XML source
         *
         * \param callback
         *  PropertyCallback function to be called for each Property element loaded from the layout.  This is
         *  called prior to the property value being applied to the window enabling client code manipulation of
         *  properties.
         *
         * \param userdata
         *  Client code data pointer passed to the PropertyCallback function.
         *
         * \return
         *  Pointer to the root Window object defined in the layout.
         */

        public Window LoadLayoutFromContainer(RawDataContainer source, PropertyCallback callback = null,
                                              object userdata = null)
        {
            throw new NotImplementedException();
        }