Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TxtRendererConfig.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* $Id$ */
  18. package org.apache.fop.render.txt;
  19. import java.util.EnumMap;
  20. import org.apache.avalon.framework.configuration.Configuration;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.apps.FOUserAgent;
  23. import org.apache.fop.apps.MimeConstants;
  24. import org.apache.fop.fonts.DefaultFontConfig;
  25. import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser;
  26. import org.apache.fop.render.RendererConfig;
  27. import org.apache.fop.render.RendererConfigOption;
  28. /**
  29. * The Text renderer configuration data object.
  30. */
  31. public final class TxtRendererConfig implements RendererConfig {
  32. public enum TxtRendererOption implements RendererConfigOption {
  33. ENCODING("encoding", "UTF-8");
  34. private final String name;
  35. private final Object defaultValue;
  36. private TxtRendererOption(String name, Object defaultValue) {
  37. this.name = name;
  38. this.defaultValue = defaultValue;
  39. }
  40. public String getName() {
  41. return name;
  42. }
  43. public Object getDefaultValue() {
  44. return defaultValue;
  45. }
  46. }
  47. private final EnumMap<TxtRendererOption, Object> params
  48. = new EnumMap<TxtRendererOption, Object>(TxtRendererOption.class);
  49. private final DefaultFontConfig fontConfig;
  50. private TxtRendererConfig(DefaultFontConfig fontConfig) {
  51. this.fontConfig = fontConfig;
  52. }
  53. public DefaultFontConfig getFontInfoConfig() {
  54. return fontConfig;
  55. }
  56. public String getEncoding() {
  57. return (String) params.get(TxtRendererOption.ENCODING);
  58. }
  59. /**
  60. * The Text renderer configuration data parser.
  61. */
  62. public static final class TxtRendererConfigParser implements RendererConfigParser {
  63. /** {@inheritDoc} */
  64. public TxtRendererConfig build(FOUserAgent userAgent, Configuration cfg) throws FOPException {
  65. TxtRendererConfig config = new TxtRendererConfig(new DefaultFontConfigParser().parse(cfg,
  66. userAgent.validateStrictly()));
  67. if (cfg != null) {
  68. TxtRendererOption option = TxtRendererOption.ENCODING;
  69. String value = cfg.getChild(option.getName(), true).getValue(null);
  70. config.params.put(option, value != null ? value : option.getDefaultValue());
  71. }
  72. return config;
  73. }
  74. /** {@inheritDoc} */
  75. public String getMimeType() {
  76. return MimeConstants.MIME_PLAIN_TEXT;
  77. }
  78. }
  79. }