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.

PageProductionException.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.fo.pagination;
  19. import java.util.Locale;
  20. import org.xml.sax.Locator;
  21. import org.xml.sax.helpers.LocatorImpl;
  22. import org.apache.fop.events.Event;
  23. import org.apache.fop.events.EventFormatter;
  24. import org.apache.fop.events.EventExceptionManager.ExceptionFactory;
  25. /**
  26. * Exception thrown by FOP if there is a problem while producing new pages.
  27. */
  28. public class PageProductionException extends RuntimeException {
  29. private static final long serialVersionUID = -5126033718398975158L;
  30. private String localizedMessage;
  31. private Locator locator;
  32. /**
  33. * Creates a new PageProductionException.
  34. * @param message the message
  35. * @param locator the optional locator that points to the error in the source file
  36. */
  37. public PageProductionException(String message, Locator locator) {
  38. super(message);
  39. setLocator(locator);
  40. }
  41. /**
  42. * Set a location associated with the exception.
  43. * @param locator the locator holding the location.
  44. */
  45. public void setLocator(Locator locator) {
  46. this.locator = new LocatorImpl(locator);
  47. }
  48. /**
  49. * Returns the locattion associated with the exception.
  50. * @return the locator or null if the location information is not available
  51. */
  52. public Locator getLocator() {
  53. return this.locator;
  54. }
  55. /**
  56. * Sets the localized message for this exception.
  57. * @param msg the localized message
  58. */
  59. public void setLocalizedMessage(String msg) {
  60. this.localizedMessage = msg;
  61. }
  62. /** {@inheritDoc} */
  63. public String getLocalizedMessage() {
  64. if (this.localizedMessage != null) {
  65. return this.localizedMessage;
  66. } else {
  67. return super.getLocalizedMessage();
  68. }
  69. }
  70. /** Exception factory for {@link PageProductionException}. */
  71. public static class PageProductionExceptionFactory implements ExceptionFactory {
  72. /** {@inheritDoc} */
  73. public Throwable createException(Event event) {
  74. Object obj = event.getParam("loc");
  75. Locator loc = (obj instanceof Locator ? (Locator)obj : null);
  76. String msg = EventFormatter.format(event, Locale.ENGLISH);
  77. PageProductionException ex = new PageProductionException(msg, loc);
  78. if (!Locale.ENGLISH.equals(Locale.getDefault())) {
  79. ex.setLocalizedMessage(EventFormatter.format(event));
  80. }
  81. return ex;
  82. }
  83. /** {@inheritDoc} */
  84. public Class<PageProductionException> getExceptionClass() {
  85. return PageProductionException.class;
  86. }
  87. }
  88. }