Example usage for org.springframework.core.io AbstractResource getInputStream

List of usage examples for org.springframework.core.io AbstractResource getInputStream

Introduction

In this page you can find the example usage for org.springframework.core.io AbstractResource getInputStream.

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream for the content of an underlying resource.

Usage

From source file:alfio.util.TemplateManager.java

private Template compile(AbstractResource resource, TemplateOutput templateOutput) {
    try (InputStreamReader tmpl = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
        return compilers.get(templateOutput).compile(tmpl);
    } catch (IOException ioe) {
        throw new IllegalStateException(ioe);
    }//from  ww w. j  ava2s.  c  om
}

From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java

protected String getTemplateText(String template) throws IOException {
    InputStream inputStream = null;
    if (resourceLoader != null && grailsApplication.isWarDeployed()) {
        inputStream = resourceLoader.getResource("/WEB-INF/templates/scaffolding/" + template).getInputStream();
    } else {/*from  w w w .j a  va2s  . c o m*/
        AbstractResource templateFile = getTemplateResource(template);
        if (templateFile.exists()) {
            inputStream = templateFile.getInputStream();
        }
    }

    return inputStream == null ? null : IOGroovyMethods.getText(inputStream);
}

From source file:org.esupportail.pay.web.admin.PayEvtController.java

@RequestMapping(value = "/{id}/logo")
public void getLogoFile(@PathVariable("id") Long id, HttpServletRequest request, HttpServletResponse response) {
    try {// w w w. j a  v a  2  s .com
        PayEvt evt = PayEvt.findPayEvt(id);
        if (evt.getLogoFile().getBinaryFile() != null) {
            IOUtils.copy(evt.getLogoFile().getBinaryFile().getBinaryStream(), response.getOutputStream());
        } else {
            AbstractResource defaultLogo = new ServletContextResource(servletContext, "images/credit-card.png");
            IOUtils.copy(defaultLogo.getInputStream(), response.getOutputStream());
        }
    } catch (Exception ioe) {
        log.warn("Get Logo of PayEvt " + id + " failed.", ioe);
    }
}

From source file:org.esupportail.pay.web.anonyme.PayController.java

@RequestMapping(value = "logo/{evtUrlId}")
public void getLogoFileEvt(@PathVariable("evtUrlId") String evtUrlId, HttpServletRequest request,
        HttpServletResponse response) {/*from  w  ww . j  av  a2s  .  c  o m*/
    try {
        List<PayEvt> evts = PayEvt.findPayEvtsByUrlIdEquals(evtUrlId).getResultList();
        if (evts.size() == 0) {
            throw new EntityNotFoundException();
        }
        PayEvt evt = evts.get(0);
        if (evt.getLogoFile().getBinaryFile() != null) {
            IOUtils.copy(evt.getLogoFile().getBinaryFile().getBinaryStream(), response.getOutputStream());
        } else {
            AbstractResource defaultLogo = new ServletContextResource(servletContext, "images/credit-card.png");
            IOUtils.copy(defaultLogo.getInputStream(), response.getOutputStream());
        }
    } catch (Exception ioe) {
        log.warn("Get Logo of PayEvt with urlId " + evtUrlId + " failed.", ioe);
    }
}

From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java

private void setRuleMaps() {
    setupConfigurationMaps();/* w  w  w  . j  av  a2 s .c om*/
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        AbstractResource resource = null;
        Document doc = null;
        if (StringUtils.startsWith(this.getConversionRuleFile(), "classpath")) {
            resource = new ClassPathResource(this.getConversionRuleFile(),
                    Thread.currentThread().getContextClassLoader());
        } else {
            resource = new FileSystemResource(this.getConversionRuleFile());
        }
        if (!resource.exists()) {
            doc = db.parse(this.getClass().getResourceAsStream(this.getConversionRuleFile()));
        } else {
            doc = db.parse(resource.getInputStream());
        }
        doc.getDocumentElement().normalize();
        XPath xpath = XPathFactory.newInstance().newXPath();

        // Get the moved classes rules
        XPathExpression exprClassNames = xpath.compile("//*[@name='maint_doc_classname_changes']/pattern");
        NodeList classNamesList = (NodeList) exprClassNames.evaluate(doc, XPathConstants.NODESET);
        for (int s = 0; s < classNamesList.getLength(); s++) {
            String matchText = xpath.evaluate("match/text()", classNamesList.item(s));
            String replaceText = xpath.evaluate("replacement/text()", classNamesList.item(s));
            classNameRuleMap.put(matchText, replaceText);
        }

        // Get the property changed rules

        XPathExpression exprClassProperties = xpath
                .compile("//*[@name='maint_doc_changed_class_properties']/pattern");
        XPathExpression exprClassPropertiesPatterns = xpath.compile("pattern");
        NodeList propertyClassList = (NodeList) exprClassProperties.evaluate(doc, XPathConstants.NODESET);
        for (int s = 0; s < propertyClassList.getLength(); s++) {
            String classText = xpath.evaluate("class/text()", propertyClassList.item(s));
            Map<String, String> propertyRuleMap = new HashMap<String, String>();
            NodeList classPropertiesPatterns = (NodeList) exprClassPropertiesPatterns
                    .evaluate(propertyClassList.item(s), XPathConstants.NODESET);
            for (int c = 0; c < classPropertiesPatterns.getLength(); c++) {
                String matchText = xpath.evaluate("match/text()", classPropertiesPatterns.item(c));
                String replaceText = xpath.evaluate("replacement/text()", classPropertiesPatterns.item(c));
                propertyRuleMap.put(matchText, replaceText);
            }
            classPropertyRuleMap.put(classText, propertyRuleMap);
        }
    } catch (Exception e) {
        System.out.println("Error parsing rule xml file. Please check file. : " + e.getMessage());
        e.printStackTrace();
    }
}