List of usage examples for org.springframework.core.io UrlResource UrlResource
public UrlResource(String path) throws MalformedURLException
From source file:org.universAAL.itests.IntegrationTest.java
/** * This method parses pax run arguments from eclipse launch configuration, * extracts list of bundles and sorts it by the runlevel. Bundles are * wrapped in the org.springframework.core.io.Resource class as URLs with * "wrap" and "mvn" protocol.//w w w . j av a 2 s . c o m * * @param paxArgs * pax run arguments from the launch configurations provided as * DOM NodeList * @return Returns list of resources. * @throws IOException */ private List<Resource> parsePaxArgs(final NodeList paxArgs) throws IOException { List<BundleToLaunch> bundleList = new ArrayList<BundleToLaunch>(); for (int i = 0; i < paxArgs.getLength(); i++) { Node paxArgNode = paxArgs.item(i); if (paxArgNode.getAttributes() != null) { Node valueAttrib = paxArgNode.getAttributes().getNamedItem("value"); if (valueAttrib != null) { String paxArg = valueAttrib.getTextContent(); BundleToLaunch bToLaunch = filterArtifactUrl(paxArg); if (bToLaunch != null) { bundleList.add(bToLaunch); } } } } Collections.sort(bundleList, new Comparator<BundleToLaunch>() { public int compare(final BundleToLaunch o1, final BundleToLaunch o2) { if (o1.runLevel < o2.runLevel) return -1; if (o1.runLevel > o2.runLevel) return 1; return 0; } }); List<Resource> bundleResources = new ArrayList<Resource>(); for (BundleToLaunch b : bundleList) { bundleResources.add(new UrlResource(b.bundleUrl)); } return bundleResources; }
From source file:org.universAAL.itests.IntegrationTest.java
/** * This method processes configured urls of pax artifacts (composites and * bundles) and returns single list of bundles. * * @return Returns list of resources.// w ww . j a v a2s .c o m * @throws Exception * This method can throw multiple exceptions so it was * aggregated to the most general one - the Exception. */ private List<Resource> processPaxArtifactUrls() throws Exception { InvocationHandler dummyProxyHandler = new InvocationHandler() { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { return null; } }; PropertyResolver dummyPropertyResolver = new PropertyResolver() { public String get(final String arg0) { return null; } }; BundleContext dummyBundleContext = (BundleContext) Proxy.newProxyInstance( BundleContext.class.getClassLoader(), new Class[] { BundleContext.class }, dummyProxyHandler); ProvisionServiceImpl provisionService = new ProvisionServiceImpl(dummyBundleContext); CompositeScanner compositeScanner = new CompositeScanner(dummyPropertyResolver, provisionService); BundleScanner bundleScanner = new BundleScanner(dummyPropertyResolver); provisionService.addScanner(bundleScanner, "scan-bundle"); provisionService.addScanner(compositeScanner, "scan-composite"); List<Resource> bundleResource = new ArrayList<Resource>(); for (String compositeUrl : paxArtifactsUrls) { List<ScannedBundle> scannedBundles = provisionService.scan(compositeUrl); Set<String> bundlesAlreadyAdded = new HashSet<String>(); for (ScannedBundle scannedBundle : scannedBundles) { BundleToLaunch bToLaunch = filterArtifactUrl(scannedBundle.getLocation()); if (bToLaunch != null) { if (!bundlesAlreadyAdded.contains(bToLaunch.bundleUrl)) { bundlesAlreadyAdded.add(bToLaunch.bundleUrl); bundleResource.add(new UrlResource(bToLaunch.bundleUrl)); } } } } return bundleResource; }
From source file:org.universAAL.itests.IntegrationTest.java
/** * Adds additionall dependencies which are needed for launching uAAL * Integration Test./*from ww w . j av a2 s . co m*/ * * @return Returns array of resources. */ private Resource[] insertNeededDeps(final List<Resource> bundles) throws Exception { String itestsVersion = MavenUtils.getArtifactVersion("org.universAAL.support", "itests"); bundles.add(0, new UrlResource("mvn:org.apache.commons/com.springsource.org.apache.commons.io/1.4.0")); bundles.add(0, new UrlResource("mvn:org.universAAL.support/itests/" + itestsVersion)); bundles.add(0, new UrlResource("mvn:org.ops4j.pax.url/pax-url-wrap/1.3.5")); bundles.add(0, new UrlResource("mvn:org.ops4j.pax.url/pax-url-mvn/1.3.5")); bundles.add(0, new UrlResource("mvn:org.ops4j.pax.url/pax-url-mvn/1.3.5")); if (ignoreLastBundle) { Resource last = bundles.get(bundles.size() - 1); log("Ignoring Last Bundle: " + last.getDescription()); bundles.remove(bundles.size() - 1); } return bundles.toArray(new Resource[bundles.size()]); }
From source file:com.liferay.portal.service.impl.PortletLocalServiceImpl.java
private PortletCategory _readLiferayDisplayXML(String servletContextName, String xml) throws Exception { PortletCategory portletCategory = new PortletCategory(); if (xml == null) { xml = ContentUtil.get("com/liferay/portal/deploy/dependencies/liferay-display.xml"); }//from w w w.j a v a 2 s . com Document document = SAXReaderUtil.read(xml, true); Element rootElement = document.getRootElement(); Set<String> portletIds = new HashSet<String>(); _readLiferayDisplay(servletContextName, rootElement, portletCategory, portletIds); if (servletContextName == null) { ClassLoader classLoader = getClass().getClassLoader(); String resourceName = "WEB-INF/liferay-display-ext.xml"; Enumeration<URL> resources = classLoader.getResources(resourceName); if (_log.isDebugEnabled() && !resources.hasMoreElements()) { _log.debug("No " + resourceName + " has been found"); } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); if (_log.isDebugEnabled()) { _log.debug("Loading " + resourceName + " from: " + resource); } if (resource == null) { continue; } InputStream is = new UrlResource(resource).getInputStream(); try { String xmlExt = IOUtils.toString(is, "UTF-8"); Document extDoc = SAXReaderUtil.read(xmlExt, true); Element extRootElement = extDoc.getRootElement(); _readLiferayDisplay(servletContextName, extRootElement, portletCategory, portletIds); } catch (Exception e) { _log.error("Problem while loading file " + resource, e); } finally { is.close(); } } } // Portlets that do not belong to any categories should default to the // Undefined category Set<String> undefinedPortletIds = new HashSet<String>(); for (Portlet portlet : _getPortletsPool().values()) { String portletId = portlet.getPortletId(); PortletApp portletApp = portlet.getPortletApp(); if ((servletContextName != null) && (portletApp.isWARFile()) && (portletId.endsWith( PortletConstants.WAR_SEPARATOR + PortalUtil.getJsSafePortletId(servletContextName)) && (!portletIds.contains(portletId)))) { undefinedPortletIds.add(portletId); } else if ((servletContextName == null) && (!portletApp.isWARFile()) && (portletId.indexOf(PortletConstants.WAR_SEPARATOR) == -1) && (!portletIds.contains(portletId))) { undefinedPortletIds.add(portletId); } } if (!undefinedPortletIds.isEmpty()) { PortletCategory undefinedCategory = new PortletCategory("category.undefined"); portletCategory.addCategory(undefinedCategory); undefinedCategory.getPortletIds().addAll(undefinedPortletIds); } return portletCategory; }
From source file:com.liferay.portal.service.impl.PortletLocalServiceImpl.java
private Set<String> _readLiferayPortletExtXML(Map<String, Portlet> portletsPool) throws Exception { Set<String> result = new HashSet(); ClassLoader classLoader = getClass().getClassLoader(); // load xmls/* w w w.j av a 2 s .co m*/ String resourceName = "WEB-INF/liferay-portlet-ext.xml"; Enumeration<URL> resources = classLoader.getResources(resourceName); if (_log.isDebugEnabled() && !resources.hasMoreElements()) { _log.debug("No " + resourceName + " has been found"); } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); if (_log.isDebugEnabled()) { _log.debug("Loading " + resourceName + " from: " + resource); } if (resource == null) { continue; } InputStream is = new UrlResource(resource).getInputStream(); try { String xmlExt = IOUtils.toString(is, "UTF-8"); result.addAll(_readLiferayPortletXML(xmlExt, portletsPool)); } catch (Exception e) { _log.error("Problem while loading file " + resource, e); } finally { is.close(); } } return result; }
From source file:com.liferay.portal.service.impl.PortletLocalServiceImpl.java
private Set<String> _readPortletExtXML(ServletContext servletContext, Map<String, Portlet> portletsPool, Set<String> servletURLPatterns, PluginPackage pluginPackage) throws Exception { Set<String> result = new HashSet(); ClassLoader classLoader = getClass().getClassLoader(); // load xmls//ww w . ja va 2s.c o m String resourceName = "WEB-INF/portlet-ext.xml"; Enumeration<URL> resources = classLoader.getResources(resourceName); if (_log.isDebugEnabled() && !resources.hasMoreElements()) { _log.debug("No " + resourceName + " has been found"); } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); if (_log.isDebugEnabled()) { _log.debug("Loading " + resourceName + " from: " + resource); } if (resource == null) { continue; } InputStream is = new UrlResource(resource).getInputStream(); try { String xmlExt = IOUtils.toString(is, "UTF-8"); result.addAll( _readPortletXML(servletContext, xmlExt, portletsPool, servletURLPatterns, pluginPackage)); } catch (Exception e) { _log.error("Problem while loading file " + resource, e); } finally { is.close(); } } return result; }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
/** * Get the local NodeTypeRegistry for one specific file. Contains system definitions, dependencies and * definitions from the current file.//from w ww . j av a 2s .c om * * @param path * @return * @throws RepositoryException */ private synchronized NodeTypeRegistry loadRegistry(String path) throws RepositoryException { NodeTypeRegistry ntr = nodeTypeRegistryMap.get(path); if (ntr != null) { return ntr; } else { try { ntr = createBaseRegistry(); FileObject file = getFile(path); if (file.exists()) { nodeTypeRegistryMap.put(path, ntr); namespaceDefinitions.put(ntr, new HashMap<String, String>()); ntr.addDefinitionsFile(new UrlResource(file.getURL()), module.getId()); } } catch (ParseException | IOException e) { throw new RepositoryException("Failed to load node type registry", e); } return ntr; } }
From source file:no.abmu.util.hibernate3.spring.ApplicationContextLoaderH3.java
public void init() { configFile = System.getProperty(CONFIG_FILE_KEY); if (applicationContext != null) { Map beans = applicationContext.getBeansOfType(LocalSessionFactoryBean.class); for (Iterator iterator = beans.values().iterator(); iterator.hasNext();) { LocalSessionFactoryBean localSessionFactoryBean = (LocalSessionFactoryBean) iterator.next(); // localSessionFactoryBean.dropDatabaseSchema(); try { localSessionFactoryBean.destroy(); } catch (HibernateException e) { throw new RuntimeException(e); }//from www . j a v a 2s. c o m } } applicationContext = null; Resource res = null; try { if (configFile == null) { throw new IllegalArgumentException("you need to set the system property " + CONFIG_FILE_KEY); } res = new FileSystemResource(configFile); if (!res.exists()) { res = new ClassPathResource(configFile); } if (!res.exists()) { res = new UrlResource(configFile); } if (!res.exists()) { throw new IllegalArgumentException("The resource " + configFile + " could not be loaded as a url, classpath resource or a file"); } factory = new XmlBeanFactory(res); } catch (Exception e) { logger.error("Problem when loading application context", e); if (!(e instanceof IllegalArgumentException)) { resultingException = new IllegalArgumentException("Problem creating context " + e.getMessage()); resultingException.initCause(e); } else { resultingException = (IllegalArgumentException) e; } } }
From source file:objective.taskboard.utils.IOUtilities.java
public static Resource asResource(URL url) { return new UrlResource(url); }
From source file:org.activiti.rest.osgi.OsgiClassPathStoreResourceResolver.java
protected Resource resolveRootDirResource(Resource original) throws IOException { Resource resolved = super.resolveRootDirResource(original); if (resolved == original) { // Equinox/Felix specific hack try {/* w w w . j a va2 s. co m*/ URL url = original.getURL(); URLConnection con = url.openConnection(); try { Method mth = con.getClass().getMethod("getLocalURL"); mth.setAccessible(true); URL localUrl = (URL) mth.invoke(con); if (localUrl != null) { return new UrlResource(localUrl); } } catch (NoSuchMethodException t) { Object targetModule = getField(con, "m_targetModule"); int classPathIdx = (Integer) getField(con, "m_classPathIdx"); Object content; if (classPathIdx == 0) { content = getField(targetModule, "m_content"); } else { Object[] contentPath = (Object[]) getField(targetModule, "m_contentPath"); content = contentPath[classPathIdx - 1]; } URL localUrl = getContentUrl(content, url.getPath()); return new UrlResource(localUrl); } } catch (Throwable t) { logger.debug("Could not resolve url"); } } return original; }