List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public static String getPortalTranslation(String key, String language) { String translation = ""; language = language.replaceAll("_", "-"); try {//from w w w . j a va2 s . c o m ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("content/language/application/" + language + "/SpiritEhrPortal.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(url.getFile()); doc.getDocumentElement().normalize(); XPath xpath = XPathFactory.newInstance().newXPath(); translation = xpath.evaluate("//*[@key='" + key + "']", doc); if (Validator.isNull(translation)) translation = key; } catch (Exception e) { Log.error(e.getMessage()); } return translation; }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public static String getConsentText(String language) { String translation = ""; language = language.replaceAll("_", "-"); try {/*from w w w . ja v a 2 s . co m*/ ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("content/language/consent/Consent_LegalText_" + language + ".xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(url.getFile()); doc.getDocumentElement().normalize(); XPath xpath = XPathFactory.newInstance().newXPath(); String xpathExpression = "/Consent/LegalText"; NodeList nodes = (NodeList) xpath.evaluate(xpathExpression, doc, XPathConstants.NODESET); translation = nodes.item(0).getTextContent(); } catch (Exception e) { Log.error("Error getting consent text for country " + language); } return translation; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java
@SuppressWarnings("serial") public void setupScreen(final AppProperties appProperties, final String settingsPath) throws Exception { LOG.debug("setupScreen"); this.setJMenuBar(mnuMain); theSettingsPath = settingsPath;// www. jav a 2s .c o m LOG.debug("setupScreen, setting provenance event presenter"); theAppProperties = appProperties; theUserGroupData = theAppProperties.getUserData().getUser(theAppProperties.getLoggedOnUser()) .getUserGroupData(); final boolean searchVisible = (theUserGroupData.isIncludeCMS2Search() || theUserGroupData.isIncludeCMS1Search() || theUserGroupData.isIncludeProducerList() || theUserGroupData.isIncludeNoCMSOption()); pnlCmsReference.setVisible(searchVisible); mnuViewShowSearch.setVisible(searchVisible); if (theUserGroupData.isIncludeCMS2Search()) { rbnCMS2.setSelected(true); } else if (theUserGroupData.isIncludeCMS1Search()) { rbnCMS1.setSelected(true); } else if (theUserGroupData.isIncludeProducerList()) { rbnStaffMediated.setSelected(true); } else if (theUserGroupData.isIncludeNoCMSOption()) { rbnNoCmsRef.setSelected(true); } rbnCMS2.setVisible(theUserGroupData.isIncludeCMS2Search()); rbnCMS1.setVisible(theUserGroupData.isIncludeCMS1Search()); rbnNoCmsRef.setVisible(theUserGroupData.isIncludeNoCMSOption()); rbnStaffMediated.setVisible(theUserGroupData.isIncludeProducerList()); rbnCMS1.setText(theAppProperties.getApplicationData().getCMS1Label()); rbnCMS2.setText(theAppProperties.getApplicationData().getCMS2Label()); if (theUserGroupData.isIncludeCMS2Search()) { rbnCMS2.setSelected(true); } else { if (theUserGroupData.isIncludeCMS1Search()) { rbnCMS1.setSelected(true); } else { rbnNoCmsRef.setSelected(true); } } setTitle(title + theAppProperties.getAppVersion()); ClassLoader cLoader = Thread.currentThread().getContextClassLoader(); java.net.URL imageURL = cLoader.getResource("Indigo_logo_64x64.jpg"); setIconImage(Toolkit.getDefaultToolkit().getImage(imageURL)); LOG.debug("setupScreen, setting FormControl"); try { theFormControl = new FormControl(this, theSettingsPath); fixBackwardsCompatibility(); } catch (Exception ex) { LOG.error("Error loading form parameters", ex); } LOG.debug("setupScreen, adding handlers"); depositPresenter.addHandlers(treeFileSystem, treeEntities, treeStructMap, cmbSelectTemplate, cmbSelectStructTemplate, cmbSortBy, cmbFixityType, tblDetail, tblJobQueueRunning, tblJobQueuePending, tblJobQueueFailed, tblJobQueueDeposited, tblJobQueueComplete, mnuFileFavourites, lstProducers, lstMaterialFlow); LOG.debug("setupScreen, handlers added"); checkButtons(); setCMSDetails(); setHotKeyVisibility(); depositPresenter.checkForInitialLoadScreenSizes(theFormControl, splitAddIE, SPLIT_IE_ATTR, splitMain, SPLIT_MAIN_ATTR, splitMainDetail, SPLIT_MAIN_DETAIL_ATTR, splitMainRight, SPLIT_MAIN_RIGHT_ATTR); final Action updateDividersAction = new AbstractAction() { public void actionPerformed(final ActionEvent e) { Timer t = (Timer) e.getSource(); t.stop(); splitAddIE.setDividerLocation(theFormControl.getExtra(SPLIT_IE_ATTR, 175)); splitMain.setDividerLocation(theFormControl.getExtra(SPLIT_MAIN_ATTR, 200)); splitMainDetail.setDividerLocation(theFormControl.getExtra(SPLIT_MAIN_DETAIL_ATTR, 200)); splitMainRight.setDividerLocation(theFormControl.getExtra(SPLIT_MAIN_RIGHT_ATTR, 200)); splitMain.repaint(); splitMainDetail.repaint(); splitMainRight.repaint(); TableColumn col = tblDetail.getColumnModel().getColumn(0); col.setPreferredWidth(theFormControl.getExtra(META_DATA_COL_1_ATTR, 200)); col = tblDetail.getColumnModel().getColumn(1); col.setPreferredWidth(theFormControl.getExtra(META_DATA_COL_2_ATTR, 200)); MultiSplitLayout layout = mspJobQueue.getMultiSplitLayout(); layout.setFloatingDividers(false); MultiSplitLayout.Split model = (MultiSplitLayout.Split) layout.getModel(); MultiSplitLayout.Divider divider = (MultiSplitLayout.Divider) model.getChildren().get(1); Rectangle bounds = divider.getBounds(); int top = theFormControl.getExtra(JOB_QUEUE_DIVIDER_1_ATTR, bounds.y); bounds.y = top; divider.setBounds(bounds); theOldHeight1 = top; divider = (MultiSplitLayout.Divider) model.getChildren().get(3); bounds = divider.getBounds(); top = theFormControl.getExtra(JOB_QUEUE_DIVIDER_2_ATTR, bounds.y); bounds.y = top; divider.setBounds(bounds); theOldHeight2 = top; divider = (MultiSplitLayout.Divider) model.getChildren().get(5); bounds = divider.getBounds(); top = theFormControl.getExtra(JOB_QUEUE_DIVIDER_3_ATTR, bounds.y); bounds.y = top; divider.setBounds(bounds); theOldHeight3 = top; divider = (MultiSplitLayout.Divider) model.getChildren().get(7); bounds = divider.getBounds(); top = theFormControl.getExtra(JOB_QUEUE_DIVIDER_4_ATTR, bounds.y); bounds.y = top; divider.setBounds(bounds); theOldHeight4 = top; } }; new Timer(200, updateDividersAction).start(); final PersonalSettings personalSettings = theAppProperties.getApplicationData().getPersonalSettings(); theStandardFont = personalSettings.getStandardFont(); final SortBy sortBy = personalSettings.getSortFilesBy(); for (int i = 0; i < cmbSortBy.getItemCount(); i++) { final SortBy item = (SortBy) cmbSortBy.getItemAt(i); if (item.equals(sortBy)) { cmbSortBy.setSelectedIndex(i); break; } } setJobQueuePanes(); LOG.debug("setupScreen, end"); addHotKeyListener(this); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private static URL _readJalopyXmlFromClassLoader() { ClassLoader classLoader = ServiceBuilder.class.getClassLoader(); URL url = classLoader.getResource("jalopy.xml"); if (url == null) { throw new RuntimeException("Unable to load jalopy.xml from the class loader"); }/*from w ww .j a v a 2 s.c o m*/ return url; }
From source file:org.apache.hadoop.hive.conf.HiveConf.java
private static URL findConfigFile(ClassLoader classLoader, String name, boolean doLog) { URL result = classLoader.getResource(name); if (result == null) { String confPath = System.getenv("HIVE_CONF_DIR"); result = checkConfigFile(new File(confPath, name)); if (result == null) { String homePath = System.getenv("HIVE_HOME"); String nameInConf = "conf" + File.separator + name; result = checkConfigFile(new File(homePath, nameInConf)); if (result == null) { URI jarUri = null; try { // Handle both file:// and jar:<url>!{entry} in the case of shaded hive libs URL sourceUrl = HiveConf.class.getProtectionDomain().getCodeSource().getLocation(); jarUri = sourceUrl.getProtocol().equalsIgnoreCase("jar") ? new URI(sourceUrl.getPath()) : sourceUrl.toURI(); } catch (Throwable e) { if (l4j.isInfoEnabled()) { l4j.info("Cannot get jar URI", e); }/* w w w . j av a 2 s. co m*/ System.err.println("Cannot get jar URI: " + e.getMessage()); } // From the jar file, the parent is /lib folder File parent = new File(jarUri).getParentFile(); if (parent != null) { result = checkConfigFile(new File(parent.getParentFile(), nameInConf)); } } } } if (doLog && l4j.isInfoEnabled()) { l4j.info("Found configuration file " + result); } return result; }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public String getLanguagesFromCS() { String listOfLangs = ""; try {//from ww w . j a v a2s. c o m ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("content/language/languages.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(url.getFile()); doc.getDocumentElement().normalize(); NodeList nodeLst = doc.getElementsByTagName("entry"); String seperator = ""; for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (listOfLangs.length() > 1) { seperator = ","; } Element link = (Element) nodeLst.item(s); String a1 = link.getAttribute("key"); if (getCountryIdsFromCS(a1).get(0) != null) { listOfLangs = listOfLangs + seperator + a1; } } } catch (Exception e) { Log.error(e.getMessage()); } return listOfLangs; }
From source file:org.apache.axis2.deployment.DeploymentEngine.java
protected ArrayList populateService(AxisServiceGroup serviceGroup, URL servicesURL, String serviceName) throws DeploymentException { try {// ww w.j a va 2 s. c om serviceGroup.setServiceGroupName(serviceName); ClassLoader serviceClassLoader = Utils.createClassLoader(new URL[] { servicesURL }, axisConfig.getServiceClassLoader(), true, (File) axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR), axisConfig.isChildFirstClassLoading()); String metainf = "meta-inf"; serviceGroup.setServiceGroupClassLoader(serviceClassLoader); //processing wsdl.list InputStream wsdlfilesStream = serviceClassLoader.getResourceAsStream("meta-inf/wsdl.list"); if (wsdlfilesStream == null) { wsdlfilesStream = serviceClassLoader.getResourceAsStream("META-INF/wsdl.list"); if (wsdlfilesStream != null) { metainf = "META-INF"; } } HashMap servicesMap = new HashMap(); if (wsdlfilesStream != null) { ArchiveReader reader = new ArchiveReader(); BufferedReader input = new BufferedReader(new InputStreamReader(wsdlfilesStream)); String line; while ((line = input.readLine()) != null) { line = line.trim(); if (line.length() > 0 && line.charAt(0) != '#') { line = metainf + "/" + line; try { List services = reader.getAxisServiceFromWsdl( serviceClassLoader.getResourceAsStream(line), serviceClassLoader, line); if (services != null) { for (Object service : services) { AxisService axisService = (AxisService) service; servicesMap.put(axisService.getName(), axisService); } } } catch (Exception e) { throw new DeploymentException(e); } } } } InputStream servicexmlStream = serviceClassLoader.getResourceAsStream("META-INF/services.xml"); if (servicexmlStream == null) { servicexmlStream = serviceClassLoader.getResourceAsStream("meta-inf/services.xml"); } else { metainf = "META-INF"; } if (servicexmlStream == null) { throw new DeploymentException( Messages.getMessage(DeploymentErrorMsgs.SERVICE_XML_NOT_FOUND, servicesURL.toString())); } DescriptionBuilder builder = new DescriptionBuilder(servicexmlStream, configContext); OMElement rootElement = builder.buildOM(); String elementName = rootElement.getLocalName(); if (TAG_SERVICE.equals(elementName)) { AxisService axisService = null; String wsdlLocation = "META-INF/service.wsdl"; InputStream wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation); URL wsdlURL = serviceClassLoader.getResource(metainf + "/service.wsdl"); if (wsdlStream == null) { wsdlLocation = "META-INF/" + serviceName + ".wsdl"; wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation); wsdlURL = serviceClassLoader.getResource(wsdlLocation); } if (wsdlStream != null) { WSDL11ToAxisServiceBuilder wsdl2AxisServiceBuilder = new WSDL11ToAxisServiceBuilder(wsdlStream, null, null); File file = Utils.toFile(servicesURL); if (file != null && file.exists()) { wsdl2AxisServiceBuilder .setCustomWSDLResolver(new AARBasedWSDLLocator(wsdlLocation, file, wsdlStream)); wsdl2AxisServiceBuilder.setCustomResolver(new AARFileBasedURIResolver(file)); } if (wsdlURL != null) { wsdl2AxisServiceBuilder.setDocumentBaseUri(wsdlURL.toString()); } axisService = wsdl2AxisServiceBuilder.populateService(); axisService.setWsdlFound(true); axisService.setCustomWsdl(true); axisService.setName(serviceName); } if (axisService == null) { axisService = new AxisService(serviceName); } axisService.setParent(serviceGroup); axisService.setClassLoader(serviceClassLoader); ServiceBuilder serviceBuilder = new ServiceBuilder(configContext, axisService); AxisService service = serviceBuilder.populateService(rootElement); ArrayList serviceList = new ArrayList(); serviceList.add(service); return serviceList; } else if (TAG_SERVICE_GROUP.equals(elementName)) { ServiceGroupBuilder groupBuilder = new ServiceGroupBuilder(rootElement, servicesMap, configContext); ArrayList servicList = groupBuilder.populateServiceGroup(serviceGroup); Iterator serviceIterator = servicList.iterator(); while (serviceIterator.hasNext()) { AxisService axisService = (AxisService) serviceIterator.next(); String wsdlLocation = "META-INF/service.wsdl"; InputStream wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation); URL wsdlURL = serviceClassLoader.getResource(wsdlLocation); if (wsdlStream == null) { wsdlLocation = "META-INF/" + serviceName + ".wsdl"; wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation); wsdlURL = serviceClassLoader.getResource(wsdlLocation); } if (wsdlStream != null) { WSDL11ToAxisServiceBuilder wsdl2AxisServiceBuilder = new WSDL11ToAxisServiceBuilder( wsdlStream, axisService); File file = Utils.toFile(servicesURL); if (file != null && file.exists()) { wsdl2AxisServiceBuilder .setCustomWSDLResolver(new AARBasedWSDLLocator(wsdlLocation, file, wsdlStream)); wsdl2AxisServiceBuilder.setCustomResolver(new AARFileBasedURIResolver(file)); } if (wsdlURL != null) { wsdl2AxisServiceBuilder.setDocumentBaseUri(wsdlURL.toString()); } axisService = wsdl2AxisServiceBuilder.populateService(); axisService.setWsdlFound(true); axisService.setCustomWsdl(true); // Set the default message receiver for the operations that were // not listed in the services.xml Iterator operations = axisService.getOperations(); while (operations.hasNext()) { AxisOperation operation = (AxisOperation) operations.next(); if (operation.getMessageReceiver() == null) { operation.setMessageReceiver(loadDefaultMessageReceiver( operation.getMessageExchangePattern(), axisService)); } } } } return servicList; } } catch (IOException e) { throw new DeploymentException(e); } catch (XMLStreamException e) { throw new DeploymentException(e); } return null; }
From source file:org.apache.maven.plugin.javadoc.AbstractJavadocMojo.java
/** * @param classPath a not null String list of files where resource will be look up. * @param resource a not null ressource to find in the class path. * @return the resource from the given classpath or null if not found * @see ClassLoader#getResource(String)//from w ww. jav a 2 s . c o m * @since 2.6 */ private URL getResource(final List<String> classPath, final String resource) { List<URL> urls = new ArrayList<URL>(classPath.size()); for (String filename : classPath) { try { urls.add(new File(filename).toURL()); } catch (MalformedURLException e) { getLog().error("MalformedURLException: " + e.getMessage()); } } ClassLoader javadocClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null); return javadocClassLoader.getResource(resource); }
From source file:fr.cls.atoll.motu.library.misc.intfce.Organizer.java
/** * Find resource.// ww w . j a v a 2 s . c om * * @param name the name or the resource * * @return the uRL of the resource or null if not found * * @throws MotuException the motu exception */ public static URL findResource(String name) throws MotuException { // first see if the resource is a plain file URL url = null; File f = new File(name); if (f.exists()) { try { url = f.toURI().toURL(); } catch (MalformedURLException e) { throw new MotuException( String.format("Organizer#findResource - Could not create URL from path: '%s'", f), e); } return url; } // search for the resource on the classpath // get the default class/resource loader // ClassLoader cl = getClass().getClassLoader(); ClassLoader cl = Organizer.class.getClassLoader(); return cl.getResource(name); }