org.xwiki.environment.Environment.getResourceAsStream()方法的使用及代码示例

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

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

Environment.getResourceAsStream介绍

暂无

代码示例

代码示例来源: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/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 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.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-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: 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-watchlist-api

  1. sourceImageInputStream = environment.getResourceAsStream("/resources/icons/xwiki/noavatar.png");

相关文章