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 
24 #ifndef INCLUDED_OOXML_FACTORY_HXX
25 #define INCLUDED_OOXML_FACTORY_HXX
26 
27 #include <hash_map>
28 #include <boost/shared_ptr.hpp>
29 
30 #ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX
31 #include <resourcemodel/WW8ResourceModel.hxx>
32 #endif
33 
34 #ifndef INCLUDED_OOXML_FAST_TOKENS_HXX
35 #include <ooxml/OOXMLFastTokens.hxx>
36 #endif
37 
38 #ifndef INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX
39 #include "OOXMLFastContextHandler.hxx"
40 #endif
41 
42 namespace writerfilter {
43 namespace ooxml {
44 
45 using namespace std;
46 
47 enum ResourceType_t {
48     RT_NoResource,
49     RT_Table,
50     RT_Stream,
51     RT_List,
52     RT_Integer,
53     RT_Properties,
54     RT_Hex,
55     RT_String,
56     RT_Shape,
57     RT_Boolean,
58     RT_HexValue,
59     RT_Value,
60     RT_XNote,
61     RT_TextTableCell,
62     RT_TextTableRow,
63     RT_TextTable,
64     RT_PropertyTable,
65     RT_Any
66 };
67 
68 struct AttributeInfo
69 {
70     ResourceType_t m_nResource;
71     Id m_nRef;
72 
73     AttributeInfo(ResourceType_t nResource, Id nRef);
74     AttributeInfo();
75 };
76 
77 typedef hash_map<Token_t, AttributeInfo> AttributeToResourceMap;
78 typedef boost::shared_ptr<AttributeToResourceMap> AttributeToResourceMapPointer;
79 typedef hash_map<Id, AttributeToResourceMapPointer> AttributesMap;
80 
81 typedef hash_map<rtl::OUString, sal_Int32, ::rtl::OUStringHash> ListValueMap;
82 typedef boost::shared_ptr<ListValueMap> ListValueMapPointer;
83 typedef hash_map<Id, ListValueMapPointer> ListValuesMap;
84 
85 struct CreateElement
86 {
87     ResourceType_t m_nResource;
88     Id m_nId;
89 
90     CreateElement(ResourceType_t nResource, Id nId);
91     CreateElement();
92 };
93 
94 typedef hash_map<Token_t, CreateElement> CreateElementMap;
95 typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer;
96 typedef hash_map<Id, CreateElementMapPointer> CreateElementsMap;
97 typedef hash_map<Id, string> IdToStringMap;
98 typedef boost::shared_ptr<IdToStringMap> IdToStringMapPointer;
99 
100 typedef hash_map<Id, Token_t> TokenToIdMap;
101 typedef boost::shared_ptr<TokenToIdMap> TokenToIdMapPointer;
102 typedef hash_map<Id, TokenToIdMapPointer> TokenToIdsMap;
103 
104 class OOXMLFactory_ns {
105 public:
106     typedef boost::shared_ptr<OOXMLFactory_ns> Pointer_t;
107 
108     virtual void startAction(OOXMLFastContextHandler * pHandler);
109     virtual void charactersAction(OOXMLFastContextHandler * pHandler, const ::rtl::OUString & rString);
110     virtual void endAction(OOXMLFastContextHandler * pHandler);
111     virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue);
112     virtual string getDefineName(Id nId) const;
113 #ifdef DEBUG_FACTORY
114     virtual string getName() const;
115 #endif
116 
117     AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
118     ListValueMapPointer getListValueMap(Id nId);
119     CreateElementMapPointer getCreateElementMap(Id nId);
120     TokenToIdMapPointer getTokenToIdMap(Id nId);
121 
122 protected:
123     virtual ~OOXMLFactory_ns();
124 
125     AttributesMap m_AttributesMap;
126     ListValuesMap m_ListValuesMap;
127     CreateElementsMap m_CreateElementsMap;
128     TokenToIdsMap m_TokenToIdsMap;
129 
130     virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0;
131     virtual ListValueMapPointer createListValueMap(Id nId) = 0;
132     virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0;
133     virtual TokenToIdMapPointer createTokenToIdMap(Id nId) = 0;
134 };
135 
136 class OOXMLFactory
137 {
138 public:
139     typedef boost::shared_ptr<OOXMLFactory> Pointer_t;
140 
141     static Pointer_t getInstance();
142 
143     uno::Reference< xml::sax::XFastContextHandler> createFastChildContext
144     (OOXMLFastContextHandler * pHandler, Token_t Element);
145 
146     uno::Reference< xml::sax::XFastContextHandler> createFastChildContextFromStart
147     (OOXMLFastContextHandler * pHandler, Token_t Element);
148 
149     void attributes(OOXMLFastContextHandler * pHandler,
150                     const uno::Reference< xml::sax::XFastAttributeList > & Attribs);
151 
152     void characters(OOXMLFastContextHandler * pHandler,
153                     const ::rtl::OUString & rString);
154 
155     void startAction(OOXMLFastContextHandler * pHandler, Token_t nToken);
156     void endAction(OOXMLFastContextHandler * pHandler, Token_t nToken);
157 
158     virtual ~OOXMLFactory();
159 
160 private:
161     static Pointer_t m_Instance;
162 
163     OOXMLFactory();
164     OOXMLFactory_ns::Pointer_t getFactoryForNamespace(Id id);
165 
166     uno::Reference< xml::sax::XFastContextHandler>
167     createFastChildContextFromFactory(OOXMLFastContextHandler * pHandler,
168                                       OOXMLFactory_ns::Pointer_t pFactory,
169                                       Token_t Element);
170 };
171 
172 }
173 }
174 
175 #endif // INCLUDED_OOXML_FACTORY_HXX
176