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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. String vProperty = "";
  77. // Try each of the stored values in turn
  78. Iterator iprop = property.getList().iterator();
  79. while (iprop.hasNext() && prop == null) {
  80. Property p = (Property)iprop.next();
  81. if (p.getNCname() != null) {
  82. vProperty += p.getNCname() + " ";
  83. }
  84. prop = maker.convertShorthandProperty(propertyList, p, null);
  85. }
  86. propertyList.validatePropertyValue(vProperty.trim(), prop, property);
  87. return prop;
  88. }
  89. }