/// <summary>
        /// Validates the syntax to see if it is valid SPARQL Results
        /// </summary>
        /// <param name="data">Data to validate</param>
        /// <returns></returns>
        public ISyntaxValidationResults Validate(string data)
        {
            String message;

            try
            {
                SparqlResultSet results = new SparqlResultSet();
                StringParser.ParseResultSet(results, data);
                message = "Valid SPARQL Results - " + results.Count + " Results - Parser: " + _parser.GetType().Name;

                return(new SyntaxValidationResults(true, message, results));
            }
            catch (RdfParseException parseEx)
            {
                message = "Invalid SPARQL Results - Parsing Error from Parser: " + _parser.GetType().Name + " - " + parseEx.Message;
                return(new SyntaxValidationResults(message, parseEx));
            }
            catch (RdfException rdfEx)
            {
                message = "Invalid SPARQL Results - RDF Error from Parser: " + _parser.GetType().Name + " - " + rdfEx.Message;
                return(new SyntaxValidationResults(message, rdfEx));
            }
            catch (Exception ex)
            {
                message = "Invalid SPARQL Results - Error from Parser: " + _parser.GetType().Name + " - " + ex.Message;
                return(new SyntaxValidationResults(message, ex));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Registers a parser as the default SPARQL Rsults Parser for all the given MIME types and updates relevant definitions to include the MIME types and file extensions
        /// </summary>
        /// <param name="parser">SPARQL Results Parser</param>
        /// <param name="mimeTypes">MIME Types</param>
        /// <param name="fileExtensions">File Extensions</param>
        public static void RegisterParser(ISparqlResultsReader parser, IEnumerable<String> mimeTypes, IEnumerable<String> fileExtensions)
        {
            if (!_init) Init();

            if (!mimeTypes.Any()) throw new RdfException("Cannot register a parser without specifying at least 1 MIME Type");

            //Get any existing defintions that are to be altered
            IEnumerable<MimeTypeDefinition> existing = GetDefinitions(mimeTypes);
            foreach (MimeTypeDefinition def in existing)
            {
                foreach (String type in mimeTypes)
                {
                    def.AddMimeType(type);
                }
                foreach (String ext in fileExtensions)
                {
                    def.AddFileExtension(ext);
                }
                def.SparqlResultsParserType = parser.GetType();
            }

            //Create any new defintions
            IEnumerable<String> newTypes = mimeTypes.Where(t => !GetDefinitions(t).Any());
            if (newTypes.Any())
            {
                MimeTypeDefinition newDef = new MimeTypeDefinition(String.Empty, newTypes, fileExtensions);
                newDef.SparqlResultsParserType = parser.GetType();
                AddDefinition(newDef);
            }
        }