* @return the rdf/xml representation of all the posts on the current resource
*/
@SuppressWarnings("unchecked")
public String exportPosts2RDF()
{
Model tempModel = null;
try
{
tempModel = DbFace.getTempModel();
StringWriter stringWriter = new StringWriter();
List<Person> authors = getPostsAuthors();
ClosableIterator<Statement> reif = model.queryConstruct(RdfQuery.RDFQ_GIVEN_RESOURCE_POST_GRAPH.toString(
SIOC.postedResource, SIOC.Post, SIOC.postedWhen, SIOC.postedBy, SIOC.postBody, SIOC.title, SIOC.hasReply,SIOC.topic, uri),
"SPARQL").iterator();
while (reif.hasNext()){
tempModel.addStatement(reif.next());
}
reif.close();
ClosableIterator<Statement> statements = tempModel.findStatements(Variable.ANY, new URIImpl(SIOC.postedBy), Variable.ANY);
Collection addedAuthors = new ArrayList();
/* Exported XML must apply to the SIOC convent, so foreach post the created_by should no longer be set to
* the author's mbox, but must point to the Sioc:User node (it must be added).
* Foaf:Person pointing to the Sioc:User must be added as well.
* In other words: the statement from the graph must be removed, and two new must be added.
*/
while(statements.hasNext()) {
Statement stmt = statements.next();
tempModel.removeStatement(stmt);
/* given up, as a user doesn't have an account, Sioc:User does not intrduce any new information
//Sioc:User node
BNode bNode = graph.getValueFactory().createBNode();
graph.add(new StatementImpl(stmt.getSubject(), stmt.getPredicate(), bNode));
graph.add(new StatementImpl(bNode, valueFactory.createURI(XFOAF_SSCF.accountOf), valueFactory.createLiteral(stmt.getObject().toString())));
graph.add(new StatementImpl(bNode, valueFactory.createURI(RDF.TYPE), valueFactory.createURI(XFOAF_SSCF.User)));
//dodanie Foaf:Person holdsAccount
graph.add(new StatementImpl((Resource)stmt.getObject(), valueFactory.createURI(FOAF.maker), bNode));
*/
tempModel.addStatement(stmt.getSubject(),model.createURI(FOAF.maker.toString()),stmt.getObject());
tempModel.addStatement(stmt.getObject().asURI(), RDF.type, model.createURI(FOAF.Person.toString()));
Person tmpPerson = null;
for (Person p : authors) {
if (!addedAuthors.contains(p) && stmt.getObject().toString().equals(p.getMbox().toString())) {
tmpPerson = p;
break;
}
}
//System.out.println(s.getObject().toString());
if (tmpPerson != null) {
tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.mbox.toString()),tmpPerson.getMbox().toString());
if (tmpPerson.getName() != null && !"".equals(tmpPerson.getName()) && !"nullnull".equals(tmpPerson.getName())) {
tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.name.toString()),tmpPerson.getName());
}
if (tmpPerson.getGivenname() != null && !"".equals(tmpPerson.getGivenname())) {
tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.givenname.toString()),tmpPerson.getGivenname());
}
if (tmpPerson.getFamily_name() != null && !"".equals(tmpPerson.getFamily_name())) {
tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.family_name.toString()),tmpPerson.getFamily_name());
}
addedAuthors.add(tmpPerson);
}
}
tempModel.writeTo(stringWriter);
tempModel = null;
statements.close();
return stringWriter.toString();