List of usage examples for org.springframework.core.io Resource getURL
URL getURL() throws IOException;
From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java
/** * Parse the <code>jar-file</code> XML elements. */// w w w. j a va 2s . c o m @SuppressWarnings("unchecked") protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException { List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL); for (Element element : jars) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { Resource[] resources = this.resourcePatternResolver.getResources(value); boolean found = false; for (Resource resource : resources) { if (resource.exists()) { found = true; unitInfo.addJarFileUrl(resource.getURL()); } } if (!found) { // relative to the persistence unit root, according to the JPA spec URL rootUrl = unitInfo.getPersistenceUnitRootUrl(); if (rootUrl != null) { unitInfo.addJarFileUrl(new URL(rootUrl, value)); } else { logger.warn("Cannot resolve jar-file entry [" + value + "] in persistence unit '" + unitInfo.getPersistenceUnitName() + "' without root URL"); } } } } }
From source file:se.ivankrizsan.messagecowboy.services.transport.MuleTransportService.java
/** * Builds a string containing the Mule configuration resources the transport * service is to be configured with./*from w w w . j a v a 2s .co m*/ * * @return Configuration resources string, or empty string if no configuration * resources. * @throws IOException If error occurs discovering configuration resource. */ protected String buildMuleConfigResourcesString() throws IOException { final StringBuffer theMuleConfigResource = new StringBuffer(); final PathMatchingResourcePatternResolver theConnectorsResolver = new PathMatchingResourcePatternResolver(); for (String theConfigRsrcsLocationPattern : mConfigResourcesLocationPatterns) { final Resource[] theConnectorsConfigurations = theConnectorsResolver .getResources(theConfigRsrcsLocationPattern); LOGGER.debug("Found {} connector configuration files using the pattern {}", theConnectorsConfigurations.length, theConfigRsrcsLocationPattern); if (theConnectorsConfigurations.length > 0) { for (Resource theResource : theConnectorsConfigurations) { /* Only comma-separate if there already is an entry. */ if (theMuleConfigResource.length() > 0) { theMuleConfigResource.append(","); } theMuleConfigResource.append(theResource.getURL()); } } } return theMuleConfigResource.toString(); }
From source file:org.solmix.runtime.support.spring.ContainerXmlBeanDefinitionReader.java
@Override protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource) throws BeanDefinitionStoreException { // sadly, the Spring class we are extending has the critical function // getValidationModeForResource // marked private instead of protected, so trickery is called for here. boolean suppressValidation = false; try {//w ww. j a v a2 s . c o m URL url = resource.getURL(); if (url.getFile().contains("META-INF/solmix/")) { suppressValidation = true; } } catch (IOException e) { // this space intentionally left blank. } int savedValidation = visibleValidationMode; if (suppressValidation) { setValidationMode(VALIDATION_NONE); } int r = super.doLoadBeanDefinitions(inputSource, resource); setValidationMode(savedValidation); return r; }
From source file:com.alibaba.citrus.service.velocity.impl.VelocityConfigurationImpl.java
private String getTemplateNameOfPreloadedResource(Resource resource) { URL url;// w w w . j ava 2 s .c om try { url = resource.getURL(); } catch (IOException e) { url = null; } String templateNameBase; if (url != null) { templateNameBase = "globalVMs/" + StringUtils.getFilename(url.getPath()); } else { templateNameBase = "globalVMs/globalVM.vm"; } String templateName = templateNameBase; // ??resource for (int i = 1; preloadedResources.containsKey(templateName) && !resource.equals(preloadedResources.get(templateName)); i++) { templateName = templateNameBase + i; } preloadedResources.put(templateName, resource); return templateName; }
From source file:com.wavemaker.commons.classloader.ThrowawayFileClassLoader.java
@Override protected URL findResource(String name) { URL ret = null;// w w w.ja v a2 s. co m JarFile jarFile = null; try { for (Resource entry : this.classPath) { if (entry.getFilename().toLowerCase().endsWith(".jar")) { jarFile = new JarFile(entry.getFile()); ZipEntry ze = jarFile.getEntry(name); jarFile.close(); if (ze != null) { ret = new URL("jar:" + entry.getURL() + "!/" + name); break; } } else { Resource file = entry.createRelative(name); if (file.exists()) { ret = file.getURL(); break; } } } } catch (IOException e) { throw new WMRuntimeException(e); } return ret; }
From source file:com.panet.imeta.job.JobEntryLoader.java
private ClassLoader getClassLoader(JobPlugin sp) throws FileSystemException, MalformedURLException { String jarfiles[] = sp.getJarfiles(); List<URL> classpath = new ArrayList<URL>(); // safe to use filesystem because at this point it is all local // and we are using this so we can do things like */lib/*.jar and so // forth, as with ant ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new FileSystemResourceLoader()); for (int i = 0; i < jarfiles.length; i++) { try {//from w ww . ja v a2s . c om Resource[] paths = resolver.getResources(jarfiles[i]); for (Resource path : paths) { classpath.add(path.getURL()); } } catch (IOException e) { e.printStackTrace(); continue; } } URL urls[] = classpath.toArray(new URL[] {}); // Load the class!! // // First get the class loader: get the one that's the // webstart classloader, not the thread classloader // ClassLoader classLoader = getClass().getClassLoader(); // ClassLoader classLoader = getClass().getClassLoader(); // Construct a new URLClassLoader based on this one... URLClassLoader ucl = (URLClassLoader) classLoaders.get(sp.getID()); if (ucl == null) { synchronized (classLoaders) { ucl = new PDIClassLoader(urls, classLoader); classLoaders.put(sp.getID(), ucl); // save for later use... } } return ucl; }
From source file:org.codehaus.griffon.runtime.spring.GriffonRuntimeConfigurator.java
private void doPostResourceConfiguration(GriffonApplication application, RuntimeSpringConfiguration springConfig) { ClassLoader classLoader = ApplicationClassLoader.get(); String resourceName = SPRING_RESOURCES_XML; try {// w w w. j a v a 2s . c o m Resource springResources = new ClassPathResource(resourceName); if (springResources != null && springResources.exists()) { if (LOG.isDebugEnabled()) LOG.debug( "[RuntimeConfiguration] Configuring additional beans from " + springResources.getURL()); DefaultListableBeanFactory xmlBf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xmlBf).loadBeanDefinitions(springResources); xmlBf.setBeanClassLoader(classLoader); String[] beanNames = xmlBf.getBeanDefinitionNames(); if (LOG.isDebugEnabled()) LOG.debug("[RuntimeConfiguration] Found [" + beanNames.length + "] beans to configure"); for (String beanName : beanNames) { BeanDefinition bd = xmlBf.getBeanDefinition(beanName); final String beanClassName = bd.getBeanClassName(); Class<?> beanClass = beanClassName == null ? null : ClassUtils.forName(beanClassName, classLoader); springConfig.addBeanDefinition(beanName, bd); String[] aliases = xmlBf.getAliases(beanName); for (String alias : aliases) { springConfig.addAlias(alias, beanName); } if (beanClass != null) { if (BeanFactoryPostProcessor.class.isAssignableFrom(beanClass)) { ((ConfigurableApplicationContext) springConfig.getUnrefreshedApplicationContext()) .addBeanFactoryPostProcessor( (BeanFactoryPostProcessor) xmlBf.getBean(beanName)); } } } } else if (LOG.isDebugEnabled()) { LOG.debug("[RuntimeConfiguration] " + resourceName + " not found. Skipping configuration."); } } catch (Exception ex) { LOG.error("[RuntimeConfiguration] Unable to perform post initialization config: " + resourceName, sanitize(ex)); } loadSpringGroovyResources(springConfig, application); }
From source file:com.qcadoo.plugin.internal.descriptorparser.DefaultPluginDescriptorParser.java
@Override public InternalPlugin parse(final Resource resource) { try {//from w w w. j a v a2s . co m LOG.info("Parsing descriptor for:" + resource); boolean ignoreModules = false; URL url = ResourceUtils.extractJarFileURL(resource.getURL()); return parse(resource.getInputStream(), ignoreModules, FilenameUtils.getName(url.toString())); } catch (IOException e) { throw new PluginException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e.getMessage(), e); } }