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.

ImageLoader.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.image;
  18. import org.apache.fop.apps.FOUserAgent;
  19. /**
  20. * Class to load images.
  21. */
  22. class ImageLoader {
  23. private String url;
  24. private ImageCache cache;
  25. private boolean valid = true;
  26. private FOUserAgent userAgent;
  27. private FopImage image = null;
  28. /**
  29. * Main constructor.
  30. * @param url URL to the image
  31. * @param cache Image cache
  32. * @param ua User agent
  33. */
  34. public ImageLoader(String url, ImageCache cache, FOUserAgent ua) {
  35. this.url = url;
  36. this.cache = cache;
  37. this.userAgent = ua;
  38. }
  39. /**
  40. * Loads the image.
  41. * @return the loaded image
  42. */
  43. public synchronized FopImage loadImage() {
  44. if (!valid || image != null) {
  45. return image;
  46. }
  47. image = ImageFactory.loadImage(url, userAgent);
  48. if (image == null) {
  49. cache.invalidateImage(url, userAgent);
  50. valid = false;
  51. }
  52. return image;
  53. }
  54. }