本文整理了Java中org.xwiki.environment.Environment.getResourceAsStream()
方法的一些代码示例,展示了Environment.getResourceAsStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.getResourceAsStream()
方法的具体详情如下:
包路径:org.xwiki.environment.Environment
类名称:Environment
方法名:getResourceAsStream
暂无
代码示例来源: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/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 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.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-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: 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-watchlist-api
sourceImageInputStream = environment.getResourceAsStream("/resources/icons/xwiki/noavatar.png");
内容来源于网络,如有侵权,请联系作者删除!