private SecurityController configureController(final Element rootEl) throws ConfigurationException { SecurityController controller = (SecurityController) configureClass(rootEl, "controller", this); try { if (controller == null) { controller = (SecurityController) ClassLoaderUtil.loadClass(SecurityController.NULL_CONTROLLER, getClass()).newInstance(); } } catch (final Exception e) { throw new ConfigurationException("Could not lookup class: " + SecurityController.NULL_CONTROLLER, e); } return controller; }
protected URL getURL(String name) { return ClassLoaderUtil.getResource(name, getClass()); } }
protected InputStream findInputStream(String name, String packagePrefix) throws IOException { String resourcePath; if (packagePrefix.endsWith("/") && name.startsWith("/")) { resourcePath = packagePrefix + name.substring(1); } else { resourcePath = packagePrefix + name; } String enc = (String) Configuration.get(WebWorkConstants.WEBWORK_I18N_ENCODING); resourcePath = URLDecoder.decode(resourcePath, enc); return ClassLoaderUtil.getResourceAsStream(resourcePath, getClass()); }
@Override protected void addResultTypes( PackageConfig packageContext, Element element ) { NodeList resultTypeList = element.getElementsByTagName( "result-type" ); for ( int i = 0; i < resultTypeList.getLength(); i++ ) { Element resultTypeElement = (Element) resultTypeList.item( i ); String name = resultTypeElement.getAttribute( "name" ); String className = resultTypeElement.getAttribute( "class" ); String def = resultTypeElement.getAttribute( "default" ); try { Class<?> clazz = ClassLoaderUtil.loadClass( className, getClass() ); ResultTypeConfig resultType = new ResultTypeConfig( name, clazz ); packageContext.addResultTypeConfig( resultType ); // set the default result type if ( "true".equals( def ) ) { packageContext.setDefaultResultType( name ); } } catch ( ClassNotFoundException e ) { LOG.error( "Result class [" + className + "] doesn't exist, ignoring" ); } } }
/** * This is a convenience method to load a resource as a stream. * * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return (url != null) ? url.openStream() : null; } catch (IOException e) { return null; } }
InputStream in = ClassLoaderUtil.getResourceAsStream(loc, klass); in = ClassLoaderUtil.getResourceAsStream(loc, klass); in = ClassLoaderUtil.getResourceAsStream(loc, klass); in = ClassLoaderUtil.getResourceAsStream(loc, klass); in = ClassLoaderUtil.getResourceAsStream(loc, klass); in = ClassLoaderUtil.getResourceAsStream(loc, klass);
private void addProvider() { if (logger.isDebugEnabled()) { logger.debug("UserProvider class = " + currentClass + " " + currentProperties); } if (configurationBuilder != null) { try { UserProvider provider; provider = (UserProvider) ClassLoaderUtil.loadClass(currentClass, this.getClass()).newInstance(); if (provider.init(currentProperties)) { configurationBuilder.addProvider(provider); } else { logger.error("Could not initialize provider " + currentClass); throw new RuntimeException("Could not initialize provider " + currentClass); } } catch (final Exception e) { logger.error("Could not create instance of provider", e); throw new RuntimeException(e); } } }
/** * This is a convenience method to load a resource as a stream. * * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return (url != null) ? url.openStream() : null; } catch (IOException e) { return null; } }
is = ClassLoaderUtil.getResourceAsStream(propName, getClass());
private void configureInterceptors(final Element rootEl) throws ConfigurationException { final NodeList nl = rootEl.getElementsByTagName("interceptors"); if ((nl != null) && (nl.getLength() > 0)) { final Element interceptorsEl = (Element) nl.item(0); final NodeList interceptorList = interceptorsEl.getElementsByTagName("interceptor"); for (int i = 0; i < interceptorList.getLength(); i++) { final Element interceptorEl = (Element) interceptorList.item(i); final String interceptorClazz = interceptorEl.getAttribute("class"); if ((interceptorClazz == null) || "".equals(interceptorClazz)) { throw new ConfigurationException("Interceptor element with bad class attribute"); } try { SecurityConfigImpl.log.debug("Adding interceptor of class: " + interceptorClazz); final Interceptor interceptor = (Interceptor) ClassLoaderUtil.loadClass(interceptorClazz, getClass()).newInstance(); interceptor.init(getInitParameters(interceptorEl), this); interceptors.add(interceptor); } catch (final Exception e) { throw new ConfigurationException("Could not getRequest service: " + interceptorClazz, e); } } } }
private Element loadConfigXml(final String configFileLocation) throws SAXException, IOException, ParserConfigurationException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final URL fileUrl = ClassLoaderUtil.getResource(configFileLocation, getClass()); if (fileUrl == null) { throw new IllegalArgumentException("No such XML file: " + configFileLocation); } // Parse document final Document doc = factory.newDocumentBuilder().parse(fileUrl.toString()); return doc.getDocumentElement(); }
configProvider = (HibernateConfigurationProvider) ClassLoaderUtil.loadClass(configProviderClass, this.getClass()).newInstance();
private Document parseActionsXmlFile(final String actionsXmlFile) { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); URL fileUrl = ClassLoaderUtil.getResource(actionsXmlFile + ".xml", this.getClass()); if (fileUrl == null) { fileUrl = ClassLoaderUtil.getResource("/" + actionsXmlFile + ".xml", this.getClass()); } if (fileUrl == null) { throw new IllegalArgumentException("No such XML file:/" + actionsXmlFile + ".xml"); } try { return factory.newDocumentBuilder().parse(fileUrl.toString()); } catch (final SAXException e) { throw new RuntimeException(e); } catch (final IOException e) { throw new RuntimeException(e); } catch (final ParserConfigurationException e) { throw new RuntimeException(e); } }
final SecurityService service = (SecurityService) ClassLoaderUtil.loadClass(serviceClazz, getClass()).newInstance();
/** * Load a given resource. * * This method will try to load the resource using the following methods (in order): * <ul> * <li>From Thread.currentThread().getContextClassLoader() * <li>From ClassLoaderUtil.class.getClassLoader() * <li>callingClass.getClassLoader() * </ul> * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static URL getResource(String resourceName, Class callingClass) { URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName); if (url == null) { url = ClassLoaderUtil.class.getClassLoader().getResource(resourceName); } if (url == null) { ClassLoader cl = callingClass.getClassLoader(); if (cl != null) { url = cl.getResource(resourceName); } } if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) { return getResource('/' + resourceName, callingClass); } return url; }
configProvider = (HibernateConfigurationProvider) ClassLoaderUtil.loadClass(configProviderClass, this.getClass()).newInstance();
/** * Load a given resource. * * This method will try to load the resource using the following methods (in order): * <ul> * <li>From Thread.currentThread().getContextClassLoader() * <li>From ClassLoaderUtil.class.getClassLoader() * <li>callingClass.getClassLoader() * </ul> * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static URL getResource(String resourceName, Class callingClass) { URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName); if (url == null) { url = ClassLoaderUtil.class.getClassLoader().getResource(resourceName); } if (url == null) { ClassLoader cl = callingClass.getClassLoader(); if (cl != null) { url = cl.getResource(resourceName); } } if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) { return getResource('/' + resourceName, callingClass); } return url; }
configProvider = (HibernateConfigurationProvider) ClassLoaderUtil.loadClass(configProviderClass, this.getClass()).newInstance();
@Nonnull public static XmlJohnsonConfig fromFile(@Nonnull String fileName) { URL url = ClassLoaderUtil.getResource(checkNotNull(fileName, "fileName"), XmlJohnsonConfig.class); if (url != null) { LOG.debug("Loading {} from classpath at {}", fileName, url); fileName = url.toString(); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(fileName); return fromDocument(document); } catch (IOException e) { throw new ConfigurationJohnsonException("Failed to parse [" + fileName + "]; the file could not be read", e); } catch (ParserConfigurationException e) { throw new ConfigurationJohnsonException("Failed to parse [" + fileName + "]; JVM configuration is invalid", e); } catch (SAXException e) { throw new ConfigurationJohnsonException("Failed to parse [" + fileName + "]; XML is not well-formed", e); } }
try initable = (Initable) ClassLoaderUtil.loadClass(clazz, owner.getClass()).newInstance();