Frames | No Frames |
1: /* ======================================================================== 2: * JCommon : a free general purpose class library for the Java(tm) platform 3: * ======================================================================== 4: * 5: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jcommon/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ---------------- 28: * SafeTagList.java 29: * ---------------- 30: * (C)opyright 2003-2005, by Thomas Morgner and Contributors. 31: * 32: * Original Author: Thomas Morgner; 33: * Contributor(s): David Gilbert (for Object Refinery Limited); 34: * 35: * $Id: SafeTagList.java,v 1.3 2005/10/18 13:35:06 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 21-Feb-2003 : Added standard header and Javadocs (DG); 40: * 41: */ 42: 43: package org.jfree.xml.writer; 44: 45: import java.util.HashMap; 46: 47: /** 48: * A container for information relating to the tags in the JFreeReport XML report files. Some tags 49: * cannot be spread across multiple lines, because it causes problems for the parser. 50: * 51: * @author Thomas Morgner. 52: */ 53: public class SafeTagList { 54: 55: /** Storage for the tag information. */ 56: private HashMap safeTags; 57: 58: /** 59: * A tag description. 60: */ 61: private static class SafeDescription { 62: 63: /** A flag indicating whether or not it is safe to put a new line after the open tag. */ 64: private boolean open; 65: 66: /** A flag indicating whether or not it is safe to put a new line before the close tag. */ 67: private boolean close; 68: 69: /** 70: * Creates a new tag description. 71: * 72: * @param open the 'open' flag. 73: * @param close the 'close' flag. 74: */ 75: public SafeDescription(final boolean open, final boolean close) { 76: this.open = open; 77: this.close = close; 78: } 79: 80: /** 81: * Returns the 'open' flag. 82: * 83: * @return <code>true</code> or <code>false</code>. 84: */ 85: public boolean isOpen() { 86: return this.open; 87: } 88: 89: /** 90: * Returns the 'close' flag. 91: * 92: * @return <code>true</code> or <code>false</code>. 93: */ 94: public boolean isClose() { 95: return this.close; 96: } 97: } 98: 99: /** 100: * Creates a new list. 101: */ 102: public SafeTagList() { 103: this.safeTags = new HashMap(); 104: } 105: 106: /** 107: * Adds a tag with both the 'open' and 'close' flags set to <code>true</code>. 108: * 109: * @param tag the tag name. 110: */ 111: public void add (final String tag) { 112: this.safeTags.put(tag, new SafeDescription(true, true)); 113: } 114: 115: /** 116: * Adds a tag. 117: * 118: * @param tag the tag name. 119: * @param open the 'open' flag. 120: * @param closed the 'close' flag. 121: */ 122: public void add (final String tag, final boolean open, final boolean closed) { 123: this.safeTags.put(tag, new SafeDescription(open, closed)); 124: } 125: 126: /** 127: * Returns <code>true</code> if it is safe to start a new line 128: * immediately after an open tag. 129: * 130: * @param tag the tag name. 131: * 132: * @return A boolean. 133: */ 134: public boolean isSafeForOpen (final String tag) { 135: final SafeDescription sd = (SafeDescription) this.safeTags.get(tag); 136: if (sd == null) { 137: return false; 138: } 139: return sd.isOpen(); 140: } 141: 142: /** 143: * Returns <code>true</code> if it is safe to start a new 144: * line immediately after a close tag. 145: * 146: * @param tag the tag name. 147: * 148: * @return A boolean. 149: */ 150: public boolean isSafeForClose (final String tag) { 151: final SafeDescription sd = (SafeDescription) this.safeTags.get(tag); 152: if (sd == null) { 153: return false; 154: } 155: return sd.isClose(); 156: } 157: 158: }