List of usage examples for org.springframework.core.io Resource getURL
URL getURL() throws IOException;
From source file:eu.eidas.node.utils.PropertiesUtil.java
@Override public void setLocations(Resource... locations) { super.setLocations(locations); this.locations = new ArrayList<Resource>(); for (Resource location : locations) { this.locations.add(location); try {//from w w w.jav a 2s . c om if (location.getURL() != null && location.getFilename() != null && MASTER_CONF_FILE.equalsIgnoreCase(location.getFilename())) { PropertiesUtil.setEidasXmlLocation(location.getURL().toString()); } } catch (IOException ioe) { LOG.error("cannot retrieve the url of " + MASTER_CONF_FILE + " {}", ioe); } } }
From source file:de.acosix.alfresco.utility.share.config.Log4jHierarchyInit.java
protected void importLogSettings(final Method method, final String springUrl) { Resource[] resources = null;/*from w ww. ja v a 2s. co m*/ try { resources = this.resolver.getResources(springUrl); } catch (final Exception e) { LOGGER.warn("Failed to find additional Logger configuration: {}", springUrl); } if (resources != null) { // Read each resource for (final Resource resource : resources) { try { final URL url = resource.getURL(); method.invoke(null, url); } catch (final Throwable e) { LOGGER.debug("Failed to add extra Logger configuration: \n URL: {}\n Error: {}", springUrl, e); } } } }
From source file:com.netxforge.oss2.core.xml.CastorUtils.java
/** * Unmarshal a Castor XML configuration file. Uses Java 5 generics for * return type and throws DataAccessExceptions. * * @param clazz the class representing the marshalled XML configuration file * @param resource the marshalled XML configuration file to unmarshal * @return Unmarshalled object representing XML file * @throws DataAccessException if the resource could not be opened or the * underlying Castor//from w w w .jav a2 s . co m * Unmarshaller.unmarshal() call throws a MarshalException or * ValidationException. The underlying exception will be translated * using MarshallingExceptionTranslator and will include information about * the resource from its {@link Resource#toString() toString()} method. */ public static <T> T unmarshalWithTranslatedExceptions(Class<T> clazz, Resource resource, boolean preserveWhitespace) { // TODO It might be useful to add code to test for readability on real files; the code below is from DefaultManualProvisioningDao - dj@opennms.org // if (!importFile.canRead()) { // throw new PermissionDeniedDataAccessException("Unable to read file "+importFile, null); // } InputStream in; try { in = resource.getInputStream(); } catch (IOException e) { throw CASTOR_EXCEPTION_TRANSLATOR .translate("opening XML configuration file for resource '" + resource + "'", e); } try { InputSource source = new InputSource(in); try { source.setSystemId(resource.getURL().toString()); } catch (Throwable t) { /* * resource.getURL() might throw an IOException * (or maybe a DataAccessException, since it's a * RuntimeException), indicating that the resource can't be * represented as a URL. We don't really care so much--we'll * only lose the ability for Castor to include the resource URL * in error messages and for it to directly resolve relative * URLs (which we don't currently use), so we just ignore it. */ } return unmarshal(clazz, source, preserveWhitespace); } catch (MarshalException e) { throw CASTOR_EXCEPTION_TRANSLATOR.translate("unmarshalling XML file for resource '" + resource + "'", e); } catch (ValidationException e) { throw CASTOR_EXCEPTION_TRANSLATOR.translate("unmarshalling XML file for resource '" + resource + "'", e); } finally { IOUtils.closeQuietly(in); } }
From source file:io.servicecomb.core.definition.loader.SchemaLoader.java
/** * resource??schemaId.yaml//w ww.ja v a2 s . c om */ public SchemaMeta registerSchema(String microserviceName, Resource resource) { try { String schemaId = FilenameUtils.getBaseName(resource.getFilename()); String swaggerContent = IOUtils.toString(resource.getURL()); SchemaMeta schemaMeta = registerSchema(microserviceName, schemaId, swaggerContent); return schemaMeta; } catch (Throwable e) { throw new Error(e); } }
From source file:org.solmix.runtime.support.spring.ContainerEntityResolver.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource source = super.resolveEntity(publicId, systemId); if (null == source && null != systemId) { // try the schema and dtd resolver in turn, ignoring the suffix in publicId LOG.info("Attempting to resolve systemId {}", systemId); source = schemaResolver.resolveEntity(publicId, systemId); if (null == source) { source = dtdResolver.resolveEntity(publicId, systemId); }/* w w w. jav a 2s.c o m*/ } String resourceLocation = schemaMappings.get(systemId); if (resourceLocation != null && publicId == null) { Resource resource = new ClassPathResource(resourceLocation, classLoader); if (resource != null && resource.exists()) { source.setPublicId(systemId); source.setSystemId(resource.getURL().toString()); } } return source; }
From source file:org.beangle.ems.dev.hibernate.web.action.EvolutionAction.java
public String exec() throws IOException { String sql = get("sql"); if (null == sql) { String sqlfile = get("sqlfile"); InputStream is = null;// ww w . jav a 2 s. c o m Resource resource = resolver.getResource(sqlfile); StringBuilder sb = new StringBuilder(); try { is = resource.getURL().openStream(); put("resource", resource); List<String> sqllines = IOs.readLines(is); for (String line : sqllines) { sb.append(line).append("\n"); } } catch (IOException e) { e.printStackTrace(); } finally { if (null != is) is.close(); } sql = sb.toString(); } String[] statements = Strings.split(sql, ";"); List<String> sqls = CollectUtils.newArrayList(); Map<String, String> results = CollectUtils.newHashMap(); for (String statement : statements) { if (Strings.isBlank(statement)) continue; try { sqls.add(statement); jdbcTemplate.execute(statement); results.put(statement, "success"); } catch (Exception e) { results.put(statement, e.getMessage()); } } put("sqls", sqls); put("results", results); put("databaseName", databaseName); return forward("results"); }
From source file:org.solmix.runtime.cm.support.SpringConfigureUnitManager.java
private void logTraceMessage(String msg, Resource location) { if (logger.isTraceEnabled()) { try {//w ww. j a v a2 s . co m logger.trace(msg + location.getURL().getPath()); } catch (IOException e) { } } }
From source file:com.nagarro.core.util.ws.impl.AddonAwareMessageSource.java
/** * Searches for files defined by fileFilter under baseFile directory and subdirectories defined by dirFilter. * * @param baseFile/*from www .j a va 2 s .c o m*/ * base directory where search starts * @return Collection of paths to message bundle files * @throws IOException */ protected Collection<String> getAddonsMessages(final String baseFile) throws IOException { final List<String> result = Lists.newArrayList(); final Resource[] resources = applicationContext.getResources(baseAddonDir.getFilename() + "**"); for (final Resource resource : resources) { final String path = resource.getURL().toExternalForm(); if (validatePath(path) && validateFilename(path)) { result.add(path); } } return result; }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.ProfileMarshaller.java
public ProfileMarshaller() throws JAXBException, SAXException, IOException { jaxbContext = JAXBContext.newInstance(Profile.class, TomcatDataSource.class, DbcpDataSource.class, AjpConnector.class, HttpConnector.class); Resource schemaResource = new ClassPathResource("tomcatserverconfig-profile-2.0.xsd", Profile.class); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); profileSchema = schemaFactory.newSchema(schemaResource.getURL()); }