List of usage examples for org.apache.http.nio.entity NStringEntity NStringEntity
public NStringEntity(final String s, String charset) throws UnsupportedEncodingException
From source file:org.kitodo.data.index.elasticsearch.type.RulesetType.java
@SuppressWarnings("unchecked") @Override// ww w. j a v a 2 s .c o m public HttpEntity createDocument(Ruleset ruleset) { LinkedHashMap<String, String> orderedRulesetMap = new LinkedHashMap<>(); orderedRulesetMap.put("title", ruleset.getTitle()); orderedRulesetMap.put("file", ruleset.getFile()); orderedRulesetMap.put("fileContent", ""); JSONObject rulesetObject = new JSONObject(orderedRulesetMap); return new NStringEntity(rulesetObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.elasticsearch.index.type.HistoryType.java
@SuppressWarnings("unchecked") @Override// w w w . j a v a2s .c om public HttpEntity createDocument(History history) { JSONObject historyObject = new JSONObject(); historyObject.put("numericValue", history.getNumericValue()); historyObject.put("stringValue", history.getStringValue()); historyObject.put("type", history.getHistoryType().getValue()); String date = history.getDate() != null ? formatDate(history.getDate()) : null; historyObject.put("date", date); Integer process = history.getProcess() != null ? history.getProcess().getId() : null; historyObject.put("process", process); return new NStringEntity(historyObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:talkeeg.httpserver.TemplateEvaluator.java
HttpAsyncContentProducer evaluate(String templateId, Object arg) { StringBuilder sb = new StringBuilder(); sb.append("<html><body>"); sb.append("<pre>").append(arg).append("</pre>"); sb.append("</body></html>"); return new NStringEntity(sb.toString(), this.serverConfig.getCharset()); }
From source file:talkeeg.httpserver.ErrorHandler.java
void handle(HttpResponse response, Exception e) { // not in all states we can change status line! response.setStatusLine(response.getProtocolVersion(), HttpStatus.SC_INTERNAL_SERVER_ERROR, e.toString()); response.setEntity(new NStringEntity("<html><body>", config.getCharset())); }
From source file:org.kitodo.data.index.elasticsearch.type.HistoryType.java
@SuppressWarnings("unchecked") @Override/* ww w . j a va 2 s .c o m*/ public HttpEntity createDocument(History history) { LinkedHashMap<String, String> orderedHistoryMap = new LinkedHashMap<>(); orderedHistoryMap.put("numericValue", history.getNumericValue().toString()); orderedHistoryMap.put("stringValue", history.getStringValue()); orderedHistoryMap.put("type", history.getHistoryType().toString()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String date = history.getDate() != null ? dateFormat.format(history.getDate()) : null; orderedHistoryMap.put("date", date); orderedHistoryMap.put("process", history.getProcess().getId().toString()); JSONObject historyObject = new JSONObject(orderedHistoryMap); return new NStringEntity(historyObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.index.elasticsearch.type.UserGroupType.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a v a2s. c o m*/ public HttpEntity createDocument(UserGroup userGroup) { LinkedHashMap<String, String> orderedUserGroupMap = new LinkedHashMap<>(); orderedUserGroupMap.put("title", userGroup.getTitle()); orderedUserGroupMap.put("permission", userGroup.getPermission().toString()); JSONArray users = new JSONArray(); List<User> userGroupUsers = userGroup.getUsers(); for (User user : userGroupUsers) { JSONObject userObject = new JSONObject(); userObject.put("id", user.getId().toString()); users.add(userObject); } JSONObject userGroupObject = new JSONObject(orderedUserGroupMap); userGroupObject.put("users", users); return new NStringEntity(userGroupObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.elasticsearch.index.type.UserType.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2s.c o m*/ public HttpEntity createDocument(User user) { JSONObject userObject = new JSONObject(); userObject.put("name", user.getName()); userObject.put("surname", user.getSurname()); userObject.put("login", user.getLogin()); userObject.put("ldapLogin", user.getLdapLogin()); userObject.put("active", String.valueOf(user.isActive())); userObject.put("location", user.getLocation()); userObject.put("metadataLanguage", user.getMetadataLanguage()); userObject.put("userGroups", addObjectRelation(user.getUserGroups())); userObject.put("filters", addObjectRelation(user.getFilters())); userObject.put("projects", addObjectRelation(user.getProjects())); userObject.put("processingTasks", addObjectRelation(user.getProcessingTasks())); userObject.put("tasks", addObjectRelation(user.getTasks())); return new NStringEntity(userObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.hydracache.server.httpd.handler.UnsupportedHttpMethodHandler.java
@Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); NStringEntity body = new NStringEntity("<html><body><h1>Method not allowed</h1></body></html>", "UTF-8"); body.setContentType("text/html; UTF-8"); response.setEntity(body);//from w w w .ja v a 2 s . c o m }
From source file:org.kitodo.data.index.elasticsearch.type.BatchType.java
@SuppressWarnings("unchecked") @Override/*from www .j ava 2 s . c o m*/ public HttpEntity createDocument(Batch batch) { LinkedHashMap<String, String> orderedBatchMap = new LinkedHashMap<>(); orderedBatchMap.put("title", batch.getTitle()); String type = batch.getType() != null ? batch.getType().toString() : "null"; orderedBatchMap.put("type", type); JSONArray processes = new JSONArray(); List<Process> batchProcesses = batch.getProcesses(); for (Process process : batchProcesses) { JSONObject processObject = new JSONObject(); processObject.put("id", process.getId().toString()); processes.add(processObject); } JSONObject batchObject = new JSONObject(orderedBatchMap); batchObject.put("processes", processes); return new NStringEntity(batchObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.elasticsearch.index.type.PropertyType.java
@SuppressWarnings("unchecked") @Override/* ww w. j a v a 2 s. co m*/ public HttpEntity createDocument(Property property) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); String creationDate = property.getCreationDate() != null ? formatDate(property.getCreationDate()) : null; propertyObject.put("creationDate", creationDate); propertyObject.put("processes", addObjectRelation(property.getProcesses())); propertyObject.put("templates", addObjectRelation(property.getTemplates())); propertyObject.put("workpieces", addObjectRelation(property.getWorkpieces())); String type = null; if (!property.getProcesses().isEmpty()) { type = "process"; } else if (!property.getTemplates().isEmpty()) { type = "template"; } else if (!property.getWorkpieces().isEmpty()) { type = "workpiece"; } propertyObject.put("type", type); return new NStringEntity(propertyObject.toJSONString(), ContentType.APPLICATION_JSON); }