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.

Region.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.pagination;
  8. // FOP
  9. import org.apache.fop.fo.FObj;
  10. import org.apache.fop.fo.PropertyList;
  11. import org.apache.fop.apps.FOPException;
  12. import org.apache.fop.layout.RegionArea;
  13. /**
  14. * Abstract base class for pagination regions.
  15. */
  16. public abstract class Region extends FObj {
  17. public static final String PROP_REGION_NAME = "region-name";
  18. private SimplePageMaster _layoutMaster;
  19. private String _regionName;
  20. protected Region(FObj parent,
  21. PropertyList propertyList) throws FOPException {
  22. super(parent, propertyList);
  23. // regions may have name, or default
  24. if (null == this.properties.get(PROP_REGION_NAME)) {
  25. setRegionName(getDefaultRegionName());
  26. } else if (this.properties.get(PROP_REGION_NAME).getString().equals("")) {
  27. setRegionName(getDefaultRegionName());
  28. } else {
  29. setRegionName(this.properties.get(PROP_REGION_NAME).getString());
  30. // check that name is OK. Not very pretty.
  31. if (isReserved(getRegionName())
  32. &&!getRegionName().equals(getDefaultRegionName())) {
  33. throw new FOPException(PROP_REGION_NAME + " '" + _regionName
  34. + "' for " + this.getName()
  35. + " not permitted.");
  36. }
  37. }
  38. if (parent.getName().equals("fo:simple-page-master")) {
  39. _layoutMaster = (SimplePageMaster)parent;
  40. getPageMaster().addRegion(this);
  41. } else {
  42. throw new FOPException(getName() + " must be child "
  43. + "of simple-page-master, not "
  44. + parent.getName());
  45. }
  46. }
  47. /**
  48. * Creates a Region layout object for this pagination Region.
  49. */
  50. abstract RegionArea makeRegionArea(int allocationRectangleXPosition,
  51. int allocationRectangleYPosition,
  52. int allocationRectangleWidth,
  53. int allocationRectangleHeight);
  54. /**
  55. * Returns the default region name (xsl-region-before, xsl-region-start,
  56. * etc.)
  57. */
  58. protected abstract String getDefaultRegionName();
  59. public abstract String getRegionClass();
  60. /**
  61. * Returns the name of this region
  62. */
  63. public String getRegionName() {
  64. return _regionName;
  65. }
  66. private void setRegionName(String name) {
  67. _regionName = name;
  68. }
  69. protected SimplePageMaster getPageMaster() {
  70. return _layoutMaster;
  71. }
  72. /**
  73. * Checks to see if a given region name is one of the reserved names
  74. *
  75. * @param name a region name to check
  76. * @return true if the name parameter is a reserved region name
  77. */
  78. protected boolean isReserved(String name) throws FOPException {
  79. return (name.equals("xsl-region-before")
  80. || name.equals("xsl-region-start")
  81. || name.equals("xsl-region-end")
  82. || name.equals("xsl-region-after")
  83. || name.equals("xsl-before-float-separator")
  84. || name.equals("xsl-footnote-separator"));
  85. }
  86. public boolean generatesReferenceAreas() {
  87. return true;
  88. }
  89. }