List of usage examples for org.springframework.core.io Resource getFilename
@Nullable String getFilename();
From source file:com.temenos.interaction.loader.properties.ReloadablePropertiesFactoryBean.java
private void refreshResources(List<Resource> resources) { assert propertiesPersister != null; assert reloadableProperties != null; for (Resource location : resources) { try {/* ww w.j av a2s . c o m*/ String fileName = location.getFilename().toLowerCase(); if (fileName.startsWith("metadata-") && fileName.endsWith(".xml")) { logger.info("Refreshing : " + location.getFilename()); if (xmlNotifier != null) xmlNotifier.execute(new XmlChangedEventImpl(location)); } if (fileName.endsWith(".properties")) { Properties newProperties = new Properties(); /* * Ensure this property has been loaded. */ propertiesPersister.load(newProperties, location.getInputStream()); boolean loadNewProperties = false; // only update IRIS properties -- ignore all others if (fileName.startsWith("iris-")) { loadNewProperties = reloadableProperties.updateProperties(newProperties); } if (loadNewProperties) { logger.info("Loading new : " + location.getFilename()); reloadableProperties.notifyPropertiesLoaded(location, newProperties); } else { logger.info("Refreshing : " + location.getFilename()); /* * Notify subscribers that properties have been modified */ reloadableProperties.notifyPropertiesChanged(location, newProperties); } } } catch (Exception e) { logger.error("Unexpected error when dynamically loading resources ", e); } } }
From source file:org.web4thejob.module.SystemJobletImpl.java
@Override public List<Resource> getResources() { List<Resource> resources = new ArrayList<Resource>(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try {/*from w w w . j av a 2s . c o m*/ for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) { if (resource.getFilename().equals("AuxiliaryDatabaseObjects.hbm.xml")) continue; resources.add(resource); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } return resources; }
From source file:slina.mb.work.LogServiceImpl.java
public List<LogEvent> processLog(int id) throws IOException { List<LogFilePathImpl> logFilePathList = this.logFilesMap.get(id); List<LogEvent> eventlogList = new ArrayList<LogEvent>(); if (logFilePathList == null) { return eventlogList; }//from w w w .j a va 2 s.com for (LogFilePath logPath : logFilePathList) { //String filepath = logPath.getfullFilePath(); Resource resource = logPath.getResource(); int paserId = logPath.getParserId(); int paserConfigId = logPath.getParserConfigId(); LOGGER.info("Process file for display : " + resource.getFilename()); Log4jParser logParser = logParserMap.get(paserId); List<String> filelist = this.logFileReader.readFile(resource); List<LogEvent> logList = logParser.createLogEvents(paserConfigId, filelist); eventlogList.addAll(logList); } if (eventlogList.size() > 2) { Collections.sort(eventlogList, new LogEventComparator()); } return eventlogList; }
From source file:com.wavemaker.tools.project.LocalDeploymentManager.java
@Override protected Map<String, Object> addMoreProperties(LocalFolder projectDir, String deployName, Map<String, Object> properties) { StudioFileSystem fileSystem = this.projectManager.getFileSystem(); Map<String, Object> newProperties = new HashMap<String, Object>(); if (getProjectManager() != null && getProjectManager().getCurrentProject() != null) { newProperties.put(PROJECT_ENCODING_PROPERTY, getProjectManager().getCurrentProject().getEncoding()); }//from w ww . j a v a 2s. c om newProperties.put(TOMCAT_HOST_PROPERTY, getStudioConfiguration().getTomcatHost()); System.setProperty("wm.proj." + TOMCAT_HOST_PROPERTY, getStudioConfiguration().getTomcatHost()); newProperties.put(TOMCAT_PORT_PROPERTY, getStudioConfiguration().getTomcatPort() + ""); System.setProperty("wm.proj." + TOMCAT_PORT_PROPERTY, getStudioConfiguration().getTomcatPort() + ""); newProperties.put("tomcat.manager.username", getStudioConfiguration().getTomcatManagerUsername()); System.setProperty("wm.proj.tomcat.manager.username", getStudioConfiguration().getTomcatManagerUsername()); newProperties.put("tomcat.manager.password", getStudioConfiguration().getTomcatManagerPassword()); System.setProperty("wm.proj.tomcat.manager.password", getStudioConfiguration().getTomcatManagerPassword()); newProperties.putAll(properties); try { newProperties.put(STUDIO_WEBAPPROOT_PROPERTY, new LocalFolder(fileSystem.getStudioWebAppRoot().getFile())); } catch (IOException ex) { throw new WMRuntimeException(ex); } newProperties.put(PROJECT_DIR_PROPERTY, projectDir); Resource projectDirFile = fileSystem.getResourceForURI(projectDir.getLocalFile().getAbsolutePath()); String projectName = projectDirFile.getFilename(); newProperties.put(PROJECT_NAME_PROPERTY, projectName); if (deployName != null) { newProperties.put(DEPLOY_NAME_PROPERTY, deployName); System.setProperty("wm.proj." + DEPLOY_NAME_PROPERTY, deployName); } return newProperties; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.DatasetFactory.java
private Map<String, DatasetDescriptionImpl> loadFromYaml() throws IOException { // Scan for locators PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] locators = resolver.getResources("classpath:META-INF/org.dkpro.core/datasets.txt"); // Read locators Set<String> patterns = new LinkedHashSet<>(); for (Resource locator : locators) { try (InputStream is = locator.getInputStream()) { IOUtils.lineIterator(is, "UTF-8").forEachRemaining(l -> patterns.add(l)); }//from w ww. j a v a2 s .c o m } // Scan for YAML dataset descriptions List<Resource> resources = new ArrayList<>(); for (String pattern : patterns) { for (Resource r : resolver.getResources(pattern)) { resources.add(r); } } // Configure YAML deserialization Constructor datasetConstructor = new Constructor(DatasetDescriptionImpl.class); TypeDescription datasetDesc = new TypeDescription(DatasetDescriptionImpl.class); datasetDesc.putMapPropertyType("artifacts", String.class, ArtifactDescriptionImpl.class); datasetDesc.putListPropertyType("licenses", LicenseDescriptionImpl.class); datasetConstructor.addTypeDescription(datasetDesc); TypeDescription artifactDesc = new TypeDescription(ArtifactDescriptionImpl.class); artifactDesc.putListPropertyType("actions", ActionDescriptionImpl.class); datasetConstructor.addTypeDescription(artifactDesc); Yaml yaml = new Yaml(datasetConstructor); // Ensure that there is a fixed order (at least if toString is correctly implemented) Collections.sort(resources, (a, b) -> { return a.toString().compareTo(b.toString()); }); // Load the YAML descriptions Map<String, DatasetDescriptionImpl> sets = new LinkedHashMap<>(); for (Resource res : resources) { LOG.debug("Loading [" + res + "]"); try (InputStream is = res.getInputStream()) { String id = FilenameUtils.getBaseName(res.getFilename()); DatasetDescriptionImpl ds = yaml.loadAs(is, DatasetDescriptionImpl.class); ds.setId(id); ds.setOwner(this); // Inject artifact names into artifacts for (Entry<String, ArtifactDescription> e : ds.getArtifacts().entrySet()) { ((ArtifactDescriptionImpl) e.getValue()).setName(e.getKey()); } sets.put(ds.getId(), ds); } } return sets; }
From source file:net.happyonroad.component.container.support.DefaultComponentResolver.java
@Override public Component resolveComponent(final Dependency dependency, Resource resource) throws InvalidComponentNameException, DependencyNotMeetException { logger.debug("Resolving {} from {}", dependency, resource); String originName = resource.getFilename(); if (originName == null) originName = resource.getDescription(); String fileName = FilenameUtils.getName(originName); Dependency basic = Dependency.parse(fileName); if (!dependency.accept(basic)) { throw new InvalidComponentNameException( "The component file name: " + fileName + " does not satisfy the dependency: " + dependency); }/*from w w w. ja v a 2 s .co m*/ DefaultComponent comp; InputStream stream = null; if (fileName.endsWith(".pom")) { try { stream = resource.getInputStream(); comp = (DefaultComponent) resolveComponent(dependency, stream); comp.setUnderlyingResource(resource); if (!comp.isAggregating()) { File jarFile = digJarFilePath(fileName); if (jarFile != null) { ComponentJarResource jarResource = new ComponentJarResource(dependency, jarFile.getName()); comp.setResource(jarResource); } else { logger.warn("Can't find jar file for {}", comp); } } } catch (IOException e) { throw new IllegalArgumentException("The pom file does not exist: " + fileName); } finally { try { if (stream != null) stream.close(); } catch (IOException ex) { /**/} } } else { if (dependency.getVersion() == null) { dependency.setVersion(basic.getVersion()); } ComponentJarResource jarResource = new ComponentJarResource(dependency, fileName); try { stream = jarResource.getPomStream(); comp = (DefaultComponent) resolveComponent(dependency, stream); comp.setUnderlyingResource(resource); comp.setResource(jarResource); } catch (IOException e) { throw new InvalidComponentException(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), "jar", "Can't resolve pom.xml: " + e.getMessage()); } finally { try { if (stream != null) stream.close(); } catch (IOException ex) { /**/} } } if (comp.getType() == null) comp.setType(dependency.getType()); if (!dependency.accept(comp)) throw new InvalidComponentNameException( "The component file name: " + fileName + " conflict with its inner pom: " + comp.toString()); comp.setClassLoader(new ComponentClassLoader(comp)); return comp; }
From source file:com.photon.phresco.configuration.XmlPropertyPlaceholderConfigurer.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (this.locations != null) { Properties mergedProps = new Properties(); for (int i = 0; i < this.locations.length; i++) { Resource location = this.locations[i]; InputStream in = null; try { in = location.getInputStream(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace();/* w ww . j a v a2 s . com*/ } try { if (location.getFilename().endsWith(".xml")) { // this.getClass().getClassLoader().getResourceAsStream(getLocation()); ConfigReader reader = new ConfigReader(in); String envName = System.getProperty(serverEnvironment); if (envName == null) { envName = reader.getDefaultEnvName(); } List<Configuration> configByEnv = reader.getConfigByEnv(envName); for (Configuration config : configByEnv) { if (this.configurationTypes != null) { for (i = 0; i < this.configurationTypes.length; i++) { Resource configurationTypes = this.configurationTypes[i]; String configTypes = configurationTypes.getFilename(); String[] splitStrings = configTypes.split(","); List<String> allowedTokens = Arrays.asList(splitStrings); if (allowedTokens.contains(config.getType())) { mergedProps = config.getProperties(); } } } // props.list(System.out); } } else { if (this.fileEncoding != null) { this.propertiesPersister.load(mergedProps, new InputStreamReader(in, this.fileEncoding)); } else { this.propertiesPersister.load(mergedProps, in); } } } catch (IOException ex) { if (this.ignoreResourceNotFound) { if (logger.isWarnEnabled()) { logger.warn("Could not load properties from " + location + ": " + ex.getMessage()); } } else { try { throw ex; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } // Convert the merged properties, if necessary. convertProperties(mergedProps); // Let the subclass process the properties. processProperties(beanFactory, mergedProps); } }
From source file:org.apache.uima.ruta.resource.TreeWordList.java
/** * Constructs a TreeWordList from a resource. * //www . j a v a 2 s . c o m * @param resource * Resource to create a TextWordList from * @throws IllegalArgumentException * When {@code resource.getFileName()} is null or does not end with .txt or .twl. */ public TreeWordList(Resource resource, boolean dictRemoveWS) throws IOException { this.dictRemoveWS = dictRemoveWS; final String name = resource.getFilename(); InputStream stream = null; try { stream = resource.getInputStream(); if (name == null) { throw new IllegalArgumentException("List does not have a name."); } else if (name.endsWith(".txt")) { buildNewTree(stream); } else if (name.endsWith(".twl")) { readXML(stream, "UTF-8"); } else { throw new IllegalArgumentException("File name should end with .twl or .txt, found " + name); } } finally { if (stream != null) { stream.close(); } } this.name = name; }
From source file:org.activiti.engine.impl.cfg.spring.ProcessEngineFactoryBean.java
private String getResourceName(Resource resource) { String name;//from ww w. j a v a 2 s . c o m if (resource instanceof ContextResource) { name = ((ContextResource) resource).getPathWithinContext(); } else if (resource instanceof ByteArrayResource) { name = resource.getDescription(); } else { try { name = resource.getFile().getAbsolutePath(); } catch (IOException e) { name = resource.getFilename(); } } return name; }
From source file:net.sf.springderby.IjSqlScriptExecutor.java
public void executeScript(Connection connection, Resource script, String encoding) throws SQLException, DataAccessException, IOException { InputStream in = script.getInputStream(); try {/*from w w w. j av a 2 s. c om*/ OutputStream out = new WriterOutputStream(new LoggerWriter(log), "UTF-8"); try { // runScript returns the number of SQLExceptions thrown during the execution if (ij.runScript(connection, in, encoding, out, "UTF-8") > 0) { // TODO: this exception is no longer appropriate throw new SchemaCreationException("Script " + script.getFilename() + " executed with errors"); } } finally { out.close(); } } finally { in.close(); } }