Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GenericShorthandParser.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 1999-2005 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fo.properties;
  18. import java.util.Iterator;
  19. import org.apache.fop.fo.PropertyList;
  20. import org.apache.fop.fo.expr.PropertyException;
  21. /**
  22. * Generic shorthand parser for ListProperties
  23. */
  24. public class GenericShorthandParser implements ShorthandParser {
  25. /**
  26. * Constructor.
  27. */
  28. public GenericShorthandParser() {
  29. }
  30. /**
  31. * @param list the ListProperty
  32. * @param index the index into the List of properties
  33. * @return the property from the List of properties at the index parameter
  34. */
  35. protected Property getElement(Property list, int index) {
  36. if (list.getList().size() > index) {
  37. return (Property) list.getList().get(index);
  38. } else {
  39. return null;
  40. }
  41. }
  42. /**
  43. * @see org.apache.fop.fo.properties.ShorthandParser#getValueForProperty()
  44. */
  45. public Property getValueForProperty(int propId,
  46. Property property,
  47. PropertyMaker maker,
  48. PropertyList propertyList)
  49. throws PropertyException {
  50. // Check for keyword "inherit"
  51. if (property.getList().size() == 1) {
  52. String sval = getElement(property, 0).getString();
  53. if (sval != null && sval.equals("inherit")) {
  54. return propertyList.getFromParent(propId);
  55. }
  56. }
  57. return convertValueForProperty(propId, property, maker, propertyList);
  58. }
  59. /**
  60. * Converts a property name into a Property
  61. * @param propId the property ID in the Constants interface
  62. * @param maker the Property.Maker to be used in the conversion
  63. * @param property ...
  64. * @param propertyList the PropertyList from which the Property should be
  65. * extracted
  66. * @return the Property matching the parameters, or null if not found
  67. * @throws PropertyException (when?)
  68. */
  69. protected Property convertValueForProperty(int propId,
  70. Property property,
  71. PropertyMaker maker,
  72. PropertyList propertyList)
  73. throws PropertyException {
  74. Property prop = null;
  75. // Try each of the stored values in turn
  76. Iterator iprop = property.getList().iterator();
  77. while (iprop.hasNext() && prop == null) {
  78. Property p = (Property)iprop.next();
  79. prop = maker.convertShorthandProperty(propertyList, p, null);
  80. }
  81. return prop;
  82. }
  83. }