KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > visual > ReferenceBitmapLoader


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: ReferenceBitmapLoader.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.visual;
21
22 import java.awt.image.BufferedImage JavaDoc;
23 import java.io.File JavaDoc;
24
25 import org.apache.avalon.framework.configuration.Configurable;
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.apache.avalon.framework.configuration.ConfigurationException;
28
29 /**
30  * BitmapProducer implementation that simply loads preproduced reference bitmaps from a
31  * certain directory.
32  * <p>
33  * Here's what the configuration element looks like for the class:
34  * <p>
35  * <pre>
36  * <producer classname="org.apache.fop.visual.ReferenceBitmapLoader">
37  * <directory>C:/Temp/ref-bitmaps</directory>
38  * </producer>
39  * </pre>
40  */

41 public class ReferenceBitmapLoader extends AbstractBitmapProducer implements Configurable {
42
43     private File JavaDoc bitmapDirectory;
44     
45     /** @see org.apache.avalon.framework.configuration.Configurable */
46     public void configure(Configuration cfg) throws ConfigurationException {
47         this.bitmapDirectory = new File JavaDoc(cfg.getChild("directory").getValue(null));
48         if (!bitmapDirectory.exists()) {
49             throw new ConfigurationException("Directory could not be found: " + bitmapDirectory);
50         }
51     }
52
53     /** @see org.apache.fop.visual.BitmapProducer */
54     public BufferedImage JavaDoc produce(File JavaDoc src, ProducerContext context) {
55         try {
56             File JavaDoc bitmap = new File JavaDoc(bitmapDirectory, src.getName() + ".png");
57             if (bitmap.exists()) {
58                 return BitmapComparator.getImage(bitmap);
59             } else {
60                 return null;
61             }
62         } catch (Exception JavaDoc e) {
63             log.error(e);
64             return null;
65         }
66     }
67
68 }
69
Popular Tags