private Extractor getExtractor(ServletContext context, String id) { CompareRegistry registry = (CompareRegistry) context.getAttribute(CompareRegistry.class.getName()); Collection<Extractor> Extractors = registry.getAvailableExtractors(); Extractor extractor = null; for (Extractor e : Extractors) { if (e.getClass().getName().equals(id)) { extractor = e; } } return extractor; }
@GET @Path("/{id}") @Produces("application/json") public Map<String, Object> getExtractorJSON( @PathParam("id") String id, @Context ServletContext context) { log.trace("/extractors/" + id + " requested"); Extractor extractor = getExtractor(context, id); Map<String, Object> json = new HashMap<String, Object>(); if (extractor != null) { json.put("name", extractor.getName()); json.put("id", extractor.getClass().getName()); json.put("supportedFeature", extractor.getFeatureType().getName()); } else { json.put("Error", "Extractor not found"); } return json; }
@GET @Path("/") @Produces("application/json") public List<Map<String, Object>> listJSON(@Context ServletContext context) { log.trace("/extractors requested"); Collection<Extractor> extractors = getExtractors(context); List<Map<String, Object>> jsonReturn = new ArrayList<Map<String, Object>>(); if (extractors.size() == 0) { return jsonReturn; } else { for (Extractor extractor : extractors) { Map<String, Object> json = new HashMap<String, Object>(); json.put("name", extractor.getName()); json.put("id", extractor.getClass().toString()); json.put("supportedFeature", extractor.getFeatureType().getName()); jsonReturn.add(json); } return jsonReturn; } }
@GET @Path("/") @Produces("text/html") public String listHTML(@Context ServletContext context) { log.trace("/extractors requested"); Collection<Extractor> extractors = getExtractors(context); if (extractors.size() == 0) { return "No Extractors"; } else { String content = new String("<h3>Versus > Extractors</h3><ul>"); for (Extractor extractor : extractors) { content += "<li><a href='extractors/" + extractor.getClass().getName() + "'>" + extractor.getClass().getName() + "</a></li>"; } content += "</ul>"; return content; } }