de.intarsys.tools.locator.ExpandingLocatorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of isrt Show documentation
Show all versions of isrt Show documentation
The basic runtime tools and interfaces for intarsys components.
package de.intarsys.tools.locator;
import java.io.File;
import java.io.IOException;
import de.intarsys.tools.expression.EvaluationException;
import de.intarsys.tools.expression.IStringEvaluator;
import de.intarsys.tools.file.FileTools;
import de.intarsys.tools.functor.Args;
public class ExpandingLocatorFactory extends DelegatingLocatorFactory {
final private IStringEvaluator evaluator;
final private File parent;
public ExpandingLocatorFactory(ILocatorFactory factory,
IStringEvaluator evaluator, File parent) {
super(factory);
this.evaluator = evaluator;
this.parent = parent;
}
@Override
public ILocator createLocator(String location) throws IOException {
String expanded;
try {
expanded = (String) evaluator.evaluate(location, Args.create());
} catch (EvaluationException e) {
expanded = location;
}
expanded = FileTools.trimPath(expanded);
if (parent != null) {
File output = FileTools.resolvePath(parent, expanded);
return super.createLocator(output.getAbsolutePath());
}
return super.createLocator(expanded);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy