Esempio n. 1
0
/**
 * Attempts to update the uri mappings in the given context using the
 * given attribute/value pair.
 *
 * @param attribute the attribute, which must start with xmlns.
 * @param value the value of the attribute
 */
void rdfa_update_uri_mappings(
   rdfacontext* context, const char* attr, const char* value)
{
   // * the [current element] is parsed for [URI mappings] and these
   // are added to the [list of URI mappings]. Note that a [URI
   // mapping] will simply overwrite any current mapping in the list
   // that has the same name;
   
   // Mappings are provided by @xmlns. The value to be mapped is set
   // by the XML namespace prefix, and the value to map is the value
   // of the attribute -- a URI. Note that the URI is not processed
   // in any way; in particular if it is a relative path it is not
   // resolved against the [current base]. Authors are advised to
   // follow best practice for using namespaces, which includes not
   // using relative paths.
   
   if(strcmp(attr, "xmlns") == 0)
   {
      rdfa_update_mapping(
         context->uri_mappings, XMLNS_DEFAULT_MAPPING, value);
   }
   else if(strstr(attr, "xmlns:") != NULL)
   {
      // check to make sure we're actually dealing with an
      // xmlns: namespace attribute
      // TODO: Could we segfault here? Probably.
      if((attr[5] == ':') && (attr[6] != '\0'))
      {
         rdfa_generate_namespace_triple(context, &attr[6], value);
         rdfa_update_mapping(
            context->uri_mappings, &attr[6], value);
      }
   }
}
Esempio n. 2
0
/**
 * Attempts to update the uri mappings in the given context using the
 * given attribute/value pair.
 *
 * @param attribute the attribute, which must start with xmlns.
 * @param value the value of the attribute
 */
