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.

PageGroup.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.Factory;
  22. /**
  23. * A page group is used in the data stream to define a named, logical grouping
  24. * of sequential pages. Page groups are delimited by begin-end structured fields
  25. * that carry the name of the page group. Page groups are defined so that the
  26. * pages that comprise the group can be referenced or processed as a single
  27. * entity. Page groups are often processed in stand-alone fashion; that is, they
  28. * are indexed, retrieved, and presented outside the context of the containing
  29. * document.
  30. */
  31. public class PageGroup extends AbstractResourceEnvironmentGroupContainer {
  32. /**
  33. * Sequence number for TLE's.
  34. */
  35. private int tleSequence = 0;
  36. /**
  37. * Constructor for the PageGroup.
  38. *
  39. * @param factory the resource manager
  40. * @param name the name of the page group
  41. * @param tleSequence current start tle sequence number within stream
  42. */
  43. public PageGroup(Factory factory, String name, int tleSequence) {
  44. super(factory, name);
  45. this.tleSequence = tleSequence;
  46. }
  47. /**
  48. * Creates a TagLogicalElement on the page.
  49. *
  50. * @param name
  51. * the name of the tag
  52. * @param value
  53. * the value of the tag
  54. */
  55. public void createTagLogicalElement(String name, String value) {
  56. TagLogicalElement tle = factory.createTagLogicalElement(name, value, tleSequence);
  57. if (!getTagLogicalElements().contains(tle)) {
  58. getTagLogicalElements().add(tle);
  59. tleSequence++;
  60. }
  61. }
  62. /**
  63. * Method to mark the end of the page group.
  64. */
  65. public void endPageGroup() {
  66. complete = true;
  67. }
  68. /** {@inheritDoc} */
  69. protected void writeContent(OutputStream os) throws IOException {
  70. writeObjects(tagLogicalElements, os, true);
  71. super.writeContent(os);
  72. }
  73. /** {@inheritDoc} */
  74. protected void writeStart(OutputStream os) throws IOException {
  75. byte[] data = new byte[17];
  76. copySF(data, Type.BEGIN, Category.PAGE_GROUP);
  77. os.write(data);
  78. }
  79. /** {@inheritDoc} */
  80. protected void writeEnd(OutputStream os) throws IOException {
  81. byte[] data = new byte[17];
  82. copySF(data, Type.END, Category.PAGE_GROUP);
  83. os.write(data);
  84. }
  85. /** {@inheritDoc} */
  86. public String toString() {
  87. return this.getName();
  88. }
  89. /** @return the TLE sequence number */
  90. public int getTleSequence() {
  91. return tleSequence;
  92. }
  93. }