Search in sources :

Example 1 with InitializationException

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);
        }
    }
}
Also used : NetworkAdapter(org.xwiki.observation.remote.NetworkAdapter) RemoteEventException(org.xwiki.observation.remote.RemoteEventException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 2 with InitializationException

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;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InitializationException(org.xwiki.component.phase.InitializationException) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader)

Example 3 with InitializationException

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);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) InitializationException(org.xwiki.component.phase.InitializationException) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Example 4 with InitializationException

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);
    }
}
Also used : DefaultComponentDependency(org.xwiki.component.descriptor.DefaultComponentDependency) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) BinEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver) ResourceReferenceResolver(org.xwiki.resource.ResourceReferenceResolver) WikiEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver) ComponentRepositoryException(org.xwiki.component.manager.ComponentRepositoryException) ExtendedURL(org.xwiki.url.ExtendedURL) InitializationException(org.xwiki.component.phase.InitializationException) EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) EntityReference(org.xwiki.model.reference.EntityReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 5 with InitializationException

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");
}
Also used : InputStream(java.io.InputStream) ScriptEngineManager(javax.script.ScriptEngineManager) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) InitializationException(org.xwiki.component.phase.InitializationException) Syntax(org.xwiki.rendering.syntax.Syntax) ParseException(org.xwiki.rendering.parser.ParseException) InitializationException(org.xwiki.component.phase.InitializationException) ScriptException(javax.script.ScriptException) IOException(java.io.IOException)

Aggregations

InitializationException (org.xwiki.component.phase.InitializationException)24 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)9 CacheException (org.xwiki.cache.CacheException)8 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)8 IOException (java.io.IOException)4 CacheFactory (org.xwiki.cache.CacheFactory)4 InputStream (java.io.InputStream)3 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)3 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)2 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)2 CompositeFilterStreamDescriptor (org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor)2 FilterStreamDescriptor (org.xwiki.filter.descriptor.FilterStreamDescriptor)2 EntityReference (org.xwiki.model.reference.EntityReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1