Example usage for org.springframework.util ResourceUtils getFile

List of usage examples for org.springframework.util ResourceUtils getFile

Introduction

In this page you can find the example usage for org.springframework.util ResourceUtils getFile.

Prototype

public static File getFile(URI resourceUri) throws FileNotFoundException 

Source Link

Document

Resolve the given resource URI to a java.io.File , i.e.

Usage

From source file:org.paxml.tag.sql.DdlTag.java

private File getContainerFile() {

    if (StringUtils.isEmpty(dir)) {
        throw new PaxmlRuntimeException("No 'dir' property specified!");
    }/*from  w  ww  .j a v  a  2 s  .c om*/

    try {
        return ResourceUtils.getFile(dir);
    } catch (FileNotFoundException e) {
        return new File(dir);
    }
}

From source file:com.redblackit.web.client.X509HttpClientFactoryBean.java

/**
 * Ensure we have keystores and passwords defined.
 * //  w  w  w  .  ja  v  a  2 s  .  c o  m
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
@Override
public void afterPropertiesSet() throws Exception {
    if (getKeyStore() == null || getKeyStore().length() == 0 || getKeyStoreType() == null
            || getKeyStoreType().length() == 0 || getKeyStorePassword() == null
            || getKeyStorePassword().length() == 0 || getTrustStore() == null || getTrustStore().length() == 0
            || getTrustStoreType() == null || getTrustStoreType().length() == 0
            || getTrustStorePassword() == null || getTrustStorePassword().length() == 0) {
        throw new IllegalArgumentException("Missing key/trust store info:" + this);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("afterPropertiesSet:E:this=" + this);
    }

    try {

        final KeyStore keystore = KeyStore.getInstance(getKeyStoreType());
        InputStream keystoreInput = new FileInputStream(ResourceUtils.getFile(getKeyStore()));
        keystore.load(keystoreInput, getKeyStorePassword().toCharArray());

        KeyStore truststore = KeyStore.getInstance(getTrustStoreType());
        InputStream truststoreInput = new FileInputStream(ResourceUtils.getFile(getTrustStore()));
        truststore.load(truststoreInput, getTrustStorePassword().toCharArray());

        final SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("https", getHttpsPort(),
                new SSLSocketFactory(keystore, getKeyStorePassword(), truststore)));

        if (httpParams == null) {
            httpParams = new BasicHttpParams();
            httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_READ_TIMEOUT_MILLISECONDS);
        }

        httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry), httpParams);

        if (logger.isDebugEnabled()) {
            logger.debug("afterPropertiesSet:R:this=" + this);
        }

    } catch (Throwable t) {
        throw new RuntimeException(this.toString(), t);
    }

}

From source file:com.taobao.itest.util.XlsUtil.java

/**
 * To read Excel data into a Map structure
 * //from  w  ww  . j  a  v a2s . com
 * @param excelDir
 *            excel file path, such as: abc.xls this file exists called to
 *            the same level directory
 * 
 * @return converted Map
 */
