protected void checkExistingName(String name) throws JRException { if (getStyle(name) != null) { throw new JRException("Duplicate declaration of template style : " + name); } }
/** * Returns an included style by name. * * @param name the name of the style to be returned * @return the style having the specified name, or <code>null</code> if not found */ public JRStyle getStyle(String name) { JRStyle style = null; for (Iterator it = styles.iterator(); it.hasNext();) { JRStyle itStyle = (JRStyle) it.next(); if (nameMatches(itStyle, name)) { style = itStyle; break; } } return style; }
/** * Adds a style to the template. * * @param style the style to add * @throws JRException when a style with the same name already exists */ public void addStyle(JRStyle style) throws JRException { checkExistingName(style.getName()); if (style.isDefault()) { defaultStyle = style; } styles.add(style); }
protected void setParentStyle(JRDesignStyle currentStyle, String parentStyleName) { JRSimpleTemplate template = (JRSimpleTemplate) digester.peek(digester.getCount() - 1); JRStyle parent = template.getStyle(parentStyleName); if (parent == null) { currentStyle.setParentStyleNameReference(parentStyleName); } else { currentStyle.setParentStyle(parent); } }
/** * Removes an included style. * * @param name the name of the style to be removed * @return the removed style, or <code>null</code> if not found */ public JRStyle removeStyle(String name) { JRStyle removed = null; for (ListIterator it = styles.listIterator(); it.hasNext();) { JRStyle style = (JRStyle) it.next(); if (nameMatches(style, name)) { if (style.isDefault()) { defaultStyle = null; } removed = style; it.remove(); break; } } return removed; }