예제 #1
0
static int
raptor_xml_writer_end_element_common(raptor_xml_writer* xml_writer,
                                     raptor_xml_element *element,
                                     int is_empty)
{
  raptor_iostream* iostr = xml_writer->iostr;

  if(is_empty)
    raptor_iostream_write_byte('/', iostr);
  else {
    
    raptor_iostream_write_byte('<', iostr);

    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);
  }
  
  raptor_iostream_write_byte('>', iostr);

  return 0;
  
}
/**
 * raptor_statement_ntriples_write:
 * @statement: statement to write
 * @iostr: raptor iostream
 * @write_graph_term: flag to write graph term if present
 * 
 * Write a #raptor_statement formatted in N-Triples or N-Quads format
 * to a #raptor_iostream
 * 
 * Return value: non-0 on failure
 **/
int
raptor_statement_ntriples_write(const raptor_statement *statement,
                                raptor_iostream* iostr,
                                int write_graph_term)
{
  unsigned int flags = RAPTOR_ESCAPED_WRITE_NTRIPLES_LITERAL;

  RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(statement, raptor_statement, 1);

  if(raptor_term_escaped_write(statement->subject, flags, iostr))
    return 1;
  
  raptor_iostream_write_byte(' ', iostr);
  if(raptor_term_escaped_write(statement->predicate, flags, iostr))
    return 1;
  
  raptor_iostream_write_byte(' ', iostr);
  if(raptor_term_escaped_write(statement->object, flags, iostr))
    return 1;

  if(statement->graph && write_graph_term) {
    raptor_iostream_write_byte(' ', iostr);
    if(raptor_term_escaped_write(statement->graph, flags, iostr))
      return 1;
  }
  
  raptor_iostream_counted_string_write(" .\n", 3, iostr);

  return 0;
}
예제 #3
0
static void
raptor_dot_serializer_write_node_type(raptor_serializer * serializer,
				      raptor_identifier_type type)
{
  switch(type) {
    case RAPTOR_IDENTIFIER_TYPE_LITERAL:
    case RAPTOR_IDENTIFIER_TYPE_XML_LITERAL:
      raptor_iostream_write_byte(serializer->iostream, 'L');
      break;

    case RAPTOR_IDENTIFIER_TYPE_ANONYMOUS:
      raptor_iostream_write_byte(serializer->iostream, 'B');
      break;

    case RAPTOR_IDENTIFIER_TYPE_RESOURCE:
    case RAPTOR_IDENTIFIER_TYPE_PREDICATE:
      raptor_iostream_write_byte(serializer->iostream, 'R');
      break;

    case RAPTOR_IDENTIFIER_TYPE_ORDINAL:
    case RAPTOR_IDENTIFIER_TYPE_UNKNOWN:
      raptor_iostream_write_byte(serializer->iostream, '?');
      break;
  }
}
예제 #4
0
/**
 * rasqal_variable_write:
 * @v: the #rasqal_variable object
 * @iostr: the #raptor_iostream handle to write to
 *
 * Write a Rasqal variable to an iostream in a debug format.
 * 
 * The write debug format may change in any release.
 * 
 **/
void
rasqal_variable_write(rasqal_variable* v, raptor_iostream* iostr)
{
  if(!v || !iostr)
    return;
    
  if(v->type == RASQAL_VARIABLE_TYPE_ANONYMOUS)
    raptor_iostream_counted_string_write("anon-variable(", 14, iostr);
  else
    raptor_iostream_counted_string_write("variable(", 9, iostr);

  raptor_iostream_string_write(v->name, iostr);

  if(v->expression) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_expression_write(v->expression, iostr);
  }

  if(v->value) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_literal_write(v->value, iostr);
  }

#ifdef RASQAL_DEBUG_VARIABLE_USAGE
  raptor_iostream_write_byte('[', iostr);
  raptor_iostream_decimal_write(v->usage, iostr);
  raptor_iostream_write_byte(']', iostr);
