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.

GenericShorthandParser.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 1999-2004 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;
  18. import java.util.Enumeration;
  19. import org.apache.fop.fo.properties.ListProperty;
  20. import org.apache.fop.fo.properties.Property;
  21. import org.apache.fop.fo.properties.PropertyMaker;
  22. public class GenericShorthandParser implements ShorthandParser {
  23. /**
  24. * Constructor.
  25. */
  26. public GenericShorthandParser() {
  27. }
  28. /**
  29. * @param index the index into the List of properties
  30. * @return the property from the List of properties at the index parameter
  31. */
  32. protected Property getElement(ListProperty list, int index) {
  33. if (list.getList().size() > index) {
  34. return (Property) list.getList().elementAt(index);
  35. } else {
  36. return null;
  37. }
  38. }
  39. // Stores 1 to 3 values for border width, style, color
  40. // Used for: border, border-top, border-right etc
  41. public Property getValueForProperty(int propId,
  42. ListProperty listProperty,
  43. PropertyMaker maker,
  44. PropertyList propertyList) {
  45. Property prop = null;
  46. // Check for keyword "inherit"
  47. if (listProperty.getList().size() == 1) {
  48. String sval = getElement(listProperty, 0).getString();
  49. if (sval != null && sval.equals("inherit")) {
  50. return propertyList.getFromParent(propId);
  51. }
  52. }
  53. return convertValueForProperty(propId, listProperty, maker, propertyList);
  54. }
  55. /**
  56. * Converts a property name into a Property
  57. * @param propId the property ID in the Constants interface
  58. * @param maker the Property.Maker to be used in the conversion
  59. * @param propertyList the PropertyList from which the Property should be
  60. * extracted
  61. * @return the Property matching the parameters, or null if not found
  62. */
  63. protected Property convertValueForProperty(int propId,
  64. ListProperty listProperty,
  65. PropertyMaker maker,
  66. PropertyList propertyList) {
  67. Property prop = null;
  68. // Try each of the stored values in turn
  69. Enumeration eprop = listProperty.getList().elements();
  70. while (eprop.hasMoreElements() && prop == null) {
  71. Property p = (Property) eprop.nextElement();
  72. prop = maker.convertShorthandProperty(propertyList, p, null);
  73. }
  74. return prop;
  75. }
  76. }