protected InputStream getInputStream(String resource) { InputStream resourceInputStream = resources.getResourceAsStream(resource); if (resourceInputStream == null) { throw new RuntimeException("View resource not found: " + resource); } return resourceInputStream; } }
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); } }
/** * 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(); } }
@Override public InputStream provide() { Resources resources = AppBeans.get(Resources.NAME); return resources.getResourceAsStream(resourcePath); } }
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 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(); }
public void loadThemeProperties(String fileName, Map<String, String> themeMap) { try (InputStream propertiesStream = resources.getResourceAsStream(fileName)) { if (propertiesStream == null) { throw new DevelopmentException(String.format("Unable to load theme constants for: '%s'", fileName)); } Properties properties = new Properties(); try (InputStreamReader propertiesReader = new InputStreamReader(propertiesStream, StandardCharsets.UTF_8)) { properties.load(propertiesReader); } catch (IOException e) { throw new DevelopmentException(String.format("Unable to parse theme constants for: '%s'", fileName)); } String includeValue = properties.getProperty("@include"); if (includeValue != null) { String[] themeIncludes = StringUtils.split(includeValue, " ,"); for (String include : themeIncludes) { loadThemeProperties(include, themeMap); } } for (Map.Entry<Object, Object> entry : properties.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (key != null && !"@include".equals(key) && value != null) { themeMap.put(key.toString(), value.toString()); } } } catch (IOException e) { throw new RuntimeException(String.format("Unable to read theme properties from '%s'", fileName)); } }
stream = resources.getResourceAsStream(fileName); if (stream == null) { throw new IllegalStateException("Resource is not found: " + fileName);
@Override protected void createResource() { String name = StringUtils.isNotEmpty(fileName) ? fileName : FilenameUtils.getName(path); resource = new StreamResource(() -> AppBeans.get(Resources.class).getResourceAsStream(path), name); StreamResource streamResource = (StreamResource) this.resource; streamResource.setMIMEType(mimeType); streamResource.setCacheTime(cacheTime); streamResource.setBufferSize(bufferSize); }
String ancestorTemplate = root.attributeValue("extends"); if (!StringUtils.isBlank(ancestorTemplate)) { InputStream ancestorStream = resources.getResourceAsStream(ancestorTemplate); if (ancestorStream == null) { ancestorStream = getClass().getResourceAsStream(ancestorTemplate);
if (StringUtils.isNoneEmpty(windowInfo.getTemplate())) { try { InputStream resource = resources.getResourceAsStream(windowInfo.getTemplate()); if (resource != null) { Document document = documentBuilder.parse(resource);