@Test(groups = "Integration") public void testGetResourceViaSftpWithUsername() throws Exception { String user = System.getProperty("user.name"); InputStream stream = utils.getResourceFromUrl("sftp://" + user + "@localhost:" + tempFile.getAbsolutePath()); assertEquals(ResourceUtils.readFullyString(stream), tempFileContents); }
@Test public void testGetResourceViaFileWithPrefix() throws Exception { // on windows the correct syntax is file:///c:/path (note the extra /); // however our routines also accept file://c:/path so the following is portable InputStream stream = utils.getResourceFromUrl("file://" + tempFile.getAbsolutePath()); assertEquals(ResourceUtils.readFullyString(stream), tempFileContents); }
public static ProgressDialog buildProgressDialog(Context context, boolean cancelble) { final ProgressDialog dialog = new ProgressDialog(context, ResourceUtils.getStyleId(context, "LoadingDialog")); // 设置window type if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST); } else { dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE); } try { if (context instanceof Activity) { if (!((Activity) context).isFinishing()) { dialog.show(); } } else { dialog.show(); } } catch (Exception e) { e.printStackTrace(); } dialog.setContentView(ResourceUtils.getLayoutId(context, "pj_layout_progressbar")); ImageView loading = (ImageView) dialog.findViewById(ResourceUtils.getId(context, "iv_loading")); AnimationDrawable anim = (AnimationDrawable) loading.getBackground(); anim.start(); dialog.setCancelable(cancelble); return dialog; }
@Test public void testBuilder() throws Exception { final KijiTableLayout layout = KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE)); final Kiji kiji = new InstanceBuilder() .withTable("table", layout) .withRow("row1") .withFamily("family") .withQualifier("column") .withValue(1, "foo1") .withValue(2, "foo2") .withRow("row2") .withFamily("family") .withQualifier("column") .withValue(100, "foo3") .build(); final KijiTable table = kiji.openTable("table"); final KijiTableReader reader = table.openTableReader(); // Verify the first row. final KijiDataRequest req = KijiDataRequest.create("family", "column"); final KijiRowData row1 = reader.get(table.getEntityId("row1"), req); assertEquals("foo2", row1.getValue("family", "column", 2).toString()); // Verify the second row. final KijiRowData row2 = reader.get(table.getEntityId("row2"), req); assertEquals("foo3", row2.getValue("family", "column", 100).toString()); ResourceUtils.closeOrLog(reader); ResourceUtils.releaseOrLog(table); ResourceUtils.releaseOrLog(kiji); }
private void loadKeyboardForLocale(final Locale newLocale) { final Keyboard cachedKeyboard = mLocaleToKeyboardMap.get(newLocale); if (cachedKeyboard != null) { mKeyboard = cachedKeyboard; return; } final InputMethodSubtype subtype; synchronized (mLock) { subtype = mLocaleToSubtypeMap.get(newLocale); } if (subtype == null) { return; } final EditorInfo editorInfo = new EditorInfo(); editorInfo.inputType = InputType.TYPE_CLASS_TEXT; final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(mContext, editorInfo); final Resources res = mContext.getResources(); final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setSubtype(subtype); builder.setIsSpellChecker(false /* isSpellChecker */); final KeyboardLayoutSet layoutSet = builder.build(); mKeyboard = layoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); }
@Test public void testMergeFilePaths() throws Exception { assertEquals(ResourceUtils.mergeFilePaths("a"), "a"); assertEquals(ResourceUtils.mergeFilePaths("a", "b"), "a/b"); assertEquals(ResourceUtils.mergeFilePaths("a/", "b"), "a/b"); assertEquals(ResourceUtils.mergeFilePaths("a", "b/"), "a/b/"); assertEquals(ResourceUtils.mergeFilePaths("/a", "b"), "/a/b"); }
@Test public void testDataUrl() throws Exception { assertEquals(utils.getResourceAsString("data:,hello"), "hello"); assertEquals(utils.getResourceAsString("data:,hello%20world"), "hello world"); // above is correct. below are not valid ... but we accept them anyway assertEquals(utils.getResourceAsString("data:hello"), "hello"); assertEquals(utils.getResourceAsString("data://hello"), "hello"); assertEquals(utils.getResourceAsString("data:hello world"), "hello world"); }
/** * @param title The title of the dialog * @param message The message of the dialog * @param silentDefault The default return value if installer is running silently * @return true if user click YES option. In silent mode return <code>silentDefault</code> */ public static boolean showYesNoDialog( final String title, final String message, final boolean silentDefault) { initLAF(); switch (UiMode.getCurrentUiMode()) { case SWING: LogManager.logIndent("... showing Yes/No dialog"); LogManager.log("title: " + title); LogManager.log("message: " + message); final int result = JOptionPane.showConfirmDialog(null, message, title, YES_NO_OPTION); LogManager.logUnindent( "... dialog closed, choice : " + (result == YES_OPTION ? "yes" : (result == NO_OPTION ? "no" : "closed"))); return result == YES_OPTION; case SILENT: LogManager.log(message); final String option = StringUtils.format( ResourceUtils.getString( UiUtils.class, silentDefault ? RESOURCE_SILENT_DEFAULT_YES : RESOURCE_SILENT_DEFAULT_NO)); System.err.println(message); System.err.println(option); LogManager.log(message); LogManager.log(option); return silentDefault; } // never get this line... return true; }
@Test public void explicitClasspathResourceWithSlash() { List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy", ClassUtils.getDefaultClassLoader()); assertEquals(1, urls.size()); assertTrue(urls.get(0).startsWith("file:")); }
@BeforeClass(alwaysRun = true) public void setUp() throws Exception { utils = new ResourceUtils(this, "mycontext"); tempFile = ResourceUtils.writeToTempFile( new ByteArrayInputStream(tempFileContents.getBytes()), "resourceutils-test", ".txt"); }
@Override public ProcessStatus startSourceDocCreationOrUpdate( final String idNoSlash, final String projectSlug, final String iterationSlug, final Resource resource, final Set<String> extensions, final boolean copytrans) { HProjectIteration hProjectIteration = retrieveAndCheckIteration(projectSlug, iterationSlug, true); resourceUtils.validateExtensions(extensions); // gettext, comment String name = "SourceDocCreationOrUpdate: " + projectSlug + "-" + iterationSlug + "-" + idNoSlash; AsyncTaskHandle<HDocument> handle = new AsyncTaskHandle<HDocument>(); Serializable taskId = asyncTaskHandleManager.registerTaskHandle(handle); documentServiceImpl.saveDocumentAsync( projectSlug, iterationSlug, resource, extensions, copytrans, true, handle); return getProcessStatus(taskId.toString()); // TODO Change to return 202 // Accepted, // with a url to get the // progress }
@Test public void recursiveFiles() { List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample", ClassUtils.getDefaultClassLoader()); assertEquals(1, urls.size()); assertTrue(urls.get(0).startsWith("file:")); }
public static String getDefaultLookAndFeelClassName() { switch (UiMode.getCurrentUiMode()) { case SWING: String className = UIManager.getSystemLookAndFeelClassName(); // if the default look and feel is the cross-platform one, we might // need to correct this choice. E.g. - KDE, where GTK look and feel // would be much more appropriate if (className.equals(UIManager.getCrossPlatformLookAndFeelClassName())) { // if the current platform is Linux and the desktop manager is // KDE, then we should try to use the GTK look and feel try { if (System.getProperty("os.name").contains("Linux") && (System.getenv("KDE_FULL_SESSION") != null)) { // check whether the GTK look and feel class is // available -- we'll get CNFE if it is not and it will // not be set Class.forName(LookAndFeelType.GTK.getClassName()); className = LookAndFeelType.GTK.getClassName(); } } catch (ClassNotFoundException e) { ErrorManager.notifyDebug( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_FORCE_GTK), e); } } return className; default: return null; } }
public void addTemplate(String name, Resource resource) { String template = ResourceUtils.toString(resource); if (stringTemplateLoader.findTemplateSource(name) != null) { log.warn("Overiding template named:" + name); } stringTemplateLoader.putTemplate(name, template); }
@Test public void implicitFile() { List<String> urls = ResourceUtils.getUrls("src/test/resources/init.groovy", ClassUtils.getDefaultClassLoader()); assertEquals(1, urls.size()); assertTrue(urls.get(0).startsWith("file:")); }
/** * Analyzes the data file identified by the given resource name. * * @param aResourceName the name of the resource (= data file) to analyse, cannot be <code>null * </code>. * @return the analysis results, never <code>null</code>. * @throws Exception in case of exceptions. */ private I2CDataSet analyseDataFile( final String aResourceName, final int aSclIndex, final int aSdaIndex) throws Exception { URL resource = ResourceUtils.getResource(getClass(), aResourceName); AcquisitionResult container = DataTestUtils.getCapturedData(resource); ToolContext toolContext = DataTestUtils.createToolContext(container); ToolProgressListener progressListener = Mockito.mock(ToolProgressListener.class); AnnotationListener annotationListener = Mockito.mock(AnnotationListener.class); I2CAnalyserTask worker = new I2CAnalyserTask(toolContext, progressListener, annotationListener); worker.setLineAIndex(aSclIndex); worker.setLineBIndex(aSdaIndex); worker.setDetectSDA_SCL(false); worker.setReportACK(false); worker.setReportNACK(false); worker.setReportStart(false); worker.setReportStop(false); // Simulate we're running in a separate thread by directly calling the main // working routine... I2CDataSet result = worker.call(); assertNotNull(result); return result; }
@Test public void directoryOfFilesWithPrefix() { List<String> urls = ResourceUtils.getUrls( "file:src/test/resources/dir-sample/code/*", ClassUtils.getDefaultClassLoader()); assertEquals(1, urls.size()); assertTrue(urls.get(0).startsWith("file:")); }
public InputStreamReader getInputStreamReader() { InputStream in = ResourceUtils.getResourceAsStream(this, this); if (in == null) { return null; } InputStreamReader reader = new InputStreamReader(in); return reader; }
public static ProgressDialog buildProgressDialog(Context context, String msg, boolean cancelble) { final ProgressDialog dialog = new ProgressDialog(context, ResourceUtils.getStyleId(context, "LoadingDialog")); // 设置window type if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST); } else { dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE); } dialog.show(); dialog.setContentView(ResourceUtils.getLayoutId(context, "pj_layout_progressbar")); ImageView loading = (ImageView) dialog.findViewById(ResourceUtils.getId(context, "iv_loading")); AnimationDrawable anim = (AnimationDrawable) loading.getBackground(); anim.start(); ((TextView) dialog.findViewById(ResourceUtils.getId(context, "tv_progressbar_message"))) .setText(msg); dialog.setCancelable(cancelble); return dialog; }
/* */ public InputStreamReader getInputStreamReader() /* */ { /* 117 */ InputStream in = ResourceUtils.getResourceAsStream(this, this); /* */ /* 119 */ if (in == null) { /* 120 */ return null; /* */ } /* */ /* 123 */ InputStreamReader reader = new InputStreamReader(in); /* */ /* 125 */ return reader; /* */ }
@Test public void testWriteStreamToTempFile() throws Exception { File tempFileLocal = ResourceUtils.writeToTempFile( new ByteArrayInputStream("mycontents".getBytes()), "resourceutils-test", ".txt"); try { List<String> lines = Files.readLines(tempFileLocal, Charsets.UTF_8); assertEquals(lines, ImmutableList.of("mycontents")); } finally { tempFileLocal.delete(); } }
@Test public void duplicateResource() throws Exception { URLClassLoader loader = new URLClassLoader( new URL[] { new URL("file:./src/test/resources/"), new File("src/test/resources/").getAbsoluteFile().toURI().toURL() }); List<String> urls = ResourceUtils.getUrls("classpath:init.groovy", loader); assertEquals(1, urls.size()); assertTrue(urls.get(0).startsWith("file:")); }
@Test public void testPropertiesStreamToTempFile() throws Exception { Properties props = new Properties(); props.setProperty("mykey", "myval"); File tempFileLocal = ResourceUtils.writeToTempFile(props, "resourceutils-test", ".txt"); FileInputStream fis = null; try { fis = new FileInputStream(tempFileLocal); Properties props2 = new Properties(); props2.load(fis); assertEquals(props2.getProperty("mykey"), "myval"); } finally { Closeables.closeQuietly(fis); tempFileLocal.delete(); } }
/** * @param title The title of the dialog * @param message The message of the dialog * @param silentDefault The dafault return value if installer is running silently * @return true if user click YES option. In silent mode return <code>silentDefault</code> */ public static int showYesNoCancelDialog( final String title, final String message, final int silentDefault) { initLAF(); switch (UiMode.getCurrentUiMode()) { case SWING: LogManager.logIndent("... show Yes/No/Cancel dialog"); LogManager.log("title: " + title); LogManager.log("message: " + message); int result = JOptionPane.showConfirmDialog(null, message, title, YES_NO_CANCEL_OPTION); LogManager.logUnindent( "... dialog closed, choice : " + (result == YES_OPTION ? "yes" : (result == NO_OPTION ? "no" : (result == CANCEL_OPTION ? "cancel" : "closed")))); return result; case SILENT: LogManager.log(message); String resource; switch (silentDefault) { case YES_OPTION: resource = RESOURCE_SILENT_DEFAULT_YES; break; case NO_OPTION: resource = RESOURCE_SILENT_DEFAULT_NO; break; case CANCEL_OPTION: resource = RESOURCE_SILENT_DEFAULT_CANCEL; break; default: resource = StringUtils.EMPTY_STRING; break; } final String option = StringUtils.format(ResourceUtils.getString(UiUtils.class, resource)); System.err.println(message); System.err.println(option); LogManager.log(message); LogManager.log(option); return silentDefault; } // never get this line... return silentDefault; }
/** * Analyzes the data file identified by the given resource name. * * @param aResourceName the name of the resource (= data file) to analyse, cannot be <code>null * </code>. * @return the analysis results, never <code>null</code>. * @throws Exception in case of exceptions. */ private I2CDataSet analyseDataFile( final String aResourceName, final int aSclIndex, final int aSdaIndex) throws Exception { URL resource = ResourceUtils.getResource(getClass(), aResourceName); DataContainer container = DataTestUtils.getCapturedData(resource); ToolContext toolContext = DataTestUtils.createToolContext(0, container.getValues().length); I2CAnalyserWorker worker = new I2CAnalyserWorker(container, toolContext); worker.setLineAIndex(aSclIndex); worker.setLineBIndex(aSdaIndex); worker.setDetectSDA_SCL(false); worker.setReportACK(false); worker.setReportNACK(false); worker.setReportStart(false); worker.setReportStop(false); // Simulate we're running in a separate thread by directly calling the main // working routine... I2CDataSet result = worker.doInBackground(); assertNotNull(result); return result; }
/** * Restrict the given set of files to those that are newer than their corresponding target files. * * @param files the original set of files * @param srcDir all files are relative to this directory * @param destDir target files live here. if null file names returned by the mapper are assumed to * be absolute. * @param mapper knows how to construct a target file names from source file names. * @param granularity The number of milliseconds leeway to give before deciding a target is out of * date. */ public String[] restrict( String[] files, File srcDir, File destDir, FileNameMapper mapper, long granularity) throws Exception { // record destdir for later use in getResource this.destDir = destDir; Vector<Resource> v = new Vector<Resource>(); for (String file : files) { File src = FileUtils.resolveFile(srcDir, file); v.addElement(new Resource(file, src.exists(), src.lastModified(), src.isDirectory())); } Resource[] sourceresources = new Resource[v.size()]; v.copyInto(sourceresources); // build the list of sources which are out of date with // respect to the target Resource[] outofdate = ResourceUtils.selectOutOfDateSources(/*task, */ sourceresources, mapper, this, granularity); String[] result = new String[outofdate.length]; for (int counter = 0; counter < outofdate.length; counter++) { result[counter] = outofdate[counter].getName(); } return result; }
@Override public ProcessStatus startSourceDocCreation( final String idNoSlash, final String projectSlug, final String iterationSlug, final Resource resource, final Set<String> extensions, final boolean copytrans) { HProjectIteration hProjectIteration = retrieveAndCheckIteration(projectSlug, iterationSlug, true); resourceUtils.validateExtensions(extensions); // gettext, comment HDocument document = documentDAO.getByDocIdAndIteration(hProjectIteration, resource.getName()); // already existing non-obsolete document. if (document != null) { if (!document.isObsolete()) { // updates must happen through PUT on the actual resource ProcessStatus status = new ProcessStatus(); status.setStatusCode(ProcessStatusCode.Failed); status.getMessages().add("A document with name " + resource.getName() + " already exists."); return status; } } String name = "SourceDocCreation: " + projectSlug + "-" + iterationSlug + "-" + idNoSlash; AsyncTaskHandle<HDocument> handle = new AsyncTaskHandle<HDocument>(); Serializable taskId = asyncTaskHandleManager.registerTaskHandle(handle); documentServiceImpl.saveDocumentAsync( projectSlug, iterationSlug, resource, extensions, copytrans, true, handle); return getProcessStatus(taskId.toString()); // TODO Change to return 202 // Accepted, // with a url to get the // progress }
public static int getDimension( Properties props, final String defaultPropertyName, final int defaultValue) { int dimension = defaultValue; String propertyName = defaultPropertyName; if (props.getProperty(propertyName + "." + UiUtils.getLAF()) != null) { propertyName = propertyName + "." + UiUtils.getLAF(); } if (props.getProperty(propertyName) != null) { try { dimension = Integer.parseInt(props.getProperty(propertyName).trim()); } catch (NumberFormatException e) { final String warning = ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_PARSE_SYSTEM_PROPERTY, propertyName, props.getProperty(propertyName)); ErrorManager.notifyWarning(warning, e); } } return dimension; }
public static void initializeLookAndFeel() throws InitializationException { if (lookAndFeelInitialized) { return; } try { LogManager.log("... initializing look and feel"); LogManager.indent(); switch (UiMode.getCurrentUiMode()) { case SWING: String className = System.getProperty(LAF_CLASS_NAME_PROPERTY); if (className == null) { LogManager.log( "... custom look and feel class name was not specified, using system default"); className = UiUtils.getDefaultLookAndFeelClassName(); } else if (!className.contains(StringUtils.DOT)) { // short name of the L&F class className = UiUtils.getLookAndFeelClassNameByShortName(className); } LogManager.log("... class name: " + className); if (Boolean.getBoolean(LAF_DECORATED_WINDOWS_PROPERTY)) { JFrame.setDefaultLookAndFeelDecorated(true); } try { Thread jdkFileChooserWarningLogThread = null; try { // this helps to avoid some GTK L&F bugs for some locales LogManager.log("... get installed L&Fs"); UIManager.getInstalledLookAndFeels(); LogManager.log("... set specified L&F"); UIManager.setLookAndFeel(className); LogManager.log("... check headless"); if (GraphicsEnvironment.isHeadless()) { HeadlessException e = new HeadlessException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_INIT_UI_HEADLESS)); System.err.println( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_INIT_UI)); System.err.println(e.getMessage()); throw new InitializationException( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_INIT_UI), e); } if (System.getProperty("os.name").startsWith("Windows")) { // workaround for the issue with further using JFileChooser // in case of missing system icons // Java Issue : // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6210674 // NBI Issue : // http://www.netbeans.org/issues/show_bug.cgi?id=105065 // it also a workaround for two more bugs // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6449933 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6489447 LogManager.log("... creating JFileChooser object to check possible issues with UI"); if (System.getProperty("java.version").startsWith("1.6")) { File desktop = new File(SystemUtils.getUserHomeDirectory(), "Desktop"); File[] zips = null; final List<String> names = new ArrayList<String>(); if (FileUtils.exists(desktop)) { zips = desktop.listFiles( new FileFilter() { public boolean accept(File pathname) { boolean result = pathname.getName().endsWith(".zip") && pathname.length() > 1000000L; if (result) { names.add(pathname.getName()); } return result; } }); } if (zips != null && zips.length > 0) { jdkFileChooserWarningLogThread = new NbiThread() { @Override public void run() { try { sleep(8000); // 8 seconds } catch (InterruptedException e) { return; } final File lock = new File( Installer.getInstance().getLocalDirectory(), Installer.LOCK_FILE_NAME); LogManager.log("\n... !!! WARNING !!!"); LogManager.log( "... There are some big zip files on your desktop: " + StringUtils.asString(names)); LogManager.log( "... In case installer UI does not appear for a long time:"); LogManager.log("... 1) kill the installer process"); LogManager.log( "... 2) move those zip files somewhere from the desktop"); LogManager.log("... 3) delete " + lock); LogManager.log("... 4) run installer again"); LogManager.log( "... For more details see the following bugs descriptions: "); LogManager.log( "... http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6372808"); LogManager.log( "... http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050516"); } }; jdkFileChooserWarningLogThread.start(); } } if (SwingUtilities.isEventDispatchThread()) { new JFileChooser(); } else { try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { new JFileChooser(); } }); } catch (InvocationTargetException e) { throw (e.getCause() != null) ? e.getCause() : e; } } if (jdkFileChooserWarningLogThread != null) { jdkFileChooserWarningLogThread.interrupt(); jdkFileChooserWarningLogThread = null; } LogManager.log("... getting default Toolkit to check possible issues with UI"); Toolkit.getDefaultToolkit(); // workaround for JDK issue with JProgressBar using StyleXP // http://www.netbeans.org/issues/show_bug.cgi?id=106876 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337517 LogManager.log("... creating JProgressBar object to check possible issues with UI"); new JProgressBar().getMaximumSize(); LogManager.log("... all UI checks done"); } LogManager.log("... L&F is set"); } catch (Throwable e) { if (jdkFileChooserWarningLogThread != null) { jdkFileChooserWarningLogThread.interrupt(); jdkFileChooserWarningLogThread = null; } // we're catching Throwable here as pretty much anything can happen // while setting the look and feel and we have no control over it // if something wrong happens we should fall back to the default // cross-platform look and feel which is assumed to be working // correctly LogManager.log( "... could not activate defined L&F, initializing cross-platfrom one", e); if (e instanceof InternalError) { System.err.println(e.getMessage()); } else if (e instanceof ExceptionInInitializerError) { final Throwable cause = e.getCause(); if ((cause != null) && (cause instanceof HeadlessException)) { System.err.println(cause.getMessage()); } } className = UIManager.getCrossPlatformLookAndFeelClassName(); LogManager.log("... cross-platform L&F class-name : " + className); UIManager.setLookAndFeel(className); if (System.getProperty(LAF_CLASS_NAME_PROPERTY) != null) { // Throw exception only if user specified custom L&F, // otherwise just go to initialization of cross-platfrom L&F // (Exception e is already logged above) // See also http://www.netbeans.org/issues/show_bug.cgi?id=122557 // This exception would be thrown only if cross-platform LAF is successfully // installed throw new InitializationException( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_DEFINED_LAF), e); } } } catch (NoClassDefFoundError e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (ClassNotFoundException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (InstantiationException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (IllegalAccessException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (UnsupportedLookAndFeelException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } break; } } finally { LogManager.unindent(); LogManager.log("... initializing L&F finished"); if (Boolean.getBoolean("nbi.look.and.feel.dump.defaults")) { try { LogManager.logIndent("... dumping UIManger L&F defaults: "); Hashtable hash = (Hashtable) UIManager.getLookAndFeelDefaults(); Enumeration keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); LogManager.log("" + key + " = " + hash.get(key)); } } catch (Exception e) { LogManager.log(e); } finally { LogManager.unindent(); } } lookAndFeelInitialized = true; lookAndFeelType = getLAF(); } }
@Test public void testGetResourceViaFileWithoutPrefix() throws Exception { InputStream stream = utils.getResourceFromUrl(tempFile.getAbsolutePath()); assertEquals(ResourceUtils.readFullyString(stream), tempFileContents); }