DeploymentFileRepositorypublic class DeploymentFileRepository extends org.jboss.system.ServiceMBeanSupport implements DeploymentFileRepositoryMBeanThis class wraps the file system
for deployments. It gives a file-based
persistence mechanism for deployments.
Used by web-console to store -service.xml files,
-ds.xml files, etc..., really anything text based.
Deployments are tied to a specific name and that name
corresponds to the base file name. |
Fields Summary |
---|
private String | baseDir | private File | base | protected File | serverHomeThe server's home directory, for relative paths. |
Methods Summary |
---|
public java.lang.String | getBaseDir()
return baseDir;
| private java.io.File | getFile(java.io.File parent, java.lang.String child)Wrap the File(File parent, String child) CTOR to make sure the
resulting child is indeed under the parent hierarchy,
i.e. don't allow a ../../../rogue-child.txt
see JBAS-3861
File childFile = new File(parent, child);
if (childFile.getCanonicalPath().indexOf(parent.getCanonicalPath()) != 0)
throw new IllegalArgumentException("child '" + child + "' should be a child of parent '" + parent + "'");
return childFile;
| public boolean | isStored(java.lang.String folder, java.lang.String name, java.lang.String fileExtension)
File dir = getFile(base, folder);
String filename = name.replace(' ", '_") + fileExtension;
File file = getFile(dir, filename);
return file.exists();
| public javax.management.ObjectName | preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
// get server's home for relative paths, need this for setting
// attribute final values, so we need to do it here
ServerConfig serverConfig = ServerConfigLocator.locate();
serverHome = serverConfig.getServerHomeDir();
return super.preRegister(server, name);
| public void | remove(java.lang.String folder, java.lang.String name, java.lang.String fileExtension)
File dir = getFile(base, folder);
String filename = name.replace(' ", '_") + fileExtension;
File file = getFile(dir, filename);
file.delete();
| public void | setBaseDir(java.lang.String baseDir)
this.base = getFile(serverHome, baseDir);
this.baseDir = baseDir;
log.debug("BaseDir set to: " + this.base);
| public void | store(java.lang.String folder, java.lang.String name, java.lang.String fileExtension, java.lang.String data, boolean noHotDeploy)
log.debug("store called");
File dir = getFile(base, folder);
log.debug("repository folder: " + dir.toString());
log.debug("absolute: " + dir.getAbsolutePath());
if (!dir.exists())
{
if (!dir.mkdirs())
{
throw new RuntimeException("Failed to create directory: " + dir.toString());
}
}
String filename = name.replace(' ", '_") + fileExtension;
File file = getFile(dir, filename);
File tmpfile = new File(dir, filename + ".tmp");
PrintWriter writer = new PrintWriter(new FileOutputStream(tmpfile));
writer.write(data);
writer.close();
if (file.exists() && noHotDeploy)
{
long modified = file.lastModified();
tmpfile.setLastModified(modified);
file.delete();
}
if (!tmpfile.renameTo(file))
{
throw new RuntimeException("Failed to rename tmpfile to " + file.toString());
}
|
|