Search in sources :

Example 1 with ReferencedSiteConfiguration

use of org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration 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;
}
Also used : ReferencedSiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) License(org.apache.stanbol.entityhub.servicesapi.site.License) SiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration) ReferencedSiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)

Aggregations

RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)1 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)1 License (org.apache.stanbol.entityhub.servicesapi.site.License)1 ReferencedSiteConfiguration (org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration)1 SiteConfiguration (org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration)1