@Override public String getResourceAsString(String name) { return resources.getResourceAsString(name); } }
protected InputStream getInputStream(String resource) { InputStream resourceInputStream = resources.getResourceAsStream(resource); if (resourceInputStream == null) { throw new RuntimeException("View resource not found: " + resource); } return resourceInputStream; } }
protected void _registerAppComponents() { String configNames = AppContext.getProperty(WEB_COMPONENTS_CONFIG_XML_PROP); if (Strings.isNullOrEmpty(configNames)) { return; } log.debug("Loading UI components from {}", configNames); StringTokenizer tokenizer = new StringTokenizer(configNames); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); _registerComponent(stream); } catch (ClassNotFoundException | IOException e) { throw new RuntimeException("Unable to load components config " + location, e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource {} not found, ignore it", location); } } }
protected void loadScreensXml() { String configName = AppContext.getProperty(WINDOW_CONFIG_XML_PROP); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { try (InputStream stream = resource.getInputStream()) { loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException("Unable to read window config from " + location, e); } } else { log.warn("Resource {} not found, ignore it", location); } } }
@RequestMapping(value = "/swagger.yaml", method = RequestMethod.GET, produces = "application/yaml") public String getSwaggerYaml() { return resources.getResourceAsString("classpath:rest-api-swagger.yaml"); }
@Override public InputStream provide() { Resources resources = AppBeans.get(Resources.NAME); return resources.getResourceAsStream(resourcePath); } }
protected void init() { String configName = AppContext.getProperty(CUBA_REST_QUERIES_CONFIG_PROP_NAME); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource {} not found, ignore it", location); } } }
@RequestMapping(value = "/swagger.yaml", method = RequestMethod.GET, produces = "application/yaml") public String getSwaggerYaml() { return resources.getResourceAsString("classpath:com/haulmont/reports/rest-api-swagger.yaml"); }
protected String loadTemplate(String resourcePath) { try (InputStream stream = resources.getResourceAsStream(resourcePath)) { if (stream == null) { throw new DevelopmentException("Template is not found " + resourcePath, "Path", resourcePath); } return IOUtils.toString(stream, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Unable to read screen template"); } }
protected void init() { String configName = AppContext.getProperty(CUBA_REST_SERVICES_CONFIG_PROP_NAME); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException("Error on parsing rest services config", e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource " + location + " not found, ignore it"); } } }
@Nonnull protected String getScript(String filename) throws FileNotFoundException { // resources.getResource().getFile() can't return file from jar String script = resources.getResourceAsString("classpath:" + scriptsFolder + filename); if (script == null) { throw new FileNotFoundException(format("Script %s is not found", filename)); } return script; }
protected Element readXml(String path) { try (InputStream stream = resources.getResourceAsStream(path)) { if (stream == null) { throw new IllegalStateException("Resource not found: " + path); } Document document = Dom4j.readDocument(stream); return document.getRootElement(); } catch (IOException e) { throw new IllegalStateException("Unable to read resource: " + path); } }
protected void init() { rootItems.clear(); String configName = AppContext.getProperty(MENU_CONFIG_XML_PROP); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); Element rootElement = Dom4j.readDocument(stream).getRootElement(); loadMenuItems(rootElement, null); } catch (IOException e) { throw new RuntimeException("Unable to read menu config", e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource {} not found, ignore it", location); } } }
@Nullable protected String getLocalizedTemplateContent(Resources resources, String defaultTemplateName, String locale) { String localizedTemplate = FilenameUtils.getFullPath(defaultTemplateName) + FilenameUtils.getBaseName(defaultTemplateName) + "_" + locale + "." + FilenameUtils.getExtension(defaultTemplateName); return resources.getResourceAsString(localizedTemplate); }
/** * copy/paste from {@link com.haulmont.cuba.core.sys.MetadataBuildSupport#readXml(String)} */ protected Element readXml(String path) throws IOException { try (InputStream stream = resources.getResourceAsStream(path)) { if (stream == null) { throw new FileNotFoundException("File not found by path: " + path); } Document document = Dom4j.readDocument(stream); return document.getRootElement(); } }
protected void init() { String configName = AppContext.getProperty(CUBA_REST_JSON_TRANSFORMATION_CONFIG_PROP_NAME); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource " + location + " not found, ignore it"); } } }
protected Template loadDefaultTemplate(String templatePath, SimpleTemplateEngine templateEngine) { String defaultTemplateContent = resources.getResourceAsString(templatePath); if (defaultTemplateContent == null) { throw new IllegalStateException("Not found default email template for reset passwords operation"); } //noinspection UnnecessaryLocalVariable Template template = getTemplate(templateEngine, defaultTemplateContent); return template; }
protected void redirectWithBlankHtmlPage(HttpServletRequest request, HttpServletResponse response) throws IOException { BufferedWriter page = new BufferedWriter(new OutputStreamWriter( response.getOutputStream(), StandardCharsets.UTF_8)); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(request.getRequestURI()); stringBuilder.append("?"); stringBuilder.append(FROM_HTML_REDIRECT_PARAM); stringBuilder.append("=true"); Map<String, String[]> parameterMap = request.getParameterMap(); for (Map.Entry<String, String[]> paramEntry : parameterMap.entrySet()) { String[] paramValue = paramEntry.getValue(); for (String paramPart : paramValue) { stringBuilder.append("&"); stringBuilder.append(paramEntry.getKey()); stringBuilder.append("="); stringBuilder.append(paramPart); } } String url = stringBuilder.toString(); InputStream redirectPageStream = resources.getResourceAsStream(REDIRECT_PAGE_TEMPLATE_PATH); if (redirectPageStream == null) { throw new IllegalStateException("Unable to get redirect page template: " + REDIRECT_PAGE_TEMPLATE_PATH); } page.write(String.format(IOUtils.toString(redirectPageStream, StandardCharsets.UTF_8.name()), url, url)); page.close(); }
protected void init() { String configName = AppContext.getProperty(CUBA_REST_SERVICES_CONFIG_PROP_NAME); StringTokenizer tokenizer = new StringTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); loadConfig(Dom4j.readDocument(stream).getRootElement()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } else { log.warn("Resource " + location + " not found, ignore it"); } } }
private String getLocalizedTemplateContent(String defaultTemplateName, String locale) { String localizedTemplate = FilenameUtils.getFullPath(defaultTemplateName) + FilenameUtils.getBaseName(defaultTemplateName) + "_" + locale + "." + FilenameUtils.getExtension(defaultTemplateName); return resources.getResourceAsString(localizedTemplate); }