public void testExtractFileName() { String path1 = "home" + File.separator + "tom" + File.separator + "tesfile1.dim"; String path2 = "C:" + File.separator + "Data" + File.separator + "TestFiles" + File.separator + "tesfile2.dim"; String path3 = File.separator + "tesfile3.dim"; String expected1 = "tesfile1.dim"; String expected2 = "tesfile2.dim"; String expected3 = "tesfile3.dim"; // check that null is not allowed as argument try { FileUtils.getFileNameFromPath(null); fail("Exception expected here!"); } catch (IllegalArgumentException e) { } assertEquals(expected1, FileUtils.getFileNameFromPath(path1)); assertEquals(expected2, FileUtils.getFileNameFromPath(path2)); assertEquals(expected3, FileUtils.getFileNameFromPath(path3)); }
static boolean insertImageLayer(LayerSourcePageContext pageContext) { AffineTransform transform = (AffineTransform) pageContext.getPropertyValue(PROPERTY_NAME_WORLD_TRANSFORM); String imageFilePath = (String) pageContext.getPropertyValue(PROPERTY_NAME_IMAGE_FILE_PATH); try { ProductSceneView sceneView = pageContext.getAppContext().getSelectedProductSceneView(); final ImageFileLayerType type = LayerTypeRegistry.getLayerType(ImageFileLayerType.class); final PropertySet configuration = type.createLayerConfig(sceneView); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_IMAGE_FILE, new File(imageFilePath)); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_WORLD_TRANSFORM, transform); Layer layer = type.createLayer(sceneView, configuration); layer.setName(FileUtils.getFileNameFromPath(imageFilePath)); Layer rootLayer = sceneView.getRootLayer(); rootLayer.getChildren().add(sceneView.getFirstImageLayerIndex(), layer); return true; } catch (Exception e) { pageContext.showErrorDialog(e.getMessage()); return false; } } }