use of com.opensymphony.xwork2.FileManager in project struts by apache.
the class DefaultFileManagerFactory method lookupFileManager.
private FileManager lookupFileManager() {
Set<String> names = container.getInstanceNames(FileManager.class);
LOG.debug("Found following implementations of FileManager interface: {}", names);
Set<FileManager> internals = new HashSet<>();
Set<FileManager> users = new HashSet<>();
for (String fmName : names) {
FileManager fm = container.getInstance(FileManager.class, fmName);
if (fm.internal()) {
internals.add(fm);
} else {
users.add(fm);
}
}
for (FileManager fm : users) {
if (fm.support()) {
LOG.debug("Using FileManager implementation [{}]", fm.getClass().getSimpleName());
return fm;
}
}
LOG.debug("No user defined FileManager, looking up for internal implementations!");
for (FileManager fm : internals) {
if (fm.support()) {
return fm;
}
}
return null;
}
use of com.opensymphony.xwork2.FileManager in project struts by apache.
the class DefaultFileManagerFactory method getFileManager.
public FileManager getFileManager() {
if (fileManagerHolder != null) {
return fileManagerHolder.getFileManager();
}
FileManager fileManager = lookupFileManager();
if (fileManager != null) {
LOG.debug("Using FileManager implementation [{}]", fileManager.getClass().getSimpleName());
fileManager.setReloadingConfigs(reloadingConfigs);
fileManagerHolder = new FileManagerHolder(fileManager);
return fileManager;
}
LOG.debug("Using default implementation of FileManager provided under name [system]: {}", systemFileManager.getClass().getSimpleName());
systemFileManager.setReloadingConfigs(reloadingConfigs);
fileManagerHolder = new FileManagerHolder(systemFileManager);
return systemFileManager;
}
use of com.opensymphony.xwork2.FileManager in project struts by apache.
the class DummyFileManager method testFileManagerFactoryWithRealConfig.
public void testFileManagerFactoryWithRealConfig() throws Exception {
// given
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
container.inject(factory);
// when
FileManager fm = factory.getFileManager();
// then
assertTrue(fm instanceof DefaultFileManager);
}
use of com.opensymphony.xwork2.FileManager in project struts by apache.
the class DummyFileManager method testCreateDefaultFileManager.
public void testCreateDefaultFileManager() throws Exception {
// given
fileManager = null;
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
factory.setFileManager(new DefaultFileManager());
factory.setContainer(new DummyContainer());
// when
FileManager fm = factory.getFileManager();
// then
assertTrue(fm instanceof DefaultFileManager);
}
use of com.opensymphony.xwork2.FileManager in project struts by apache.
the class BaseOsgiHost method getVersion.
/**
* @param url URL for package
* @return the version used to export the packages. it tries to get it from MANIFEST.MF, or the file name
*/
protected String getVersion(URL url) {
if ("jar".equals(url.getProtocol())) {
JarFile jarFile = null;
try {
ActionContext actionContext = null;
FileManagerFactory fileManagerFactory = null;
FileManager fileManager = null;
actionContext = ServletActionContext.getContext();
if (actionContext == null) {
LOG.warn("ActionContext is null. Cannot load FileManagerFactory from it");
}
if (actionContext != null) {
fileManagerFactory = actionContext.getInstance(FileManagerFactory.class);
}
if (fileManagerFactory == null) {
LOG.warn("FileManagerFactory is null in ActionContext. Cannot load FileManager from it");
} else {
fileManager = fileManagerFactory.getFileManager();
}
if (fileManager == null) {
if (fileManagerFactory != null) {
LOG.debug("FileManager is null in FileManagerFactory. Using a DefaultFileManager");
} else {
LOG.debug("Using a DefaultFileManager");
}
fileManager = new DefaultFileManager();
}
jarFile = new JarFile(new File(fileManager.normalizeToFileProtocol(url).toURI()));
Manifest manifest = jarFile.getManifest();
String jarFileName = jarFile.getName();
if (jarFileName != null) {
// Strip extraneous file path elements to limit the string to the JAR name itself, if possible.
int lastExclamationIndex = jarFileName.lastIndexOf("!");
if (lastExclamationIndex != -1) {
jarFileName = jarFileName.substring(0, lastExclamationIndex);
}
if (jarFileName.toLowerCase().endsWith(".jar")) {
int lastPathSeparatorIndex = jarFileName.lastIndexOf(File.separator);
if (lastPathSeparatorIndex != -1) {
jarFileName = jarFileName.substring(lastPathSeparatorIndex + 1);
}
}
}
if (manifest != null) {
String version = manifest.getMainAttributes().getValue("Bundle-Version");
if (StringUtils.isNotBlank(version)) {
LOG.debug("Attempting to get bundle version for [{}] via its JAR manifest", url.toExternalForm());
return getVersionFromString(version);
} else {
// try to get the version from the file name
LOG.debug("Attempting to get bundle version for [{}] via its filename [{}]", url.toExternalForm(), jarFileName);
return getVersionFromString(jarFileName);
}
} else {
// try to get the version from the file name
LOG.debug("Attempting to get bundle version for [{}] via its filename [{}]", url.toExternalForm(), jarFileName);
return getVersionFromString(jarFileName);
}
} catch (Exception e) {
LOG.error("Unable to extract version from [{}], defaulting to '1.0.0'", url.toExternalForm());
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (Exception ex) {
}
}
}
}
return "1.0.0";
}
Aggregations