Permalink
Browse files

updated the jena serializer to online import the resource given to im…

…portResource rather than the whole model which that resource is in
  • Loading branch information...
1 parent a802d4f commit 6b9c2a3a8088ca9fd182dfa82c4f99b17298d49d @tristan committed Apr 23, 2012
@@ -127,6 +127,17 @@ public static Object fromInputStream(InputStream content, String enc) throws IOE
return fromReader(new BufferedReader(new InputStreamReader(content, enc)));
}
+ public static String toPrettyString(Object obj) {
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ return mapper.defaultPrettyPrintingWriter().writeValueAsString(obj);
+ } catch (Exception e) {
+ // TODO: if the obj isn't valid json this should throw an exception of some kind
+ return "";
+ }
+ }
+
public static String toString(Object obj) { // throws
// JsonGenerationException,
// JsonMappingException {
@@ -38,39 +38,32 @@ public void importModel(Model model) {
// document
ResIterator subjects = model.listSubjects();
while (subjects.hasNext()) {
-
Resource subject = subjects.next();
- String subj = getID(subject);
+ importResource(subject);
+ }
+ }
- StmtIterator statements = model.listStatements(subject, (Property) null, (RDFNode) null);
- while (statements.hasNext()) {
- Statement statement = statements.next();
- Property predicate = statement.getPredicate();
- RDFNode object = statement.getObject();
+ public void importResource(Resource subject) {
+ String subj = getID(subject);
+ StmtIterator statements = subject.getModel().listStatements(subject, (Property) null, (RDFNode) null);
+ while (statements.hasNext()) {
+ Statement statement = statements.next();
+ Property predicate = statement.getPredicate();
+ RDFNode object = statement.getObject();
- if (object.isLiteral()) {
- Literal literal = object.asLiteral();
- String value = literal.getLexicalForm();
- String datatypeURI = literal.getDatatypeURI();
- String language = literal.getLanguage();
+ if (object.isLiteral()) {
+ Literal literal = object.asLiteral();
+ String value = literal.getLexicalForm();
+ String datatypeURI = literal.getDatatypeURI();
+ String language = literal.getLanguage();
- triple(subj, predicate.getURI(), value, datatypeURI, language);
- } else {
- Resource resource = object.asResource();
- String res = getID(resource);
+ triple(subj, predicate.getURI(), value, datatypeURI, language);
+ } else {
+ Resource resource = object.asResource();
+ String res = getID(resource);
- triple(subj, predicate.getURI(), res);
- }
+ triple(subj, predicate.getURI(), res);
}
-
- }
- }
-
- public void importResource(Resource r) {
- Model model = r.getModel();
- if (model == null) {
- return;
}
- importModel(model);
}
}

0 comments on commit 6b9c2a3

Please sign in to comment.