Beispiel #1
0
  /**
   * Adds an AU extension and associates it with the specified prefix, even before {@link
   * DHtmlUpdateServlet} is started.
   *
   * <p>Unlike {@link #addAuExtension(String, AuExtension)}, it can be called even if the update
   * servlet is not loaded yet ({@link #getUpdateServlet} returns null).
   *
   * <p>If there was an AU extension associated with the same name, the the old AU extension will be
   * replaced.
   *
   * @since 5.0.0
   */
  public static final AuExtension addAuExtension(WebApp wapp, String prefix, AuExtension extension)
      throws ServletException {
    DHtmlUpdateServlet upsv = DHtmlUpdateServlet.getUpdateServlet(wapp);
    if (upsv == null) {
      synchronized (DHtmlUpdateServlet.class) {
        upsv = DHtmlUpdateServlet.getUpdateServlet(wapp);
        if (upsv == null) {
          checkAuExtension(prefix, extension);
          Map aues = (Map) wapp.getAttribute(ATTR_AU_PROCESSORS);
          if (aues == null) wapp.setAttribute(ATTR_AU_PROCESSORS, aues = new HashMap(4));
          return (AuExtension) aues.put(prefix, extension);
        }
      }
    }

    return upsv.addAuExtension(prefix, extension);
  }
Beispiel #2
0
  /**
   * Adds an AU extension and associates it with the specified prefix.
   *
   * <p>If there was an AU extension associated with the same name, the the old AU extension will be
   * replaced.
   *
   * <p>If you want to add an Au extension, even before DHtmlUpdateServlet is started, use {@link
   * #addAuExtension(WebApp, String, AuExtension)} instead.
   *
   * @param prefix the prefix. It must start with "/", but it cannot be "/" nor "/web" (which are
   *     reserved).
   * @param extension the AU extension (never null).
   * @return the previous AU extension associated with the specified prefix, or null if the prefix
   *     was not associated before.
   * @see #addAuExtension(WebApp,String,AuExtension)
   * @since 5.0.0
   */
  public AuExtension addAuExtension(String prefix, AuExtension extension) throws ServletException {
    checkAuExtension(prefix, extension);

    if (_aues.get(prefix) == extension) // speed up to avoid sync
    return extension; // nothing changed

    extension.init(this);

    // To avoid using sync in doGet(), we make a copy here
    final AuExtension old;
    synchronized (this) {
      final Map ps = new HashMap(_aues);
      old = (AuExtension) ps.put(prefix, extension);
      _aues = ps;
    }
    if (old != null)
      try {
        old.destroy();
      } catch (Throwable ex) {
        log.warningBriefly("Unable to stop " + old, ex);
      }
    return old;
  }