ch.unifr.diuf.diva.did.commands.DeleteImage.java Source code

Java tutorial

Introduction

Here is the source code for ch.unifr.diuf.diva.did.commands.DeleteImage.java

Source

/*****************************************************
  DIVADid
      
  A document image degradation method.
  ------------------------------
  Author:
  2015 by Mathias Seuret <mathias.seuret@unifr.ch>
  -------------------
    
  This software is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation version 3.
    
  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
    
  You should have received a copy of the GNU Lesser General Public
  License along with this software; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 ******************************************************************************/
package ch.unifr.diuf.diva.did.commands;

import ch.unifr.diuf.diva.did.Script;
import java.io.IOException;
import org.jdom2.Element;
import org.jdom2.JDOMException;

/**
 *
 * @author Mathias Seuret
 */
public class DeleteImage extends AbstractCommand {

    public DeleteImage(Script script) {
        super(script);
    }

    @Override
    public float execute(Element task) throws IOException, JDOMException, InterruptedException {
        String refName = task.getAttributeValue("ref");
        if (refName == null) {
            throw new IllegalArgumentException("\n" + commandName + ": ref is required");
        }
        refName = script.preprocess(refName);

        if (!script.getImages().containsKey(refName)) {
            throw new IllegalArgumentException("\n" + commandName + ": cannot find ref image " + refName);
        }

        script.getImages().remove(refName);

        return 0;
    }

}