#endif

  raptor_iostream_write_byte(')', iostr);
}
예제 #5
0
static void
rasqal_query_write_sparql_uri(sparql_writer_context *wc,
                              raptor_iostream* iostr, raptor_uri* uri)
{
  size_t len;
  unsigned char* string;
  raptor_qname* qname;

  qname = raptor_new_qname_from_namespace_uri(wc->nstack, uri, 10);
  if(qname) {
    const raptor_namespace* nspace = raptor_qname_get_namespace(qname);
    if(!raptor_namespace_get_prefix(nspace))
      raptor_iostream_write_byte(':', iostr);
    raptor_qname_write(qname, iostr);
    raptor_free_qname(qname);
    return;
  }
  
  if(wc->base_uri)
    string = raptor_uri_to_relative_counted_uri_string(wc->base_uri, uri, &len);
  else
    string = raptor_uri_as_counted_string(uri, &len);

  raptor_iostream_write_byte('<', iostr);
  raptor_string_ntriples_write(string, len, '>', iostr);
  raptor_iostream_write_byte('>', iostr);

  if(wc->base_uri)
    raptor_free_memory(string);
}
예제 #6
0
static int
rasqal_iostream_write_csv_string(const unsigned char *string, size_t len,
                                 raptor_iostream *iostr)
{
  const char delim = '\x22';
  int quoting_needed = 0;
  size_t i;

  for(i = 0; i < len; i++) {
    char c = string[i];
    /* Quoting needed for delim (double quote), comma, linefeed or return */
    if(c == delim   || c == ',' || c == '\r' || c == '\n') {
      quoting_needed++;
      break;
    }
  }
  if(!quoting_needed)
    return raptor_iostream_counted_string_write(string, len, iostr);

  raptor_iostream_write_byte(delim, iostr);
  for(i = 0; i < len; i++) {
    char c = string[i];
    if(c == delim)
      raptor_iostream_write_byte(delim, iostr);
    raptor_iostream_write_byte(c, iostr);
  }
  raptor_iostream_write_byte(delim, iostr);

  return 0;
}
예제 #7
0
static void
rasqal_query_write_sparql_triple(sparql_writer_context *wc,
                                 raptor_iostream* iostr, rasqal_triple* triple)
{
  rasqal_query_write_sparql_literal(wc, iostr, triple->subject);
  raptor_iostream_write_byte(' ', iostr);
  if(triple->predicate->type == RASQAL_LITERAL_URI &&
     raptor_uri_equals(triple->predicate->value.uri, wc->type_uri))
    raptor_iostream_write_byte('a', iostr);
  else
    rasqal_query_write_sparql_literal(wc, iostr, triple->predicate);
  raptor_iostream_write_byte(' ', iostr);
  rasqal_query_write_sparql_literal(wc, iostr, triple->object);
  raptor_iostream_counted_string_write(" .", 2, iostr);
}
예제 #8
0
/**
 * raptor_turtle_writer_reference:
 * @turtle_writer: Turtle writer object
 * @uri: URI to write
 *
 * Write a URI to the Turtle writer.
 *
 **/
void
raptor_turtle_writer_reference(raptor_turtle_writer* turtle_writer, 
                               raptor_uri* uri)
{
  unsigned char* uri_str;
  size_t length;
  
  uri_str = raptor_uri_to_relative_counted_uri_string(turtle_writer->base_uri, uri, &length);

  raptor_iostream_write_byte('<', turtle_writer->iostr);
  if(uri_str)
    raptor_string_ntriples_write(uri_str, length, '>', turtle_writer->iostr);
  raptor_iostream_write_byte('>', turtle_writer->iostr);

  RAPTOR_FREE(cstring, uri_str);
}
예제 #9
0
static void
raptor_dot_serializer_write_uri(raptor_serializer* serializer,
				raptor_uri* uri)
{
  raptor_dot_context* context = (raptor_dot_context*)serializer->context;
  unsigned char* full = raptor_uri_as_string(uri);
  int i;

  for( i = 0 ; i < raptor_sequence_size(context->namespaces) ; i++ ) {
    raptor_namespace* ns =
      (raptor_namespace*)raptor_sequence_get_at(context->namespaces, i);
    const unsigned char* ns_uri_string;
    size_t ns_uri_string_len;
    ns_uri_string=raptor_uri_as_counted_string(ns->uri, &ns_uri_string_len);

    if(!strncmp((char*)full, (char*)ns_uri_string, ns_uri_string_len) ) {
      const unsigned char* prefix = raptor_namespace_get_prefix(ns);
      
      if(prefix) {	
        raptor_iostream_write_string(serializer->iostream, prefix);
        raptor_iostream_write_byte(serializer->iostream, ':');
      }

      raptor_iostream_write_string(serializer->iostream,
                                   full + ns_uri_string_len);

      return;
    }
  }

  raptor_iostream_write_string(serializer->iostream, full);
}
예제 #10
0
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);
}
예제 #11
0
/**
 * raptor_xml_writer_flush:
 * @xml_writer: XML writer object
 *
 * Finish the XML writer.
 *
 **/
