当前位置: 首页>>代码示例>>Java>>正文


Java JSON类代码示例

本文整理汇总了Java中org.apache.jena.atlas.json.JSON的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JSON类属于org.apache.jena.atlas.json包,在下文中一共展示了JSON类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConcept

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
/**
 * Return the concept with the supplied URI with pref label, uri and type fields populated
 * @param conceptUri - the concept to be returned
 * @return - the requested concept 
 * @throws OEClientException - an error has occurred contacting the server
 */
public Concept getConcept(String conceptUri) throws OEClientException {
	logger.info("getConcept entry: {}", conceptUri);

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", basicProperties);
	queryParameters.put("path", getPathParameter(conceptUri));
	Invocation.Builder invocationBuilder = getInvocationBuilder(getApiURL(), queryParameters);

	Date startDate = new Date();
	logger.info("getConcept making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getConcept call complete: {}", startDate.getTime());

	logger.info("getConceptDetails - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isDebugEnabled()) logger.debug("getConceptDetails: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:30,代码来源:OEClientReadOnly.java

示例2: getConceptByIdentifier

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
/**
 * Return the concept with the supplied identifier
 * @param identifier - the unique identifier for the concept (not the URI)
 * @return - the requested concept
 * @throws OEClientException - an error has occurred contacting the server
 */
public Concept getConceptByIdentifier(Identifier identifier) throws OEClientException {
	logger.info("getConceptByIdentifier entry: {}", identifier);

	String url = getModelURL() + "/skos:Concept/meta:transitiveInstance";

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", basicProperties);
	queryParameters.put("filters", String.format("subject(exists %s \"%s\")", getWrappedUri(identifier.getUri()), identifier.getValue()));
	Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);

	Date startDate = new Date();
	logger.info("getConceptByIdentifier making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getConceptByIdentifier call complete: {}", startDate.getTime());

	logger.info("getConceptByIdentifier - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isDebugEnabled()) logger.debug("getConceptByIdentifier: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:32,代码来源:OEClientReadOnly.java

示例3: populateRelatedConceptUris

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
public void populateRelatedConceptUris(String relationshipUri, Concept concept) throws OEClientException {
	logger.info("populateNarrowerConceptURIs entry: {}", concept.getUri());

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", getWrappedUri(relationshipUri));
	Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);

	Date startDate = new Date();
	logger.info("populateNarrowerConceptURIs making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("populateNarrowerConceptURIs call complete: {}", startDate.getTime());

	logger.info("populateNarrowerConceptURIs - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isDebugEnabled()) logger.debug("populateNarrowerConceptURIs: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		concept.populateRelatedConceptUris(relationshipUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:23,代码来源:OEClientReadOnly.java

示例4: populateMetadata

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
public void populateMetadata(String metadataUri, Concept concept) throws OEClientException {
	logger.info("populateMetadata entry: {}", concept.getUri());

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", getWrappedUri(metadataUri));
	Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);

	Date startDate = new Date();
	logger.info("populateMetadata making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("populateMetadata call complete: {}", startDate.getTime());

	logger.info("populateMetadata - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isDebugEnabled()) logger.debug("populateNarrowerConceptURIs: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		concept.populateMetadata(metadataUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:23,代码来源:OEClientReadOnly.java

示例5: json

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
public static void json(HttpServletRequest req, HttpServletResponse resp, JsonValue responseContent) {
    try { 
        resp.setHeader(HttpNames.hCacheControl, "no-cache");
        resp.setHeader(HttpNames.hContentType,  WebContent.contentTypeJSON);
        resp.setStatus(HttpSC.OK_200);
        try(ServletOutputStream out = resp.getOutputStream(); IndentedWriter b = new IndentedWriter(out); ) {
            b.setFlatMode(true);
            JSON.write(b, responseContent);
            b.ensureStartOfLine();
            b.flush();
            out.write('\n');
        }
    } catch (IOException ex) {
        LOG.warn("json: IOException", ex);
        try { 
            resp.sendError(HttpSC.INTERNAL_SERVER_ERROR_500, "Internal server error");
        } catch (IOException ex2) {}
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:20,代码来源:S_JSON.java

示例6: getFieldAsObject

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
private static JsonObject getFieldAsObject(JsonObject arg, String field) {
    try {
        if ( ! arg.hasKey(field) ) {
            LOG.warn("Bad request: Missing Field: "+field+" Arg: "+JSON.toStringFlat(arg)) ;
            throw new DeltaBadRequestException("Missing field: "+field) ;
        }
        JsonValue jv = arg.get(field) ;
        if ( ! jv.isObject() ) {
            
        }
        return jv.getAsObject();
    } catch (JsonException ex) {
        LOG.warn("Bad request: Field: "+field+" Arg: "+JSON.toStringFlat(arg)) ;
        throw new DeltaBadRequestException("Bad field '"+field+"' : "+arg.get(field)) ;
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:17,代码来源:S_DRPC.java

示例7: run

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
@Override
public void run(Model results) throws Exception {
	Resource testCase = getResource();
	String queryString = JenaUtil.getStringProperty(testCase, SH.select);
	Model model = testCase.getModel();
	JsonObject expectedJSON = JSON.parse(JenaUtil.getStringProperty(testCase, DASH.expectedResult));
	
	for(TestCaseContextFactory contextFactory : contextFactories) {
		TestCaseContext context = contextFactory.createContext();
		context.setUpTestContext();
		try {
			String actual = createResultSetJSON(queryString, model);
			JsonObject actualJSON = JSON.parse(actual);
			if(!actualJSON.equals(expectedJSON)) {
				createFailure(results, "Mismatching result set. Actual: " + actual, context);
				return;
			}
		}
		finally {
			context.tearDownTestContext();
		}
	}
	createResult(results, DASH.SuccessTestCaseResult);
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:25,代码来源:QueryTestCaseType.java

示例8: getAllModels

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
public Collection<Model> getAllModels() throws OEClientException {
	logger.info("getAllModels entry");
	
	String url = getApiURL() + "/sys/sys:Model/rdf:instance";
	logger.info("getAllModels URL: {}", url);
	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", "meta:displayName,meta:graphUri");

	Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);

	Date startDate = new Date();
	logger.info("getAllModels making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getAllModels call complete: {}", startDate.getTime());

	logger.info("getAllModels - status: {}", response.getStatus());

	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isInfoEnabled()) logger.info("getAllModels: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
		Collection<Model> models = new ArrayList<Model>();
		Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
		while (jsonValueIterator.hasNext()) {
			JsonObject modelObject = jsonValueIterator.next().getAsObject();
			models.add(new Model(modelObject));
		}
		return models;
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:34,代码来源:OEClientReadOnly.java

示例9: getRelationshipTypes

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
private Collection<RelationshipType> getRelationshipTypes(String parentType) throws OEClientException {
	logger.info("getRelationshipTypes entry: {}", parentType);

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", "rdfs:label,owl:inverseOf,rdfs:subPropertyOf,owl:inverseOf/rdfs:label,owl:inverseOf/rdfs:subPropertyOf");
	Invocation.Builder invocationBuilder = getInvocationBuilder(getModelURL() + "/" + parentType +"/meta:transitiveSubProperty", queryParameters);

	Date startDate = new Date();
	logger.info("getRelationshipTypes making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getRelationshipTypes call complete: {}", startDate.getTime());

	logger.info("getRelationshipTypes - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isInfoEnabled()) logger.info("getConceptClasses: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
		Collection<RelationshipType> relationshipTypes = new HashSet<RelationshipType>();
		Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
		while (jsonValueIterator.hasNext()) {
			relationshipTypes.add(new RelationshipType(this, jsonValueIterator.next().getAsObject()));
		}
		return relationshipTypes;
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:29,代码来源:OEClientReadOnly.java

示例10: getConceptClasses

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
/**
 * Return all concept classes
 * @return - a collection containing all concept classes
 * @throws OEClientException - an error has occurred contacting the server
 */
public Collection<ConceptClass> getConceptClasses(int limit) throws OEClientException {
	logger.info("getConceptClasses entry");

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", "rdfs:label,rdfs:subClassOf");
	queryParameters.put("limit", Integer.toString(limit));
	Invocation.Builder invocationBuilder = getInvocationBuilder(getModelURL() + "/skos:Concept/meta:transitiveSubClass", queryParameters);

	Date startDate = new Date();
	logger.info("getConceptClasses making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getConceptClasses call complete: {}", startDate.getTime());

	logger.info("getConceptClasses - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isInfoEnabled()) logger.info("getConceptClasses: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
		Collection<ConceptClass> conceptClasses = new HashSet<ConceptClass>();
		Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
		while (jsonValueIterator.hasNext()) {
			conceptClasses.add(new ConceptClass(this, jsonValueIterator.next().getAsObject()));
		}
		return conceptClasses;
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:35,代码来源:OEClientReadOnly.java

示例11: testVocabularyManagement

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
@Test
public void testVocabularyManagement() throws Exception {
	RESTResource resource;
	String ontoId;

	Map<String,String> parameters = new HashMap<String,String>();
	
	// POST vocabulary
	String ontoUri = "http://purl.oclc.org/NET/ssnx/qu/qu-rec20";
	InputStream uriStream = new ByteArrayInputStream(ontoUri.getBytes("UTF-8"));
	resource = vch.post(new URI(baseUri + "/vocab"), parameters, uriStream);
	ontoId = resource.path;

	Assert.assertTrue("QU ontology not registered", VocabularyUtils.containsVocabulary(ontoUri));
	
	// GET vocabulary by SPARQL query
	parameters.clear();
	parameters.put("query", "?s ?p ?o");
	resource = vch.get(new URI(baseUri + "/vocab"), parameters);
	
	JsonValue ontoIds = JSON.parseAny(resource.content);
	Assert.assertTrue("Vocabulary collection is not an array", ontoIds.isArray());
	Assert.assertTrue("Vocabulary imports were not added", ontoIds.getAsArray().size() > 1);
	Assert.assertTrue("QU ontology not found", ontoIds.getAsArray().contains(new JsonString(ontoId)));
	
	// GET vocabulary by id
	VocabularyHandler vh = new VocabularyHandler(ontoId, ThingDirectory.servers);
	resource = vh.get(new URI(baseUri + ontoId), null);
	
	ByteArrayInputStream byteStream = new ByteArrayInputStream(resource.content.getBytes());
	Model m = ModelFactory.createDefaultModel();
	m.read(byteStream, "", "Turtle");
	Assert.assertFalse("QU ontology definition is not valid", m.isEmpty());

	// DELETE vocabulary
	vh.delete(new URI(baseUri + ontoId), null, null);
	Assert.assertFalse("QU ontology not deleted", VocabularyUtils.containsVocabulary(ontoUri));
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:39,代码来源:ThingWebRepoTest.java

示例12: handleMissingConfigFile

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
private static void handleMissingConfigFile(Path path) {
    //throw new DeltaConfigException("No such file: "+path.toString());
    JsonObject obj = JSONX.buildObject(b->{
        b.key(F_VERSION).value(DeltaConst.SYSTEM_VERSION);
        // Default log provider
        b.key(F_LOG_TYPE).value(DeltaConst.LOG_FILE);
    });
    try ( IndentedWriter out = new IndentedWriter(Files.newOutputStream(path)); ) {
        JSON.write(out, obj);
        out.ensureStartOfLine();
    } catch (IOException ex) { IO.exception(ex); }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:13,代码来源:LocalServerConfig.java

示例13: makeDataSource

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
/**
 * Create a {@link DataSource} by reading the "source.cfg" file"
 * @param dataSourceArea The directory where the DataSources details are stored.
 * @return DataSource
 */
public static DataSource makeDataSource(Path dataSourceArea) {
    JsonObject sourceObj = JSON.read(dataSourceArea.resolve(DeltaConst.DS_CONFIG).toString());
    DataSourceDescription dsd = DataSourceDescription.fromJson(sourceObj);
    Id id = dsd.getId();
    String baseStr = dsd.getName();
    String uriStr = dsd.getUri(); 
    DataSource dataSource = DataSource.connect(id, uriStr, baseStr, dataSourceArea);
    return dataSource ;
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:15,代码来源:Cfg.java

示例14: synchronized

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
private Id createDataSource$(PatchStore patchStore, DataSourceDescription dsd) {
    synchronized(lock) {
        Path sourcePath = null;
        if ( ! patchStore.isEphemeral() ) {
            Location sourceArea = dataSourceArea(serverRoot, dsd.getName());
            sourcePath = IOX.asPath(sourceArea);

            // Checking.
            // The area can exist, but it must not be formatted for a DataSource 
            //        if ( sourceArea.exists() )
            //            throw new DeltaException("Area already exists");

            if ( Cfg.isMinimalDataSource(LOG, sourcePath) )
                throw new DeltaBadRequestException("DataSource area already exists at: "+sourceArea);
            if ( ! Cfg.isEnabled(sourcePath) )
                throw new DeltaBadRequestException("DataSource area disabled: "+sourceArea);

            String patchesDirName = sourceArea.getPath(DeltaConst.LOG);
            if ( FileOps.exists(patchesDirName) )
                throw new DeltaBadRequestException("DataSource area does not have a configuration but does have a patches area.");

            String dataDirName = sourceArea.getPath(DeltaConst.DATA);
            if ( FileOps.exists(dataDirName) )
                throw new DeltaBadRequestException("DataSource area has a likely looking database already");

            // Create source.cfg.
            JsonObject obj = dsd.asJson();
            LOG.info(JSON.toStringFlat(obj));
            try (OutputStream out = Files.newOutputStream(sourcePath.resolve(DeltaConst.DS_CONFIG))) {
                JSON.write(out, obj);
            } catch (IOException ex)  { throw IOX.exception(ex); }
        }
        // XXX Pass in dsd
        DataSource newDataSource = DataSource.connect(dsd.getId(), dsd.getUri(), dsd.getName(), sourcePath);
        dataRegistry.put(dsd.getId(), newDataSource);
        return dsd.getId() ;
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:39,代码来源:LocalServer.java

示例15: getFieldAsString

import org.apache.jena.atlas.json.JSON; //导入依赖的package包/类
private static String getFieldAsString(JsonObject arg, String field, boolean required) {
    try {
        if ( ! arg.hasKey(field) ) {
            if ( required ) {
                LOG.warn("Bad request: Missing Field: "+field+" Arg: "+JSON.toStringFlat(arg)) ;
                throw new DeltaBadRequestException("Missing field: "+field) ;
            }
            return null;
        }
        return arg.get(field).getAsString().value() ;
    } catch (JsonException ex) {
        LOG.warn("Bad request: Field not a string: "+field+" Arg: "+JSON.toStringFlat(arg)) ;
        throw new DeltaBadRequestException("Bad field '"+field+"' : "+arg.get(field)) ;
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:16,代码来源:S_DRPC.java


注:本文中的org.apache.jena.atlas.json.JSON类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。