/*
 * Copyright 2011 Wyona
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.wyona.yanel.impl.workflow;

import org.wyona.yanel.core.api.attributes.WorkflowableV1;
import org.wyona.yanel.core.workflow.Action;
import org.wyona.yanel.core.workflow.Workflow;
import org.wyona.yanel.core.workflow.WorkflowException;

import org.apache.log4j.Logger;

/**
 * Send notifications via email
 */
public class EmailAction implements Action {

    private static Logger log = Logger.getLogger(EmailAction.class);

    private String expression;

    /**
     * @see org.wyona.yanel.core.workflow.Action#setExpression(String)
     */
    public void setExpression(String expression) {
        this.expression = expression;
    }

    /**
     * @see org.wyona.yanel.core.workflow.Action#execute(WorkflowableV1, Workflow, String)
     */
    public void execute(WorkflowableV1 workflowable, Workflow workflow, String revision) throws WorkflowException {
        log.warn("Send emails to: " + expression);
    }
}

@@ -1472,16 +1472,179 @@
 ption %7B%0A
+        String%5B%5D emailAddresses = getEmailAddresses();%0A        if (emailAddresses != null) %7B%0A            for (int i = 0; i %3C emailAddresses.length; i++) %7B%0A        
         
@@ -1663,17 +1663,16 @@
 nd email
-s
  to: %22 +
@@ -1677,19 +1677,780 @@
  + e
-xpression);
+mailAddresses%5Bi%5D);%0A            %7D%0A        %7D else %7B%0A            throw new WorkflowException(%22No email addresses!%22);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Get email addresses%0A     */%0A    private String%5B%5D getEmailAddresses() throws WorkflowException %7B%0A        if (expression != null) %7B%0A            String%5B%5D ea = expression.split(%22,%22);%0A            String%5B%5D emails = new String%5Bea.length%5D; // TODO: Make more fault tolerant%0A            for(int i = 0; i %3C ea.length; i++) %7B%0A                if (ea%5Bi%5D.indexOf(%22@%22) %3C 1) %7B%0A                    throw new WorkflowException(%22No such email address: %22 + ea%5Bi%5D);%0A                %7D else %7B%0A                    emails%5Bi%5D = ea%5Bi%5D.trim();%0A                %7D%0A            %7D%0A            return emails;%0A        %7D else %7B%0A            return null;%0A        %7D
 %0A   

parse email addresses