kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.util; kitaev@213: kitaev@213: import java.util.LinkedList; kitaev@213: import java.util.List; kitaev@213: kitaev@213: /** kitaev@213: * File names often need transformations, like Windows-style path to Unix or human-readable data file name to storage location. kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public interface PathRewrite { kitaev@213: kitaev@213: // XXX think over CharSequence use instead of String kitaev@213: public String rewrite(String path); kitaev@213: kitaev@213: public static class Empty implements PathRewrite { kitaev@213: public String rewrite(String path) { kitaev@213: return path; kitaev@213: } kitaev@213: } kitaev@213: kitaev@213: public class Composite implements PathRewrite { kitaev@213: private List chain; kitaev@213: kitaev@213: public Composite(PathRewrite... e) { kitaev@213: LinkedList r = new LinkedList(); kitaev@213: for (int i = 0; e != null && i < e.length; i++) { kitaev@213: r.addLast(e[i]); kitaev@213: } kitaev@213: chain = r; kitaev@213: } kitaev@213: public Composite chain(PathRewrite e) { kitaev@213: chain.add(e); kitaev@213: return this; kitaev@213: } kitaev@213: kitaev@213: public String rewrite(String path) { kitaev@213: for (PathRewrite pr : chain) { kitaev@213: path = pr.rewrite(path); kitaev@213: } kitaev@213: return path; kitaev@213: } kitaev@213: } kitaev@213: }