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.rpt;
24 
25 import com.sun.star.report.OfficeToken;
26 import com.sun.star.report.pentaho.OfficeNamespaces;
27 import com.sun.star.report.pentaho.model.ObjectOleElement;
28 import com.sun.star.report.pentaho.parser.draw.ObjectOleReadHandler;
29 import com.sun.star.report.pentaho.parser.text.NoCDATATextContentReadHandler;
30 
31 import org.jfree.report.structure.Section;
32 
33 import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler;
34 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
35 
36 import org.xml.sax.Attributes;
37 import org.xml.sax.SAXException;
38 
39 /**
40  *
41  * @author Ocke Janssen
42  */
43 public class SubDocumentReadHandler extends NoCDATATextContentReadHandler
44 {
45 
46     private final ObjectOleElement element;
47     private boolean ignore = false;
48 
SubDocumentReadHandler(final ObjectOleElement element)49     public SubDocumentReadHandler(final ObjectOleElement element)
50     {
51         this.element = element;
52     }
53 
SubDocumentReadHandler(final Section section, final ObjectOleElement element)54     public SubDocumentReadHandler(final Section section, final ObjectOleElement element)
55     {
56         super(section);
57         this.element = element;
58     }
59 
SubDocumentReadHandler(final Section section)60     public SubDocumentReadHandler(final Section section)
61     {
62         this(section, new ObjectOleElement());
63         ignore = true;
64     }
65 
66     /**
67      * Starts parsing.
68      *
69      * @param attrs the attributes.
70      * @throws org.xml.sax.SAXException if there is a parsing error.
71      */
startParsing(final Attributes attrs)72     protected void startParsing(final Attributes attrs) throws SAXException
73     {
74         if (!ignore)
75         {
76             super.startParsing(attrs);
77         }
78     }
79 
80     /**
81      * Returns the handler for a child element.
82      *
83      * @param tagName the tag name.
84      * @param atts    the attributes.
85      * @return the handler or null, if the tagname is invalid.
86      * @throws org.xml.sax.SAXException if there is a parsing error.
87      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)88     protected XmlReadHandler getHandlerForChild(final String uri,
89             final String tagName,
90             final Attributes atts)
91             throws SAXException
92     {
93         if (OfficeNamespaces.OOREPORT_NS.equals(uri))
94         {
95             // expect a report control. The control will modifiy the current
96             // element (as we do not separate the elements that strictly ..)
97             if ("report-control".equals(tagName))
98             {
99                 return new IgnoreAnyChildReadHandler();
100             }
101             if ("report-element".equals(tagName))
102             {
103                 return new ReportElementReadHandler(element);
104             }
105             if ("master-detail-fields".equals(tagName))
106             {
107                 return new MasterDetailReadHandler(element);
108             }
109         }
110         if (OfficeNamespaces.DRAWING_NS.equals(uri))
111         {
112             final XmlReadHandler readHandler;
113             if (OfficeToken.OBJECT_OLE.equals(tagName))
114             {
115                 readHandler = new ObjectOleReadHandler(element);
116             }
117             else if ("frame".equals(tagName))
118             {
119                 readHandler = new SubDocumentReadHandler(new Section(), element);
120             }
121             else
122             {
123                 readHandler = null;
124             }
125             if (readHandler != null)
126             {
127                 getChildren().add(readHandler);
128                 return readHandler;
129             }
130         }
131         return super.getHandlerForChild(uri, tagName, atts);
132     }
133 }
134