public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; } }
public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; } }
public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; }
public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; }
final FacesContext context = FacesContext.getCurrentInstance(); ClassicEngineBoot.getInstance().start(); try { // load report definition ResourceManager manager = new ResourceManager(); manager.registerDefaults(); ExternalContext extContext = context.getExternalContext(); String reportPath = "file:" + extContext.getRealPath("name/name.prpt"); Resource res = manager.createDirectly(new URL(reportPath), MasterReport.class); MasterReport report = (MasterReport) res.getResource(); ................ ................ httpServletResponse.setContentType("application/rtf"); httpServletResponse.setHeader("Content-Disposition", "attachment; filename=\"name.rtf\""); RTFReportUtil.createRTF(report, httpServletResponse.getOutputStream()); FacesContext.getCurrentInstance().responseComplete(); } catch (ReportProcessingException ex) {
@Test public void assertNoRedundantUriParametersForResource() { processResource("RestDocEndpoint.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/mount/api/v1/widgets/{id1}/gizmos"); AssertJUnit.assertNotNull("Resource /mount/api/v1/widgets/{id1}/gizmos not found", resource); resource = resource.getResource("/{id2}"); AssertJUnit.assertNotNull("Resource /mount/api/v1/widgets/{id1}/gizmos/{id2} not found", resource); }
@Test public void assertUriParameterNormalization() { processResource("UriParameterNormalization.java", "raml", "all"); Raml raml = new RamlDocumentBuilder().build(defaultApiOutput, "http://example.com"); AssertJUnit.assertNotNull("RAML not parseable", raml); Resource resource = raml.getResource("/widgets/{id}"); AssertJUnit.assertNotNull("Resource /widgets/{id} not found", resource); UriParameter id = resource.getUriParameters().get("id"); AssertJUnit.assertNotNull("Resource /widgets/{id} has no id URI parameter", id); // Flakey test depends on order of resource processing // AssertJUnit.assertEquals("Resource /widgets/{id} id URI parameter description is wrong", // "The widget identifier documented in POST.", id.getDescription().trim()); resource = resource.getResource("/gadgets"); AssertJUnit.assertNotNull("Resource /widgets/{id}/gadgets not found", resource); id = resource.getUriParameters().get("id"); AssertJUnit.assertNull("Resource /widgets/{id}/gadgets has it's own id URI parameter when it should not", id); }