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_TAG_LOGGER_HXX
25 #define INCLUDED_TAG_LOGGER_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <WriterFilterDllApi.hxx>
30 #include <resourcemodel/WW8ResourceModel.hxx>
31 #include <string>
32 #include <vector>
33 #include <stack>
34 #include <hash_map>
35 #include <boost/shared_ptr.hpp>
36 #include <iostream>
37 
38 namespace writerfilter
39 {
40     using namespace::std;
41 
42     struct XMLAttribute
43     {
44         string mName;
45         string mValue;
46     public:
XMLAttributewriterfilter::XMLAttribute47         XMLAttribute(string sName, string sValue)
48         : mName(sName), mValue(sValue)
49         {
50         }
51     };
52 
53     class WRITERFILTER_DLLPUBLIC XMLTag
54     {
55     public:
56         enum eMode { START, END, COMPLETE };
57         typedef boost::shared_ptr<XMLTag> Pointer_t;
58         static Pointer_t NIL;
59 
60     private:
61         string mTag;
62         string mChars;
63 
64         typedef vector<XMLAttribute> XMLAttributes_t;
65         XMLAttributes_t mAttrs;
66         typedef vector<XMLTag::Pointer_t> XMLTags_t;
67         XMLTags_t mTags;
68         eMode mMode;
69 
70     public:
XMLTag(string sTag,eMode mode=COMPLETE)71         XMLTag(string sTag, eMode mode = COMPLETE) : mTag(sTag), mMode(mode) {}
72 
73         void addAttr(string name, string value);
74         void addAttr(string name, const ::rtl::OUString & value);
75         void addAttr(string name, sal_uInt32 nValue);
76         void addAttr(string name, uno::Any rAny);
77         void addTag(Pointer_t pTag);
78         void chars(const string & rChars);
79         void chars(const ::rtl::OUString & rChars);
80         const string & getTag() const;
81         string toString() const;
82         string toTree(const string & sIndent = "") const;
83 
84         ostream & output(ostream & o, const string & sIndent = "") const;
85     };
86 
87     class WRITERFILTER_DLLPUBLIC TagLogger
88     {
89     public:
90         typedef boost::shared_ptr<TagLogger> Pointer_t;
91 
92     private:
93         stack<XMLTag::Pointer_t> mTags;
94         XMLTag::Pointer_t currentTag() const;
95         XMLTag::Pointer_t mpRoot;
96         string mFileName;
97 
98         TagLogger();
99 
100     public:
101         ~TagLogger();
102 
103         static Pointer_t getInstance(const char * name);
104 
105         void setFileName(const string & rName);
106 
107         void startDocument();
108         void element(const string & name);
109         void startElement(const string & name);
110         void attribute(const string & name, const string & value);
111         void attribute(const string & name, const ::rtl::OUString & value);
112         void attribute(const string & name, sal_uInt32 value);
113         void attribute(const string & name, const uno::Any aAny);
114         void addTag(XMLTag::Pointer_t pTag);
115         void chars(const string & chars);
116         void chars(const ::rtl::OUString & chars);
117         void endElement(const string & name);
118         void endDocument();
119 
120         ostream & output(ostream & o) const;
121         static void dump(const char * name);
122     };
123 
124     class IdToString
125     {
126     public:
127         typedef boost::shared_ptr<IdToString> Pointer_t;
128         virtual string toString(const Id & id) const = 0;
129     };
130 
131     class WRITERFILTER_DLLPUBLIC PropertySetToTagHandler : public Properties
132     {
133         XMLTag::Pointer_t mpTag;
134         IdToString::Pointer_t mpIdToString;
135 
136     public:
137         PropertySetToTagHandler(IdToString::Pointer_t pIdToString);
138         virtual ~PropertySetToTagHandler();
139 
getTag() const140         XMLTag::Pointer_t getTag() const { return mpTag; }
141 
142         void resolve(XMLTag & rTag,
143                      writerfilter::Reference<Properties>::Pointer_t props);
144 
145         virtual void attribute(Id name, Value & val);
146         virtual void sprm(Sprm & sprm);
147     };
148 
149 WRITERFILTER_DLLPUBLIC XMLTag::Pointer_t unoPropertySetToTag(uno::Reference<beans::XPropertySet> rPropSet);
150 }
151 
152 #endif // INCLUDED_TAG_LOGGER_HXX
153