use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.
the class DefaultRemoteObservationManager method initialize.
@Override
public void initialize() throws InitializationException {
try {
String networkAdapterHint = this.configuration.getNetworkAdapter();
this.networkAdapter = this.componentManager.getInstance(NetworkAdapter.class, networkAdapterHint);
} catch (ComponentLookupException e) {
throw new InitializationException("Failed to initialize network adapter [" + this.configuration.getNetworkAdapter() + "]", e);
}
// Start configured channels and register them against the JMX server
for (String channelId : this.configuration.getChannels()) {
try {
startChannel(channelId);
} catch (RemoteEventException e) {
this.logger.error("Failed to start channel [" + channelId + "]", e);
}
}
}
use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.
the class DefaultEntityResourceActionLister method initialize.
@Override
public void initialize() throws InitializationException {
// Parse the Struts config file (struts-config.xml) to extract all available actions
List<String> actionNames = new ArrayList<>();
SAXBuilder builder = new SAXBuilder();
// Make sure we don't require an Internet Connection to parse the Struts config file!
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
// 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 = builder.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;
}
use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.
the class DefaultOfficeResourceViewer method initialize.
@Override
public void initialize() throws InitializationException {
try {
LRUCacheConfiguration attachmentConfig = new LRUCacheConfiguration(MODULE_NAME + ".attachment", 50);
this.attachmentCache = this.cacheManager.createNewCache(attachmentConfig);
// We have no idea when to invalidate the cache so lets at least put a time to live
LRUCacheConfiguration exteralConfig = new LRUCacheConfiguration(MODULE_NAME + ".external", 50, 3600);
this.externalCache = this.cacheManager.createNewCache(exteralConfig);
} catch (CacheException e) {
throw new InitializationException("Failed to create caches.", e);
}
}
use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.
the class StandardExtendedURLResourceTypeResolver method registerEntityResourceReferenceResolver.
private void registerEntityResourceReferenceResolver(String registrationHint, Class<? extends ResourceReferenceResolver<ExtendedURL>> registrationImplementation, String wikiExtractorHint) throws InitializationException {
DefaultComponentDescriptor<ResourceReferenceResolver<ExtendedURL>> resolverDescriptor = new DefaultComponentDescriptor<>();
resolverDescriptor.setImplementation(registrationImplementation);
resolverDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON);
String hint = computeHint(registrationHint);
resolverDescriptor.setRoleHint(hint);
resolverDescriptor.setRoleType(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class));
// Register dependencies
DefaultComponentDependency<WikiReferenceExtractor> wikiReferenceExtractorDependency = new DefaultComponentDependency<>();
wikiReferenceExtractorDependency.setRoleType(WikiReferenceExtractor.class);
wikiReferenceExtractorDependency.setRoleHint(wikiExtractorHint);
wikiReferenceExtractorDependency.setName("wikiExtractor");
resolverDescriptor.addComponentDependency(wikiReferenceExtractorDependency);
DefaultComponentDependency<EntityReferenceResolver<EntityReference>> entityReferenceResolverDependency = new DefaultComponentDependency<>();
entityReferenceResolverDependency.setRoleType(new DefaultParameterizedType(null, EntityReferenceResolver.class, EntityReference.class));
entityReferenceResolverDependency.setName("defaultReferenceEntityReferenceResolver");
resolverDescriptor.addComponentDependency(entityReferenceResolverDependency);
DefaultComponentDependency<StandardURLConfiguration> standardURLConfigurationDependency = new DefaultComponentDependency<>();
standardURLConfigurationDependency.setRoleType(StandardURLConfiguration.class);
standardURLConfigurationDependency.setName("configuration");
resolverDescriptor.addComponentDependency(standardURLConfigurationDependency);
DefaultComponentDependency<EntityResourceActionLister> entityResourceActionListerDependency = new DefaultComponentDependency<>();
entityResourceActionListerDependency.setRoleType(EntityResourceActionLister.class);
entityResourceActionListerDependency.setName("entityResourceActionLister");
resolverDescriptor.addComponentDependency(entityResourceActionListerDependency);
try {
this.rootComponentManager.registerComponent(resolverDescriptor);
} catch (ComponentRepositoryException e) {
throw new InitializationException(String.format("Failed to dynamically register Resource Reference Resolver for hint [%s]", hint), e);
}
}
use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.
the class PygmentsParser method initialize.
@Override
public void initialize() throws InitializationException {
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
// Get the script
InputStream is = getClass().getResourceAsStream("/pygments/code.py");
if (is != null) {
try {
this.script = IOUtils.toString(is, "UTF8");
} catch (Exception e) {
throw new InitializationException("Failed to read resource /pygments/code.py resource", e);
} finally {
IOUtils.closeQuietly(is);
}
} else {
throw new InitializationException("Failed to find resource /pygments/code.py resource");
}
// Get the Python engine
this.engine = scriptEngineManager.getEngineByName(ENGINE_ID);
if (this.engine == null) {
throw new InitializationException("Failed to find engine for Python script language");
}
String highlightSyntaxId = getSyntaxId() + "-highlight";
this.syntax = new Syntax(new SyntaxType(highlightSyntaxId, highlightSyntaxId), "1.0");
}
Aggregations