本文整理了Java中org.xwiki.environment.Environment
类的一些代码示例,展示了Environment
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment
类的具体详情如下:
包路径:org.xwiki.environment.Environment
类名称:Environment
[英]Abstraction that represents an Environment (Java SE, Servlet, Portlet, etc) and provides API to access environment-related data.
[中]表示环境(JavaSE、Servlet、Portlet等)并提供API以访问与环境相关的数据的抽象。
代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-api
/**
* @return extension manage home folder
*/
public File getHome()
{
return new File(this.environment.getPermanentDirectory(), "extension/");
}
代码示例来源:origin: org.phenotips/xwiki-platform-svg
private File getBaseTempDir()
{
File tempDir = new File(new File(this.environment.getTemporaryDirectory(), "temp"), TEMP_DIR_NAME);
return tempDir;
}
代码示例来源:origin: phenotips/phenotips
@Override
public void initialize() throws InitializationException
{
InputStream data = null;
try {
data = this.environment.getResourceAsStream(XWIKI_CFG_FILE);
if (data != null) {
this.properties.load(data);
} else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_CFG_FILE available,
// in which case default values are used.
this.logger.debug("No configuration file [{}] found. Using default configuration values.",
XWIKI_CFG_FILE);
}
} catch (Exception ex) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
+ "Internal error [{}]", XWIKI_CFG_FILE, ex.getMessage());
}
}
代码示例来源:origin: org.phenotips/clinical-text-analysis-extension-biolark
final File biolarkRoot = new File(this.environment.getPermanentDirectory(), BiolarkWrapperImpl.ROOT_DIRECTORY);
final File biolarkProperties = new File(biolarkRoot, BiolarkWrapperImpl.PROPERTIES_FILENAME);
final File emptyDir = new File(biolarkRoot, BiolarkWrapperImpl.IO_FILENAME);
new File(this.environment.getTemporaryDirectory(), "biolark_resources.jar").getAbsolutePath();
File resources = BiolarkFileUtils.downloadFile(pathToArchive, BiolarkWrapperImpl.RESOURCE_FILES_URL);
BiolarkFileUtils.extractArchive(resources, biolarkRoot);
代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-api
@Override
public DefaultCoreExtension loadEnvironmentExtension(DefaultCoreExtensionRepository repository)
{
//////////
// XED
URL xedURL = this.environment.getResource("/META-INF/extension.xed");
if (xedURL != null) {
try (InputStream xedStream = this.environment.getResourceAsStream("/META-INF/extension.xed")) {
return this.parser.loadCoreExtensionDescriptor(repository, null, xedStream);
} catch (Exception e) {
this.logger.error("Failed to load [{}] descriptor file", xedURL, e);
}
}
//////////
// Others
for (ExtensionScanner scanner : this.scanners) {
DefaultCoreExtension environmentExtension = scanner.scanEnvironment(repository);
if (environmentExtension != null) {
return environmentExtension;
}
}
//////////
// Could not find any valid descriptor
this.logger.debug("No declared environmennt extension");
return null;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-configuration-default
xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
if (xwikiPropertiesUrl != null) {
this.logger.info("loading {} from {}", XWIKI_PROPERTIES_FILE, xwikiPropertiesUrl.toExternalForm());
代码示例来源:origin: org.xwiki.platform/xwiki-platform-store-filesystem-oldcore
@Override
public void initialize() throws InitializationException
{
this.pre11StoreRootDirectory = new File(this.environment.getPermanentDirectory(), "storage");
this.storeRootDirectory = this.pre11StoreRootDirectory;
}
代码示例来源:origin: phenotips/phenotips
private File getBaseTempDir()
{
File tempDir = new File(new File(this.environment.getTemporaryDirectory(), "temp"), TEMP_DIR_NAME);
return tempDir;
}
代码示例来源:origin: org.phenotips/storage-migrators-api
@Override
public void initialize() throws InitializationException
{
InputStream data = null;
try {
data = this.environment.getResourceAsStream(XWIKI_CFG_FILE);
if (data != null) {
this.properties.load(data);
} else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_CFG_FILE available,
// in which case default values are used.
this.logger.debug("No configuration file [{}] found. Using default configuration values.",
XWIKI_CFG_FILE);
}
} catch (Exception ex) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
+ "Internal error [{}]", XWIKI_CFG_FILE, ex.getMessage());
}
}
代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-api
@Override
public void initialize() throws InitializationException
{
File permanentDirectory = this.environment.getPermanentDirectory();
if (permanentDirectory != null) {
this.folder = new File(permanentDirectory, "cache/extension/core/");
}
}
代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-repository-maven
public File createTemporaryFile(String prefix, String suffix) throws IOException
{
Path filesDirectory = this.environment.getTemporaryDirectory().toPath().resolve("extension/download/files/");
Files.createDirectories(filesDirectory);
return Files.createTempFile(filesDirectory, prefix, suffix).toFile();
}
}
代码示例来源:origin: org.xwiki.contrib/xwiki-platform-cloud-configuration-default
/**
* Load remapping definitions from the remapping file and provide them as a configuration source.
*
* @return A configuration source containing the remappings. null if the file is not present.
* @throws Exception if there is an error loading the file.
*/
private ConfigurationSource loadRemappings() throws Exception
{
InputStream is = this.environment.getResourceAsStream(REMAPPING_FILE);
if (is == null) {
return null;
}
Properties properties = new Properties();
try {
properties.load(is);
} catch (Exception e) {
throw new InitializationException(String.format("Unable to read %s", REMAPPING_FILE), e);
}
BaseConfiguration configuration = new BaseConfiguration();
for (String key : properties.stringPropertyNames()) {
configuration.setProperty(key, properties.get(key));
}
CommonsConfigurationSource commonsConfigurationSource = new CommonsConfigurationSource();
commonsConfigurationSource.setConfiguration(configuration);
return commonsConfigurationSource;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-search-solr-api
/**
* @return the default home directory located inside the environment's permanent directory.
*/
String getDefaultHomeDirectory()
{
String result = new File(this.environment.getPermanentDirectory(), DEFAULT_SOLR_DIRECTORY_NAME).getPath();
return result;
}
}
代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-repository-maven
@Override
public File getLocalRepository()
{
String localRepositoryPath =
this.configurationSourceProvider.get().getProperty("extension.aether.localRepository");
File directory;
if (localRepositoryPath == null) {
directory = new File(this.environment.getTemporaryDirectory(), "aether-repository");
} else {
directory = new File(localRepositoryPath);
}
return directory;
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-observation-remote
/**
* Load channel configuration.
*
* @param channelId the identifier of the channel
* @return the channel configuration
* @throws IOException failed to load configuration file
*/
private ProtocolStackConfigurator loadChannelConfiguration(String channelId) throws IOException
{
String channelFile = channelId + ".xml";
String path = "/WEB-INF/" + CONFIGURATION_PATH + channelFile;
InputStream is = null;
try {
Environment environment = this.componentManager.getInstance(Environment.class);
is = environment.getResourceAsStream(path);
} catch (ComponentLookupException e) {
// Environment not found, continue by fallbacking on JGroups's standard configuration.
this.logger.debug("Failed to lookup the Environment component.", e);
}
if (is == null) {
// Fallback on JGroups standard configuration locations
is = ConfiguratorFactory.getConfigStream(channelFile);
if (is == null && !Global.DEFAULT_PROTOCOL_STACK.equals(channelFile)) {
// Fallback on default JGroups configuration
is = ConfiguratorFactory.getConfigStream(Global.DEFAULT_PROTOCOL_STACK);
}
}
return XmlConfigurator.getInstance(is);
}
代码示例来源:origin: edu.toronto.cs.phenotips/phenotype-mapping-service
protected File getInternalFile(String name, String dir)
{
File parent = new File(this.environment.getPermanentDirectory(), dir);
if (!parent.exists()) {
parent.mkdirs();
}
return new File(parent, name);
}
代码示例来源:origin: phenotips/phenotips
/**
* Convert a stream into a file.
*
* @param in an inputstream
* @return a File
* @throws IOException when we can't open file
*/
private File stream2file(InputStream in, String nameRoot) throws IOException
{
File tempDir = this.env.getTemporaryDirectory();
final File tempFile;
if (tempDir != null) {
tempFile = new File(tempDir, String.format("phenotips_boqa_%s.tmp", nameRoot));
} else {
tempFile = File.createTempFile("phenotips_boqa", ".tmp");
}
tempFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);
return tempFile;
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-resource-default
@Override
public void initialize() throws InitializationException
{
// Parse the Struts config file (struts-config.xml) to extract all available actions
List<String> actionNames = new ArrayList<>();
// Step 1: Get a stream on the Struts config file if it exists
InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
if (strutsConfigStream != null) {
// Step 2: Parse the Strust config file, looking for action names
Document document;
try {
document = createSAXBuilder().build(strutsConfigStream);
} catch (JDOMException | IOException e) {
throw new InitializationException(
String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
}
Element mappingElement = document.getRootElement().getChild("action-mappings");
for (Element element : mappingElement.getChildren("action")) {
// We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
// it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
// "name" element value.
actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
}
}
this.strutsActionNames = actionNames;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-search-lucene-api
/**
* @return the Lucene work directory where to store Lucene index files
*/
private File getLuceneWorkDirectory()
{
File dir = new File(this.environment.getPermanentDirectory().getAbsolutePath(), "lucene");
if (!dir.exists()) {
dir.mkdir();
}
return dir;
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-cache-api
/**
* @return the path of the temporary local folder based on configuration identifier
*/
protected String createTempDir()
{
String path = (String) this.configuration.get(CONFX_CACHE_PATH);
if (path == null) {
File file;
if (this.environment != null) {
file = new File(this.environment.getTemporaryDirectory().getAbsolutePath(), "cache");
} else {
file = new File(System.getProperty("java.io.tmpdir"), "xwiki");
}
if (this.configuration.getConfigurationId() == null) {
file = new File(file, this.configuration.getConfigurationId());
}
if (!file.exists()) {
file.mkdirs();
}
path = file.getAbsolutePath();
}
return path;
}
内容来源于网络,如有侵权,请联系作者删除!