気が付き次第ここに追加する。
Confluenceのデータディレクトリからのパス
confluence-project/confluence-core/confluence/src/java/com/atlassian/confluence/util/ConfluenceHomeGlobalConstants.java
に記載されている。
package com.atlassian.confluence.util; public class ConfluenceHomeGlobalConstants { public static final String ATTACHMENTS_DIR = "attachments"; public static final String LUCENE_INDEX_DIR = "index"; public static final String TEMP_DIR = "temp"; public static final String PLUGINS_DIR = "plugins"; public static final String PLUGINS_TEMP_DIR = "plugins-temp"; public static final String PLUGINS_CACHE_DIR = "plugins-cache"; public static final String BUNDLED_PLUGINS_DIR = "bundled-plugins"; public static final String BUNDLED_PLUGINS_LANGUAGE_DIR = "bundled-plugins_language"; public static final String WEB_RESOURCE_TEMP_DIR = "webresource-temp"; public static final String BACKUPTYPE_AUTOMATIC = "automatic.backups"; public static final String BACKUPTYPE_DISABLE = "disable.backups"; public static final String BACKUPTYPE_SPECIFY = "specify.backup.dir"; public static final String AUTOMATIC_BACKUP_DIRECTORY = "backups"; public static final String ATTACHMENT_STORAGE_FILE_SYSTEM = "file.system.based.attachments.storage"; public static final String ATTACHMENT_STORAGE_DATABASE = "database.based.attachments.storage"; public static final String ATTACHMENT_STORAGE_WEBDAV = "webdav.based.attachments.storage"; public static final String RESOURCES_DIR = "resources"; public static final String LOGS_DIR = "logs"; public static final String OSGI_PERSISTENT_CACHE_DIR = "plugins-osgi-cache"; public static final String BACKUP_SET_PATH_ALLOWED = "confluence.backup.path.set.allowed"; }
普通にtempとか書くよりも、ConfluenceHomeGlobalConstants.TEMP_DIRとか書くべき。
ConfluenceのHomeとかをとれるAtlassianBootstrapManager
atlassian-config/src/main/java/com/atlassian/config/bootstrap/AtlassianBootstrapManager.java
にある。
import com.atlassian.confluence.setup.BootstrapManager; import com.atlassian.config.util.BootstrapUtils; AtlassianBootstrapManager bm; bm = BootstrapUtils.getBootstrapManager();
で使える。
メソッドで取れる値の一覧
bootStrapManager.getApplicationHome() | Confluenceのデータディレクトリ |
---|---|
bootStrapManager.getConfiguredApplicationHome() | Confluenceのデータディレクトリ |
bootStrapManager.getFilePathProperty("foo") | null (何に使う?) |
bootStrapManager.getOperation() | null (何に使う?) |
bootStrapManager.getString("bar") | null (何に使う?) |
Confluenceのデータディレクトリが欲しいときは、getApplicationHome()で良いと思う。
ファイルアップロードを行った際のテンポラリファイルの場所
単一ファイルのアップロードの場合は、
を使う。
import com.atlassian.xwork.FileUploadUtils;
FileUploadUtils.UploadedFile uploadedFile;
upfile = FileUploadUtils.getSingleUploadedFile();
でアップロードしたファイルのオブジェクトupfileが取得できるので、これを使う。
メソッドで取れる値の一覧
この時点でアップロード処理が終わり、テンポラリディレクトリに乱数名でファイルが格納されている。
upfile.getAbsolutePath() | Confluenceのデータディレクトリ\temp\upload__5abd8926_146427cad1d__8000_00000030.tmp |
---|---|
upfile.getAbsoluteFile() | 上記のFileオブジェクト |
upfile.getCanonicalPath() | Confluenceのデータディレクトリ\temp\upload__5abd8926_146427cad1d__8000_00000030.tmp |
upfile.getCanonicalFile() | 上記のFileオブジェクト |
upfile.getName() | upload__5abd8926_146427cad1d__8000_00000030.tmp |
upfile.getParent() | Confluenceのデータディレクトリ\temp |
upfile.getParentFile() | 上記のFileオブジェクト |
upfile.getPath() | Confluenceのデータディレクトリ\temp\upload__5abd8926_146427cad1d__8000_00000030.tmp |
メインで使うのは、おそらくgetCanonicalPath(), getName()あたり。
ServletContextオブジェクトから取得
下記は、XWorkでServletContextを取得する場合。
import com.opensymphony.webwork.ServletActionContext; import javax.servlet.ServletContext; context = ServletActionContext.getServletContext(); directoryPath = context.getRealPath("/foo");
サーブレット内だとthis.getServletContext()で取得できる。
テンポラリディレクトリは何を使うべきか?
Atlassianの人がここで答えてる。
Store temporary files - Atlassian Answers
要は、JVMが与えてくれるディレクトリとかは使わないでBootstrapManager::getConfluenceHome() + "/temp"が一番良いんじゃないか?と。
その理由は、1日1回このディレクトリをクリーンにするタスクが走るからだそうな。なるほど。
追記:もうちょっとマシな取得方法
こんな感じ。
String attachmentDir = BootstrapUtils.getBootstrapManager().getFilePathProperty(ConfluenceBootstrapConstants.ATTACHMENTS_DIR_PROP);
ConfluenceBootstrapConstantsにより、取れるものが変わる。
public interface ConfluenceBootstrapConstants { String CONFLUENCE_HOME_CONSTANT = "${confluenceHome}"; // to be replaced by getFilePathProperty String LUCENE_INDEX_DIR_PROP = "lucene.index.dir"; String ATTACHMENTS_DIR_PROP = "attachments.dir"; String TEMP_DIR_PROP = "webwork.multipart.saveDir";//Because WW is looking for this directory to save the uploaded files (temporary) String LICENSE_HASH_KEY = "confluence.license.hash"; String LICENSE_MESSAGE_KEY = "confluence.license.message"; String WEBAPP_CONTEXT_PATH_KEY = "confluence.webapp.context.path"; //Macro manager keys String GLOBAL_PLUGIN_STATE = "confluence.plugin.state.global"; String DEFAULT_LICENSE_REGISTRY_KEY = "CONF"; String INSTALLATION_DATE_KEY = "confluence.server.installation.date"; }