void
raptor_xml_writer_flush(raptor_xml_writer* xml_writer)
{
  if(xml_writer->pending_newline) {
    raptor_iostream_write_byte('\n', xml_writer->iostr);
    xml_writer->pending_newline = 0;
  }
}
예제 #12
0
static int
test_write_to_string(raptor_world *world,
                     const char* test_string, size_t test_string_len,
                     const unsigned int expected_bytes_count)
{
  raptor_iostream *iostr = NULL;
  unsigned long count;
  int rc = 0;
  void *string = NULL;
  size_t string_len;
  const char* const label="write iostream to a string";

  
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
  fprintf(stderr, "%s: Testing %s\n", program, label);
#endif

  iostr = raptor_new_iostream_to_string(world, &string, &string_len, NULL);
  if(!iostr) {
    fprintf(stderr, "%s: Failed to create write iostream to string\n",
            program);
    rc = 1;
    goto tidy;
  }

  raptor_iostream_write_bytes(test_string, 1, test_string_len, iostr);
  raptor_iostream_write_byte('\n', iostr);
  
  count = raptor_iostream_tell(iostr);
  if(count != expected_bytes_count) {
    fprintf(stderr, "%s: %s wrote %d bytes, expected %d\n", program, label,
            (int)count, expected_bytes_count);
    rc = 1;
  }

  raptor_free_iostream(iostr); iostr = NULL;

  if(!string) {
    fprintf(stderr, "%s: %s failed to create a string\n", program, label);
    return 1;
  }
  if(string_len != count) {
    fprintf(stderr, "%s: %s created a string length %d, expected %d\n",
            program, label, (int)string_len, (int)count);
    return 1;
  }

  tidy:
  if(string)
    raptor_free_memory(string);
  if(iostr)
    raptor_free_iostream(iostr);
  
  if(rc)
    fprintf(stderr, "%s: FAILED Testing %s\n", program, label);
    
  return rc;
}
예제 #13
0
/**
 * rasqal_variable_write:
 * @v: the #rasqal_variable object
 * @iostr: the #raptor_iostream handle to write to
 *
 * Write a Rasqal variable to an iostream in a debug format.
 * 
 * The write debug format may change in any release.
 * 
 **/
void
rasqal_variable_write(rasqal_variable* v, raptor_iostream* iostr)
{
  if(v->type == RASQAL_VARIABLE_TYPE_ANONYMOUS)
    raptor_iostream_counted_string_write("anon-variable(", 14, iostr);
  else
    raptor_iostream_counted_string_write("variable(", 9, iostr);
  raptor_iostream_string_write(v->name, iostr);
  if(v->expression) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_expression_write(v->expression, iostr);
  }
  if(v->value) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_literal_write(v->value, iostr);
  }
  raptor_iostream_write_byte(')', iostr);
}
예제 #14
0
/* Handle printing a pending newline OR newline with indenting */
static int
raptor_xml_writer_indent(raptor_xml_writer *xml_writer)
{
  int num_spaces;

  if(!XML_WRITER_AUTO_INDENT(xml_writer)) {
    if(xml_writer->pending_newline) {
      raptor_iostream_write_byte('\n', xml_writer->iostr);
      xml_writer->pending_newline = 0;

      if(xml_writer->current_element)
        xml_writer->current_element->content_cdata_seen = 1;
    }
    return 0;
  }
  
  num_spaces = xml_writer->depth * XML_WRITER_INDENT(xml_writer);

  /* Do not write an extra newline at the start of the document
   * (after the XML declaration or XMP processing instruction has
   * been writtten)
   */
  if(xml_writer->xml_declaration_checked == 1)
    xml_writer->xml_declaration_checked++;
  else {
    raptor_iostream_write_byte('\n', xml_writer->iostr);
    xml_writer->pending_newline = 0;
  }
  
  while(num_spaces > 0) {

    int count = (num_spaces > (int)SPACES_BUFFER_SIZE) ? (int)SPACES_BUFFER_SIZE : num_spaces;

    raptor_iostream_counted_string_write(spaces_buffer, count,
                                         xml_writer->iostr);

    num_spaces -= count;
  }

  if(xml_writer->current_element)
    xml_writer->current_element->content_cdata_seen = 1;

  return 0;
}
예제 #15
0
파일: rdf_statement.c 프로젝트: nxg/librdf
/**
 * librdf_statement_write:
 * @statement: the statement
 * @iostr: raptor iostream to write to
 *
 * Write the statement to an iostream
 * 
 * This method is for debugging and the format of the output should
 * not be relied on.
 *
 * Return value: non-0 on failure
 **/
