org.xwiki.environment.Environment类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.xwiki.environment.Environment类的一些代码示例,展示了Environment类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment类的具体详情如下:
包路径:org.xwiki.environment.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

  1. /**
  2. * @return extension manage home folder
  3. */
  4. public File getHome()
  5. {
  6. return new File(this.environment.getPermanentDirectory(), "extension/");
  7. }

代码示例来源:origin: org.phenotips/xwiki-platform-svg

  1. private File getBaseTempDir()
  2. {
  3. File tempDir = new File(new File(this.environment.getTemporaryDirectory(), "temp"), TEMP_DIR_NAME);
  4. return tempDir;
  5. }

代码示例来源:origin: phenotips/phenotips

  1. @Override
  2. public void initialize() throws InitializationException
  3. {
  4. InputStream data = null;
  5. try {
  6. data = this.environment.getResourceAsStream(XWIKI_CFG_FILE);
  7. if (data != null) {
  8. this.properties.load(data);
  9. } else {
  10. // We use a debug logging level here since we consider it's ok that there's no XWIKI_CFG_FILE available,
  11. // in which case default values are used.
  12. this.logger.debug("No configuration file [{}] found. Using default configuration values.",
  13. XWIKI_CFG_FILE);
  14. }
  15. } catch (Exception ex) {
  16. // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
  17. // will use default values for all configurable elements.
  18. this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
  19. + "Internal error [{}]", XWIKI_CFG_FILE, ex.getMessage());
  20. }
  21. }

代码示例来源:origin: org.phenotips/clinical-text-analysis-extension-biolark

  1. final File biolarkRoot = new File(this.environment.getPermanentDirectory(), BiolarkWrapperImpl.ROOT_DIRECTORY);
  2. final File biolarkProperties = new File(biolarkRoot, BiolarkWrapperImpl.PROPERTIES_FILENAME);
  3. final File emptyDir = new File(biolarkRoot, BiolarkWrapperImpl.IO_FILENAME);
  4. new File(this.environment.getTemporaryDirectory(), "biolark_resources.jar").getAbsolutePath();
  5. File resources = BiolarkFileUtils.downloadFile(pathToArchive, BiolarkWrapperImpl.RESOURCE_FILES_URL);
  6. BiolarkFileUtils.extractArchive(resources, biolarkRoot);

代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-api

  1. @Override
  2. public DefaultCoreExtension loadEnvironmentExtension(DefaultCoreExtensionRepository repository)
  3. {
  4. //////////
  5. // XED
  6. URL xedURL = this.environment.getResource("/META-INF/extension.xed");
  7. if (xedURL != null) {
  8. try (InputStream xedStream = this.environment.getResourceAsStream("/META-INF/extension.xed")) {
  9. return this.parser.loadCoreExtensionDescriptor(repository, null, xedStream);
  10. } catch (Exception e) {
  11. this.logger.error("Failed to load [{}] descriptor file", xedURL, e);
  12. }
  13. }
  14. //////////
  15. // Others
  16. for (ExtensionScanner scanner : this.scanners) {
  17. DefaultCoreExtension environmentExtension = scanner.scanEnvironment(repository);
  18. if (environmentExtension != null) {
  19. return environmentExtension;
  20. }
  21. }
  22. //////////
  23. // Could not find any valid descriptor
  24. this.logger.debug("No declared environmennt extension");
  25. return null;
  26. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-configuration-default

  1. xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
  2. if (xwikiPropertiesUrl != null) {
  3. this.logger.info("loading {} from {}", XWIKI_PROPERTIES_FILE, xwikiPropertiesUrl.toExternalForm());

代码示例来源:origin: org.xwiki.platform/xwiki-platform-store-filesystem-oldcore

  1. @Override
  2. public void initialize() throws InitializationException
  3. {
  4. this.pre11StoreRootDirectory = new File(this.environment.getPermanentDirectory(), "storage");
  5. this.storeRootDirectory = this.pre11StoreRootDirectory;
  6. }

代码示例来源:origin: phenotips/phenotips

  1. private File getBaseTempDir()
  2. {
  3. File tempDir = new File(new File(this.environment.getTemporaryDirectory(), "temp"), TEMP_DIR_NAME);
  4. return tempDir;
  5. }

代码示例来源:origin: org.phenotips/storage-migrators-api

  1. @Override
  2. public void initialize() throws InitializationException
  3. {
  4. InputStream data = null;
  5. try {
  6. data = this.environment.getResourceAsStream(XWIKI_CFG_FILE);
  7. if (data != null) {
  8. this.properties.load(data);
  9. } else {
  10. // We use a debug logging level here since we consider it's ok that there's no XWIKI_CFG_FILE available,
  11. // in which case default values are used.
  12. this.logger.debug("No configuration file [{}] found. Using default configuration values.",
  13. XWIKI_CFG_FILE);
  14. }
  15. } catch (Exception ex) {
  16. // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
  17. // will use default values for all configurable elements.
  18. this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
  19. + "Internal error [{}]", XWIKI_CFG_FILE, ex.getMessage());
  20. }
  21. }

代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-api

  1. @Override
  2. public void initialize() throws InitializationException
  3. {
  4. File permanentDirectory = this.environment.getPermanentDirectory();
  5. if (permanentDirectory != null) {
  6. this.folder = new File(permanentDirectory, "cache/extension/core/");
  7. }
  8. }

代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-repository-maven

  1. public File createTemporaryFile(String prefix, String suffix) throws IOException
  2. {
  3. Path filesDirectory = this.environment.getTemporaryDirectory().toPath().resolve("extension/download/files/");
  4. Files.createDirectories(filesDirectory);
  5. return Files.createTempFile(filesDirectory, prefix, suffix).toFile();
  6. }
  7. }

