xref: /AOO41X/main/xmlscript/inc/xmlscript/xml_helper.hxx (revision 05236b1a0a8122ee73deabdbaef6d40a9b9d7792)
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 #ifndef _XMLSCRIPT_XML_HELPER_HXX_
24 #define _XMLSCRIPT_XML_HELPER_HXX_
25 
26 #include <vector>
27 #include <rtl/byteseq.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 
33 
34 namespace xmlscript
35 {
36 
37 /*##################################################################################################
38 
39     EXPORTING
40 
41 ##################################################################################################*/
42 
43 //==================================================================================================
44 class XMLElement
45     : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XAttributeList >
46 {
47 public:
48     inline XMLElement( ::rtl::OUString const & name )
49         SAL_THROW( () )
50         : _name( name )
51         {}
52 
53     /** Adds a sub element of element.
54 
55         @param xElem element reference
56     */
57     void SAL_CALL addSubElement(
58         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > const & xElem )
59         SAL_THROW( () );
60 
61     /** Gets sub element of given index.  The index follows order in which sub elements were added.
62 
63         @param nIndex index of sub element
64     */
65     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > SAL_CALL getSubElement( sal_Int32 nIndex )
66         SAL_THROW( () );
67 
68     /** Adds an attribute to elements.
69 
70         @param rAttrName qname of attribute
71         @param rValue value string of element
72     */
73     void SAL_CALL addAttribute( ::rtl::OUString const & rAttrName, ::rtl::OUString const & rValue )
74         SAL_THROW( () );
75 
76     /** Gets the tag name (qname) of element.
77 
78         @return
79                 qname of element
80     */
getName()81     inline ::rtl::OUString SAL_CALL getName() SAL_THROW( () )
82         { return _name; }
83 
84     /** Dumps out element (and all sub elements).
85 
86         @param xOut document handler to be written to
87     */
88     void SAL_CALL dump(
89         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > const & xOut );
90     /** Dumps out sub elements (and all further sub elements).
91 
92         @param xOut document handler to be written to
93     */
94     void SAL_CALL dumpSubElements(
95         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > const & xOut );
96 
97     // XAttributeList
98     virtual sal_Int16 SAL_CALL getLength()
99         throw (::com::sun::star::uno::RuntimeException);
100     virtual ::rtl::OUString SAL_CALL getNameByIndex( sal_Int16 nPos )
101         throw (::com::sun::star::uno::RuntimeException);
102     virtual ::rtl::OUString SAL_CALL getTypeByIndex( sal_Int16 nPos )
103         throw (::com::sun::star::uno::RuntimeException);
104     virtual ::rtl::OUString SAL_CALL getTypeByName( ::rtl::OUString const & rName )
105         throw (::com::sun::star::uno::RuntimeException);
106     virtual ::rtl::OUString SAL_CALL getValueByIndex( sal_Int16 nPos )
107         throw (::com::sun::star::uno::RuntimeException);
108     virtual ::rtl::OUString SAL_CALL getValueByName( ::rtl::OUString const & rName )
109         throw (::com::sun::star::uno::RuntimeException);
110 
111 protected:
112     ::rtl::OUString _name;
113 
114     ::std::vector< ::rtl::OUString > _attrNames;
115     ::std::vector< ::rtl::OUString > _attrValues;
116 
117     ::std::vector< ::com::sun::star::uno::Reference<
118                    ::com::sun::star::xml::sax::XAttributeList > > _subElems;
119 };
120 
121 
122 /*##################################################################################################
123 
124     STREAMING
125 
126 ##################################################################################################*/
127 
128 //==================================================================================================
129 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
130 SAL_CALL createInputStream(
131     ::rtl::ByteSequence const & rInData )
132     SAL_THROW( () );
133 
134 //==================================================================================================
135 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
136 SAL_CALL createOutputStream(
137     ::rtl::ByteSequence * pOutData )
138     SAL_THROW( () );
139 
140 }
141 
142 #endif
143