20 package net.sf.gridarta.model.scripts;
23 import java.io.IOException;
25 import org.apache.log4j.Category;
26 import org.apache.log4j.Logger;
27 import org.jetbrains.annotations.NotNull;
51 public static String
localizeEventPath(@NotNull
final File localMapDir,
final File f, @NotNull
final File mapDir) {
52 if (!mapDir.exists()) {
53 LOG.warn(
"Map directory '" + mapDir.getAbsolutePath() +
"' does not exist!");
59 for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) {
68 path = f.getAbsolutePath().substring(mapDir.getCanonicalPath().length());
69 }
catch (
final IOException ignored) {
70 path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length());
72 path = path.replace(
'\\',
'/');
73 if (!path.startsWith(
"/")) {
79 path = f.getAbsolutePath().substring(localMapDir.getCanonicalPath().length());
80 }
catch (
final IOException ignored) {
81 path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length());
83 path = path.replace(
'\\',
'/');
84 while (!path.isEmpty() && path.startsWith(
"/")) {
85 path = path.substring(1);
102 String defScriptName = archetypeName.trim();
103 final int i = defScriptName.indexOf(
' ');
105 if (defScriptName.length() > 12 || defScriptName.lastIndexOf(
' ') != i) {
107 defScriptName = defScriptName.substring(0, i);
110 defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2);
113 if (defScriptName.length() >= 3) {
114 defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1);
116 defScriptName +=
"Script" + scriptEnding;
118 return pathManager.getMapPath(
new File(baseDir, defScriptName));
static final Category LOG
The Logger for printing log messages.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
Reading and writing of maps, handling of paths.
Base package of all Gridarta classes.
static String chooseDefaultScriptName(@NotNull final File baseDir, final String archetypeName, final String scriptEnding, @NotNull final PathManager pathManager)
Try to create a reasonable default script name for lazy users.
static String localizeEventPath(@NotNull final File localMapDir, final File f, @NotNull final File mapDir)
This method is called when the user selects a new event to be created.
ScriptUtils()
Private constructor to prevent instantiation.