代码示例来源:origin: org.xwiki.contrib/xwiki-platform-cloud-configuration-default

  1. /**
  2. * Load remapping definitions from the remapping file and provide them as a configuration source.
  3. *
  4. * @return A configuration source containing the remappings. null if the file is not present.
  5. * @throws Exception if there is an error loading the file.
  6. */
  7. private ConfigurationSource loadRemappings() throws Exception
  8. {
  9. InputStream is = this.environment.getResourceAsStream(REMAPPING_FILE);
  10. if (is == null) {
  11. return null;
  12. }
  13. Properties properties = new Properties();
  14. try {
  15. properties.load(is);
  16. } catch (Exception e) {
  17. throw new InitializationException(String.format("Unable to read %s", REMAPPING_FILE), e);
  18. }
  19. BaseConfiguration configuration = new BaseConfiguration();
  20. for (String key : properties.stringPropertyNames()) {
  21. configuration.setProperty(key, properties.get(key));
  22. }
  23. CommonsConfigurationSource commonsConfigurationSource = new CommonsConfigurationSource();
  24. commonsConfigurationSource.setConfiguration(configuration);
  25. return commonsConfigurationSource;
  26. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-search-solr-api

  1. /**
  2. * @return the default home directory located inside the environment's permanent directory.
  3. */
  4. String getDefaultHomeDirectory()
  5. {
  6. String result = new File(this.environment.getPermanentDirectory(), DEFAULT_SOLR_DIRECTORY_NAME).getPath();
  7. return result;
  8. }
  9. }

代码示例来源:origin: org.xwiki.commons/xwiki-commons-extension-repository-maven

  1. @Override
  2. public File getLocalRepository()
  3. {
  4. String localRepositoryPath =
  5. this.configurationSourceProvider.get().getProperty("extension.aether.localRepository");
  6. File directory;
  7. if (localRepositoryPath == null) {
  8. directory = new File(this.environment.getTemporaryDirectory(), "aether-repository");
  9. } else {
  10. directory = new File(localRepositoryPath);
  11. }
  12. return directory;
  13. }
  14. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-observation-remote

  1. /**
  2. * Load channel configuration.
  3. *
  4. * @param channelId the identifier of the channel
  5. * @return the channel configuration
  6. * @throws IOException failed to load configuration file
  7. */
  8. private ProtocolStackConfigurator loadChannelConfiguration(String channelId) throws IOException
  9. {
  10. String channelFile = channelId + ".xml";
  11. String path = "/WEB-INF/" + CONFIGURATION_PATH + channelFile;
  12. InputStream is = null;
  13. try {
  14. Environment environment = this.componentManager.getInstance(Environment.class);
  15. is = environment.getResourceAsStream(path);
  16. } catch (ComponentLookupException e) {
  17. // Environment not found, continue by fallbacking on JGroups's standard configuration.
  18. this.logger.debug("Failed to lookup the Environment component.", e);
  19. }
  20. if (is == null) {
  21. // Fallback on JGroups standard configuration locations
  22. is = ConfiguratorFactory.getConfigStream(channelFile);
  23. if (is == null && !Global.DEFAULT_PROTOCOL_STACK.equals(channelFile)) {
  24. // Fallback on default JGroups configuration
  25. is = ConfiguratorFactory.getConfigStream(Global.DEFAULT_PROTOCOL_STACK);
  26. }
  27. }
  28. return XmlConfigurator.getInstance(is);
  29. }

