use of uk.me.parabola.mkgmap.reader.osm.Style in project mkgmap by openstreetmap.
the class StyleImpl method readStyle.
/**
* Evaluate the style options and try to read the style.
*
* The option --style-file give the location of an alternate file or
* directory containing styles rather than the default built in ones.
*
* The option --style gives the name of a style, either one of the
* built in ones or selects one from the given style-file.
*
* If there is no name given, but there is a file then the file should
* just contain one style.
*
* @param props the program properties
* @return A style instance or null in case of error.
*/
public static Style readStyle(EnhancedProperties props) {
String loc = props.getProperty("style-file");
if (loc == null)
loc = props.getProperty("map-features");
String name = props.getProperty("style");
if (loc == null && name == null)
name = "default";
if (name == null) {
StyleFileLoader loader = null;
try {
loader = StyleFileLoader.createStyleLoader(loc, null);
int numEntries = loader.list().length;
if (numEntries > 1)
throw new ExitException("Style file " + loc + " contains multiple styles, use option --style to select one.");
} catch (FileNotFoundException e) {
throw new ExitException("Could not open style file " + loc);
} finally {
Utils.closeFile(loader);
}
}
Style style;
try {
style = new StyleImpl(loc, name, props, WITHOUT_CHECKS);
} catch (SyntaxException e) {
System.err.println("Error in style: " + e.getMessage());
throw new ExitException("Could not open style " + (name == null ? "" : name));
} catch (FileNotFoundException e) {
String msg = "Could not open style ";
if (name != null) {
msg += name;
if (loc != null)
msg += " in " + loc;
} else
msg += loc + " . Make sure that it points to a style or add the --style option.";
throw new ExitException(msg);
}
return style;
}
use of uk.me.parabola.mkgmap.reader.osm.Style in project mkgmap by openstreetmap.
the class StyledConverterTest method makeConverter.
private StyledConverter makeConverter(String name) throws FileNotFoundException {
Style style = new StyleImpl(LOC, name);
MapCollector coll = new MapCollector() {
public void addToBounds(Coord p) {
}
// could save points in the same way as lines to test them
public void addPoint(MapPoint point) {
}
public void addLine(MapLine line) {
// Save line so that it can be examined in the tests.
assertNotNull("points are not null", line.getPoints());
lines.add(line);
}
public void addShape(MapShape shape) {
}
public void addRoad(MapRoad road) {
lines.add(road);
}
public int addRestriction(GeneralRouteRestriction grr) {
return 0;
}
public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) {
}
};
return new StyledConverter(style, coll, new EnhancedProperties());
}
use of uk.me.parabola.mkgmap.reader.osm.Style in project mkgmap by openstreetmap.
the class Main method listStyles.
private void listStyles() {
String[] names;
try {
StyleFileLoader loader = StyleFileLoader.createStyleLoader(styleFile, null);
names = loader.list();
loader.close();
} catch (FileNotFoundException e) {
log.debug("didn't find style file", e);
throw new ExitException("Could not list style file " + styleFile);
}
Arrays.sort(names);
System.out.println("The following styles are available:");
for (String name : names) {
Style style = readOneStyle(name, false);
if (style == null)
continue;
StyleInfo info = style.getInfo();
System.out.format("%-15s %6s: %s\n", searchedStyleName, info.getVersion(), info.getSummary());
if (verbose) {
for (String s : info.getLongDescription().split("\n")) System.out.printf("\t%s\n", s.trim());
}
}
}
use of uk.me.parabola.mkgmap.reader.osm.Style in project mkgmap by openstreetmap.
the class Main method checkStyles.
/**
* Check one or all styles in the path given in styleFile.
*/
private void checkStyles() {
String[] names;
try {
StyleFileLoader loader = StyleFileLoader.createStyleLoader(styleFile, null);
names = loader.list();
loader.close();
} catch (FileNotFoundException e) {
log.debug("didn't find style file", e);
throw new ExitException("Could not check style file " + styleFile);
}
Arrays.sort(names);
if (styleOption == null) {
if (names.length > 1)
System.out.println("The following styles are available:");
else
System.out.println("Found one style in " + styleFile);
}
int checked = 0;
for (String name : names) {
if (styleOption != null && !Objects.equals(name, styleOption))
continue;
if (names.length > 1) {
System.out.println("checking style: " + name);
}
++checked;
boolean performChecks = true;
if (Objects.equals("classpath:styles", styleFile) && !Objects.equals("default", name)) {
performChecks = false;
}
Style style = readOneStyle(name, performChecks);
if (style == null) {
System.out.println("could not open style " + name);
}
}
if (checked == 0)
System.out.println("could not open style " + styleOption + " in " + styleFile);
System.out.println("finished check-styles");
}
use of uk.me.parabola.mkgmap.reader.osm.Style in project mkgmap by openstreetmap.
the class Main method readOneStyle.
/**
* Try to read a style from styleFile directory
* @param name name of the style
* @param performChecks perform checks?
* @return the style or null in case of errors
*/
private Style readOneStyle(String name, boolean performChecks) {
searchedStyleName = name;
Style style = null;
try {
style = new StyleImpl(styleFile, name, new EnhancedProperties(), performChecks);
} catch (SyntaxException e) {
System.err.println("Error in style: " + e.getMessage());
} catch (FileNotFoundException e) {
log.debug("could not find style", name);
try {
searchedStyleName = new File(styleFile).getName();
style = new StyleImpl(styleFile, null, new EnhancedProperties(), performChecks);
} catch (SyntaxException e1) {
System.err.println("Error in style: " + e1.getMessage());
} catch (FileNotFoundException e1) {
log.debug("could not find style", styleFile);
}
}
return style;
}
Aggregations