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.

AFPResourceInfoElement.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.render.afp.extensions;
  19. import org.apache.fop.apps.FOPException;
  20. //import org.apache.fop.fo.Constants;
  21. import org.apache.fop.fo.Constants;
  22. import org.apache.fop.fo.FONode;
  23. //import org.apache.fop.fo.ValidationException;
  24. import org.apache.fop.fo.extensions.ExtensionAttachment;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.xml.sax.Attributes;
  27. import org.xml.sax.Locator;
  28. /**
  29. * Extension element for afp:resource-group
  30. */
  31. public class AFPResourceInfoElement extends AbstractAFPExtensionObject {
  32. /**
  33. * Main constructor
  34. * @param parent parent FO node
  35. */
  36. public AFPResourceInfoElement(FONode parent) {
  37. super(parent, AFPResourceInfo.ELEMENT);
  38. }
  39. /**
  40. * @throws FOPException if there's a problem during processing
  41. * @see org.apache.fop.fo.FONode#startOfNode()
  42. */
  43. protected void startOfNode() throws FOPException {
  44. if (parent.getNameId() != Constants.FO_INSTREAM_FOREIGN_OBJECT
  45. && parent.getNameId() != Constants.FO_EXTERNAL_GRAPHIC) {
  46. invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
  47. "rule.childOfInstreamForeignObjectorExternalGraphic");
  48. }
  49. }
  50. /**
  51. * {@inheritDoc}
  52. */
  53. public void processNode(String elementName, Locator locator,
  54. Attributes attlist, PropertyList propertyList)
  55. throws FOPException {
  56. getExtensionAttachment();
  57. String attr = attlist.getValue("name");
  58. if (attr != null && attr.length() > 0) {
  59. extensionAttachment.setName(attr);
  60. } else {
  61. throw new FOPException(elementName + " must have a name attribute.");
  62. }
  63. String lvl = attlist.getValue("level");
  64. AFPResourceInfo resourceInfo = (AFPResourceInfo)getExtensionAttachment();
  65. if (lvl != null && lvl.length() > 0) {
  66. resourceInfo.setLevel(lvl);
  67. if (resourceInfo.isExternalLevel()) {
  68. String dest = attlist.getValue("dest");
  69. if (dest != null && dest.length() > 0) {
  70. resourceInfo.setExternalDestination(dest);
  71. } else {
  72. throw new FOPException("must have a dest attribute.");
  73. }
  74. }
  75. } else {
  76. throw new FOPException("must have a level attribute.");
  77. }
  78. }
  79. /**
  80. * {@inheritDoc}
  81. */
  82. protected ExtensionAttachment instantiateExtensionAttachment() {
  83. return new AFPResourceInfo();
  84. }
  85. }