void rdfa_update_uri_mappings(
   rdfacontext* context, const char* attr, const char* value)
{
#ifdef LIBRDFA_IN_RAPTOR
  raptor_namespace_stack* nstack;
  nstack = &context->sax2->namespaces;
#endif

   /* * the [current element] is parsed for [URI mappings] and these
    * are added to the [list of URI mappings]. Note that a [URI
    * mapping] will simply overwrite any current mapping in the list
    * that has the same name; */

   /* Mappings are provided by @xmlns. The value to be mapped is set
    * by the XML namespace prefix, and the value to map is the value
    * of the attribute -- a URI. Note that the URI is not processed
    * in any way; in particular if it is a relative path it is not
    * resolved against the [current base]. Authors are advised to
    * follow best practice for using namespaces, which includes not
    * using relative paths. */

   if(attr == NULL)
   {
#ifdef LIBRDFA_IN_RAPTOR
      raptor_namespaces_start_namespace_full(nstack,
                                             NULL,
                                             (const unsigned char*)value,
                                             0);
#else
      rdfa_update_mapping(
         context->uri_mappings, XMLNS_DEFAULT_MAPPING, value,
         (update_mapping_value_fp)rdfa_replace_string);
#endif
   }
   else if(strcmp(attr, "_") == 0)
   {
#define FORMAT_1 "The underscore character must not be declared as a prefix " \
         "because it conflicts with the prefix for blank node identifiers. " \
         "The occurrence of this prefix declaration is being ignored."
#ifdef LIBRDFA_IN_RAPTOR
      raptor_parser_warning((raptor_parser*)context->callback_data, 
                            FORMAT_1);
#else
      rdfa_processor_triples(context,
         RDFA_PROCESSOR_WARNING,
         FORMAT_1);
#endif
   }
   else if(attr[0] == ':' || attr[0] == '_' ||
      (attr[0] >= 'A' && attr[0] <= 'Z') ||
      (attr[0] >= 'a' && attr[0] <= 'z') ||
      ((unsigned char)attr[0] >= 0xc0 && (unsigned char)attr[0] <= 0xd6) ||
      ((unsigned char)attr[0] >= 0xd8 && (unsigned char)attr[0] <= 0xf6) || (unsigned char)attr[0] >= 0xf8)
   {
#ifdef LIBRDFA_IN_RAPTOR
     raptor_namespaces_start_namespace_full(nstack,
                                            (const unsigned char*)attr,
                                            (const unsigned char*)value,
                                            0);
#else
      rdfa_generate_namespace_triple(context, attr, value);
      rdfa_update_mapping(context->uri_mappings, attr, value,
         (update_mapping_value_fp)rdfa_replace_string);
#endif
   }
   else
   {
      /* allowable characters for CURIEs:
       * ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] |
       * [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
       * [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD]
       * | [#x10000-#xEFFFF]
       */

      /* Generate the processor warning if this is an invalid prefix */
#define FORMAT_2 "The declaration of the '%s' prefix is invalid " \
         "because it starts with an invalid character. Please see " \
         "http://www.w3.org/TR/REC-xml/#NT-NameStartChar for a " \
         "full explanation of valid first characters for declaring " \
         "prefixes."
#ifdef LIBRDFA_IN_RAPTOR
      raptor_parser_warning((raptor_parser*)context->callback_data, 
                            FORMAT_2, attr);
#else
      char msg[1024];
      snprintf(msg, 1024, FORMAT_1);
      rdfa_processor_triples(context, RDFA_PROCESSOR_WARNING, msg);
#endif
   }

#ifdef LIBRDFA_IN_RAPTOR
#else
   /* print the current mapping */
   if(DEBUG)
   {
      printf("DEBUG: PREFIX MAPPINGS:");
      rdfa_print_mapping(context->uri_mappings,
         (print_mapping_value_fp)rdfa_print_string);
   }
#endif
}
Esempio n. 3
0
void run_curie_tests()
{
   rdfacontext* context =
      rdfa_create_context("http://example.org/");

   rdfa_init_context(context);
   
   rdfa_update_mapping(
      context->uri_mappings, "dc", "http://purl.org/dc/elements/1.1/");
   rdfa_update_mapping(
      context->uri_mappings, "dctv", "http://purl.org/dc/dcmitype/");
   
   printf("------------------------ CURIE tests ---------------------\n");
   
   run_test(context, "IRI", "http://www.example.org/iri",
            rdfa_resolve_curie, "http://www.example.org/iri",
            CURIE_PARSE_HREF_SRC);
   run_test(context, "Safe CURIE", "[dc:title]",
            rdfa_resolve_curie, "http://purl.org/dc/elements/1.1/title",
            CURIE_PARSE_PROPERTY);
   run_test(context, "Unsafe CURIE", "dc:title",
            rdfa_resolve_curie, "http://purl.org/dc/elements/1.1/title",
            CURIE_PARSE_PROPERTY);
   run_test(context, "Non-prefixed CURIE", ":nonprefixed",
            rdfa_resolve_curie, "http://example.org/nonprefixed",
            CURIE_PARSE_PROPERTY);
   run_test(context, "Reference-only CURIE", "foobar",
            rdfa_resolve_curie, NULL, CURIE_PARSE_PROPERTY);
   run_test(context, "Reference-only safe CURIE", "[foobar]",
            rdfa_resolve_curie, NULL, CURIE_PARSE_PROPERTY);
   run_test(context, "Empty safe CURIE", "[]",
            rdfa_resolve_curie, NULL, CURIE_PARSE_PROPERTY);
   run_test(context, "Blank named safe CURIE", "[_:frank]",
            rdfa_resolve_curie, "_:frank", CURIE_PARSE_PROPERTY);

   rdfalist* dctvlist = rdfa_create_list(2);
   rdfa_add_item(
      dctvlist, "http://purl.org/dc/dcmitype/Image", RDFALIST_FLAG_NONE);
   rdfa_add_item(
      dctvlist, "http://purl.org/dc/dcmitype/Sound", RDFALIST_FLAG_NONE);
   run_list_test(
      context, "XHTML multiple @type_of", "[dctv:Image] [dctv:Sound]",
      rdfa_resolve_curie_list, dctvlist, CURIE_PARSE_INSTANCEOF_DATATYPE);
   rdfa_free_list(dctvlist);

   rdfalist* nllist = rdfa_create_list(2);
   rdfa_add_item(
      nllist, XHTML_VOCAB_URI "next", RDFALIST_FLAG_NONE);
   rdfa_add_item(
      nllist, XHTML_VOCAB_URI "license", RDFALIST_FLAG_NONE);
   run_list_test(
      context, "XHTML multiple @rel/@rev", "next license",
      rdfa_resolve_curie_list, nllist, CURIE_PARSE_RELREV);
   rdfa_free_list(nllist);
   
   rdfalist* dtlist = rdfa_create_list(2);
   rdfa_add_item(
      dtlist, XHTML_VOCAB_URI "description", RDFALIST_FLAG_NONE);
   rdfa_add_item(
      dtlist, XHTML_VOCAB_URI "title", RDFALIST_FLAG_NONE);   
   run_list_test(
      context, "XHTML multiple @property", "description title",
      rdfa_resolve_curie_list, dtlist, CURIE_PARSE_PROPERTY);
   rdfa_free_list(dtlist);

   run_test_set(context, "XHTML @rel/@rev reserved",
      my_g_relrev_reserved_words, XHTML_RELREV_RESERVED_WORDS_SIZE,
      rdfa_resolve_relrev_curie, XHTML_VOCAB_URI, CURIE_PARSE_RELREV);

   printf("---------------------- CURIE test results ---------------------\n"
          "%i passed, %i failed\n",
          g_test_passes, g_test_fails);

   rdfa_free_context(context);
}