@@ -0,0 +1,3030 @@
+/*%0A * Copyright 2014 Wyona%0A */%0Apackage org.wyona.yanel.impl.resources.mailman;%0A%0Aimport org.wyona.yanel.impl.resources.BasicXMLResource;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.InputStream;%0A%0Aimport org.apache.logging.log4j.Logger;%0Aimport org.apache.logging.log4j.LogManager;%0A%0A/**%0A * Get email, password and list names in order to subscribe user to various mailman mailing lists%0A */%0Apublic class SubscribeToMailmanResourceV100 extends BasicXMLResource %7B%0A    %0A    private static Logger log = LogManager.getLogger(SubscribeToMailmanResourceV100.class);%0A    %0A    /**%0A     * @see org.wyona.yanel.impl.resources.BasicXMLResource#getContentXML(String)%0A     */%0A    @Override%0A    protected InputStream getContentXML(String viewId) throws Exception %7B%0A        if (log.isDebugEnabled()) %7B%0A            log.debug(%22requested viewId: %22 + viewId);%0A        %7D%0A%0A        StringBuilder sb = new StringBuilder(%22%3C?xml version=%5C%221.0%5C%22?%3E%22);%0A%0A        String email = getEnvironment().getRequest().getParameter(%22email%22);%0A        if (email != null) %7B%0A            String password = getEnvironment().getRequest().getParameter(%22password%22);%0A            String passwordConfirmed = getEnvironment().getRequest().getParameter(%22password-confirmed%22);%0A            if (passwordsMatch(password, passwordConfirmed)) %7B%0A                subscribeToMailman(email, password);%0A                sb.append(%22%3Csubscribe-to-mailman%3E%22);%0A                sb.append(%22  %3Csuccess/%3E%22);%0A                sb.append(%22%3C/subscribe-to-mailman%3E%22);%0A            %7D else %7B%0A                sb.append(%22%3Csubscribe-to-mailman%3E%22);%0A                sb.append(%22  %3Cexception message=%5C%22passwords did not match%5C%22/%3E%22);%0A                sb.append(%22%3C/subscribe-to-mailman%3E%22);%0A            %7D%0A        %7D else %7B%0A            sb.append(%22%3Csubscribe-to-mailman/%3E%22);%0A        %7D%0A%0A        return new ByteArrayInputStream(sb.toString().getBytes());%0A    %7D%0A%0A    /**%0A     * @param email E-Mail address of user%0A     * @param password Password of user%0A     */%0A    private void subscribeToMailman(String email, String password) %7B%0A        log.warn(%22DEBUG: Subscribe user '%22 + email + %22' to mailman ...%22);%0A        java.util.Enumeration%3CString%3E paras = getEnvironment().getRequest().getParameterNames();%0A        while(paras.hasMoreElements()) %7B%0A            String para = paras.nextElement().toString();%0A            if (para.startsWith(%22list-%22)) %7B%0A                String listname = para.substring(5);%0A                log.warn(%22DEBUG: Subscribe to list '%22 + listname + %22' ...%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * Check whether passwords match%0A     * @param password User password%0A     * @param passwordConfirmed Confirmed user password%0A     * @return true when passwords match and false otherwise%0A     */%0A    private boolean passwordsMatch(String password, String passwordConfirmed) %7B%0A        if (password != null && passwordConfirmed != null && password.equals(passwordConfirmed)) %7B%0A            return true;%0A        %7D else %7B%0A            log.warn(%22Passwords did not match!%22);%0A            return false;%0A        %7D%0A    %7D%0A%7D%0A

check passwords and loop over mailing list names