package de.dfki.km.json.jsonld.impl;

import java.util.Iterator;

import org.openrdf.model.Graph;
import org.openrdf.model.Literal;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SesameJSONLDSerializer extends de.dfki.km.json.jsonld.JSONLDSerializer
{
    private static final Logger LOG = LoggerFactory.getLogger(SesameJSONLDSerializer.class);
    
    public void importGraph(Graph model, Resource... contexts)
    {
        Iterator<Statement> statements = model.match(null, null, null, contexts);
        while(statements.hasNext())
        {
            Statement statement = statements.next();
            Resource subject = statement.getSubject();
            URI predicate = statement.getPredicate();
            Value object = statement.getObject();
            
            if(object instanceof Literal)
            {
                Literal literal = (Literal)object;
                String value = literal.getLabel();
                URI datatypeURI = literal.getDatatype();
                String language = literal.getLanguage();
                
                triple(subject.stringValue(), predicate.stringValue(), value, datatypeURI.stringValue(), language);
            }
            else
            {
                triple(subject.stringValue(), predicate.stringValue(), object.stringValue());
            }
        }
    }
    
}

@@ -709,16 +709,22 @@
         
+handle
 Statemen
@@ -724,17 +724,17 @@
 tatement
- 
+(
 statemen
@@ -734,28 +734,89 @@
 tatement
- = s
+s.next());%0A        %7D%0A    %7D%0A    %0A    public void handleStatement(S
 tatement
 s.next()
@@ -811,22 +811,30 @@
 ment
-s.
+ 
 next
-();
+Statement)
 %0A    
+%7B%0A
     
@@ -848,33 +848,37 @@
 ource subject = 
-s
+nextS
 tatement.getSubj
@@ -888,28 +888,24 @@
 ();%0A        
-    
 URI predicat
@@ -908,17 +908,21 @@
 icate = 
-s
+nextS
 tatement
@@ -946,20 +946,16 @@
         
-    
 Value ob
@@ -961,17 +961,21 @@
 bject = 
-s
+nextS
 tatement
@@ -996,30 +996,25 @@
         
-    %0A 
+%0A
         
    if(ob
@@ -1005,19 +1005,16 @@
         
-   
 if(objec
@@ -1039,34 +1039,26 @@
 al)%0A        
-  
-  %7B%0A    
+%7B%0A
             
@@ -1100,28 +1100,24 @@
             
-    
 String value
@@ -1147,28 +1147,24 @@
             
- 
-   
 URI datatype
@@ -1188,28 +1188,24 @@
 Datatype();%0A
-    
             
@@ -1253,30 +1253,25 @@
             
-    %0A 
+%0A
             
@@ -1262,35 +1262,32 @@
    %0A            
-   
 triple(subject.s
@@ -1374,34 +1374,26 @@
 e);%0A        
-    %7D%0A    
+%7D%0A
         else
@@ -1397,34 +1397,26 @@
 lse%0A        
-    %7B%0A    
+%7B%0A
             
@@ -1497,22 +1497,8 @@
 ));%0A
-            %7D%0A
     

add individual statement handling