List of usage examples for org.springframework.core.io AbstractResource exists
@Override public boolean exists()
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 . jav a2 s . c om AbstractResource templateFile = getTemplateResource(template); if (templateFile.exists()) { inputStream = templateFile.getInputStream(); } } return inputStream == null ? null : IOGroovyMethods.getText(inputStream); }
From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java
protected AbstractResource getTemplateResource(String template) throws IOException { String name = "src/templates/scaffolding/" + template; AbstractResource templateFile = new FileSystemResource(new File(basedir, name).getAbsoluteFile()); if (!templateFile.exists()) { templateFile = new FileSystemResource(new File(getPluginDir(), name).getAbsoluteFile()); }//from ww w . ja v a 2s .com return templateFile; }
From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java
private void setRuleMaps() { setupConfigurationMaps();/*from w ww . j a v a 2 s. c o m*/ 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(); } }