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.

GenericShorthandParser.java 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.properties;
  19. import java.util.Iterator;
  20. import org.apache.fop.fo.PropertyList;
  21. import org.apache.fop.fo.expr.PropertyException;
  22. /**
  23. * Generic shorthand parser for ListProperties
  24. */
  25. public class GenericShorthandParser implements ShorthandParser {
  26. /**
  27. * Constructor.
  28. */
  29. public GenericShorthandParser() {
  30. }
  31. /**
  32. * @param list the ListProperty
  33. * @param index the index into the List of properties
  34. * @return the property from the List of properties at the index parameter
  35. */
  36. protected Property getElement(Property list, int index) {
  37. if (list.getList().size() > index) {
  38. return (Property) list.getList().get(index);
  39. } else {
  40. return null;
  41. }
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public Property getValueForProperty(int propId,
  47. Property property,
  48. PropertyMaker maker,
  49. PropertyList propertyList)
  50. throws PropertyException {
  51. // Check for keyword "inherit"
  52. if (property.getList().size() == 1) {
  53. String sval = getElement(property, 0).getString();
  54. if (sval != null && sval.equals("inherit")) {
  55. return propertyList.getFromParent(propId);
  56. }
  57. }
  58. return convertValueForProperty(propId, property, maker, propertyList);
  59. }
  60. /**
  61. * Converts a property name into a Property
  62. * @param propId the property ID in the Constants interface
  63. * @param maker the Property.Maker to be used in the conversion
  64. * @param property ...
  65. * @param propertyList the PropertyList from which the Property should be
  66. * extracted
  67. * @return the Property matching the parameters, or null if not found
  68. * @throws PropertyException (when?)
  69. */
  70. protected Property convertValueForProperty(int propId,
  71. Property property,
  72. PropertyMaker maker,
  73. PropertyList propertyList)
  74. throws PropertyException {
  75. Property prop = null;
  76. // Try each of the stored values in turn
  77. Iterator iprop = property.getList().iterator();
  78. while (iprop.hasNext() && prop == null) {
  79. Property p = (Property)iprop.next();
  80. prop = maker.convertShorthandProperty(propertyList, p, null);
  81. // The following produces a regression, about which see FOP-2311.
  82. // propertyList.validatePropertyValue(p.getNCname(), prop, property);
  83. }
  84. return prop;
  85. }
  86. }