static void emit_start_section(const char* id, const char* title, raptor_iostream* iostr) { raptor_iostream_string_write("<section id=\"", iostr); raptor_iostream_string_write(id, iostr); raptor_iostream_string_write( "\">\n" "<title>", iostr); raptor_xml_escape_string_write((const unsigned char*)title, strlen(title), '\0', iostr); raptor_iostream_string_write("</title>\n", iostr); }
static void emit_format_description_name(const char* type_name, const raptor_syntax_description* sd, raptor_iostream* iostr) { raptor_xml_escape_string_write((const unsigned char*)sd->label, strlen(sd->label), '\0', iostr); if(type_name) { raptor_iostream_write_byte(' ', iostr); raptor_iostream_string_write(type_name, iostr); } raptor_iostream_string_write(" (", iostr); emit_literal(sd->names[0], iostr); raptor_iostream_write_byte(')', iostr); }
static int rasqal_iostream_write_html_literal(rasqal_world* world, raptor_iostream *iostr, rasqal_literal* l) { if(!l) { raptor_iostream_counted_string_write("<span class=\"unbound\">", 22, iostr); raptor_iostream_counted_string_write("unbound", 7, iostr); } else { const unsigned char* str; size_t len; switch(l->type) { case RASQAL_LITERAL_URI: str = RASQAL_GOOD_CAST(const unsigned char*, raptor_uri_as_counted_string(l->value.uri, &len)); raptor_iostream_counted_string_write("<span class=\"uri\">", 18, iostr); raptor_iostream_counted_string_write("<a href=\"", 9, iostr); raptor_xml_escape_string_write(str, len, '"', iostr); raptor_iostream_counted_string_write("\">", 2, iostr); raptor_xml_escape_string_write(str, len, 0, iostr); raptor_iostream_counted_string_write("</a>", 4, iostr); break; case RASQAL_LITERAL_BLANK: raptor_iostream_counted_string_write("<span class=\"blank\">", 20, iostr); raptor_xml_escape_string_write(l->string, l->string_len, 0, iostr); break; case RASQAL_LITERAL_XSD_STRING: case RASQAL_LITERAL_BOOLEAN: case RASQAL_LITERAL_INTEGER: case RASQAL_LITERAL_DOUBLE: case RASQAL_LITERAL_STRING: case RASQAL_LITERAL_PATTERN: case RASQAL_LITERAL_QNAME: case RASQAL_LITERAL_FLOAT: case RASQAL_LITERAL_DECIMAL: case RASQAL_LITERAL_DATE: case RASQAL_LITERAL_DATETIME: case RASQAL_LITERAL_UDT: case RASQAL_LITERAL_INTEGER_SUBTYPE: raptor_iostream_counted_string_write("<span class=\"literal\">", 22, iostr); raptor_iostream_counted_string_write("<span class=\"value\"", 19, iostr); if(l->language) { str = RASQAL_GOOD_CAST(const unsigned char*, l->language); raptor_iostream_counted_string_write(" xml:lang=\"", 11, iostr); raptor_xml_escape_string_write(str, strlen(l->language), '"', iostr); raptor_iostream_write_byte('"', iostr); } raptor_iostream_write_byte('>', iostr); raptor_xml_escape_string_write(l->string, l->string_len, 0, iostr); raptor_iostream_counted_string_write("</span>", 7, iostr); if(l->datatype) { raptor_iostream_counted_string_write("^^<<span class=\"datatype\">", 29, iostr); str = RASQAL_GOOD_CAST(const unsigned char*, raptor_uri_as_counted_string(l->datatype, &len)); raptor_xml_escape_string_write(str, len, 0, iostr); raptor_iostream_counted_string_write("</span>>", 11, iostr); } break; case RASQAL_LITERAL_VARIABLE: return rasqal_iostream_write_html_literal(world, iostr, l->value.variable->value); case RASQAL_LITERAL_UNKNOWN: default: rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, NULL, "Cannot turn literal type %d into HTML", l->type); return 1; }
/** * raptor_xml_element_write: * @element: XML element to format * @nstack: Namespace stack context to use in formatting * @is_empty: non-0 if element is empty * @is_end: non-0 if this is an end element (else is a start element) * @depth: XML element depth * @iostr: iostream object * * Write a formatted XML element to a #raptor_iostream * * Return value: non-0 on failure */ int raptor_xml_element_write(raptor_xml_element *element, raptor_namespace_stack *nstack, int is_empty, int is_end, int depth, raptor_iostream* iostr) { struct nsd *nspace_declarations = NULL; size_t nspace_declarations_count = 0; unsigned int i; /* max is 1 per element and 1 for each attribute + size of declared */ if(nstack) { int nspace_max_count = element->attribute_count+1; if(element->declared_nspaces) nspace_max_count += raptor_sequence_size(element->declared_nspaces); nspace_declarations = RAPTOR_CALLOC(struct nsd*, nspace_max_count, sizeof(struct nsd)); } if(element->name->nspace) { if(!is_end && nstack && !raptor_namespaces_namespace_in_scope(nstack, element->name->nspace)) { nspace_declarations[0].declaration= raptor_namespace_format_as_xml(element->name->nspace, &nspace_declarations[0].length); nspace_declarations[0].nspace = element->name->nspace; nspace_declarations_count++; } } if(!is_end && element->attributes) { for(i = 0; i < element->attribute_count; i++) { /* qname */ if(element->attributes[i]->nspace) { if(nstack && !raptor_namespaces_namespace_in_scope(nstack, element->attributes[i]->nspace) && element->attributes[i]->nspace != element->name->nspace) { /* not in scope and not same as element (so already going to be declared)*/ unsigned int j; int declare_me = 1; /* check it wasn't an earlier declaration too */ for(j = 0; j < nspace_declarations_count; j++) if(nspace_declarations[j].nspace == element->attributes[j]->nspace) { declare_me = 0; break; } if(declare_me) { nspace_declarations[nspace_declarations_count].declaration= raptor_namespace_format_as_xml(element->attributes[i]->nspace, &nspace_declarations[nspace_declarations_count].length); nspace_declarations[nspace_declarations_count].nspace = element->attributes[i]->nspace; nspace_declarations_count++; } } } } } if(!is_end && nstack && element->declared_nspaces && raptor_sequence_size(element->declared_nspaces) > 0) { for(i = 0; i< (unsigned int)raptor_sequence_size(element->declared_nspaces); i++) { raptor_namespace* nspace = (raptor_namespace*)raptor_sequence_get_at(element->declared_nspaces, i); unsigned int j; int declare_me = 1; /* check it wasn't an earlier declaration too */ for(j = 0; j < nspace_declarations_count; j++) if(nspace_declarations[j].nspace == nspace) { declare_me = 0; break; } if(declare_me) { nspace_declarations[nspace_declarations_count].declaration= raptor_namespace_format_as_xml(nspace, &nspace_declarations[nspace_declarations_count].length); nspace_declarations[nspace_declarations_count].nspace = nspace; nspace_declarations_count++; } } } raptor_iostream_write_byte('<', iostr); if(is_end) raptor_iostream_write_byte('/', iostr); if(element->name->nspace && element->name->nspace->prefix_length > 0) { raptor_iostream_counted_string_write((const char*)element->name->nspace->prefix, element->name->nspace->prefix_length, iostr); raptor_iostream_write_byte(':', iostr); } raptor_iostream_counted_string_write((const char*)element->name->local_name, element->name->local_name_length, iostr); /* declare namespaces */ if(nspace_declarations_count) { /* sort them into the canonical order */ qsort((void*)nspace_declarations, nspace_declarations_count, sizeof(struct nsd), raptor_nsd_compare); /* add them */ for(i = 0; i < nspace_declarations_count; i++) { raptor_iostream_write_byte(' ', iostr); raptor_iostream_counted_string_write((const char*)nspace_declarations[i].declaration, nspace_declarations[i].length, iostr); RAPTOR_FREE(char*, nspace_declarations[i].declaration); nspace_declarations[i].declaration = NULL; raptor_namespace_stack_start_namespace(nstack, (raptor_namespace*)nspace_declarations[i].nspace, depth); } } if(!is_end && element->attributes) { for(i = 0; i < element->attribute_count; i++) { raptor_iostream_write_byte(' ', iostr); if(element->attributes[i]->nspace && element->attributes[i]->nspace->prefix_length > 0) { raptor_iostream_counted_string_write((char*)element->attributes[i]->nspace->prefix, element->attributes[i]->nspace->prefix_length, iostr); raptor_iostream_write_byte(':', iostr); } raptor_iostream_counted_string_write((const char*)element->attributes[i]->local_name, element->attributes[i]->local_name_length, iostr); raptor_iostream_counted_string_write("=\"", 2, iostr); raptor_xml_escape_string_write(element->attributes[i]->value, element->attributes[i]->value_length, '"', iostr); raptor_iostream_write_byte('"', iostr); } } if(is_empty) raptor_iostream_write_byte('/', iostr); raptor_iostream_write_byte('>', iostr); if(nstack) RAPTOR_FREE(stringarray, nspace_declarations); return 0; }