KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > plan > PlanElementMapping


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: PlanElementMapping.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.plan;
21
22 import org.apache.fop.fo.FONode;
23 import org.apache.fop.fo.ElementMapping;
24 import org.apache.fop.image.analyser.XMLReader;
25 import org.apache.fop.image.FopImage;
26 import org.w3c.dom.DOMImplementation JavaDoc;
27 import org.w3c.dom.Document JavaDoc;
28
29 /**
30  * This class provides the element mapping for FOP.
31  */

32 public class PlanElementMapping extends ElementMapping {
33
34     /** Plan Namespace */
35     public static final String JavaDoc NAMESPACE = "http://xmlgraphics.apache.org/fop/plan";
36
37     /** Main constructor. */
38     public PlanElementMapping() {
39         this.namespaceURI = NAMESPACE;
40     }
41
42     /** @see org.apache.fop.fo.ElementMapping#getDOMImplementation() */
43     public DOMImplementation JavaDoc getDOMImplementation() {
44         return getDefaultDOMImplementation();
45     }
46
47     /** @see org.apache.fop.fo.ElementMapping#initialize() */
48     protected void initialize() {
49         if (foObjs == null) {
50             foObjs = new java.util.HashMap JavaDoc();
51             foObjs.put("plan", new PE());
52             foObjs.put(DEFAULT, new PlanMaker());
53
54             XMLReader.setConverter(this.namespaceURI, new PlanConverter());
55         }
56     }
57
58     static class PlanMaker extends ElementMapping.Maker {
59         public FONode make(FONode parent) {
60             return new PlanObj(parent);
61         }
62     }
63
64     static class PE extends ElementMapping.Maker {
65         public FONode make(FONode parent) {
66             return new PlanElement(parent);
67         }
68     }
69
70     static class PlanConverter implements XMLReader.Converter {
71         public FopImage.ImageInfo convert(Document JavaDoc doc) {
72             try {
73                 PlanRenderer pr = new PlanRenderer();
74                 pr.setFontInfo("Helvetica", 12);
75                 FopImage.ImageInfo info = new FopImage.ImageInfo();
76                 info.data = pr.createSVGDocument(doc);
77                 info.width = (int)pr.getWidth();
78                 info.height = (int)pr.getHeight();
79                 info.mimeType = "image/svg+xml";
80                 info.str = "http://www.w3.org/2000/svg";
81     
82                 return info;
83             } catch (Throwable JavaDoc t) {
84                 /**@todo Log this properly! */
85             }
86             return null;
87         }
88     }
89
90 }
91
Popular Tags