/** * Rename file using prefix and suffix settings. * * @param path the path to rename */ protected void renameFile(Path path) { // bail out if there's no in-writing settings if (!StringUtils.hasText(prefix) && !StringUtils.hasText(suffix)) { return; } String name = path.getName(); if (StringUtils.startsWithIgnoreCase(name, prefix)) { name = name.substring(prefix.length()); } if (StringUtils.endsWithIgnoreCase(name, suffix)) { name = name.substring(0, name.length() - suffix.length()); } Path toPath = new Path(path.getParent(), name); try { FileSystem fs = path.getFileSystem(getConfiguration()); if (!fs.rename(path, toPath)) { throw new StoreException( "Failed renaming from " + path + " to " + toPath + " with configuration " + getConfiguration()); } } catch (IOException e) { log.error("Error renaming file", e); throw new StoreException("Error renaming file", e); } }
private void loadBeanDefinitionsFromImportedResources( Map<String, Class<? extends BeanDefinitionReader>> importedResources) { Map<Class<?>, BeanDefinitionReader> readerInstanceCache = new HashMap<Class<?>, BeanDefinitionReader>(); for (Map.Entry<String, Class<? extends BeanDefinitionReader>> entry : importedResources.entrySet()) { String resource = entry.getKey(); Class<? extends BeanDefinitionReader> readerClass = entry.getValue(); // Default reader selection necessary? if (BeanDefinitionReader.class == readerClass) { if (StringUtils.endsWithIgnoreCase(resource, ".groovy")) { // When clearly asking for Groovy, that's what they'll get... readerClass = GroovyBeanDefinitionReader.class; } else { // Primarily ".xml" files but for any other extension as well readerClass = XmlBeanDefinitionReader.class; } } BeanDefinitionReader reader = readerInstanceCache.get(readerClass); if (reader == null) { try { // Instantiate the specified BeanDefinitionReader reader = readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(this.registry); // Delegate the current ResourceLoader to it if possible if (reader instanceof AbstractBeanDefinitionReader) { AbstractBeanDefinitionReader abdr = ((AbstractBeanDefinitionReader) reader); abdr.setResourceLoader(this.resourceLoader); abdr.setEnvironment(this.environment); } readerInstanceCache.put(readerClass, reader); } catch (Exception ex) { throw new IllegalStateException( "Could not instantiate BeanDefinitionReader class [" + readerClass.getName() + "]"); } } // TODO SPR-6310: qualify relative path locations as done in // AbstractContextLoader.modifyLocations reader.loadBeanDefinitions(resource); } }
/** * Load bean definitions from the specified Groovy script or XML file. * * <p>Note that {@code ".xml"} files will be parsed as XML content; all other kinds of resources * will be parsed as Groovy scripts. * * @param encodedResource the resource descriptor for the Groovy script or XML file, allowing * specification of an encoding to use for parsing the file * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException { // Check for XML files and redirect them to the "standard" XmlBeanDefinitionReader String filename = encodedResource.getResource().getFilename(); if (StringUtils.endsWithIgnoreCase(filename, ".xml")) { return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource); } Closure beans = new Closure(this) { public Object call(Object[] args) { invokeBeanDefiningClosure((Closure) args[0]); return null; } }; Binding binding = new Binding() { @Override public void setVariable(String name, Object value) { if (currentBeanDefinition != null) { applyPropertyToBeanDefinition(name, value); } else { super.setVariable(name, value); } } }; binding.setVariable("beans", beans); int countBefore = getRegistry().getBeanDefinitionCount(); try { GroovyShell shell = new GroovyShell(getResourceLoader().getClassLoader(), binding); shell.evaluate(encodedResource.getReader(), "beans"); } catch (Throwable ex) { throw new BeanDefinitionParsingException( new Problem( "Error evaluating Groovy script: " + ex.getMessage(), new Location(encodedResource.getResource()), null, ex)); } return getRegistry().getBeanDefinitionCount() - countBefore; }
protected Map<String, AwardHierarchyNode> getAwardHierarchyNodes( String awardNumber, String currentAwardNumber, String currentSequenceNumber) { if (awardHierarchyNodes == null || awardHierarchyNodes.size() == 0 || StringUtils.endsWithIgnoreCase(LAST_5_CHARS_OF_ROOT, awardNumber.substring(8))) { if (canUseExistingTMSessionObject(awardNumber)) { awardHierarchyNodes = ((TimeAndMoneyDocument) GlobalVariables.getUserSession() .retrieveObject( GlobalVariables.getUserSession().getKualiSessionId() + Constants.TIME_AND_MONEY_DOCUMENT_STRING_FOR_SESSION)) .getAwardHierarchyNodes(); } else { Map<String, AwardHierarchy> awardHierarchyItems = awardHierarchyService.getAwardHierarchy(awardNumber, new ArrayList<String>()); awardHierarchyService.populateAwardHierarchyNodes( awardHierarchyItems, awardHierarchyNodes, currentAwardNumber, currentSequenceNumber); } } return awardHierarchyNodes; }
private static String explodedEntryIfZip(SpringYarnAppmasterLaunchContextProperties syalcp) { return StringUtils.endsWithIgnoreCase(syalcp.getArchiveFile(), ".zip") ? "./" + syalcp.getArchiveFile() : null; }