001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine;
029:
030: import java.util.StringTokenizer;
031:
032: /**
033: * @author Teodor Danciu (teodord@users.sourceforge.net)
034: * @version $Id: JRPrintElementIndex.java 1650 2007-03-22 16:28:57Z teodord $
035: */
036: public class JRPrintElementIndex {
037:
038: /**
039: *
040: */
041: private int reportIndex = 0;
042: private int pageIndex = 0;
043: private String address = null;
044:
045: /**
046: *
047: */
048: public JRPrintElementIndex(int reportIndex, int pageIndex,
049: String address) {
050: this .reportIndex = reportIndex;
051: this .pageIndex = pageIndex;
052: this .address = address;
053: }
054:
055: /**
056: *
057: */
058: public int getReportIndex() {
059: return this .reportIndex;
060: }
061:
062: /**
063: *
064: */
065: public int getPageIndex() {
066: return this .pageIndex;
067: }
068:
069: /**
070: *
071: *
072: public Integer[] getElementIndexes()
073: {
074: return (Integer[]) elementIndexes.toArray(new Integer[elementIndexes.size()]);
075: }
076:
077:
078: /**
079: * Returns a String representation of this element index.
080: * <p>
081: * The representation is obtained by appending all the indexes that compose this instance.
082: * The result is compatible with {@link #parsePrintElementIndex(String) parsePrintElementIndex(String)},
083: * which can be used to recreate the elemetn index instance from a String representation.
084: * </p>
085: */
086: public String toString() {
087: StringBuffer str = new StringBuffer();
088: str.append(reportIndex);
089: str.append('_');
090: str.append(pageIndex);
091: str.append('_');
092: str.append(address);
093: return str.toString();
094: }
095:
096: /**
097: *
098: */
099: public Integer[] getAddressArray() {
100: StringTokenizer tkzer = new StringTokenizer(address, "_");
101:
102: Integer[] elementIndexes = new Integer[tkzer.countTokens()];
103: int c = 0;
104: while (tkzer.hasMoreTokens()) {
105: elementIndexes[c++] = Integer.valueOf(tkzer.nextToken());
106: }
107:
108: return elementIndexes;
109: }
110:
111: /**
112: * Parses a String representation as obtained by {@link #toString() toString()} back
113: * into an element index instance.
114: *
115: * @param indexStr the String representation of an element index
116: * @return an element index instance corresponding to the String representation
117: */
118: public static JRPrintElementIndex parsePrintElementIndex(
119: String indexStr) {
120: StringTokenizer tkzer = new StringTokenizer(indexStr, "_");
121:
122: String reportIndexToken = tkzer.nextToken();
123: String pageIndexToken = tkzer.nextToken();
124:
125: return new JRPrintElementIndex(Integer
126: .parseInt(reportIndexToken), Integer
127: .parseInt(pageIndexToken), indexStr
128: .substring(reportIndexToken.length()
129: + pageIndexToken.length() + 2));
130: }
131:
132: }
|