use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.
the class ReferencedSiteRootResource method getLicenseInfo.
@GET
@Path(value = ReferencedSiteRootResource.LICENSE_PATH + "/{name}")
public Response getLicenseInfo(@PathParam(value = "site") String siteId, @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam(value = "name") String name) {
Site site = getSite(siteId);
MediaType acceptedMediaType = getAcceptableMediaType(headers, MediaType.APPLICATION_JSON_TYPE);
if (name == null || name.isEmpty()) {
// return all
} else if (name.startsWith(LICENSE_NAME)) {
try {
String numberString = name.substring(LICENSE_NAME.length());
if (numberString.isEmpty()) {
numberString = "0";
}
// license0 is the first one
int count = -1;
if (site.getConfiguration().getLicenses() != null) {
for (License license : site.getConfiguration().getLicenses()) {
if (license.getUrl() == null) {
count++;
}
if (Integer.toString(count).equals(numberString)) {
ResponseBuilder rb = Response.ok(license2Representation(uriInfo.getAbsolutePath().toString(), license));
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
}
} catch (NumberFormatException e) {
return Response.status(Status.NOT_FOUND).entity("No License found.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
return Response.status(Response.Status.NOT_FOUND).build();
}
use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.
the class ReferencedSiteRootResource method site2Representation.
/*
* Referenced Site Metadata
*/
/**
* Transforms a site to a Representation that can be serialised
* @param context
* @return
*/
private Representation site2Representation(Site site, String id) {
RdfValueFactory valueFactory = RdfValueFactory.getInstance();
RdfRepresentation rep = valueFactory.createRepresentation(id);
String namespace = NamespaceEnum.entityhub.getNamespace();
rep.add(namespace + "localMode", site.supportsLocalMode());
rep.add(namespace + "supportsSearch", site.supportsSearch());
SiteConfiguration config = site.getConfiguration();
rep.add("http://www.w3.org/2000/01/rdf-schema#label", config.getName());
rep.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", valueFactory.createReference(namespace + "ReferencedSite"));
if (config.getDescription() != null) {
rep.add("http://www.w3.org/2000/01/rdf-schema#description", config.getDescription());
}
if (config.getAttribution() != null) {
rep.add("http://creativecommons.org/ns#attributionName", config.getAttribution());
}
if (config.getAttributionUrl() != null) {
rep.add("http://creativecommons.org/ns#attributionURL", config.getAttributionUrl());
}
// add the licenses
if (config.getLicenses() != null) {
int count = 0;
for (License license : config.getLicenses()) {
String licenseUrl;
if (license.getUrl() != null) {
licenseUrl = license.getUrl();
} else {
licenseUrl = id + (!id.endsWith("/") ? "/" : "") + LICENSE_PATH + '/' + LICENSE_NAME + (count > 0 ? count : "");
count++;
}
// if defined add the name to dc:license
if (license.getName() != null) {
rep.add("http://purl.org/dc/terms/license", licenseUrl);
}
// link to the license via cc:license
rep.add("http://creativecommons.org/ns#license", licenseUrl);
}
}
if (config.getEntityPrefixes() != null) {
for (String prefix : config.getEntityPrefixes()) {
rep.add(namespace + "entityPrefix", prefix);
}
} else {
// all entities are allowed/processed
rep.add(namespace + "entityPrefix", "*");
}
if (config instanceof ReferencedSiteConfiguration) {
ReferencedSiteConfiguration refConfig = (ReferencedSiteConfiguration) config;
if (refConfig.getCacheStrategy() != null) {
rep.add(namespace + "cacheStrategy", valueFactory.createReference(namespace + "cacheStrategy-" + refConfig.getCacheStrategy().name()));
}
// add the accessUri and queryUri
if (refConfig.getAccessUri() != null) {
rep.add(namespace + "accessUri", valueFactory.createReference(refConfig.getAccessUri()));
}
if (refConfig.getQueryUri() != null) {
rep.add(namespace + "queryUri", valueFactory.createReference(refConfig.getQueryUri()));
}
}
return rep;
}
use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.
the class SiteConfigurationImpl method getLicenses.
@Override
public final License[] getLicenses() {
// get Licenses based on related keys
int elements = 0;
String[] names = getLicenseName();
if (names == null) {
names = new String[] {};
} else {
elements = Math.max(elements, names.length);
}
String[] texts = getLicenseText();
if (texts == null) {
texts = new String[] {};
} else {
elements = Math.max(elements, texts.length);
}
String[] urls = getLicenseUrl();
if (urls == null) {
urls = new String[] {};
} else {
elements = Math.max(elements, urls.length);
}
Collection<License> licenseList = new ArrayList<License>();
for (int i = 0; i < elements; i++) {
try {
licenseList.add(new License(names.length > i ? names[i] : null, urls.length > i ? urls[i] : null, texts.length > i ? texts[i] : null));
} catch (IllegalArgumentException e) {
// ignore if name, text and url == null and/or empty
}
}
return licenseList.isEmpty() ? new License[] {} : licenseList.toArray(new License[licenseList.size()]);
}
Aggregations