Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AFPForeignAttributeReader.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.afp;
  19. import java.net.URI;
  20. import java.util.Map;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.xmlgraphics.util.QName;
  24. import org.apache.fop.afp.AFPResourceInfo;
  25. import org.apache.fop.afp.AFPResourceLevel;
  26. import org.apache.fop.render.afp.extensions.AFPElementMapping;
  27. /**
  28. * Parses any AFP foreign attributes
  29. */
  30. public class AFPForeignAttributeReader {
  31. private static final Log LOG = LogFactory.getLog("org.apache.xmlgraphics.afp");
  32. /** the resource-name attribute */
  33. public static final QName RESOURCE_NAME = new QName(
  34. AFPElementMapping.NAMESPACE, "afp:resource-name");
  35. /** the resource-level attribute */
  36. public static final QName RESOURCE_LEVEL = new QName(
  37. AFPElementMapping.NAMESPACE, "afp:resource-level");
  38. /** the resource-group-file attribute */
  39. public static final QName RESOURCE_GROUP_URI = new QName(
  40. AFPElementMapping.NAMESPACE, "afp:resource-group-file");
  41. /**
  42. * Main constructor
  43. */
  44. public AFPForeignAttributeReader() {
  45. }
  46. /**
  47. * Returns the resource information
  48. *
  49. * @param foreignAttributes the foreign attributes
  50. * @return the resource information
  51. */
  52. public AFPResourceInfo getResourceInfo(Map<QName, String> foreignAttributes) {
  53. AFPResourceInfo resourceInfo = new AFPResourceInfo();
  54. if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
  55. String resourceName = foreignAttributes.get(RESOURCE_NAME);
  56. if (resourceName != null) {
  57. resourceInfo.setName(resourceName);
  58. }
  59. AFPResourceLevel level = getResourceLevel(foreignAttributes);
  60. if (level != null) {
  61. resourceInfo.setLevel(level);
  62. }
  63. }
  64. return resourceInfo;
  65. }
  66. /**
  67. * Returns the resource level
  68. *
  69. * @param foreignAttributes the foreign attributes
  70. * @return the resource level
  71. */
  72. public AFPResourceLevel getResourceLevel(Map<QName, String> foreignAttributes) {
  73. AFPResourceLevel resourceLevel = null;
  74. if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
  75. if (foreignAttributes.containsKey(RESOURCE_LEVEL)) {
  76. String levelString = foreignAttributes.get(RESOURCE_LEVEL);
  77. resourceLevel = AFPResourceLevel.valueOf(levelString);
  78. // if external get resource group file attributes
  79. if (resourceLevel != null && resourceLevel.isExternal()) {
  80. String resourceGroupUri = foreignAttributes.get(RESOURCE_GROUP_URI);
  81. if (resourceGroupUri == null) {
  82. String msg = RESOURCE_GROUP_URI + " not specified";
  83. throw new UnsupportedOperationException(msg);
  84. }
  85. resourceLevel.setExternalUri(URI.create(resourceGroupUri));
  86. }
  87. }
  88. }
  89. return resourceLevel;
  90. }
  91. }