int
librdf_statement_write(librdf_statement *statement, raptor_iostream *iostr) 
{
  LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(statement, librdf_statement, 1);

  if(!statement)
    return 1;
  
  if(librdf_node_write(statement->subject, iostr))
    return 1;
  raptor_iostream_write_byte(' ', iostr);
  if(librdf_node_write(statement->predicate, iostr))
    return 1;
  raptor_iostream_write_byte(' ', iostr);
  if(librdf_node_write(statement->object, iostr))
    return 1;

  return 0;
}
예제 #16
0
/**
 * rasqal_triple_write:
 * @t: #rasqal_triple object.
 * @iostr: The #raptor_iostream handle to write to.
 * 
 * Write a Rasqal triple to an iostream in a debug format.
 * 
 * The print debug format may change in any release.
 **/
void
rasqal_triple_write(rasqal_triple* t, raptor_iostream* iostr)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN(t, rasqal_triple);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN(iostr, raptor_iostream);
  
  raptor_iostream_counted_string_write("triple(", 7, iostr);
  rasqal_literal_write(t->subject, iostr);
  raptor_iostream_counted_string_write(", ", 2, iostr);
  rasqal_literal_write(t->predicate, iostr);
  raptor_iostream_counted_string_write(", ", 2, iostr);
  rasqal_literal_write(t->object, iostr);
  raptor_iostream_write_byte(')', iostr);
  if(t->origin) {
    raptor_iostream_counted_string_write(" with origin(", 13, iostr);
    rasqal_literal_write(t->origin, iostr);
    raptor_iostream_write_byte(')', iostr);
  }
}
예제 #17
0
static void
raptor_dot_serializer_write_node(raptor_serializer * serializer,
				 const void* term,
				 raptor_identifier_type type,
				 raptor_uri* literal_datatype,
				 const unsigned char * literal_language) {
  switch(type) {
    case RAPTOR_IDENTIFIER_TYPE_LITERAL:
    case RAPTOR_IDENTIFIER_TYPE_XML_LITERAL:
      raptor_dot_iostream_write_string(serializer->iostream, (const unsigned char*)term);
      if(literal_language && type == RAPTOR_IDENTIFIER_TYPE_LITERAL) {
        raptor_iostream_write_byte(serializer->iostream, '|');
        raptor_iostream_write_string(serializer->iostream, "Language: ");
        raptor_iostream_write_string(serializer->iostream, literal_language);
      }
      if(type == RAPTOR_IDENTIFIER_TYPE_XML_LITERAL) {
        raptor_iostream_write_byte(serializer->iostream, '|');
        raptor_iostream_write_string(serializer->iostream, "Datatype: ");
        raptor_iostream_write_string(serializer->iostream, raptor_xml_literal_datatype_uri_string);
      } else if(literal_datatype) {
        raptor_iostream_write_byte(serializer->iostream, '|');
        raptor_iostream_write_string(serializer->iostream, "Datatype: ");
	raptor_dot_serializer_write_uri(serializer, (raptor_uri*)literal_datatype);
      }

      break;
      
    case RAPTOR_IDENTIFIER_TYPE_ANONYMOUS:
      raptor_iostream_write_counted_string(serializer->iostream, "_:", 2);
      raptor_iostream_write_string(serializer->iostream, term);
      break;
  
    case RAPTOR_IDENTIFIER_TYPE_RESOURCE:
    case RAPTOR_IDENTIFIER_TYPE_PREDICATE:
      raptor_dot_serializer_write_uri(serializer, (raptor_uri*)term);
      break;
      
    case RAPTOR_IDENTIFIER_TYPE_ORDINAL:
    case RAPTOR_IDENTIFIER_TYPE_UNKNOWN:
    default:
      RAPTOR_FATAL2("Unknown type %d", type);
  }
}
예제 #18
0
/**
 * raptor_dot_iostream_write_string:
 * @iostr: #raptor_iostream to write to
 * @string: UTF-8 string to write
 * @len: length of UTF-8 string
 * or \0 for no escaping.
 *
 * Write an UTF-8 string, escaped for graphviz.
 *
 * Return value: non-0 on failure.
 **/
