List of usage examples for org.springframework.core.io Resource getURL
URL getURL() throws IOException;
From source file:de.alpharogroup.duplicate.files.panels.progressbar.ImagePanelTest.java
/** * The main method./*ww w. j ava 2 s .co m*/ * * @param args the arguments */ public static void main(String[] args) { final JFrame frame = new JFrame(); frame.addWindowListener(new CloseWindow()); frame.setTitle("ImagePanelTest"); ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext(); Resource resource = ctx.getResource("classpath:images/EngineHierarchy.PNG"); Resource log4jconfig = ctx.getResource("classpath:conf/log4j/log4jconfig.xml"); try { DOMConfigurator.configure(log4jconfig.getURL()); } catch (FactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } File imageFile = null; try { imageFile = resource.getFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BufferedImage image = null; try { image = javax.imageio.ImageIO.read(imageFile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ImagePanel pnlIconPanel = new ImagePanel(image); frame.add(pnlIconPanel); frame.setBounds(0, 0, 534, 336); frame.setVisible(true); }
From source file:de.alpharogroup.duplicate.files.desktoppane.MainApplication.java
/** * The main method./*from w w w.j a v a 2s .c om*/ * * @param args * the arguments */ public static void main(final String[] args) { final ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext(); final Resource resource = ctx.getResource("classpath:conf/log4j/log4jconfig.xml"); try { DOMConfigurator.configure(resource.getURL()); } catch (final FactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } final MainFrame mainFrame = MainFrame.getInstance(); final DesktopMenu menu = DesktopMenu.getInstance(); mainFrame.setJMenuBar(menu.getMenubar()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setSize(ScreenSizeExtensions.getScreenWidth(), ScreenSizeExtensions.getScreenHeight()); mainFrame.setVisible(true); mainFrame.getDesktopPane().getDesktopManager().activateFrame(mainFrame.getInternalFrame()); mainFrame.getDesktopPane().getDesktopManager().maximizeFrame(mainFrame.getInternalFrame()); mainFrame.getInternalFrame().toFront(); // Set default look and feel... try { UIManager.setLookAndFeel(LookAndFeels.SYSTEM.getLookAndFeelName()); SwingUtilities.updateComponentTreeUI(mainFrame); mainFrame.setCurrentLookAndFeels(LookAndFeels.SYSTEM); } catch (final ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (final InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (final IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (final UnsupportedLookAndFeelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:fr.certu.chouette.command.Command.java
/** * @param args//from ww w. j av a 2s . c o m */ public static void main(String[] args) { // pattern partially work String[] context = { "classpath*:/chouetteContext.xml" }; if (args.length >= 1) { if (args[0].equalsIgnoreCase("-help") || args[0].equalsIgnoreCase("-h")) { printHelp(); System.exit(0); } if (args[0].equalsIgnoreCase("-noDao")) { List<String> newContext = new ArrayList<String>(); PathMatchingResourcePatternResolver test = new PathMatchingResourcePatternResolver(); try { Resource[] re = test.getResources("classpath*:/chouetteContext.xml"); for (Resource resource : re) { if (!resource.getURL().toString().contains("dao")) { newContext.add(resource.getURL().toString()); } } context = newContext.toArray(new String[0]); dao = false; } catch (Exception e) { System.err.println("cannot remove dao : " + e.getLocalizedMessage()); } } applicationContext = new ClassPathXmlApplicationContext(context); ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); Command command = (Command) factory.getBean("Command"); initDao(); command.execute(args); closeDao(); System.runFinalization(); } else { printHelp(); } }
From source file:com.home.ln_spring.ch5.event.ResourceDemo.java
private static void displayInfo(Resource res) throws Exception { System.out.println(res.getClass()); System.out.println(res.getURL().getContent()); System.out.println(""); }
From source file:com.googlecode.flyway.core.util.ResourceUtils.java
/** * Retrieves the location of a resource on disk. * * @param resource The resource to evaluate. * @return The location of the resource on disk. */// ww w .j a va 2 s .com public static String getResourceLocation(Resource resource) { try { return resource.getURL().toExternalForm(); } catch (IOException e) { try { return resource.getFile().getAbsolutePath(); } catch (IOException e1) { return resource.getFilename(); } } }
From source file:io.servicecomb.foundation.common.utils.Log4jUtils.java
private static String genFileContext(List<Resource> resList, Properties properties) throws IOException { List<Entry<Object, Object>> entryList = properties.entrySet().stream() .sorted(new Comparator<Entry<Object, Object>>() { @Override//from w w w . j a v a 2 s . c o m public int compare(Entry<Object, Object> o1, Entry<Object, Object> o2) { return o1.getKey().toString().compareTo(o2.getKey().toString()); } }).collect(Collectors.toList()); StringBuilder sb = new StringBuilder(); for (Resource res : resList) { sb.append("#").append(res.getURL().getPath()).append("\n"); } for (Entry<Object, Object> entry : entryList) { sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n"); } return sb.toString(); }
From source file:com.google.code.activetemplates.impl.handlers.BuiltinHandlerSPI.java
private static final <T> Set<Class<T>> getClasses(String pkg, Class<T> clazz) throws Exception { pkg = pkg.replace('.', '/'); Set<Class<T>> classes = new HashSet<Class<T>>(); ResourcePatternResolver res = new PathMatchingResourcePatternResolver(); Resource[] resources = res.getResources("classpath*:" + pkg + "/*.class"); for (Resource r : resources) { String className = r.getURL().getFile(); className = className.substring(className.indexOf(pkg), className.length() - ".class".length()); className = className.replace('/', '.'); try {/* w ww. ja va2 s . c o m*/ Class<?> cl = Class.forName(className); if (clazz.isAssignableFrom(cl)) { @SuppressWarnings("unchecked") Class<T> tcl = (Class<T>) cl; classes.add(tcl); } } catch (ClassNotFoundException e) { } } return classes; }
From source file:io.gravitee.gateway.env.PropertiesConfiguration.java
@Bean(name = "graviteeProperties") public static Properties graviteeProperties() throws IOException { LOGGER.info("Loading Gravitee configuration."); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION); Resource yamlResource = new FileSystemResource(yamlConfiguration); LOGGER.info("\tGravitee configuration loaded from {}", yamlResource.getURL().getPath()); yaml.setResources(yamlResource);//from w w w.j a v a2 s .c om Properties properties = yaml.getObject(); LOGGER.info("Loading Gravitee configuration. DONE"); return properties; }
From source file:io.wcm.devops.conga.resource.ClasspathResourceCollectionImpl.java
private static boolean isFolder(org.springframework.core.io.Resource classpathResource) throws IOException { return StringUtils.endsWith(classpathResource.getURL().toString(), "/"); }
From source file:io.gravitee.management.rest.spring.PropertiesConfiguration.java
@Bean(name = "graviteeProperties") public static Properties graviteeProperties() throws IOException { LOGGER.info("Loading Gravitee Management configuration."); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION); Resource yamlResource = new FileSystemResource(yamlConfiguration); LOGGER.info("\tGravitee Management configuration loaded from {}", yamlResource.getURL().getPath()); yaml.setResources(yamlResource);/*from w w w . jav a 2 s . c o m*/ Properties properties = yaml.getObject(); LOGGER.info("Loading Gravitee Management configuration. DONE"); return properties; }