Java Code Examples for com.hp.hpl.jena.rdf.model.Model#setNsPrefixes()

The following examples show how to use com.hp.hpl.jena.rdf.model.Model#setNsPrefixes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceBuilder.java    From LodView with MIT License 6 votes vote down vote up
public String buildRDFResource(String IRI, String sparql, Lang lang, ConfigurationBean conf) throws Exception {
	String result = "empty content";
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefixes(conf.getPrefixes());

	SPARQLEndPoint se = new SPARQLEndPoint(conf, null, null);
	model = se.extractData(model, IRI, sparql, conf.getDefaultRawDataQueries());

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	RDFWriter rdfWriter = model.getWriter(lang.getName());
	rdfWriter.setProperty("showXMLDeclaration","true");
	rdfWriter.setProperty("relativeURIs","");

	rdfWriter.write(model, baos, conf.getIRInamespace());

	byte[] resultByteArray = baos.toByteArray();
	result = new String(resultByteArray);

	return result;
}
 
Example 2
Source File: ResourceBuilder.java    From LodView with MIT License 6 votes vote down vote up
public String buildRDFResource(String IRI, Model m, Lang lang, ConfigurationBean conf) throws Exception {
	String result = "empty content";
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefixes(conf.getPrefixes());

	SPARQLEndPoint se = new SPARQLEndPoint(conf, null, null);
	model = se.extractLocalData(model, IRI, m, conf.getDefaultRawDataQueries());

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	RDFWriter rdfWriter = model.getWriter(lang.getName());
	rdfWriter.setProperty("showXMLDeclaration","true");
	rdfWriter.setProperty("relativeURIs","");

	rdfWriter.write(model, baos, conf.getIRInamespace());
	rdfWriter.setProperty("showXMLDeclaration","true");
	rdfWriter.setProperty("relativeURIs","");

	byte[] resultByteArray = baos.toByteArray();
	result = new String(resultByteArray);

	return result;
}
 
Example 3
Source File: GeneralResourceCollection.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public Model getInventoryModel(int limit) {
	log.info("Listing entity set: " + entityMaker);
	Model result = ModelFactory.createDefaultModel();
	result.setNsPrefixes(mapping.getPrefixes());
	GeneralFindQuery query = new GeneralFindQuery(Triple.ANY, inventory, limit, 
			new ExecutionContext(mapping.getContext(), null, null, null));
	Iterator<Triple> it = TripleQueryIter.create(query.iterator());
	while (it.hasNext()) {
		result.getGraph().add(it.next());
	}
	return result;
}
 
Example 4
Source File: ResourceCollection.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public Model getInventoryModel(int limit) {
	log.info("Listing entity set: " + entityMaker);
	Model result = ModelFactory.createDefaultModel();
	result.setNsPrefixes(mapping.getPrefixes());
	FindQuery query = new FindQuery(Triple.ANY, inventory, limit, 
			new ExecutionContext(mapping.getContext(), null, null, null));
	Iterator<Triple> it = TripleQueryIter.create(query.iterator());
	while (it.hasNext()) {
		result.getGraph().add(it.next());
	}
	return result;
}
 
Example 5
Source File: ResourceDescriptionServlet.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws IOException, ServletException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	String relativeResourceURI = request.getRequestURI().substring(
			request.getContextPath().length()
					+ request.getServletPath().length());
	// Some servlet containers keep the leading slash, some don't
	if (!"".equals(relativeResourceURI)
			&& "/".equals(relativeResourceURI.substring(0, 1))) {
		relativeResourceURI = relativeResourceURI.substring(1);
	}
	if (request.getQueryString() != null) {
		relativeResourceURI = relativeResourceURI + "?"
				+ request.getQueryString();
	}

	/* Determine service stem, i.e. vocab/ in /[vocab/]data */
	int servicePos;
	if (-1 == (servicePos = request.getServletPath().indexOf(
			"/" + D2RServer.getDataServiceName())))
		throw new ServletException("Expected to find service path /"
				+ D2RServer.getDataServiceName());
	String serviceStem = request.getServletPath().substring(1,
			servicePos + 1);

	String resourceURI = RequestParamHandler
			.removeOutputRequestParam(server.resourceBaseURI(serviceStem)
					+ relativeResourceURI);
	String documentURL = server.dataURL(serviceStem, relativeResourceURI);

	String pageURL = server.pageURL(serviceStem, relativeResourceURI);

	String sparqlQuery = "DESCRIBE <" + resourceURI + ">";
	QueryExecution qe = QueryExecutionFactory.create(sparqlQuery,
			server.dataset());
	if (server.getConfig().getPageTimeout() > 0) {
		qe.setTimeout(Math.round(server.getConfig().getPageTimeout() * 1000));
	}
	Model description = qe.execDescribe();
	qe.close();
	
	if (description.size() == 0) {
		response.sendError(404);
	}
	if (description.qnameFor(FOAF.primaryTopic.getURI()) == null
			&& description.getNsPrefixURI("foaf") == null) {
		description.setNsPrefix("foaf", FOAF.NS);
	}
	Resource resource = description.getResource(resourceURI);

	Resource document = description.getResource(documentURL);
	document.addProperty(FOAF.primaryTopic, resource);

	Statement label = resource.getProperty(RDFS.label);
	if (label != null) {
		document.addProperty(RDFS.label,
				"RDF Description of " + label.getString());
	}
	server.addDocumentMetadata(description, document);
	if (server.getConfig().serveMetadata()) {
		// add document metadata from template
		Model resourceMetadataTemplate = server.getConfig().getResourceMetadataTemplate(
				server, getServletContext());
		MetadataCreator resourceMetadataCreator = new MetadataCreator(
				server, resourceMetadataTemplate);
		description.add(resourceMetadataCreator.addMetadataFromTemplate(
				resourceURI, documentURL, pageURL));
		
		Map<String, String> descPrefixes = description.getNsPrefixMap();
		descPrefixes.putAll(resourceMetadataTemplate.getNsPrefixMap());
		description.setNsPrefixes(descPrefixes);
	}
	// TODO: Add a Content-Location header
	new ModelResponse(description, request, response).serve();
}