List of usage examples for java.util PropertyResourceBundle getString
public final String getString(String key)
From source file:org.nuxeo.ecm.admin.runtime.RuntimeInstrospection.java
protected static SimplifiedBundleInfo getBundleSimplifiedInfo(Bundle bundle) { if (!(bundle instanceof BundleImpl)) { return null; }/* w w w . j a v a 2s . co m*/ BundleImpl nxBundle = (BundleImpl) bundle; BundleFile file = nxBundle.getBundleFile(); File jarFile = null; if (file instanceof JarBundleFile) { JarBundleFile jar = (JarBundleFile) file; jarFile = jar.getFile(); } if (jarFile == null || jarFile.isDirectory()) { return null; } SimplifiedBundleInfo result = null; try (ZipFile zFile = new ZipFile(jarFile)) { // Look for a pom.properties to extract its Maven version Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith("pom.properties")) { try (InputStream pomStream = zFile.getInputStream(entry)) { PropertyResourceBundle prb = new PropertyResourceBundle(pomStream); String version = prb.getString("version"); result = new SimplifiedBundleInfo(bundle.getSymbolicName(), version); } break; } } } catch (IOException e) { log.debug(e.getMessage(), e); } if (result == null) { // Fall back on the filename to extract a version try { Version version = new Version(jarFile.getName()); result = new SimplifiedBundleInfo(bundle.getSymbolicName(), version.toString()); } catch (NumberFormatException e) { log.debug(e.getMessage()); } } if (result == null) { // Fall back on the MANIFEST Bundle-Version try { org.osgi.framework.Version version = bundle.getVersion(); result = new SimplifiedBundleInfo(bundle.getSymbolicName(), version.toString()); } catch (RuntimeException e) { log.debug(e.getMessage()); result = new SimplifiedBundleInfo(bundle.getSymbolicName(), "unknown"); } } return result; }
From source file:org.pentaho.platform.plugin.services.importer.LocaleImportHandler.java
/** * return locale specific properties from resource bundle * * @param locale//w w w . j a v a2 s. c om * @return */ private Properties buildLocaleProperties(RepositoryFileImportBundle locale, Properties localePropertiesFromIndex) { Properties localeProperties = new Properties(); PropertyResourceBundle rb = null; String comment = locale.getComment(); String fileTitle = locale.getName(); if (!localePropertiesFromIndex.isEmpty()) { // for old style index.xml as locale comment = localePropertiesFromIndex.getProperty(DESC_PROPERTY_NAME); fileTitle = localePropertiesFromIndex.getProperty(TITLE_PROPERTY_NAME); } else { try { byte[] bytes = IOUtils.toByteArray(locale.getInputStream()); java.io.InputStream bundleInputStream = new ByteArrayInputStream(bytes); rb = new PropertyResourceBundle(bundleInputStream); } catch (Exception returnEmptyIfError) { getLogger().error(returnEmptyIfError.getMessage()); return localeProperties; } if (rb != null) { // this is the 4.8 style - name and description // First try file desc. If no file desc, try for a directory desc, else try fallback comment = rb.containsKey(DESC_PROPERTY_NAME) ? rb.getString(DESC_PROPERTY_NAME) : rb.containsKey(FILE_DESCRIPTION) ? rb.getString(FILE_DESCRIPTION) : rb.containsKey(DIRECTORY_DESCRIPTION) ? rb.getString(DIRECTORY_DESCRIPTION) : comment; // First try name. If no name, try title. If no title, try for a directory name, else use filename. fileTitle = rb.containsKey(TITLE_PROPERTY_NAME) ? rb.getString(TITLE_PROPERTY_NAME) : rb.containsKey("title") ? rb.getString("title") : rb.containsKey(FILE_TITLE) ? rb.getString(FILE_TITLE) : rb.containsKey(DIRECTORY_NAME) ? rb.getString(DIRECTORY_NAME) : fileTitle; } } // this is the new .locale Jcr property names localeProperties.setProperty(FILE_DESCRIPTION, comment != null ? comment : StringUtils.EMPTY); localeProperties.setProperty(FILE_TITLE, fileTitle != null ? fileTitle : StringUtils.EMPTY); return localeProperties; }
From source file:org.sakaiproject.search.component.test.LoaderComponentIntegrationTest.java
/** * Fetches the "maven.tomcat.home" property from the maven build.properties * file located in the user's $HOME directory. * /*from ww w .ja v a 2s . c o m*/ * @return * @throws Exception */ private static String getTomcatHome() throws Exception { String testTomcatHome = System.getProperty("test.tomcat.home"); if (testTomcatHome != null && testTomcatHome.length() > 0) { return testTomcatHome; } else { String homeDir = System.getProperty("user.home"); File file = new File(homeDir + File.separatorChar + "build.properties"); FileInputStream fis = new FileInputStream(file); PropertyResourceBundle rb = new PropertyResourceBundle(fis); return rb.getString("maven.tomcat.home"); } }
From source file:org.socraticgrid.docmgr.repository.util.DocumentLoadUtil.java
/** * Method reads bunch of files kept under a folder and move them to different folder after processing.. *///from w ww . j a v a2s . co m public static void readFiles() { String propFileName = "filespath"; PropertyResourceBundle prop = (PropertyResourceBundle) PropertyResourceBundle.getBundle(propFileName); String inFilePath = prop.getString("inFilePath"); String outFilePath = prop.getString("outFilePath"); log.info("In Put File Path -> " + inFilePath); log.info("Out Put File Path -> " + outFilePath); File inputfolder = new File(inFilePath); File files[] = inputfolder.listFiles(); if (files.length != 0) { String inFileName = ""; File destFile = null; String absolutePath = ""; for (File inFile : files) { if (inFile.isFile()) { try { absolutePath = inFile.getAbsolutePath(); try { log.info("absolutePath" + absolutePath); loadData(absolutePath); } catch (Throwable t) { log.debug("Failed to load documents: " + t.getMessage()); t.printStackTrace(); } Thread.sleep(500); } catch (InterruptedException ex) { log.error(ex.getMessage()); } inFileName = inFile.getName(); destFile = new File(outFilePath, inFileName); try { copyFile(inFile, destFile); //inFile.delete(); } catch (IOException ex) { log.error(ex.getMessage()); } } } } else { log.info( "Input files Not found under the specific directory, Please verify filespath.properties and run again"); } }