KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > extensions > svg > BatikExtensionElementMapping


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: BatikExtensionElementMapping.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.extensions.svg;
21
22 import java.util.HashMap JavaDoc;
23 import javax.xml.parsers.SAXParserFactory JavaDoc;
24
25 import org.apache.batik.util.XMLResourceDescriptor;
26 import org.apache.fop.fo.ElementMapping;
27 import org.apache.fop.fo.FONode;
28 import org.w3c.dom.DOMImplementation JavaDoc;
29
30 /**
31  * This Element Mapping is for Batik SVG Extension elements
32  * of the http://xml.apache.org/batik/ext namespace.
33  */

34 public class BatikExtensionElementMapping extends ElementMapping {
35     
36     /** Namespace URI for Batik extension elements */
37     public static final String JavaDoc URI = "http://xml.apache.org/batik/ext";
38     
39     private boolean batikAvail = true;
40
41     /** Main constructor. */
42     public BatikExtensionElementMapping() {
43         namespaceURI = URI;
44     }
45
46     /** @see org.apache.fop.fo.ElementMapping#getDOMImplementation() */
47     public DOMImplementation JavaDoc getDOMImplementation() {
48         return null; //no DOMImplementation necessary here
49
}
50
51     /**
52      * Returns the fully qualified classname of an XML parser for
53      * Batik classes that apparently need it (error messages, perhaps)
54      * @return an XML parser classname
55      */

56     private final String JavaDoc getAParserClassName() {
57         try {
58             //TODO Remove when Batik uses JAXP instead of SAX directly.
59
SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
60             return factory.newSAXParser().getXMLReader().getClass().getName();
61         } catch (Exception JavaDoc e) {
62             return null;
63         }
64     }
65
66     protected void initialize() {
67         if (foObjs == null && batikAvail == true) {
68             // this sets the parser that will be used
69
// by default (SVGBrokenLinkProvider)
70
// normally the user agent value is used
71
try {
72                 XMLResourceDescriptor.setXMLParserClassName(
73                   getAParserClassName());
74
75                 foObjs = new HashMap JavaDoc();
76                 foObjs.put("batik", new SE());
77                 foObjs.put(DEFAULT, new SVGMaker());
78             } catch (Throwable JavaDoc t) {
79                 // if the classes are not available
80
// the DISPLAY is not checked
81
batikAvail = false;
82             }
83         }
84     }
85
86     static class SVGMaker extends ElementMapping.Maker {
87         public FONode make(FONode parent) {
88             return new SVGObj(parent);
89         }
90     }
91
92     static class SE extends ElementMapping.Maker {
93         public FONode make(FONode parent) {
94             return new SVGElement(parent);
95         }
96     }
97
98 }
99
Popular Tags