public static Map<String, List<Map<String, Object>>> readData(String execlDir) {

    Map<String, List<Map<String, Object>>> allData = new HashMap<String, List<Map<String, Object>>>();

    List<Map<String, Object>> sheet = null;

    String excelRealPath = getExcelRealPath(execlDir);
    IDataSet dataSet;
    try {
        dataSet = new XlsDataSet(ResourceUtils.getFile(excelRealPath));

        // traverse all sheet
        String[] allDataTable = dataSet.getTableNames();

        ITable dataTable = null;
        ITableMetaData meta = null;
        Column[] columns = null;

        Map<String, Object> row = null;
        String columnName = null;
        Object obj = null;

        // read every Sheet
        for (int d = 0; d < allDataTable.length; d++) {
            dataTable = dataSet.getTable(allDataTable[d]);
            meta = dataTable.getTableMetaData();
            columns = meta.getColumns();

            sheet = new ArrayList<Map<String, Object>>();
            // read every line
            for (int k = 0; k < dataTable.getRowCount(); k++) {
                row = Collections.synchronizedMap(new CamelCasingHashMap<String, Object>());
                ;
                for (int i = 0; i < columns.length; i++) {
                    columnName = columns[i].getColumnName();
                    obj = dataTable.getValue(k, columnName);
                    row.put(columnName, obj);
                }
                sheet.add(k, row);
            }

            allData.put(allDataTable[d], sheet);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return allData;

}

From source file:io.cos.cas.authentication.handler.support.OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java

@Override
public void afterPropertiesSet() throws Exception {
    final File xslFile = ResourceUtils.getFile(this.institutionsAuthXslLocation);
    final StreamSource xslStreamSource = new StreamSource(xslFile);
    final TransformerFactory tFactory = TransformerFactory.newInstance();
    this.institutionsAuthTransformer = tFactory.newTransformer(xslStreamSource);

    super.afterPropertiesSet();
}

From source file:org.biopax.validator.api.ValidatorUtils.java

/**
 * Gets the validator's home directory path.
 * //from w  w w.  j  ava 2s  . c o m
 * @return
 * @throws IOException 
 */
public static String getHomeDir() throws IOException {
    Resource r = new FileSystemResource(ResourceUtils.getFile("classpath:"));
    return r.createRelative("..").getFile().getCanonicalPath();
}

From source file:demo.tomcat.SciTomcatEmbeddedServletContainerFactory.java

private void configureSslKeyStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
    try {//from   w  ww  . ja v a2 s  .c  om
        File file = ResourceUtils.getFile(ssl.getKeyStore());
        protocol.setKeystoreFile(file.getAbsolutePath());
    } catch (FileNotFoundException ex) {
        throw new EmbeddedServletContainerException("Could not find key store " + ssl.getKeyStore(), ex);
    }
    if (ssl.getKeyStoreType() != null) {
        protocol.setKeystoreType(ssl.getKeyStoreType());
    }
    if (ssl.getKeyStoreProvider() != null) {
        protocol.setKeystoreProvider(ssl.getKeyStoreProvider());
    }
}

From source file:demo.tomcat.SciTomcatEmbeddedServletContainerFactory.java

private void configureSslTrustStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
    if (ssl.getTrustStore() != null) {
        try {//w  ww. ja v a  2  s .c  om
            File file = ResourceUtils.getFile(ssl.getTrustStore());
            protocol.setTruststoreFile(file.getAbsolutePath());
        } catch (FileNotFoundException ex) {
            throw new EmbeddedServletContainerException("Could not find trust store " + ssl.getTrustStore(),
                    ex);
        }
    }
    protocol.setTruststorePass(ssl.getTrustStorePassword());
    if (ssl.getTrustStoreType() != null) {
        protocol.setTruststoreType(ssl.getTrustStoreType());
    }
    if (ssl.getTrustStoreProvider() != null) {
        protocol.setTruststoreProvider(ssl.getTrustStoreProvider());
    }
}

From source file:com.jfinal.ext.plugin.config.ConfigKit.java

/**
 * @param includeResources/* w w  w  . j  a  va 2  s .c o m*/
 * @param excludeResources
 * @param reload
 */
static void init(List<String> includeResources, List<String> excludeResources, boolean reload) {
    ConfigKit.includeResources = includeResources;
    ConfigKit.excludeResources = excludeResources;
    ConfigKit.reload = reload;
    for (final String resource : includeResources) {
        LOG.debug("include :" + resource);
        List<File> propertiesFiles = new ArrayList<File>();
        File propertiesFile = null;
        try {
            propertiesFile = ResourceUtils.getFile(resource);
            propertiesFiles.add(propertiesFile);
        } catch (FileNotFoundException e) {
            LOG.error("Can't load file " + propertiesFile, e);
        }
        //         File[] propertiesFiles = null;
        //         propertiesFiles = new File(PathKit.getRootClassPath())
        //               .listFiles(new FileFilter() {
        //
        //                  @Override
        //                  public boolean accept(File pathname) {
        //                     return Pattern.compile(resource)
        //                           .matcher(pathname.getName()).matches();
        //                  }
        //               });
        for (File file : propertiesFiles) {
            String fileName = file.getName();
            LOG.debug("fileName:" + fileName);
            //            if (fileName.endsWith("-test." + ConfigPlugin.suffix)) {
            //               continue;
            //            }
            boolean excluded = false;
            for (String exclude : excludeResources) {
                if (Pattern.compile(exclude).matcher(file.getName()).matches()) {
                    excluded = true;
                }
            }
            if (excluded) {
                break;
            }
            lastmodifies.put(fileName, new File(fileName).lastModified());
            map.putAll(ResourceKit.readProperties(fileName));
            if (fileName.endsWith("-test." + ConfigPlugin.suffix)) {
                try {
                    testMap.putAll(ResourceKit.readProperties(testFileName(fileName)));
                } catch (Exception e) {
                    LOG.info(e.getMessage());
                }
            }
        }
    }
    LOG.debug("map" + map);
    LOG.debug("testMap" + testMap);
    LOG.info("config init success!");
}

From source file:com.meidusa.venus.client.VenusServiceFactory.java

