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.

InterchangeSet.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /**
  20. * MO:DCA Interchange Set
  21. */
  22. public class InterchangeSet {
  23. /** interchange set 1 string value */
  24. public static final String MODCA_PRESENTATION_INTERCHANGE_SET_1 = "MO:DCA-P IS/1";
  25. /** interchange set 2 string value */
  26. public static final String MODCA_PRESENTATION_INTERCHANGE_SET_2 = "MO:DCA-P IS/2";
  27. /** resource interchange set string value */
  28. public static final String MODCA_RESOURCE_INTERCHANGE_SET = "MO:DCA-L";
  29. private static final String[] NAMES = {
  30. MODCA_PRESENTATION_INTERCHANGE_SET_1,
  31. MODCA_PRESENTATION_INTERCHANGE_SET_2,
  32. MODCA_RESOURCE_INTERCHANGE_SET
  33. };
  34. private static final int SET_1 = 0;
  35. private static final int SET_2 = 1;
  36. private static final int RESOURCE_SET = 2;
  37. /** the actual interchange set in use */
  38. private int value;
  39. /**
  40. * Returns the interchange set value of a given string
  41. *
  42. * @param str an interchange set value
  43. * @return an interchange set
  44. */
  45. public static InterchangeSet valueOf(String str) {
  46. if (MODCA_PRESENTATION_INTERCHANGE_SET_1.equals(str)) {
  47. return new InterchangeSet(SET_1);
  48. } else if (MODCA_PRESENTATION_INTERCHANGE_SET_2.equals(str)) {
  49. return new InterchangeSet(SET_2);
  50. } else if (MODCA_RESOURCE_INTERCHANGE_SET.equals(str)) {
  51. return new InterchangeSet(RESOURCE_SET);
  52. } else {
  53. throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str);
  54. }
  55. }
  56. /**
  57. * Main constructor
  58. *
  59. * @param value the interchange set value
  60. */
  61. public InterchangeSet(int value) {
  62. this.value = value;
  63. }
  64. /**
  65. * Returns true if complies with MOD:CA interchange set 1
  66. *
  67. * @return true if complies with MOD:CA interchange set 1
  68. */
  69. protected boolean is1() {
  70. return value == SET_1;
  71. }
  72. /**
  73. * Returns true if complies with MOD:CA interchange set 2
  74. *
  75. * @return true if complies with MOD:CA interchange set 2
  76. */
  77. public boolean is2() {
  78. return value == SET_2;
  79. }
  80. /**
  81. * Returns true if complies with MOD:CA resource set
  82. *
  83. * @return true if complies with MOD:CA resource set
  84. */
  85. public boolean isResource() {
  86. return value == RESOURCE_SET;
  87. }
  88. /** {@inheritDoc} */
  89. public String toString() {
  90. return NAMES[value];
  91. }
  92. /**
  93. * Returns true if MOD:CA interchange set 2 (resource groups) is supported
  94. *
  95. * @return true if MOD:CA interchange set 2 (resource groups) is supported
  96. */
  97. public boolean supportsLevel2() {
  98. return is2() || isResource();
  99. }
  100. }