You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Declarations.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.fo.pagination;
  19. // Java
  20. import java.util.Map;
  21. import org.xml.sax.Locator;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.FObj;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.ValidationException;
  27. /**
  28. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_declarations">
  29. * <code>fo:declarations</code></a> object.
  30. *
  31. * A declarations formatting object holds a set of color-profiles
  32. * and optionally additional non-XSL namespace elements.
  33. * The color-profiles are held in a hashmap for use with color-profile
  34. * references.
  35. */
  36. public class Declarations extends FObj {
  37. private Map<String, ColorProfile> colorProfiles = null;
  38. /**
  39. * @param parent FONode that is the parent of this object
  40. */
  41. public Declarations(FONode parent) {
  42. super(parent);
  43. ((Root) parent).setDeclarations(this);
  44. }
  45. /** {@inheritDoc} */
  46. public void bind(PropertyList pList) throws FOPException {
  47. // No properties defined for fo:declarations
  48. }
  49. /**
  50. * {@inheritDoc}
  51. * <br>XSL 1.0: (color-profile)+ (and non-XSL NS nodes)
  52. * <br>FOP/XSL 1.1: (color-profile)* (and non-XSL NS nodes)
  53. */
  54. protected void validateChildNode(Locator loc, String nsURI, String localName)
  55. throws ValidationException {
  56. if (FO_URI.equals(nsURI)) {
  57. if (!localName.equals("color-profile")) {
  58. invalidChildError(loc, nsURI, localName);
  59. }
  60. } // anything outside of XSL namespace is OK.
  61. }
  62. /**
  63. * At the end of this element sort out the children into
  64. * a hashmap of color profiles and a list of extension attachments.
  65. * @throws FOPException if there's a problem during processing
  66. */
  67. protected void endOfNode() throws FOPException {
  68. if (firstChild != null) {
  69. for (FONodeIterator iter = getChildNodes(); iter.hasNext();) {
  70. FONode node = iter.nextNode();
  71. if (node.getName().equals("fo:color-profile")) {
  72. ColorProfile cp = (ColorProfile)node;
  73. if (!"".equals(cp.getColorProfileName())) {
  74. addColorProfile(cp);
  75. } else {
  76. getFOValidationEventProducer().missingProperty(this,
  77. cp.getName(), "color-profile-name", locator);
  78. }
  79. } else {
  80. log.debug("Ignoring element " + node.getName()
  81. + " inside fo:declarations.");
  82. }
  83. }
  84. }
  85. firstChild = null;
  86. }
  87. private void addColorProfile(ColorProfile cp) {
  88. if (colorProfiles == null) {
  89. colorProfiles = new java.util.HashMap<String, ColorProfile>();
  90. }
  91. if (colorProfiles.get(cp.getColorProfileName()) != null) {
  92. // duplicate names
  93. getFOValidationEventProducer().colorProfileNameNotUnique(this,
  94. cp.getName(), cp.getColorProfileName(), locator);
  95. }
  96. colorProfiles.put(cp.getColorProfileName(), cp);
  97. }
  98. /** {@inheritDoc} */
  99. public String getLocalName() {
  100. return "declarations";
  101. }
  102. /**
  103. * {@inheritDoc}
  104. * @return {@link org.apache.fop.fo.Constants#FO_DECLARATIONS}
  105. */
  106. public int getNameId() {
  107. return FO_DECLARATIONS;
  108. }
  109. /**
  110. * Return ColorProfile with given name.
  111. *
  112. * @param cpName Name of ColorProfile, i.e. the value of the color-profile-name attribute of
  113. * the fo:color-profile element
  114. * @return The org.apache.fop.fo.pagination.ColorProfile object associated with this
  115. * color-profile-name or null
  116. */
  117. public ColorProfile getColorProfile(String cpName) {
  118. ColorProfile profile = null;
  119. if (this.colorProfiles != null) {
  120. profile = this.colorProfiles.get(cpName);
  121. }
  122. return profile;
  123. }
  124. }