@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
    logger.trace("current Venus Client id=" + PacketConstant.VENUS_CLIENT_ID);
    if (venusExceptionFactory == null) {
        XmlVenusExceptionFactory xmlVenusExceptionFactory = new XmlVenusExceptionFactory();

        //3.0.8??? exception ?
        //xmlVenusExceptionFactory.setConfigFiles(new String[] { "classpath:com/meidusa/venus/exception/VenusSystemException.xml" });
        xmlVenusExceptionFactory.init();
        this.venusExceptionFactory = xmlVenusExceptionFactory;
    }/*from  w w  w .j  a  v a 2s  .  c  om*/

    handler.setVenusExceptionFactory(venusExceptionFactory);
    if (enableAsync) {
        if (connector == null) {
            this.connector = new ConnectionConnector("connection Connector");
            connector.setDaemon(true);

        }

        if (connManager == null) {
            try {
                connManager = new ConnectionManager("Connection Manager", this.getAsyncExecutorSize());
            } catch (IOException e) {
                throw new InitialisationException(e);
            }
            connManager.setDaemon(true);
            connManager.start();
        }

        connector.setProcessors(new ConnectionManager[] { connManager });
        connector.start();
    }

    beanContext = new ClientBeanContext(beanFactory);
    BeanContextBean.getInstance().setBeanContext(beanContext);
    VenusBeanUtilsBean
            .setInstance(new ClientBeanUtilsBean(new ConvertUtilsBean(), new PropertyUtilsBean(), beanContext));
    AthenaExtensionResolver.getInstance().resolver();
    handler.setContainer(this.container);
    reloadConfiguration();

    __RELOAD: {
        if (enableReload) {
            File[] files = new File[this.configFiles.length];
            for (int i = 0; i < this.configFiles.length; i++) {
                try {
                    files[i] = ResourceUtils.getFile(configFiles[i].trim());
                } catch (FileNotFoundException e) {
                    logger.warn(e.getMessage());
                    enableReload = false;
                    logger.warn("venus serviceFactory configuration reload disabled!");
                    break __RELOAD;
                }
            }
            VenusFileWatchdog dog = new VenusFileWatchdog(files);
            dog.setDelay(1000 * 10);
            dog.start();
        }
    }
}

From source file:com.meidusa.venus.frontend.http.VenusPoolFactory.java

@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
    logger.trace("current Venus Client id=" + PacketConstant.VENUS_CLIENT_ID);

    beanContext = new BeanContext() {
        public Object getBean(String beanName) {
            if (beanFactory != null) {
                return beanFactory.getBean(beanName);
            } else {
                return null;
            }/* ww  w. j  a va2  s .  c  o  m*/
        }

        public Object createBean(Class clazz) throws Exception {
            if (beanFactory instanceof AutowireCapableBeanFactory) {
                AutowireCapableBeanFactory factory = (AutowireCapableBeanFactory) beanFactory;
                return factory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
            }
            return null;
        }
    };

    BeanContextBean.getInstance().setBeanContext(beanContext);
    VenusBeanUtilsBean.setInstance(new BeanUtilsBean(new ConvertUtilsBean(), new PropertyUtilsBean()) {

        public void setProperty(Object bean, String name, Object value)
                throws IllegalAccessException, InvocationTargetException {
            if (value instanceof String) {
                PropertyDescriptor descriptor = null;
                try {
                    descriptor = getPropertyUtils().getPropertyDescriptor(bean, name);
                    if (descriptor == null) {
                        return; // Skip this property setter
                    } else {
                        if (descriptor.getPropertyType().isEnum()) {
                            Class<Enum> clazz = (Class<Enum>) descriptor.getPropertyType();
                            value = Enum.valueOf(clazz, (String) value);
                        } else {
                            Object temp = null;
                            try {
                                temp = ConfigUtil.filter((String) value, beanContext);
                            } catch (Exception e) {
                            }
                            if (temp == null) {
                                temp = ConfigUtil.filter((String) value);
                            }
                            value = temp;
                        }
                    }
                } catch (NoSuchMethodException e) {
                    return; // Skip this property setter
                }
            }
            super.setProperty(bean, name, value);
        }

    });

    reloadConfiguration();

    __RELOAD: {
        if (enableReload) {
            File[] files = new File[this.configFiles.length];
            for (int i = 0; i < this.configFiles.length; i++) {
                try {
                    files[i] = ResourceUtils.getFile(configFiles[i].trim());
                } catch (FileNotFoundException e) {
                    logger.warn(e.getMessage());
                    enableReload = false;
                    logger.warn("venus serviceFactory configuration reload disabled!");
                    break __RELOAD;
                }
            }
            VenusFileWatchdog dog = new VenusFileWatchdog(files);
            dog.setDelay(1000 * 10);
            dog.start();
        }
    }
}