1*1a37d047SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1a37d047SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1a37d047SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1a37d047SAndrew Rist * distributed with this work for additional information 6*1a37d047SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1a37d047SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1a37d047SAndrew Rist * "License"); you may not use this file except in compliance 9*1a37d047SAndrew Rist * with the License. You may obtain a copy of the License at 10*1a37d047SAndrew Rist * 11*1a37d047SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1a37d047SAndrew Rist * 13*1a37d047SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1a37d047SAndrew Rist * software distributed under the License is distributed on an 15*1a37d047SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1a37d047SAndrew Rist * KIND, either express or implied. See the License for the 17*1a37d047SAndrew Rist * specific language governing permissions and limitations 18*1a37d047SAndrew Rist * under the License. 19*1a37d047SAndrew Rist * 20*1a37d047SAndrew Rist *************************************************************/ 21*1a37d047SAndrew Rist 22*1a37d047SAndrew Rist 23cdf0e10cSrcweir package com.sun.star.report.pentaho.parser.style; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.report.pentaho.OfficeNamespaces; 26cdf0e10cSrcweir import com.sun.star.report.pentaho.model.OfficeStyles; 27cdf0e10cSrcweir import com.sun.star.report.pentaho.parser.ElementReadHandler; 28cdf0e10cSrcweir import com.sun.star.report.pentaho.parser.data.DataStyleReadHandler; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import java.util.ArrayList; 31cdf0e10cSrcweir import java.util.List; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import org.jfree.report.modules.factories.report.flow.SectionReadHandler; 34cdf0e10cSrcweir import org.jfree.report.structure.Element; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 37cdf0e10cSrcweir 38cdf0e10cSrcweir import org.xml.sax.Attributes; 39cdf0e10cSrcweir import org.xml.sax.SAXException; 40cdf0e10cSrcweir 41cdf0e10cSrcweir public class OfficeStylesReadHandler extends ElementReadHandler 42cdf0e10cSrcweir { 43cdf0e10cSrcweir 44cdf0e10cSrcweir private final List textStyleChilds; 45cdf0e10cSrcweir private final List dataStyleChilds; 46cdf0e10cSrcweir private final List otherStyleChilds; 47cdf0e10cSrcweir private final List pageLayoutChilds; 48cdf0e10cSrcweir private final OfficeStyles officeStyles; 49cdf0e10cSrcweir OfficeStylesReadHandler(final OfficeStyles officeStyles)50cdf0e10cSrcweir public OfficeStylesReadHandler(final OfficeStyles officeStyles) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir this.officeStyles = officeStyles; 53cdf0e10cSrcweir this.pageLayoutChilds = new ArrayList(); 54cdf0e10cSrcweir this.dataStyleChilds = new ArrayList(); 55cdf0e10cSrcweir this.textStyleChilds = new ArrayList(); 56cdf0e10cSrcweir this.otherStyleChilds = new ArrayList(); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir /** 60cdf0e10cSrcweir * Returns the handler for a child element. 61cdf0e10cSrcweir * 62cdf0e10cSrcweir * @param tagName the tag name. 63cdf0e10cSrcweir * @param atts the attributes. 64cdf0e10cSrcweir * @return the handler or null, if the tagname is invalid. 65cdf0e10cSrcweir * 66cdf0e10cSrcweir * @throws org.xml.sax.SAXException if there is a parsing error. 67cdf0e10cSrcweir */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)68cdf0e10cSrcweir protected XmlReadHandler getHandlerForChild(final String uri, final String tagName, 69cdf0e10cSrcweir final Attributes atts) 70cdf0e10cSrcweir throws SAXException 71cdf0e10cSrcweir { 72cdf0e10cSrcweir if (OfficeNamespaces.STYLE_NS.equals(uri)) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir if ("style".equals(tagName)) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir final OfficeStyleReadHandler xrh = new OfficeStyleReadHandler(); 77cdf0e10cSrcweir textStyleChilds.add(xrh); 78cdf0e10cSrcweir return xrh; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir else if ("page-layout".equals(tagName)) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir final PageLayoutReadHandler prh = new PageLayoutReadHandler(); 83cdf0e10cSrcweir pageLayoutChilds.add(prh); 84cdf0e10cSrcweir return prh; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir else if (OfficeNamespaces.DATASTYLE_NS.equals(uri)) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir final DataStyleReadHandler xrh = new DataStyleReadHandler(false); 90cdf0e10cSrcweir dataStyleChilds.add(xrh); 91cdf0e10cSrcweir return xrh; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir final SectionReadHandler genericReadHander = new SectionReadHandler(); 95cdf0e10cSrcweir otherStyleChilds.add(genericReadHander); 96cdf0e10cSrcweir return genericReadHander; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir /** 100cdf0e10cSrcweir * Done parsing. 101cdf0e10cSrcweir * 102cdf0e10cSrcweir * @throws org.xml.sax.SAXException if there is a parsing error. 103cdf0e10cSrcweir */ doneParsing()104cdf0e10cSrcweir protected void doneParsing() throws SAXException 105cdf0e10cSrcweir { 106cdf0e10cSrcweir for (int i = 0; i < textStyleChilds.size(); i++) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir final OfficeStyleReadHandler handler = 109cdf0e10cSrcweir (OfficeStyleReadHandler) textStyleChilds.get(i); 110cdf0e10cSrcweir officeStyles.addStyle(handler.getOfficeStyle()); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir for (int i = 0; i < pageLayoutChilds.size(); i++) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir final PageLayoutReadHandler handler = 116cdf0e10cSrcweir (PageLayoutReadHandler) pageLayoutChilds.get(i); 117cdf0e10cSrcweir officeStyles.addPageStyle(handler.getPageLayout()); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir for (int i = 0; i < dataStyleChilds.size(); i++) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir final DataStyleReadHandler handler = 123cdf0e10cSrcweir (DataStyleReadHandler) dataStyleChilds.get(i); 124cdf0e10cSrcweir officeStyles.addDataStyle(handler.getDataStyle()); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir for (int i = 0; i < otherStyleChilds.size(); i++) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir final SectionReadHandler handler = 130cdf0e10cSrcweir (SectionReadHandler) otherStyleChilds.get(i); 131cdf0e10cSrcweir officeStyles.addOtherNode((Element) handler.getNode()); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir getElement()135cdf0e10cSrcweir public Element getElement() 136cdf0e10cSrcweir { 137cdf0e10cSrcweir return officeStyles; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140