static int
raptor_dot_iostream_write_string(raptor_iostream *iostr,
				 const unsigned char *string)
{
  unsigned char c;

  for( ; (c = *string) ; string++ ) {
    if( (c == '\\') || (c == '"') || (c == '|') ||
        (c == '{')  || (c == '}') ) {
      raptor_iostream_write_byte(iostr, '\\');
      raptor_iostream_write_byte(iostr, c);
    } else if( c == '\n' ) {
      raptor_iostream_write_byte(iostr, '\\');
      raptor_iostream_write_byte(iostr, 'n');
    } else
      raptor_iostream_write_byte(iostr, c);
  }

  return 0;
}
예제 #19
0
static int
raptor_json_serialize_end(raptor_serializer* serializer)
{
  raptor_json_context* context = (raptor_json_context*)serializer->context;
  char* value;
  
  raptor_json_writer_newline(context->json_writer);

  if(context->is_resource) {
    /* start outer object */
    raptor_json_writer_start_block(context->json_writer, '{');
    raptor_json_writer_newline(context->json_writer);
    
    raptor_avltree_visit(context->avltree,
                         raptor_json_serialize_avltree_visit,
                         serializer);

    /* end last triples block */
    if(context->last_statement) {
      raptor_json_writer_newline(context->json_writer);
      raptor_json_writer_end_block(context->json_writer, ']');
      raptor_json_writer_newline(context->json_writer);
      
      raptor_json_writer_end_block(context->json_writer, '}');
      raptor_json_writer_newline(context->json_writer);
    }
  } else {
    /* end triples array */
    raptor_json_writer_end_block(context->json_writer, ']');
    raptor_json_writer_newline(context->json_writer);
  }


  value = RAPTOR_OPTIONS_GET_STRING(serializer, RAPTOR_OPTION_JSON_EXTRA_DATA);
  if(value) {
    raptor_iostream_write_byte(',', serializer->iostream);
    raptor_json_writer_newline(context->json_writer);
    raptor_iostream_string_write(value, serializer->iostream);
    raptor_json_writer_newline(context->json_writer);
  }


  /* end outer object */
  raptor_json_writer_end_block(context->json_writer, '}');
  raptor_json_writer_newline(context->json_writer);

  /* end callback */
  if(RAPTOR_OPTIONS_GET_STRING(serializer, RAPTOR_OPTION_JSON_CALLBACK))
    raptor_iostream_counted_string_write((const unsigned char*)");", 2,
                                         serializer->iostream);

  return 0;
}
예제 #20
0
static void
rasqal_query_write_sparql_triple_data(sparql_writer_context *wc,
                                      raptor_iostream* iostr,
                                      raptor_sequence *triples,
                                      int indent)
{
  int triple_index = 0;
  
  raptor_iostream_counted_string_write("{\n", 2, iostr);
  indent += 2;
  
  /* look for triples */
  while(1) {
    rasqal_triple* t = raptor_sequence_get_at(triples, triple_index);
    if(!t)
      break;
    
    rasqal_query_write_indent(iostr, indent);
    if(t->origin) {
      raptor_iostream_counted_string_write("GRAPH ", 6, iostr);
      rasqal_query_write_sparql_literal(wc, iostr, t->origin);
      raptor_iostream_counted_string_write(" { ", 3, iostr);
    }
    
    rasqal_query_write_sparql_triple(wc, iostr, t);

    if(t->origin)
      raptor_iostream_counted_string_write(" }", 2, iostr);

    raptor_iostream_write_byte('\n', iostr);
    
    triple_index++;
  }
  
  indent -= 2;
  
  rasqal_query_write_indent(iostr, indent);
  raptor_iostream_write_byte('}', iostr);
  
}
예제 #21
0
static int
rasqal_rowsource_write_internal(rasqal_rowsource *rowsource,
                                raptor_iostream* iostr, int indent)
{
    const char* rs_name = rowsource->handler->name;
    int arg_count = 0;
    unsigned int indent_delta;
    int offset;
    rasqal_rowsource* inner_rowsource;

    indent_delta = (unsigned int)strlen(rs_name);

    raptor_iostream_counted_string_write(rs_name, indent_delta, iostr);
    raptor_iostream_counted_string_write("(\n", 2, iostr);
    indent_delta++;

    indent += indent_delta;
    rasqal_rowsource_write_indent(iostr, indent);


    for(offset = 0;
            (inner_rowsource = rasqal_rowsource_get_inner_rowsource(rowsource, offset));
            offset++) {
        if(arg_count) {
            raptor_iostream_counted_string_write(" ,\n", 3, iostr);
            rasqal_rowsource_write_indent(iostr, indent);
        }
        rasqal_rowsource_write_internal(inner_rowsource, iostr, indent);
        arg_count++;
    }

    raptor_iostream_write_byte('\n', iostr);
    indent-= indent_delta;

    rasqal_rowsource_write_indent(iostr, indent);
    raptor_iostream_write_byte(')', iostr);

    return 0;
}
예제 #22
0
static void
raptor_dot_serializer_write_term_type(raptor_serializer * serializer,
                                      raptor_term_type type)
{
  switch(type) {
    case RAPTOR_TERM_TYPE_LITERAL:
      raptor_iostream_write_byte('L', serializer->iostream);
      break;

    case RAPTOR_TERM_TYPE_BLANK:
      raptor_iostream_write_byte('B', serializer->iostream);
      break;

    case RAPTOR_TERM_TYPE_URI:
      raptor_iostream_write_byte('R', serializer->iostream);
      break;

    case RAPTOR_TERM_TYPE_UNKNOWN:
      raptor_iostream_write_byte('?', serializer->iostream);
      break;
  }
}
예제 #23
0
static void
rasqal_iostream_write_json_boolean(raptor_iostream* iostr, 
                                   const char* name, int json_bool)
{
  raptor_iostream_write_byte('\"', iostr);
  raptor_iostream_string_write(name, iostr);
  raptor_iostream_counted_string_write("\" : ",4, iostr);

  if(json_bool)
    raptor_iostream_counted_string_write("true", 4, iostr);
  else
    raptor_iostream_counted_string_write("false", 5, iostr);

}
예제 #24
0
static void
raptor_dot_serializer_write_term(raptor_serializer * serializer,
                                 raptor_term* term)
{
  switch(term->type) {
    case RAPTOR_TERM_TYPE_LITERAL:
      raptor_dot_iostream_write_string(serializer->iostream,
                                       term->value.literal.string);
      if(term->value.literal.language) {
        raptor_iostream_write_byte('|', serializer->iostream);
        raptor_iostream_string_write("Language: ", serializer->iostream);
        raptor_iostream_string_write(term->value.literal.language,
                                     serializer->iostream);
      }
      if(term->value.literal.datatype) {
        raptor_iostream_write_byte('|', serializer->iostream);
        raptor_iostream_string_write("Datatype: ", serializer->iostream);
        raptor_dot_serializer_write_uri(serializer, term->value.literal.datatype);
      }
      break;
      
    case RAPTOR_TERM_TYPE_BLANK:
      raptor_iostream_counted_string_write("_:", 2, serializer->iostream);
      raptor_iostream_string_write(term->value.blank.string, serializer->iostream);
      break;
  
    case RAPTOR_TERM_TYPE_URI:
      raptor_dot_serializer_write_uri(serializer, term->value.uri);
      break;
      
    case RAPTOR_TERM_TYPE_UNKNOWN:
    default:
      raptor_log_error_formatted(serializer->world, RAPTOR_LOG_LEVEL_ERROR,
                                 NULL, "Triple has unsupported term type %d",
                                 term->type);
  }
}
예제 #25
0
static void
emit_start_desc_list(const char* title, raptor_iostream *iostr)
{
  raptor_iostream_string_write(
    "  <variablelist>\n",
    iostr);
  if(title) {
    raptor_iostream_string_write(
"  <title>",
    iostr);
    raptor_iostream_string_write(title, iostr);
    raptor_iostream_string_write("</title>\n", iostr);
  }
  raptor_iostream_write_byte('\n', iostr);
}
예제 #26
0
static int
raptor_json_serialize_start(raptor_serializer* serializer)
{
  raptor_json_context* context = (raptor_json_context*)serializer->context;
  raptor_uri* base_uri;
  char* value;
  
  base_uri = RAPTOR_OPTIONS_GET_NUMERIC(serializer, RAPTOR_OPTION_RELATIVE_URIS)
             ? serializer->base_uri : NULL;
  
  context->json_writer = raptor_new_json_writer(serializer->world,
                                                base_uri,
                                                serializer->iostream);
  if(!context->json_writer)
    return 1;

  if(context->is_resource) {
    context->avltree = raptor_new_avltree((raptor_data_compare_handler)raptor_statement_compare,
                                          (raptor_data_free_handler)raptor_free_statement,
                                          0);
    if(!context->avltree) {
      raptor_free_json_writer(context->json_writer);
      context->json_writer = NULL;
      return 1;
    }
  }

  /* start callback */
  value = RAPTOR_OPTIONS_GET_STRING(serializer, RAPTOR_OPTION_JSON_CALLBACK);
  if(value) {
    raptor_iostream_string_write(value, serializer->iostream);
    raptor_iostream_write_byte('(', serializer->iostream);
  }

  if(!context->is_resource) {
    /* start outer object */
    raptor_json_writer_start_block(context->json_writer, '{');
    raptor_json_writer_newline(context->json_writer);

    /* start triples array */
    raptor_iostream_counted_string_write((const unsigned char*)"\"triples\" : ", 12,
                                         serializer->iostream);
    raptor_json_writer_start_block(context->json_writer, '[');
    raptor_json_writer_newline(context->json_writer);
  }
  
  return 0;
}
예제 #27
0
static int
rasqal_query_write_sparql_select(sparql_writer_context *wc,
                                 raptor_iostream *iostr, 
                                 raptor_sequence* vars_seq)
{
  int count = raptor_sequence_size(vars_seq);
  int i;
  
  for(i = 0; i < count; i++) {
    rasqal_variable* v = (rasqal_variable*)raptor_sequence_get_at(vars_seq, i);
    raptor_iostream_write_byte(' ', iostr);
    rasqal_query_write_sparql_variable(wc, iostr, v);
  }

  return 0;
}
예제 #28
0
static void
emit_function(const char* name, raptor_iostream* iostr)
{
  int i;
  char c;
  
  raptor_iostream_string_write("<link linkend=\">", iostr);
  for(i = 0; (c = name[i]); i++) {
    if(c == '_')
      c = '-';
    raptor_iostream_write_byte(c, iostr);
  }
  raptor_iostream_string_write("\"><function>", iostr);
  raptor_iostream_string_write(name, iostr);
  raptor_iostream_string_write("()</function></link>", iostr);
}
예제 #29
0
static void
rasqal_query_write_sparql_variable(sparql_writer_context *wc,
                                   raptor_iostream* iostr, rasqal_variable* v)
{
  if(v->expression) {
    raptor_iostream_counted_string_write("( ", 2, iostr);
    rasqal_query_write_sparql_expression(wc, iostr, v->expression);
    raptor_iostream_counted_string_write(" AS ", 4, iostr);
  }
  if(v->type == RASQAL_VARIABLE_TYPE_ANONYMOUS)
    raptor_iostream_counted_string_write("_:", 2, iostr);
  else if(!v->expression)
    raptor_iostream_write_byte('?', iostr);
  raptor_iostream_string_write(v->name, iostr);
  if(v->expression)
    raptor_iostream_counted_string_write(" )", 2, iostr);
}
예제 #30
0
/**
 * raptor_turtle_writer_qname:
 * @turtle_writer: Turtle writer object
 * @qname: qname to write
 *
 * Write a QName to the Turtle writer.
 *
 **/
void
raptor_turtle_writer_qname(raptor_turtle_writer* turtle_writer,
                           raptor_qname* qname)
{
  raptor_iostream* iostr = turtle_writer->iostr;
  
  if(qname->nspace && qname->nspace->prefix_length > 0)
    raptor_iostream_counted_string_write(qname->nspace->prefix,
                                         qname->nspace->prefix_length,
                                         iostr);
  raptor_iostream_write_byte(':', iostr);
  
  raptor_iostream_counted_string_write(qname->local_name,
                                       qname->local_name_length,
                                       iostr);
  return;
}