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: $ */
19:
20: package org.apache.fop.render;
21:
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.apache.fop.apps.FOUserAgent;
27:
28: /**
29: * Abstract base classes for renderer-related configurator classes. This class basically just
30: * provides an accessor to the specific renderer configuration object.
31: */
32: public abstract class AbstractRendererConfigurator {
33:
34: /** logger instance */
35: protected static Log log = LogFactory
36: .getLog(AbstractRendererConfigurator.class);
37:
38: /** fop factory configuration */
39: protected FOUserAgent userAgent = null;
40:
41: /**
42: * Default constructor
43: * @param userAgent user agent
44: */
45: public AbstractRendererConfigurator(FOUserAgent userAgent) {
46: super ();
47: this .userAgent = userAgent;
48: }
49:
50: /**
51: * Returns the configuration subtree for a specific renderer.
52: * @param renderer the renderer
53: * @return the requested configuration subtree, null if there's no configuration
54: */
55: protected Configuration getRendererConfig(Renderer renderer) {
56: Configuration cfg = userAgent.getFactory().getUserConfig();
57: if (cfg == null) {
58: if (log.isDebugEnabled()) {
59: log.debug("userconfig is null");
60: }
61: return null;
62: }
63:
64: String mimeType = renderer.getMimeType();
65: if (mimeType == null) {
66: if (log.isInfoEnabled()) {
67: log.info("renderer mimeType is null");
68: }
69: return null;
70: }
71:
72: Configuration userRendererConfig = null;
73:
74: Configuration[] cfgs = cfg.getChild("renderers").getChildren(
75: "renderer");
76: for (int i = 0; i < cfgs.length; ++i) {
77: Configuration child = cfgs[i];
78: try {
79: if (child.getAttribute("mime").equals(mimeType)) {
80: userRendererConfig = child;
81: break;
82: }
83: } catch (ConfigurationException e) {
84: // silently pass over configurations without mime type
85: }
86: }
87: log.debug((userRendererConfig == null ? "No u" : "U")
88: + "ser configuration found for MIME type " + mimeType);
89: return userRendererConfig;
90: }
91: }
|