Java File Name Clean cleanFilename(String typeName)

Here you can find the source of cleanFilename(String typeName)

Description

Produce a clean filename given a resource typeName.

License

Open Source License

Parameter

Parameter Description
typeName a parameter

Declaration

public static String cleanFilename(String typeName) 

Method Source Code

//package com.java2s;
/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net//from w ww  . j  av  a2  s  .  co m
 * (C) 2004-2011, Refractions Research Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD
 * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html).
 */

public class Main {
    /**
     * Produce a clean filename given a resource typeName.
     * <p>
     * This method will replace all non alpha numeric characters with "_".
     * <p>
     * Example:<code>String filename = URLUtils.cleanFilename("topp:tasmania_citities");</code>
     * 
     * @param typeName
     * @return
     */
    public static String cleanFilename(String typeName) {
        StringBuffer fix = new StringBuffer(typeName);
        for (int i = 0; i < fix.length(); i++) {
            char c = fix.charAt(i);
            if (!Character.isLetterOrDigit(c)) {
                fix.setCharAt(i, '_');
            }
        }
        return fix.toString();
    }
}

Related

  1. cleanFileName(String name)
  2. cleanFileName(String name)
  3. cleanFileName(String path)
  4. cleanFileName(String s)
  5. cleanFileName(String sText)