/*
This file is part of RouteConverter.
RouteConverter is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
RouteConverter 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with RouteConverter; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2007 Christian Pesch. All Rights Reserved.
*/
package slash.navigation.url;
import slash.navigation.base.BaseUrlFormat;
import slash.navigation.base.ParserContext;
import slash.navigation.base.RouteCharacteristics;
import slash.navigation.base.Wgs84Route;
import slash.navigation.common.NavigationPosition;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.regex.Pattern.MULTILINE;
import static slash.common.io.Transfer.trim;
/**
* Reads routes from URL Reference (.url) files.
*
* @author Christian Pesch
*/
public class UrlFormat extends BaseUrlFormat {
private static final Pattern URL_PATTERN = Pattern.
compile(".*?((file|mailto|(news|(ht|f)tp(s?))\\://){1}\\S+).*?", MULTILINE);
public String getExtension() {
return ".url";
}
public String getName() {
return "URL Reference (" + getExtension() + ")";
}
public int getMaximumPositionCount() {
throw new UnsupportedOperationException();
}
public boolean isSupportsWriting() {
return false;
}
public boolean isSupportsMultipleRoutes() {
throw new UnsupportedOperationException();
}
public boolean isWritingRouteCharacteristics() {
throw new UnsupportedOperationException();
}
public <P extends NavigationPosition> Wgs84Route createRoute(RouteCharacteristics characteristics, String name, List<P> positions) {
throw new UnsupportedOperationException();
}
protected String findURL(String text) {
text = replaceLineFeeds(text, " ");
Matcher urlMatcher = URL_PATTERN.matcher(text);
if (!urlMatcher.matches())
return null;
return trim(urlMatcher.group(1));
}
protected void processURL(String url, String encoding, ParserContext<Wgs84Route> context) throws IOException {
context.parse(url);
}
public void write(Wgs84Route route, PrintWriter writer, int startIndex, int endIndex) throws IOException {
throw new UnsupportedOperationException();
}
}