代码示例来源:origin: edu.toronto.cs.phenotips/phenotype-mapping-service

  1. protected File getInternalFile(String name, String dir)
  2. {
  3. File parent = new File(this.environment.getPermanentDirectory(), dir);
  4. if (!parent.exists()) {
  5. parent.mkdirs();
  6. }
  7. return new File(parent, name);
  8. }

代码示例来源:origin: phenotips/phenotips

  1. /**
  2. * Convert a stream into a file.
  3. *
  4. * @param in an inputstream
  5. * @return a File
  6. * @throws IOException when we can't open file
  7. */
  8. private File stream2file(InputStream in, String nameRoot) throws IOException
  9. {
  10. File tempDir = this.env.getTemporaryDirectory();
  11. final File tempFile;
  12. if (tempDir != null) {
  13. tempFile = new File(tempDir, String.format("phenotips_boqa_%s.tmp", nameRoot));
  14. } else {
  15. tempFile = File.createTempFile("phenotips_boqa", ".tmp");
  16. }
  17. tempFile.deleteOnExit();
  18. FileOutputStream out = new FileOutputStream(tempFile);
  19. IOUtils.copy(in, out);
  20. return tempFile;
  21. }
  22. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-resource-default

  1. @Override
  2. public void initialize() throws InitializationException
  3. {
  4. // Parse the Struts config file (struts-config.xml) to extract all available actions
  5. List<String> actionNames = new ArrayList<>();
  6. // Step 1: Get a stream on the Struts config file if it exists
  7. InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
  8. if (strutsConfigStream != null) {
  9. // Step 2: Parse the Strust config file, looking for action names
  10. Document document;
  11. try {
  12. document = createSAXBuilder().build(strutsConfigStream);
  13. } catch (JDOMException | IOException e) {
  14. throw new InitializationException(
  15. String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
  16. }
  17. Element mappingElement = document.getRootElement().getChild("action-mappings");
  18. for (Element element : mappingElement.getChildren("action")) {
  19. // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
  20. // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
  21. // "name" element value.
  22. actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
  23. }
  24. }
  25. this.strutsActionNames = actionNames;
  26. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-search-lucene-api

  1. /**
  2. * @return the Lucene work directory where to store Lucene index files
  3. */
  4. private File getLuceneWorkDirectory()
  5. {
  6. File dir = new File(this.environment.getPermanentDirectory().getAbsolutePath(), "lucene");
  7. if (!dir.exists()) {
  8. dir.mkdir();
  9. }
  10. return dir;
  11. }
  12. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-cache-api

  1. /**
  2. * @return the path of the temporary local folder based on configuration identifier
  3. */
  4. protected String createTempDir()
  5. {
  6. String path = (String) this.configuration.get(CONFX_CACHE_PATH);
  7. if (path == null) {
  8. File file;
  9. if (this.environment != null) {
  10. file = new File(this.environment.getTemporaryDirectory().getAbsolutePath(), "cache");
  11. } else {
  12. file = new File(System.getProperty("java.io.tmpdir"), "xwiki");
  13. }
  14. if (this.configuration.getConfigurationId() == null) {
  15. file = new File(file, this.configuration.getConfigurationId());
  16. }
  17. if (!file.exists()) {
  18. file.mkdirs();
  19. }
  20. path = file.getAbsolutePath();
  21. }
  22. return path;
  23. }

相关文章