package com.lowagie.text.html.simpleparser;

import java.io.*;
import java.net.MalformedURLException;
import java.util.*;

import com.lowagie.text.*;

public class DefaultImageProvider implements ImageProvider {
    private HTMLWorker worker;

    public DefaultImageProvider(HTMLWorker worker) {
	this.worker = worker;
    }

    public Image getImage(String src) throws BadElementException, MalformedURLException, IOException {
	Map interfaceProps = worker.getInterfaceProps();
	
	Image img = null;
	
        if (interfaceProps != null) {
            HashMap images = (HashMap)interfaceProps.get("img_static");
            if (images != null) {
                Image tim = (Image)images.get(src);
                if (tim != null)
                    img = Image.getInstance(tim);
            } else {
                if (!src.startsWith("http")) { // relative src references only
                    String baseurl = (String)interfaceProps.get("img_baseurl");
                    if (baseurl != null) {
                        src = baseurl+src;
                        img = Image.getInstance(src);
                    }
                }
            }
        }
//        if (img == null) {
//            if (!src.startsWith("http")) {
//                String path = cprops.getProperty("image_path");
//                if (path == null)
//                    path = "";
//                src = new File(path, src).getPath();
//            }
//            img = Image.getInstance(src);
//        }
        return img;
    }
}
