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.parser.office; 24 25 import com.sun.star.report.pentaho.OfficeNamespaces; 26 import com.sun.star.report.pentaho.model.FontFaceDeclsSection; 27 import com.sun.star.report.pentaho.model.FontFaceElement; 28 import com.sun.star.report.pentaho.parser.ElementReadHandler; 29 import com.sun.star.report.pentaho.parser.style.FontFaceReadHandler; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 import org.jfree.report.structure.Element; 35 36 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 37 38 import org.xml.sax.Attributes; 39 import org.xml.sax.SAXException; 40 41 42 /** 43 * Reads the font-face declarations section. This one can only contain 44 * font-face elements. 45 * 46 * @author Thomas Morgner 47 * @since 13.03.2007 48 */ 49 public class FontFaceDeclsReadHandler extends ElementReadHandler 50 { 51 52 private final FontFaceDeclsSection fontFaceDecls; 53 private final List fontFaceReadHandlers; 54 FontFaceDeclsReadHandler(final FontFaceDeclsSection fontFaceDecls)55 public FontFaceDeclsReadHandler(final FontFaceDeclsSection fontFaceDecls) 56 { 57 this.fontFaceDecls = fontFaceDecls; 58 this.fontFaceReadHandlers = new ArrayList(); 59 } 60 getFontFaceDecls()61 public FontFaceDeclsSection getFontFaceDecls() 62 { 63 return fontFaceDecls; 64 } 65 66 /** 67 * Returns the handler for a child element. 68 * 69 * @param tagName the tag name. 70 * @param atts the attributes. 71 * @return the handler or null, if the tagname is invalid. 72 * 73 * @throws org.xml.sax.SAXException if there is a parsing error. 74 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)75 protected XmlReadHandler getHandlerForChild(final String uri, 76 final String tagName, 77 final Attributes atts) 78 throws SAXException 79 { 80 if (!OfficeNamespaces.STYLE_NS.equals(uri)) 81 { 82 return null; 83 } 84 85 if ("font-face".equals(tagName)) 86 { 87 final FontFaceReadHandler frh = new FontFaceReadHandler(); 88 fontFaceReadHandlers.add(frh); 89 return frh; 90 } 91 return null; 92 } 93 94 /** 95 * Done parsing. 96 * 97 * @throws org.xml.sax.SAXException if there is a parsing error. 98 */ doneParsing()99 protected void doneParsing() 100 throws SAXException 101 { 102 for (int i = 0; i < fontFaceReadHandlers.size(); i++) 103 { 104 final FontFaceReadHandler handler = (FontFaceReadHandler) fontFaceReadHandlers.get(i); 105 fontFaceDecls.addFontFace((FontFaceElement) handler.getElement()); 106 } 107 } 108 getElement()109 public Element getElement() 110 { 111 return fontFaceDecls; 112 } 113 } 114