@Test void versionIsReturned() throws Exception { JSONObject response = (JSONObject)resource.getRedPens("").getEntity(); assertEquals(RedPen.VERSION, response.getString("version")); }
@Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); }
RedPenConfigurationResource { @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); } }
RedPenConfigurationResource { @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); }  }
RedPenConfigurationResource { @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); }  @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang); @Path("/export") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_XML) @WinkAPIDescriber.Description("Returns the configuration XML corresponds to the UI") Response exportConfiguration(JSONObject requestJSON); }
RedPenConfigurationResource { @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); }  @Path("/redpens") @GET @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang); @Path("/export") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_XML) @WinkAPIDescriber.Description("Returns the configuration XML corresponds to the UI") Response exportConfiguration(JSONObject requestJSON);  }