/** * Returns an empty {@link RDFBackend} instance intended to be used to create * {@link RdfPathParser} instances<p> * {@link RDFBackend} has currently two distinct roles <ol> * <li> to traverse the graph ( basically the * {@link RDFBackend#listObjects(Object, Object)} and * {@link RDFBackend#listSubjects(Object, Object)} methods) * <li> to create Nodes and convert Nodes * </ol> * The {@link RdfPathParser} while requiring an {@link RDFBackend} instance * depends only on the 2nd role. Therefore the data managed by the * {@link RDFBackend} instance are of no importance.<p> * The {@link RDFBackend} provided by this constant is intended to be only * used for the 2nd purpose and does contain no information! * <li> */ public static RDFBackend<RDFTerm> getEmptyBackend(){ if(EMPTY_BACKEND == null){ EMPTY_BACKEND = new ClerezzaBackend(new SimpleGraph()); } return EMPTY_BACKEND; }
/** * Creates a {@link RDFBackend} over the {@link ContentItem#getMetadata() * metadata} and all {@link ContentItem#getPart(int, Class) content parts} * compatible to {@link Graph} * @param ci the content item * @param includeAdditionalMetadata if <code>true</code> the {@link RDFBackend} * will also include RDF data stored in content parts */ public ContentItemBackend(ContentItem ci, boolean includeAdditionalMetadata){ included = includeAdditionalMetadata ? unmodifiableMap(getContentParts(ci, Graph.class)) : EMPTY_INCLUDED; Graph graph; if(included.isEmpty()){ graph = ci.getMetadata(); } else { Graph[] tcs = new Graph[included.size()+1]; tcs[0] = ci.getMetadata(); System.arraycopy(included.values().toArray(), 0, tcs, 1, included.size()); graph = new UnionGraph(tcs); } backend = new ClerezzaBackend(graph); this.ci = ci; this.readLock = ci.getLock().readLock(); } /**
graph = new UnionGraph(tcs); backend = new ClerezzaBackend(graph); this.ci = ci; this.readLock = ci.getLock().readLock();
/** * Renders a GraphNode with a template located in the templates * folder of any active bundle * * @param node the GraphNode to be rendered * @param templatePath the freemarker path to the template * @param out where the result is written to */ public void render(GraphNode node, final String templatePath, Writer out) { //A GraphNode backend could be graph unspecific, so the same engine could be //reused, possibly being signifantly more performant (caching, etc.) RDFBackend<RDFTerm> backend = new ClerezzaBackend(node.getGraph()); RDFTerm context = node.getNode(); TemplateEngine<RDFTerm> engine = new TemplateEngine<RDFTerm>(backend); engine.setTemplateLoader(templateLoader); try { engine.processFileTemplate(context, templatePath, null, out); out.flush(); } catch (IOException e) { throw new RuntimeException(e); } catch (TemplateException e) { throw new RuntimeException(e); } }
/** * Renders a GraphNode with a template located in the templates * folder of any active bundle * * @param node the GraphNode to be rendered * @param templatePath the freemarker path to the template * @param out where the result is written to */ public void render(GraphNode node, final String templatePath, Writer out) { //A GraphNode backend could be graph unspecific, so the same engine could be //reused, possibly being signifantly more performant (caching, etc.) RDFBackend<RDFTerm> backend = new ClerezzaBackend(node.getGraph()); RDFTerm context = node.getNode(); TemplateEngine<RDFTerm> engine = new TemplateEngine<RDFTerm>(backend); engine.setTemplateLoader(templateLoader); try { engine.processFileTemplate(context, templatePath, null, out); out.flush(); } catch (IOException e) { throw new RuntimeException(e); } catch (TemplateException e) { throw new RuntimeException(e); } }