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.

FOPEventListenerProxy.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.event;
  19. import org.apache.fop.apps.FOUserAgent;
  20. import org.apache.fop.events.Event;
  21. import org.apache.fop.events.EventListener;
  22. import org.apache.fop.events.model.EventSeverity;
  23. import org.apache.fop.fo.FOValidationEventProducer;
  24. import org.apache.fop.layoutmgr.BlockLevelEventProducer;
  25. /**
  26. * EventListener proxy that inspects all events and adjusts severity levels where necessary.
  27. * For validation events, it reacts on each event based on the strict validation setting in
  28. * the user agent.
  29. * For layout events, it reduces the default severity level if FOP signals that it can recover
  30. * from the event.
  31. */
  32. public class FOPEventListenerProxy implements EventListener {
  33. private static final String FOVALIDATION_EVENT_ID_PREFIX
  34. = FOValidationEventProducer.class.getName();
  35. private static final String BLOCK_LEVEL_EVENT_ID_PREFIX
  36. = BlockLevelEventProducer.class.getName();
  37. private EventListener delegate;
  38. private FOUserAgent userAgent;
  39. /**
  40. * Main constructor.
  41. * @param delegate the event listener to delegate events to
  42. * @param userAgent the FO user agent
  43. */
  44. public FOPEventListenerProxy(EventListener delegate, FOUserAgent userAgent) {
  45. this.delegate = delegate;
  46. this.userAgent = userAgent;
  47. }
  48. /** {@inheritDoc} */
  49. public synchronized void processEvent(Event event) {
  50. if (event.getEventID().startsWith(FOVALIDATION_EVENT_ID_PREFIX)) {
  51. Boolean canRecover = (Boolean)event.getParam("canRecover");
  52. if (Boolean.TRUE.equals(canRecover) && !userAgent.validateStrictly()) {
  53. //Reduce severity if FOP can recover
  54. event.setSeverity(EventSeverity.WARN);
  55. }
  56. } else if (event.getEventID().startsWith(BLOCK_LEVEL_EVENT_ID_PREFIX)) {
  57. Boolean canRecover = (Boolean)event.getParam("canRecover");
  58. if (Boolean.TRUE.equals(canRecover)) {
  59. //Reduce severity if FOP can recover
  60. event.setSeverity(EventSeverity.WARN);
  61. }
  62. }
  63. this.delegate.processEvent(event);
  64. }
  65. }