001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * StaticDrawableURLElementFactory.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.elementfactory;
030:
031: import java.net.URL;
032:
033: import org.jfree.report.DrawableElement;
034: import org.jfree.report.Element;
035: import org.jfree.report.filter.templates.DrawableURLElementTemplate;
036:
037: /**
038: * A factory to create an drawable element that loads its drawable from an static URL. The
039: * content string may contain a relative URL if an valid base URL is given.
040: *
041: * @author Thomas Morgner
042: */
043: public class StaticDrawableURLElementFactory extends ElementFactory {
044: /**
045: * The content URL (may be a relative URL).
046: */
047: private String content;
048: /**
049: * The base URL for relative content URLs.
050: */
051: private URL baseURL;
052:
053: /**
054: * DefaultConstructor.
055: */
056: public StaticDrawableURLElementFactory() {
057: }
058:
059: /**
060: * Returns the content part of the URL. This string may contain a relative URL, if the
061: * base URL is defined.
062: *
063: * @return the content part of the URL.
064: */
065: public String getContent() {
066: return content;
067: }
068:
069: /**
070: * Defines the content part of the URL. This string may contain a relative URL, if the
071: * base URL is defined.
072: *
073: * @param content the content part of the URL.
074: */
075: public void setContent(final String content) {
076: this .content = content;
077: }
078:
079: /**
080: * Returns the BaseURL. The base URL is used to build the complete URL if the content
081: * url is relative.
082: *
083: * @return the base URL.
084: */
085: public URL getBaseURL() {
086: return baseURL;
087: }
088:
089: /**
090: * Defines the base URL.
091: *
092: * @param baseURL the base URL.
093: */
094: public void setBaseURL(final URL baseURL) {
095: this .baseURL = baseURL;
096: }
097:
098: /**
099: * Creates a new drawable field element based on the defined properties.
100: *
101: * @return the generated elements
102: *
103: * @throws IllegalStateException if the field name is not set.
104: * @see ElementFactory#createElement()
105: */
106: public Element createElement() {
107: final DrawableElement element = new DrawableElement();
108: applyElementName(element);
109: applyStyle(element.getStyle());
110:
111: final DrawableURLElementTemplate fieldTemplate = new DrawableURLElementTemplate();
112: fieldTemplate.setContent(getContent());
113: fieldTemplate.setBaseURL(getBaseURL());
114: element.setDataSource(fieldTemplate);
115:
116: return element;
117: }
118:
119: }
|