01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 495371 2007-01-11 21:03:07Z adelmelle $ */
19:
20: package org.apache.fop.fo.extensions.svg;
21:
22: import java.util.HashMap;
23: import javax.xml.parsers.SAXParserFactory;
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;
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 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 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 getAParserClassName() {
57: try {
58: //TODO Remove when Batik uses JAXP instead of SAX directly.
59: SAXParserFactory factory = SAXParserFactory.newInstance();
60: return factory.newSAXParser().getXMLReader().getClass()
61: .getName();
62: } catch (Exception e) {
63: return null;
64: }
65: }
66:
67: protected void initialize() {
68: if (foObjs == null && batikAvail) {
69: // this sets the parser that will be used
70: // by default (SVGBrokenLinkProvider)
71: // normally the user agent value is used
72: try {
73: XMLResourceDescriptor
74: .setXMLParserClassName(getAParserClassName());
75:
76: foObjs = new HashMap();
77: foObjs.put("batik", new SE());
78: foObjs.put(DEFAULT, new SVGMaker());
79: } catch (Throwable t) {
80: // if the classes are not available
81: // the DISPLAY is not checked
82: batikAvail = false;
83: }
84: }
85: }
86:
87: static class SVGMaker extends ElementMapping.Maker {
88: public FONode make(FONode parent) {
89: return new SVGObj(parent);
90: }
91: }
92:
93: static class SE extends ElementMapping.Maker {
94: public FONode make(FONode parent) {
95: return new SVGElement(parent);
96: }
97: }
98:
99: }
|