rdf.cpp revision bf1d02bbf9f93b5d10304fd4f70f367d430c750e
/** @file
* RDF manipulation functions.
*
* @todo move these to xml/ instead of dialogs/
*/
/* Authors:
* Kees Cook <kees@outflux.net>
* Jon Phillips <jon@rejon.org>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2004 Kees Cook <kees@outflux.net>
* Copyright (C) 2006 Jon Phillips <jon@rejon.org>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "rdf.h"
#include "sp-item-group.h"
#include "inkscape.h"
#include "sp-root.h"
/*
Example RDF XML from various places...
<rdf:RDF xmlns="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
<dc:title>title of work</dc:title>
<dc:date>year</dc:date>
<dc:description>description of work</dc:description>
<dc:creator><Agent>
<dc:title>creator</dc:title>
</Agent></dc:creator>
<dc:rights><Agent>
<dc:title>holder</dc:title>
</Agent></dc:rights>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:source rdf:resource="source"/>
<license rdf:resource="http://creativecommons.org/licenses/by/2.0/"
/>
</Work>
<rdf:RDF xmlns="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
<dc:title>SVG Road Signs</dc:title>
<dc:rights><Agent>
<dc:title>John Cliff</dc:title>
</Agent></dc:rights>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<license rdf:resource="http://creativecommons.org/ns#PublicDomain" />
</Work>
<License rdf:about="http://creativecommons.org/ns#PublicDomain">
<permits rdf:resource="http://creativecommons.org/ns#Reproduction" />
<permits rdf:resource="http://creativecommons.org/ns#Distribution" />
<permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
</License>
</rdf:RDF>
Bag example:
<dc:subject>
<rdf:Bag>
<rdf:li>open clip art logo</rdf:li>
<rdf:li>images</rdf:li>
<rdf:li>logo</rdf:li>
<rdf:li>clip art</rdf:li>
<rdf:li>ocal</rdf:li>
<rdf:li>logotype</rdf:li>
<rdf:li>filetype</rdf:li>
</rdf:Bag>
</dc:subject>
*/
struct rdf_double_t rdf_license_empty [] = {
};
struct rdf_double_t rdf_license_cc_a [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
};
struct rdf_double_t rdf_license_cc_a_sa [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
{ "cc:requires", "http://creativecommons.org/ns#ShareAlike", },
};
struct rdf_double_t rdf_license_cc_a_nd [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
};
struct rdf_double_t rdf_license_cc_a_nc [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
{ "cc:prohibits", "http://creativecommons.org/ns#CommercialUse", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
};
struct rdf_double_t rdf_license_cc_a_nc_sa [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
{ "cc:prohibits", "http://creativecommons.org/ns#CommercialUse", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
{ "cc:requires", "http://creativecommons.org/ns#ShareAlike", },
};
struct rdf_double_t rdf_license_cc_a_nc_nd [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
{ "cc:prohibits", "http://creativecommons.org/ns#CommercialUse", },
};
struct rdf_double_t rdf_license_pd [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
};
struct rdf_double_t rdf_license_freeart [] = {
{ "cc:permits", "http://creativecommons.org/ns#Reproduction", },
{ "cc:permits", "http://creativecommons.org/ns#Distribution", },
{ "cc:permits", "http://creativecommons.org/ns#DerivativeWorks", },
{ "cc:requires", "http://creativecommons.org/ns#ShareAlike", },
{ "cc:requires", "http://creativecommons.org/ns#Notice", },
{ "cc:requires", "http://creativecommons.org/ns#Attribution", },
};
struct rdf_double_t rdf_license_ofl [] = {
{ "cc:permits", "http://scripts.sil.org/pub/OFL/Reproduction", },
{ "cc:permits", "http://scripts.sil.org/pub/OFL/Distribution", },
{ "cc:permits", "http://scripts.sil.org/pub/OFL/Embedding", },
{ "cc:permits", "http://scripts.sil.org/pub/OFL/DerivativeWorks", },
{ "cc:requires", "http://scripts.sil.org/pub/OFL/Notice", },
{ "cc:requires", "http://scripts.sil.org/pub/OFL/Attribution", },
{ "cc:requires", "http://scripts.sil.org/pub/OFL/ShareAlike", },
{ "cc:requires", "http://scripts.sil.org/pub/OFL/DerivativeRenaming", },
{ "cc:requires", "http://scripts.sil.org/pub/OFL/BundlingWhenSelling", },
};
struct rdf_license_t rdf_licenses [] = {
{ N_("CC Attribution"),
},
{ N_("CC Attribution-ShareAlike"),
},
{ N_("CC Attribution-NoDerivs"),
},
{ N_("CC Attribution-NonCommercial"),
},
{ N_("CC Attribution-NonCommercial-ShareAlike"),
},
{ N_("CC Attribution-NonCommercial-NoDerivs"),
},
{ N_("Public Domain"),
},
{ N_("FreeArt"),
},
{ N_("Open Font License"),
},
};
#define XML_TAG_NAME_SVG "svg:svg"
#define XML_TAG_NAME_METADATA "svg:metadata"
#define XML_TAG_NAME_RDF "rdf:RDF"
#define XML_TAG_NAME_WORK "cc:Work"
#define XML_TAG_NAME_LICENSE "cc:License"
// Remember when using the "title" and "tip" elements to pass them through
// the localization functions when you use them!
struct rdf_work_entity_t rdf_work_entities [] = {
},
N_("Date associated with the creation of this document (YYYY-MM-DD)"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
N_("The physical or digital manifestation of this document (MIME type)"), RDF_FORMAT_LINE, RDF_EDIT_HARDCODED,
},
},
N_("Name of entity primarily responsible for making the content of this document"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
N_("Name of entity with rights to the Intellectual Property of this document"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
N_("Name of entity responsible for making this document available"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
},
},
},
N_("Two-letter language tag with optional subtags for the language of this document (e.g. 'en-GB')"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
N_("The topic of this document as comma-separated key words, phrases, or classifications"), RDF_FORMAT_LINE, RDF_EDIT_GENERIC,
},
// TRANSLATORS: "Coverage": the spatial or temporal characteristics of the content.
// For info, see Appendix D of http://www.w3.org/TR/1998/WD-rdf-schema-19980409/
},
},
// FIXME: need to handle 1 agent per line of input
N_("Names of entities responsible for making contributions to the content of this document"), RDF_FORMAT_MULTILINE, RDF_EDIT_GENERIC,
},
// TRANSLATORS: URL to a page that defines the license for the document
// TRANSLATORS: this is where you put a URL to a page that defines the license
},
// TRANSLATORS: fragment of XML representing the license of the document
},
}
};
// Simple start of C++-ification:
class RDFImpl
{
public:
/**
* Some implementations do not put RDF stuff inside <metadata>,
* so we need to check for it and add it if we don't see it.
*/
static unsigned int setWorkEntity(SPDocument * doc, struct rdf_work_entity_t & entity, gchar const * text);
/**
* Pull the text out of an RDF entity, depends on how it's stored.
*
* @return A pointer to the entity's static contents as a string
* @param repr The XML element to extract from
*
*/
static const gchar *getReprText( Inkscape::XML::Node const * repr, struct rdf_work_entity_t const & entity );
struct rdf_work_entity_t const & entity,
};
/**
*
*
*/
{
struct rdf_work_entity_t *entity;
}
return NULL;
}
/*
* Takes the inkscape rdf struct and spits out a static RDF, which is only
* useful for testing. We must merge the rdf struct into the XML DOM for
* changes to be saved.
*/
/*
Since g_markup_printf_escaped doesn't exist for most people's glib
right now, this function will remain commented out since it's only
for generic debug anyway. --Kees
gchar *
rdf_string(struct rdf_t * rdf)
{
gulong overall=0;
gchar *string=NULL;
gchar *rdf_head="\
<rdf:RDF xmlns=\"http://creativecommons.org/ns#\"\
xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\
xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\
";
gchar *work_head="\
<Work rdf:about=\"\">\
<dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\" />\
";
gchar *work_title=NULL;
gchar *work_date=NULL;
gchar *work_description=NULL;
gchar *work_creator=NULL;
gchar *work_owner=NULL;
gchar *work_source=NULL;
gchar *work_license=NULL;
gchar *license_head=NULL;
gchar *license=NULL;
gchar *license_end="</License>\n";
gchar *work_end="</Work>\n";
gchar *rdf_end="</rdf:RDF>\n";
if (rdf && rdf->work_title && rdf->work_title[0]) {
work_title=g_markup_printf_escaped(" <dc:title>%s</dc:title>\n",
rdf->work_title);
overall+=strlen(work_title);
}
if (rdf && rdf->work_date && rdf->work_date[0]) {
work_date=g_markup_printf_escaped(" <dc:date>%s</dc:date>\n",
rdf->work_date);
overall+=strlen(work_date);
}
if (rdf && rdf->work_description && rdf->work_description[0]) {
work_description=g_markup_printf_escaped(" <dc:description>%s</dc:description>\n",
rdf->work_description);
overall+=strlen(work_description);
}
if (rdf && rdf->work_creator && rdf->work_creator[0]) {
work_creator=g_markup_printf_escaped(" <dc:creator><Agent>\
<dc:title>%s</dc:title>\
</Agent></dc:creator>\n",
rdf->work_creator);
overall+=strlen(work_creator);
}
if (rdf && rdf->work_owner && rdf->work_owner[0]) {
work_owner=g_markup_printf_escaped(" <dc:rights><Agent>\
<dc:title>%s</dc:title>\
</Agent></dc:rights>\n",
rdf->work_owner);
overall+=strlen(work_owner);
}
if (rdf && rdf->work_source && rdf->work_source[0]) {
work_source=g_markup_printf_escaped(" <dc:source rdf:resource=\"%s\" />\n",
rdf->work_source);
overall+=strlen(work_source);
}
if (rdf && rdf->license && rdf->license->work_rdf && rdf->license->work_rdf[0]) {
work_license=g_markup_printf_escaped(" <license rdf:resource=\"%s\" />\n",
rdf->license->work_rdf);
overall+=strlen(work_license);
license_head=g_markup_printf_escaped("<License rdf:about=\"%s\">\n",
rdf->license->work_rdf);
overall+=strlen(license_head);
overall+=strlen(rdf->license->license_rdf);
overall+=strlen(license_end);
}
overall+=strlen(rdf_head)+strlen(rdf_end);
overall+=strlen(work_head)+strlen(work_end);
overall++; // NULL term
if (!(string=(gchar*)g_malloc(overall))) {
return NULL;
}
string[0]='\0';
strcat(string,rdf_head);
strcat(string,work_head);
if (work_title) strcat(string,work_title);
if (work_date) strcat(string,work_date);
if (work_description) strcat(string,work_description);
if (work_creator) strcat(string,work_creator);
if (work_owner) strcat(string,work_owner);
if (work_source) strcat(string,work_source);
if (work_license) strcat(string,work_license);
strcat(string,work_end);
if (license_head) {
strcat(string,license_head);
strcat(string,rdf->license->license_rdf);
strcat(string,license_end);
}
strcat(string,rdf_end);
return string;
}
*/
const gchar *RDFImpl::getReprText( Inkscape::XML::Node const * repr, struct rdf_work_entity_t const & entity )
{
case RDF_CONTENT:
case RDF_AGENT:
case RDF_RESOURCE:
case RDF_XML:
return "xml goes here";
case RDF_BAG:
/* clear the static string. yucky. */
/* backwards compatible: read contents */
}
temp ;
temp->firstChild()) {
if (bag) {
}
else {
}
}
}
return bag;
default:
break;
}
return NULL;
}
struct rdf_work_entity_t const & entity,
{
int i;
// set document's title element to the RDF title
}
}
case RDF_CONTENT:
return TRUE;
}
else {
return TRUE;
}
case RDF_AGENT:
}
}
return TRUE;
}
else {
return TRUE;
}
case RDF_RESOURCE:
return true;
case RDF_XML:
return 1;
case RDF_BAG:
/* backward compatibility: drop the dc:subject contents */
}
}
/* toss all the old list items */
}
/* chop our list up on commas */
}
g_strfreev( strlist );
return 1;
default:
break;
}
return 0;
}
{
if ( !node ) {
g_critical("Null node passed to ensureParentIsMetadata().");
g_critical( "No parent node when verifying <metadata> placement." );
} else {
if ( !metadata ) {
g_critical("Unable to create metadata element.");
} else {
// attach the metadata node
// move the node into it
sp_repr_unparent( node );
}
}
}
}
{
if ( !doc ) {
g_critical("Null doc passed to getRdfRootRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else {
}
return rdf;
}
{
if ( !doc ) {
g_critical("Null doc passed to ensureRdfRootRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else {
if ( !rdf ) {
if ( !svg ) {
g_critical("Unable to locate svg element.");
} else {
if ( !parent ) {
g_critical("Unable to create metadata element");
} else {
}
}
g_critical("Parent has no document");
} else if ( parent ) {
if ( !rdf ) {
g_critical("Unable to create root RDF element.");
} else {
}
}
}
}
}
if ( rdf ) {
}
return rdf;
}
{
if ( !doc ) {
g_critical("Null doc passed to getXmlRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else if (!name) {
g_critical("Null name passed to getXmlRepr()");
} else {
if ( rdf ) {
}
}
return xml;
}
{
}
{
if ( !doc ) {
g_critical("Null doc passed to ensureXmlRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else if (!name) {
g_critical("Null name passed to ensureXmlRepr()");
} else {
if ( rdf ) {
if ( !xml ) {
if ( !xml ) {
} else {
}
}
}
}
return xml;
}
{
if ( !doc ) {
g_critical("Null doc passed to getWorkRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else if (!name) {
g_critical("Null name passed to getWorkRepr()");
} else {
if ( work ) {
}
}
return item;
}
{
if ( !doc ) {
g_critical("Null doc passed to ensureWorkRepr()");
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else if (!name) {
g_critical("Null name passed to ensureWorkRepr()");
} else {
if ( work ) {
if ( !item ) {
//printf("missing XML '%s'\n",name);
if ( !item ) {
} else {
}
}
}
}
return item;
}
// Public API:
{
if ( !doc ) {
g_critical("Null doc passed to rdf_get_work_entity()");
} else if ( entity ) {
//g_message("want '%s'\n",entity->title);
//g_message("found '%s' == '%s'\n", entity->title, result );
}
return result;
}
{
if ( item ) {
// TODO note that this is the location that used to set the title if needed. Ensure code it not required.
}
return result;
}
// Public API:
{
unsigned int result = 0;
if ( !doc ) {
g_critical("Null doc passed to rdf_set_work_entity()");
} else if ( entity ) {
}
return result;
}
unsigned int RDFImpl::setWorkEntity(SPDocument * doc, struct rdf_work_entity_t & entity, const gchar * text)
{
int result = 0;
if ( !text ) {
// FIXME: on a "NULL" text, delete the entity. For now, blank it.
text = "";
}
/*
printf("changing '%s' (%s) to '%s'\n",
entity->title,
entity->tag,
text);
*/
if ( !item ) {
g_critical("Unable to get work element");
} else {
}
return result;
}
static bool
{
#ifdef DEBUG_MATCH
#endif
int count = 0;
count++;
}
#ifdef DEBUG_MATCH
#endif
bool found_match=FALSE;
for (int i=0; i<count; i++) {
// skip already matched items
if (matched[i]) continue;
#ifdef DEBUG_MATCH
#endif
#ifdef DEBUG_MATCH
printf("\t\tgood!\n");
#endif
break;
}
}
if (!found_match) {
// if we checked each known item of the license
// and didn't find it, we must abort
#ifdef DEBUG_MATCH
#endif
break;
}
}
#ifdef DEBUG_MATCH
#endif
// scan looking for an unmatched item
if (matched[i]==0) {
#ifdef DEBUG_MATCH
#endif
}
}
#ifdef DEBUG_MATCH
#endif
#ifdef DEBUG_MATCH
#endif
return result;
}
// Public API:
{
}
{
if (repr) {
return license;
}
}
}
#ifdef DEBUG_MATCH
else {
printf("no license XML\n");
}
#endif
return NULL;
}
// Public API:
{
}
{
// drop old license section
if (repr) {
}
if ( !license ) {
// All done
} else if ( !doc->getReprDoc() ) {
g_critical("XML doc is null.");
} else {
// build new license section
}
}
}
struct rdf_entity_default_t {
};
struct rdf_entity_default_t rdf_defaults[] = {
{ "type", "http://purl.org/dc/dcmitype/StillImage", },
};
// Public API:
{
}
{
// Create metadata node if it doesn't already exist
if ( !doc->getReprDoc()) {
g_critical("XML doc is null.");
} else {
// create repr
// insert into the document
// clean up
}
}
// install defaults
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :