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 #include <com/sun/star/text/TableColumnSeparator.hpp>
25 #include <resourcemodel/TagLogger.hxx>
26 #include "PropertyMapHelper.hxx"
27 
28 namespace writerfilter
29 {
30 namespace dmapper
31 {
32 
33 using namespace ::com::sun::star;
34 
lcl_TableColumnSeparatorsToTag(const uno::Any & rTableColumnSeparators)35 XMLTag::Pointer_t lcl_TableColumnSeparatorsToTag(const uno::Any & rTableColumnSeparators)
36 {
37     uno::Sequence<text::TableColumnSeparator> aSeq;
38     rTableColumnSeparators >>= aSeq;
39 
40     XMLTag::Pointer_t pResult(new XMLTag("property.TableColumnSeparators"));
41 
42     sal_uInt32 nLength = aSeq.getLength();
43     for (sal_uInt32 n = 0; n < nLength; ++n)
44     {
45         XMLTag::Pointer_t pTagSeparator(new XMLTag("separator"));
46 
47         pTagSeparator->addAttr("position", aSeq[n].Position);
48         pTagSeparator->addAttr("visible", aSeq[n].IsVisible);
49 
50         pResult->addTag(pTagSeparator);
51     }
52 
53     return pResult;
54 }
55 
lcl_PropertyValuesToTag(beans::PropertyValues & rValues)56 XMLTag::Pointer_t lcl_PropertyValuesToTag(beans::PropertyValues & rValues)
57 {
58     XMLTag::Pointer_t pResult(new XMLTag("propertyValues"));
59 
60     beans::PropertyValue * pValues = rValues.getArray();
61 
62     for (sal_Int32 n = 0; n < rValues.getLength(); ++n)
63     {
64         XMLTag::Pointer_t pTag(new XMLTag("propertyValue"));
65 
66         pTag->addAttr("name", pValues[n].Name);
67 
68         try
69         {
70             sal_Int32 aInt = 0;
71             pValues[n].Value >>= aInt;
72             pTag->addAttr("value", aInt);
73         }
74         catch (...)
75         {
76             pTag->addAttr("exception", "true");
77         }
78 
79         if (pValues[n].Name.equalsAscii("TableColumnSeparators"))
80         {
81             pTag->addTag(lcl_TableColumnSeparatorsToTag(pValues[n].Value));
82         }
83 
84         pResult->addTag(pTag);
85     }
86 
87     return pResult;
88 }
89 
lcl_PropertyValueSeqToTag(PropertyValueSeq_t & rPropValSeq)90 XMLTag::Pointer_t lcl_PropertyValueSeqToTag(PropertyValueSeq_t & rPropValSeq)
91 {
92     XMLTag::Pointer_t pResult(new XMLTag("PropertyValueSeq"));
93 
94     beans::PropertyValues * pValues = rPropValSeq.getArray();
95 
96     for (sal_Int32 n = 0; n < rPropValSeq.getLength(); ++n)
97     {
98         XMLTag::Pointer_t pTag(lcl_PropertyValuesToTag(pValues[n]));
99 
100         pResult->addTag(pTag);
101     }
102 
103     return pResult;
104 }
105 
lcl_PropertyValueSeqSeqToTag(PropertyValueSeqSeq_t rPropValSeqSeq)106 XMLTag::Pointer_t lcl_PropertyValueSeqSeqToTag(PropertyValueSeqSeq_t rPropValSeqSeq)
107 {
108     XMLTag::Pointer_t pResult(new XMLTag("PropertyValueSeq"));
109 
110     PropertyValueSeq_t * pValues = rPropValSeqSeq.getArray();
111 
112     for (sal_Int32 n = 0; n < rPropValSeqSeq.getLength(); ++n)
113     {
114         XMLTag::Pointer_t pTag(lcl_PropertyValueSeqToTag(pValues[n]));
115 
116         pResult->addTag(pTag);
117     }
118 
119     return pResult;
120 }
121 
122 }
123 }
124