1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.report.pentaho.layoutprocessor; 24 25 import com.sun.star.report.pentaho.model.FormattedTextElement; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 30 31 /** 32 * A variables collection is used to collect all FormattedTextElement objects 33 * of a repeated header or footer. Later, for each of these elements a variable 34 * setter is inserted into a hidden (in fact just very small) paragraph. These 35 * variables can later be read using the 'variable-get' construct. 36 * 37 * From the idea, this is equal to the 'strings' declaration of CSS3, although 38 * this code is explicit instead of declarative. 39 * 40 * @author Thomas Morgner 41 * @since 22.03.2007 42 */ 43 public class VariablesCollection 44 { 45 46 private VariablesCollection parent; 47 private String namePrefix; 48 private List variables; 49 VariablesCollection(final String namePrefix)50 public VariablesCollection(final String namePrefix) 51 { 52 this(namePrefix, null); 53 } 54 VariablesCollection(final String namePrefix, final VariablesCollection parent)55 public VariablesCollection(final String namePrefix, final VariablesCollection parent) 56 { 57 if (namePrefix == null) 58 { 59 throw new NullPointerException("NamePrefix cannot be null"); 60 } 61 62 this.namePrefix = namePrefix; 63 this.parent = parent; 64 this.variables = new ArrayList(); 65 } 66 getParent()67 public VariablesCollection getParent() 68 { 69 return parent; 70 } 71 getNamePrefix()72 public String getNamePrefix() 73 { 74 return namePrefix; 75 } 76 addVariable(final FormattedTextElement element)77 public String addVariable(final FormattedTextElement element) 78 { 79 variables.add(element); 80 final int size = variables.size(); 81 return namePrefix + size; 82 } 83 getVariables()84 public FormattedTextElement[] getVariables() 85 { 86 return (FormattedTextElement[]) variables.toArray(new FormattedTextElement[variables.size()]); 87 } 88 getVariablesCount()89 public int getVariablesCount() 90 { 91 return variables.size(); 92 } 93 } 94