Here you can find the source of pathAsUrlString(String path)
Parameter | Description |
---|---|
path | a parameter |
public final static String pathAsUrlString(String path)
//package com.java2s; /*// www . j a va2 s . c o m * Copyright (c) 2006-2009 by Dirk Riehle, http://dirkriehle.com * * This file is part of the Wahlzeit photo rating application. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/>. */ import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * The string, which separates path segments in a URL */ private static final String URL_SEPARATOR = "/"; /** * Convert separators in a filesystem path to URL separators. It does not escape the URL characters. Use * java.net.URLEncoder for this. * * @param path * @return * @fixme Review for performance */ public final static String pathAsUrlString(String path) { if (!File.separator.equals(URL_SEPARATOR)) { // We are not on a platform where file separator matches the url separator, // we need to convert between them. path = path.replaceAll(Pattern.quote(File.separator), Matcher.quoteReplacement(URL_SEPARATOR)); } return path; } }