private static String createValidNodeName(final String originalBandName) { String name = StringUtils.createValidName(originalBandName, null, '_'); while (name.startsWith("_")) { name = name.substring(1); } while (name.endsWith("_")) { name = name.substring(0, name.length() - 1); } return name; } }
/** * Creates a valid filename for the given source name. The method returns a string which is the given name where * each occurence of a character which is not a letter, a digit or one of '_', '-', '.' is replaced by an * underscore. The returned string always has the same length as the source name. * * @param name the source name, must not be <code>null</code> */ public static String createValidFilename(String name) { Guardian.assertNotNull("name", name); return StringUtils.createValidName(name, new char[]{'_', '-', '.'}, '_'); }
public void testCreateValidName() { char[] validChars; String validName; String expectedName; validChars = null; validName = StringUtils.createValidName("Ha123:A*A+A#A-A!A$A", validChars, '_'); expectedName = "Ha123_A_A_A_A_A_A_A"; assertEquals(expectedName, validName); validChars = new char[]{'+', '-', '$'}; validName = StringUtils.createValidName("Ha123:A*A+A#A-A!A$A", validChars, '_'); expectedName = "Ha123_A_A+A_A-A_A$A"; assertEquals(expectedName, validName); validChars = new char[]{':', '*', '+', '-', '$', '#', '!'}; validName = StringUtils.createValidName("Ha123:A*A+A#A-A!A$A", validChars, '_'); expectedName = "Ha123:A*A+A#A-A!A$A"; assertEquals(expectedName, validName); }
String productName = StringUtils.createValidName(getInput().toString(), null, '_'); final Product product = new Product(productName, "CSV", sceneRasterWidth, sceneRasterHeight); product.setPreferredTileSize(sceneRasterWidth, sceneRasterHeight);
/** * Creates a product from the product file. */ private Product createProduct() { String productName = _file.getFileName(); productName = StringUtils.createValidName(productName, new char[]{'.', '_'}, '_'); Product prodRet = new Product(productName, _file.getSensorType(), AtsrConstants.ATSR_SCENE_RASTER_WIDTH, AtsrConstants.ATSR_SCENE_RASTER_HEIGHT, this); prodRet.setFileLocation(_file.getFile()); // add all metadata if required // ---------------------------- if (!isMetadataIgnored()) { // add the metadata addMetadata(prodRet); // add the tie point grids addTiePointGrids(prodRet); addGeoCoding(prodRet); } // add the bands to the product addBandsToProduct(prodRet); addActiveFireBitmaskDefs(prodRet); return prodRet; }