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 83 ostream & output(ostream & o, const string & sIndent = "") const; 84 }; 85 86 class WRITERFILTER_DLLPUBLIC TagLogger 87 { 88 public: 89 typedef boost::shared_ptr<TagLogger> Pointer_t; 90 91 private: 92 stack<XMLTag::Pointer_t> mTags; 93 XMLTag::Pointer_t currentTag() const; 94 XMLTag::Pointer_t mpRoot; 95 string mFileName; 96 97 TagLogger(); 98 99 public: 100 ~TagLogger(); 101 102 static Pointer_t getInstance(const char * name); 103 104 void setFileName(const string & rName); 105 106 void startDocument(); 107 void element(const string & name); 108 void startElement(const string & name); 109 void attribute(const string & name, const string & value); 110 void attribute(const string & name, const ::rtl::OUString & value); 111 void attribute(const string & name, sal_uInt32 value); 112 void attribute(const string & name, const uno::Any aAny); 113 void addTag(XMLTag::Pointer_t pTag); 114 void chars(const string & chars); 115 void chars(const ::rtl::OUString & chars); 116 void endElement(const string & name); 117 void endDocument(); 118 119 ostream & output(ostream & o) const; 120 static void dump(const char * name); 121 }; 122 123 class IdToString 124 { 125 public: 126 typedef boost::shared_ptr<IdToString> Pointer_t; 127 virtual string toString(const Id & id) const = 0; 128 }; 129 130 class WRITERFILTER_DLLPUBLIC PropertySetToTagHandler : public Properties 131 { 132 XMLTag::Pointer_t mpTag; 133 IdToString::Pointer_t mpIdToString; 134 135 public: 136 PropertySetToTagHandler(IdToString::Pointer_t pIdToString); 137 virtual ~PropertySetToTagHandler(); 138 getTag() const139 XMLTag::Pointer_t getTag() const { return mpTag; } 140 141 void resolve(XMLTag & rTag, 142 writerfilter::Reference<Properties>::Pointer_t props); 143 144 virtual void attribute(Id name, Value & val); 145 virtual void sprm(Sprm & sprm); 146 }; 147 148 WRITERFILTER_DLLPUBLIC XMLTag::Pointer_t unoPropertySetToTag(uno::Reference<beans::XPropertySet> rPropSet); 149 } 150 151 #endif // INCLUDED_TAG_LOGGER_HXX 152