Ejemplo n.º 1
0
  // FIXME: Perhaps this should fail somehow.
  public AttachmentManager(WikiEngine engine, Properties props) {
    String classname;

    m_engine = engine;

    //
    //  If user wants to use a cache, then we'll use the CachingProvider.
    //
    boolean useCache = "true".equals(props.getProperty(PageManager.PROP_USECACHE));

    if (useCache) {
      classname = "org.apache.wiki.providers.CachingAttachmentProvider";
    } else {
      classname = props.getProperty(PROP_PROVIDER);
    }

    //
    //  If no class defined, then will just simply fail.
    //
    if (classname == null) {
      log.info("No attachment provider defined - disabling attachment support.");
      return;
    }

    //
    //  Create and initialize the provider.
    //
    try {
      Class<?> providerclass = ClassUtil.findClass("org.apache.wiki.providers", classname);

      m_provider = (WikiAttachmentProvider) providerclass.newInstance();

      m_provider.initialize(m_engine, props);
    } catch (ClassNotFoundException e) {
      log.error("Attachment provider class not found", e);
    } catch (InstantiationException e) {
      log.error("Attachment provider could not be created", e);
    } catch (IllegalAccessException e) {
      log.error("You may not access the attachment provider class", e);
    } catch (NoRequiredPropertyException e) {
      log.error("Attachment provider did not find a property that it needed: " + e.getMessage(), e);
      m_provider = null; // No, it did not work.
    } catch (IOException e) {
      log.error("Attachment provider reports IO error", e);
      m_provider = null;
    }
  }